1 // Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 
6 #include <vsomeip/internal/logger.hpp>
7 
8 #include "../include/configuration_plugin_impl.hpp"
9 #include "../include/configuration_impl.hpp"
10 
11 VSOMEIP_PLUGIN(vsomeip_v3::configuration_plugin_impl)
12 
13 namespace vsomeip_v3 {
14 
configuration_plugin_impl()15 configuration_plugin_impl::configuration_plugin_impl()
16     : plugin_impl("vsomeip-configuration-plugin",
17             VSOMEIP_CONFIG_PLUGIN_VERSION,
18             plugin_type_e::CONFIGURATION_PLUGIN) {
19 }
20 
~configuration_plugin_impl()21 configuration_plugin_impl::~configuration_plugin_impl() {
22 }
23 
24 std::shared_ptr<configuration>
get_configuration(const std::string & _name)25 configuration_plugin_impl::get_configuration(const std::string &_name) {
26     std::lock_guard<std::mutex> its_lock(mutex_);
27     if (!default_) {
28         default_ = std::make_shared<cfg::configuration_impl>();
29         default_->load(_name);
30     }
31 
32 #ifdef VSOMEIP_ENABLE_CONFIGURATION_OVERLAYS
33     auto its_configuration(default_);
34     if (its_configuration->has_overlay(_name)) {
35         VSOMEIP_INFO << "Loading configuration overlay for \"" << _name << "\"";
36         auto its_iterator = configurations_.find(_name);
37         if (its_iterator != configurations_.end()) {
38             its_configuration = its_iterator->second;
39         } else {
40             its_configuration = std::make_shared<cfg::configuration_impl>(
41                     *(its_configuration.get()));
42             its_configuration->load_overlay(_name);
43             configurations_[_name] = its_configuration;
44         }
45     }
46     return its_configuration;
47 #else
48     return default_;
49 #endif // VSOMEIP_ENABLE_CONFIGURATION_OVERLAYS
50 }
51 
52 } // namespace vsomeip_v3
53