2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Helge Norberg, helge.norberg@svt.se
24 #include "system_info_provider.h"
26 #include <boost/property_tree/ptree.hpp>
27 #include <boost/thread/mutex.hpp>
28 #include <boost/thread/lock_guard.hpp>
29 #include <boost/algorithm/string/case_conv.hpp>
34 namespace caspar { namespace core {
36 struct system_info_provider_repository::impl
38 mutable boost::mutex mutex_;
39 std::vector<system_info_provider> info_providers_;
40 std::map<std::wstring, version_provider> version_providers_;
42 void register_system_info_provider(system_info_provider provider)
44 boost::lock_guard<boost::mutex> lock(mutex_);
46 info_providers_.push_back(std::move(provider));
49 void register_version_provider(const std::wstring& version_name, version_provider provider)
51 boost::lock_guard<boost::mutex> lock(mutex_);
53 version_providers_.insert(std::make_pair(boost::algorithm::to_lower_copy(version_name), std::move(provider)));
56 void fill_information(boost::property_tree::wptree& info) const
58 boost::lock_guard<boost::mutex> lock(mutex_);
60 for (auto& provider : info_providers_)
64 std::wstring get_version(const std::wstring& version_name) const
66 boost::lock_guard<boost::mutex> lock(mutex_);
68 auto found = version_providers_.find(boost::algorithm::to_lower_copy(version_name));
70 if (found == version_providers_.end())
71 CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"No version provider with name " + version_name));
73 return found->second();
77 system_info_provider_repository::system_info_provider_repository()
82 void system_info_provider_repository::register_system_info_provider(system_info_provider provider)
84 impl_->register_system_info_provider(std::move(provider));
87 void system_info_provider_repository::register_version_provider(
88 const std::wstring& version_name, version_provider provider)
90 impl_->register_version_provider(version_name, provider);
93 void system_info_provider_repository::fill_information(boost::property_tree::wptree& info) const
95 impl_->fill_information(info);
98 std::wstring system_info_provider_repository::get_version(const std::wstring& version_name) const
100 return impl_->get_version(version_name);