IVI_SETTINGS_PLUGIN_LIBRARY = $(top_builddir)/lib/libsettings.la
connman_la_SOURCES = \
+ dbus_connection.cpp \
connman.cpp \
connman_manager.cpp \
service.cpp \
noinst_HEADERS = \
config.h \
connman_api.hpp \
+ dbus_connection.hpp \
connman.hpp \
connman_manager.hpp \
service.hpp \
// ----------------------------------------------------------------------
-ivi::settings::bluetooth::bluetooth(connman_manager & manager,
+ivi::settings::bluetooth::bluetooth(GDBusConnection * connection,
+ connman_manager & manager,
event_callback const & e)
- : technology_(technology_name, manager, e)
+ : technology_(technology_name, connection, manager, e)
{
}
public:
/// Constructor.
- bluetooth(connman_manager & manager, event_callback const & e);
+ bluetooth(GDBusConnection * connection,
+ connman_manager & manager,
+ event_callback const & e);
/// Destructor.
virtual ~bluetooth();
#include <boost/lexical_cast.hpp>
-ivi::settings::clock::clock(event_callback const & e)
- : connman_("net.connman.Clock", "/", e)
+ivi::settings::clock::clock(GDBusConnection * connection,
+ event_callback const & e)
+ : connman_("net.connman.Clock", "/", connection, e)
{
}
public:
/// Constructor.
- clock(event_callback const & e);
+ clock(GDBusConnection * connection, event_callback const & e);
/// Destructor.
virtual ~clock();
ivi::settings::connman::connman(char const * interface,
char const * path,
+ GDBusConnection * connection,
event_callback const & e)
: proxy_(nullptr)
, event_callback_(e)
GError * error = nullptr;
proxy_ =
- g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- nullptr, // GDBusInterfaceInfo
- name,
- path,
- interface,
- nullptr, // GCancellable
- &error);
+ g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ nullptr, // GDBusInterfaceInfo
+ name,
+ path,
+ interface,
+ nullptr, // GCancellable
+ &error);
unique_ptr<GError> safe_error(error);
// Listen for changes to properties.
subscription_id_ =
g_dbus_connection_signal_subscribe(
- g_dbus_proxy_get_connection(G_DBUS_PROXY(proxy_)),
+ connection,
nullptr,
interface,
"PropertyChanged",
/**
* Constructor.
*
- * @param[in] interface Connman D-Bus interface.
- * @param[in] path Connman D-Bus object path.
+ * @param[in] interface Connman D-Bus interface.
+ * @param[in] path Connman D-Bus object path.
+ * @param[in] connection Underlying D-Bus connection.
+ * @param[in] e Callback through which events will be
+ * sent to clients.
*/
connman(char const * interface,
char const * path,
+ GDBusConnection * connection,
event_callback const & e);
/// Destructor.
/// Get pointer to underlying GDBusProxy.
GDBusProxy * proxy() const { return proxy_; }
+ /// Get pointer to underlying GDBusConnection.
+ GDBusConnection *
+ connection() const
+ {
+ return g_dbus_proxy_get_connection(G_DBUS_PROXY(proxy_));
+ }
+
/// Convenience function to get D-Bus interface name.
char const *
interface_name() const
*/
#include "connman_manager.hpp"
+#include "dbus_connection.hpp"
#include <settingsd/dbus_signal_callback.hpp>
#include <settingsd/glib_traits.hpp>
ivi::settings::connman_manager::connman_manager(
+ GDBusConnection * connection,
event_callback const & e)
: connman_("net.connman.Manager", // Interface
"/", // Object path
+ connection,
e)
, event_callback_(e)
, subscription_id_(
g_dbus_connection_signal_subscribe(
- g_dbus_proxy_get_connection(G_DBUS_PROXY(connman_.proxy())),
+ connection,
nullptr,
connman_.interface_name(),
"ServicesChanged",
ivi::settings::connman_manager::~connman_manager()
{
- g_dbus_connection_signal_unsubscribe(
- g_dbus_proxy_get_connection(G_DBUS_PROXY(connman_.proxy())),
- subscription_id_);
+ g_dbus_connection_signal_unsubscribe(connman_.connection(),
+ subscription_id_);
}
GVariant *
public:
/// Constructor.
- connman_manager(event_callback const & e);
+ connman_manager(GDBusConnection * connection,
+ event_callback const & e);
/// Destructor.
~connman_manager();
--- /dev/null
+/**
+ * @file dbus_connection.cpp
+ *
+ * @brief Settings daemon D-Bus connection adapter.
+ *
+ * @author Michael Leibowitz @<michael.leibowitz@@intel.com@>
+ * @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 "dbus_connection.hpp"
+
+#include <settingsd/glib_traits.hpp>
+#include <settingsd/unique_ptr.hpp>
+
+#include <stdexcept>
+
+
+ivi::settings::dbus_connection::dbus_connection()
+ : connection_(nullptr)
+{
+ GError * error = nullptr;
+
+ connection_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
+
+ if (connection_ == nullptr) {
+ unique_ptr<GError> safe_error(error);
+ throw std::runtime_error(error->message);
+ }
+}
+
+ivi::settings::dbus_connection::~dbus_connection()
+{
+ GError * error = nullptr;
+
+ if (connection_ != nullptr
+ && !g_dbus_connection_close_sync(connection_,
+ nullptr,
+ &error)) {
+ g_critical("D-Bus connection close failed: %s.\n",
+ error->message);
+ g_error_free(error);
+ }
+}
+
+
+// Local Variables:
+// mode:c++
+// c-basic-offset:2
+// indent-tabs-mode: nil
+// End:
--- /dev/null
+/**
+ * @file dbus_connection.hpp
+ *
+ * @brief D-Bus connecton adapter 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; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * @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
+ *
+ * @note This is an internal header.
+ */
+
+#ifndef IVI_SETTINGS_DBUS_CONNECTION_HPP
+#define IVI_SETTINGS_DBUS_CONNECTION_HPP
+
+#include <gio/gio.h>
+
+
+namespace ivi
+{
+ namespace settings
+ {
+ class dbus_connection
+ {
+ public:
+
+ /// Constructor.
+ dbus_connection();
+
+ /// Destructor.
+ ~dbus_connection();
+
+ /// Get pointer to underlying D-Bus connection
+ GDBusConnection *
+ connection()
+ {
+ return connection_;
+ }
+
+ private:
+
+ /**
+ * @name Prevent copying
+ */
+ //@{
+ dbus_connection(dbus_connection const &) = delete;
+ dbus_connection & operator=(dbus_connection const &) = delete;
+ //@}
+
+ private:
+
+ /// Underlying connection to D-Bus system bus.
+ GDBusConnection * connection_;
+
+ };
+ }
+}
+
+#endif /* IVI_SETTINGS_DBUS_CONNECTION_HPP */
+
+
+// Local Variables:
+// mode:c++
+// c-basic-offset:2
+// indent-tabs-mode: nil
+// End:
// ----------------------------------------------------------------------
-ivi::settings::ethernet::ethernet(connman_manager & manager,
+ivi::settings::ethernet::ethernet(GDBusConnection * connection,
+ connman_manager & manager,
event_callback const & e)
- : technology_(technology_name, manager, e)
+ : technology_(technology_name, connection, manager, e)
{
}
public:
/// Constructor.
- ethernet(connman_manager & manager, event_callback const & e);
+ ethernet(GDBusConnection * connection,
+ connman_manager & manager,
+ event_callback const & e);
/// Destructor.
virtual ~ethernet();
*/
#include "connman_api.hpp"
+#include "dbus_connection.hpp"
#include "connman_manager.hpp"
#include "bluetooth.hpp"
#include "clock.hpp"
register_settings(ivi::settings::registrar & r,
ivi::settings::event_callback const & e)
{
+ // Only one connection to the D-Bus system bus is needed. All
+ // connman based settings plugins will share it.
+ static ivi::settings::dbus_connection con;
+ GDBusConnection * const connection = con.connection();
+
// Only one instance of connman_manager is needed since the
// corresponding connman Manager is really a global object.
- static ivi::settings::connman_manager manager(e);
+ static ivi::settings::connman_manager manager(connection, e);
std::unique_ptr<ivi::settings::plugin> bt(
- new ivi::settings::bluetooth(manager, e));
+ new ivi::settings::bluetooth(connection, manager, e));
std::unique_ptr<ivi::settings::plugin> eth(
- new ivi::settings::ethernet(manager, e));
+ new ivi::settings::ethernet(connection, manager, e));
std::unique_ptr<ivi::settings::plugin> wifi(
- new ivi::settings::wifi(manager, e));
+ new ivi::settings::wifi(connection, manager, e));
std::unique_ptr<ivi::settings::plugin> clk(
- new ivi::settings::clock(e));
+ new ivi::settings::clock(connection, e));
return
r.register_setting(std::move(bt))
ivi::settings::service::service(std::string service_path,
+ GDBusConnection * connection,
event_callback const & e)
: connman_("net.connman.Service", // Interface
service_path.c_str(), // Object path
+ connection,
e)
{
}
*
* @param[in] service_path The D-Bus object path for connman
* service.
+ * @param[in] connection Underlying D-Bus connection.
* @param[in] e Callback through which events will be
* sent to clients.
*/
service(std::string service_path,
+ GDBusConnection * connection,
event_callback const & e);
/// Connect to the service.
ivi::settings::technology::technology(std::string tech,
+ GDBusConnection * connection,
connman_manager & manager,
event_callback const & e)
: connman_("net.connman.Technology", // Interface
("/net/connman/technology/"
+ tech).c_str(), // Object path
+ connection,
e)
, manager_(manager)
, technology_(tech)
/// @todo Refactor malformed JSON request handling code.
if (service_path != nullptr) {
- service s(service_path, event_callback_);
+ service s(service_path,
+ connman_.connection(),
+ event_callback_);
s.connect(response);
} else {
response.send_error(
json_reader_end_member(reader);
if (service_path != nullptr) {
- service s(service_path, event_callback_);
+ service s(service_path,
+ connman_.connection(),
+ event_callback_);
s.disconnect(response);
} else {
response.send_error(
/**
* Constructor.
*
- * @param[in] tech The connman technology, e.g. "bluetooth".
- * @param[in] e Callback through which events will be sent to
- * clients.
+ * @param[in] tech The connman technology,
+ * e.g. "bluetooth".
+ * @param[in] connection Underlying D-Bus connection.
+ * @param[in] manager Connman manager proxy.
+ * @param[in] e Callback through which events will be
+ * sent to clients.
*/
technology(std::string tech,
+ GDBusConnection * connection,
connman_manager & manager,
event_callback const & e);
// ----------------------------------------------------------------------
-ivi::settings::wifi::wifi(connman_manager & manager,
+ivi::settings::wifi::wifi(GDBusConnection * connection,
+ connman_manager & manager,
event_callback const & e)
- : technology_(technology_name, manager, e)
+ : technology_(technology_name, connection, manager, e)
{
}
public:
/// Constructor.
- wifi(connman_manager & manager, event_callback const & e);
+ wifi(GDBusConnection * connection,
+ connman_manager & manager,
+ event_callback const & e);
/// Destructor.
virtual ~wifi();