Files
media_cas_packager_sdk_source/util/status.cc
2018-10-01 14:59:29 -07:00

63 lines
2.2 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Google LLC.
//
// This software is licensed under the terms defined in the Widevine Master
// License Agreement. For a copy of this agreement, please contact
// widevine-licensing@google.com.
////////////////////////////////////////////////////////////////////////////////
#include <string>
#include "base/macros.h"
#include "absl/strings/str_cat.h"
#include "util/status.h"
namespace widevine {
namespace util {
namespace {
const char* kLicenseServerStatusMessage[] = {"OK",
"UNKNOWN_ERROR",
"UNKNOWN_ERROR",
"INVALID_ARGUMENT",
"UNKNOWN_ERROR",
"NOT_FOUND",
"ALREADY_EXISTS",
"PERMISSION_DENIED",
"UNKNOWN_ERROR",
"UNKNOWN_ERROR",
"UNKNOWN_ERROR",
"UNKNOWN_ERROR",
"UNIMPLEMENTED",
"INTERNAL",
"UNAVAILABLE"};
} // namespace
std::string GenericErrorSpace::SpaceName() { return "generic"; }
std::string GenericErrorSpace::CodeToString(int code) {
static_assert(
arraysize(kLicenseServerStatusMessage) == error::NUM_ERRORS,
"mismatching license_server_sdk status message and license_server_sdk "
"status.");
if (code >= 0 && code < error::NUM_ERRORS)
return kLicenseServerStatusMessage[code];
return std::to_string(code);
}
std::string Status::ToString() const {
if (status_code_ == error::OK) return "OK";
return absl::StrCat("Errors::", error_space_->String(status_code_), ": ",
error_message_);
}
std::ostream& operator<<(std::ostream& os, const Status& x) {
os << x.ToString();
return os;
}
} // namespace util
} // namespace widevine