Allow CE CDM integrators to specify their own logging
This patch adds a new interface that partners must provide to Cdm::initialize(), ILogger. ILogger replaces stderr as the sink to which logging messages are sent. For partners that still want to log to stderr, a reference implementation that logs to stderr is provided. As a side-effect of this, many test-related source files had to be updated to thread the new parameter to Cdm::initialize() through them. This also necessitated adding a new variant of FormatString() that can be called with a va_list directly so it can be called from other functions that take varargs. Bug: 201446862 Merged from https://widevine-internal-review.googlesource.com/177270 Change-Id: Ie31a10162773883b337f3a6144cf180a2b100139
This commit is contained in:
committed by
Robert Shih
parent
8e48e36554
commit
c232299f78
@@ -13,6 +13,11 @@ namespace wvutil {
|
||||
#endif
|
||||
bool FormatString(std::string* out, const char* fmt, ...);
|
||||
|
||||
#ifdef __GNUC__
|
||||
[[gnu::format(printf, 2, 0)]]
|
||||
#endif
|
||||
bool VFormatString(std::string* out, const char* fmt, va_list vlist);
|
||||
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_UTIL_STRING_FORMAT_H_
|
||||
|
||||
@@ -16,20 +16,27 @@ namespace wvutil {
|
||||
bool FormatString(std::string* out, const char* fmt, ...) {
|
||||
if (out == nullptr || fmt == nullptr) return false;
|
||||
|
||||
va_list ap1;
|
||||
va_start(ap1, fmt);
|
||||
const int desired_size = vsnprintf(nullptr, 0, fmt, ap1);
|
||||
va_end(ap1);
|
||||
va_list vlist;
|
||||
va_start(vlist, fmt);
|
||||
const bool result = VFormatString(out, fmt, vlist);
|
||||
va_end(vlist);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool VFormatString(std::string* out, const char* fmt, va_list vlist) {
|
||||
if (out == nullptr || fmt == nullptr) return false;
|
||||
|
||||
va_list vlist_copy;
|
||||
va_copy(vlist_copy, vlist);
|
||||
const int desired_size = vsnprintf(nullptr, 0, fmt, vlist_copy);
|
||||
va_end(vlist_copy);
|
||||
|
||||
if (desired_size < 0) return false;
|
||||
const size_t buffer_size =
|
||||
static_cast<size_t>(desired_size) + 1; // +1 for null
|
||||
std::unique_ptr<char[]> buffer(new char[buffer_size]);
|
||||
|
||||
va_list ap2;
|
||||
va_start(ap2, fmt);
|
||||
const int actual_size = vsnprintf(buffer.get(), buffer_size, fmt, ap2);
|
||||
va_end(ap2);
|
||||
const int actual_size = vsnprintf(buffer.get(), buffer_size, fmt, vlist);
|
||||
|
||||
if (actual_size != desired_size) return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user