DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
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/media/base/status.h"
8 
9 #include "packager/base/logging.h"
10 #include "packager/base/strings/stringprintf.h"
11 
12 namespace shaka {
13 namespace media {
14 
15 namespace error {
16 namespace {
17 std::string ErrorCodeToString(Code error_code) {
18  switch (error_code) {
19  case OK:
20  return "OK";
21  case UNKNOWN:
22  return "UNKNOWN";
23  case CANCELLED:
24  return "CANCELLED";
25  case INVALID_ARGUMENT:
26  return "INVALID_ARGUMENT";
27  case UNIMPLEMENTED:
28  return "UNIMPLEMENTED";
29  case FILE_FAILURE:
30  return "FILE_FAILURE";
31  case END_OF_STREAM:
32  return "END_OF_STREAM";
33  case HTTP_FAILURE:
34  return "HTTP_FAILURE";
35  case PARSER_FAILURE:
36  return "PARSER_FAILURE";
37  case ENCRYPTION_FAILURE:
38  return "ENCRYPTION_FAILURE";
39  case CHUNKING_ERROR:
40  return "CHUNKING_ERROR";
41  case MUXER_FAILURE:
42  return "MUXER_FAILURE";
43  case FRAGMENT_FINALIZED:
44  return "FRAGMENT_FINALIZED";
45  case SERVER_ERROR:
46  return "SERVER_ERROR";
47  case INTERNAL_ERROR:
48  return "INTERNAL_ERROR";
49  case STOPPED:
50  return "STOPPED";
51  case TIME_OUT:
52  return "TIME_OUT";
53  case NOT_FOUND:
54  return "NOT_FOUND";
55  case ALREADY_EXISTS:
56  return "ALREADY_EXISTS";
57  default:
58  NOTIMPLEMENTED() << "Unknown Status Code: " << error_code;
59  return "UNKNOWN_STATUS";
60  }
61 }
62 } // namespace
63 } // namespace error
64 
65 const Status Status::OK = Status(error::OK, "");
66 const Status Status::UNKNOWN = Status(error::UNKNOWN, "");
67 
68 std::string Status::ToString() const {
69  if (error_code_ == error::OK)
70  return "OK";
71 
72  return base::StringPrintf("%d (%s): %s",
73  error_code_,
74  error::ErrorCodeToString(error_code_).c_str(),
75  error_message_.c_str());
76 }
77 
78 std::ostream& operator<<(std::ostream& os, const Status& x) {
79  os << x.ToString();
80  return os;
81 }
82 
83 } // namespace media
84 } // namespace shaka
std::string ToString() const
Definition: status.cc:68