Shaka Player Embedded
storage.h
Go to the documentation of this file.
1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_STORAGE_H_
16 #define SHAKA_EMBEDDED_STORAGE_H_
17 
18 #include <memory>
19 #include <string>
20 #include <type_traits>
21 #include <unordered_map>
22 #include <vector>
23 
24 #include "async_results.h"
25 #include "macros.h"
26 #include "offline_externs.h"
27 #include "player.h"
28 
29 namespace shaka {
30 
31 class JsManager;
32 
39 class SHAKA_EXPORT Storage final {
40  public:
45  class Client {
46  public:
48 
49 
55  virtual void OnProgress(StoredContent content, double progress);
56  };
57 
63  Storage(JsManager* engine, Player* player = nullptr);
64  Storage(Storage&&);
65  ~Storage();
66 
67  Storage& operator=(Storage&&);
68 
70 
76  static AsyncResults<bool> Support(JsManager* engine);
77 
84  static AsyncResults<void> DeleteAll(JsManager* engine);
85 
86 
91  AsyncResults<void> Initialize(Client* client = nullptr);
92 
98  AsyncResults<void> Destroy();
99 
100 
102  AsyncResults<bool> GetStoreInProgress();
103 
104 
106 
116  AsyncResults<bool> Configure(const std::string& name_path, DefaultValueType);
117  AsyncResults<bool> Configure(const std::string& name_path, bool value);
118  AsyncResults<bool> Configure(const std::string& name_path, double value);
119  AsyncResults<bool> Configure(const std::string& name_path,
120  const std::string& value);
121  template <typename T, typename = typename std::enable_if<
122  std::is_arithmetic<T>::value>::type>
123  AsyncResults<bool> Configure(const std::string& name_path, T value) {
124  // Since there are both bool and double overloads, any other number type
125  // will cause an ambiguous call. This disambiguates the calls.
126  return Configure(name_path, static_cast<double>(value));
127  }
128  AsyncResults<bool> Configure(const std::string& name_path,
129  const char* value) {
130  // For some reason, the compiler tries to use the bool overload over the
131  // std::string one when passing a char pointer.
132  return Configure(name_path, std::string(value));
133  }
135 
136 
144 
149  AsyncResults<void> Remove(const std::string& content_uri);
150 
155  AsyncResults<bool> RemoveEmeSessions();
156 
162  AsyncResults<StoredContent> Store(const std::string& uri);
163 
169  const std::string& uri,
170  const std::unordered_map<std::string, std::string>& app_metadata);
171 
172  private:
173  class Impl;
174  std::unique_ptr<Impl> impl_;
175 };
176 
177 } // namespace shaka
178 
179 #endif // SHAKA_EMBEDDED_STORAGE_H_
#define SHAKA_EXPORT
Definition: macros.h:30
AsyncResults< bool > Configure(const std::string &name_path, T value)
Definition: storage.h:123
ExceptionCode type
#define SHAKA_NON_COPYABLE_TYPE(Type)
Definition: macros.h:43
#define SHAKA_DECLARE_INTERFACE_METHODS(Type)
Definition: macros.h:55
AsyncResults< bool > Configure(const std::string &name_path, const char *value)
Definition: storage.h:128