4 * @brief Settings plugin loader implementation.
6 * @author Ossama Othman @<ossama.othman@@intel.com@>
9 * Copyright 2012, 2013 Intel Corporation All Rights Reserved.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation;
14 * version 2.1 of the License.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
29 #include "manager.hpp"
30 #include <settingsd/plugin.hpp>
31 #include <settingsd/registrar.hpp>
32 #include <settingsd/event_callback.hpp>
34 #include <system_error>
39 /// We use this macro to silence @c -pedantic warnings from g++ that
40 /// there is no way to properly fix.
41 # define IVI_SETTINGS_EXTENSION __extension__
43 # define IVI_SETTINGS_EXTENSION
47 ivi::settings::loader::loader(std::string const & plugin_name,
48 ivi::settings::manager & mgr)
49 : handle_(dlopen(plugin_name.c_str(), RTLD_LAZY | RTLD_GLOBAL))
51 if (handle_ == nullptr) {
52 throw std::system_error(std::error_code(), dlerror());
55 // Reset any lingering dynamic linking related errors (see
59 // Retrieve the settings factory and destroyer functions.
60 typedef bool(*factory_type)(registrar &, event_callback const &);
61 factory_type const register_settings =
62 IVI_SETTINGS_EXTENSION reinterpret_cast<factory_type>(
64 "register_settings"));
66 if (register_settings == nullptr)
67 throw std::system_error(std::error_code(), dlerror());
69 // Now create the underlying settings implementation.
72 event_callback e(mgr);
73 if (!register_settings(r, e))
74 throw std::runtime_error("Unable to make \""
76 + "\" settings plugin");
79 ivi::settings::loader::~loader()
88 // indent-tabs-mode: nil