Add static AsString functions for PeerConnectionInterface enums

Changes one preexisting enum-to-string function to use the new format.

Also changes the RTC_LOG macros that created collisions with ToString,
for tidiness, and documents the recommended function form.

Bug: webrtc:13272
Change-Id: Ic8bb54ed31402ba32675b142d796cf276ee78df5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235722
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35296}
This commit is contained in:
Harald Alvestrand
2021-11-02 10:54:38 +00:00
committed by WebRTC LUCI CQ
parent 1bffe9e885
commit 31b03e9d50
4 changed files with 108 additions and 32 deletions

View File

@ -82,7 +82,15 @@ in the (slow) process of being removed from the codebase.
* RecursiveCriticalSection. Try to use [webrtc::Mutex][6] instead, and don't recurse.
## Enum-To-String functions
If there is a need to convert an enum to a string representation, such as for
enums exposed at the Javascript API interface, the recommended way is to write
a function named AsString, declared "static constexpr" and returning an
absl::string_view. The declaration should be right after the enum declaration,
in the same scope; the implementation (which must be marked "inline") should
be at the end of the same header file.
If the enum is not defined within a class, the "static" keyword is not needed.
[1]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/api/units/timestamp.h;drc=b95d90b78a3491ef8e8aa0640dd521515ec881ca;l=29
[2]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/rtc_base/thread.h;drc=1107751b6f11c35259a1c5c8a0f716e227b7e3b4;l=194