diff options
author | Ossama Othman <ossama.othman@intel.com> | 2013-11-26 12:57:06 -0800 |
---|---|---|
committer | Ossama Othman <ossama.othman@intel.com> | 2013-11-26 12:57:06 -0800 |
commit | cc55a073c51f01e3e7caa91f6a6d60e658337857 (patch) | |
tree | ee76e7bd6004092e670a17b8b287edd79c039298 | |
parent | f612f06d4ab4f892fda44aca9b98a5068c4b8b05 (diff) | |
download | settings-daemon-cc55a073c51f01e3e7caa91f6a6d60e658337857.tar.gz settings-daemon-cc55a073c51f01e3e7caa91f6a6d60e658337857.tar.bz2 settings-daemon-cc55a073c51f01e3e7caa91f6a6d60e658337857.zip |
Migrated to new connman::service interface.
Change-Id: Ic907b6a604355f330b477acb6e1d55cd8921039c
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
-rw-r--r-- | plugins/connman/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/connman/connman_service.cpp | 109 | ||||
-rw-r--r-- | plugins/connman/connman_service.hpp | 100 | ||||
-rw-r--r-- | plugins/connman/registration.cpp | 5 | ||||
-rw-r--r-- | plugins/connman/service.cpp | 39 | ||||
-rw-r--r-- | plugins/connman/service.hpp | 24 |
6 files changed, 272 insertions, 7 deletions
diff --git a/plugins/connman/Makefile.am b/plugins/connman/Makefile.am index b8ebe39..f6683fc 100644 --- a/plugins/connman/Makefile.am +++ b/plugins/connman/Makefile.am @@ -36,6 +36,7 @@ connman_la_SOURCES = \ dbus_connection.cpp \ connman.cpp \ connman_manager.cpp \ + connman_service.cpp \ connman_technology.cpp \ service.cpp \ technology.cpp \ @@ -63,6 +64,7 @@ noinst_HEADERS = \ dbus_connection.hpp \ connman.hpp \ connman_manager.hpp \ + connman_service.hpp \ connman_technology.hpp \ service.hpp \ technology.hpp \ diff --git a/plugins/connman/connman_service.cpp b/plugins/connman/connman_service.cpp new file mode 100644 index 0000000..143087d --- /dev/null +++ b/plugins/connman/connman_service.cpp @@ -0,0 +1,109 @@ +/** + * @file connman_service.cpp + * + * @brief Connman Service operations. + * + * @author Ossama Othman @<ossama.othman@@intel.com@> + * + * @copyright @par + * Copyright 2013 Intel Corporation All Rights Reserved. + * @par + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * @par + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * @par + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include "connman_service.hpp" +#include "service.hpp" + +#include <settingsd/response_callback.hpp> +#include <settingsd/glib_traits.hpp> +#include <settingsd/unique_ptr.hpp> + + +#include <cstring> + +// ---------------------------------------------------------------------- + +namespace +{ + std::string const service_name("connman::service"); +} + +// ---------------------------------------------------------------------- + +ivi::settings::connman_service::connman_service( + GDBusConnection * connection, + event_callback const & e) + : connection_(connection) + , event_callback_(e) +{ +} + +ivi::settings::connman_service::~connman_service() +{ +} + +std::string const & +ivi::settings::connman_service::id() const +{ + return service_name; +} + +void +ivi::settings::connman_service::handle_request( + std::string request, + response_callback response) +{ + unique_ptr<JsonParser> const parser(json_parser_new()); + json_parser_load_from_data(parser.get(), request.c_str(), -1, nullptr); + + unique_ptr<JsonReader> const safe_reader( + json_reader_new(json_parser_get_root(parser.get()))); + JsonReader * const reader = safe_reader.get(); + + char const * name = nullptr; + if (json_reader_read_member(reader, "name")) + name = json_reader_get_string_value(reader); + else + response.send_error( + "Malformed " + id() + " request: missing 'name' element"); + + json_reader_end_member(reader); + + if (name != nullptr) { + if (json_reader_read_member(reader, "value")) { + // The service object path is the first array element. + json_reader_read_element(reader, 0); + char const * const path = json_reader_get_string_value(reader); + json_reader_end_element(reader); + + if (path != nullptr) { + service s(path, connection_, event_callback_); + s.handle_request(name, reader, response); + } + } + json_reader_end_member(reader); + } else { + response.send_error( + "Operation name for " + id() + " request is not a string."); + } +} + + +// Local Variables: +// mode:c++ +// c-basic-offset:2 +// indent-tabs-mode: nil +// End: diff --git a/plugins/connman/connman_service.hpp b/plugins/connman/connman_service.hpp new file mode 100644 index 0000000..c76902c --- /dev/null +++ b/plugins/connman/connman_service.hpp @@ -0,0 +1,100 @@ +/** + * @file connman_service.hpp + * + * @brief Connman Service-based settings plugin header. + * + * @author Ossama Othman @<ossama.othman@@intel.com@> + * + * @copyright @par + * Copyright 2013 Intel Corporation All Rights Reserved. + * @par + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * @par + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * @par + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef IVI_SETTINGS_CONNMAN_CONNMAN_SERVICE_HPP +#define IVI_SETTINGS_CONNMAN_CONNMAN_SERVICE_HPP + +#include "connman.hpp" + +#include <settingsd/plugin.hpp> +#include <settingsd/event_callback.hpp> + +#include <gio/gio.h> + +#include <string> + + +namespace ivi +{ + namespace settings + { + class connman_manager; + + /** + * @class connman_service + * + * @brief D-Bus Connman Service object bridge. + * + * This class exposes the Connman Service D-Bus API through the + * settings daemon WebSocket API. + */ + class connman_service : public plugin + { + public: + + /// Constructor. + connman_service(GDBusConnection * connection, + event_callback const & e); + + /// Destructor. + ~connman_service(); + + /** + * @name Settings Plugin API + * + * Interface defined by the @c ivi::settings::plugin abstract + * base class. + * + * @see settingsd/plugin.hpp + */ + //@{ + virtual std::string const & id() const; + virtual void handle_request(std::string request, + response_callback response); + //@} + + private: + + /// The underlying D-Bus connection. + GDBusConnection * const connection_; + + /// Callback through which events will be sent to clients. + event_callback event_callback_; + + }; + + } +} + + +#endif /* IVI_SETTINGS_CONNMAN_CONNMAN_SERVICE_HPP */ + + +// Local Variables: +// mode:c++ +// c-basic-offset:2 +// indent-tabs-mode: nil +// End: diff --git a/plugins/connman/registration.cpp b/plugins/connman/registration.cpp index 4b37c82..51f4aaa 100644 --- a/plugins/connman/registration.cpp +++ b/plugins/connman/registration.cpp @@ -27,6 +27,7 @@ #include "connman_api.hpp" #include "dbus_connection.hpp" #include "connman_manager.hpp" +#include "connman_service.hpp" #include "connman_technology.hpp" #include "clock.hpp" @@ -57,6 +58,9 @@ register_settings(ivi::settings::registrar & r, new ivi::settings::connman_manager(connection, e); std::unique_ptr<ivi::settings::plugin> manager(mgr); + std::unique_ptr<ivi::settings::plugin> service( + new ivi::settings::connman_service(connection, e)); + std::unique_ptr<ivi::settings::plugin> technology( new ivi::settings::connman_technology(connection, *mgr, e)); @@ -65,6 +69,7 @@ register_settings(ivi::settings::registrar & r, return r.register_setting(std::move(manager)) + && r.register_setting(std::move(service)) && r.register_setting(std::move(technology)) && r.register_setting(std::move(clk)); } diff --git a/plugins/connman/service.cpp b/plugins/connman/service.cpp index 463b191..8d25157 100644 --- a/plugins/connman/service.cpp +++ b/plugins/connman/service.cpp @@ -30,7 +30,7 @@ #include <settingsd/unique_ptr.hpp> #include <settingsd/response_callback.hpp> -#include <chrono> +#include <cstring> ivi::settings::service::service(std::string service_path, @@ -44,14 +44,47 @@ ivi::settings::service::service(std::string service_path, } void -ivi::settings::service::connect(response_callback response) +ivi::settings::service::handle_request(char const * name, + JsonReader * reader, + response_callback & response) +{ + if (name != nullptr) { + if (strcmp(name, "connect") == 0) + connect(reader, response); + else if (strcmp(name, "disconnect") == 0) + disconnect(reader, response); + else { + response.send_error( + std::string("Unrecognized connman service request name: ") + + name); + } + } +} + +void +ivi::settings::service::connect(JsonReader * /* reader */, + response_callback response) { call_method("Connect", response); } void -ivi::settings::service::disconnect(response_callback response) +ivi::settings::service::disconnect(JsonReader * reader, + response_callback response) { + bool null = false; + // The value is the second array element. + if (json_reader_read_element(reader, 1)) { + null = json_reader_get_null_value(reader); + } + json_reader_end_element(reader); + + if (!null) { + response.send_error( + "connman::service::disconnect parameter is not null."); + return; + } + call_method("Disconnect", response); } diff --git a/plugins/connman/service.hpp b/plugins/connman/service.hpp index 3f75e2a..56c9b62 100644 --- a/plugins/connman/service.hpp +++ b/plugins/connman/service.hpp @@ -62,13 +62,29 @@ namespace ivi GDBusConnection * connection, event_callback const & e); + /** + * Handle connman Service object request. + * + * @param[in] name The Connman Service method name. + * @param[in] reader @c JsonReader object containing desired + * values. The value will be in the second + * array element. + * @param[in] response Callback through which results will be + * sent. + */ + void handle_request(char const * name, + JsonReader * reader, + response_callback & response); + + private: + /// Connect to the service. - void connect(response_callback response); + void connect(JsonReader * reader, + response_callback response); /// Disconnect from the service. - void disconnect(response_callback response); - - private: + void disconnect(JsonReader * reader, + response_callback response); /** * Call the method @a name on the connman Service object. |