Shaka Packager SDK
status.cc
1 // Copyright 2014 Google Inc. 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 "packager/base/logging.h"
10 #include "packager/base/strings/stringprintf.h"
11 
12 namespace shaka {
13 
14 namespace error {
15 namespace {
16 const char* ErrorCodeToString(Code error_code) {
17  switch (error_code) {
18  case OK:
19  return "OK";
20  case UNKNOWN:
21  return "UNKNOWN";
22  case CANCELLED:
23  return "CANCELLED";
24  case INVALID_ARGUMENT:
25  return "INVALID_ARGUMENT";
26  case UNIMPLEMENTED:
27  return "UNIMPLEMENTED";
28  case FILE_FAILURE:
29  return "FILE_FAILURE";
30  case END_OF_STREAM:
31  return "END_OF_STREAM";
32  case HTTP_FAILURE:
33  return "HTTP_FAILURE";
34  case PARSER_FAILURE:
35  return "PARSER_FAILURE";
36  case ENCRYPTION_FAILURE:
37  return "ENCRYPTION_FAILURE";
38  case CHUNKING_ERROR:
39  return "CHUNKING_ERROR";
40  case MUXER_FAILURE:
41  return "MUXER_FAILURE";
42  case FRAGMENT_FINALIZED:
43  return "FRAGMENT_FINALIZED";
44  case SERVER_ERROR:
45  return "SERVER_ERROR";
46  case INTERNAL_ERROR:
47  return "INTERNAL_ERROR";
48  case STOPPED:
49  return "STOPPED";
50  case TIME_OUT:
51  return "TIME_OUT";
52  case NOT_FOUND:
53  return "NOT_FOUND";
54  case ALREADY_EXISTS:
55  return "ALREADY_EXISTS";
56  case TRICK_PLAY_ERROR:
57  return "TRICK_PLAY_ERROR";
58  }
59 
60  NOTIMPLEMENTED() << "Unknown Status Code: " << error_code;
61  return "UNKNOWN_STATUS";
62 }
63 } // namespace
64 } // namespace error
65 
66 const Status Status::OK = Status(error::OK, "");
67 const Status Status::UNKNOWN = Status(error::UNKNOWN, "");
68 
69 Status::Status(error::Code error_code, const std::string& error_message)
70  : error_code_(error_code) {
71  if (!ok()) {
72  error_message_ = error_message;
73  if (!error_message.empty())
74  VLOG(1) << ToString();
75  }
76 }
77 
78 void Status::Update(Status new_status) {
79  if (ok())
80  *this = std::move(new_status);
81 }
82 
83 std::string Status::ToString() const {
84  if (error_code_ == error::OK)
85  return "OK";
86 
87  return base::StringPrintf("%d (%s): %s", error_code_,
88  error::ErrorCodeToString(error_code_),
89  error_message_.c_str());
90 }
91 
92 std::ostream& operator<<(std::ostream& os, const Status& x) {
93  os << x.ToString();
94  return os;
95 }
96 
97 } // namespace shaka
Status()
Creates a "successful" status.
Definition: status.h:113
std::string ToString() const
Definition: status.cc:83
void Update(Status new_status)
Definition: status.cc:78
All the methods that are virtual are virtual for mocking.