2 * @file response_callback.hpp
4 * @brief Settings response callback header.
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
28 #ifndef IVI_SETTINGS_RESPONSE_CALLBACK_HPP
29 #define IVI_SETTINGS_RESPONSE_CALLBACK_HPP
31 #include <settingsd/settings_api.hpp>
33 #include <libwebsockets.h>
34 #include <json-glib/json-glib.h>
44 template<typename T> class smart_ptr;
47 * @class response_callback response_callback.hpp <settingsd/response_callback.hpp>
49 * @brief Callback that handles sending response to Settings app.
51 * A @c response_callback sends a JSON formatted response string
52 * to the Settings app. It is up to the specific settings plugin
53 * to decide what goes in to the response.
55 class SETTINGS_API response_callback
60 response_callback(struct libwebsocket * wsi,
62 std::string transaction_id);
68 * Send (successful) response to Settings app.
70 * The settings daemon requires that plugins use the json-glib
71 * library to build JSON respons strings. Plugins will pass a
72 * callback function @a response_builder that uses to the
73 * json-glib high level "builder" API to append the results of
74 * the successful Settings app request to the JSON response
75 * string. Plugins should take care to only use the builder
76 * functions that add members and their corresponding to
77 * values. They should not attempt to start or end the top
78 * level JSON object. That will be automatically handled by
81 * @param[in] response_builder Callback function that appends
82 * JSON formatted response data.
85 std::function<void(JsonBuilder *)> response_builder);
88 * Send error response to Settings app.
90 * @param[in] error_message Free form error message.
92 bool send_error(std::string error_message);
95 * The settings type/ID associated with the request and
98 * @note This method is generally used for debugging purposes,
101 std::string const & type() const { return type_; }
106 * Add string value to the response. If the string is empty a
107 * null JSON value will be added instead.
109 void add_string_value(JsonBuilder * builder,
110 std::string const & name,
111 std::string const & value);
114 * Begin the JSON formatted response to the Settings app
117 * The appropriate "header" information will be prepended to the
118 * response, such as transaction ID and result success or
121 * @param[in] result @c "succeeded" or @c "failed"
123 smart_ptr<JsonBuilder> begin_response(char const * result);
126 * End the JSON formatted response to the Settings app request.
128 void end_response(smart_ptr<JsonBuilder> const & builder);
131 * Send the JSON formatted response to the Settings app
132 * request over the corresponding websocket.
134 bool send_payload(smart_ptr<JsonBuilder> const & builder);
139 * Pointer to the websocket through which the response will be
140 * sent to the Settings app.
142 struct libwebsocket * const wsi_;
145 * Settings type (e.g. "bluetooth", "wifi", etc).
147 std::string const type_;
150 * Transaction/request ID created by Settings app.
152 std::string const transaction_id_;
159 #endif /* IVI_SETTINGS_RESPONSE_CALLBACK_HPP */
165 // indent-tabs-mode: nil