| 1 | /* | 
|---|---|
| 2 | Copyright 2018 Google Inc. All Rights Reserved. | 
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); | 
| 5 | you may not use this file except in compliance with the License. | 
| 6 | You may obtain a copy of the License at | 
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 | 
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software | 
| 11 | distributed under the License is distributed on an "AS-IS" BASIS, | 
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| 13 | See the License for the specific language governing permissions and | 
| 14 | limitations under the License. | 
| 15 | */ | 
| 16 | |
| 17 | #include "graph/source_parameters_manager.h" | 
| 18 | |
| 19 | #include "base/logging.h" | 
| 20 | |
| 21 | namespace vraudio { | 
| 22 | |
| 23 | void SourceParametersManager::Register(SourceId source_id) { | 
| 24 | DCHECK(parameters_.find(source_id) == parameters_.end()); | 
| 25 | parameters_[source_id] = SourceParameters(); | 
| 26 | } | 
| 27 | |
| 28 | void SourceParametersManager::Unregister(SourceId source_id) { | 
| 29 | parameters_.erase(x: source_id); | 
| 30 | } | 
| 31 | |
| 32 | const SourceParameters* SourceParametersManager::GetParameters( | 
| 33 | SourceId source_id) const { | 
| 34 | const auto source_parameters_itr = parameters_.find(x: source_id); | 
| 35 | if (source_parameters_itr == parameters_.end()) { | 
| 36 |     LOG(ERROR) << "Source "<< source_id << " not found";  | 
| 37 | return nullptr; | 
| 38 | } | 
| 39 | return &source_parameters_itr->second; | 
| 40 | } | 
| 41 | |
| 42 | SourceParameters* SourceParametersManager::GetMutableParameters( | 
| 43 | SourceId source_id) { | 
| 44 | auto source_parameters_itr = parameters_.find(x: source_id); | 
| 45 | if (source_parameters_itr == parameters_.end()) { | 
| 46 |     LOG(ERROR) << "Source "<< source_id << " not found";  | 
| 47 | return nullptr; | 
| 48 | } | 
| 49 | return &source_parameters_itr->second; | 
| 50 | } | 
| 51 | |
| 52 | void SourceParametersManager::ProcessAllParameters(const Process& process) { | 
| 53 | for (auto& source_parameters_itr : parameters_) { | 
| 54 | process(&source_parameters_itr.second); | 
| 55 | } | 
| 56 | } | 
| 57 | |
| 58 | } // namespace vraudio | 
| 59 | 
