4 * @brief Settings manager header.
6 * @author Ossama Othman @<ossama.othman@@intel.com@>
9 * Copyright 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
26 * @note This header is internal.
29 #ifndef IVI_SETTINGS_MANAGER_HPP
30 #define IVI_SETTINGS_MANAGER_HPP
34 #include <settingsd/plugin.hpp>
35 #include <settingsd/send_callback.hpp>
37 #include <libwebsockets.h>
53 * @brief The @c manager class is repository for all
56 * This class exposes the basic settings interface, and hides the
57 * underlying settings plugin details from the caller. All
58 * interaction with settings plugins is done through this class.
60 class SETTINGS_API manager
67 * @param[in] dir The settings plugin directory path.
69 manager(std::string const & dir);
74 /// Register settings plugin with the settings daemon.
75 bool register_setting(std::unique_ptr<plugin> p);
78 * Dispatch request to appropriate settings plugin.
80 * @param[in] request JSON formatted request string.
81 * @param[in] wsi Websocket through which response will be
84 void dispatch(std::string request, libwebsocket * wsi);
87 * Subscribe client on the other side of the WebSocket @a wsi to
88 * events created by settings plugins.
90 void subscribe_client(libwebsocket * wsi);
93 * Unsubscribe client on the other side of the WebSocket @a wsi
94 * from receiving further settings plugin events.
96 void unsubscribe_client(libwebsocket * wsi);
99 * Send JSON formatted event to all clients.
101 * @param[in] builder Object used to generate the JSON formatted
104 * @return @c true on success.
106 bool send_event(unique_ptr<JsonBuilder> const & builder) const;
111 * @name Prevent copying
114 manager(manager const &) = delete;
115 manager & operator=(manager const &) = delete;
119 void load_settings(std::string const & dir);
124 * @todo A map may be overkill if only a few plugins will ever be
125 * registered. It may actually be more efficient from both
126 * a space and time point of view to simply use an array or
127 * linked list - although those alternatives would force us
128 * to explicitly prevent registration of settings plugins
129 * with duplicate names.
131 typedef std::map<std::string, std::unique_ptr<plugin>> map_type;
134 * List of settings plugin loaders.
136 * Each plugin could potentially register multiple plugins so we
137 * keep track of the loaders independently. We only keep these
138 * around so that we can gracefully close the plugins if
141 * @note This member must come before the settings plugin map,
142 * @c settings_, so that the plugins are still in memory
143 * (i.e. not @c dlclose()d) before they are destructed.
144 * Remember that the members are destroyed in the reverse
145 * order they are initialized.
147 std::vector<std::unique_ptr<loader>> loaders_;
149 /// Map of settings name to @c settings instance.
152 /// Mutex used to synchronize access to the send_callback list.
153 mutable std::mutex mutex_;
156 * List of client WebSockets to be used for sending events to
159 std::vector<send_callback> send_callbacks_;
167 #endif /* IVI_SETTINGS_MANAGER_HPP */
173 // indent-tabs-mode: nil