-
Notifications
You must be signed in to change notification settings - Fork 518
/
Copy pathstatus.h
160 lines (117 loc) · 4.04 KB
/
status.h
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// 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
#ifndef PACKAGER_STATUS_H_
#define PACKAGER_STATUS_H_
#include <iostream>
#include <string>
#if defined(SHARED_LIBRARY_BUILD)
#if defined(_WIN32)
#if defined(SHAKA_IMPLEMENTATION)
#define SHAKA_EXPORT __declspec(dllexport)
#else
#define SHAKA_EXPORT __declspec(dllimport)
#endif // defined(SHAKA_IMPLEMENTATION)
#else // defined(_WIN32)
#if defined(SHAKA_IMPLEMENTATION)
#define SHAKA_EXPORT __attribute__((visibility("default")))
#else
#define SHAKA_EXPORT
#endif
#endif // defined(_WIN32)
#else // defined(SHARED_LIBRARY_BUILD)
#define SHAKA_EXPORT
#endif // defined(SHARED_LIBRARY_BUILD)
namespace shaka {
namespace error {
/// Error codes for the packager APIs.
enum Code {
// Not an error; returned on success
OK,
// Unknown error. An example of where this error may be returned is
// errors raised by APIs that do not return enough error information
// may be converted to this error.
UNKNOWN,
// The operation was cancelled (typically by the caller).
CANCELLED,
// Client specified an invalid argument. INVALID_ARGUMENT indicates
// arguments that are problematic regardless of the state of the system
// (e.g. a malformed file name).
INVALID_ARGUMENT,
// Operation is not implemented or not supported/enabled.
UNIMPLEMENTED,
// Cannot open file.
FILE_FAILURE,
// End of stream.
END_OF_STREAM,
// Failure to get HTTP response successfully,
HTTP_FAILURE,
// Unable to parse the media file.
PARSER_FAILURE,
// Failed to do the encryption.
ENCRYPTION_FAILURE,
// Error when trying to do chunking.
CHUNKING_ERROR,
// Fail to mux the media file.
MUXER_FAILURE,
// This track fragment is finalized.
FRAGMENT_FINALIZED,
// Server errors. Receives malformed response from server.
SERVER_ERROR,
// Internal errors. Some invariants have been broken.
INTERNAL_ERROR,
// The operation was stopped.
STOPPED,
// The operation timed out.
TIME_OUT,
// Value was not found.
NOT_FOUND,
// The entity that a client attempted to create (e.g., file or directory)
// already exists.
ALREADY_EXISTS,
// Error when trying to generate trick play stream.
TRICK_PLAY_ERROR,
};
} // namespace error
class SHAKA_EXPORT Status {
public:
/// Creates a "successful" status.
Status() : error_code_(error::OK) {}
/// Create a status with the specified code, and error message.
/// If "error_code == error::OK", error_message is ignored and a Status
/// object identical to Status::OK is constructed.
Status(error::Code error_code, const std::string& error_message);
/// @name Some pre-defined Status objects.
/// @{
static const Status OK; // Identical to 0-arg constructor.
static const Status UNKNOWN;
/// @}
/// If "ok()", stores "new_status" into *this. If "!ok()", preserves
/// the current "error_code()/error_message()",
///
/// Convenient way of keeping track of the first error encountered.
/// Instead of:
/// if (overall_status.ok()) overall_status = new_status
/// Use:
/// overall_status.Update(new_status);
void Update(Status new_status);
bool ok() const { return error_code_ == error::OK; }
error::Code error_code() const { return error_code_; }
const std::string& error_message() const { return error_message_; }
bool operator==(const Status& x) const {
return error_code_ == x.error_code() && error_message_ == x.error_message();
}
bool operator!=(const Status& x) const { return !(*this == x); }
/// @return A combination of the error code name and message.
std::string ToString() const;
private:
error::Code error_code_;
std::string error_message_;
// Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
// generated copy constructor and assignment operator.
};
SHAKA_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x);
} // namespace shaka
#endif // PACKAGER_STATUS_H_