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