Shaka Packager SDK
status.h
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 #ifndef PACKAGER_STATUS_H_
8 #define PACKAGER_STATUS_H_
9 
10 #include <iostream>
11 #include <string>
12 
13 #if defined(SHARED_LIBRARY_BUILD)
14 #if defined(_WIN32)
15 
16 #if defined(SHAKA_IMPLEMENTATION)
17 #define SHAKA_EXPORT __declspec(dllexport)
18 #else
19 #define SHAKA_EXPORT __declspec(dllimport)
20 #endif // defined(SHAKA_IMPLEMENTATION)
21 
22 #else // defined(_WIN32)
23 
24 #if defined(SHAKA_IMPLEMENTATION)
25 #define SHAKA_EXPORT __attribute__((visibility("default")))
26 #else
27 #define SHAKA_EXPORT
28 #endif
29 
30 #endif // defined(_WIN32)
31 
32 #else // defined(SHARED_LIBRARY_BUILD)
33 #define SHAKA_EXPORT
34 #endif // defined(SHARED_LIBRARY_BUILD)
35 
36 namespace shaka {
37 
38 namespace error {
39 
41 enum Code {
42  // Not an error; returned on success
43  OK,
44 
45  // Unknown error. An example of where this error may be returned is
46  // errors raised by APIs that do not return enough error information
47  // may be converted to this error.
48  UNKNOWN,
49 
50  // The operation was cancelled (typically by the caller).
51  CANCELLED,
52 
53  // Client specified an invalid argument. INVALID_ARGUMENT indicates
54  // arguments that are problematic regardless of the state of the system
55  // (e.g. a malformed file name).
56  INVALID_ARGUMENT,
57 
58  // Operation is not implemented or not supported/enabled.
59  UNIMPLEMENTED,
60 
61  // Cannot open file.
62  FILE_FAILURE,
63 
64  // End of stream.
65  END_OF_STREAM,
66 
67  // Failure to get HTTP response successfully,
68  HTTP_FAILURE,
69 
70  // Unable to parse the media file.
71  PARSER_FAILURE,
72 
73  // Failed to do the encryption.
74  ENCRYPTION_FAILURE,
75 
76  // Error when trying to do chunking.
77  CHUNKING_ERROR,
78 
79  // Fail to mux the media file.
80  MUXER_FAILURE,
81 
82  // This track fragment is finalized.
83  FRAGMENT_FINALIZED,
84 
85  // Server errors. Receives malformed response from server.
86  SERVER_ERROR,
87 
88  // Internal errors. Some invariants have been broken.
89  INTERNAL_ERROR,
90 
91  // The operation was stopped.
92  STOPPED,
93 
94  // The operation timed out.
95  TIME_OUT,
96 
97  // Value was not found.
98  NOT_FOUND,
99 
100  // The entity that a client attempted to create (e.g., file or directory)
101  // already exists.
102  ALREADY_EXISTS,
103 
104  // Error when trying to generate trick play stream.
105  TRICK_PLAY_ERROR,
106 };
107 
108 } // namespace error
109 
110 class SHAKA_EXPORT Status {
111  public:
113  Status() : error_code_(error::OK) {}
114 
118  Status(error::Code error_code, const std::string& error_message);
119 
122  static const Status OK; // Identical to 0-arg constructor.
123  static const Status UNKNOWN;
125 
134  void Update(Status new_status);
135 
136  bool ok() const { return error_code_ == error::OK; }
137  error::Code error_code() const { return error_code_; }
138  const std::string& error_message() const { return error_message_; }
139 
140  bool operator==(const Status& x) const {
141  return error_code_ == x.error_code() && error_message_ == x.error_message();
142  }
143  bool operator!=(const Status& x) const { return !(*this == x); }
144 
146  std::string ToString() const;
147 
148  private:
149  error::Code error_code_;
150  std::string error_message_;
151 
152  // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
153  // generated copy constructor and assignment operator.
154 };
155 
156 SHAKA_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x);
157 
158 } // namespace shaka
159 
160 #endif // PACKAGER_STATUS_H_
All the methods that are virtual are virtual for mocking.
Status()
Creates a "successful" status.
Definition: status.h:113