summaryrefslogtreecommitdiff
path: root/src/lib/adapter.c
diff options
context:
space:
mode:
authorAlexander Orlenko <zxteam@gmail.com>2010-07-13 20:52:33 +1100
committerAlexander Orlenko <zxteam@gmail.com>2010-07-13 20:52:33 +1100
commit499a706c529a9e821cb7dcb54f63dfa50117ba39 (patch)
tree2f447807ec77d5f969061c24665487bd843d5b97 /src/lib/adapter.c
parentc0da8ea7173fcdd5b5abd0a6c1430850f6fc69f6 (diff)
downloadbluez-tools-499a706c529a9e821cb7dcb54f63dfa50117ba39.tar.gz
Added getting of dbus introspection data xml to check interface existence
Diffstat (limited to 'src/lib/adapter.c')
-rw-r--r--src/lib/adapter.c94
1 files changed, 60 insertions, 34 deletions
diff --git a/src/lib/adapter.c b/src/lib/adapter.c
index 7cbd4af..228ce81 100644
--- a/src/lib/adapter.c
+++ b/src/lib/adapter.c
@@ -25,6 +25,8 @@
#include <config.h>
#endif
+#include <string.h>
+
#include "dbus-common.h"
#include "marshallers.h"
#include "adapter.h"
@@ -36,6 +38,10 @@
struct _AdapterPrivate {
DBusGProxy *dbus_g_proxy;
+ /* Introspection data */
+ DBusGProxy *introspection_g_proxy;
+ gchar *introspection_xml;
+
/* Properties */
gchar *address;
guint32 class;
@@ -113,6 +119,10 @@ static void adapter_dispose(GObject *gobject)
/* Proxy free */
g_object_unref(self->priv->dbus_g_proxy);
+ /* Introspection data free */
+ g_free(self->priv->introspection_xml);
+ g_object_unref(self->priv->introspection_g_proxy);
+
/* Chain up to the parent class */
G_OBJECT_CLASS(adapter_parent_class)->dispose(gobject);
}
@@ -226,9 +236,29 @@ static void adapter_init(Adapter *self)
g_assert(conn != NULL);
}
-static void adapter_post_init(Adapter *self)
+static void adapter_post_init(Adapter *self, const gchar *dbus_object_path)
{
- g_assert(self->priv->dbus_g_proxy != NULL);
+ g_assert(dbus_object_path != NULL);
+ g_assert(strlen(dbus_object_path) > 0);
+ g_assert(self->priv->dbus_g_proxy == NULL);
+
+ GError *error = NULL;
+
+ /* Getting introspection XML */
+ self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, BLUEZ_DBUS_NAME, dbus_object_path, "org.freedesktop.DBus.Introspectable");
+ self->priv->introspection_xml = NULL;
+ if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) {
+ g_critical("%s", error->message);
+ }
+ g_assert(error == NULL);
+
+ gchar *test_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_ADAPTER_INTERFACE, "\">");
+ if (!g_regex_match_simple(test_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
+ g_critical("Interface \"%s\" does not exist in \"%s\"", BLUEZ_DBUS_ADAPTER_INTERFACE, dbus_object_path);
+ g_assert(FALSE);
+ }
+ g_free(test_intf_regex_str);
+ self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(conn, BLUEZ_DBUS_NAME, dbus_object_path, BLUEZ_DBUS_ADAPTER_INTERFACE);
/* DBus signals connection */
@@ -253,8 +283,10 @@ static void adapter_post_init(Adapter *self)
dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self, NULL);
/* Properties init */
- GError *error = NULL;
GHashTable *properties = adapter_get_properties(self, &error);
+ if (error != NULL) {
+ g_critical("%s", error->message);
+ }
g_assert(error == NULL);
g_assert(properties != NULL);
@@ -401,70 +433,46 @@ static void _adapter_get_property(GObject *object, guint property_id, GValue *va
static void _adapter_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
Adapter *self = ADAPTER(object);
+ GError *error = NULL;
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_ADAPTER_INTERFACE);
- adapter_post_init(self);
- }
+ adapter_post_init(self, g_value_get_string(value));
break;
case PROP_DISCOVERABLE:
- {
- GError *error = NULL;
adapter_set_property(self, "Discoverable", value, &error);
- g_assert(error == NULL);
- }
break;
case PROP_DISCOVERABLE_TIMEOUT:
- {
- GError *error = NULL;
adapter_set_property(self, "DiscoverableTimeout", value, &error);
- g_assert(error == NULL);
- }
break;
case PROP_NAME:
- {
- GError *error = NULL;
adapter_set_property(self, "Name", value, &error);
- g_assert(error == NULL);
- }
break;
case PROP_PAIRABLE:
- {
- GError *error = NULL;
adapter_set_property(self, "Pairable", value, &error);
- g_assert(error == NULL);
- }
break;
case PROP_PAIRABLE_TIMEOUT:
- {
- GError *error = NULL;
adapter_set_property(self, "PairableTimeout", value, &error);
- g_assert(error == NULL);
- }
break;
case PROP_POWERED:
- {
- GError *error = NULL;
adapter_set_property(self, "Powered", value, &error);
- g_assert(error == NULL);
- }
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
+
+ if (error != NULL) {
+ g_critical("%s", error->message);
+ }
+ g_assert(error == NULL);
}
static void adapter_async_notify_callback(DBusGProxy *proxy, DBusGProxyCall *call, gpointer data)
@@ -655,6 +663,9 @@ void adapter_set_discoverable(Adapter *self, const gboolean value)
adapter_set_property(self, "Discoverable", &t, &error);
g_value_unset(&t);
+ if (error != NULL) {
+ g_critical("%s", error->message);
+ }
g_assert(error == NULL);
}
@@ -677,6 +688,9 @@ void adapter_set_discoverable_timeout(Adapter *self, const guint32 value)
adapter_set_property(self, "DiscoverableTimeout", &t, &error);
g_value_unset(&t);
+ if (error != NULL) {
+ g_critical("%s", error->message);
+ }
g_assert(error == NULL);
}
@@ -706,6 +720,9 @@ void adapter_set_name(Adapter *self, const gchar *value)
adapter_set_property(self, "Name", &t, &error);
g_value_unset(&t);
+ if (error != NULL) {
+ g_critical("%s", error->message);
+ }
g_assert(error == NULL);
}
@@ -728,6 +745,9 @@ void adapter_set_pairable(Adapter *self, const gboolean value)
adapter_set_property(self, "Pairable", &t, &error);
g_value_unset(&t);
+ if (error != NULL) {
+ g_critical("%s", error->message);
+ }
g_assert(error == NULL);
}
@@ -750,6 +770,9 @@ void adapter_set_pairable_timeout(Adapter *self, const guint32 value)
adapter_set_property(self, "PairableTimeout", &t, &error);
g_value_unset(&t);
+ if (error != NULL) {
+ g_critical("%s", error->message);
+ }
g_assert(error == NULL);
}
@@ -772,6 +795,9 @@ void adapter_set_powered(Adapter *self, const gboolean value)
adapter_set_property(self, "Powered", &t, &error);
g_value_unset(&t);
+ if (error != NULL) {
+ g_critical("%s", error->message);
+ }
g_assert(error == NULL);
}