summaryrefslogtreecommitdiff
path: root/implementation/configuration/src/configuration_plugin_impl.cpp
blob: df175f337c7322c952fa7def004efbb7c813c7ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <vsomeip/internal/logger.hpp>

#include "../include/configuration_plugin_impl.hpp"
#include "../include/configuration_impl.hpp"

VSOMEIP_PLUGIN(vsomeip_v3::configuration_plugin_impl)

namespace vsomeip_v3 {

configuration_plugin_impl::configuration_plugin_impl()
    : plugin_impl("vsomeip-configuration-plugin",
            VSOMEIP_CONFIG_PLUGIN_VERSION,
            plugin_type_e::CONFIGURATION_PLUGIN) {
}

configuration_plugin_impl::~configuration_plugin_impl() {
}

std::shared_ptr<configuration>
configuration_plugin_impl::get_configuration(const std::string &_name) {
    std::lock_guard<std::mutex> its_lock(mutex_);
    if (!default_) {
        default_ = std::make_shared<cfg::configuration_impl>();
        default_->load(_name);
    }

#ifdef VSOMEIP_ENABLE_CONFIGURATION_OVERLAYS
    auto its_configuration(default_);
    if (its_configuration->has_overlay(_name)) {
        VSOMEIP_INFO << "Loading configuration overlay for \"" << _name << "\"";
        auto its_iterator = configurations_.find(_name);
        if (its_iterator != configurations_.end()) {
            its_configuration = its_iterator->second;
        } else {
            its_configuration = std::make_shared<cfg::configuration_impl>(
                    *(its_configuration.get()));
            its_configuration->load_overlay(_name);
            configurations_[_name] = its_configuration;
        }
    }
    return its_configuration;
#else
    return default_;
#endif // VSOMEIP_ENABLE_CONFIGURATION_OVERLAYS
}

} // namespace vsomeip_v3