2 * @file connman_service.cpp
4 * @brief Connman Service operations.
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
27 #include "connman_service.hpp"
28 #include "service.hpp"
30 #include <settingsd/response_callback.hpp>
31 #include <settingsd/glib_traits.hpp>
32 #include <settingsd/unique_ptr.hpp>
37 // ----------------------------------------------------------------------
41 std::string const service_name("connman::service");
44 // ----------------------------------------------------------------------
46 ivi::settings::connman_service::connman_service(
47 GDBusConnection * connection,
48 connman_manager & manager)
49 : connection_(connection)
54 ivi::settings::connman_service::~connman_service()
59 ivi::settings::connman_service::id() const
65 ivi::settings::connman_service::handle_request(
67 response_callback response)
69 unique_ptr<JsonParser> const parser(json_parser_new());
70 json_parser_load_from_data(parser.get(), request.c_str(), -1, nullptr);
72 unique_ptr<JsonReader> const safe_reader(
73 json_reader_new(json_parser_get_root(parser.get())));
74 JsonReader * const reader = safe_reader.get();
76 char const * name = nullptr;
77 if (json_reader_read_member(reader, "name"))
78 name = json_reader_get_string_value(reader);
81 "Malformed " + id() + " request: missing 'name' element");
83 json_reader_end_member(reader);
85 if (name != nullptr) {
86 if (json_reader_read_member(reader, "value")) {
87 // The service object path is the first array element.
88 json_reader_read_element(reader, 0);
89 char const * const path = json_reader_get_string_value(reader);
90 json_reader_end_element(reader);
92 if (path != nullptr) {
93 service s(path, connection_);
94 s.handle_request(name, reader, manager_, response);
97 json_reader_end_member(reader);
100 "Operation name for " + id() + " request is not a string.");
108 // indent-tabs-mode: nil