summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Orlenko <zxteam@gmail.com>2010-07-13 11:00:04 +1100
committerAlexander Orlenko <zxteam@gmail.com>2010-07-13 11:00:04 +1100
commite01e7c9a76997de7cfcf5d5eda325cb1a9b8a2b2 (patch)
tree98cfa85761ca911472852bef101f10fe10a8fa00 /src
parent024e778b2cae61d9b72223d2363666a037eec92d (diff)
downloadbluez-tools-e01e7c9a76997de7cfcf5d5eda325cb1a9b8a2b2.tar.gz
Forked bluez-api 4.66 doc and fixed some typo
Removed on-fly patches in generator script Added Network Hub/Peer/Router interfaces
Diffstat (limited to 'src')
-rw-r--r--src/lib/hub.c289
-rw-r--r--src/lib/hub.h71
-rw-r--r--src/lib/peer.c289
-rw-r--r--src/lib/peer.h71
-rw-r--r--src/lib/router.c289
-rw-r--r--src/lib/router.h71
6 files changed, 1080 insertions, 0 deletions
diff --git a/src/lib/hub.c b/src/lib/hub.c
new file mode 100644
index 0000000..361ceaf
--- /dev/null
+++ b/src/lib/hub.c
@@ -0,0 +1,289 @@
+/*
+ *
+ * bluez-tools - a set of tools to manage bluetooth devices for linux
+ *
+ * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "dbus-common.h"
+#include "marshallers.h"
+#include "hub.h"
+
+#define BLUEZ_DBUS_HUB_INTERFACE "org.bluez.network.Hub"
+
+#define HUB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), HUB_TYPE, HubPrivate))
+
+struct _HubPrivate {
+ DBusGProxy *dbus_g_proxy;
+
+ /* Properties */
+ gboolean enable;
+ gchar *name;
+ gchar *uuid;
+};
+
+G_DEFINE_TYPE(Hub, hub, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+
+ PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
+ PROP_ENABLE, /* readwrite */
+ PROP_NAME, /* readwrite */
+ PROP_UUID /* readonly */
+};
+
+static void _hub_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _hub_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void hub_dispose(GObject *gobject)
+{
+ Hub *self = HUB(gobject);
+
+ /* Properties free */
+ g_free(self->priv->name);
+ g_free(self->priv->uuid);
+
+ /* Proxy free */
+ g_object_unref(self->priv->dbus_g_proxy);
+
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(hub_parent_class)->dispose(gobject);
+}
+
+static void hub_class_init(HubClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = hub_dispose;
+
+ g_type_class_add_private(klass, sizeof(HubPrivate));
+
+ /* Properties registration */
+ GParamSpec *pspec;
+
+ gobject_class->get_property = _hub_get_property;
+ gobject_class->set_property = _hub_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+
+ /* boolean Enable [readwrite] */
+ pspec = g_param_spec_boolean("Enable", NULL, NULL, FALSE, G_PARAM_READWRITE);
+ g_object_class_install_property(gobject_class, PROP_ENABLE, pspec);
+
+ /* string Name [readwrite] */
+ pspec = g_param_spec_string("Name", NULL, NULL, NULL, G_PARAM_READWRITE);
+ g_object_class_install_property(gobject_class, PROP_NAME, pspec);
+
+ /* string UUID [readonly] */
+ pspec = g_param_spec_string("UUID", NULL, NULL, NULL, G_PARAM_READABLE);
+ g_object_class_install_property(gobject_class, PROP_UUID, pspec);
+}
+
+static void hub_init(Hub *self)
+{
+ self->priv = HUB_GET_PRIVATE(self);
+
+ g_assert(conn != NULL);
+}
+
+static void hub_post_init(Hub *self)
+{
+ g_assert(self->priv->dbus_g_proxy != NULL);
+
+ /* Properties init */
+ GError *error = NULL;
+ GHashTable *properties = hub_get_properties(self, &error);
+ g_assert(error == NULL);
+ g_assert(properties != NULL);
+
+ /* boolean Enable [readwrite] */
+ if (g_hash_table_lookup(properties, "Enable")) {
+ self->priv->enable = g_value_get_boolean(g_hash_table_lookup(properties, "Enable"));
+ } else {
+ self->priv->enable = FALSE;
+ }
+
+ /* string Name [readwrite] */
+ if (g_hash_table_lookup(properties, "Name")) {
+ self->priv->name = g_value_dup_string(g_hash_table_lookup(properties, "Name"));
+ } else {
+ self->priv->name = g_strdup("undefined");
+ }
+
+ /* string UUID [readonly] */
+ if (g_hash_table_lookup(properties, "UUID")) {
+ self->priv->uuid = g_value_dup_string(g_hash_table_lookup(properties, "UUID"));
+ } else {
+ self->priv->uuid = g_strdup("undefined");
+ }
+
+ g_hash_table_unref(properties);
+}
+
+static void _hub_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ Hub *self = HUB(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, hub_get_dbus_object_path(self));
+ break;
+
+ case PROP_ENABLE:
+ g_value_set_boolean(value, hub_get_enable(self));
+ break;
+
+ case PROP_NAME:
+ g_value_set_string(value, hub_get_name(self));
+ break;
+
+ case PROP_UUID:
+ g_value_set_string(value, hub_get_uuid(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _hub_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ Hub *self = HUB(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ {
+ const gchar *dbus_object_path = g_value_get_string(value);
+ g_assert(dbus_object_path != NULL);
+ g_assert(self->priv->dbus_g_proxy == NULL);
+ self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(conn, BLUEZ_DBUS_NAME, dbus_object_path, BLUEZ_DBUS_HUB_INTERFACE);
+ hub_post_init(self);
+ }
+ break;
+
+ case PROP_ENABLE:
+ {
+ GError *error = NULL;
+ hub_set_property(self, "Enable", value, &error);
+ g_assert(error == NULL);
+ }
+ break;
+
+ case PROP_NAME:
+ {
+ GError *error = NULL;
+ hub_set_property(self, "Name", value, &error);
+ g_assert(error == NULL);
+ }
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+/* Methods */
+
+/* dict GetProperties() */
+GHashTable *hub_get_properties(Hub *self, GError **error)
+{
+ g_assert(HUB_IS(self));
+
+ GHashTable *ret = NULL;
+ dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetProperties", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &ret, G_TYPE_INVALID);
+
+ return ret;
+}
+
+/* void SetProperty(string name, variant value) */
+void hub_set_property(Hub *self, const gchar *name, const GValue *value, GError **error)
+{
+ g_assert(HUB_IS(self));
+
+ dbus_g_proxy_call(self->priv->dbus_g_proxy, "SetProperty", error, G_TYPE_STRING, name, G_TYPE_VALUE, value, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+/* Properties access methods */
+const gchar *hub_get_dbus_object_path(Hub *self)
+{
+ g_assert(HUB_IS(self));
+
+ return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
+}
+
+const gboolean hub_get_enable(Hub *self)
+{
+ g_assert(HUB_IS(self));
+
+ return self->priv->enable;
+}
+
+void hub_set_enable(Hub *self, const gboolean value)
+{
+ g_assert(HUB_IS(self));
+
+ GError *error = NULL;
+
+ GValue t = {0};
+ g_value_init(&t, G_TYPE_BOOLEAN);
+ g_value_set_boolean(&t, value);
+ hub_set_property(self, "Enable", &t, &error);
+ g_value_unset(&t);
+
+ g_assert(error == NULL);
+}
+
+const gchar *hub_get_name(Hub *self)
+{
+ g_assert(HUB_IS(self));
+
+ return self->priv->name;
+}
+
+void hub_set_name(Hub *self, const gchar *value)
+{
+ g_assert(HUB_IS(self));
+
+ GError *error = NULL;
+
+ GValue t = {0};
+ g_value_init(&t, G_TYPE_STRING);
+ g_value_set_string(&t, value);
+ hub_set_property(self, "Name", &t, &error);
+ g_value_unset(&t);
+
+ g_assert(error == NULL);
+}
+
+const gchar *hub_get_uuid(Hub *self)
+{
+ g_assert(HUB_IS(self));
+
+ return self->priv->uuid;
+}
+
diff --git a/src/lib/hub.h b/src/lib/hub.h
new file mode 100644
index 0000000..a6e6a1f
--- /dev/null
+++ b/src/lib/hub.h
@@ -0,0 +1,71 @@
+/*
+ *
+ * bluez-tools - a set of tools to manage bluetooth devices for linux
+ *
+ * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __HUB_H
+#define __HUB_H
+
+#include <glib-object.h>
+
+/*
+ * Type macros
+ */
+#define HUB_TYPE (hub_get_type())
+#define HUB(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), HUB_TYPE, Hub))
+#define HUB_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), HUB_TYPE))
+#define HUB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), HUB_TYPE, HubClass))
+#define HUB_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), HUB_TYPE))
+#define HUB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), HUB_TYPE, HubClass))
+
+typedef struct _Hub Hub;
+typedef struct _HubClass HubClass;
+typedef struct _HubPrivate HubPrivate;
+
+struct _Hub {
+ GObject parent_instance;
+
+ /*< private >*/
+ HubPrivate *priv;
+};
+
+struct _HubClass {
+ GObjectClass parent_class;
+};
+
+/* used by HUB_TYPE */
+GType hub_get_type(void) G_GNUC_CONST;
+
+/*
+ * Method definitions
+ */
+GHashTable *hub_get_properties(Hub *self, GError **error);
+void hub_set_property(Hub *self, const gchar *name, const GValue *value, GError **error);
+
+const gchar *hub_get_dbus_object_path(Hub *self);
+const gboolean hub_get_enable(Hub *self);
+void hub_set_enable(Hub *self, const gboolean value);
+const gchar *hub_get_name(Hub *self);
+void hub_set_name(Hub *self, const gchar *value);
+const gchar *hub_get_uuid(Hub *self);
+
+#endif /* __HUB_H */
+
diff --git a/src/lib/peer.c b/src/lib/peer.c
new file mode 100644
index 0000000..2d1b787
--- /dev/null
+++ b/src/lib/peer.c
@@ -0,0 +1,289 @@
+/*
+ *
+ * bluez-tools - a set of tools to manage bluetooth devices for linux
+ *
+ * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "dbus-common.h"
+#include "marshallers.h"
+#include "peer.h"
+
+#define BLUEZ_DBUS_PEER_INTERFACE "org.bluez.network.Peer"
+
+#define PEER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PEER_TYPE, PeerPrivate))
+
+struct _PeerPrivate {
+ DBusGProxy *dbus_g_proxy;
+
+ /* Properties */
+ gboolean enable;
+ gchar *name;
+ gchar *uuid;
+};
+
+G_DEFINE_TYPE(Peer, peer, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+
+ PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
+ PROP_ENABLE, /* readwrite */
+ PROP_NAME, /* readwrite */
+ PROP_UUID /* readonly */
+};
+
+static void _peer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _peer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void peer_dispose(GObject *gobject)
+{
+ Peer *self = PEER(gobject);
+
+ /* Properties free */
+ g_free(self->priv->name);
+ g_free(self->priv->uuid);
+
+ /* Proxy free */
+ g_object_unref(self->priv->dbus_g_proxy);
+
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(peer_parent_class)->dispose(gobject);
+}
+
+static void peer_class_init(PeerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = peer_dispose;
+
+ g_type_class_add_private(klass, sizeof(PeerPrivate));
+
+ /* Properties registration */
+ GParamSpec *pspec;
+
+ gobject_class->get_property = _peer_get_property;
+ gobject_class->set_property = _peer_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+
+ /* boolean Enable [readwrite] */
+ pspec = g_param_spec_boolean("Enable", NULL, NULL, FALSE, G_PARAM_READWRITE);
+ g_object_class_install_property(gobject_class, PROP_ENABLE, pspec);
+
+ /* string Name [readwrite] */
+ pspec = g_param_spec_string("Name", NULL, NULL, NULL, G_PARAM_READWRITE);
+ g_object_class_install_property(gobject_class, PROP_NAME, pspec);
+
+ /* string UUID [readonly] */
+ pspec = g_param_spec_string("UUID", NULL, NULL, NULL, G_PARAM_READABLE);
+ g_object_class_install_property(gobject_class, PROP_UUID, pspec);
+}
+
+static void peer_init(Peer *self)
+{
+ self->priv = PEER_GET_PRIVATE(self);
+
+ g_assert(conn != NULL);
+}
+
+static void peer_post_init(Peer *self)
+{
+ g_assert(self->priv->dbus_g_proxy != NULL);
+
+ /* Properties init */
+ GError *error = NULL;
+ GHashTable *properties = peer_get_properties(self, &error);
+ g_assert(error == NULL);
+ g_assert(properties != NULL);
+
+ /* boolean Enable [readwrite] */
+ if (g_hash_table_lookup(properties, "Enable")) {
+ self->priv->enable = g_value_get_boolean(g_hash_table_lookup(properties, "Enable"));
+ } else {
+ self->priv->enable = FALSE;
+ }
+
+ /* string Name [readwrite] */
+ if (g_hash_table_lookup(properties, "Name")) {
+ self->priv->name = g_value_dup_string(g_hash_table_lookup(properties, "Name"));
+ } else {
+ self->priv->name = g_strdup("undefined");
+ }
+
+ /* string UUID [readonly] */
+ if (g_hash_table_lookup(properties, "UUID")) {
+ self->priv->uuid = g_value_dup_string(g_hash_table_lookup(properties, "UUID"));
+ } else {
+ self->priv->uuid = g_strdup("undefined");
+ }
+
+ g_hash_table_unref(properties);
+}
+
+static void _peer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ Peer *self = PEER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, peer_get_dbus_object_path(self));
+ break;
+
+ case PROP_ENABLE:
+ g_value_set_boolean(value, peer_get_enable(self));
+ break;
+
+ case PROP_NAME:
+ g_value_set_string(value, peer_get_name(self));
+ break;
+
+ case PROP_UUID:
+ g_value_set_string(value, peer_get_uuid(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _peer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ Peer *self = PEER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ {
+ const gchar *dbus_object_path = g_value_get_string(value);
+ g_assert(dbus_object_path != NULL);
+ g_assert(self->priv->dbus_g_proxy == NULL);
+ self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(conn, BLUEZ_DBUS_NAME, dbus_object_path, BLUEZ_DBUS_PEER_INTERFACE);
+ peer_post_init(self);
+ }
+ break;
+
+ case PROP_ENABLE:
+ {
+ GError *error = NULL;
+ peer_set_property(self, "Enable", value, &error);
+ g_assert(error == NULL);
+ }
+ break;
+
+ case PROP_NAME:
+ {
+ GError *error = NULL;
+ peer_set_property(self, "Name", value, &error);
+ g_assert(error == NULL);
+ }
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+/* Methods */
+
+/* dict GetProperties() */
+GHashTable *peer_get_properties(Peer *self, GError **error)
+{
+ g_assert(PEER_IS(self));
+
+ GHashTable *ret = NULL;
+ dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetProperties", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &ret, G_TYPE_INVALID);
+
+ return ret;
+}
+
+/* void SetProperty(string name, variant value) */
+void peer_set_property(Peer *self, const gchar *name, const GValue *value, GError **error)
+{
+ g_assert(PEER_IS(self));
+
+ dbus_g_proxy_call(self->priv->dbus_g_proxy, "SetProperty", error, G_TYPE_STRING, name, G_TYPE_VALUE, value, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+/* Properties access methods */
+const gchar *peer_get_dbus_object_path(Peer *self)
+{
+ g_assert(PEER_IS(self));
+
+ return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
+}
+
+const gboolean peer_get_enable(Peer *self)
+{
+ g_assert(PEER_IS(self));
+
+ return self->priv->enable;
+}
+
+void peer_set_enable(Peer *self, const gboolean value)
+{
+ g_assert(PEER_IS(self));
+
+ GError *error = NULL;
+
+ GValue t = {0};
+ g_value_init(&t, G_TYPE_BOOLEAN);
+ g_value_set_boolean(&t, value);
+ peer_set_property(self, "Enable", &t, &error);
+ g_value_unset(&t);
+
+ g_assert(error == NULL);
+}
+
+const gchar *peer_get_name(Peer *self)
+{
+ g_assert(PEER_IS(self));
+
+ return self->priv->name;
+}
+
+void peer_set_name(Peer *self, const gchar *value)
+{
+ g_assert(PEER_IS(self));
+
+ GError *error = NULL;
+
+ GValue t = {0};
+ g_value_init(&t, G_TYPE_STRING);
+ g_value_set_string(&t, value);
+ peer_set_property(self, "Name", &t, &error);
+ g_value_unset(&t);
+
+ g_assert(error == NULL);
+}
+
+const gchar *peer_get_uuid(Peer *self)
+{
+ g_assert(PEER_IS(self));
+
+ return self->priv->uuid;
+}
+
diff --git a/src/lib/peer.h b/src/lib/peer.h
new file mode 100644
index 0000000..30f58df
--- /dev/null
+++ b/src/lib/peer.h
@@ -0,0 +1,71 @@
+/*
+ *
+ * bluez-tools - a set of tools to manage bluetooth devices for linux
+ *
+ * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __PEER_H
+#define __PEER_H
+
+#include <glib-object.h>
+
+/*
+ * Type macros
+ */
+#define PEER_TYPE (peer_get_type())
+#define PEER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PEER_TYPE, Peer))
+#define PEER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PEER_TYPE))
+#define PEER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PEER_TYPE, PeerClass))
+#define PEER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PEER_TYPE))
+#define PEER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PEER_TYPE, PeerClass))
+
+typedef struct _Peer Peer;
+typedef struct _PeerClass PeerClass;
+typedef struct _PeerPrivate PeerPrivate;
+
+struct _Peer {
+ GObject parent_instance;
+
+ /*< private >*/
+ PeerPrivate *priv;
+};
+
+struct _PeerClass {
+ GObjectClass parent_class;
+};
+
+/* used by PEER_TYPE */
+GType peer_get_type(void) G_GNUC_CONST;
+
+/*
+ * Method definitions
+ */
+GHashTable *peer_get_properties(Peer *self, GError **error);
+void peer_set_property(Peer *self, const gchar *name, const GValue *value, GError **error);
+
+const gchar *peer_get_dbus_object_path(Peer *self);
+const gboolean peer_get_enable(Peer *self);
+void peer_set_enable(Peer *self, const gboolean value);
+const gchar *peer_get_name(Peer *self);
+void peer_set_name(Peer *self, const gchar *value);
+const gchar *peer_get_uuid(Peer *self);
+
+#endif /* __PEER_H */
+
diff --git a/src/lib/router.c b/src/lib/router.c
new file mode 100644
index 0000000..883efa5
--- /dev/null
+++ b/src/lib/router.c
@@ -0,0 +1,289 @@
+/*
+ *
+ * bluez-tools - a set of tools to manage bluetooth devices for linux
+ *
+ * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "dbus-common.h"
+#include "marshallers.h"
+#include "router.h"
+
+#define BLUEZ_DBUS_ROUTER_INTERFACE "org.bluez.network.Router"
+
+#define ROUTER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), ROUTER_TYPE, RouterPrivate))
+
+struct _RouterPrivate {
+ DBusGProxy *dbus_g_proxy;
+
+ /* Properties */
+ gboolean enable;
+ gchar *name;
+ gchar *uuid;
+};
+
+G_DEFINE_TYPE(Router, router, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+
+ PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
+ PROP_ENABLE, /* readwrite */
+ PROP_NAME, /* readwrite */
+ PROP_UUID /* readonly */
+};
+
+static void _router_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _router_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void router_dispose(GObject *gobject)
+{
+ Router *self = ROUTER(gobject);
+
+ /* Properties free */
+ g_free(self->priv->name);
+ g_free(self->priv->uuid);
+
+ /* Proxy free */
+ g_object_unref(self->priv->dbus_g_proxy);
+
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(router_parent_class)->dispose(gobject);
+}
+
+static void router_class_init(RouterClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = router_dispose;
+
+ g_type_class_add_private(klass, sizeof(RouterPrivate));
+
+ /* Properties registration */
+ GParamSpec *pspec;
+
+ gobject_class->get_property = _router_get_property;
+ gobject_class->set_property = _router_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+
+ /* boolean Enable [readwrite] */
+ pspec = g_param_spec_boolean("Enable", NULL, NULL, FALSE, G_PARAM_READWRITE);
+ g_object_class_install_property(gobject_class, PROP_ENABLE, pspec);
+
+ /* string Name [readwrite] */
+ pspec = g_param_spec_string("Name", NULL, NULL, NULL, G_PARAM_READWRITE);
+ g_object_class_install_property(gobject_class, PROP_NAME, pspec);
+
+ /* string UUID [readonly] */
+ pspec = g_param_spec_string("UUID", NULL, NULL, NULL, G_PARAM_READABLE);
+ g_object_class_install_property(gobject_class, PROP_UUID, pspec);
+}
+
+static void router_init(Router *self)
+{
+ self->priv = ROUTER_GET_PRIVATE(self);
+
+ g_assert(conn != NULL);
+}
+
+static void router_post_init(Router *self)
+{
+ g_assert(self->priv->dbus_g_proxy != NULL);
+
+ /* Properties init */
+ GError *error = NULL;
+ GHashTable *properties = router_get_properties(self, &error);
+ g_assert(error == NULL);
+ g_assert(properties != NULL);
+
+ /* boolean Enable [readwrite] */
+ if (g_hash_table_lookup(properties, "Enable")) {
+ self->priv->enable = g_value_get_boolean(g_hash_table_lookup(properties, "Enable"));
+ } else {
+ self->priv->enable = FALSE;
+ }
+
+ /* string Name [readwrite] */
+ if (g_hash_table_lookup(properties, "Name")) {
+ self->priv->name = g_value_dup_string(g_hash_table_lookup(properties, "Name"));
+ } else {
+ self->priv->name = g_strdup("undefined");
+ }
+
+ /* string UUID [readonly] */
+ if (g_hash_table_lookup(properties, "UUID")) {
+ self->priv->uuid = g_value_dup_string(g_hash_table_lookup(properties, "UUID"));
+ } else {
+ self->priv->uuid = g_strdup("undefined");
+ }
+
+ g_hash_table_unref(properties);
+}
+
+static void _router_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ Router *self = ROUTER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, router_get_dbus_object_path(self));
+ break;
+
+ case PROP_ENABLE:
+ g_value_set_boolean(value, router_get_enable(self));
+ break;
+
+ case PROP_NAME:
+ g_value_set_string(value, router_get_name(self));
+ break;
+
+ case PROP_UUID:
+ g_value_set_string(value, router_get_uuid(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _router_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ Router *self = ROUTER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ {
+ const gchar *dbus_object_path = g_value_get_string(value);
+ g_assert(dbus_object_path != NULL);
+ g_assert(self->priv->dbus_g_proxy == NULL);
+ self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(conn, BLUEZ_DBUS_NAME, dbus_object_path, BLUEZ_DBUS_ROUTER_INTERFACE);
+ router_post_init(self);
+ }
+ break;
+
+ case PROP_ENABLE:
+ {
+ GError *error = NULL;
+ router_set_property(self, "Enable", value, &error);
+ g_assert(error == NULL);
+ }
+ break;
+
+ case PROP_NAME:
+ {
+ GError *error = NULL;
+ router_set_property(self, "Name", value, &error);
+ g_assert(error == NULL);
+ }
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+/* Methods */
+
+/* dict GetProperties() */
+GHashTable *router_get_properties(Router *self, GError **error)
+{
+ g_assert(ROUTER_IS(self));
+
+ GHashTable *ret = NULL;
+ dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetProperties", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &ret, G_TYPE_INVALID);
+
+ return ret;
+}
+
+/* void SetProperty(string name, variant value) */
+void router_set_property(Router *self, const gchar *name, const GValue *value, GError **error)
+{
+ g_assert(ROUTER_IS(self));
+
+ dbus_g_proxy_call(self->priv->dbus_g_proxy, "SetProperty", error, G_TYPE_STRING, name, G_TYPE_VALUE, value, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+/* Properties access methods */
+const gchar *router_get_dbus_object_path(Router *self)
+{
+ g_assert(ROUTER_IS(self));
+
+ return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
+}
+
+const gboolean router_get_enable(Router *self)
+{
+ g_assert(ROUTER_IS(self));
+
+ return self->priv->enable;
+}
+
+void router_set_enable(Router *self, const gboolean value)
+{
+ g_assert(ROUTER_IS(self));
+
+ GError *error = NULL;
+
+ GValue t = {0};
+ g_value_init(&t, G_TYPE_BOOLEAN);
+ g_value_set_boolean(&t, value);
+ router_set_property(self, "Enable", &t, &error);
+ g_value_unset(&t);
+
+ g_assert(error == NULL);
+}
+
+const gchar *router_get_name(Router *self)
+{
+ g_assert(ROUTER_IS(self));
+
+ return self->priv->name;
+}
+
+void router_set_name(Router *self, const gchar *value)
+{
+ g_assert(ROUTER_IS(self));
+
+ GError *error = NULL;
+
+ GValue t = {0};
+ g_value_init(&t, G_TYPE_STRING);
+ g_value_set_string(&t, value);
+ router_set_property(self, "Name", &t, &error);
+ g_value_unset(&t);
+
+ g_assert(error == NULL);
+}
+
+const gchar *router_get_uuid(Router *self)
+{
+ g_assert(ROUTER_IS(self));
+
+ return self->priv->uuid;
+}
+
diff --git a/src/lib/router.h b/src/lib/router.h
new file mode 100644
index 0000000..a082695
--- /dev/null
+++ b/src/lib/router.h
@@ -0,0 +1,71 @@
+/*
+ *
+ * bluez-tools - a set of tools to manage bluetooth devices for linux
+ *
+ * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __ROUTER_H
+#define __ROUTER_H
+
+#include <glib-object.h>
+
+/*
+ * Type macros
+ */
+#define ROUTER_TYPE (router_get_type())
+#define ROUTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), ROUTER_TYPE, Router))
+#define ROUTER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), ROUTER_TYPE))
+#define ROUTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), ROUTER_TYPE, RouterClass))
+#define ROUTER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), ROUTER_TYPE))
+#define ROUTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), ROUTER_TYPE, RouterClass))
+
+typedef struct _Router Router;
+typedef struct _RouterClass RouterClass;
+typedef struct _RouterPrivate RouterPrivate;
+
+struct _Router {
+ GObject parent_instance;
+
+ /*< private >*/
+ RouterPrivate *priv;
+};
+
+struct _RouterClass {
+ GObjectClass parent_class;
+};
+
+/* used by ROUTER_TYPE */
+GType router_get_type(void) G_GNUC_CONST;
+
+/*
+ * Method definitions
+ */
+GHashTable *router_get_properties(Router *self, GError **error);
+void router_set_property(Router *self, const gchar *name, const GValue *value, GError **error);
+
+const gchar *router_get_dbus_object_path(Router *self);
+const gboolean router_get_enable(Router *self);
+void router_set_enable(Router *self, const gboolean value);
+const gchar *router_get_name(Router *self);
+void router_set_name(Router *self, const gchar *value);
+const gchar *router_get_uuid(Router *self);
+
+#endif /* __ROUTER_H */
+