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