Shaka Player Embedded
implementation_registry.cc
Go to the documentation of this file.
1 // Copyright 2017 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 
16 
17 #include <glog/logging.h>
18 
19 #include <mutex>
20 #include <unordered_map>
21 
22 #include "src/util/macros.h"
23 
24 namespace shaka {
25 namespace eme {
26 
27 namespace {
28 
30 std::unordered_map<std::string, std::shared_ptr<ImplementationFactory>>
31  factories_;
32 std::mutex mutex_;
34 
35 } // namespace
36 
38  const std::string& key_system,
39  std::shared_ptr<ImplementationFactory> factory) {
40  std::unique_lock<std::mutex> lock(mutex_);
41  const auto it = factories_.find(key_system);
42  if (it != factories_.end())
43  it->second = factory;
44  else
45  factories_.emplace(key_system, factory);
46 }
47 
48 std::shared_ptr<ImplementationFactory>
49 ImplementationRegistry::GetImplementation(const std::string& key_system) {
50  std::unique_lock<std::mutex> lock(mutex_);
51  auto it = factories_.find(key_system);
52  return it != factories_.end() ? it->second : nullptr;
53 }
54 
55 } // namespace eme
56 } // namespace shaka
#define END_ALLOW_COMPLEX_STATICS
Definition: macros.h:43
static std::shared_ptr< ImplementationFactory > GetImplementation(const std::string &key_system)
#define BEGIN_ALLOW_COMPLEX_STATICS
Definition: macros.h:42
static void AddImplementation(const std::string &key_system, std::shared_ptr< ImplementationFactory > factory)