This reverts commit aaa6851d53741179a591d79fc82c4dd6651a7ba5. Reason for revert: breaks chromium webrtc import Original change's description: > Deprecate old constructors and set_type() in Candidate and Port > > * Deprecates constructors that use string based `type` > * Deprecates string based type functions in favor of enum based. > * Restrict possible values of Candidate::type. Ensure a valid value > is assigned at construction. > * Make Port constructors protected to limit their use to subclasses. > - The reason for this is to make sure that use of SharedSocket() > is controlled (it adds a bit of complexity). > * Simplify construction of Port (remove Construct() etc) > > Bug: webrtc:15846 > Change-Id: If24ed674e175642efa49da37fd2bc847dd14f613 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/339860 > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#41865} Bug: webrtc:15846 Change-Id: Ic8b7cba97f8fb207ef51a88900e704658ade28b7 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/342140 Auto-Submit: Ilya Nikolaevskiy <ilnik@webrtc.org> Owners-Override: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org> Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Cr-Commit-Position: refs/heads/main@{#41867}
How to write code in the api/ directory
Mostly, just follow the regular style guide, but:
- Note that
api/code is not exempt from the “.hand.ccfiles come in pairs” rule, so if you declare something inapi/path/to/foo.h, it should be defined inapi/path/to/foo.cc. - Headers in
api/should, if possible, not#includeheaders outsideapi/. It’s not always possible to avoid this, but be aware that it adds to a small mountain of technical debt that we’re trying to shrink. .ccfiles inapi/, on the other hand, are free to#includeheaders outsideapi/.- Avoid structs in api, prefer classes.
The preferred way for api/ code to access non-api/ code is to call
it from a .cc file, so that users of our API headers won’t transitively
#include non-public headers.
For headers in api/ that need to refer to non-public types, forward
declarations are often a lesser evil than including non-public header files. The
usual rules still apply, though.
.cc files in api/ should preferably be kept reasonably small. If a
substantial implementation is needed, consider putting it with our non-public
code, and just call it from the api/ .cc file.
Avoid defining api with structs as it makes harder for the api to evolve. Your struct may gain invariant, or change how it represents data. Evolving struct from the api is particular challenging as it is designed to be used in other code bases and thus needs to be updated independetly from its usage. Class with accessors and setters makes such migration safer. See Google C++ style guide for more.
If you need to evolve existent struct in api, prefer first to convert it into a class.