Shaka Packager SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
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 std::string 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  default:
57  NOTIMPLEMENTED() << "Unknown Status Code: " << error_code;
58  return "UNKNOWN_STATUS";
59  }
60 }
61 } // namespace
62 } // namespace error
63 
64 const Status Status::OK = Status(error::OK, "");
65 const Status Status::UNKNOWN = Status(error::UNKNOWN, "");
66 
67 std::string Status::ToString() const {
68  if (error_code_ == error::OK)
69  return "OK";
70 
71  return base::StringPrintf("%d (%s): %s",
72  error_code_,
73  error::ErrorCodeToString(error_code_).c_str(),
74  error_message_.c_str());
75 }
76 
77 std::ostream& operator<<(std::ostream& os, const Status& x) {
78  os << x.ToString();
79  return os;
80 }
81 
82 } // namespace shaka
std::string ToString() const
Definition: status.cc:67