Shaka Packager SDK
status.cc
1 // Copyright 2014 Google LLC. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include <packager/status.h>
8 
9 #include <absl/log/log.h>
10 #include <absl/strings/str_format.h>
11 
12 #include <packager/macros/logging.h>
13 
14 namespace shaka {
15 
16 namespace error {
17 namespace {
18 const char* ErrorCodeToString(Code error_code) {
19  switch (error_code) {
20  case OK:
21  return "OK";
22  case UNKNOWN:
23  return "UNKNOWN";
24  case CANCELLED:
25  return "CANCELLED";
26  case INVALID_ARGUMENT:
27  return "INVALID_ARGUMENT";
28  case UNIMPLEMENTED:
29  return "UNIMPLEMENTED";
30  case FILE_FAILURE:
31  return "FILE_FAILURE";
32  case END_OF_STREAM:
33  return "END_OF_STREAM";
34  case HTTP_FAILURE:
35  return "HTTP_FAILURE";
36  case PARSER_FAILURE:
37  return "PARSER_FAILURE";
38  case ENCRYPTION_FAILURE:
39  return "ENCRYPTION_FAILURE";
40  case CHUNKING_ERROR:
41  return "CHUNKING_ERROR";
42  case MUXER_FAILURE:
43  return "MUXER_FAILURE";
44  case FRAGMENT_FINALIZED:
45  return "FRAGMENT_FINALIZED";
46  case SERVER_ERROR:
47  return "SERVER_ERROR";
48  case INTERNAL_ERROR:
49  return "INTERNAL_ERROR";
50  case STOPPED:
51  return "STOPPED";
52  case TIME_OUT:
53  return "TIME_OUT";
54  case NOT_FOUND:
55  return "NOT_FOUND";
56  case ALREADY_EXISTS:
57  return "ALREADY_EXISTS";
58  case TRICK_PLAY_ERROR:
59  return "TRICK_PLAY_ERROR";
60  }
61 
62  NOTIMPLEMENTED() << "Unknown Status Code: " << error_code;
63  return "UNKNOWN_STATUS";
64 }
65 } // namespace
66 } // namespace error
67 
68 const Status Status::OK = Status(error::OK, "");
69 const Status Status::UNKNOWN = Status(error::UNKNOWN, "");
70 
71 Status::Status(error::Code error_code, const std::string& error_message)
72  : error_code_(error_code) {
73  if (!ok()) {
74  error_message_ = error_message;
75  if (!error_message.empty())
76  VLOG(1) << ToString();
77  }
78 }
79 
80 void Status::Update(Status new_status) {
81  if (ok())
82  *this = std::move(new_status);
83 }
84 
85 std::string Status::ToString() const {
86  if (error_code_ == error::OK)
87  return "OK";
88 
89  return absl::StrFormat("%d (%s): %s", error_code_,
90  error::ErrorCodeToString(error_code_),
91  error_message_.c_str());
92 }
93 
94 std::ostream& operator<<(std::ostream& os, const Status& x) {
95  os << x.ToString();
96  return os;
97 }
98 
99 } // namespace shaka
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66