summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am97
-rw-r--r--src/bt-adapter.137
-rw-r--r--src/bt-adapter.c551
-rw-r--r--src/bt-agent.159
-rw-r--r--src/bt-agent.c89
-rw-r--r--src/bt-audio.1167
-rw-r--r--src/bt-audio.c153
-rw-r--r--src/bt-device.139
-rw-r--r--src/bt-device.c1067
-rw-r--r--src/bt-input.1167
-rw-r--r--src/bt-input.c148
-rw-r--r--src/bt-monitor.1180
-rw-r--r--src/bt-monitor.c490
-rw-r--r--src/bt-network.135
-rw-r--r--src/bt-network.c57
-rw-r--r--src/bt-obex.133
-rw-r--r--src/bt-obex.c1404
-rw-r--r--src/bt-serial.1170
-rw-r--r--src/bt-serial.c155
-rw-r--r--src/lib/agent-helper.c371
-rw-r--r--src/lib/agent-helper.h (renamed from src/lib/obexd-api.h)42
-rw-r--r--src/lib/bluez-api.h82
-rw-r--r--src/lib/bluez/adapter.c816
-rw-r--r--src/lib/bluez/adapter.h66
-rw-r--r--src/lib/bluez/agent.c379
-rw-r--r--src/lib/bluez/agent.h96
-rw-r--r--src/lib/bluez/agent_manager.c161
-rw-r--r--src/lib/bluez/agent_manager.h82
-rw-r--r--src/lib/bluez/alert.c161
-rw-r--r--src/lib/bluez/alert.h82
-rw-r--r--src/lib/bluez/alert_agent.c183
-rw-r--r--src/lib/bluez/alert_agent.h83
-rw-r--r--src/lib/bluez/audio.c279
-rw-r--r--src/lib/bluez/audio.h70
-rw-r--r--src/lib/bluez/cycling_speed.c210
-rw-r--r--src/lib/bluez/cycling_speed.h85
-rw-r--r--src/lib/bluez/cycling_speed_manager.c162
-rw-r--r--src/lib/bluez/cycling_speed_manager.h75
-rw-r--r--src/lib/bluez/device.c749
-rw-r--r--src/lib/bluez/device.h67
-rw-r--r--src/lib/bluez/health_channel.c241
-rw-r--r--src/lib/bluez/health_channel.h90
-rw-r--r--src/lib/bluez/health_device.c231
-rw-r--r--src/lib/bluez/health_device.h88
-rw-r--r--src/lib/bluez/health_manager.c161
-rw-r--r--src/lib/bluez/health_manager.h81
-rw-r--r--src/lib/bluez/heart_rate.c198
-rw-r--r--src/lib/bluez/heart_rate.h84
-rw-r--r--src/lib/bluez/heart_rate_manager.c162
-rw-r--r--src/lib/bluez/heart_rate_manager.h75
-rw-r--r--src/lib/bluez/input.c278
-rw-r--r--src/lib/bluez/input.h70
-rw-r--r--src/lib/bluez/manager.c322
-rw-r--r--src/lib/bluez/manager.h70
-rw-r--r--src/lib/bluez/media.c190
-rw-r--r--src/lib/bluez/media.h84
-rw-r--r--src/lib/bluez/media_control.c259
-rw-r--r--src/lib/bluez/media_control.h94
-rw-r--r--src/lib/bluez/media_player.c417
-rw-r--r--src/lib/bluez/media_player.h109
-rw-r--r--src/lib/bluez/network.c291
-rw-r--r--src/lib/bluez/network.h31
-rw-r--r--src/lib/bluez/network_server.c121
-rw-r--r--src/lib/bluez/network_server.h18
-rw-r--r--src/lib/bluez/obex/obex_agent_manager.c154
-rw-r--r--src/lib/bluez/obex/obex_agent_manager.h81
-rw-r--r--src/lib/bluez/obex/obex_client.c161
-rw-r--r--src/lib/bluez/obex/obex_client.h81
-rw-r--r--src/lib/bluez/obex/obex_file_transfer.c236
-rw-r--r--src/lib/bluez/obex/obex_file_transfer.h88
-rw-r--r--src/lib/bluez/obex/obex_message.c380
-rw-r--r--src/lib/bluez/obex/obex_message.h101
-rw-r--r--src/lib/bluez/obex/obex_message_access.c204
-rw-r--r--src/lib/bluez/obex/obex_message_access.h84
-rw-r--r--src/lib/bluez/obex/obex_object_push.c197
-rw-r--r--src/lib/bluez/obex/obex_object_push.h79
-rw-r--r--src/lib/bluez/obex/obex_phonebook_access.c197
-rw-r--r--src/lib/bluez/obex/obex_phonebook_access.h83
-rw-r--r--src/lib/bluez/obex/obex_session.c258
-rw-r--r--src/lib/bluez/obex/obex_session.h90
-rw-r--r--src/lib/bluez/obex/obex_synchronization.c169
-rw-r--r--src/lib/bluez/obex/obex_synchronization.h81
-rw-r--r--src/lib/bluez/obex/obex_transfer.c301
-rw-r--r--src/lib/bluez/obex/obex_transfer.h96
-rw-r--r--src/lib/bluez/profile_manager.c154
-rw-r--r--src/lib/bluez/profile_manager.h81
-rw-r--r--src/lib/bluez/proximity_monitor.c236
-rw-r--r--src/lib/bluez/proximity_monitor.h88
-rw-r--r--src/lib/bluez/proximity_reporter.c210
-rw-r--r--src/lib/bluez/proximity_reporter.h85
-rw-r--r--src/lib/bluez/serial.c192
-rw-r--r--src/lib/bluez/serial.h68
-rw-r--r--src/lib/bluez/sim_access.c203
-rw-r--r--src/lib/bluez/sim_access.h86
-rw-r--r--src/lib/bluez/thermometer.c198
-rw-r--r--src/lib/bluez/thermometer.h84
-rw-r--r--src/lib/bluez/thermometer_manager.c162
-rw-r--r--src/lib/bluez/thermometer_manager.h75
-rw-r--r--src/lib/dbus-common.c87
-rw-r--r--src/lib/dbus-common.h46
-rw-r--r--src/lib/helpers.c625
-rw-r--r--src/lib/helpers.h12
-rw-r--r--src/lib/manager.c276
-rw-r--r--src/lib/manager.h67
-rw-r--r--src/lib/marshallers.c588
-rw-r--r--src/lib/marshallers.h116
-rw-r--r--src/lib/marshallers.list25
-rw-r--r--src/lib/obex_agent.c296
-rw-r--r--src/lib/obex_agent.h92
-rw-r--r--src/lib/obexd/obexagent.c323
-rw-r--r--src/lib/obexd/obexagent.h98
-rw-r--r--src/lib/obexd/obexclient.c158
-rw-r--r--src/lib/obexd/obexclient.h71
-rw-r--r--src/lib/obexd/obexclient_file_transfer.c240
-rw-r--r--src/lib/obexd/obexclient_file_transfer.h74
-rw-r--r--src/lib/obexd/obexclient_session.c288
-rw-r--r--src/lib/obexd/obexclient_session.h72
-rw-r--r--src/lib/obexd/obexclient_transfer.c280
-rw-r--r--src/lib/obexd/obexclient_transfer.h71
-rw-r--r--src/lib/obexd/obexmanager.c218
-rw-r--r--src/lib/obexd/obexmanager.h67
-rw-r--r--src/lib/obexd/obexsession.c223
-rw-r--r--src/lib/obexd/obexsession.h68
-rw-r--r--src/lib/obexd/obextransfer.c216
-rw-r--r--src/lib/obexd/obextransfer.h67
-rw-r--r--src/lib/properties.c269
-rw-r--r--src/lib/properties.h61
127 files changed, 13360 insertions, 9941 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a8f97e4..1658b78 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,68 +1,55 @@
AM_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
AM_LDFLAGS = $(GLIB_LIBS) $(DBUS_GLIB_LIBS)
-# Marshallers generation
-#BUILT_SOURCES = lib/marshallers.c lib/marshallers.h
-#GENMARSHAL_FLAGS = --prefix="g_cclosure_bt_marshal" --g-fatal-warnings
-#
-#lib/marshallers.h: lib/marshallers.list
-# glib-genmarshal $(GENMARSHAL_FLAGS) --header lib/marshallers.list > lib/marshallers.h
-#
-#lib/marshallers.c: lib/marshallers.list
-# glib-genmarshal $(GENMARSHAL_FLAGS) --body lib/marshallers.list > lib/marshallers.c
-
-bluez_sources = lib/bluez/adapter.c lib/bluez/adapter.h \
- lib/bluez/agent.c lib/bluez/agent.h \
- lib/bluez/audio.c lib/bluez/audio.h \
+bluez_sources = lib/bluez/adapter.c lib/bluez/adapter.h \
+ lib/bluez/agent_manager.c lib/bluez/agent_manager.h \
+ lib/bluez/alert_agent.c lib/bluez/alert_agent.h \
+ lib/bluez/alert.c lib/bluez/alert.h \
+ lib/bluez/cycling_speed.c lib/bluez/cycling_speed.h \
+ lib/bluez/cycling_speed_manager.c lib/bluez/cycling_speed_manager.h \
lib/bluez/device.c lib/bluez/device.h \
- lib/bluez/input.c lib/bluez/input.h \
- lib/bluez/manager.c lib/bluez/manager.h \
+ lib/bluez/health_channel.c lib/bluez/health_channel.h \
+ lib/bluez/health_device.c lib/bluez/health_device.h \
+ lib/bluez/health_manager.c lib/bluez/health_manager.h \
+ lib/bluez/heart_rate.c lib/bluez/heart_rate.h \
+ lib/bluez/heart_rate_manager.c lib/bluez/heart_rate_manager.h \
+ lib/bluez/media.c lib/bluez/media.h \
+ lib/bluez/media_control.c lib/bluez/media_control.h \
+ lib/bluez/media_player.c lib/bluez/media_player.h \
lib/bluez/network.c lib/bluez/network.h \
lib/bluez/network_server.c lib/bluez/network_server.h \
- lib/bluez/serial.c lib/bluez/serial.h
-
-if OBEX
-obexd_sources = lib/obexd/obexagent.c lib/obexd/obexagent.h \
- lib/obexd/obexclient.c lib/obexd/obexclient.h \
- lib/obexd/obexclient_file_transfer.c lib/obexd/obexclient_file_transfer.h \
- lib/obexd/obexclient_session.c lib/obexd/obexclient_session.h \
- lib/obexd/obexclient_transfer.c lib/obexd/obexclient_transfer.h \
- lib/obexd/obexmanager.c lib/obexd/obexmanager.h \
- lib/obexd/obexsession.c lib/obexd/obexsession.h \
- lib/obexd/obextransfer.c lib/obexd/obextransfer.h
-else
-obexd_sources =
-endif
-
-lib_sources = lib/marshallers.c lib/marshallers.h \
+ lib/bluez/obex/obex_agent_manager.c lib/bluez/obex/obex_agent_manager.h \
+ lib/bluez/obex/obex_client.c lib/bluez/obex/obex_client.h \
+ lib/bluez/obex/obex_file_transfer.c lib/bluez/obex/obex_file_transfer.h \
+ lib/bluez/obex/obex_message_access.c lib/bluez/obex/obex_message_access.h \
+ lib/bluez/obex/obex_message.c lib/bluez/obex/obex_message.h \
+ lib/bluez/obex/obex_object_push.c lib/bluez/obex/obex_object_push.h \
+ lib/bluez/obex/obex_phonebook_access.c lib/bluez/obex/obex_phonebook_access.h \
+ lib/bluez/obex/obex_session.c lib/bluez/obex/obex_session.h \
+ lib/bluez/obex/obex_synchronization.c lib/bluez/obex/obex_synchronization.h \
+ lib/bluez/obex/obex_transfer.c lib/bluez/obex/obex_transfer.h \
+ lib/bluez/profile_manager.c lib/bluez/profile_manager.h \
+ lib/bluez/proximity_monitor.c lib/bluez/proximity_monitor.h \
+ lib/bluez/proximity_reporter.c lib/bluez/proximity_reporter.h \
+ lib/bluez/sim_access.c lib/bluez/sim_access.h \
+ lib/bluez/thermometer.c lib/bluez/thermometer.h \
+ lib/bluez/thermometer_manager.c lib/bluez/thermometer_manager.h
+
+lib_sources = lib/agent-helper.c lib/agent-helper.h \
lib/dbus-common.c lib/dbus-common.h \
lib/helpers.c lib/helpers.h \
+ lib/manager.c lib/manager.h \
+ lib/obex_agent.c lib/obex_agent.h \
+ lib/properties.c lib/properties.h \
lib/sdp.c lib/sdp.h \
lib/bluez-api.h
-if OBEX
-lib_sources += lib/obexd-api.h
-endif
-
-bin_PROGRAMS = bt-monitor bt-adapter bt-agent bt-device bt-input bt-audio bt-network bt-serial
-bt_monitor_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-monitor.c
-bt_adapter_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-adapter.c
-bt_agent_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-agent.c
-bt_device_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-device.c
-bt_input_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-input.c
-bt_audio_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-audio.c
-bt_network_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-network.c
-bt_serial_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-serial.c
-
-if OBEX
-bin_PROGRAMS += bt-obex
-bt_obex_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-obex.c
+bin_PROGRAMS = bt-adapter bt-agent bt-device bt-network bt-obex
+bt_adapter_SOURCES = $(lib_sources) $(bluez_sources) bt-adapter.c
+bt_agent_SOURCES = $(lib_sources) $(bluez_sources) bt-agent.c
+bt_device_SOURCES = $(lib_sources) $(bluez_sources) bt-device.c
+bt_network_SOURCES = $(lib_sources) $(bluez_sources) bt-network.c
+bt_obex_SOURCES = $(lib_sources) $(bluez_sources) bt-obex.c
bt_obex_LDADD = $(LIBREADLINE)
-endif
-
-dist_man_MANS = bt-monitor.1 bt-adapter.1 bt-agent.1 bt-device.1 bt-input.1 bt-audio.1 bt-network.1 bt-serial.1
-if OBEX
-dist_man_MANS += bt-obex.1
-endif
-#CLEANFILES = lib/marshallers.c lib/marshallers.h
+dist_man_MANS = bt-adapter.1 bt-agent.1 bt-device.1 bt-network.1 bt-obex.1
diff --git a/src/bt-adapter.1 b/src/bt-adapter.1
index 3466c47..f24eef6 100644
--- a/src/bt-adapter.1
+++ b/src/bt-adapter.1
@@ -1,4 +1,4 @@
-.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
+.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
@@ -38,6 +38,8 @@
. ds PI \(*p
. ds L" ``
. ds R" ''
+. ds C`
+. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
@@ -48,17 +50,24 @@
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
-.ie \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
+.\"
+.\" Avoid warning from groff about undefined register 'F'.
+.de IX
..
-. nr % 0
-. rr F
-.\}
-.el \{\
-. de IX
+.nr rF 0
+.if \n(.g .if rF .nr rF 1
+.if (\n(rF:(\n(.g==0)) \{
+. if \nF \{
+. de IX
+. tm Index:\\$1\t\\n%\t"\\$2"
..
+. if !\nF==2 \{
+. nr % 0
+. nr F 2
+. \}
+. \}
.\}
+.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
@@ -124,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "bt-adapter 1"
-.TH bt-adapter 1 "2010-08-16" "" "bluez-tools"
+.TH bt-adapter 1 "2014-08-01" "" "bluez-tools"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -133,7 +142,7 @@
bt\-adapter \- a bluetooth adapter manager
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
-bt-adapter [\s-1OPTION\s0...]
+bt-adapter [\s-1OPTION...\s0]
.PP
Help Options:
\-h, \-\-help
@@ -167,14 +176,14 @@ show information about adapter, change adapter properties or discover remote dev
Discover remote devices (with remote device name resolving)
.PP
\&\fB\-\-set <property> <value>\fR
- Change adapter properties (see \s-1ADAPTER\s0 \s-1PROPERTIES\s0 section for list
+ Change adapter properties (see \s-1ADAPTER PROPERTIES\s0 section for list
of available properties)
.SH "ADAPTER PROPERTIES"
.IX Header "ADAPTER PROPERTIES"
string Address [ro]
The Bluetooth adapter address (\s-1MAC\s0).
.PP
-string Name [rw]
+string Alias [rw]
The Bluetooth adapter friendly name.
.PP
uint32 Class [ro]
@@ -231,4 +240,4 @@ list UUIDs [ro]
Alexander Orlenko <zxteam@gmail.com>.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
-\&\fIbt\-agent\fR\|(1) \fIbt\-audio\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-input\fR\|(1) \fIbt\-monitor\fR\|(1) \fIbt\-network\fR\|(1) \fIbt\-serial\fR\|(1)
+\&\fIbt\-agent\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-network\fR\|(1)
diff --git a/src/bt-adapter.c b/src/bt-adapter.c
index ca5d971..179e6e1 100644
--- a/src/bt-adapter.c
+++ b/src/bt-adapter.c
@@ -1,83 +1,74 @@
-/*
- *
- * 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
+/*
+ * File: main.c
+ * Author: workout
*
+ * Created on April 18, 2014, 1:14 PM
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <gio/gio.h>
+#include <glib.h>
#include <locale.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <glib.h>
-
#include "lib/dbus-common.h"
-#include "lib/helpers.h"
#include "lib/bluez-api.h"
+#include "lib/helpers.h"
-static void adapter_device_found(Adapter *adapter, const gchar *address, GHashTable *values, gpointer data)
+static void _adapter_property_changed(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
{
- g_assert(data != NULL);
- GHashTable *found_devices = data;
-
- if (g_hash_table_lookup(found_devices, address) != NULL) {
- return;
- }
-
- if (g_hash_table_size(found_devices) == 0) g_print("\n");
-
- g_print("[%s]\n", address);
- g_print(" Name: %s\n", g_hash_table_lookup(values, "Name") != NULL ? g_value_get_string(g_hash_table_lookup(values, "Name")) : NULL);
- g_print(" Alias: %s\n", g_hash_table_lookup(values, "Alias") != NULL ? g_value_get_string(g_hash_table_lookup(values, "Alias")) : NULL);
- g_print(" Address: %s\n", g_value_get_string(g_hash_table_lookup(values, "Address")));
- g_print(" Icon: %s\n", g_value_get_string(g_hash_table_lookup(values, "Icon")));
- g_print(" Class: 0x%x\n", g_value_get_uint(g_hash_table_lookup(values, "Class")));
- g_print(" LegacyPairing: %d\n", g_value_get_boolean(g_hash_table_lookup(values, "LegacyPairing")));
- g_print(" Paired: %d\n", g_value_get_boolean(g_hash_table_lookup(values, "Paired")));
- g_print(" RSSI: %d\n", g_value_get_int(g_hash_table_lookup(values, "RSSI")));
- g_print("\n");
-
- g_hash_table_insert(found_devices, g_strdup(address), g_value_dup_string(g_hash_table_lookup(values, "Alias")));
+ g_assert(user_data != NULL);
+ GMainLoop *mainloop = user_data;
+
+ GVariant *changed_properties = g_variant_get_child_value(parameters, 1);
+ GVariant *discovering_variant = g_variant_lookup_value(changed_properties, "Discovering", NULL);
+ if(discovering_variant)
+ {
+ const gboolean discovering = g_variant_get_boolean(discovering_variant);
+ if(!discovering)
+ {
+ g_main_loop_quit(mainloop);
+ }
+ g_variant_unref(discovering_variant);
+ }
+ g_variant_unref(changed_properties);
}
-/*
-static void adapter_device_disappeared(Adapter *adapter, const gchar *address, gpointer data)
+static void _manager_device_found(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
{
- g_assert(data != NULL);
- GHashTable *found_devices = data;
-
- g_print("Device disappeared: %s (%s)\n", g_value_get_string(g_hash_table_lookup(found_devices, address)), address);
-}
- */
-
-static void adapter_property_changed(Adapter *adapter, const gchar *name, const GValue *value, gpointer data)
-{
- g_assert(data != NULL);
- GMainLoop *mainloop = data;
-
- if (g_strcmp0(name, "Discovering") == 0 && g_value_get_boolean(value) == FALSE) {
- g_main_loop_quit(mainloop);
- }
+ g_assert(user_data != NULL);
+ const gchar *adapter_object_path = user_data;
+
+ GVariant *arg0 = g_variant_get_child_value(parameters, 0);
+ const gchar *str_object_path = g_variant_get_string(arg0, NULL);
+ g_variant_unref(arg0);
+
+ if (!g_str_has_prefix(str_object_path, adapter_object_path))
+ return;
+
+ GVariant *interfaces_and_properties = g_variant_get_child_value(parameters, 1);
+ GVariant *properties = NULL;
+ if (g_variant_lookup(interfaces_and_properties, DEVICE_DBUS_INTERFACE, "@a{sv}", &properties))
+ {
+ g_print("[%s]\n", g_variant_get_string(g_variant_lookup_value(properties, "Address", NULL), NULL));
+ g_print(" Name: %s\n", g_variant_lookup_value(properties, "Name", NULL) != NULL ? g_variant_get_string(g_variant_lookup_value(properties, "Name", NULL), NULL) : NULL);
+ g_print(" Alias: %s\n", g_variant_lookup_value(properties, "Alias", NULL) != NULL ? g_variant_get_string(g_variant_lookup_value(properties, "Alias", NULL), NULL) : NULL);
+ g_print(" Address: %s\n", g_variant_lookup_value(properties, "Address", NULL) != NULL ? g_variant_get_string(g_variant_lookup_value(properties, "Address", NULL), NULL) : NULL);
+ g_print(" Icon: %s\n", g_variant_lookup_value(properties, "Icon", NULL) != NULL ? g_variant_get_string(g_variant_lookup_value(properties, "Icon", NULL), NULL) : NULL);
+ g_print(" Class: 0x%x\n", g_variant_lookup_value(properties, "Class", NULL) != NULL ? g_variant_get_uint32(g_variant_lookup_value(properties, "Class", NULL)) : 0x0);
+ g_print(" LegacyPairing: %d\n", g_variant_lookup_value(properties, "LegacyPairing", NULL) != NULL ? g_variant_get_boolean(g_variant_lookup_value(properties, "LegacyPairing", NULL)) : FALSE);
+ g_print(" Paired: %d\n", g_variant_lookup_value(properties, "Paired", NULL) != NULL ? g_variant_get_boolean(g_variant_lookup_value(properties, "Paired", NULL)) : FALSE);
+ g_print(" RSSI: %d\n", g_variant_lookup_value(properties, "RSSI", NULL) != NULL ? g_variant_get_int16(g_variant_lookup_value(properties, "RSSI", NULL)) : 0x0);
+ g_print("\n");
+
+ g_variant_unref(properties);
+ }
+ g_variant_unref(interfaces_and_properties);
}
static gboolean list_arg = FALSE;
@@ -89,200 +80,252 @@ static gchar *set_property_arg = NULL;
static gchar *set_value_arg = NULL;
static GOptionEntry entries[] = {
- {"list", 'l', 0, G_OPTION_ARG_NONE, &list_arg, "List all available adapters", NULL},
- {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter Name or MAC", "<name|mac>"},
- {"info", 'i', 0, G_OPTION_ARG_NONE, &info_arg, "Show adapter info", NULL},
- {"discover", 'd', 0, G_OPTION_ARG_NONE, &discover_arg, "Discover remote devices", NULL},
- {"set", 0, 0, G_OPTION_ARG_NONE, &set_arg, "Set adapter property", NULL},
- {NULL}
+ {"list", 'l', 0, G_OPTION_ARG_NONE, &list_arg, "List all available adapters", NULL},
+ {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter Name or MAC", "<name|mac>"},
+ {"info", 'i', 0, G_OPTION_ARG_NONE, &info_arg, "Show adapter info", NULL},
+ {"discover", 'd', 0, G_OPTION_ARG_NONE, &discover_arg, "Discover remote devices", NULL},
+ {"set", 's', 0, G_OPTION_ARG_NONE, &set_arg, "Set adapter property", NULL},
+ {NULL}
};
+/*
+ *
+ */
int main(int argc, char *argv[])
{
- GError *error = NULL;
- GOptionContext *context;
-
- /* Query current locale */
- setlocale(LC_CTYPE, "");
-
- g_type_init();
- dbus_init();
-
- context = g_option_context_new("- a bluetooth adapter manager");
- g_option_context_add_main_entries(context, entries, NULL);
- g_option_context_set_summary(context, "Version "PACKAGE_VERSION);
- g_option_context_set_description(context,
- "Set Options:\n"
- " --set <property> <value>\n"
- " Where `property` is one of:\n"
- " Name\n"
- " Discoverable\n"
- " DiscoverableTimeout\n"
- " Pairable\n"
- " PairableTimeout\n"
- " Powered\n\n"
- //"Report bugs to <"PACKAGE_BUGREPORT">."
- "Project home page <"PACKAGE_URL">."
- );
-
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- g_print("%s: %s\n", g_get_prgname(), error->message);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- } else if (!list_arg && !info_arg && !discover_arg && !set_arg) {
- g_print("%s", g_option_context_get_help(context, FALSE, NULL));
- exit(EXIT_FAILURE);
- } else if (set_arg && (argc != 3 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0)) {
- g_print("%s: Invalid arguments for --set\n", g_get_prgname());
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- }
-
- g_option_context_free(context);
-
- if (!dbus_system_connect(&error)) {
- g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- /* Check, that bluetooth daemon is running */
- if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) {
- g_printerr("%s: bluez service is not found\n", g_get_prgname());
- g_printerr("Did you forget to run bluetoothd?\n");
- exit(EXIT_FAILURE);
- }
-
- Manager *manager = g_object_new(MANAGER_TYPE, NULL);
-
- if (list_arg) {
- const GPtrArray *adapters_list = manager_get_adapters(manager);
- g_assert(adapters_list != NULL);
-
- if (adapters_list->len == 0) {
- g_print("No adapters found\n");
- exit(EXIT_FAILURE);
- }
-
- g_print("Available adapters:\n");
- for (int i = 0; i < adapters_list->len; i++) {
- const gchar *adapter_path = g_ptr_array_index(adapters_list, i);
- Adapter *adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", adapter_path, NULL);
- g_print("%s (%s)\n", adapter_get_name(adapter), adapter_get_address(adapter));
- g_object_unref(adapter);
- }
- } else if (info_arg) {
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
-
- gchar *adapter_intf = g_path_get_basename(adapter_get_dbus_object_path(adapter));
- g_print("[%s]\n", adapter_intf);
- g_print(" Name: %s [rw]\n", adapter_get_name(adapter));
- g_print(" Address: %s\n", adapter_get_address(adapter));
- g_print(" Class: 0x%x\n", adapter_get_class(adapter));
- g_print(" Discoverable: %d [rw]\n", adapter_get_discoverable(adapter));
- g_print(" DiscoverableTimeout: %d [rw]\n", adapter_get_discoverable_timeout(adapter));
- g_print(" Discovering: %d\n", adapter_get_discovering(adapter));
- g_print(" Pairable: %d [rw]\n", adapter_get_pairable(adapter));
- g_print(" PairableTimeout: %d [rw]\n", adapter_get_pairable_timeout(adapter));
- g_print(" Powered: %d [rw]\n", adapter_get_powered(adapter));
- g_print(" UUIDs: [");
- const gchar **uuids = adapter_get_uuids(adapter);
- for (int j = 0; uuids[j] != NULL; j++) {
- if (j > 0) g_print(", ");
- g_print("%s", uuid2name(uuids[j]));
- }
- g_print("]\n");
-
- g_free(adapter_intf);
- g_object_unref(adapter);
- } else if (discover_arg) {
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
-
- // To store pairs MAC => Name
- GHashTable *found_devices = g_hash_table_new(g_str_hash, g_str_equal);
-
- // Mainloop
- GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
-
- g_signal_connect(adapter, "DeviceFound", G_CALLBACK(adapter_device_found), found_devices);
- //g_signal_connect(adapter, "DeviceDisappeared", G_CALLBACK(adapter_device_disappeared), found_devices);
- g_signal_connect(adapter, "PropertyChanged", G_CALLBACK(adapter_property_changed), mainloop);
-
- g_print("Searching...\n");
- adapter_start_discovery(adapter, &error);
- exit_if_error(error);
-
- g_main_loop_run(mainloop);
- /* Discovering process here... */
- g_main_loop_unref(mainloop);
-
- g_print("Done\n");
- g_hash_table_unref(found_devices);
- g_object_unref(adapter);
- } else if (set_arg) {
- set_property_arg = argv[1];
- set_value_arg = argv[2];
-
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
-
- GValue v = {0,};
-
- if (g_strcmp0(set_property_arg, "Name") == 0) {
- g_value_init(&v, G_TYPE_STRING);
- g_value_set_string(&v, set_value_arg);
- } else if (
- g_strcmp0(set_property_arg, "Discoverable") == 0 ||
- g_strcmp0(set_property_arg, "Pairable") == 0 ||
- g_strcmp0(set_property_arg, "Powered") == 0
- ) {
- g_value_init(&v, G_TYPE_BOOLEAN);
-
- if (g_strcmp0(set_value_arg, "0") == 0 || g_ascii_strcasecmp(set_value_arg, "FALSE") == 0 || g_ascii_strcasecmp(set_value_arg, "OFF") == 0) {
- g_value_set_boolean(&v, FALSE);
- } else if (g_strcmp0(set_value_arg, "1") == 0 || g_ascii_strcasecmp(set_value_arg, "TRUE") == 0 || g_ascii_strcasecmp(set_value_arg, "ON") == 0) {
- g_value_set_boolean(&v, TRUE);
- } else {
- g_print("%s: Invalid boolean value: %s\n", g_get_prgname(), set_value_arg);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- }
- } else if (
- g_strcmp0(set_property_arg, "DiscoverableTimeout") == 0 ||
- g_strcmp0(set_property_arg, "PairableTimeout") == 0
- ) {
- g_value_init(&v, G_TYPE_UINT);
- g_value_set_uint(&v, (guint) atoi(set_value_arg));
- } else {
- g_print("%s: Invalid property: %s\n", g_get_prgname(), set_property_arg);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- }
-
- GHashTable *props = adapter_get_properties(adapter, &error);
- exit_if_error(error);
- GValue *old_value = g_hash_table_lookup(props, set_property_arg);
- g_assert(old_value != NULL);
- if (G_VALUE_HOLDS_STRING(old_value)) {
- g_print("%s: %s -> %s\n", set_property_arg, g_value_get_string(old_value), g_value_get_string(&v));
- } else if (G_VALUE_HOLDS_BOOLEAN(old_value)) {
- g_print("%s: %d -> %d\n", set_property_arg, g_value_get_boolean(old_value), g_value_get_boolean(&v));
- } else if (G_VALUE_HOLDS_UINT(old_value)) {
- g_print("%s: %d -> %d\n", set_property_arg, g_value_get_uint(old_value), g_value_get_uint(&v));
- }
- g_hash_table_unref(props);
-
- adapter_set_property(adapter, set_property_arg, &v, &error);
- exit_if_error(error);
-
- g_value_unset(&v);
- g_object_unref(adapter);
- }
-
- g_object_unref(manager);
- dbus_disconnect();
-
- exit(EXIT_SUCCESS);
+ GError *error = NULL;
+ GOptionContext *context;
+
+ /* Query current locale */
+ setlocale(LC_CTYPE, "");
+
+ // g_type_init(); // DEPRECATED
+ dbus_init();
+
+ context = g_option_context_new("- a bluetooth adapter manager");
+ g_option_context_add_main_entries(context, entries, NULL);
+ g_option_context_set_summary(context, "Version "PACKAGE_VERSION);
+ g_option_context_set_description(context,
+ "Set Options:\n"
+ " --set <property> <value>\n"
+ " Where `property` is one of:\n"
+ " Name\n"
+ " Discoverable\n"
+ " DiscoverableTimeout\n"
+ " Pairable\n"
+ " PairableTimeout\n"
+ " Powered\n\n"
+ "Report bugs to <"PACKAGE_BUGREPORT">."
+ "Project home page <"PACKAGE_URL">."
+ );
+
+ if (!g_option_context_parse(context, &argc, &argv, &error))
+ {
+ g_print("%s: %s\n", g_get_prgname(), error->message);
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+ else if (!list_arg && !info_arg && !discover_arg && !set_arg)
+ {
+ g_print("%s", g_option_context_get_help(context, FALSE, NULL));
+ exit(EXIT_FAILURE);
+ }
+ else if (set_arg && (argc != 3 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0))
+ {
+ g_print("%s: Invalid arguments for --set\n", g_get_prgname());
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+
+ g_option_context_free(context);
+
+ if (!dbus_system_connect(&error))
+ {
+ g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Check, that bluetooth daemon is running */
+ if (!intf_supported(BLUEZ_DBUS_SERVICE_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE))
+ {
+ g_printerr("%s: bluez service is not found\n", g_get_prgname());
+ g_printerr("Did you forget to run bluetoothd?\n");
+ exit(EXIT_FAILURE);
+ }
+
+ Manager *manager = g_object_new(MANAGER_TYPE, NULL);
+
+ if (list_arg)
+ {
+ const GPtrArray *adapters_list = manager_get_adapters(manager);
+ g_assert(adapters_list != NULL);
+
+ if (adapters_list->len == 0)
+ {
+ g_print("No adapters found\n");
+ exit(EXIT_FAILURE);
+ }
+
+ g_print("Available adapters:\n");
+ for (int i = 0; i < adapters_list->len; i++)
+ {
+ const gchar *adapter_path = g_ptr_array_index(adapters_list, i);
+ Adapter *adapter = adapter_new(adapter_path);
+ g_print("%s (%s)\n", adapter_get_name(adapter, &error), adapter_get_address(adapter, &error));
+ g_object_unref(adapter);
+ }
+ }
+ else if (info_arg)
+ {
+ Adapter *adapter = find_adapter(adapter_arg, &error);
+ exit_if_error(error);
+
+ gchar *adapter_intf = g_path_get_basename(adapter_get_dbus_object_path(adapter));
+ g_print("[%s]\n", adapter_intf);
+ g_print(" Name: %s\n", adapter_get_name(adapter, &error));
+ g_print(" Address: %s\n", adapter_get_address(adapter, &error));
+ g_print(" Alias: %s [rw]\n", adapter_get_alias(adapter, &error));
+ g_print(" Class: 0x%x\n", adapter_get_class(adapter, &error));
+ g_print(" Discoverable: %d [rw]\n", adapter_get_discoverable(adapter, &error));
+ g_print(" DiscoverableTimeout: %d [rw]\n", adapter_get_discoverable_timeout(adapter, &error));
+ g_print(" Discovering: %d\n", adapter_get_discovering(adapter, &error));
+ g_print(" Pairable: %d [rw]\n", adapter_get_pairable(adapter, &error));
+ g_print(" PairableTimeout: %d [rw]\n", adapter_get_pairable_timeout(adapter, &error));
+ g_print(" Powered: %d [rw]\n", adapter_get_powered(adapter, &error));
+ g_print(" UUIDs: [");
+ const gchar **uuids = adapter_get_uuids(adapter, &error);
+ for (int j = 0; uuids[j] != NULL; j++)
+ {
+ if (j > 0) g_print(", ");
+ g_print("%s", uuid2name(uuids[j]));
+ }
+ g_print("]\n");
+
+ g_free(adapter_intf);
+ g_object_unref(adapter);
+ }
+ else if (discover_arg)
+ {
+ Adapter *adapter = find_adapter(adapter_arg, &error);
+ exit_if_error(error);
+
+ // To store pairs MAC => Name
+ GHashTable *found_devices = g_hash_table_new(g_str_hash, g_str_equal);
+
+ // Mainloop
+ GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
+
+ guint object_sig_sub_id = g_dbus_connection_signal_subscribe(system_conn, "org.bluez", "org.freedesktop.DBus.ObjectManager", "InterfacesAdded", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, _manager_device_found, (gpointer) adapter_get_dbus_object_path(adapter), NULL);
+ exit_if_error(error);
+ guint prop_sig_sub_id = g_dbus_connection_signal_subscribe(system_conn, "org.bluez", "org.freedesktop.DBus.Properties", "PropertiesChanged", adapter_get_dbus_object_path(adapter), NULL, G_DBUS_SIGNAL_FLAGS_NONE, _adapter_property_changed, mainloop, NULL);
+ exit_if_error(error);
+
+ g_print("Searching...\n");
+ adapter_start_discovery(adapter, &error);
+ exit_if_error(error);
+
+ g_main_loop_run(mainloop);
+ /* Discovering process here... */
+ g_main_loop_unref(mainloop);
+
+ g_dbus_connection_signal_unsubscribe(system_conn, object_sig_sub_id);
+ exit_if_error(error);
+ g_dbus_connection_signal_unsubscribe(system_conn, prop_sig_sub_id);
+ exit_if_error(error);
+
+ g_print("Done\n");
+ g_hash_table_unref(found_devices);
+ g_object_unref(adapter);
+ }
+ else if (set_arg)
+ {
+ set_property_arg = argv[1];
+ set_value_arg = argv[2];
+
+ Adapter *adapter = find_adapter(adapter_arg, &error);
+ exit_if_error(error);
+
+ GVariant *v = NULL;
+
+ if (g_strcmp0(set_property_arg, "Alias") == 0)
+ {
+ v = g_variant_new_string(set_value_arg);
+ }
+ else if (
+ g_strcmp0(set_property_arg, "Discoverable") == 0 ||
+ g_strcmp0(set_property_arg, "Pairable") == 0 ||
+ g_strcmp0(set_property_arg, "Powered") == 0
+ )
+ {
+ if (g_strcmp0(set_value_arg, "0") == 0 || g_ascii_strcasecmp(set_value_arg, "FALSE") == 0 || g_ascii_strcasecmp(set_value_arg, "OFF") == 0)
+ {
+ v = g_variant_new_boolean(FALSE);
+ }
+ else if (g_strcmp0(set_value_arg, "1") == 0 || g_ascii_strcasecmp(set_value_arg, "TRUE") == 0 || g_ascii_strcasecmp(set_value_arg, "ON") == 0)
+ {
+ v = g_variant_new_boolean(TRUE);
+ }
+ else
+ {
+ g_print("%s: Invalid boolean value: %s\n", g_get_prgname(), set_value_arg);
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+ }
+ else if (
+ g_strcmp0(set_property_arg, "DiscoverableTimeout") == 0 ||
+ g_strcmp0(set_property_arg, "PairableTimeout") == 0
+ )
+ {
+ v = g_variant_new_uint32((guint32) atoi(set_value_arg));
+ }
+ else
+ {
+ g_print("%s: Invalid property: %s\n", g_get_prgname(), set_property_arg);
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+
+ GVariant *props = adapter_get_properties(adapter, &error);
+ exit_if_error(error);
+
+ if(g_ascii_strcasecmp(set_property_arg, "Alias") == 0)
+ adapter_set_alias(adapter, g_variant_get_string(v, NULL), &error);
+ else if(g_ascii_strcasecmp(set_property_arg, "Discoverable") == 0)
+ adapter_set_discoverable(adapter, g_variant_get_boolean(v), &error);
+ else if(g_ascii_strcasecmp(set_property_arg, "DiscoverableTimeout") == 0)
+ adapter_set_discoverable_timeout(adapter, g_variant_get_uint32(v), &error);
+ else if(g_ascii_strcasecmp(set_property_arg, "Pairable") == 0)
+ adapter_set_pairable(adapter, g_variant_get_boolean(v), &error);
+ else if(g_ascii_strcasecmp(set_property_arg, "PairableTimeout") == 0)
+ adapter_set_pairable_timeout(adapter, g_variant_get_uint32(v), &error);
+ else if(g_ascii_strcasecmp(set_property_arg, "Powered") == 0)
+ adapter_set_powered(adapter, g_variant_get_boolean(v), &error);
+
+ exit_if_error(error);
+
+ GVariant *old_value = g_variant_lookup_value(props, set_property_arg, NULL);
+ g_assert(old_value != NULL);
+ if (g_variant_type_equal(G_VARIANT_TYPE_STRING, g_variant_get_type(old_value)))
+ {
+ g_print("%s: %s -> %s\n", set_property_arg, g_variant_get_string(old_value, NULL), g_variant_get_string(v, NULL));
+ }
+ else if (g_variant_type_equal(G_VARIANT_TYPE_BOOLEAN, g_variant_get_type(old_value)))
+ {
+ g_print("%s: %u -> %u\n", set_property_arg, g_variant_get_boolean(old_value), g_variant_get_boolean(v));
+ }
+ else if (g_variant_type_equal(G_VARIANT_TYPE_UINT32, g_variant_get_type(old_value)))
+ {
+ g_print("%s: %u -> %u\n", set_property_arg, g_variant_get_uint32(old_value), g_variant_get_uint32(v));
+ }
+ g_variant_unref(props);
+
+ // g_variant_unref(v); /* Floating references do not need to be unref */
+ g_object_unref(adapter);
+ }
+
+ g_object_unref(manager);
+ dbus_disconnect();
+
+ exit(EXIT_SUCCESS);
}
-
diff --git a/src/bt-agent.1 b/src/bt-agent.1
index c367390..98a5226 100644
--- a/src/bt-agent.1
+++ b/src/bt-agent.1
@@ -1,4 +1,4 @@
-.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
+.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
@@ -38,6 +38,8 @@
. ds PI \(*p
. ds L" ``
. ds R" ''
+. ds C`
+. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
@@ -48,17 +50,24 @@
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
-.ie \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
+.\"
+.\" Avoid warning from groff about undefined register 'F'.
+.de IX
..
-. nr % 0
-. rr F
-.\}
-.el \{\
-. de IX
+.nr rF 0
+.if \n(.g .if rF .nr rF 1
+.if (\n(rF:(\n(.g==0)) \{
+. if \nF \{
+. de IX
+. tm Index:\\$1\t\\n%\t"\\$2"
..
+. if !\nF==2 \{
+. nr % 0
+. nr F 2
+. \}
+. \}
.\}
+.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
@@ -124,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "bt-agent 1"
-.TH bt-agent 1 "2010-08-11" "" "bluez-tools"
+.TH bt-agent 1 "2014-08-03" "" "bluez-tools"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -133,13 +142,15 @@
bt\-adapter \- a bluetooth agent
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
-bt-agent [\s-1OPTION\s0...]
+bt-agent [\s-1OPTION...\s0]
.PP
Help Options:
\-h, \-\-help
.PP
Application Options:
- \-a, \-\-adapter=<name|mac>
+ \-c, \-\-capability=<capability>
+ \-p, \-\-pin
+ \-d, \-\-daemon
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This interactive utility is used to manage incoming Bluetooth requests
@@ -149,12 +160,28 @@ This interactive utility is used to manage incoming Bluetooth requests
\&\fB\-h, \-\-help\fR
Show help
.PP
-\&\fB\-a, \-\-adapter <name|mac>\fR
- Specify adapter to use by his Name or \s-1MAC\s0 address
- (if this option does not defined \- default adapter used)
+\&\fB\-c, \-\-capability <capability>\fR
+ Specify the input and output capabilities of the agent.
+ `capability` can be one of:
+ DisplayOnly
+ DisplayYesNo (default)
+ KeyboardOnly
+ NoInputNoOutput
+ (if this option does not defined \- `DisplayYesNo' will be used)
+.PP
+\&\fB\-p, \-\-pin <file path<gt\fR>
+ Use a file that holds a list of authorization codes for each device by name or mac address.
+ The contents of the file should be in this format:
+ \s-1AA:BB:CC:DD:EE:FF 123456
+ \s0 RemoteDeviceName * (accept any pin code)
+ If a pin file is included, it will check the passkey of the pairing device against the key included in the file. It will automatically authorize the device if the key matches, otherwise it will request the user for manual authorization.
+.PP
+\&\fB\-d, \-\-daemon\fR
+ Run the agent as a background process (as a daemon).
+ The agent will rely on a pin file and request no manual user authorization. Any devices that attempt to pair without a valid passkey defined in the pin file will be automatically rejected.
.SH "AUTHOR"
.IX Header "AUTHOR"
Alexander Orlenko <zxteam@gmail.com>.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
-\&\fIbt\-adapter\fR\|(1) \fIbt\-audio\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-input\fR\|(1) \fIbt\-monitor\fR\|(1) \fIbt\-network\fR\|(1) \fIbt\-serial\fR\|(1)
+\&\fIbt\-adapter\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-network\fR\|(1)
diff --git a/src/bt-agent.c b/src/bt-agent.c
index 3b1bbc2..feabaa6 100644
--- a/src/bt-agent.c
+++ b/src/bt-agent.c
@@ -34,9 +34,11 @@
#include <glib.h>
#include <glib/gstdio.h>
+#include <gio/gio.h>
#include "lib/dbus-common.h"
#include "lib/helpers.h"
+#include "lib/agent-helper.h"
#include "lib/bluez-api.h"
static gboolean need_unregister = TRUE;
@@ -45,7 +47,8 @@ static GMainLoop *mainloop = NULL;
static GHashTable *pin_hash_table = NULL;
static gchar *pin_arg = NULL;
-static void read_pin_file(const gchar *filename, GHashTable *pin_hash_table, gboolean first_run)
+// Not touching this for now. It seems to work.
+static void _read_pin_file(const gchar *filename, GHashTable *pin_hash_table, gboolean first_run)
{
g_assert(filename != NULL && strlen(filename) > 0);
g_assert(pin_hash_table != NULL);
@@ -127,37 +130,23 @@ static void signal_handler(int sig)
{
g_message("%s received", sig == SIGTERM ? "SIGTERM" : (sig == SIGUSR1 ? "SIGUSR1" : "SIGINT"));
- if (sig == SIGUSR1 && pin_arg) {
- /* Re-read PIN's file */
- g_print("Re-reading PIN's file\n");
- read_pin_file(pin_arg, pin_hash_table, FALSE);
- } else if (sig == SIGTERM || sig == SIGINT) {
-
-
- if (g_main_loop_is_running(mainloop))
- g_main_loop_quit(mainloop);
+ if (sig == SIGUSR1 && pin_arg)
+ {
+ /* Re-read PIN's file */
+ g_print("Re-reading PIN's file\n");
+ _read_pin_file(pin_arg, pin_hash_table, FALSE);
+ }
+ else if (sig == SIGTERM || sig == SIGINT)
+ {
+ if (g_main_loop_is_running(mainloop))
+ g_main_loop_quit(mainloop);
}
}
-static void agent_released(Agent *agent, gpointer data)
-{
- g_assert(data != NULL);
- GMainLoop *mainloop = data;
-
- need_unregister = FALSE;
-
- if (g_main_loop_is_running(mainloop))
- g_main_loop_quit(mainloop);
-
- g_print("Agent released\n");
-}
-
-static gchar *adapter_arg = NULL;
static gchar *capability_arg = NULL;
static gboolean daemon_arg = FALSE;
static GOptionEntry entries[] = {
- {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter Name or MAC", "<name|mac>"},
{"capability", 'c', 0, G_OPTION_ARG_STRING, &capability_arg, "Agent capability", "<capability>"},
{"pin", 'p', 0, G_OPTION_ARG_STRING, &pin_arg, "Path to the PIN's file"},
{"daemon", 'd', 0, G_OPTION_ARG_NONE, &daemon_arg, "Run in background (as daemon)"},
@@ -172,7 +161,8 @@ int main(int argc, char *argv[])
/* Query current locale */
setlocale(LC_CTYPE, "");
- g_type_init();
+ // Deprecated
+ // g_type_init();
dbus_init();
context = g_option_context_new(" - a bluetooth agent");
@@ -184,7 +174,7 @@ int main(int argc, char *argv[])
" DisplayYesNo (default)\n"
" KeyboardOnly\n"
" NoInputNoOutput\n\n"
- //"Report bugs to <"PACKAGE_BUGREPORT">."
+ "Report bugs to <"PACKAGE_BUGREPORT">."
"Project home page <"PACKAGE_URL">."
);
@@ -211,38 +201,47 @@ int main(int argc, char *argv[])
g_option_context_free(context);
- if (!dbus_system_connect(&error)) {
+ if (!dbus_system_connect(&error))
+ {
g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
exit(EXIT_FAILURE);
}
/* Check, that bluetooth daemon is running */
- if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) {
+ if (!intf_supported(BLUEZ_DBUS_SERVICE_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE))
+ {
g_printerr("%s: bluez service is not found\n", g_get_prgname());
g_printerr("Did you forget to run bluetoothd?\n");
exit(EXIT_FAILURE);
}
-
+
/* Read PIN's file */
- if (pin_arg) {
+ if (pin_arg)
+ {
pin_hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
- read_pin_file(pin_arg, pin_hash_table, TRUE);
+ _read_pin_file(pin_arg, pin_hash_table, TRUE);
}
mainloop = g_main_loop_new(NULL, FALSE);
Manager *manager = g_object_new(MANAGER_TYPE, NULL);
-
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
-
- Agent *agent = g_object_new(AGENT_TYPE, "PinHashTable", pin_hash_table, "Interactive", !daemon_arg, NULL);
-
- adapter_register_agent(adapter, AGENT_DBUS_PATH, capability_arg, &error);
+
+ AgentManager *agent_manager = agent_manager_new();
+
+ if(daemon_arg)
+ register_agent_callbacks(FALSE, pin_hash_table, mainloop, &error);
+ else
+ register_agent_callbacks(TRUE, pin_hash_table, mainloop, &error);
+
+ exit_if_error(error);
+
+ agent_manager_register_agent(agent_manager, AGENT_PATH, capability_arg, &error);
exit_if_error(error);
g_print("Agent registered\n");
-
- g_signal_connect(agent, "AgentReleased", G_CALLBACK(agent_released), mainloop);
+
+ agent_manager_request_default_agent(agent_manager, AGENT_PATH, &error);
+ exit_if_error(error);
+ g_print("Default agent requested\n");
if (daemon_arg) {
pid_t pid, sid;
@@ -277,7 +276,8 @@ int main(int argc, char *argv[])
g_main_loop_run(mainloop);
if (need_unregister) {
- adapter_unregister_agent(adapter, AGENT_DBUS_PATH, &error);
+ g_print("unregistering agent...\n");
+ agent_manager_unregister_agent(agent_manager, AGENT_PATH, &error);
exit_if_error(error);
/* Waiting for AgentReleased signal */
@@ -286,12 +286,11 @@ int main(int argc, char *argv[])
g_main_loop_unref(mainloop);
- g_object_unref(agent);
- g_object_unref(adapter);
+ unregister_agent_callbacks(NULL);
+ g_object_unref(agent_manager);
g_object_unref(manager);
dbus_disconnect();
exit(EXIT_SUCCESS);
}
-
diff --git a/src/bt-audio.1 b/src/bt-audio.1
deleted file mode 100644
index c83ca9d..0000000
--- a/src/bt-audio.1
+++ /dev/null
@@ -1,167 +0,0 @@
-.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
-.\"
-.\" Standard preamble:
-.\" ========================================================================
-.de Sp \" Vertical space (when we can't use .PP)
-.if t .sp .5v
-.if n .sp
-..
-.de Vb \" Begin verbatim text
-.ft CW
-.nf
-.ne \\$1
-..
-.de Ve \" End verbatim text
-.ft R
-.fi
-..
-.\" Set up some character translations and predefined strings. \*(-- will
-.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
-.\" double quote, and \*(R" will give a right double quote. \*(C+ will
-.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
-.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
-.\" nothing in troff, for use with C<>.
-.tr \(*W-
-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
-.ie n \{\
-. ds -- \(*W-
-. ds PI pi
-. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
-. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
-. ds L" ""
-. ds R" ""
-. ds C` ""
-. ds C' ""
-'br\}
-.el\{\
-. ds -- \|\(em\|
-. ds PI \(*p
-. ds L" ``
-. ds R" ''
-'br\}
-.\"
-.\" Escape single quotes in literal strings from groff's Unicode transform.
-.ie \n(.g .ds Aq \(aq
-.el .ds Aq '
-.\"
-.\" If the F register is turned on, we'll generate index entries on stderr for
-.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
-.\" entries marked with X<> in POD. Of course, you'll have to process the
-.\" output yourself in some meaningful fashion.
-.ie \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
-..
-. nr % 0
-. rr F
-.\}
-.el \{\
-. de IX
-..
-.\}
-.\"
-.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
-.\" Fear. Run. Save yourself. No user-serviceable parts.
-. \" fudge factors for nroff and troff
-.if n \{\
-. ds #H 0
-. ds #V .8m
-. ds #F .3m
-. ds #[ \f1
-. ds #] \fP
-.\}
-.if t \{\
-. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
-. ds #V .6m
-. ds #F 0
-. ds #[ \&
-. ds #] \&
-.\}
-. \" simple accents for nroff and troff
-.if n \{\
-. ds ' \&
-. ds ` \&
-. ds ^ \&
-. ds , \&
-. ds ~ ~
-. ds /
-.\}
-.if t \{\
-. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
-. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
-. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
-. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
-. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
-. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
-.\}
-. \" troff and (daisy-wheel) nroff accents
-.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
-.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
-.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
-.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
-.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
-.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
-.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
-.ds ae a\h'-(\w'a'u*4/10)'e
-.ds Ae A\h'-(\w'A'u*4/10)'E
-. \" corrections for vroff
-.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
-.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
-. \" for low resolution devices (crt and lpr)
-.if \n(.H>23 .if \n(.V>19 \
-\{\
-. ds : e
-. ds 8 ss
-. ds o a
-. ds d- d\h'-1'\(ga
-. ds D- D\h'-1'\(hy
-. ds th \o'bp'
-. ds Th \o'LP'
-. ds ae ae
-. ds Ae AE
-.\}
-.rm #[ #] #H #V #F C
-.\" ========================================================================
-.\"
-.IX Title "bt-audio 1"
-.TH bt-audio 1 "2010-08-11" "" "bluez-tools"
-.\" For nroff, turn off justification. Always turn off hyphenation; it makes
-.\" way too many mistakes in technical documents.
-.if n .ad l
-.nh
-.SH "NAME"
-bt\-audio \- a bluetooth generic audio manager
-.SH "SYNOPSIS"
-.IX Header "SYNOPSIS"
-bt-audio [\s-1OPTION\s0...]
-.PP
-Help Options:
- \-h, \-\-help
-.PP
-Application Options:
- \-a, \-\-adapter=<name|mac>
- \-c, \-\-connect=<name|mac>
- \-d, \-\-disconnect=<name|mac>
-.SH "DESCRIPTION"
-.IX Header "DESCRIPTION"
-This utility is used to manage outgoing audio service connections.
-.SH "OPTIONS"
-.IX Header "OPTIONS"
-\&\fB\-h, \-\-help\fR
- Show help
-.PP
-\&\fB\-a, \-\-adapter <name|mac>\fR
- Specify adapter to use by his Name or \s-1MAC\s0 address
- (if this option does not defined \- default adapter used)
-.PP
-\&\fB\-c, \-\-connect <name|mac>\fR
- Connect all supported audio profiles on the device
-.PP
-\&\fB\-d, \-\-disconnect <name|mac>\fR
- Disconnect all audio profiles on the device
-.SH "AUTHOR"
-.IX Header "AUTHOR"
-Alexander Orlenko <zxteam@gmail.com>.
-.SH "SEE ALSO"
-.IX Header "SEE ALSO"
-\&\fIbt\-adapter\fR\|(1) \fIbt\-agent\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-input\fR\|(1) \fIbt\-monitor\fR\|(1) \fIbt\-network\fR\|(1) \fIbt\-serial\fR\|(1)
diff --git a/src/bt-audio.c b/src/bt-audio.c
deleted file mode 100644
index e163503..0000000
--- a/src/bt-audio.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- *
- * 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 <locale.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <glib.h>
-
-#include "lib/dbus-common.h"
-#include "lib/helpers.h"
-#include "lib/bluez-api.h"
-
-static void audio_property_changed(Audio *audio, const gchar *name, const GValue *value, gpointer data)
-{
- g_assert(data != NULL);
- GMainLoop *mainloop = data;
-
- if (g_strcmp0(name, "State") == 0) {
- if (g_ascii_strcasecmp(g_value_get_string(value), "connecting") == 0) {
- g_print("Connecting to an audio service\n");
- } else if (g_ascii_strcasecmp(g_value_get_string(value), "connected") == 0) {
- g_print("Audio service is connected\n");
- g_main_loop_quit(mainloop);
- } else {
- g_print("Audio service is disconnected\n");
- g_main_loop_quit(mainloop);
- }
- }
-}
-
-static gchar *adapter_arg = NULL;
-static gchar *connect_arg = NULL;
-static gchar *disconnect_arg = NULL;
-
-static GOptionEntry entries[] = {
- {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter Name or MAC", "<name|mac>"},
- {"connect", 'c', 0, G_OPTION_ARG_STRING, &connect_arg, "Connect to the audio device", "<name|mac>"},
- {"disconnect", 'd', 0, G_OPTION_ARG_STRING, &disconnect_arg, "Disconnect from the audio device", "<name|mac>"},
- {NULL}
-};
-
-int main(int argc, char *argv[])
-{
- GError *error = NULL;
- GOptionContext *context;
-
- /* Query current locale */
- setlocale(LC_CTYPE, "");
-
- g_type_init();
- dbus_init();
-
- context = g_option_context_new("- a bluetooth generic audio manager");
- g_option_context_add_main_entries(context, entries, NULL);
- g_option_context_set_summary(context, "Version "PACKAGE_VERSION);
- g_option_context_set_description(context,
- //"Report bugs to <"PACKAGE_BUGREPORT">."
- "Project home page <"PACKAGE_URL">."
- );
-
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- g_print("%s: %s\n", g_get_prgname(), error->message);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- } else if ((!connect_arg || strlen(connect_arg) == 0) && (!disconnect_arg || strlen(disconnect_arg) == 0)) {
- g_print("%s", g_option_context_get_help(context, FALSE, NULL));
- exit(EXIT_FAILURE);
- }
-
- g_option_context_free(context);
-
- if (!dbus_system_connect(&error)) {
- g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- /* Check, that bluetooth daemon is running */
- if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) {
- g_printerr("%s: bluez service is not found\n", g_get_prgname());
- g_printerr("Did you forget to run bluetoothd?\n");
- exit(EXIT_FAILURE);
- }
-
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
-
- Device *device = find_device(adapter, connect_arg != NULL ? connect_arg : disconnect_arg, &error);
- exit_if_error(error);
-
- if (!intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), AUDIO_DBUS_INTERFACE)) {
- g_printerr("Audio service is not supported by this device\n");
- exit(EXIT_FAILURE);
- }
-
- GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
-
- Audio *audio = g_object_new(AUDIO_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL);
- g_signal_connect(audio, "PropertyChanged", G_CALLBACK(audio_property_changed), mainloop);
-
- if (connect_arg) {
- if (g_ascii_strcasecmp(audio_get_state(audio), "connected") == 0) {
- g_print("Audio service is already connected\n");
- } else if (g_ascii_strcasecmp(audio_get_state(audio), "connecting") == 0) {
- g_print("Audio service is already in connection state\n");
- } else {
- audio_connect(audio, &error);
- exit_if_error(error);
- g_main_loop_run(mainloop);
- }
- } else if (disconnect_arg) {
- if (g_ascii_strcasecmp(audio_get_state(audio), "disconnected") == 0) {
- g_print("Audio service is already disconnected\n");
- } else {
- audio_disconnect(audio, &error);
- exit_if_error(error);
- g_main_loop_run(mainloop);
- }
- }
-
- g_main_loop_unref(mainloop);
- g_object_unref(audio);
- g_object_unref(device);
- g_object_unref(adapter);
- dbus_disconnect();
-
- exit(EXIT_SUCCESS);
-}
-
diff --git a/src/bt-device.1 b/src/bt-device.1
index 0cb4dfe..2bb2f94 100644
--- a/src/bt-device.1
+++ b/src/bt-device.1
@@ -1,4 +1,4 @@
-.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
+.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
@@ -38,6 +38,8 @@
. ds PI \(*p
. ds L" ``
. ds R" ''
+. ds C`
+. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
@@ -48,17 +50,24 @@
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
-.ie \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
+.\"
+.\" Avoid warning from groff about undefined register 'F'.
+.de IX
..
-. nr % 0
-. rr F
-.\}
-.el \{\
-. de IX
+.nr rF 0
+.if \n(.g .if rF .nr rF 1
+.if (\n(rF:(\n(.g==0)) \{
+. if \nF \{
+. de IX
+. tm Index:\\$1\t\\n%\t"\\$2"
..
+. if !\nF==2 \{
+. nr % 0
+. nr F 2
+. \}
+. \}
.\}
+.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
@@ -124,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "bt-device 1"
-.TH bt-device 1 "2010-11-22" "" "bluez-tools"
+.TH bt-device 1 "2014-08-01" "" "bluez-tools"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -133,7 +142,7 @@
bt\-device \- a bluetooth device manager
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
-bt-device [\s-1OPTION\s0...]
+bt-device [\s-1OPTION...\s0]
.PP
Help Options:
\-h, \-\-help
@@ -166,8 +175,8 @@ about device, discover remote device services or change device properties.
List added devices
.PP
\&\fB\-c, \-\-connect <mac>\fR
- Connect to the remote device by his \s-1MAC\s0, retrieve all \s-1SDP\s0
- records and then initiate the pairing
+ Connect to the remote device by his \s-1MAC,\s0 retrieve all \s-1SDP
+ \s0 records and then initiate the pairing
.PP
\&\fB\-d, \-\-disconnect <name|mac>\fR
Disconnects a specific remote device by terminating the
@@ -184,7 +193,7 @@ about device, discover remote device services or change device properties.
the `pattern` parameter can be used to specify specific UUIDs
.PP
\&\fB\-\-set <property> <value>\fR
- Change device properties (see \s-1DEVICE\s0 \s-1PROPERTIES\s0 section for list
+ Change device properties (see \s-1DEVICE PROPERTIES\s0 section for list
of available properties)
.PP
\&\fB\-v, \-\-verbose\fR
@@ -241,4 +250,4 @@ boolean LegacyPairing [ro]
Alexander Orlenko <zxteam@gmail.com>.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
-\&\fIbt\-adapter\fR\|(1) \fIbt\-agent\fR\|(1) \fIbt\-audio\fR\|(1) \fIbt\-input\fR\|(1) \fIbt\-monitor\fR\|(1) \fIbt\-network\fR\|(1) \fIbt\-serial\fR\|(1)
+\&\fIbt\-adapter\fR\|(1) \fIbt\-agent\fR\|(1) \fIbt\-network\fR\|(1)
diff --git a/src/bt-device.c b/src/bt-device.c
index 799ee32..3472331 100644
--- a/src/bt-device.c
+++ b/src/bt-device.c
@@ -25,27 +25,31 @@
#include <config.h>
#endif
+#include <errno.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
+#include <gio/gio.h>
#include "lib/dbus-common.h"
#include "lib/helpers.h"
+#include "lib/agent-helper.h"
#include "lib/sdp.h"
#include "lib/bluez-api.h"
-enum {
- REC,
- ATTR,
- SEQ,
- ELEM,
+enum
+{
+ REC,
+ ATTR,
+ SEQ,
+ ELEM,
- ATTR_ID,
- UUID_ID,
+ ATTR_ID,
+ UUID_ID,
- LAST_E
+ LAST_E
};
static int xml_t[LAST_E] = {0, 0, 0, 0, -1, -1};
@@ -68,411 +72,690 @@ static gboolean verbose_arg = FALSE;
static gboolean is_verbose_attr(int attr_id)
{
- if (
- attr_id == SDP_ATTR_ID_SERVICE_CLASS_ID_LIST ||
- attr_id == SDP_ATTR_ID_PROTOCOL_DESCRIPTOR_LIST ||
- attr_id == SDP_ATTR_ID_BLUETOOTH_PROFILE_DESCRIPTOR_LIST ||
- attr_id == SDP_ATTR_ID_DOCUMENTATION_URL ||
- attr_id == SDP_ATTR_ID_SERVICE_NAME ||
- attr_id == SDP_ATTR_ID_SERVICE_DESCRIPTION ||
- attr_id == SDP_ATTR_ID_PROVIDER_NAME ||
- attr_id == SDP_ATTR_ID_SECURITY_DESCRIPTION
- )
- return FALSE;
-
- return TRUE;
+ if (
+ attr_id == SDP_ATTR_ID_SERVICE_CLASS_ID_LIST ||
+ attr_id == SDP_ATTR_ID_PROTOCOL_DESCRIPTOR_LIST ||
+ attr_id == SDP_ATTR_ID_BLUETOOTH_PROFILE_DESCRIPTOR_LIST ||
+ attr_id == SDP_ATTR_ID_DOCUMENTATION_URL ||
+ attr_id == SDP_ATTR_ID_SERVICE_NAME ||
+ attr_id == SDP_ATTR_ID_SERVICE_DESCRIPTION ||
+ attr_id == SDP_ATTR_ID_PROVIDER_NAME ||
+ attr_id == SDP_ATTR_ID_SECURITY_DESCRIPTION
+ )
+ return FALSE;
+
+ return TRUE;
}
static const gchar *xml_get_attr_value(const gchar *attr_name, const gchar **attribute_names, const gchar **attribute_values)
{
- for (int i = 0; attribute_names[i] != NULL; i++) {
- if (g_strcmp0(attribute_names[i], attr_name) == 0) {
- return attribute_values[i];
- }
- }
-
- return NULL;
+ for (int i = 0; attribute_names[i] != NULL; i++)
+ {
+ if (g_strcmp0(attribute_names[i], attr_name) == 0)
+ {
+ return attribute_values[i];
+ }
+ }
+
+ return NULL;
}
static void xml_start_element(GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- GError **error)
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error)
{
- const gchar *id_t = xml_get_attr_value("id", attribute_names, attribute_values);
- const gchar *value_t = xml_get_attr_value("value", attribute_names, attribute_values);
-
- if (g_strcmp0(element_name, "record") == 0) {
- xml_t[REC]++;
- } else if (g_strcmp0(element_name, "attribute") == 0 && id_t) {
- int attr_id = xtoi(id_t);
- const gchar *attr_name = sdp_get_attr_id_name(attr_id);
-
- xml_t[ATTR]++;
- xml_t[ATTR_ID] = attr_id;
-
- if (!verbose_arg && is_verbose_attr(xml_t[ATTR_ID])) return;
-
- if (attr_name == NULL) {
- g_print("AttrID-%s: ", id_t);
- } else {
- g_print("%s: ", attr_name);
- }
- } else if (g_strcmp0(element_name, "sequence") == 0) {
- xml_t[SEQ]++;
- } else if (g_pattern_match_simple("*int*", element_name) && value_t) {
- xml_t[ELEM]++;
-
- if (!verbose_arg && is_verbose_attr(xml_t[ATTR_ID])) return;
-
- if (xml_t[ELEM] == 1 && xml_t[SEQ] > 1) {
- g_print("\n");
- for (int i = 0; i < xml_t[SEQ]; i++) g_print(" ");
- } else if (xml_t[ELEM] > 1) {
- g_print(", ");
- }
-
- if (xml_t[UUID_ID] == SDP_UUID_RFCOMM) {
- g_print("Channel: %d", xtoi(value_t));
- } else {
- g_print("0x%x", xtoi(value_t));
- }
- } else if (g_strcmp0(element_name, "uuid") == 0 && value_t) {
- int uuid_id = -1;
- const gchar *uuid_name;
-
- if (value_t[0] == '0' && value_t[1] == 'x') {
- uuid_id = xtoi(value_t);
- uuid_name = sdp_get_uuid_name(uuid_id);
- } else {
- uuid_name = uuid2name(value_t);
- }
-
- xml_t[ELEM]++;
- xml_t[UUID_ID] = uuid_id;
-
- if (!verbose_arg && is_verbose_attr(xml_t[ATTR_ID])) return;
-
- if (xml_t[ELEM] == 1 && xml_t[SEQ] > 1) {
- g_print("\n");
- for (int i = 0; i < xml_t[SEQ]; i++) g_print(" ");
- } else if (xml_t[ELEM] > 1) {
- g_print(", ");
- }
-
- if (uuid_name == NULL) {
- g_print("\"UUID-%s\"", value_t);
- } else {
- g_print("\"%s\"", uuid_name);
- }
- } else if (g_strcmp0(element_name, "text") == 0 && value_t) {
- xml_t[ELEM]++;
-
- if (!verbose_arg && is_verbose_attr(xml_t[ATTR_ID])) return;
-
- if (xml_t[ELEM] == 1 && xml_t[SEQ] > 1) {
- g_print("\n");
- for (int i = 0; i < xml_t[SEQ]; i++) g_print(" ");
- } else if (xml_t[ELEM] > 1) {
- g_print(", ");
- }
-
- g_print("\"%s\"", value_t);
- } else if (g_strcmp0(element_name, "boolean") == 0 && value_t) {
- xml_t[ELEM]++;
-
- if (!verbose_arg && is_verbose_attr(xml_t[ATTR_ID])) return;
-
- if (xml_t[ELEM] == 1 && xml_t[SEQ] > 1) {
- g_print("\n");
- for (int i = 0; i < xml_t[SEQ]; i++) g_print(" ");
- } else if (xml_t[ELEM] > 1) {
- g_print(", ");
- }
-
- g_print("%s", value_t);
- } else {
- if (error)
- *error = g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, "Invalid XML element: %s", element_name);
- }
+ const gchar *id_t = xml_get_attr_value("id", attribute_names, attribute_values);
+ const gchar *value_t = xml_get_attr_value("value", attribute_names, attribute_values);
+
+ if (g_strcmp0(element_name, "record") == 0)
+ {
+ xml_t[REC]++;
+ }
+ else if (g_strcmp0(element_name, "attribute") == 0 && id_t)
+ {
+ int attr_id = xtoi(id_t);
+ const gchar *attr_name = sdp_get_attr_id_name(attr_id);
+
+ xml_t[ATTR]++;
+ xml_t[ATTR_ID] = attr_id;
+
+ if (!verbose_arg && is_verbose_attr(xml_t[ATTR_ID])) return;
+
+ if (attr_name == NULL)
+ {
+ g_print("AttrID-%s: ", id_t);
+ }
+ else
+ {
+ g_print("%s: ", attr_name);
+ }
+ }
+ else if (g_strcmp0(element_name, "sequence") == 0)
+ {
+ xml_t[SEQ]++;
+ }
+ else if (g_pattern_match_simple("*int*", element_name) && value_t)
+ {
+ xml_t[ELEM]++;
+
+ if (!verbose_arg && is_verbose_attr(xml_t[ATTR_ID])) return;
+
+ if (xml_t[ELEM] == 1 && xml_t[SEQ] > 1)
+ {
+ g_print("\n");
+ for (int i = 0; i < xml_t[SEQ]; i++) g_print(" ");
+ }
+ else if (xml_t[ELEM] > 1)
+ {
+ g_print(", ");
+ }
+
+ if (xml_t[UUID_ID] == SDP_UUID_RFCOMM)
+ {
+ g_print("Channel: %d", xtoi(value_t));
+ }
+ else
+ {
+ g_print("0x%x", xtoi(value_t));
+ }
+ }
+ else if (g_strcmp0(element_name, "uuid") == 0 && value_t)
+ {
+ int uuid_id = -1;
+ const gchar *uuid_name;
+
+ if (value_t[0] == '0' && value_t[1] == 'x')
+ {
+ uuid_id = xtoi(value_t);
+ uuid_name = sdp_get_uuid_name(uuid_id);
+ }
+ else
+ {
+ uuid_name = uuid2name(value_t);
+ }
+
+ xml_t[ELEM]++;
+ xml_t[UUID_ID] = uuid_id;
+
+ if (!verbose_arg && is_verbose_attr(xml_t[ATTR_ID])) return;
+
+ if (xml_t[ELEM] == 1 && xml_t[SEQ] > 1)
+ {
+ g_print("\n");
+ for (int i = 0; i < xml_t[SEQ]; i++) g_print(" ");
+ }
+ else if (xml_t[ELEM] > 1)
+ {
+ g_print(", ");
+ }
+
+ if (uuid_name == NULL)
+ {
+ g_print("\"UUID-%s\"", value_t);
+ }
+ else
+ {
+ g_print("\"%s\"", uuid_name);
+ }
+ }
+ else if (g_strcmp0(element_name, "text") == 0 && value_t)
+ {
+ xml_t[ELEM]++;
+
+ if (!verbose_arg && is_verbose_attr(xml_t[ATTR_ID])) return;
+
+ if (xml_t[ELEM] == 1 && xml_t[SEQ] > 1)
+ {
+ g_print("\n");
+ for (int i = 0; i < xml_t[SEQ]; i++) g_print(" ");
+ }
+ else if (xml_t[ELEM] > 1)
+ {
+ g_print(", ");
+ }
+
+ g_print("\"%s\"", value_t);
+ }
+ else if (g_strcmp0(element_name, "boolean") == 0 && value_t)
+ {
+ xml_t[ELEM]++;
+
+ if (!verbose_arg && is_verbose_attr(xml_t[ATTR_ID])) return;
+
+ if (xml_t[ELEM] == 1 && xml_t[SEQ] > 1)
+ {
+ g_print("\n");
+ for (int i = 0; i < xml_t[SEQ]; i++) g_print(" ");
+ }
+ else if (xml_t[ELEM] > 1)
+ {
+ g_print(", ");
+ }
+
+ g_print("%s", value_t);
+ }
+ else
+ {
+ if (error)
+ *error = g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, "Invalid XML element: %s", element_name);
+ }
}
static void xml_end_element(GMarkupParseContext *context,
- const gchar *element_name,
- gpointer user_data,
- GError **error)
+ const gchar *element_name,
+ gpointer user_data,
+ GError **error)
{
- if (g_strcmp0(element_name, "record") == 0) {
- xml_t[ATTR] = 0;
- xml_t[SEQ] = 0;
- xml_t[ELEM] = 0;
-
- xml_t[ATTR_ID] = -1;
- xml_t[UUID_ID] = -1;
- } else if (g_strcmp0(element_name, "attribute") == 0) {
- xml_t[SEQ] = 0;
- xml_t[ELEM] = 0;
-
- int old_attr_id = xml_t[ATTR_ID];
- xml_t[ATTR_ID] = -1;
- xml_t[UUID_ID] = -1;
-
- if (!verbose_arg && is_verbose_attr(old_attr_id)) return;
-
- g_print("\n");
- } else if (g_strcmp0(element_name, "sequence") == 0) {
- xml_t[SEQ]--;
- xml_t[ELEM] = 0;
-
- xml_t[UUID_ID] = -1;
- }
+ if (g_strcmp0(element_name, "record") == 0)
+ {
+ xml_t[ATTR] = 0;
+ xml_t[SEQ] = 0;
+ xml_t[ELEM] = 0;
+
+ xml_t[ATTR_ID] = -1;
+ xml_t[UUID_ID] = -1;
+ }
+ else if (g_strcmp0(element_name, "attribute") == 0)
+ {
+ xml_t[SEQ] = 0;
+ xml_t[ELEM] = 0;
+
+ int old_attr_id = xml_t[ATTR_ID];
+ xml_t[ATTR_ID] = -1;
+ xml_t[UUID_ID] = -1;
+
+ if (!verbose_arg && is_verbose_attr(old_attr_id)) return;
+
+ g_print("\n");
+ }
+ else if (g_strcmp0(element_name, "sequence") == 0)
+ {
+ xml_t[SEQ]--;
+ xml_t[ELEM] = 0;
+
+ xml_t[UUID_ID] = -1;
+ }
}
static void create_paired_device_done(gpointer data)
{
- g_assert(data != NULL);
- GMainLoop *mainloop = data;
- g_main_loop_quit(mainloop);
+ g_assert(data != NULL);
+ GMainLoop *mainloop = data;
+ g_main_loop_quit(mainloop);
+}
+
+static void _bt_device_pair_callback(GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ g_assert(user_data != NULL);
+ GHashTable *dict = (GHashTable *) user_data;
+ Device *device = (Device *) g_hash_table_lookup(dict, "device");
+ GError *error = NULL;
+ device_pair_finish(device, res, &error);
+ exit_if_error(error);
+ GMainLoop *mainloop = (GMainLoop *) g_hash_table_lookup(dict, "mainloop");
+ g_main_loop_quit(mainloop);
+}
+
+
+
+static GHashTable *_bt_device_sdp_browse(const gchar *device_path, const gchar *pattern)
+{
+ int pipefd[2];
+ pipe(pipefd);
+
+ // Fork the process into a child process to make an exec call
+ int pid = fork();
+
+ // Child (to call sdptool)
+ if (pid == 0)
+ {
+ // close reading end in the child
+ close(pipefd[0]);
+
+ // send stdout to the pipe
+ dup2(pipefd[1], 1);
+ // send stderr to the pipe
+ dup2(pipefd[1], 2);
+
+ // this descriptor is no longer needed
+ close(pipefd[1]);
+
+ if(!g_file_test ("/bin/sdptool", G_FILE_TEST_EXISTS))
+ {
+ write(2, "sdptool not found\n", sizeof("sdptool not found\n"));
+ exit(EXIT_FAILURE);
+ }
+
+ if(pattern == NULL || strlen(pattern) == 0)
+ execl("/bin/sdptool", "/bin/sdptool", "browse", "--xml", device_path, (char *) 0);
+ else
+ execl("/bin/sdptool", "/bin/sdptool", "browse", "--xml", "--uuid", pattern, device_path, (char *) 0);
+
+ }
+ if(pid == -1)
+ {
+ perror("forking process failed");
+ exit(EXIT_FAILURE);
+ }
+
+ close(pipefd[1]); // close the write end of the pipe in the parent
+ GInputStream *exec_output = (GInputStream *) g_unix_input_stream_new(pipefd[0], TRUE);
+ GDataInputStream *exec_data_input_stream = g_data_input_stream_new(exec_output);
+ GPtrArray *array = g_ptr_array_new();
+ guint record_counter = 0;
+ guint n = 0;
+ GError *error = NULL;
+ GString *string_buffer = g_string_new("");
+ while(TRUE)
+ {
+ n++;
+ gchar *line = g_data_input_stream_read_line_utf8(exec_data_input_stream, NULL, NULL, &error);
+ exit_if_error(error);
+ // If there is no content, then break out of the loop
+ if(!line)
+ break;
+
+ if(n == 1)
+ {
+ if(g_regex_match_simple("Failed", line, 0, 0) || g_regex_match_simple("Error", line, 0, 0))
+ {
+ g_print("%s\n", line);
+ exit(EXIT_FAILURE);
+ }
+ else if(g_regex_match_simple("not found", line, 0, 0))
+ {
+ g_print("Failed to start SDP discovery. Please make sure you have bluez-utils installed on your system.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ continue;
+ }
+
+ if(g_regex_match_simple("<\\?xml(.*)\\?>", line, 0, 0))
+ {
+ if(record_counter != 0)
+ {
+ g_ptr_array_add(array, g_string_free(string_buffer, FALSE));
+ string_buffer = g_string_new("");
+ }
+ record_counter++;
+ }
+
+ g_string_append(string_buffer, line);
+ }
+
+ g_ptr_array_add(array, g_string_free(string_buffer, FALSE));
+
+ GHashTable *sdp_hash_table = g_hash_table_new(g_int_hash, g_int_equal);
+
+ int i = 0;
+ for(i = 0; i < array->len; i++)
+ {
+ GRegex *record_id_regex = g_regex_new("<attribute id=\"0x0000\">(\\s*<uint32 value=\"(.*)\" />\\s)</attribute>", G_REGEX_CASELESS | G_REGEX_MULTILINE | G_REGEX_NEWLINE_ANYCRLF, 0, &error);
+ exit_if_error(error);
+ GMatchInfo *match_info;
+ g_regex_match (record_id_regex, (gchar *) g_ptr_array_index(array, i), 0, &match_info);
+ if(g_match_info_matches(match_info))
+ {
+ gchar *word = g_match_info_fetch(match_info, 2);
+ guint32 *key = g_new(guint32, 1);
+ *key = 0;
+ sscanf(word, "0x%x", key);
+ g_hash_table_insert(sdp_hash_table, key, (gchar *) g_ptr_array_index(array, i));
+ g_free(word);
+ }
+ g_match_info_free(match_info);
+ g_regex_unref(record_id_regex);
+ }
+
+ g_input_stream_close(exec_output, NULL, &error);
+ exit_if_error(error);
+ g_object_unref(exec_data_input_stream);
+ g_object_unref(exec_output);
+
+ g_ptr_array_unref(array);
+
+ return sdp_hash_table;
}
static GOptionEntry entries[] = {
- {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter Name or MAC", "<name|mac>"},
- {"list", 'l', 0, G_OPTION_ARG_NONE, &list_arg, "List added devices", NULL},
- {"connect", 'c', 0, G_OPTION_ARG_STRING, &connect_arg, "Connect to the remote device", "<mac>"},
- {"disconnect", 'd', 0, G_OPTION_ARG_STRING, &disconnect_arg, "Disconnect the remote device", "<name|mac>"},
- {"remove", 'r', 0, G_OPTION_ARG_STRING, &remove_arg, "Remove device", "<name|mac>"},
- {"info", 'i', 0, G_OPTION_ARG_STRING, &info_arg, "Get info about device", "<name|mac>"},
- {"services", 's', 0, G_OPTION_ARG_NONE, &services_arg, "Discover device services", NULL},
- {"set", 0, 0, G_OPTION_ARG_NONE, &set_arg, "Set device property", NULL},
- {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_arg, "Verbosely display remote service records", NULL},
- {NULL}
+ {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter Name or MAC", "<name|mac>"},
+ {"list", 'l', 0, G_OPTION_ARG_NONE, &list_arg, "List added devices", NULL},
+ {"connect", 'c', 0, G_OPTION_ARG_STRING, &connect_arg, "Connect to the remote device", "<mac>"},
+ {"disconnect", 'd', 0, G_OPTION_ARG_STRING, &disconnect_arg, "Disconnect the remote device", "<name|mac>"},
+ {"remove", 'r', 0, G_OPTION_ARG_STRING, &remove_arg, "Remove device", "<name|mac>"},
+ {"info", 'i', 0, G_OPTION_ARG_STRING, &info_arg, "Get info about device", "<name|mac>"},
+ {"services", 's', 0, G_OPTION_ARG_NONE, &services_arg, "Discover device services", NULL},
+ {"set", 0, 0, G_OPTION_ARG_NONE, &set_arg, "Set device property", NULL},
+ {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_arg, "Verbosely display remote service records", NULL},
+ {NULL}
};
int main(int argc, char *argv[])
{
- GError *error = NULL;
- GOptionContext *context;
-
- /* Query current locale */
- setlocale(LC_CTYPE, "");
-
- g_type_init();
- dbus_init();
-
- context = g_option_context_new("- a bluetooth device manager");
- g_option_context_add_main_entries(context, entries, NULL);
- g_option_context_set_summary(context, "Version "PACKAGE_VERSION);
- g_option_context_set_description(context,
- "Services Options:\n"
- " -s, --services <name|mac> [<pattern>]\n"
- " Where `pattern` is an optional specific UUID to search\n\n"
- "Set Options:\n"
- " --set <name|mac> <property> <value>\n"
- " Where\n"
- " `name|mac` is a device Name or MAC\n"
- " `property` is one of:\n"
- " Alias\n"
- " Trusted\n"
- " Blocked\n\n"
- //"Report bugs to <"PACKAGE_BUGREPORT">."
- "Project home page <"PACKAGE_URL">."
- );
-
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- g_print("%s: %s\n", g_get_prgname(), error->message);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- } else if (!list_arg && (!connect_arg || strlen(connect_arg) == 0) && (!disconnect_arg || strlen(disconnect_arg) == 0) && (!remove_arg || strlen(remove_arg) == 0) && (!info_arg || strlen(info_arg) == 0) && !services_arg && !set_arg) {
- g_print("%s", g_option_context_get_help(context, FALSE, NULL));
- exit(EXIT_FAILURE);
- } else if (services_arg && (argc != 2 || strlen(argv[1]) == 0) && (argc != 3 || strlen(argv[1]) == 0)) {
- g_print("%s: Invalid arguments for --services\n", g_get_prgname());
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- } else if (set_arg && (argc != 4 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0 || strlen(argv[3]) == 0)) {
- g_print("%s: Invalid arguments for --set\n", g_get_prgname());
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- }
-
- g_option_context_free(context);
-
- if (!dbus_system_connect(&error)) {
- g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- /* Check, that bluetooth daemon is running */
- if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) {
- g_printerr("%s: bluez service is not found\n", g_get_prgname());
- g_printerr("Did you forget to run bluetoothd?\n");
- exit(EXIT_FAILURE);
- }
-
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
-
- if (list_arg) {
- const GPtrArray *devices_list = adapter_get_devices(adapter);
- g_assert(devices_list != NULL);
-
- if (devices_list->len == 0) {
- g_print("No devices found\n");
- exit(EXIT_FAILURE);
- }
-
- g_print("Added devices:\n");
- for (int i = 0; i < devices_list->len; i++) {
- const gchar *device_path = g_ptr_array_index(devices_list, i);
- Device *device = g_object_new(DEVICE_TYPE, "DBusObjectPath", device_path, NULL);
- g_print("%s (%s)\n", device_get_alias(device), device_get_address(device));
- g_object_unref(device);
- }
- } else if (connect_arg) {
- g_print("Connecting to: %s\n", connect_arg);
- Agent *agent = g_object_new(AGENT_TYPE, NULL);
- GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
-
- adapter_create_paired_device_begin(adapter, create_paired_device_done, mainloop, connect_arg, AGENT_DBUS_PATH, "DisplayYesNo");
- g_main_loop_run(mainloop);
- gchar *created_device = adapter_create_paired_device_end(adapter, &error);
- exit_if_error(error);
-
- g_print("Done\n");
- g_main_loop_unref(mainloop);
- g_free(created_device);
- g_object_unref(agent);
- } else if (disconnect_arg) {
- Device *device = find_device(adapter, disconnect_arg, &error);
- exit_if_error(error);
-
- g_print("Disconnecting: %s\n", disconnect_arg);
- device_disconnect(device, &error);
- exit_if_error(error);
-
- g_print("Done\n");
- g_object_unref(device);
- } else if (remove_arg) {
- Device *device = find_device(adapter, remove_arg, &error);
- exit_if_error(error);
-
- adapter_remove_device(adapter, device_get_dbus_object_path(device), &error);
- exit_if_error(error);
-
- g_print("Done\n");
- g_object_unref(device);
- } else if (info_arg) {
- Device *device = find_device(adapter, info_arg, &error);
- exit_if_error(error);
-
- g_print("[%s]\n", device_get_address(device));
- g_print(" Name: %s\n", device_get_name(device));
- g_print(" Alias: %s [rw]\n", device_get_alias(device));
- g_print(" Address: %s\n", device_get_address(device));
- g_print(" Icon: %s\n", device_get_icon(device));
- g_print(" Class: 0x%x\n", device_get_class(device));
- g_print(" Paired: %d\n", device_get_paired(device));
- g_print(" Trusted: %d [rw]\n", device_get_trusted(device));
- g_print(" Blocked: %d [rw]\n", device_get_blocked(device));
- g_print(" Connected: %d\n", device_get_connected(device));
- g_print(" UUIDs: [");
- const gchar **uuids = device_get_uuids(device);
- for (int j = 0; uuids[j] != NULL; j++) {
- if (j > 0) g_print(", ");
- g_print("%s", uuid2name(uuids[j]));
- }
- g_print("]\n");
-
- g_object_unref(device);
- } else if (services_arg) {
- services_device_arg = argv[1];
- if (argc == 3) {
- services_pattern_arg = argv[2];
- }
-
- Device *device = find_device(adapter, services_device_arg, &error);
- exit_if_error(error);
-
- g_print("Discovering services...\n");
- GHashTable *device_services = device_discover_services(device, name2uuid(services_pattern_arg), &error);
- exit_if_error(error);
-
- GHashTableIter iter;
- gpointer key, value;
-
- g_hash_table_iter_init(&iter, device_services);
- int n = 0;
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- n++;
- if (n == 1) g_print("\n");
- g_print("[RECORD:%d]\n", (gint) key);
- GMarkupParser xml_parser = {xml_start_element, xml_end_element, NULL, NULL, NULL};
- GMarkupParseContext *xml_parse_context = g_markup_parse_context_new(&xml_parser, 0, NULL, NULL);
- g_markup_parse_context_parse(xml_parse_context, value, strlen(value), &error);
- exit_if_error(error);
- g_markup_parse_context_free(xml_parse_context);
- g_print("\n");
- }
-
- g_print("Done\n");
- g_object_unref(device);
- } else if (set_arg) {
- set_device_arg = argv[1];
- set_property_arg = argv[2];
- set_value_arg = argv[3];
-
- Device *device = find_device(adapter, set_device_arg, &error);
- exit_if_error(error);
-
- GValue v = {0,};
-
- if (g_strcmp0(set_property_arg, "Alias") == 0) {
- g_value_init(&v, G_TYPE_STRING);
- g_value_set_string(&v, set_value_arg);
- } else if (
- g_strcmp0(set_property_arg, "Trusted") == 0 ||
- g_strcmp0(set_property_arg, "Blocked") == 0
- ) {
- g_value_init(&v, G_TYPE_BOOLEAN);
-
- if (g_strcmp0(set_value_arg, "0") == 0 || g_ascii_strcasecmp(set_value_arg, "FALSE") == 0 || g_ascii_strcasecmp(set_value_arg, "OFF") == 0) {
- g_value_set_boolean(&v, FALSE);
- } else if (g_strcmp0(set_value_arg, "1") == 0 || g_ascii_strcasecmp(set_value_arg, "TRUE") == 0 || g_ascii_strcasecmp(set_value_arg, "ON") == 0) {
- g_value_set_boolean(&v, TRUE);
- } else {
- g_print("%s: Invalid boolean value: %s\n", g_get_prgname(), set_value_arg);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- }
- } else {
- g_print("%s: Invalid property: %s\n", g_get_prgname(), set_property_arg);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- }
-
- GHashTable *props = device_get_properties(device, &error);
- exit_if_error(error);
- GValue *old_value = g_hash_table_lookup(props, set_property_arg);
- g_assert(old_value != NULL);
- if (G_VALUE_HOLDS_STRING(old_value)) {
- g_print("%s: %s -> %s\n", set_property_arg, g_value_get_string(old_value), g_value_get_string(&v));
- } else if (G_VALUE_HOLDS_BOOLEAN(old_value)) {
- g_print("%s: %d -> %d\n", set_property_arg, g_value_get_boolean(old_value), g_value_get_boolean(&v));
- }
- g_hash_table_unref(props);
-
- device_set_property(device, set_property_arg, &v, &error);
- exit_if_error(error);
-
- g_value_unset(&v);
- g_object_unref(device);
- }
-
- g_object_unref(adapter);
- dbus_disconnect();
-
- exit(EXIT_SUCCESS);
+ GError *error = NULL;
+ GOptionContext *context;
+
+ /* Query current locale */
+ setlocale(LC_CTYPE, "");
+
+ /* Deprecated */
+ // g_type_init();
+ dbus_init();
+
+ context = g_option_context_new("- a bluetooth device manager");
+ g_option_context_add_main_entries(context, entries, NULL);
+ g_option_context_set_summary(context, "Version "PACKAGE_VERSION);
+ g_option_context_set_description(context,
+ "Services Options:\n"
+ " -s, --services <name|mac> [<pattern>]\n"
+ " Where `pattern` is an optional specific UUID to search\n\n"
+ "Set Options:\n"
+ " --set <name|mac> <property> <value>\n"
+ " Where\n"
+ " `name|mac` is a device Name or MAC\n"
+ " `property` is one of:\n"
+ " Alias\n"
+ " Trusted\n"
+ " Blocked\n\n"
+ "Report bugs to <"PACKAGE_BUGREPORT">."
+ "Project home page <"PACKAGE_URL">."
+ );
+
+ if (!g_option_context_parse(context, &argc, &argv, &error))
+ {
+ g_print("%s: %s\n", g_get_prgname(), error->message);
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+ else if (!list_arg && (!connect_arg || strlen(connect_arg) == 0) && (!disconnect_arg || strlen(disconnect_arg) == 0) && (!remove_arg || strlen(remove_arg) == 0) && (!info_arg || strlen(info_arg) == 0) && !services_arg && !set_arg)
+ {
+ g_print("%s", g_option_context_get_help(context, FALSE, NULL));
+ exit(EXIT_FAILURE);
+ }
+ else if (services_arg && (argc != 2 || strlen(argv[1]) == 0) && (argc != 3 || strlen(argv[1]) == 0))
+ {
+ g_print("%s: Invalid arguments for --services\n", g_get_prgname());
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+ else if (set_arg && (argc != 4 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0 || strlen(argv[3]) == 0))
+ {
+ g_print("%s: Invalid arguments for --set\n", g_get_prgname());
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+
+ g_option_context_free(context);
+
+ if (!dbus_system_connect(&error))
+ {
+ g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Check, that bluetooth daemon is running */
+ if (!intf_supported(BLUEZ_DBUS_SERVICE_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE))
+ {
+ g_printerr("%s: bluez service is not found\n", g_get_prgname());
+ g_printerr("Did you forget to run bluetoothd?\n");
+ exit(EXIT_FAILURE);
+ }
+
+ Manager *manager = manager_new();
+ Adapter *adapter = find_adapter(adapter_arg, &error);
+ exit_if_error(error);
+
+ if (list_arg)
+ {
+ const gchar **devices_list = manager_get_devices(manager, adapter_get_dbus_object_path(adapter));
+
+ if (devices_list == NULL)
+ {
+ g_print("No devices found\n");
+ exit(EXIT_FAILURE);
+ }
+
+ g_print("Added devices:\n");
+ const gchar **devices = NULL;
+ for (devices = devices_list; *devices != NULL; devices++)
+ {
+ const gchar *device_path = *devices;
+ Device *device = device_new(device_path);
+ g_print("%s (%s)\n", device_get_alias(device, &error), device_get_address(device, &error));
+ exit_if_error(error);
+ g_object_unref(device);
+ }
+ }
+ else if (connect_arg)
+ {
+ g_print("Connecting to: %s\n", connect_arg);
+ GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
+
+ AgentManager *agent_manager = agent_manager_new();
+
+ agent_need_unregister = TRUE;
+
+ register_agent_callbacks(TRUE, NULL, mainloop, &error);
+ exit_if_error(error);
+
+ agent_manager_register_agent(agent_manager, AGENT_PATH, "DisplayYesNo", &error);
+ exit_if_error(error);
+
+ Device *device = find_device(adapter, connect_arg, &error);
+ exit_if_error(error);
+ if(!device)
+ {
+ g_printerr("Error: Device not found.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ GHashTable *user_data_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ g_hash_table_insert(user_data_hash, "device", device);
+ g_hash_table_insert(user_data_hash, "mainloop", mainloop);
+
+ device_pair_async(device, (GAsyncReadyCallback) _bt_device_pair_callback, (gpointer) user_data_hash);
+ g_main_loop_run(mainloop);
+
+ g_print("Done\n");
+ g_hash_table_unref(user_data_hash);
+ g_main_loop_unref(mainloop);
+ g_object_unref(device);
+ unregister_agent_callbacks(&error);
+ }
+ else if (disconnect_arg)
+ {
+ Device *device = find_device(adapter, disconnect_arg, &error);
+ exit_if_error(error);
+ if(!device)
+ {
+ g_printerr("Error: Device not found.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ g_print("Disconnecting: %s\n", disconnect_arg);
+ device_disconnect(device, &error);
+ exit_if_error(error);
+
+ g_print("Done\n");
+ g_object_unref(device);
+ }
+ else if (remove_arg)
+ {
+ Device *device = find_device(adapter, remove_arg, &error);
+ exit_if_error(error);
+ if(!device)
+ {
+ g_printerr("Error: Device not found.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ adapter_remove_device(adapter, device_get_dbus_object_path(device), &error);
+ exit_if_error(error);
+
+ g_print("Done\n");
+ g_object_unref(device);
+ }
+ else if (info_arg)
+ {
+ Device *device = find_device(adapter, info_arg, &error);
+ exit_if_error(error);
+ if(!device)
+ {
+ g_printerr("Error: Device not found.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ g_print("[%s]\n", device_get_address(device, &error));
+ g_print(" Name: %s\n", device_get_name(device, &error));
+ g_print(" Alias: %s [rw]\n", device_get_alias(device, &error));
+ g_print(" Address: %s\n", device_get_address(device, &error));
+ g_print(" Icon: %s\n", device_get_icon(device, &error));
+ g_print(" Class: 0x%x\n", device_get_class(device, &error));
+ g_print(" Paired: %d\n", device_get_paired(device, &error));
+ g_print(" Trusted: %d [rw]\n", device_get_trusted(device, &error));
+ g_print(" Blocked: %d [rw]\n", device_get_blocked(device, &error));
+ g_print(" Connected: %d\n", device_get_connected(device, &error));
+ g_print(" UUIDs: [");
+ const gchar **uuids = device_get_uuids(device, &error);
+ for (int j = 0; uuids[j] != NULL; j++)
+ {
+ if (j > 0) g_print(", ");
+ g_print("%s", uuid2name(uuids[j]));
+ }
+ g_print("]\n");
+
+ g_object_unref(device);
+ }
+ else if (services_arg)
+ {
+ services_device_arg = argv[1];
+ if (argc == 3)
+ {
+ services_pattern_arg = argv[2];
+ }
+
+ Device *device = find_device(adapter, services_device_arg, &error);
+ exit_if_error(error);
+ if(!device)
+ {
+ g_printerr("Error: Device not found.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ const gchar *device_address = device_get_address(device, &error);
+ exit_if_error(error);
+
+ g_print("Discovering services...\n");
+ // Because BlueZ 5 removed the API call for discover services, we will use sdptool as an alternative
+ // GHashTable *device_services = device_discover_services(device, name2uuid(services_pattern_arg), &error);
+ GHashTable *device_services = _bt_device_sdp_browse(device_address, name2uuid(services_pattern_arg));
+ exit_if_error(error);
+
+
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, device_services);
+ int n = 0;
+ while (g_hash_table_iter_next(&iter, &key, &value))
+ {
+ n++;
+ if (n == 1) g_print("\n");
+ // g_print("[RECORD:%d]\n", (gint) key);
+ g_print("[RECORD:0x%x]\n", *(guint32 *) key);
+ GMarkupParser xml_parser = {xml_start_element, xml_end_element, NULL, NULL, NULL};
+ GMarkupParseContext *xml_parse_context = g_markup_parse_context_new(&xml_parser, 0, NULL, NULL);
+ g_markup_parse_context_parse(xml_parse_context, value, strlen(value), &error);
+ exit_if_error(error);
+ g_markup_parse_context_free(xml_parse_context);
+ g_print("\n");
+ }
+
+ g_print("Done\n");
+ g_hash_table_unref(device_services);
+ g_object_unref(device);
+ }
+ else if (set_arg)
+ {
+ set_device_arg = argv[1];
+ set_property_arg = argv[2];
+ set_value_arg = argv[3];
+
+ Device *device = find_device(adapter, set_device_arg, &error);
+ exit_if_error(error);
+ if(!device)
+ {
+ g_printerr("Error: Device not found.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ GVariant *v = NULL;
+
+ if (g_strcmp0(set_property_arg, "Alias") == 0)
+ {
+ v = g_variant_new_string(set_value_arg);
+ }
+ else if (
+ g_strcmp0(set_property_arg, "Trusted") == 0 ||
+ g_strcmp0(set_property_arg, "Blocked") == 0
+ )
+ {
+ if (g_strcmp0(set_value_arg, "0") == 0 || g_ascii_strcasecmp(set_value_arg, "FALSE") == 0 || g_ascii_strcasecmp(set_value_arg, "OFF") == 0)
+ {
+ v = g_variant_new_boolean(FALSE);
+ }
+ else if (g_strcmp0(set_value_arg, "1") == 0 || g_ascii_strcasecmp(set_value_arg, "TRUE") == 0 || g_ascii_strcasecmp(set_value_arg, "ON") == 0)
+ {
+ v = g_variant_new_boolean(TRUE);
+ }
+ else
+ {
+ g_print("%s: Invalid boolean value: %s\n", g_get_prgname(), set_value_arg);
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+ }
+ else
+ {
+ g_print("%s: Invalid property: %s\n", g_get_prgname(), set_property_arg);
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+
+ GVariant *props = device_get_properties(device, &error);
+ exit_if_error(error);
+
+ if(g_ascii_strcasecmp(set_property_arg, "Alias") == 0)
+ device_set_alias(device, g_variant_get_string(v, NULL), &error);
+ else if(g_ascii_strcasecmp(set_property_arg, "Blocked") == 0)
+ device_set_blocked(device, g_variant_get_boolean(v), &error);
+ else if(g_ascii_strcasecmp(set_property_arg, "Trusted") == 0)
+ device_set_trusted(device, g_variant_get_boolean(v), &error);
+
+ exit_if_error(error);
+
+ GVariant *old_value = g_variant_lookup_value(props, set_property_arg, NULL);
+ g_assert(old_value != NULL);
+ if (g_variant_type_equal(G_VARIANT_TYPE_STRING, g_variant_get_type(old_value)))
+ {
+ g_print("%s: %s -> %s\n", set_property_arg, g_variant_get_string(old_value, NULL), g_variant_get_string(v, NULL));
+ }
+ else if (g_variant_type_equal(G_VARIANT_TYPE_BOOLEAN, g_variant_get_type(old_value)))
+ {
+ g_print("%s: %u -> %u\n", set_property_arg, g_variant_get_boolean(old_value), g_variant_get_boolean(v));
+ }
+ g_variant_unref(props);
+
+ // g_variant_unref(v); /* Floating references do not need to be unref */
+ g_object_unref(device);
+ }
+
+ g_object_unref(adapter);
+ dbus_disconnect();
+
+ exit(EXIT_SUCCESS);
}
-
diff --git a/src/bt-input.1 b/src/bt-input.1
deleted file mode 100644
index ef6602f..0000000
--- a/src/bt-input.1
+++ /dev/null
@@ -1,167 +0,0 @@
-.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
-.\"
-.\" Standard preamble:
-.\" ========================================================================
-.de Sp \" Vertical space (when we can't use .PP)
-.if t .sp .5v
-.if n .sp
-..
-.de Vb \" Begin verbatim text
-.ft CW
-.nf
-.ne \\$1
-..
-.de Ve \" End verbatim text
-.ft R
-.fi
-..
-.\" Set up some character translations and predefined strings. \*(-- will
-.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
-.\" double quote, and \*(R" will give a right double quote. \*(C+ will
-.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
-.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
-.\" nothing in troff, for use with C<>.
-.tr \(*W-
-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
-.ie n \{\
-. ds -- \(*W-
-. ds PI pi
-. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
-. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
-. ds L" ""
-. ds R" ""
-. ds C` ""
-. ds C' ""
-'br\}
-.el\{\
-. ds -- \|\(em\|
-. ds PI \(*p
-. ds L" ``
-. ds R" ''
-'br\}
-.\"
-.\" Escape single quotes in literal strings from groff's Unicode transform.
-.ie \n(.g .ds Aq \(aq
-.el .ds Aq '
-.\"
-.\" If the F register is turned on, we'll generate index entries on stderr for
-.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
-.\" entries marked with X<> in POD. Of course, you'll have to process the
-.\" output yourself in some meaningful fashion.
-.ie \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
-..
-. nr % 0
-. rr F
-.\}
-.el \{\
-. de IX
-..
-.\}
-.\"
-.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
-.\" Fear. Run. Save yourself. No user-serviceable parts.
-. \" fudge factors for nroff and troff
-.if n \{\
-. ds #H 0
-. ds #V .8m
-. ds #F .3m
-. ds #[ \f1
-. ds #] \fP
-.\}
-.if t \{\
-. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
-. ds #V .6m
-. ds #F 0
-. ds #[ \&
-. ds #] \&
-.\}
-. \" simple accents for nroff and troff
-.if n \{\
-. ds ' \&
-. ds ` \&
-. ds ^ \&
-. ds , \&
-. ds ~ ~
-. ds /
-.\}
-.if t \{\
-. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
-. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
-. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
-. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
-. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
-. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
-.\}
-. \" troff and (daisy-wheel) nroff accents
-.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
-.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
-.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
-.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
-.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
-.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
-.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
-.ds ae a\h'-(\w'a'u*4/10)'e
-.ds Ae A\h'-(\w'A'u*4/10)'E
-. \" corrections for vroff
-.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
-.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
-. \" for low resolution devices (crt and lpr)
-.if \n(.H>23 .if \n(.V>19 \
-\{\
-. ds : e
-. ds 8 ss
-. ds o a
-. ds d- d\h'-1'\(ga
-. ds D- D\h'-1'\(hy
-. ds th \o'bp'
-. ds Th \o'LP'
-. ds ae ae
-. ds Ae AE
-.\}
-.rm #[ #] #H #V #F C
-.\" ========================================================================
-.\"
-.IX Title "bt-input 1"
-.TH bt-input 1 "2010-08-11" "" "bluez-tools"
-.\" For nroff, turn off justification. Always turn off hyphenation; it makes
-.\" way too many mistakes in technical documents.
-.if n .ad l
-.nh
-.SH "NAME"
-bt\-input \- a bluetooth input manager
-.SH "SYNOPSIS"
-.IX Header "SYNOPSIS"
-bt-input [\s-1OPTION\s0...]
-.PP
-Help Options:
- \-h, \-\-help
-.PP
-Application Options:
- \-a, \-\-adapter=<name|mac>
- \-c, \-\-connect=<name|mac>
- \-d, \-\-disconnect=<name|mac>
-.SH "DESCRIPTION"
-.IX Header "DESCRIPTION"
-This utility is used to manage outgoing input (\s-1HID\s0) service connections.
-.SH "OPTIONS"
-.IX Header "OPTIONS"
-\&\fB\-h, \-\-help\fR
- Show help
-.PP
-\&\fB\-a, \-\-adapter <name|mac>\fR
- Specify adapter to use by his Name or \s-1MAC\s0 address
- (if this option does not defined \- default adapter used)
-.PP
-\&\fB\-c, \-\-connect <name|mac>\fR
- Connect to the input device
-.PP
-\&\fB\-d, \-\-disconnect <name|mac>\fR
- Disconnect from the input device
-.SH "AUTHOR"
-.IX Header "AUTHOR"
-Alexander Orlenko <zxteam@gmail.com>.
-.SH "SEE ALSO"
-.IX Header "SEE ALSO"
-\&\fIbt\-adapter\fR\|(1) \fIbt\-agent\fR\|(1) \fIbt\-audio\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-monitor\fR\|(1) \fIbt\-network\fR\|(1) \fIbt\-serial\fR\|(1)
diff --git a/src/bt-input.c b/src/bt-input.c
deleted file mode 100644
index 2b0b36e..0000000
--- a/src/bt-input.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- *
- * 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 <locale.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <glib.h>
-
-#include "lib/dbus-common.h"
-#include "lib/helpers.h"
-#include "lib/bluez-api.h"
-
-static void input_property_changed(Input *input, const gchar *name, const GValue *value, gpointer data)
-{
- g_assert(data != NULL);
- GMainLoop *mainloop = data;
-
- if (g_strcmp0(name, "Connected") == 0) {
- if (g_value_get_boolean(value) == TRUE) {
- g_print("Input service is connected\n");
- } else {
- g_print("Input service is disconnected\n");
- }
- g_main_loop_quit(mainloop);
- }
-}
-
-static gchar *adapter_arg = NULL;
-static gchar *connect_arg = NULL;
-static gchar *disconnect_arg = NULL;
-
-static GOptionEntry entries[] = {
- {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter Name or MAC", "<name|mac>"},
- {"connect", 'c', 0, G_OPTION_ARG_STRING, &connect_arg, "Connect to the input device", "<name|mac>"},
- {"disconnect", 'd', 0, G_OPTION_ARG_STRING, &disconnect_arg, "Disconnect from the input device", "<name|mac>"},
- {NULL}
-};
-
-int main(int argc, char *argv[])
-{
- GError *error = NULL;
- GOptionContext *context;
-
- /* Query current locale */
- setlocale(LC_CTYPE, "");
-
- g_type_init();
- dbus_init();
-
- context = g_option_context_new("- a bluetooth input manager");
- g_option_context_add_main_entries(context, entries, NULL);
- g_option_context_set_summary(context, "Version "PACKAGE_VERSION);
- g_option_context_set_description(context,
- //"Report bugs to <"PACKAGE_BUGREPORT">."
- "Project home page <"PACKAGE_URL">."
- );
-
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- g_print("%s: %s\n", g_get_prgname(), error->message);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- } else if ((!connect_arg || strlen(connect_arg) == 0) && (!disconnect_arg || strlen(disconnect_arg) == 0)) {
- g_print("%s", g_option_context_get_help(context, FALSE, NULL));
- exit(EXIT_FAILURE);
- }
-
- g_option_context_free(context);
-
- if (!dbus_system_connect(&error)) {
- g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- /* Check, that bluetooth daemon is running */
- if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) {
- g_printerr("%s: bluez service is not found\n", g_get_prgname());
- g_printerr("Did you forget to run bluetoothd?\n");
- exit(EXIT_FAILURE);
- }
-
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
-
- Device *device = find_device(adapter, connect_arg != NULL ? connect_arg : disconnect_arg, &error);
- exit_if_error(error);
-
- if (!intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), INPUT_DBUS_INTERFACE)) {
- g_printerr("Input service is not supported by this device\n");
- exit(EXIT_FAILURE);
- }
-
- GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
-
- Input *input = g_object_new(INPUT_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL);
- g_signal_connect(input, "PropertyChanged", G_CALLBACK(input_property_changed), mainloop);
-
- if (connect_arg) {
- if (input_get_connected(input) == TRUE) {
- g_print("Input service is already connected\n");
- } else {
- input_connect(input, &error);
- exit_if_error(error);
- g_main_loop_run(mainloop);
- }
- } else if (disconnect_arg) {
- if (input_get_connected(input) == FALSE) {
- g_print("Input service is already disconnected\n");
- } else {
- input_disconnect(input, &error);
- exit_if_error(error);
- g_main_loop_run(mainloop);
- }
- }
-
- g_main_loop_unref(mainloop);
- g_object_unref(input);
- g_object_unref(device);
- g_object_unref(adapter);
- dbus_disconnect();
-
- exit(EXIT_SUCCESS);
-}
-
diff --git a/src/bt-monitor.1 b/src/bt-monitor.1
deleted file mode 100644
index 3da57ae..0000000
--- a/src/bt-monitor.1
+++ /dev/null
@@ -1,180 +0,0 @@
-.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
-.\"
-.\" Standard preamble:
-.\" ========================================================================
-.de Sp \" Vertical space (when we can't use .PP)
-.if t .sp .5v
-.if n .sp
-..
-.de Vb \" Begin verbatim text
-.ft CW
-.nf
-.ne \\$1
-..
-.de Ve \" End verbatim text
-.ft R
-.fi
-..
-.\" Set up some character translations and predefined strings. \*(-- will
-.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
-.\" double quote, and \*(R" will give a right double quote. \*(C+ will
-.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
-.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
-.\" nothing in troff, for use with C<>.
-.tr \(*W-
-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
-.ie n \{\
-. ds -- \(*W-
-. ds PI pi
-. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
-. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
-. ds L" ""
-. ds R" ""
-. ds C` ""
-. ds C' ""
-'br\}
-.el\{\
-. ds -- \|\(em\|
-. ds PI \(*p
-. ds L" ``
-. ds R" ''
-'br\}
-.\"
-.\" Escape single quotes in literal strings from groff's Unicode transform.
-.ie \n(.g .ds Aq \(aq
-.el .ds Aq '
-.\"
-.\" If the F register is turned on, we'll generate index entries on stderr for
-.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
-.\" entries marked with X<> in POD. Of course, you'll have to process the
-.\" output yourself in some meaningful fashion.
-.ie \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
-..
-. nr % 0
-. rr F
-.\}
-.el \{\
-. de IX
-..
-.\}
-.\"
-.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
-.\" Fear. Run. Save yourself. No user-serviceable parts.
-. \" fudge factors for nroff and troff
-.if n \{\
-. ds #H 0
-. ds #V .8m
-. ds #F .3m
-. ds #[ \f1
-. ds #] \fP
-.\}
-.if t \{\
-. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
-. ds #V .6m
-. ds #F 0
-. ds #[ \&
-. ds #] \&
-.\}
-. \" simple accents for nroff and troff
-.if n \{\
-. ds ' \&
-. ds ` \&
-. ds ^ \&
-. ds , \&
-. ds ~ ~
-. ds /
-.\}
-.if t \{\
-. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
-. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
-. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
-. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
-. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
-. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
-.\}
-. \" troff and (daisy-wheel) nroff accents
-.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
-.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
-.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
-.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
-.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
-.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
-.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
-.ds ae a\h'-(\w'a'u*4/10)'e
-.ds Ae A\h'-(\w'A'u*4/10)'E
-. \" corrections for vroff
-.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
-.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
-. \" for low resolution devices (crt and lpr)
-.if \n(.H>23 .if \n(.V>19 \
-\{\
-. ds : e
-. ds 8 ss
-. ds o a
-. ds d- d\h'-1'\(ga
-. ds D- D\h'-1'\(hy
-. ds th \o'bp'
-. ds Th \o'LP'
-. ds ae ae
-. ds Ae AE
-.\}
-.rm #[ #] #H #V #F C
-.\" ========================================================================
-.\"
-.IX Title "bt-monitor 1"
-.TH bt-monitor 1 "2010-08-16" "" "bluez-tools"
-.\" For nroff, turn off justification. Always turn off hyphenation; it makes
-.\" way too many mistakes in technical documents.
-.if n .ad l
-.nh
-.SH "NAME"
-bt\-monitor \- a bluetooth monitor
-.SH "SYNOPSIS"
-.IX Header "SYNOPSIS"
-bt-monitor [\s-1OPTION\s0...]
-.PP
-Help Options:
- \-h, \-\-help
-.PP
-Application Options:
- \-a, \-\-adapter=<name|mac>
-.SH "DESCRIPTION"
-.IX Header "DESCRIPTION"
-This utility is used to capture DBus signals of bluetoothd. Captured next signals:
-.PP
-\&\fBManager signals\fR:
- AdapterAdded
- AdapterRemoved
- DefaultAdapterChanged
-.PP
-\&\fBAdapter signals\fR:
- DeviceCreated
- DeviceDisappeared
- DeviceFound
- DeviceRemoved
- AdapterPropertyChanged
-.PP
-\&\fBDevice signals\fR:
- DisconnectRequested
- DevicePropertyChanged
-.PP
-\&\fBServices signals\fR:
- AudioServiceConnected
- InputServiceConnected
- NetworkServiceConnected
-.SH "OPTIONS"
-.IX Header "OPTIONS"
-\&\fB\-h, \-\-help\fR
- Show help
-.PP
-\&\fB\-a, \-\-adapter <name|mac>\fR
- Specify adapter to capture by his Name or \s-1MAC\s0 address
- (if this option does not defined \- all adapters captured)
-.SH "AUTHOR"
-.IX Header "AUTHOR"
-Alexander Orlenko <zxteam@gmail.com>.
-.SH "SEE ALSO"
-.IX Header "SEE ALSO"
-\&\fIbt\-adapter\fR\|(1) \fIbt\-agent\fR\|(1) \fIbt\-audio\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-input\fR\|(1) \fIbt\-network\fR\|(1) \fIbt\-serial\fR\|(1)
diff --git a/src/bt-monitor.c b/src/bt-monitor.c
deleted file mode 100644
index 59f1cd1..0000000
--- a/src/bt-monitor.c
+++ /dev/null
@@ -1,490 +0,0 @@
-/*
- *
- * 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 <locale.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <glib.h>
-
-#include "lib/dbus-common.h"
-#include "lib/helpers.h"
-#include "lib/bluez-api.h"
-
-static gchar *adapter_arg = NULL;
-
-// adapter_path => GPtrArray{adapter_object, device1_object, device2_object, ...}
-static GHashTable *captured_adapters_devices_t = NULL;
-// device_path => GPtrArray{device_object, service1_object, service2_object, ...}
-static GHashTable *captured_devices_services_t = NULL;
-
-static void capture_adapter(Adapter *adapter);
-static void release_adapter(Adapter *adapter);
-static void capture_device(Device *device);
-static void release_device(Device *device);
-static void reload_device_services(Device *device);
-
-/*
- * Manager signals
- */
-static void manager_adapter_added(Manager *manager, const gchar *adapter_path, gpointer data)
-{
- //g_print("manager_adapter_added()\n");
-
- if (adapter_arg == NULL) {
- Adapter *adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", adapter_path, NULL);
- g_print("[Manager] Adapter added: %s (%s)\n", adapter_get_name(adapter), adapter_get_address(adapter));
- capture_adapter(adapter);
- }
-}
-
-static void manager_adapter_removed(Manager *manager, const gchar *adapter_path, gpointer data)
-{
- //g_print("manager_adapter_removed()\n");
-
- GSList *t = g_hash_table_lookup(captured_adapters_devices_t, adapter_path);
- if (t != NULL) {
- Adapter *adapter = ADAPTER(g_slist_nth_data(t, 0));
- g_print("[Manager] Adapter removed: %s (%s)\n", adapter_get_name(adapter), adapter_get_address(adapter));
- release_adapter(adapter);
- }
-
- // Exit if removed user-captured adapter
- if (adapter_arg != NULL && g_hash_table_size(captured_adapters_devices_t) == 0) {
- exit(EXIT_SUCCESS);
- }
-}
-
-static void manager_default_adapter_changed(Manager *manager, const gchar *adapter_path, gpointer data)
-{
- //g_print("manager_default_adapter_changed()\n");
-
- if (adapter_arg == NULL) {
- Adapter *adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", adapter_path, NULL);
- g_print("[Manager] Default adapter changed: %s (%s)\n", adapter_get_name(adapter), adapter_get_address(adapter));
- g_object_unref(adapter);
- }
-}
-
-static void manager_property_changed(Manager *manager, const gchar *name, const GValue *value, gpointer data)
-{
- //g_print("manager_property_changed()\n");
-
- if (adapter_arg == NULL) {
- // Only one property: Adapters
- g_print("[Manager] Property changed: %s\n", name);
- }
-}
-
-/*
- * Adapter signals
- */
-static void adapter_device_created(Adapter *adapter, const gchar *device_path, gpointer data)
-{
- //g_print("adapter_device_created()\n");
-
- if (intf_supported(BLUEZ_DBUS_NAME, device_path, DEVICE_DBUS_INTERFACE)) {
- Device *device = g_object_new(DEVICE_TYPE, "DBusObjectPath", device_path, NULL);
- g_print("[Adapter: %s (%s)] Device created: %s (%s)\n", adapter_get_name(adapter), adapter_get_address(adapter), device_get_alias(device), device_get_address(device));
- capture_device(device);
- } else {
- g_print("[Adapter: %s (%s)]* Device created: %s\n", adapter_get_name(adapter), adapter_get_address(adapter), device_path);
- }
-}
-
-static void adapter_device_disappeared(Adapter *adapter, const gchar *address, gpointer data)
-{
- //g_print("adapter_device_disappeared()\n");
-
- g_print("[Adapter: %s (%s)] Device disappeared: %s\n", adapter_get_name(adapter), adapter_get_address(adapter), address);
-}
-
-static void adapter_device_found(Adapter *adapter, const gchar *address, GHashTable *values, gpointer data)
-{
- //g_print("adapter_device_found()\n");
-
- g_print("[Adapter: %s (%s)] Device found:\n", adapter_get_name(adapter), adapter_get_address(adapter));
- g_print("[%s]\n", address);
- g_print(" Name: %s\n", g_value_get_string(g_hash_table_lookup(values, "Name")));
- g_print(" Alias: %s\n", g_value_get_string(g_hash_table_lookup(values, "Alias")));
- g_print(" Address: %s\n", g_value_get_string(g_hash_table_lookup(values, "Address")));
- g_print(" Icon: %s\n", g_value_get_string(g_hash_table_lookup(values, "Icon")));
- g_print(" Class: 0x%x\n", g_value_get_uint(g_hash_table_lookup(values, "Class")));
- g_print(" LegacyPairing: %d\n", g_value_get_boolean(g_hash_table_lookup(values, "LegacyPairing")));
- g_print(" Paired: %d\n", g_value_get_boolean(g_hash_table_lookup(values, "Paired")));
- g_print(" RSSI: %d\n", g_value_get_int(g_hash_table_lookup(values, "RSSI")));
- g_print("\n");
-}
-
-static void adapter_device_removed(Adapter *adapter, const gchar *device_path, gpointer data)
-{
- //g_print("adapter_device_removed()\n");
-
- GSList *t2 = g_hash_table_lookup(captured_devices_services_t, device_path);
- if (t2 != NULL) {
- Device *device = DEVICE(g_slist_nth_data(t2, 0));
- g_print("[Adapter: %s (%s)] Device removed: %s (%s)\n", adapter_get_name(adapter), adapter_get_address(adapter), device_get_alias(device), device_get_address(device));
- release_device(device);
- } else {
- g_print("[Adapter: %s (%s)]* Device removed: %s\n", adapter_get_name(adapter), adapter_get_address(adapter), device_path);
- }
-}
-
-static void adapter_property_changed(Adapter *adapter, const gchar *name, const GValue *value, gpointer data)
-{
- //g_print("adapter_property_changed()\n");
-
- g_print("[Adapter: %s (%s)] Property changed: %s", adapter_get_name(adapter), adapter_get_address(adapter), name);
- if (G_VALUE_HOLDS_BOOLEAN(value)) {
- g_print(" -> %d\n", g_value_get_boolean(value));
- } else if (G_VALUE_HOLDS_INT(value)) {
- g_print(" -> %d\n", g_value_get_int(value));
- } else if (G_VALUE_HOLDS_UINT(value)) {
- g_print(" -> %d\n", g_value_get_uint(value));
- } else if (G_VALUE_HOLDS_STRING(value)) {
- g_print(" -> %s\n", g_value_get_string(value));
- } else {
- g_print("\n");
- }
-}
-
-/*
- * Device signals
- */
-static void device_disconnect_requested(Device *device, gpointer data)
-{
- //g_print("device_disconnect_requested()\n");
-
- g_print("[Device: %s (%s)] Disconnect requested\n", device_get_alias(device), device_get_address(device));
-}
-
-static void device_property_changed(Device *device, const gchar *name, const GValue *value, gpointer data)
-{
- //g_print("device_property_changed()\n");
-
- g_print("[Device: %s (%s)] Property changed: %s", device_get_alias(device), device_get_address(device), name);
- if (G_VALUE_HOLDS_BOOLEAN(value)) {
- g_print(" -> %d\n", g_value_get_boolean(value));
- } else if (G_VALUE_HOLDS_INT(value)) {
- g_print(" -> %d\n", g_value_get_int(value));
- } else if (G_VALUE_HOLDS_UINT(value)) {
- g_print(" -> %d\n", g_value_get_uint(value));
- } else if (G_VALUE_HOLDS_STRING(value)) {
- g_print(" -> %s\n", g_value_get_string(value));
- } else {
- g_print("\n");
- }
-
- if (g_strcmp0(name, "UUIDs") == 0) {
- reload_device_services(device);
- }
-}
-
-/*
- * Services signals
- */
-static void audio_property_changed(Audio *audio, const gchar *name, const GValue *value, gpointer data)
-{
- //g_print("audio_property_changed()\n");
-
- Device *device = DEVICE(data);
- g_print("[Device: %s (%s)] Audio property changed: %s", device_get_alias(device), device_get_address(device), name);
- if (G_VALUE_HOLDS_BOOLEAN(value)) {
- g_print(" -> %d\n", g_value_get_boolean(value));
- } else if (G_VALUE_HOLDS_INT(value)) {
- g_print(" -> %d\n", g_value_get_int(value));
- } else if (G_VALUE_HOLDS_UINT(value)) {
- g_print(" -> %d\n", g_value_get_uint(value));
- } else if (G_VALUE_HOLDS_STRING(value)) {
- g_print(" -> %s\n", g_value_get_string(value));
- } else {
- g_print("\n");
- }
-}
-
-static void input_property_changed(Input *input, const gchar *name, const GValue *value, gpointer data)
-{
- //g_print("input_property_changed()\n");
-
- Device *device = DEVICE(data);
- g_print("[Device: %s (%s)] Input property changed: %s", device_get_alias(device), device_get_address(device), name);
- if (G_VALUE_HOLDS_BOOLEAN(value)) {
- g_print(" -> %d\n", g_value_get_boolean(value));
- } else if (G_VALUE_HOLDS_INT(value)) {
- g_print(" -> %d\n", g_value_get_int(value));
- } else if (G_VALUE_HOLDS_UINT(value)) {
- g_print(" -> %d\n", g_value_get_uint(value));
- } else if (G_VALUE_HOLDS_STRING(value)) {
- g_print(" -> %s\n", g_value_get_string(value));
- } else {
- g_print("\n");
- }
-}
-
-static void network_property_changed(Network *network, const gchar *name, const GValue *value, gpointer data)
-{
- //g_print("network_property_changed()\n");
-
- Device *device = DEVICE(data);
- g_print("[Device: %s (%s)] Network property changed: %s", device_get_alias(device), device_get_address(device), name);
- if (G_VALUE_HOLDS_BOOLEAN(value)) {
- g_print(" -> %d\n", g_value_get_boolean(value));
- } else if (G_VALUE_HOLDS_INT(value)) {
- g_print(" -> %d\n", g_value_get_int(value));
- } else if (G_VALUE_HOLDS_UINT(value)) {
- g_print(" -> %d\n", g_value_get_uint(value));
- } else if (G_VALUE_HOLDS_STRING(value)) {
- g_print(" -> %s\n", g_value_get_string(value));
- } else {
- g_print("\n");
- }
-}
-
-/*
- * Capturing methods
- */
-static void capture_adapter(Adapter *adapter)
-{
- //g_print("capture_adapter()\n");
-
- g_assert(ADAPTER_IS(adapter));
-
- GSList *t = g_slist_append(NULL, adapter);
- g_hash_table_insert(captured_adapters_devices_t, g_strdup(adapter_get_dbus_object_path(adapter)), t);
-
- g_signal_connect(adapter, "DeviceCreated", G_CALLBACK(adapter_device_created), NULL);
- g_signal_connect(adapter, "DeviceDisappeared", G_CALLBACK(adapter_device_disappeared), NULL);
- g_signal_connect(adapter, "DeviceFound", G_CALLBACK(adapter_device_found), NULL);
- g_signal_connect(adapter, "DeviceRemoved", G_CALLBACK(adapter_device_removed), NULL);
- g_signal_connect(adapter, "PropertyChanged", G_CALLBACK(adapter_property_changed), NULL);
-
- // Capturing signals from devices
- const GPtrArray *devices_list = adapter_get_devices(adapter);
- g_assert(devices_list != NULL);
- for (int i = 0; i < devices_list->len; i++) {
- const gchar *device_path = g_ptr_array_index(devices_list, i);
- Device *device = g_object_new(DEVICE_TYPE, "DBusObjectPath", device_path, NULL);
- capture_device(device);
- }
-}
-
-static void release_adapter(Adapter *adapter)
-{
- //g_print("release_adapter()\n");
-
- g_assert(ADAPTER_IS(adapter));
-
- GSList *t = g_hash_table_lookup(captured_adapters_devices_t, adapter_get_dbus_object_path(adapter));
- while (g_slist_length(t) > 1) {
- Device *device = DEVICE(g_slist_nth_data(t, 1));
- release_device(device);
- t = g_hash_table_lookup(captured_adapters_devices_t, adapter_get_dbus_object_path(adapter));
- }
- g_slist_free(t);
- g_hash_table_remove(captured_adapters_devices_t, adapter_get_dbus_object_path(adapter));
- g_object_unref(adapter);
-}
-
-static void capture_device(Device *device)
-{
- //g_print("capture_device()\n");
-
- g_assert(DEVICE_IS(device));
-
- GSList *t = g_hash_table_lookup(captured_adapters_devices_t, device_get_adapter(device));
- if (t == NULL) {
- Adapter *adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", device_get_adapter(device), NULL);
- g_printerr("[Device: %s (%s)] Uncaptured adapter: %s (%s)\n", device_get_alias(device), device_get_address(device), adapter_get_name(adapter), adapter_get_address(adapter));
- g_object_unref(adapter);
- return;
- }
- t = g_slist_append(t, device);
-
- GSList *t2 = g_hash_table_lookup(captured_devices_services_t, device_get_dbus_object_path(device));
- if (t2 != NULL) {
- g_printerr("[Device: %s (%s)] Already captured device\n", device_get_alias(device), device_get_address(device));
- return;
- }
- t2 = g_slist_append(t2, device);
-
- g_signal_connect(device, "DisconnectRequested", G_CALLBACK(device_disconnect_requested), NULL);
- g_signal_connect(device, "PropertyChanged", G_CALLBACK(device_property_changed), NULL);
-
- g_hash_table_insert(captured_adapters_devices_t, g_strdup(device_get_adapter(device)), t);
- g_hash_table_insert(captured_devices_services_t, g_strdup(device_get_dbus_object_path(device)), t2);
-
- reload_device_services(device);
-}
-
-static void release_device(Device *device)
-{
- //g_print("release_device()\n");
-
- g_assert(DEVICE_IS(device));
-
- GSList *t = g_hash_table_lookup(captured_adapters_devices_t, device_get_adapter(device));
- if (t != NULL) {
- t = g_slist_remove(t, device);
- g_hash_table_insert(captured_adapters_devices_t, g_strdup(device_get_adapter(device)), t);
- }
-
- GSList *t2 = g_hash_table_lookup(captured_devices_services_t, device_get_dbus_object_path(device));
- while (g_slist_length(t2) > 1) {
- GObject *service = g_slist_nth_data(t2, 1);
- t2 = g_slist_remove(t2, service);
- g_object_unref(service);
- }
- g_slist_free(t2);
- g_hash_table_remove(captured_devices_services_t, device_get_dbus_object_path(device));
-
- g_object_unref(device);
-}
-
-static void reload_device_services(Device *device)
-{
- //g_print("reload_device_services()\n");
-
- GSList *t2 = g_hash_table_lookup(captured_devices_services_t, device_get_dbus_object_path(device));
- if (t2 == NULL) {
- g_printerr("[Device: %s (%s)] Uncaptured device\n", device_get_alias(device), device_get_address(device));
- return;
- }
-
- while (g_slist_length(t2) > 1) {
- GObject *service = g_slist_nth_data(t2, 1);
- t2 = g_slist_remove(t2, service);
- g_object_unref(service);
- }
-
- // Capturing signals from available services
- if (intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), AUDIO_DBUS_INTERFACE)) {
- Audio *audio = g_object_new(AUDIO_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL);
- g_signal_connect(audio, "PropertyChanged", G_CALLBACK(audio_property_changed), device);
- t2 = g_slist_append(t2, audio);
- }
- if (intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), INPUT_DBUS_INTERFACE)) {
- Input *input = g_object_new(INPUT_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL);
- g_signal_connect(input, "PropertyChanged", G_CALLBACK(input_property_changed), device);
- t2 = g_slist_append(t2, input);
- }
- if (intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), NETWORK_DBUS_INTERFACE)) {
- Network *network = g_object_new(NETWORK_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL);
- g_signal_connect(network, "PropertyChanged", G_CALLBACK(network_property_changed), device);
- t2 = g_slist_append(t2, network);
- }
-
- g_hash_table_insert(captured_devices_services_t, g_strdup(device_get_dbus_object_path(device)), t2);
-}
-
-static GOptionEntry entries[] = {
- {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter Name or MAC", "<name|mac>"},
- {NULL}
-};
-
-int main(int argc, char *argv[])
-{
- GError *error = NULL;
- GOptionContext *context;
-
- /* Query current locale */
- setlocale(LC_CTYPE, "");
-
- g_type_init();
- dbus_init();
-
- context = g_option_context_new("- a bluetooth monitor");
- g_option_context_add_main_entries(context, entries, NULL);
- g_option_context_set_summary(context, "Version "PACKAGE_VERSION);
- g_option_context_set_description(context,
- //"Report bugs to <"PACKAGE_BUGREPORT">."
- "Project home page <"PACKAGE_URL">."
- );
-
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- g_print("%s: %s\n", g_get_prgname(), error->message);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- }
-
- g_option_context_free(context);
-
- if (!dbus_system_connect(&error)) {
- g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- /* Check, that bluetooth daemon is running */
- if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) {
- g_printerr("%s: bluez service is not found\n", g_get_prgname());
- g_printerr("Did you forget to run bluetoothd?\n");
- exit(EXIT_FAILURE);
- }
-
- captured_adapters_devices_t = g_hash_table_new(g_str_hash, g_str_equal);
- captured_devices_services_t = g_hash_table_new(g_str_hash, g_str_equal);
-
- Manager *manager = g_object_new(MANAGER_TYPE, NULL);
-
- if (adapter_arg != NULL) {
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
- capture_adapter(adapter);
- } else {
- const GPtrArray *adapters_list = manager_get_adapters(manager);
- g_assert(adapters_list != NULL);
-
- if (adapters_list->len == 0) {
- g_print("No adapters found\n");
- exit(EXIT_FAILURE);
- }
-
- for (int i = 0; i < adapters_list->len; i++) {
- const gchar *adapter_path = g_ptr_array_index(adapters_list, i);
- Adapter *adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", adapter_path, NULL);
- capture_adapter(adapter);
- }
- }
-
- g_signal_connect(manager, "AdapterAdded", G_CALLBACK(manager_adapter_added), NULL);
- g_signal_connect(manager, "AdapterRemoved", G_CALLBACK(manager_adapter_removed), NULL);
- g_signal_connect(manager, "DefaultAdapterChanged", G_CALLBACK(manager_default_adapter_changed), NULL);
- g_signal_connect(manager, "PropertyChanged", G_CALLBACK(manager_property_changed), NULL);
-
- g_print("Monitor registered\n");
-
- GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
- g_main_loop_run(mainloop);
-
- // TODO: Add SIGINT handler (Ctrl+C)
-
- g_main_loop_unref(mainloop);
- g_object_unref(manager);
- dbus_disconnect();
-
- exit(EXIT_SUCCESS);
-}
-
diff --git a/src/bt-network.1 b/src/bt-network.1
index 7364308..0a6381c 100644
--- a/src/bt-network.1
+++ b/src/bt-network.1
@@ -1,4 +1,4 @@
-.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
+.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
@@ -38,6 +38,8 @@
. ds PI \(*p
. ds L" ``
. ds R" ''
+. ds C`
+. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
@@ -48,17 +50,24 @@
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
-.ie \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
+.\"
+.\" Avoid warning from groff about undefined register 'F'.
+.de IX
..
-. nr % 0
-. rr F
-.\}
-.el \{\
-. de IX
+.nr rF 0
+.if \n(.g .if rF .nr rF 1
+.if (\n(rF:(\n(.g==0)) \{
+. if \nF \{
+. de IX
+. tm Index:\\$1\t\\n%\t"\\$2"
..
+. if !\nF==2 \{
+. nr % 0
+. nr F 2
+. \}
+. \}
.\}
+.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
@@ -124,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "bt-network 1"
-.TH bt-network 1 "2010-11-22" "" "bluez-tools"
+.TH bt-network 1 "2014-08-01" "" "bluez-tools"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -133,7 +142,7 @@
bt\-network \- a bluetooth network manager
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
-bt-network [\s-1OPTION\s0...]
+bt-network [\s-1OPTION...\s0]
.PP
Help Options:
\-h, \-\-help
@@ -160,11 +169,11 @@ All servers will be automatically unregistered when the application terminates.
name, uuid can be either one of \*(L"gn\*(R", \*(L"panu\*(R" or \*(L"nap\*(R"
.PP
\&\fB\-s, \-\-server <gn|panu|nap> <brige>\fR
- Register server for the provided \s-1UUID\s0, every new connection to
+ Register server for the provided \s-1UUID,\s0 every new connection to
this server will be added the bridge interface
.SH "AUTHOR"
.IX Header "AUTHOR"
Alexander Orlenko <zxteam@gmail.com>.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
-\&\fIbt\-adapter\fR\|(1) \fIbt\-agent\fR\|(1) \fIbt\-audio\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-input\fR\|(1) \fIbt\-monitor\fR\|(1) \fIbt\-serial\fR\|(1)
+\&\fIbt\-adapter\fR\|(1) \fIbt\-agent\fR\|(1) \fIbt\-device\fR\|(1)
diff --git a/src/bt-network.c b/src/bt-network.c
index b47c4bd..d8de8a1 100644
--- a/src/bt-network.c
+++ b/src/bt-network.c
@@ -31,7 +31,7 @@
#include <signal.h>
#include <unistd.h>
-#include <glib.h>
+#include <gio/gio.h>
#include "lib/dbus-common.h"
#include "lib/helpers.h"
@@ -55,22 +55,32 @@ static void trap_signals()
sigaction(SIGINT, &sa, NULL);
}
-static void network_property_changed(Network *network, const gchar *name, const GValue *value, gpointer data)
+static void _bt_network_property_changed(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
{
- g_assert(data != NULL);
- GMainLoop *mainloop = data;
-
- if (g_strcmp0(name, "Connected") == 0) {
- if (g_value_get_boolean(value) == TRUE) {
+ g_assert(user_data != NULL);
+ GMainLoop *mainloop = user_data;
+
+ GVariant *changed_properties = g_variant_get_child_value(parameters, 1);
+ g_variant_lookup_value(changed_properties, "UUID", NULL);
+ if (g_variant_lookup_value(changed_properties, "Connected", NULL))
+ {
+ if (g_variant_get_boolean(g_variant_lookup_value(changed_properties, "Connected", NULL)) == TRUE)
+ {
g_print("Network service is connected\n");
- } else {
+ }
+ else
+ {
g_print("Network service is disconnected\n");
g_main_loop_quit(mainloop);
}
- } else if (g_strcmp0(name, "Interface") == 0) {
- g_print("Interface: %s\n", g_value_get_string(value));
- } else if (g_strcmp0(name, "UUID") == 0) {
- g_print("UUID: %s (%s)\n", uuid2name(g_value_get_string(value)), g_value_get_string(value));
+ }
+ else if (g_variant_lookup_value(changed_properties, "Interface", NULL))
+ {
+ g_print("Interface: %s\n", g_variant_get_string(g_variant_lookup_value(changed_properties, "Interface", NULL), NULL));
+ }
+ else if (g_variant_lookup_value(changed_properties, "UUID", NULL))
+ {
+ g_print("UUID: %s (%s)\n", uuid2name(g_variant_get_string(g_variant_lookup_value(changed_properties, "UUID", NULL), NULL)), g_variant_get_string(g_variant_lookup_value(changed_properties, "UUID", NULL), NULL));
}
}
@@ -99,7 +109,6 @@ int main(int argc, char *argv[])
/* Query current locale */
setlocale(LC_CTYPE, "");
- g_type_init();
dbus_init();
context = g_option_context_new("- a bluetooth network manager");
@@ -115,7 +124,7 @@ int main(int argc, char *argv[])
"Server Options:\n"
" -s, --server <gn|panu|nap> <brige>\n"
" Every new connection to this server will be added the `bridge` interface\n\n"
- //"Report bugs to <"PACKAGE_BUGREPORT">."
+ "Report bugs to <"PACKAGE_BUGREPORT">."
"Project home page <"PACKAGE_URL">."
);
@@ -144,7 +153,7 @@ int main(int argc, char *argv[])
}
/* Check, that bluetooth daemon is running */
- if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) {
+ if (!intf_supported(BLUEZ_DBUS_SERVICE_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) {
g_printerr("%s: bluez service is not found\n", g_get_prgname());
g_printerr("Did you forget to run bluetoothd?\n");
exit(EXIT_FAILURE);
@@ -160,31 +169,32 @@ int main(int argc, char *argv[])
Device *device = find_device(adapter, connect_device_arg, &error);
exit_if_error(error);
- if (!intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), NETWORK_DBUS_INTERFACE)) {
+ if (!intf_supported(BLUEZ_DBUS_SERVICE_NAME, device_get_dbus_object_path(device), NETWORK_DBUS_INTERFACE)) {
g_printerr("Network service is not supported by this device\n");
exit(EXIT_FAILURE);
}
mainloop = g_main_loop_new(NULL, FALSE);
- Network *network = g_object_new(NETWORK_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL);
- g_signal_connect(network, "PropertyChanged", G_CALLBACK(network_property_changed), mainloop);
+ Network *network = network_new(device_get_dbus_object_path(device));
+ guint prop_sig_sub_id = g_dbus_connection_signal_subscribe(system_conn, "org.bluez", "org.freedesktop.DBus.Properties", "PropertiesChanged", network_get_dbus_object_path(network), NULL, G_DBUS_SIGNAL_FLAGS_NONE, _bt_network_property_changed, mainloop, NULL);
- if (network_get_connected(network) == TRUE) {
+ if (network_get_connected(network, NULL) == TRUE) {
g_print("Network service is already connected\n");
} else {
- gchar *intf = network_connect(network, connect_uuid_arg, &error);
+ gchar *intf = (gchar *) network_connect(network, connect_uuid_arg, &error);
exit_if_error(error);
trap_signals();
g_main_loop_run(mainloop);
/* Force disconnect the network device */
- if (network_get_connected(network) == TRUE) {
+ if (network_get_connected(network, NULL) == TRUE) {
network_disconnect(network, NULL);
}
g_free(intf);
}
+ g_dbus_connection_signal_unsubscribe(system_conn, prop_sig_sub_id);
g_main_loop_unref(mainloop);
g_object_unref(network);
g_object_unref(device);
@@ -198,14 +208,14 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- if (!intf_supported(BLUEZ_DBUS_NAME, adapter_get_dbus_object_path(adapter), NETWORK_SERVER_DBUS_INTERFACE)) {
+ if (!intf_supported(BLUEZ_DBUS_SERVICE_NAME, adapter_get_dbus_object_path(adapter), NETWORK_SERVER_DBUS_INTERFACE)) {
g_printerr("Network server is not supported by this adapter\n");
exit(EXIT_FAILURE);
}
gchar *server_uuid_upper = g_ascii_strup(server_uuid_arg, -1);
- NetworkServer *network_server = g_object_new(NETWORK_SERVER_TYPE, "DBusObjectPath", adapter_get_dbus_object_path(adapter), NULL);
+ NetworkServer *network_server = network_server_new(adapter_get_dbus_object_path(adapter));
network_server_register(network_server, server_uuid_arg, server_brige_arg, &error);
exit_if_error(error);
g_print("%s server registered\n", server_uuid_upper);
@@ -252,4 +262,3 @@ int main(int argc, char *argv[])
exit(EXIT_SUCCESS);
}
-
diff --git a/src/bt-obex.1 b/src/bt-obex.1
index 23a25a8..3456354 100644
--- a/src/bt-obex.1
+++ b/src/bt-obex.1
@@ -1,4 +1,4 @@
-.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
+.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
@@ -38,6 +38,8 @@
. ds PI \(*p
. ds L" ``
. ds R" ''
+. ds C`
+. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
@@ -48,17 +50,24 @@
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
-.ie \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
+.\"
+.\" Avoid warning from groff about undefined register 'F'.
+.de IX
..
-. nr % 0
-. rr F
-.\}
-.el \{\
-. de IX
+.nr rF 0
+.if \n(.g .if rF .nr rF 1
+.if (\n(rF:(\n(.g==0)) \{
+. if \nF \{
+. de IX
+. tm Index:\\$1\t\\n%\t"\\$2"
..
+. if !\nF==2 \{
+. nr % 0
+. nr F 2
+. \}
+. \}
.\}
+.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
@@ -124,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "bt-obex 1"
-.TH bt-obex 1 "2010-08-16" "" "bluez-tools"
+.TH bt-obex 1 "2014-08-01" "" "bluez-tools"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -133,7 +142,7 @@
bt\-obex \- a bluetooth OBEX client/server
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
-bt-obex [\s-1OPTION\s0...]
+bt-obex [\s-1OPTION...\s0]
.PP
Help Options:
\-h, \-\-help
@@ -188,4 +197,4 @@ You can send and receive files to/from remote device using this tool.
Alexander Orlenko <zxteam@gmail.com>.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
-\&\fIbt\-adapter\fR\|(1) \fIbt\-agent\fR\|(1) \fIbt\-audio\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-input\fR\|(1) \fIbt\-monitor\fR\|(1) \fIbt\-network\fR\|(1) \fIbt\-serial\fR\|(1)
+\&\fIbt\-adapter\fR\|(1) \fIbt\-agent\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-network\fR\|(1)
diff --git a/src/bt-obex.c b/src/bt-obex.c
index 74b3f4c..5369b80 100644
--- a/src/bt-obex.c
+++ b/src/bt-obex.c
@@ -33,92 +33,347 @@
#include <readline/readline.h>
#include <readline/history.h>
-#include <glib.h>
+#include <gio/gio.h>
+#include <glib/gstdio.h>
#include "lib/dbus-common.h"
#include "lib/helpers.h"
#include "lib/bluez-api.h"
-#include "lib/obexd-api.h"
-static GHashTable *server_transfers = NULL;
+static GHashTable *_transfers = NULL;
+static GHashTable *_transfer_infos = NULL;
static GMainLoop *mainloop = NULL;
+static gchar *_root_path = NULL;
+static gboolean _update_progress = FALSE;
-static void sigterm_handler(int sig)
-{
- g_message("%s received", sig == SIGTERM ? "SIGTERM" : "SIGINT");
+typedef struct _ObexTransferInfo ObexTransferInfo;
- if (g_main_loop_is_running(mainloop))
- g_main_loop_quit(mainloop);
-}
+struct _ObexTransferInfo {
+ gchar *filename;
+ guint64 filesize;
+ gchar *obex_root;
+ gchar *status;
+};
-static void agent_released(OBEXAgent *agent, gpointer data)
+static void sigterm_handler(int sig)
{
- g_assert(data != NULL);
- GMainLoop *mainloop = data;
+ g_message("%s received", sig == SIGTERM ? "SIGTERM" : "SIGINT");
- if (g_main_loop_is_running(mainloop))
- g_main_loop_quit(mainloop);
+ if (g_main_loop_is_running(mainloop))
+ g_main_loop_quit(mainloop);
}
-/* OBEXTransfer signals */
-static void obextransfer_progress(OBEXTransfer *transfer, gint total, gint transfered, gpointer data)
+static void _obex_server_object_manager_handler(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
{
- guint pp = (transfered / (gfloat) total)*100;
-
- static gboolean update_progress = FALSE;
- if (!update_progress) {
- g_print("[OBEXTransfer] Progress: %3u%%", pp);
- update_progress = TRUE;
- } else {
- g_print("\b\b\b\b%3u%%", pp);
- }
-
- if (pp == 100) {
- g_print("\n");
- update_progress = FALSE;
- }
+ if(g_strcmp0(signal_name, "InterfacesAdded") == 0)
+ {
+ const gchar *interface_object_path = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
+ GVariant *interfaces_and_properties = g_variant_get_child_value(parameters, 1);
+ GVariant *properties = NULL;
+
+ if(g_variant_lookup(interfaces_and_properties, OBEX_TRANSFER_DBUS_INTERFACE, "@a{sv}", &properties))
+ {
+ g_print("[OBEX Server] Transfer started\n");
+ ObexTransfer *t = obex_transfer_new(interface_object_path);
+ g_hash_table_insert(_transfers, g_strdup(interface_object_path), t);
+
+ ObexTransferInfo *info = g_malloc0(sizeof(ObexTransferInfo));
+ info->filesize = g_variant_get_uint64(g_variant_lookup_value(properties, "Size", NULL));
+ info->status = g_strdup(g_variant_get_string(g_variant_lookup_value(properties, "Status", NULL), NULL));
+ ObexSession *session = obex_session_new(g_variant_get_string(g_variant_lookup_value(properties, "Session", NULL), NULL));
+
+ info->obex_root = g_strdup(obex_session_get_root(session, NULL));
+
+ g_object_unref(session);
+
+ g_hash_table_insert(_transfer_infos, g_strdup(interface_object_path), info);
+ }
+
+ if(g_variant_lookup(interfaces_and_properties, OBEX_SESSION_DBUS_INTERFACE, "@a{sv}", &properties))
+ {
+ g_print("[OBEX Server] OBEX session opened\n");
+ }
+
+ g_variant_unref(interfaces_and_properties);
+ if(properties)
+ g_variant_unref(properties);
+ }
+ else if(g_strcmp0(signal_name, "InterfacesRemoved") == 0)
+ {
+ const gchar *interface_object_path = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
+ GVariant *interfaces = g_variant_get_child_value(parameters, 1);
+ const gchar **inf_array = g_variant_get_strv(interfaces, NULL);
+ g_variant_unref(interfaces);
+ const gchar **inf = NULL;
+ for(inf = inf_array; *inf != NULL; inf++)
+ {
+ if(g_strcmp0(*inf, OBEX_TRANSFER_DBUS_INTERFACE) == 0)
+ {
+ g_print("[OBEX Server] OBEX transfer closed\n");
+ ObexTransfer *transfer = g_hash_table_lookup(_transfers, interface_object_path);
+ g_hash_table_remove(_transfers, interface_object_path);
+ g_object_unref(transfer);
+ g_free(g_hash_table_lookup(_transfer_infos, interface_object_path));
+ g_hash_table_remove(_transfer_infos, interface_object_path);
+ }
+
+ if(g_strcmp0(*inf, OBEX_SESSION_DBUS_INTERFACE) == 0)
+ {
+ g_print("[OBEX Server] OBEX session closed\n");
+ }
+ }
+ g_free(inf_array);
+ }
}
-/* OBEXManager signals */
-static void obexmanager_session_created(OBEXManager *manager, const gchar *session_path, gpointer data)
+static void _obex_server_properties_handler(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
{
- g_print("[OBEXManager] FTP session opened\n");
+ const gchar *arg0 = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
+ GVariant *changed_properties = g_variant_get_child_value(parameters, 1);
+
+ if(g_strcmp0(arg0, OBEX_TRANSFER_DBUS_INTERFACE) == 0)
+ {
+ ObexTransfer *transfer = g_hash_table_lookup(_transfers, object_path);
+
+ guint64 size = 0x0;
+ guint64 transferred = 0x0;
+ obex_transfer_get_size(transfer, NULL);
+ g_variant_lookup(changed_properties, "Size", "t", &size);
+ if(!size)
+ size = obex_transfer_get_size(transfer, NULL);
+ g_variant_lookup(changed_properties, "Transferred", "t", &transferred);
+
+ if(size && transferred)
+ {
+ guint pp = (transferred / (gfloat) size)*100;
+
+ if (!_update_progress)
+ {
+ g_print("[OBEXTransfer] Progress: %3u%%", pp);
+ _update_progress = TRUE;
+ }
+ else
+ {
+ g_print("\b\b\b\b%3u%%", pp);
+ }
+
+ if (pp == 100)
+ {
+ g_print("\n");
+ _update_progress = FALSE;
+ }
+ }
+
+ gchar *status = NULL;
+ g_variant_lookup(changed_properties, "Status", "s", &status);
+
+ if(status)
+ {
+ if(g_strcmp0(status, "active") == 0)
+ {
+ // g_print("[OBEX Server] Transfer active\n");
+ }
+ else if(g_strcmp0(status, "complete") == 0)
+ {
+ g_print("[OBEX Server] Transfer succeeded\n");
+ ObexTransferInfo *info = g_hash_table_lookup(_transfer_infos, object_path);
+ g_rename(g_build_filename(info->obex_root, info->filename, NULL), g_build_filename(_root_path, info->filename, NULL));
+ }
+ else if(g_strcmp0(status, "error") == 0)
+ {
+ g_print("[OBEX Server] Transfer failed\n");
+ }
+ else if(g_strcmp0(status, "queued") == 0)
+ {
+ g_print("[OBEX Server] Transfer queued\n");
+ }
+ else if(g_strcmp0(status, "suspended") == 0)
+ {
+ g_print("[OBEX Server] Transfer halted\n");
+ }
+ g_free(status);
+ }
+ }
+
+ g_variant_unref(changed_properties);
}
-static void obexmanager_session_removed(OBEXManager *manager, const gchar *session_path, gpointer data)
+static void _obex_opp_client_object_manager_handler(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
{
- g_print("[OBEXManager] FTP session closed\n", session_path);
+ if(g_strcmp0(signal_name, "InterfacesAdded") == 0)
+ {
+ const gchar *interface_object_path = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
+ GVariant *interfaces_and_properties = g_variant_get_child_value(parameters, 1);
+ GVariant *properties = NULL;
+
+ if(g_variant_lookup(interfaces_and_properties, OBEX_TRANSFER_DBUS_INTERFACE, "@a{sv}", &properties))
+ {
+ // g_print("[OBEX Client] Transfer started\n");
+ ObexTransfer *t = obex_transfer_new(interface_object_path);
+ g_hash_table_insert(_transfers, g_strdup(interface_object_path), t);
+
+ ObexTransferInfo *info = g_malloc0(sizeof(ObexTransferInfo));
+ info->filesize = g_variant_get_uint64(g_variant_lookup_value(properties, "Size", NULL));
+ info->filename = g_strdup(g_variant_get_string(g_variant_lookup_value(properties, "Name", NULL), NULL));
+ info->status = g_strdup(g_variant_get_string(g_variant_lookup_value(properties, "Status", NULL), NULL));
+ ObexSession *session = obex_session_new(g_variant_get_string(g_variant_lookup_value(properties, "Session", NULL), NULL));
+
+ info->obex_root = g_strdup(obex_session_get_root(session, NULL));
+
+ g_object_unref(session);
+
+ g_hash_table_insert(_transfer_infos, g_strdup(interface_object_path), info);
+ if(g_strcmp0(info->status, "queued") == 0)
+ g_print("[Transfer#%s] Waiting...\n", info->filename);
+ }
+
+ if(g_variant_lookup(interfaces_and_properties, OBEX_SESSION_DBUS_INTERFACE, "@a{sv}", &properties))
+ {
+ // g_print("[OBEX Client] OBEX session opened\n");
+ }
+
+ g_variant_unref(interfaces_and_properties);
+ if(properties)
+ g_variant_unref(properties);
+ }
+ else if(g_strcmp0(signal_name, "InterfacesRemoved") == 0)
+ {
+ const gchar *interface_object_path = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
+ GVariant *interfaces = g_variant_get_child_value(parameters, 1);
+ const gchar **inf_array = g_variant_get_strv(interfaces, NULL);
+ g_variant_unref(interfaces);
+ const gchar **inf = NULL;
+ for(inf = inf_array; *inf != NULL; inf++)
+ {
+ if(g_strcmp0(*inf, OBEX_TRANSFER_DBUS_INTERFACE) == 0)
+ {
+ // g_print("[OBEX Client] OBEX transfer closed\n");
+ ObexTransfer *transfer = g_hash_table_lookup(_transfers, interface_object_path);
+ g_hash_table_remove(_transfers, interface_object_path);
+ g_object_unref(transfer);
+ g_free(g_hash_table_lookup(_transfer_infos, interface_object_path));
+ g_hash_table_remove(_transfer_infos, interface_object_path);
+ if (g_main_loop_is_running(mainloop))
+ g_main_loop_quit(mainloop);
+ }
+
+ if(g_strcmp0(*inf, OBEX_SESSION_DBUS_INTERFACE) == 0)
+ {
+ // g_print("[OBEX Client] OBEX session closed\n");
+ }
+ }
+ g_free(inf_array);
+ }
}
-static void obexmanager_transfer_started(OBEXManager *manager, const gchar *transfer_path, gpointer data)
+static void _obex_opp_client_properties_handler(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
{
- g_print("[OBEXManager] Transfer started\n", transfer_path);
-
- OBEXTransfer *t = g_object_new(OBEXTRANSFER_TYPE, "DBusObjectPath", transfer_path, NULL);
- g_signal_connect(t, "Progress", G_CALLBACK(obextransfer_progress), NULL);
- g_hash_table_insert(server_transfers, g_strdup(transfer_path), t);
+ const gchar *arg0 = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
+ GVariant *changed_properties = g_variant_get_child_value(parameters, 1);
+
+ if(g_strcmp0(arg0, OBEX_TRANSFER_DBUS_INTERFACE) == 0)
+ {
+ ObexTransfer *transfer = g_hash_table_lookup(_transfers, object_path);
+ ObexTransferInfo *info = g_hash_table_lookup(_transfer_infos, object_path);
+
+ guint64 size = 0x0;
+ guint64 transferred = 0x0;
+ obex_transfer_get_size(transfer, NULL);
+ g_variant_lookup(changed_properties, "Size", "t", &size);
+ if(!size)
+ size = obex_transfer_get_size(transfer, NULL);
+ g_variant_lookup(changed_properties, "Transferred", "t", &transferred);
+
+ if(size && transferred && g_strcmp0(info->status, "active") == 0)
+ {
+ guint pp = (transferred / (gfloat) size)*100;
+
+ if (!_update_progress)
+ {
+ g_print("[Transfer#%s] Progress: %3u%%", obex_transfer_get_name(transfer, NULL), pp);
+ _update_progress = TRUE;
+ }
+ else
+ {
+ g_print("\b\b\b\b%3u%%", pp);
+ }
+
+ if (pp == 100)
+ {
+ g_print("\n");
+ _update_progress = FALSE;
+ }
+ }
+
+ gchar *status = NULL;
+ g_variant_lookup(changed_properties, "Status", "s", &status);
+
+ if(status)
+ {
+ g_free(info->status);
+ info->status = g_strdup(status);
+
+ if(g_strcmp0(status, "active") == 0)
+ {
+ // g_print("[Client Server] Transfer active\n");
+ }
+ else if(g_strcmp0(status, "complete") == 0)
+ {
+ if(_update_progress)
+ {
+ _update_progress = FALSE;
+ g_print("\b\b\b\b%3u%%", 100);
+ g_print("\n");
+ }
+
+ g_print("[Transfer#%s] Completed\n", info->filename);
+ }
+ else if(g_strcmp0(status, "error") == 0)
+ {
+ if(_update_progress)
+ {
+ _update_progress = FALSE;
+ g_print("\n");
+ }
+
+ g_print("[Transfer#%s] Failed\n", info->filename);
+ }
+ else if(g_strcmp0(status, "queued") == 0)
+ {
+ // g_print("[OBEX Client] Transfer queued\n");
+ }
+ else if(g_strcmp0(status, "suspended") == 0)
+ {
+ if(_update_progress)
+ {
+ _update_progress = FALSE;
+ g_print("\n");
+ }
+
+ g_print("[Transfer#%s] Suspended\n", info->filename);
+ }
+ g_free(status);
+ }
+ }
+
+ g_variant_unref(changed_properties);
}
-static void obexmanager_transfer_completed(OBEXManager *manager, const gchar *transfer_path, gboolean success, gpointer data)
+void _agent_approved_callback(ObexAgent *obex_agent, const gchar* obex_transfer_path, const gchar *name, const guint64 size, gpointer user_data)
{
- OBEXTransfer *t = g_hash_table_lookup(server_transfers, transfer_path);
- if (t) {
- g_print("[OBEXManager] Transfer %s\n", success == TRUE ? "succeeded" : "failed");
- g_object_unref(t);
- g_hash_table_remove(server_transfers, transfer_path);
- } else {
- // Bug ?
- }
+ ObexTransferInfo *info = g_hash_table_lookup(_transfer_infos, obex_transfer_path);
+ if(!info)
+ {
+ info = g_malloc0(sizeof(ObexTransferInfo));
+ g_hash_table_insert(_transfer_infos, g_strdup(obex_transfer_path), info);
+ ObexTransfer *transfer = g_hash_table_lookup(_transfers, obex_transfer_path);
+ ObexSession *session = obex_session_new(obex_transfer_get_session(transfer, NULL));
+ info->obex_root = g_strdup(obex_session_get_root(session, NULL));
+ }
+ info->filename = g_strdup(name);
+ info->filesize = size;
}
-/* Async callback for SendFiles() */
-/*static void send_files_done(gpointer data)
-{
- g_assert(data != NULL);
- GMainLoop *mainloop = data;
- g_main_loop_quit(mainloop);
-}*/
-
/* Main arguments */
static gchar *adapter_arg = NULL;
static gboolean server_arg = FALSE;
@@ -129,448 +384,601 @@ static gchar *opp_file_arg = NULL;
static gchar *ftp_arg = NULL;
static GOptionEntry entries[] = {
- {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter name or MAC", "<name|mac>"},
- {"server", 's', 0, G_OPTION_ARG_NONE, &server_arg, "Register self at OBEX server", NULL},
- {"opp", 'p', 0, G_OPTION_ARG_NONE, &opp_arg, "Send file to remote device", NULL},
- {"ftp", 'f', 0, G_OPTION_ARG_STRING, &ftp_arg, "Start FTP session with remote device", "<name|mac>"},
- {NULL}
+ {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter name or MAC", "<name|mac>"},
+ {"server", 's', 0, G_OPTION_ARG_NONE, &server_arg, "Register self at OBEX server", NULL},
+ {"opp", 'p', 0, G_OPTION_ARG_NONE, &opp_arg, "Send file to remote device", NULL},
+ {"ftp", 'f', 0, G_OPTION_ARG_STRING, &ftp_arg, "Start FTP session with remote device", "<name|mac>"},
+ {NULL}
};
int main(int argc, char *argv[])
{
- GError *error = NULL;
- GOptionContext *context;
-
- /* Query current locale */
- setlocale(LC_CTYPE, "");
-
- g_type_init();
- dbus_init();
-
- context = g_option_context_new(" - a bluetooth OBEX client/server");
- g_option_context_add_main_entries(context, entries, NULL);
- g_option_context_set_summary(context, "Version "PACKAGE_VERSION);
- g_option_context_set_description(context,
- "Server Options:\n"
- " -s, --server [<path>]\n"
- " Register self at OBEX server and use given `path` as OPP save directory\n"
- " If `path` does not specified - use current directory\n\n"
- "OPP Options:\n"
- " -p, --opp <name|mac> <file>\n"
- " Send `file` to remote device using Object Push Profile\n\n"
- //"Report bugs to <"PACKAGE_BUGREPORT">."
- "Project home page <"PACKAGE_URL">."
- );
-
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- g_print("%s: %s\n", g_get_prgname(), error->message);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- } else if (!server_arg && !opp_arg && (!ftp_arg || strlen(ftp_arg) == 0)) {
- g_print("%s", g_option_context_get_help(context, FALSE, NULL));
- exit(EXIT_FAILURE);
- } else if (server_arg && argc != 1 && (argc != 2 || strlen(argv[1]) == 0)) {
- g_print("%s: Invalid arguments for --server\n", g_get_prgname());
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- } else if (opp_arg && (argc != 3 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0)) {
- g_print("%s: Invalid arguments for --opp\n", g_get_prgname());
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- }
-
- g_option_context_free(context);
-
- if (!dbus_system_connect(&error)) {
- g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- if (!dbus_session_connect(&error)) {
- g_printerr("Couldn't connect to DBus session bus: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- /* Check, that bluetooth daemon is running */
- if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) {
- g_printerr("%s: bluez service is not found\n", g_get_prgname());
- g_printerr("Did you forget to run bluetoothd?\n");
- exit(EXIT_FAILURE);
- }
-
- /* Check, that obexd daemon is running */
- if (!intf_supported(OBEXS_DBUS_NAME, OBEXMANAGER_DBUS_PATH, OBEXMANAGER_DBUS_INTERFACE)) {
- g_printerr("%s: obex service is not found\n", g_get_prgname());
- g_printerr("Did you forget to run obexd?\n");
- exit(EXIT_FAILURE);
- }
-
- if (server_arg) {
- if (argc == 2) {
- server_path_arg = argv[1];
- }
-
- /* Check that `path` is valid */
- gchar *root_folder = server_path_arg == NULL ? g_get_current_dir() : g_strdup(server_path_arg);
- if (!is_dir(root_folder, &error)) {
- exit_if_error(error);
- }
-
- server_transfers = g_hash_table_new(g_str_hash, g_str_equal);
-
- OBEXManager *manager = g_object_new(OBEXMANAGER_TYPE, NULL);
- g_signal_connect(manager, "SessionCreated", G_CALLBACK(obexmanager_session_created), NULL);
- g_signal_connect(manager, "SessionRemoved", G_CALLBACK(obexmanager_session_removed), NULL);
- g_signal_connect(manager, "TransferStarted", G_CALLBACK(obexmanager_transfer_started), NULL);
- g_signal_connect(manager, "TransferCompleted", G_CALLBACK(obexmanager_transfer_completed), NULL);
-
- OBEXAgent *agent = g_object_new(OBEXAGENT_TYPE, "RootFolder", root_folder, NULL);
-
- g_free(root_folder);
-
- obexmanager_register_agent(manager, OBEXAGENT_DBUS_PATH, &error);
- exit_if_error(error);
-
- mainloop = g_main_loop_new(NULL, FALSE);
-
- /* Add SIGTERM && SIGINT handlers */
- struct sigaction sa;
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = sigterm_handler;
- sigaction(SIGTERM, &sa, NULL);
- sigaction(SIGINT, &sa, NULL);
-
- g_main_loop_run(mainloop);
-
- /* Waiting for connections... */
-
- g_main_loop_unref(mainloop);
-
- /* Stop active transfers */
- GHashTableIter iter;
- gpointer key, value;
- g_hash_table_iter_init(&iter, server_transfers);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- OBEXTransfer *t = OBEXTRANSFER(value);
- obextransfer_cancel(t, NULL); // skip errors
- g_object_unref(t);
- g_hash_table_iter_remove(&iter);
- }
- g_hash_table_unref(server_transfers);
-
- obexmanager_unregister_agent(manager, OBEXAGENT_DBUS_PATH, &error);
- g_object_unref(agent);
- g_object_unref(manager);
- } else if (opp_arg) {
- opp_device_arg = argv[1];
- opp_file_arg = argv[2];
-
- /* Check that `file` is valid */
- if (!is_file(opp_file_arg, &error)) {
- exit_if_error(error);
- }
-
- gchar * files_to_send[] = {NULL, NULL};
- files_to_send[0] = g_path_is_absolute(opp_file_arg) ? g_strdup(opp_file_arg) : get_absolute_path(opp_file_arg);
-
- /* Get source address (address of adapter) */
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
- gchar *src_address = g_strdup(adapter_get_address(adapter));
-
- /* Get destination address (address of remote device) */
- gchar *dst_address = NULL;
- if (g_regex_match_simple("^\\x{2}:\\x{2}:\\x{2}:\\x{2}:\\x{2}:\\x{2}$", opp_device_arg, 0, 0)) {
- dst_address = g_strdup(opp_device_arg);
- } else {
- Device *device = find_device(adapter, opp_device_arg, &error);
- exit_if_error(error);
- dst_address = g_strdup(device_get_address(device));
- g_object_unref(device);
- }
-
- g_object_unref(adapter);
-
- /* Build arguments */
- GHashTable *device_dict = g_hash_table_new(g_str_hash, g_str_equal);
- GValue src_v = {0};
- GValue dst_v = {0};
- g_value_init(&src_v, G_TYPE_STRING);
- g_value_init(&dst_v, G_TYPE_STRING);
- g_value_set_string(&src_v, src_address);
- g_value_set_string(&dst_v, dst_address);
- g_hash_table_insert(device_dict, "Source", &src_v);
- g_hash_table_insert(device_dict, "Destination", &dst_v);
-
- mainloop = g_main_loop_new(NULL, FALSE);
-
- OBEXClient *client = g_object_new(OBEXCLIENT_TYPE, NULL);
-
- OBEXAgent *agent = g_object_new(OBEXAGENT_TYPE, NULL);
- g_signal_connect(agent, "AgentReleased", G_CALLBACK(agent_released), mainloop);
-
- /* Sending file(s) */
- obexclient_send_files(client, device_dict, files_to_send, OBEXAGENT_DBUS_PATH, &error);
- exit_if_error(error);
-
- /* Add SIGTERM && SIGINT handlers */
- struct sigaction sa;
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = sigterm_handler;
- sigaction(SIGTERM, &sa, NULL);
- sigaction(SIGINT, &sa, NULL);
-
- g_main_loop_run(mainloop);
-
- /* Sending files process here ?? */
-
- g_main_loop_unref(mainloop);
-
- g_object_unref(agent);
- g_object_unref(client);
-
- g_value_unset(&src_v);
- g_value_unset(&dst_v);
- g_hash_table_unref(device_dict);
-
- g_free(src_address);
- g_free(dst_address);
- g_free(files_to_send[0]);
- files_to_send[0] = NULL;
- } else if (ftp_arg) {
- /* Get source address (address of adapter) */
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
- gchar *src_address = g_strdup(adapter_get_address(adapter));
-
- /* Get destination address (address of remote device) */
- Device *device = find_device(adapter, ftp_arg, &error);
- exit_if_error(error);
- gchar *dst_address = g_strdup(device == NULL ? ftp_arg : device_get_address(device));
-
- g_object_unref(device);
- g_object_unref(adapter);
-
- /* Build arguments */
- GHashTable *device_dict = g_hash_table_new(g_str_hash, g_str_equal);
- GValue src_v = {0};
- GValue dst_v = {0};
- GValue target_v = {0};
- g_value_init(&src_v, G_TYPE_STRING);
- g_value_init(&dst_v, G_TYPE_STRING);
- g_value_init(&target_v, G_TYPE_STRING);
- g_value_set_string(&src_v, src_address);
- g_value_set_string(&dst_v, dst_address);
- g_value_set_string(&target_v, "FTP");
- g_hash_table_insert(device_dict, "Source", &src_v);
- g_hash_table_insert(device_dict, "Destination", &dst_v);
- g_hash_table_insert(device_dict, "Target", &target_v);
-
- OBEXClient *client = g_object_new(OBEXCLIENT_TYPE, NULL);
- OBEXAgent *agent = g_object_new(OBEXAGENT_TYPE, NULL);
-
- /* Create FTP session */
- gchar *session_path = obexclient_create_session(client, device_dict, &error);
- exit_if_error(error);
-
- OBEXClientFileTransfer *ftp_session = g_object_new(OBEXCLIENT_FILE_TRANSFER_TYPE, "DBusObjectPath", session_path, NULL);
- g_free(session_path);
-
- g_print("FTP session opened\n");
-
- while (TRUE) {
- gchar *cmd = readline("> ");
- if (cmd == NULL) {
- continue;
- } else {
- add_history(cmd);
- }
-
- gint f_argc;
- gchar **f_argv;
- /* Parsing command line */
- if (!g_shell_parse_argv(cmd, &f_argc, &f_argv, &error)) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
-
- g_free(cmd);
- continue;
- }
-
- /* Execute commands */
- if (g_strcmp0(f_argv[0], "cd") == 0) {
- if (f_argc != 2 || strlen(f_argv[1]) == 0) {
- g_print("invalid arguments\n");
- } else {
- obexclient_file_transfer_change_folder(ftp_session, f_argv[1], &error);
- if (error) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
- }
- }
- } else if (g_strcmp0(f_argv[0], "mkdir") == 0) {
- if (f_argc != 2 || strlen(f_argv[1]) == 0) {
- g_print("invalid arguments\n");
- } else {
- obexclient_file_transfer_create_folder(ftp_session, f_argv[1], &error);
- if (error) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
- }
- }
- } else if (g_strcmp0(f_argv[0], "ls") == 0) {
- if (f_argc != 1) {
- g_print("invalid arguments\n");
- } else {
- GPtrArray *folders = obexclient_file_transfer_list_folder(ftp_session, &error);
- if (error) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
- } else {
- for (int i = 0; i < folders->len; i++) {
- GHashTable *el = g_ptr_array_index(folders, i);
- g_print(
- "%s\t%llu\t%s\n",
- g_value_get_string(g_hash_table_lookup(el, "Type")),
- G_VALUE_HOLDS_UINT64(g_hash_table_lookup(el, "Size")) ?
- g_value_get_uint64(g_hash_table_lookup(el, "Size")) :
- 0,
- g_value_get_string(g_hash_table_lookup(el, "Name"))
- );
- }
- }
-
- if (folders) g_ptr_array_unref(folders);
-
- /*obexclient_remove_session(client, obexclient_file_transfer_get_dbus_object_path(ftp_session), &error);
- exit_if_error(error);
- g_object_unref(ftp_session);
- session_path = obexclient_create_session(client, device_dict, &error);
- exit_if_error(error);
- ftp_session = g_object_new(OBEXCLIENT_FILE_TRANSFER_TYPE, "DBusObjectPath", session_path, NULL);
- g_free(session_path);*/
-
- }
- } else if (g_strcmp0(f_argv[0], "get") == 0) {
- if (f_argc != 3 || strlen(f_argv[1]) == 0 || strlen(f_argv[2]) == 0) {
- g_print("invalid arguments\n");
- } else {
- gchar *abs_dst_path = get_absolute_path(f_argv[2]);
- gchar *dir = g_path_get_dirname(abs_dst_path);
- if (!is_dir(dir, &error)) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
- } else {
- obexclient_file_transfer_get_file(ftp_session, abs_dst_path, f_argv[1], &error);
- if (error) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
- }
- }
- g_free(dir);
- g_free(abs_dst_path);
- }
- } else if (g_strcmp0(f_argv[0], "put") == 0) {
- if (f_argc != 3 || strlen(f_argv[1]) == 0 || strlen(f_argv[2]) == 0) {
- g_print("invalid arguments\n");
- } else {
- gchar *abs_src_path = get_absolute_path(f_argv[1]);
- if (!is_file(abs_src_path, &error)) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
- } else {
- obexclient_file_transfer_put_file(ftp_session, abs_src_path, f_argv[2], &error);
- if (error) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
- }
- }
- g_free(abs_src_path);
- }
- } else if (g_strcmp0(f_argv[0], "cp") == 0) {
- if (f_argc != 3 || strlen(f_argv[1]) == 0 || strlen(f_argv[2]) == 0) {
- g_print("invalid arguments\n");
- } else {
- obexclient_file_transfer_copy_file(ftp_session, f_argv[1], f_argv[2], &error);
- if (error) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
- }
- }
- } else if (g_strcmp0(f_argv[0], "mv") == 0) {
- if (f_argc != 3 || strlen(f_argv[1]) == 0 || strlen(f_argv[2]) == 0) {
- g_print("invalid arguments\n");
- } else {
- obexclient_file_transfer_move_file(ftp_session, f_argv[1], f_argv[2], &error);
- if (error) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
- }
- }
- } else if (g_strcmp0(f_argv[0], "rm") == 0) {
- if (f_argc != 2 || strlen(f_argv[1]) == 0) {
- g_print("invalid arguments\n");
- } else {
- obexclient_file_transfer_delete(ftp_session, f_argv[1], &error);
- if (error) {
- g_print("%s\n", error->message);
- g_error_free(error);
- error = NULL;
- }
- }
- } else if (g_strcmp0(f_argv[0], "help") == 0) {
- g_print(
- "help\t\t\tShow this message\n"
- "exit\t\t\tClose FTP session\n"
- "cd <folder>\t\tChange the current folder of the remote device\n"
- "mkdir <folder>\t\tCreate a new folder in the remote device\n"
- "ls\t\t\tList folder contents\n"
- "get <src> <dst>\t\tCopy the src file (from remote device) to the dst file (on local filesystem)\n"
- "put <src> <dst>\t\tCopy the src file (from local filesystem) to the dst file (on remote device)\n"
- "cp <src> <dst>\t\tCopy a file within the remote device from src file to dst file\n"
- "mv <src> <dst>\t\tMove a file within the remote device from src file to dst file\n"
- "rm <target>\t\tDeletes the specified file/folder\n"
- );
- } else if (g_strcmp0(f_argv[0], "exit") == 0 || g_strcmp0(f_argv[0], "quit") == 0) {
- obexclient_remove_session(client, obexclient_file_transfer_get_dbus_object_path(ftp_session), &error);
- exit_if_error(error);
-
- g_strfreev(f_argv);
- g_free(cmd);
- break;
- } else {
- g_print("invalid command\n");
- }
-
- g_strfreev(f_argv);
- g_free(cmd);
- }
-
- g_object_unref(agent);
- g_object_unref(client);
- g_object_unref(ftp_session);
-
- g_value_unset(&src_v);
- g_value_unset(&dst_v);
- g_value_unset(&target_v);
- g_hash_table_unref(device_dict);
-
- g_free(src_address);
- g_free(dst_address);
- }
-
- dbus_disconnect();
-
- exit(EXIT_SUCCESS);
+ GError *error = NULL;
+ GOptionContext *context;
+
+ /* Query current locale */
+ setlocale(LC_CTYPE, "");
+
+ dbus_init();
+
+ context = g_option_context_new(" - a bluetooth OBEX client/server");
+ g_option_context_add_main_entries(context, entries, NULL);
+ g_option_context_set_summary(context, "Version "PACKAGE_VERSION);
+ g_option_context_set_description(context,
+ "Server Options:\n"
+ " -s, --server [<path>]\n"
+ " Register self at OBEX server and use given `path` as OPP save directory\n"
+ " If `path` does not specified - use current directory\n\n"
+ "OPP Options:\n"
+ " -p, --opp <name|mac> <file>\n"
+ " Send `file` to remote device using Object Push Profile\n\n"
+ "Report bugs to <"PACKAGE_BUGREPORT">."
+ "Project home page <"PACKAGE_URL">."
+ );
+
+ if (!g_option_context_parse(context, &argc, &argv, &error))
+ {
+ g_print("%s: %s\n", g_get_prgname(), error->message);
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+ else if (!server_arg && !opp_arg && (!ftp_arg || strlen(ftp_arg) == 0))
+ {
+ g_print("%s", g_option_context_get_help(context, FALSE, NULL));
+ exit(EXIT_FAILURE);
+ }
+ else if (server_arg && argc != 1 && (argc != 2 || strlen(argv[1]) == 0))
+ {
+ g_print("%s: Invalid arguments for --server\n", g_get_prgname());
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+ else if (opp_arg && (argc != 3 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0))
+ {
+ g_print("%s: Invalid arguments for --opp\n", g_get_prgname());
+ g_print("Try `%s --help` for more information.\n", g_get_prgname());
+ exit(EXIT_FAILURE);
+ }
+
+ g_option_context_free(context);
+
+ if (!dbus_system_connect(&error))
+ {
+ g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
+ exit(EXIT_FAILURE);
+ }
+
+ if (!dbus_session_connect(&error))
+ {
+ g_printerr("Couldn't connect to DBus session bus: %s\n", error->message);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Check, that bluetooth daemon is running */
+ if (!intf_supported(BLUEZ_DBUS_SERVICE_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE))
+ {
+ g_printerr("%s: bluez service is not found\n", g_get_prgname());
+ g_printerr("Did you forget to run bluetoothd?\n");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Check, that obexd daemon is running */
+ if (!intf_supported(BLUEZ_OBEX_DBUS_SERVICE_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE))
+ {
+ g_printerr("%s: obex service is not found\n", g_get_prgname());
+ g_printerr("Did you forget to run obexd?\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (server_arg)
+ {
+ if (argc == 2)
+ {
+ server_path_arg = argv[1];
+ }
+
+ /* Check that `path` is valid */
+ gchar *root_folder = server_path_arg == NULL ? g_get_current_dir() : g_strdup(server_path_arg);
+ if (!is_dir(root_folder, &error))
+ {
+ exit_if_error(error);
+ }
+ if(!write_access(root_folder, &error))
+ {
+ exit_if_error(error);
+ }
+
+ _transfers = g_hash_table_new(g_str_hash, g_str_equal);
+ _transfer_infos = g_hash_table_new(g_str_hash, g_str_equal);
+
+ ObexAgentManager *manager = obex_agent_manager_new();
+
+ guint obex_server_object_id = g_dbus_connection_signal_subscribe(session_conn, "org.bluez.obex", "org.freedesktop.DBus.ObjectManager", NULL, NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, _obex_server_object_manager_handler, NULL, NULL);
+ guint obex_server_properties_id = g_dbus_connection_signal_subscribe(session_conn, "org.bluez.obex", "org.freedesktop.DBus.Properties", "PropertiesChanged", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, _obex_server_properties_handler, NULL, NULL);
+
+ ObexAgent *agent = obex_agent_new(root_folder);
+ _root_path = g_strdup(root_folder);
+ g_free(root_folder);
+ obex_agent_set_approved_callback(agent, _agent_approved_callback, NULL);
+
+ obex_agent_manager_register_agent(manager, OBEX_AGENT_DBUS_PATH, &error);
+ exit_if_error(error);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+
+ /* Add SIGTERM && SIGINT handlers */
+ struct sigaction sa;
+ memset(&sa, 0, sizeof (sa));
+ sa.sa_handler = sigterm_handler;
+ sigaction(SIGTERM, &sa, NULL);
+ sigaction(SIGINT, &sa, NULL);
+
+ g_main_loop_run(mainloop);
+
+ /* Waiting for connections... */
+
+ g_main_loop_unref(mainloop);
+
+ /* Stop active transfers */
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, _transfers);
+ while (g_hash_table_iter_next(&iter, &key, &value))
+ {
+ ObexTransfer *t = OBEX_TRANSFER(value);
+ obex_transfer_cancel(t, NULL); // skip errors
+ g_object_unref(t);
+ g_hash_table_iter_remove(&iter);
+ }
+ g_hash_table_unref(_transfers);
+
+ // Remove transfer information
+ g_hash_table_iter_init(&iter, _transfer_infos);
+ while (g_hash_table_iter_next(&iter, &key, &value))
+ {
+ g_free(value);
+ g_hash_table_iter_remove(&iter);
+ }
+ g_hash_table_unref(_transfers);
+
+ g_dbus_connection_signal_unsubscribe(session_conn, obex_server_object_id);
+ g_dbus_connection_signal_unsubscribe(session_conn, obex_server_properties_id);
+
+ g_free(_root_path);
+
+ obex_agent_manager_unregister_agent(manager, OBEX_AGENT_DBUS_PATH, &error);
+ g_object_unref(agent);
+ g_object_unref(manager);
+ }
+ else if (opp_arg)
+ {
+ opp_device_arg = argv[1];
+ opp_file_arg = argv[2];
+
+ /* Check that `file` is valid */
+ if (!is_file(opp_file_arg, &error))
+ {
+ exit_if_error(error);
+ }
+
+ _transfers = g_hash_table_new(g_str_hash, g_str_equal);
+ _transfer_infos = g_hash_table_new(g_str_hash, g_str_equal);
+
+ gchar * files_to_send[] = {NULL, NULL};
+ files_to_send[0] = g_path_is_absolute(opp_file_arg) ? g_strdup(opp_file_arg) : get_absolute_path(opp_file_arg);
+
+ /* Get source address (address of adapter) */
+ Adapter *adapter = find_adapter(adapter_arg, &error);
+ exit_if_error(error);
+ gchar *src_address = g_strdup(adapter_get_address(adapter, &error));
+ exit_if_error(error);
+
+ /* Get destination address (address of remote device) */
+ gchar *dst_address = NULL;
+ if (g_regex_match_simple("^\\x{2}:\\x{2}:\\x{2}:\\x{2}:\\x{2}:\\x{2}$", opp_device_arg, 0, 0))
+ {
+ dst_address = g_strdup(opp_device_arg);
+ }
+ else
+ {
+ Device *device = find_device(adapter, opp_device_arg, &error);
+ exit_if_error(error);
+ dst_address = g_strdup(device_get_address(device, &error));
+ exit_if_error(error);
+ g_object_unref(device);
+ }
+
+ g_object_unref(adapter);
+
+ /* Build arguments */
+ GVariantBuilder *b = g_variant_builder_new(G_VARIANT_TYPE_VARDICT);
+ g_variant_builder_add(b, "{sv}", "Target", g_variant_new_string("opp"));
+ g_variant_builder_add(b, "{sv}", "Source", g_variant_new_string(src_address));
+ GVariant *device_dict = g_variant_builder_end(b);
+ g_variant_builder_unref(b);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+
+ ObexClient *client = obex_client_new();
+ const gchar *session_path = obex_client_create_session(client, dst_address, device_dict, &error);
+ exit_if_error(error);
+ ObexSession *session = obex_session_new(session_path);
+ ObexObjectPush *oop = obex_object_push_new(obex_session_get_dbus_object_path(session));
+
+ // initialize GDBus OBEX OPP client callbacks
+ guint obex_opp_object_man_id = g_dbus_connection_signal_subscribe(session_conn, "org.bluez.obex", "org.freedesktop.DBus.ObjectManager", NULL, NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, _obex_opp_client_object_manager_handler, NULL, NULL);
+ guint obex_opp_properties_id = g_dbus_connection_signal_subscribe(session_conn, "org.bluez.obex", "org.freedesktop.DBus.Properties", "PropertiesChanged", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, _obex_opp_client_properties_handler, NULL, NULL);
+
+ /* Sending file(s) */
+ obex_object_push_send_file(oop, files_to_send[0], &error);
+ exit_if_error(error);
+
+ /* Add SIGTERM && SIGINT handlers */
+ struct sigaction sa;
+ memset(&sa, 0, sizeof (sa));
+ sa.sa_handler = sigterm_handler;
+ sigaction(SIGTERM, &sa, NULL);
+ sigaction(SIGINT, &sa, NULL);
+
+ g_main_loop_run(mainloop);
+
+ /* Sending files process here ?? */
+
+ g_main_loop_unref(mainloop);
+
+ g_dbus_connection_signal_unsubscribe(session_conn, obex_opp_object_man_id);
+ g_dbus_connection_signal_unsubscribe(session_conn, obex_opp_properties_id);
+
+ /* Stop active transfers */
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, _transfers);
+ while (g_hash_table_iter_next(&iter, &key, &value))
+ {
+ ObexTransfer *t = OBEX_TRANSFER(value);
+ obex_transfer_cancel(t, NULL); // skip errors
+ g_object_unref(t);
+ g_hash_table_iter_remove(&iter);
+ }
+ g_hash_table_unref(_transfers);
+
+ // Remove transfer information objects
+ g_hash_table_iter_init(&iter, _transfer_infos);
+ while (g_hash_table_iter_next(&iter, &key, &value))
+ {
+ g_free(value);
+ g_hash_table_iter_remove(&iter);
+ }
+ g_hash_table_unref(_transfers);
+
+ g_object_unref(client);
+
+ g_variant_unref(device_dict);
+
+ g_free(src_address);
+ g_free(dst_address);
+ g_free(files_to_send[0]);
+ files_to_send[0] = NULL;
+ }
+ else if (ftp_arg)
+ {
+ /* Get source address (address of adapter) */
+ Adapter *adapter = find_adapter(adapter_arg, &error);
+ exit_if_error(error);
+ gchar *src_address = g_strdup(adapter_get_address(adapter, &error));
+ exit_if_error(error);
+
+ /* Get destination address (address of remote device) */
+ Device *device = find_device(adapter, ftp_arg, &error);
+ exit_if_error(error);
+ gchar *dst_address = g_strdup(device == NULL ? ftp_arg : device_get_address(device, &error));
+ exit_if_error(error);
+
+ g_object_unref(device);
+ g_object_unref(adapter);
+
+ /* Build arguments */
+ GVariantBuilder *b;
+ GVariant *device_dict;
+ b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(b, "{sv}", "Target", g_variant_new_string("ftp"));
+ g_variant_builder_add(b, "{sv}", "Source", g_variant_new_string(src_address));
+ device_dict = g_variant_builder_end(b);
+ g_variant_builder_unref(b);
+
+ ObexClient *client = g_object_new(OBEX_CLIENT_TYPE, NULL);
+ ObexAgent *agent = g_object_new(OBEX_AGENT_TYPE, NULL);
+
+ /* Create FTP session */
+ gchar *session_path = g_strdup(obex_client_create_session(client, dst_address, device_dict, &error));
+ exit_if_error(error);
+
+ ObexFileTransfer *ftp_session = obex_file_transfer_new(session_path);
+ g_free(session_path);
+
+ g_print("FTP session opened\n");
+
+ while (TRUE)
+ {
+ gchar *cmd = readline("> ");
+ if (cmd == NULL)
+ {
+ continue;
+ }
+ else
+ {
+ add_history(cmd);
+ }
+
+ gint f_argc;
+ gchar **f_argv;
+ /* Parsing command line */
+ if (!g_shell_parse_argv(cmd, &f_argc, &f_argv, &error))
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+
+ g_free(cmd);
+ continue;
+ }
+
+ /* Execute commands */
+ if (g_strcmp0(f_argv[0], "cd") == 0)
+ {
+ if (f_argc != 2 || strlen(f_argv[1]) == 0)
+ {
+ g_print("invalid arguments\n");
+ }
+ else
+ {
+ obex_file_transfer_change_folder(ftp_session, f_argv[1], &error);
+ if (error)
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ }
+ }
+ else if (g_strcmp0(f_argv[0], "mkdir") == 0)
+ {
+ if (f_argc != 2 || strlen(f_argv[1]) == 0)
+ {
+ g_print("invalid arguments\n");
+ }
+ else
+ {
+ obex_file_transfer_create_folder(ftp_session, f_argv[1], &error);
+ if (error)
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ }
+ }
+ else if (g_strcmp0(f_argv[0], "ls") == 0)
+ {
+ if (f_argc != 1)
+ {
+ g_print("invalid arguments\n");
+ }
+ else
+ {
+ // GPtrArray *folders = obex_file_transfer_list_folder(ftp_session, &error);
+ GVariant *folder_list = obex_file_transfer_list_folder(ftp_session, &error);
+ GPtrArray *folders = g_ptr_array_new();
+ gsize arr_size = 0;
+ // Pass the pointer
+ folders->pdata = (gpointer) g_variant_get_fixed_array(folder_list, &arr_size, sizeof(gpointer));
+ folders->len = arr_size;
+
+ if (error)
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ else
+ {
+ for (int i = 0; i < folders->len; i++)
+ {
+ /*
+ GHashTable *el = g_ptr_array_index(folders, i);
+ g_print(
+ "%s\t%llu\t%s\n",
+ g_value_get_string(g_hash_table_lookup(el, "Type")),
+ G_VALUE_HOLDS_UINT64(g_hash_table_lookup(el, "Size")) ?
+ g_value_get_uint64(g_hash_table_lookup(el, "Size")) :
+ 0,
+ g_value_get_string(g_hash_table_lookup(el, "Name"))
+ );
+ */
+
+ // DO NOT FREE THIS
+ GVariant *el = g_ptr_array_index(folders, i);
+ g_print(
+ "%s\t%llu\t%s\n",
+ g_variant_get_string(g_variant_lookup_value(el, "Type", G_VARIANT_TYPE("s")), NULL),
+ g_variant_get_uint64(g_variant_lookup_value(el, "Size", G_VARIANT_TYPE("t"))),
+ g_variant_get_string(g_variant_lookup_value(el, "Name", G_VARIANT_TYPE("s")), NULL)
+ );
+ }
+ }
+
+ // Do not free the contents of the array. g_variant_unref will free contents
+ if (folders)
+ g_ptr_array_free(folders, FALSE);
+
+ if (folder_list)
+ g_variant_unref(folder_list);
+
+ /*obexclient_remove_session(client, obexclient_file_transfer_get_dbus_object_path(ftp_session), &error);
+ exit_if_error(error);
+ g_object_unref(ftp_session);
+ session_path = obexclient_create_session(client, device_dict, &error);
+ exit_if_error(error);
+ ftp_session = g_object_new(OBEXCLIENT_FILE_TRANSFER_TYPE, "DBusObjectPath", session_path, NULL);
+ g_free(session_path);*/
+
+ }
+ }
+ else if (g_strcmp0(f_argv[0], "get") == 0)
+ {
+ if (f_argc != 3 || strlen(f_argv[1]) == 0 || strlen(f_argv[2]) == 0)
+ {
+ g_print("invalid arguments\n");
+ }
+ else
+ {
+ gchar *abs_dst_path = get_absolute_path(f_argv[2]);
+ gchar *dir = g_path_get_dirname(abs_dst_path);
+ if (!is_dir(dir, &error))
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ else
+ {
+ obex_file_transfer_get_file(ftp_session, abs_dst_path, f_argv[1], &error);
+ if (error)
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ }
+ g_free(dir);
+ g_free(abs_dst_path);
+ }
+ }
+ else if (g_strcmp0(f_argv[0], "put") == 0)
+ {
+ if (f_argc != 3 || strlen(f_argv[1]) == 0 || strlen(f_argv[2]) == 0)
+ {
+ g_print("invalid arguments\n");
+ }
+ else
+ {
+ gchar *abs_src_path = get_absolute_path(f_argv[1]);
+ if (!is_file(abs_src_path, &error))
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ else
+ {
+ obex_file_transfer_put_file(ftp_session, abs_src_path, f_argv[2], &error);
+ if (error)
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ }
+ g_free(abs_src_path);
+ }
+ }
+ else if (g_strcmp0(f_argv[0], "cp") == 0)
+ {
+ if (f_argc != 3 || strlen(f_argv[1]) == 0 || strlen(f_argv[2]) == 0)
+ {
+ g_print("invalid arguments\n");
+ }
+ else
+ {
+ obex_file_transfer_copy_file(ftp_session, f_argv[1], f_argv[2], &error);
+ if (error)
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ }
+ }
+ else if (g_strcmp0(f_argv[0], "mv") == 0)
+ {
+ if (f_argc != 3 || strlen(f_argv[1]) == 0 || strlen(f_argv[2]) == 0)
+ {
+ g_print("invalid arguments\n");
+ }
+ else
+ {
+ obex_file_transfer_move_file(ftp_session, f_argv[1], f_argv[2], &error);
+ if (error)
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ }
+ }
+ else if (g_strcmp0(f_argv[0], "rm") == 0)
+ {
+ if (f_argc != 2 || strlen(f_argv[1]) == 0)
+ {
+ g_print("invalid arguments\n");
+ }
+ else
+ {
+ obex_file_transfer_delete(ftp_session, f_argv[1], &error);
+ if (error)
+ {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ }
+ }
+ else if (g_strcmp0(f_argv[0], "help") == 0)
+ {
+ g_print(
+ "help\t\t\tShow this message\n"
+ "exit\t\t\tClose FTP session\n"
+ "cd <folder>\t\tChange the current folder of the remote device\n"
+ "mkdir <folder>\t\tCreate a new folder in the remote device\n"
+ "ls\t\t\tList folder contents\n"
+ "get <src> <dst>\t\tCopy the src file (from remote device) to the dst file (on local filesystem)\n"
+ "put <src> <dst>\t\tCopy the src file (from local filesystem) to the dst file (on remote device)\n"
+ "cp <src> <dst>\t\tCopy a file within the remote device from src file to dst file\n"
+ "mv <src> <dst>\t\tMove a file within the remote device from src file to dst file\n"
+ "rm <target>\t\tDeletes the specified file/folder\n"
+ );
+ }
+ else if (g_strcmp0(f_argv[0], "exit") == 0 || g_strcmp0(f_argv[0], "quit") == 0)
+ {
+ obex_client_remove_session(client, obex_file_transfer_get_dbus_object_path(ftp_session), &error);
+ exit_if_error(error);
+
+ g_strfreev(f_argv);
+ g_free(cmd);
+ break;
+ }
+ else
+ {
+ g_print("invalid command\n");
+ }
+
+ g_strfreev(f_argv);
+ g_free(cmd);
+ }
+
+ g_object_unref(agent);
+ g_object_unref(client);
+ g_object_unref(ftp_session);
+
+ g_variant_unref(device_dict);
+
+ g_free(src_address);
+ g_free(dst_address);
+ }
+
+ dbus_disconnect();
+
+ exit(EXIT_SUCCESS);
}
-
diff --git a/src/bt-serial.1 b/src/bt-serial.1
deleted file mode 100644
index a7688a8..0000000
--- a/src/bt-serial.1
+++ /dev/null
@@ -1,170 +0,0 @@
-.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
-.\"
-.\" Standard preamble:
-.\" ========================================================================
-.de Sp \" Vertical space (when we can't use .PP)
-.if t .sp .5v
-.if n .sp
-..
-.de Vb \" Begin verbatim text
-.ft CW
-.nf
-.ne \\$1
-..
-.de Ve \" End verbatim text
-.ft R
-.fi
-..
-.\" Set up some character translations and predefined strings. \*(-- will
-.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
-.\" double quote, and \*(R" will give a right double quote. \*(C+ will
-.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
-.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
-.\" nothing in troff, for use with C<>.
-.tr \(*W-
-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
-.ie n \{\
-. ds -- \(*W-
-. ds PI pi
-. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
-. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
-. ds L" ""
-. ds R" ""
-. ds C` ""
-. ds C' ""
-'br\}
-.el\{\
-. ds -- \|\(em\|
-. ds PI \(*p
-. ds L" ``
-. ds R" ''
-'br\}
-.\"
-.\" Escape single quotes in literal strings from groff's Unicode transform.
-.ie \n(.g .ds Aq \(aq
-.el .ds Aq '
-.\"
-.\" If the F register is turned on, we'll generate index entries on stderr for
-.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
-.\" entries marked with X<> in POD. Of course, you'll have to process the
-.\" output yourself in some meaningful fashion.
-.ie \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
-..
-. nr % 0
-. rr F
-.\}
-.el \{\
-. de IX
-..
-.\}
-.\"
-.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
-.\" Fear. Run. Save yourself. No user-serviceable parts.
-. \" fudge factors for nroff and troff
-.if n \{\
-. ds #H 0
-. ds #V .8m
-. ds #F .3m
-. ds #[ \f1
-. ds #] \fP
-.\}
-.if t \{\
-. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
-. ds #V .6m
-. ds #F 0
-. ds #[ \&
-. ds #] \&
-.\}
-. \" simple accents for nroff and troff
-.if n \{\
-. ds ' \&
-. ds ` \&
-. ds ^ \&
-. ds , \&
-. ds ~ ~
-. ds /
-.\}
-.if t \{\
-. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
-. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
-. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
-. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
-. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
-. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
-.\}
-. \" troff and (daisy-wheel) nroff accents
-.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
-.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
-.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
-.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
-.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
-.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
-.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
-.ds ae a\h'-(\w'a'u*4/10)'e
-.ds Ae A\h'-(\w'A'u*4/10)'E
-. \" corrections for vroff
-.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
-.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
-. \" for low resolution devices (crt and lpr)
-.if \n(.H>23 .if \n(.V>19 \
-\{\
-. ds : e
-. ds 8 ss
-. ds o a
-. ds d- d\h'-1'\(ga
-. ds D- D\h'-1'\(hy
-. ds th \o'bp'
-. ds Th \o'LP'
-. ds ae ae
-. ds Ae AE
-.\}
-.rm #[ #] #H #V #F C
-.\" ========================================================================
-.\"
-.IX Title "bt-serial 1"
-.TH bt-serial 1 "2010-08-12" "" "bluez-tools"
-.\" For nroff, turn off justification. Always turn off hyphenation; it makes
-.\" way too many mistakes in technical documents.
-.if n .ad l
-.nh
-.SH "NAME"
-bt\-serial \- a bluetooth serial manager
-.SH "SYNOPSIS"
-.IX Header "SYNOPSIS"
-bt-serial [\s-1OPTION\s0...]
-.PP
-Help Options:
- \-h, \-\-help
-.PP
-Application Options:
- \-a, \-\-adapter=<name|mac>
- \-c, \-\-connect <name|mac> <pattern>
- \-d, \-\-disconnect <name|mac> <tty_device>
-.SH "DESCRIPTION"
-.IX Header "DESCRIPTION"
-This utility is used to manage serial service connections.
-.SH "OPTIONS"
-.IX Header "OPTIONS"
-\&\fB\-h, \-\-help\fR
- Show help
-.PP
-\&\fB\-a, \-\-adapter <name|mac>\fR
- Specify adapter to use by his Name or \s-1MAC\s0 address
- (if this option does not defined \- default adapter used)
-.PP
-\&\fB\-c, \-\-connect <name|mac> <pattern>\fR
- Connects to a specific \s-1RFCOMM\s0 based service on a
- remote device and then creates a \s-1RFCOMM\s0 \s-1TTY\s0
- device for it; `pattern` is a profile short name (spp, dun),
- \s-1RFCOMM\s0 channel (1\-30)
-.PP
-\&\fB\-d, \-\-disconnect <name|mac> <tty_device>\fR
- Disconnect a \s-1RFCOMM\s0 \s-1TTY\s0 device that has been created
-.SH "AUTHOR"
-.IX Header "AUTHOR"
-Alexander Orlenko <zxteam@gmail.com>.
-.SH "SEE ALSO"
-.IX Header "SEE ALSO"
-\&\fIbt\-adapter\fR\|(1) \fIbt\-agent\fR\|(1) \fIbt\-audio\fR\|(1) \fIbt\-device\fR\|(1) \fIbt\-input\fR\|(1) \fIbt\-monitor\fR\|(1) \fIbt\-network\fR\|(1)
diff --git a/src/bt-serial.c b/src/bt-serial.c
deleted file mode 100644
index db39e9f..0000000
--- a/src/bt-serial.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- *
- * 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 <locale.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <glib.h>
-
-#include "lib/dbus-common.h"
-#include "lib/helpers.h"
-#include "lib/bluez-api.h"
-
-static gchar *adapter_arg = NULL;
-static gboolean connect_arg = FALSE;
-static gchar *connect_device_arg = NULL;
-static gchar *connect_service_arg = NULL;
-static gboolean disconnect_arg = FALSE;
-static gchar *disconnect_device_arg = NULL;
-static gchar *disconnect_tty_device_arg = NULL;
-
-static GOptionEntry entries[] = {
- {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter Name or MAC", "<name|mac>"},
- {"connect", 'c', 0, G_OPTION_ARG_NONE, &connect_arg, "Connect to the serial device", NULL},
- {"disconnect", 'd', 0, G_OPTION_ARG_NONE, &disconnect_arg, "Disconnect from the serial device", NULL},
- {NULL}
-};
-
-int main(int argc, char *argv[])
-{
- GError *error = NULL;
- GOptionContext *context;
-
- /* Query current locale */
- setlocale(LC_CTYPE, "");
-
- g_type_init();
- dbus_init();
-
- context = g_option_context_new(" - a bluetooth serial manager");
- g_option_context_add_main_entries(context, entries, NULL);
- g_option_context_set_summary(context, "Version "PACKAGE_VERSION);
- g_option_context_set_description(context,
- "Connect Options:\n"
- " -c, --connect <name|mac> <pattern>\n"
- " Where\n"
- " `name|mac` is a device Name or MAC\n"
- " `pattern` is:\n"
- " UUID 128 bit string\n"
- " Profile short name, e.g: spp, dun\n"
- " RFCOMM channel, 1-30\n\n"
- "Disconnect Options:\n"
- " -d, --disconnect <name|mac> <tty_device>\n"
- " Where\n"
- " `name|mac` is a device Name or MAC\n"
- " `tty_device` is a RFCOMM TTY device that has been connected\n\n"
- //"Report bugs to <"PACKAGE_BUGREPORT">."
- "Project home page <"PACKAGE_URL">."
- );
-
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- g_print("%s: %s\n", g_get_prgname(), error->message);
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- } else if (!connect_arg && !disconnect_arg) {
- g_print("%s", g_option_context_get_help(context, FALSE, NULL));
- exit(EXIT_FAILURE);
- } else if (connect_arg && (argc != 3 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0)) {
- g_print("%s: Invalid arguments for --connect\n", g_get_prgname());
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- } else if (disconnect_arg && (argc != 3 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0)) {
- g_print("%s: Invalid arguments for --disconnect\n", g_get_prgname());
- g_print("Try `%s --help` for more information.\n", g_get_prgname());
- exit(EXIT_FAILURE);
- }
-
- g_option_context_free(context);
-
- if (connect_arg) {
- connect_device_arg = argv[1];
- connect_service_arg = argv[2];
- } else {
- disconnect_device_arg = argv[1];
- disconnect_tty_device_arg = argv[2];
- }
-
- if (!dbus_system_connect(&error)) {
- g_printerr("Couldn't connect to DBus system bus: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- /* Check, that bluetooth daemon is running */
- if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) {
- g_printerr("%s: bluez service is not found\n", g_get_prgname());
- g_printerr("Did you forget to run bluetoothd?\n");
- exit(EXIT_FAILURE);
- }
-
- Adapter *adapter = find_adapter(adapter_arg, &error);
- exit_if_error(error);
-
- Device *device = find_device(adapter, connect_device_arg != NULL ? connect_device_arg : disconnect_device_arg, &error);
- exit_if_error(error);
-
- if (!intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), SERIAL_DBUS_INTERFACE)) {
- g_printerr("Serial service is not supported by this device\n");
- exit(EXIT_FAILURE);
- }
-
- Serial *serial = g_object_new(SERIAL_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL);
-
- if (connect_arg) {
- gchar *tty_device = serial_connect(serial, connect_service_arg, &error);
- exit_if_error(error);
- g_print("Created RFCOMM TTY device: %s\n", tty_device);
- g_free(tty_device);
- } else if (disconnect_arg) {
- serial_disconnect(serial, disconnect_tty_device_arg, &error);
- exit_if_error(error);
- g_print("Done\n");
- }
-
- g_object_unref(serial);
- g_object_unref(device);
- g_object_unref(adapter);
- dbus_disconnect();
-
- exit(EXIT_SUCCESS);
-}
-
diff --git a/src/lib/agent-helper.c b/src/lib/agent-helper.c
new file mode 100644
index 0000000..5269005
--- /dev/null
+++ b/src/lib/agent-helper.c
@@ -0,0 +1,371 @@
+/*
+ *
+ * bluez-tools - a set of tools to manage bluetooth devices for linux
+ *
+ * Copyright (C) 2010-2011 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 <errno.h>
+#include <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "agent-helper.h"
+
+static const gchar *_bt_agent_introspect_xml = "<node name=\"/org/blueztools\">\n\t<interface name=\"org.bluez.Agent1\">\n\t\t<method name=\"Release\">\n\t\t</method>\n\t\t<method name=\"RequestPinCode\">\n\t\t\t<arg name=\"device\" direction=\"in\" type=\"o\"/>\n\t\t\t<arg name=\"pincode\" direction=\"out\" type=\"s\"/>\n\t\t</method>\n\t\t<method name=\"DisplayPinCode\">\n\t\t\t<arg name=\"device\" direction=\"in\" type=\"o\"/>\n\t\t\t<arg name=\"pincode\" direction=\"in\" type=\"s\"/>\n\t\t</method>\n\t\t<method name=\"RequestPasskey\">\n\t\t\t<arg name=\"device\" direction=\"in\" type=\"o\"/>\n\t\t\t<arg name=\"passkey\" direction=\"out\" type=\"u\"/>\n\t\t</method>\n\t\t<method name=\"DisplayPasskey\">\n\t\t\t<arg name=\"device\" direction=\"in\" type=\"o\"/>\n\t\t\t<arg name=\"passkey\" direction=\"in\" type=\"u\"/>\n\t\t\t<arg name=\"entered\" direction=\"in\" type=\"q\"/>\n\t\t</method>\n\t\t<method name=\"RequestConfirmation\">\n\t\t\t<arg name=\"device\" direction=\"in\" type=\"o\"/>\n\t\t\t<arg name=\"passkey\" direction=\"in\" type=\"u\"/>\n\t\t</method>\n\t\t<method name=\"RequestAuthorization\">\n\t\t\t<arg name=\"device\" direction=\"in\" type=\"o\"/>\n\t\t</method>\n\t\t<method name=\"AuthorizeService\">\n\t\t\t<arg name=\"device\" direction=\"in\" type=\"o\"/>\n\t\t\t<arg name=\"uuid\" direction=\"in\" type=\"s\"/>\n\t\t</method>\n\t\t<method name=\"Cancel\">\n\t\t</method>\n\t</interface>\n</node>\n";
+static guint _bt_agent_registration_id = 0;
+static GHashTable *_pin_hash_table = NULL;
+static gboolean _interactive = TRUE;
+static GMainLoop *_mainloop = NULL;
+
+static void _bt_agent_g_destroy_notify(gpointer data);
+static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data);
+static const gchar *_find_device_pin(const gchar *device_path);
+
+static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ // g_print("%s%s\n", method_name, g_variant_print(parameters, FALSE));
+
+ if (g_strcmp0(method_name, "AuthorizeService") == 0)
+ {
+ // Return void
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ }
+ else if (g_strcmp0(method_name, "Cancel") == 0)
+ {
+ if (_interactive)
+ g_print("Request canceled\n");
+ // Return void
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ }
+ else if (g_strcmp0(method_name, "DisplayPasskey") == 0)
+ {
+ GError *error = NULL;
+ Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
+ const gchar *pin = _find_device_pin(device_get_dbus_object_path(device_obj));
+
+ if (_interactive)
+ g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
+
+ if (error)
+ {
+ g_critical("Failed to get remote device's MAC address: %s", error->message);
+ g_error_free(error);
+ }
+
+ g_object_unref(device_obj);
+
+ if (_interactive)
+ {
+ g_print("Passkey: %u, entered: %u\n", g_variant_get_uint32(g_variant_get_child_value(parameters, 1)), g_variant_get_uint16(g_variant_get_child_value(parameters, 2)));
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ return;
+ }
+ else if (pin != NULL)
+ {
+ /* OK, device found */
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ return;
+ }
+
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Pairing rejected");
+ }
+ else if (g_strcmp0(method_name, "DisplayPinCode") == 0)
+ {
+ GError *error = NULL;
+ Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
+ const gchar *pin = _find_device_pin(device_get_dbus_object_path(device_obj));
+ const gchar *pincode = g_variant_get_string(g_variant_get_child_value(parameters, 1), NULL);
+
+ if (_interactive)
+ g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
+
+ if (error)
+ {
+ g_critical("Failed to get remote device's MAC address: %s", error->message);
+ g_error_free(error);
+ }
+
+ g_object_unref(device_obj);
+
+ /* Try to use found PIN */
+ if (pin != NULL)
+ {
+ if (g_strcmp0(pin, "*") == 0 || g_strcmp0(pin, pincode) == 0)
+ {
+ if (_interactive)
+ g_print("Pin code confirmed\n");
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ }
+ else
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Passkey does not match");
+
+ return;
+ }
+ else if (_interactive)
+ {
+ g_print("Confirm pin code: %s (yes/no)? ", pincode);
+
+ gchar yn[4] = {0,};
+ errno = 0;
+ if (scanf("%3s", yn) == EOF && errno)
+ g_warning("%s\n", strerror(errno));
+ if(g_ascii_strcasecmp(yn, "yes") == 0 || g_ascii_strcasecmp(yn, "y") == 0)
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ else
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Passkey does not match");
+ return;
+ }
+
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Pairing rejected");
+ }
+ else if (g_strcmp0(method_name, "Release") == 0)
+ {
+ agent_need_unregister = FALSE;
+
+ if(_mainloop)
+ if (g_main_loop_is_running(_mainloop))
+ g_main_loop_quit(_mainloop);
+
+ g_print("Agent released\n");
+
+ // Return void
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ }
+ else if (g_strcmp0(method_name, "RequestAuthorization") == 0)
+ {
+ GError *error = NULL;
+ Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
+
+ if (_interactive)
+ g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
+
+ if(error)
+ {
+ g_critical("Failed to get remote device's MAC address: %s", error->message);
+ g_error_free(error);
+ }
+
+ g_object_unref(device_obj);
+
+ if (_interactive)
+ {
+ g_print("Authorize this device pairing (yes/no)? ");
+ gchar yn[4] = {0,};
+ errno = 0;
+ if (scanf("%3s", yn) == EOF && errno)
+ g_warning("%s\n", strerror(errno));
+ if(g_ascii_strcasecmp(yn, "yes") == 0 || g_ascii_strcasecmp(yn, "y") == 0)
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ else
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Pairing rejected");
+ return;
+ }
+
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Pairing rejected");
+ }
+ else if (g_strcmp0(method_name, "RequestConfirmation") == 0)
+ {
+ GError *error = NULL;
+ Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
+ guint32 passkey = g_variant_get_uint32(g_variant_get_child_value(parameters, 1));
+ const gchar *pin = _find_device_pin(device_get_dbus_object_path(device_obj));
+
+ if (_interactive)
+ g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
+
+ if(error)
+ {
+ g_critical("Failed to get remote device's MAC address: %s", error->message);
+ g_error_free(error);
+ }
+
+ g_object_unref(device_obj);
+
+ /* Try to use found PIN */
+ if (pin != NULL)
+ {
+ guint32 passkey_t;
+ sscanf(pin, "%u", &passkey_t);
+
+ if (g_strcmp0(pin, "*") == 0 || passkey_t == passkey)
+ {
+ if (_interactive)
+ g_print("Passkey confirmed\n");
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ }
+ else
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Passkey does not match");
+
+ return;
+ }
+ else if (_interactive)
+ {
+ g_print("Confirm passkey: %u (yes/no)? ", passkey);
+ gchar yn[4] = {0,};
+ errno = 0;
+ if (scanf("%3s", yn) == EOF && errno)
+ g_warning("%s\n", strerror(errno));
+ if(g_ascii_strcasecmp(yn, "yes") == 0 || g_ascii_strcasecmp(yn, "y") == 0)
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ else
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Passkey does not match");
+ return;
+ }
+
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Passkey does not match");
+ }
+ else if (g_strcmp0(method_name, "RequestPasskey") == 0)
+ {
+ GError *error = NULL;
+ Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
+ const gchar *pin = _find_device_pin(device_get_dbus_object_path(device_obj));
+ guint32 ret = 0;
+
+ if (_interactive)
+ g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
+
+ if(error)
+ {
+ g_critical("Failed to get remote device's MAC address: %s", error->message);
+ g_error_free(error);
+ }
+
+ g_object_unref(device_obj);
+
+ /* Try to use found PIN */
+ if (pin != NULL)
+ {
+ if (_interactive)
+ g_print("Passkey found\n");
+ sscanf(pin, "%u", &ret);
+ g_dbus_method_invocation_return_value(invocation, g_variant_new_uint32(ret));
+ return;
+ }
+ else if (_interactive)
+ {
+ g_print("Enter passkey: ");
+ errno = 0;
+ if (scanf("%u", &ret) == EOF && errno)
+ g_warning("%s\n", strerror(errno));
+ g_dbus_method_invocation_return_value(invocation, g_variant_new_uint32(ret));
+ return;
+ }
+
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "No passkey inputted");
+ }
+ else if (g_strcmp0(method_name, "RequestPinCode") == 0)
+ {
+ GError *error = NULL;
+ Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
+ const gchar *pin = _find_device_pin(device_get_dbus_object_path(device_obj));
+ const gchar *ret = NULL;
+
+ if (_interactive)
+ g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
+
+ if(error)
+ {
+ g_critical("Failed to get remote device's MAC address: %s", error->message);
+ g_error_free(error);
+ }
+
+ g_object_unref(device_obj);
+
+ /* Try to use found PIN */
+ if (pin != NULL)
+ {
+ if (_interactive)
+ g_print("Passkey found\n");
+ sscanf(pin, "%s", &ret);
+ g_dbus_method_invocation_return_value(invocation, g_variant_new_string(ret));
+ return;
+ }
+ else if (_interactive)
+ {
+ g_print("Enter passkey: ");
+ errno = 0;
+ if (scanf("%s", &ret) == EOF && errno)
+ g_warning("%s\n", strerror(errno));
+ g_dbus_method_invocation_return_value(invocation, g_variant_new_string(ret));
+ return;
+ }
+
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "No passkey inputted");
+ }
+}
+
+static void _bt_agent_g_destroy_notify(gpointer data)
+{
+ g_free(data);
+}
+
+static const gchar *_find_device_pin(const gchar *device_path)
+{
+ if (_pin_hash_table)
+ {
+ GError *error = NULL;
+ Device *device = device_new(device_path);
+ const gchar *pin_by_addr = g_hash_table_lookup(_pin_hash_table, device_get_address(device, &error));
+ const gchar *pin_by_alias = g_hash_table_lookup(_pin_hash_table, device_get_alias(device, &error));
+ if(error)
+ {
+ g_critical("Failed to get remote device's MAC address: %s", error->message);
+ g_error_free(error);
+ }
+ g_object_unref(device);
+ const gchar *pin_all = g_hash_table_lookup(_pin_hash_table, "*");
+ if (pin_by_addr)
+ return pin_by_addr;
+ else if (pin_by_alias)
+ return pin_by_alias;
+ else if (pin_all)
+ return pin_all;
+ }
+ return NULL;
+}
+
+void register_agent_callbacks(gboolean interactive_console, GHashTable *pin_dictonary, gpointer main_loop_object, GError **error)
+{
+ GDBusInterfaceVTable bt_agent_table;
+ memset(&bt_agent_table, 0x0, sizeof(bt_agent_table));
+
+ if(pin_dictonary)
+ _pin_hash_table = pin_dictonary;
+ if(main_loop_object)
+ _mainloop = (GMainLoop *) main_loop_object;
+
+ _interactive = interactive_console;
+
+ GDBusNodeInfo *bt_agent_node_info = g_dbus_node_info_new_for_xml(_bt_agent_introspect_xml, error);
+ GDBusInterfaceInfo *bt_agent_interface_info = g_dbus_node_info_lookup_interface(bt_agent_node_info, AGENT_DBUS_INTERFACE);
+ bt_agent_table.method_call = _bt_agent_method_call_func;
+ _bt_agent_registration_id = g_dbus_connection_register_object(g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error), AGENT_PATH, bt_agent_interface_info, &bt_agent_table, NULL, _bt_agent_g_destroy_notify, error);
+ g_dbus_node_info_unref(bt_agent_node_info);
+}
+
+void unregister_agent_callbacks(GError **error)
+{
+ if (_bt_agent_registration_id)
+ g_dbus_connection_unregister_object(g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error), _bt_agent_registration_id);
+} \ No newline at end of file
diff --git a/src/lib/obexd-api.h b/src/lib/agent-helper.h
index 09695f6..8e1cc85 100644
--- a/src/lib/obexd-api.h
+++ b/src/lib/agent-helper.h
@@ -21,31 +21,27 @@
*
*/
-#ifndef __OBEXD_API_H
-#define __OBEXD_API_H
+#ifndef __AGENT_HELPER_H
+#define __AGENT_HELPER_H
-#ifdef HAVE_CONFIG_H
-#include <config.h>
+#ifdef __cplusplus
+extern "C" {
#endif
-/* Global includes */
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#ifdef OBEX_SUPPORT
-#define OBEXS_DBUS_NAME "org.openobex"
-#define OBEXC_DBUS_NAME "org.openobex.client"
-
-/* OBEXD DBus API */
-#include "obexd/obexagent.h"
-#include "obexd/obexclient.h"
-#include "obexd/obexclient_file_transfer.h"
-#include "obexd/obexclient_session.h"
-#include "obexd/obexclient_transfer.h"
-#include "obexd/obexmanager.h"
-#include "obexd/obexsession.h"
-#include "obexd/obextransfer.h"
-#endif
+#include <stdio.h>
+
+#include "bluez-api.h"
+
+#define AGENT_DBUS_INTERFACE "org.bluez.Agent1"
+#define AGENT_PATH "/org/blueztools"
-#endif /* __OBEXD_API_H */
+gboolean agent_need_unregister;
+
+void register_agent_callbacks(gboolean interactive_console, GHashTable *pin_dictonary, gpointer main_loop_object, GError **error);
+void unregister_agent_callbacks(GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __AGENT_HELPER_H */ \ No newline at end of file
diff --git a/src/lib/bluez-api.h b/src/lib/bluez-api.h
index 241ad75..e3d5dd9 100644
--- a/src/lib/bluez-api.h
+++ b/src/lib/bluez-api.h
@@ -1,49 +1,55 @@
-/*
- *
- * 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 BLUEZ_API_H
+#define BLUEZ_API_H
-#ifndef __BLUEZ_API_H
-#define __BLUEZ_API_H
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
+#ifdef __cplusplus
+extern "C" {
#endif
-/* Global includes */
-#include <glib.h>
-#include <dbus/dbus-glib.h>
+#define BLUEZ_DBUS_SERVICE_NAME "org.bluez"
+#define BLUEZ_OBEX_DBUS_SERVICE_NAME "org.bluez.obex"
+#define BLUEZ_DBUS_BASE_PATH "/org/bluez"
+#define BLUEZ_OBEX_DBUS_BASE_PATH "/org/bluez/obex"
-#define BLUEZ_DBUS_NAME "org.bluez"
+#include "manager.h"
+#include "obex_agent.h"
-/* BlueZ DBus API */
#include "bluez/adapter.h"
-#include "bluez/agent.h"
-#include "bluez/audio.h"
+#include "bluez/agent_manager.h"
+#include "bluez/alert.h"
+#include "bluez/alert_agent.h"
+#include "bluez/cycling_speed.h"
+#include "bluez/cycling_speed_manager.h"
#include "bluez/device.h"
-#include "bluez/input.h"
-#include "bluez/manager.h"
+#include "bluez/health_channel.h"
+#include "bluez/health_device.h"
+#include "bluez/health_manager.h"
+#include "bluez/heart_rate.h"
+#include "bluez/heart_rate_manager.h"
+#include "bluez/media.h"
+#include "bluez/media_control.h"
+#include "bluez/media_player.h"
#include "bluez/network.h"
#include "bluez/network_server.h"
-#include "bluez/serial.h"
+#include "bluez/obex/obex_agent_manager.h"
+#include "bluez/obex/obex_client.h"
+#include "bluez/obex/obex_file_transfer.h"
+#include "bluez/obex/obex_message.h"
+#include "bluez/obex/obex_message_access.h"
+#include "bluez/obex/obex_object_push.h"
+#include "bluez/obex/obex_phonebook_access.h"
+#include "bluez/obex/obex_session.h"
+#include "bluez/obex/obex_synchronization.h"
+#include "bluez/obex/obex_transfer.h"
+#include "bluez/profile_manager.h"
+#include "bluez/proximity_monitor.h"
+#include "bluez/proximity_reporter.h"
+#include "bluez/sim_access.h"
+#include "bluez/thermometer.h"
+#include "bluez/thermometer_manager.h"
+
+#ifdef __cplusplus
+}
+#endif
-#endif /* __BLUEZ_API_H */
+#endif /* BLUEZ_H */
diff --git a/src/lib/bluez/adapter.c b/src/lib/bluez/adapter.c
index 00ad300..6bdeda3 100644
--- a/src/lib/bluez/adapter.c
+++ b/src/lib/bluez/adapter.c
@@ -24,358 +24,83 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
-
-#include <string.h>
-
+#include <gio/gio.h>
#include <glib.h>
-#include <dbus/dbus-glib.h>
+#include <string.h>
#include "../dbus-common.h"
-#include "../marshallers.h"
+#include "../properties.h"
#include "adapter.h"
#define ADAPTER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), ADAPTER_TYPE, AdapterPrivate))
struct _AdapterPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-
- /* Properties */
- gchar *address;
- guint32 class;
- GPtrArray *devices;
- gboolean discoverable;
- guint32 discoverable_timeout;
- gboolean discovering;
- gchar *name;
- gboolean pairable;
- guint32 pairable_timeout;
- gboolean powered;
- gchar **uuids;
-
- /* Async calls */
- DBusGProxyCall *create_paired_device_call;
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
};
-G_DEFINE_TYPE(Adapter, adapter, G_TYPE_OBJECT);
+G_DEFINE_TYPE_WITH_PRIVATE(Adapter, adapter, G_TYPE_OBJECT);
enum {
PROP_0,
-
- PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
- PROP_ADDRESS, /* readonly */
- PROP_CLASS, /* readonly */
- PROP_DEVICES, /* readonly */
- PROP_DISCOVERABLE, /* readwrite */
- PROP_DISCOVERABLE_TIMEOUT, /* readwrite */
- PROP_DISCOVERING, /* readonly */
- PROP_NAME, /* readwrite */
- PROP_PAIRABLE, /* readwrite */
- PROP_PAIRABLE_TIMEOUT, /* readwrite */
- PROP_POWERED, /* readwrite */
- PROP_UUIDS /* readonly */
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
};
static void _adapter_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void _adapter_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-enum {
- DEVICE_CREATED,
- DEVICE_DISAPPEARED,
- DEVICE_FOUND,
- DEVICE_REMOVED,
- PROPERTY_CHANGED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void device_created_handler(DBusGProxy *dbus_g_proxy, const gchar *device, gpointer data);
-static void device_disappeared_handler(DBusGProxy *dbus_g_proxy, const gchar *address, gpointer data);
-static void device_found_handler(DBusGProxy *dbus_g_proxy, const gchar *address, GHashTable *values, gpointer data);
-static void device_removed_handler(DBusGProxy *dbus_g_proxy, const gchar *device, gpointer data);
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data);
+static void _adapter_create_gdbus_proxy(Adapter *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
static void adapter_dispose(GObject *gobject)
{
Adapter *self = ADAPTER(gobject);
- /* DBus signals disconnection */
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "DeviceCreated", G_CALLBACK(device_created_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "DeviceDisappeared", G_CALLBACK(device_disappeared_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "DeviceFound", G_CALLBACK(device_found_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "DeviceRemoved", G_CALLBACK(device_removed_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self);
-
- /* Properties free */
- g_free(self->priv->address);
- g_ptr_array_unref(self->priv->devices);
- g_free(self->priv->name);
- g_strfreev(self->priv->uuids);
-
/* 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);
-
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
/* Chain up to the parent class */
G_OBJECT_CLASS(adapter_parent_class)->dispose(gobject);
}
+static void adapter_finalize (GObject *gobject)
+{
+ Adapter *self = ADAPTER(gobject);
+ G_OBJECT_CLASS(adapter_parent_class)->finalize(gobject);
+}
+
static void adapter_class_init(AdapterClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = adapter_dispose;
- g_type_class_add_private(klass, sizeof(AdapterPrivate));
-
/* Properties registration */
- GParamSpec *pspec;
+ GParamSpec *pspec = NULL;
gobject_class->get_property = _adapter_get_property;
gobject_class->set_property = _adapter_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);
-
- /* string Address [readonly] */
- pspec = g_param_spec_string("Address", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_ADDRESS, pspec);
-
- /* uint32 Class [readonly] */
- pspec = g_param_spec_uint("Class", NULL, NULL, 0, 0xFFFFFFFF, 0, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_CLASS, pspec);
-
- /* array{object} Devices [readonly] */
- pspec = g_param_spec_boxed("Devices", NULL, NULL, G_TYPE_PTR_ARRAY, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_DEVICES, pspec);
-
- /* boolean Discoverable [readwrite] */
- pspec = g_param_spec_boolean("Discoverable", NULL, NULL, FALSE, G_PARAM_READWRITE);
- g_object_class_install_property(gobject_class, PROP_DISCOVERABLE, pspec);
-
- /* uint32 DiscoverableTimeout [readwrite] */
- pspec = g_param_spec_uint("DiscoverableTimeout", NULL, NULL, 0, 0xFFFFFFFF, 0, G_PARAM_READWRITE);
- g_object_class_install_property(gobject_class, PROP_DISCOVERABLE_TIMEOUT, pspec);
-
- /* boolean Discovering [readonly] */
- pspec = g_param_spec_boolean("Discovering", NULL, NULL, FALSE, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_DISCOVERING, 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);
-
- /* boolean Pairable [readwrite] */
- pspec = g_param_spec_boolean("Pairable", NULL, NULL, FALSE, G_PARAM_READWRITE);
- g_object_class_install_property(gobject_class, PROP_PAIRABLE, pspec);
-
- /* uint32 PairableTimeout [readwrite] */
- pspec = g_param_spec_uint("PairableTimeout", NULL, NULL, 0, 0xFFFFFFFF, 0, G_PARAM_READWRITE);
- g_object_class_install_property(gobject_class, PROP_PAIRABLE_TIMEOUT, pspec);
-
- /* boolean Powered [readwrite] */
- pspec = g_param_spec_boolean("Powered", NULL, NULL, FALSE, G_PARAM_READWRITE);
- g_object_class_install_property(gobject_class, PROP_POWERED, pspec);
-
- /* array{string} UUIDs [readonly] */
- pspec = g_param_spec_boxed("UUIDs", NULL, NULL, G_TYPE_STRV, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_UUIDS, pspec);
-
- /* Signals registation */
- signals[DEVICE_CREATED] = g_signal_new("DeviceCreated",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[DEVICE_DISAPPEARED] = g_signal_new("DeviceDisappeared",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[DEVICE_FOUND] = g_signal_new("DeviceFound",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_bt_marshal_VOID__STRING_BOXED,
- G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_HASH_TABLE);
-
- signals[DEVICE_REMOVED] = g_signal_new("DeviceRemoved",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[PROPERTY_CHANGED] = g_signal_new("PropertyChanged",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_bt_marshal_VOID__STRING_BOXED,
- G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE);
+ if (pspec)
+ g_param_spec_unref(pspec);
}
static void adapter_init(Adapter *self)
{
- self->priv = ADAPTER_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- /* Async calls init */
- self->priv->create_paired_device_call = NULL;
-
+ self->priv = adapter_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
g_assert(system_conn != NULL);
}
-static void adapter_post_init(Adapter *self, const gchar *dbus_object_path)
-{
- 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(system_conn, "org.bluez", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", ADAPTER_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", ADAPTER_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, ADAPTER_DBUS_INTERFACE);
-
- /* DBus signals connection */
-
- /* DeviceCreated(object device) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "DeviceCreated", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "DeviceCreated", G_CALLBACK(device_created_handler), self, NULL);
-
- /* DeviceDisappeared(string address) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "DeviceDisappeared", G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "DeviceDisappeared", G_CALLBACK(device_disappeared_handler), self, NULL);
-
- /* DeviceFound(string address, dict values) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "DeviceFound", G_TYPE_STRING, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "DeviceFound", G_CALLBACK(device_found_handler), self, NULL);
-
- /* DeviceRemoved(object device) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "DeviceRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "DeviceRemoved", G_CALLBACK(device_removed_handler), self, NULL);
-
- /* PropertyChanged(string name, variant value) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self, NULL);
-
- /* Properties init */
- GHashTable *properties = adapter_get_properties(self, &error);
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
- g_assert(properties != NULL);
-
- /* string Address [readonly] */
- if (g_hash_table_lookup(properties, "Address")) {
- self->priv->address = g_value_dup_string(g_hash_table_lookup(properties, "Address"));
- } else {
- self->priv->address = g_strdup("undefined");
- }
-
- /* uint32 Class [readonly] */
- if (g_hash_table_lookup(properties, "Class")) {
- self->priv->class = g_value_get_uint(g_hash_table_lookup(properties, "Class"));
- } else {
- self->priv->class = 0;
- }
-
- /* array{object} Devices [readonly] */
- if (g_hash_table_lookup(properties, "Devices")) {
- self->priv->devices = g_value_dup_boxed(g_hash_table_lookup(properties, "Devices"));
- } else {
- self->priv->devices = g_ptr_array_new();
- }
-
- /* boolean Discoverable [readwrite] */
- if (g_hash_table_lookup(properties, "Discoverable")) {
- self->priv->discoverable = g_value_get_boolean(g_hash_table_lookup(properties, "Discoverable"));
- } else {
- self->priv->discoverable = FALSE;
- }
-
- /* uint32 DiscoverableTimeout [readwrite] */
- if (g_hash_table_lookup(properties, "DiscoverableTimeout")) {
- self->priv->discoverable_timeout = g_value_get_uint(g_hash_table_lookup(properties, "DiscoverableTimeout"));
- } else {
- self->priv->discoverable_timeout = 0;
- }
-
- /* boolean Discovering [readonly] */
- if (g_hash_table_lookup(properties, "Discovering")) {
- self->priv->discovering = g_value_get_boolean(g_hash_table_lookup(properties, "Discovering"));
- } else {
- self->priv->discovering = 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");
- }
-
- /* boolean Pairable [readwrite] */
- if (g_hash_table_lookup(properties, "Pairable")) {
- self->priv->pairable = g_value_get_boolean(g_hash_table_lookup(properties, "Pairable"));
- } else {
- self->priv->pairable = FALSE;
- }
-
- /* uint32 PairableTimeout [readwrite] */
- if (g_hash_table_lookup(properties, "PairableTimeout")) {
- self->priv->pairable_timeout = g_value_get_uint(g_hash_table_lookup(properties, "PairableTimeout"));
- } else {
- self->priv->pairable_timeout = 0;
- }
-
- /* boolean Powered [readwrite] */
- if (g_hash_table_lookup(properties, "Powered")) {
- self->priv->powered = g_value_get_boolean(g_hash_table_lookup(properties, "Powered"));
- } else {
- self->priv->powered = FALSE;
- }
-
- /* array{string} UUIDs [readonly] */
- if (g_hash_table_lookup(properties, "UUIDs")) {
- self->priv->uuids = (gchar **) g_value_dup_boxed(g_hash_table_lookup(properties, "UUIDs"));
- } else {
- self->priv->uuids = g_new0(char *, 1);
- self->priv->uuids[0] = NULL;
- }
-
- g_hash_table_unref(properties);
-}
-
static void _adapter_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
Adapter *self = ADAPTER(object);
@@ -385,50 +110,6 @@ static void _adapter_get_property(GObject *object, guint property_id, GValue *va
g_value_set_string(value, adapter_get_dbus_object_path(self));
break;
- case PROP_ADDRESS:
- g_value_set_string(value, adapter_get_address(self));
- break;
-
- case PROP_CLASS:
- g_value_set_uint(value, adapter_get_class(self));
- break;
-
- case PROP_DEVICES:
- g_value_set_boxed(value, adapter_get_devices(self));
- break;
-
- case PROP_DISCOVERABLE:
- g_value_set_boolean(value, adapter_get_discoverable(self));
- break;
-
- case PROP_DISCOVERABLE_TIMEOUT:
- g_value_set_uint(value, adapter_get_discoverable_timeout(self));
- break;
-
- case PROP_DISCOVERING:
- g_value_set_boolean(value, adapter_get_discovering(self));
- break;
-
- case PROP_NAME:
- g_value_set_string(value, adapter_get_name(self));
- break;
-
- case PROP_PAIRABLE:
- g_value_set_boolean(value, adapter_get_pairable(self));
- break;
-
- case PROP_PAIRABLE_TIMEOUT:
- g_value_set_uint(value, adapter_get_pairable_timeout(self));
- break;
-
- case PROP_POWERED:
- g_value_set_boolean(value, adapter_get_powered(self));
- break;
-
- case PROP_UUIDS:
- g_value_set_boxed(value, adapter_get_uuids(self));
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
@@ -442,31 +123,8 @@ static void _adapter_set_property(GObject *object, guint property_id, const GVal
switch (property_id) {
case PROP_DBUS_OBJECT_PATH:
- adapter_post_init(self, g_value_get_string(value));
- break;
-
- case PROP_DISCOVERABLE:
- adapter_set_property(self, "Discoverable", value, &error);
- break;
-
- case PROP_DISCOVERABLE_TIMEOUT:
- adapter_set_property(self, "DiscoverableTimeout", value, &error);
- break;
-
- case PROP_NAME:
- adapter_set_property(self, "Name", value, &error);
- break;
-
- case PROP_PAIRABLE:
- adapter_set_property(self, "Pairable", value, &error);
- break;
-
- case PROP_PAIRABLE_TIMEOUT:
- adapter_set_property(self, "PairableTimeout", value, &error);
- break;
-
- case PROP_POWERED:
- adapter_set_property(self, "Powered", value, &error);
+ self->priv->object_path = g_value_dup_string(value);
+ _adapter_create_gdbus_proxy(self, ADAPTER_DBUS_SERVICE, self->priv->object_path, &error);
break;
default:
@@ -474,390 +132,260 @@ static void _adapter_set_property(GObject *object, guint property_id, const GVal
break;
}
- if (error != NULL) {
+ if (error != NULL)
g_critical("%s", error->message);
- }
- g_assert(error == NULL);
-}
-
-static void adapter_async_notify_callback(DBusGProxy *proxy, DBusGProxyCall *call, gpointer data)
-{
- gpointer *p = data;
- void (*AsyncNotifyFunc)(gpointer data) = p[0];
- (*AsyncNotifyFunc)(p[1]);
- g_free(p);
-}
-
-/* Methods */
-
-/* void CancelDeviceCreation(string address) */
-void adapter_cancel_device_creation(Adapter *self, const gchar *address, GError **error)
-{
- g_assert(ADAPTER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "CancelDeviceCreation", error, G_TYPE_STRING, address, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* object CreateDevice(string address) */
-gchar *adapter_create_device(Adapter *self, const gchar *address, GError **error)
-{
- g_assert(ADAPTER_IS(self));
-
- gchar *ret = NULL;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "CreateDevice", error, G_TYPE_STRING, address, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &ret, G_TYPE_INVALID);
- return ret;
+ g_assert(error == NULL);
}
-/* object CreatePairedDevice(string address, object agent, string capability) [async] */
-void adapter_create_paired_device_begin(Adapter *self, void (*AsyncNotifyFunc)(gpointer data), gpointer data, const gchar *address, const gchar *agent, const gchar *capability)
+/* Constructor */
+Adapter *adapter_new(const gchar *dbus_object_path)
{
- g_assert(ADAPTER_IS(self));
- g_assert(self->priv->create_paired_device_call == NULL);
-
- gpointer *p = g_new0(gpointer, 2);
- p[0] = AsyncNotifyFunc;
- p[1] = data;
-
- self->priv->create_paired_device_call = dbus_g_proxy_begin_call(self->priv->dbus_g_proxy, "CreatePairedDevice", (DBusGProxyCallNotify) adapter_async_notify_callback, p, NULL, G_TYPE_STRING, address, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_STRING, capability, G_TYPE_INVALID);
+ return g_object_new(ADAPTER_TYPE, "DBusObjectPath", dbus_object_path, NULL);
}
-gchar *adapter_create_paired_device_end(Adapter *self, GError **error)
+/* Private DBus proxy creation */
+static void _adapter_create_gdbus_proxy(Adapter *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
{
g_assert(ADAPTER_IS(self));
- g_assert(self->priv->create_paired_device_call != NULL);
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, ADAPTER_DBUS_INTERFACE, NULL, error);
- gchar *ret = NULL;
- dbus_g_proxy_end_call(self->priv->dbus_g_proxy, self->priv->create_paired_device_call, error, DBUS_TYPE_G_OBJECT_PATH, &ret, G_TYPE_INVALID);
- self->priv->create_paired_device_call = NULL;
+ if(self->priv->proxy == NULL)
+ return;
- return ret;
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
}
-/* object FindDevice(string address) */
-gchar *adapter_find_device(Adapter *self, const gchar *address, GError **error)
-{
- g_assert(ADAPTER_IS(self));
-
- gchar *ret = NULL;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "FindDevice", error, G_TYPE_STRING, address, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &ret, G_TYPE_INVALID);
-
- return ret;
-}
-
-/* dict GetProperties() */
-GHashTable *adapter_get_properties(Adapter *self, GError **error)
-{
- g_assert(ADAPTER_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;
-}
+/* Methods */
-/* void RegisterAgent(object agent, string capability) */
-void adapter_register_agent(Adapter *self, const gchar *agent, const gchar *capability, GError **error)
+/* Get DBus object path */
+const gchar *adapter_get_dbus_object_path(Adapter *self)
{
g_assert(ADAPTER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "RegisterAgent", error, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_STRING, capability, G_TYPE_INVALID, G_TYPE_INVALID);
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
}
/* void RemoveDevice(object device) */
void adapter_remove_device(Adapter *self, const gchar *device, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "RemoveDevice", error, DBUS_TYPE_G_OBJECT_PATH, device, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void SetProperty(string name, variant value) */
-void adapter_set_property(Adapter *self, const gchar *name, const GValue *value, GError **error)
-{
- g_assert(ADAPTER_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);
+ g_dbus_proxy_call_sync(self->priv->proxy, "RemoveDevice", g_variant_new ("(o)", device), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
}
/* void StartDiscovery() */
void adapter_start_discovery(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "StartDiscovery", error, G_TYPE_INVALID, G_TYPE_INVALID);
+ g_dbus_proxy_call_sync(self->priv->proxy, "StartDiscovery", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
}
/* void StopDiscovery() */
void adapter_stop_discovery(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "StopDiscovery", error, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void UnregisterAgent(object agent) */
-void adapter_unregister_agent(Adapter *self, const gchar *agent, GError **error)
-{
- g_assert(ADAPTER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "UnregisterAgent", error, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID);
+ g_dbus_proxy_call_sync(self->priv->proxy, "StopDiscovery", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
}
/* Properties access methods */
-const gchar *adapter_get_dbus_object_path(Adapter *self)
+GVariant *adapter_get_properties(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, ADAPTER_DBUS_INTERFACE, error);
}
-const gchar *adapter_get_address(Adapter *self)
+void adapter_set_property(Adapter *self, const gchar *name, const GVariant *value, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->address;
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, ADAPTER_DBUS_INTERFACE, name, value, error);
}
-const guint32 adapter_get_class(Adapter *self)
+const gchar *adapter_get_address(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->class;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Address", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
-const GPtrArray *adapter_get_devices(Adapter *self)
+const gchar *adapter_get_alias(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->devices;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Alias", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
-const gboolean adapter_get_discoverable(Adapter *self)
+void adapter_set_alias(Adapter *self, const gchar *value, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->discoverable;
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Alias", g_variant_new_string(value), error);
}
-void adapter_set_discoverable(Adapter *self, const gboolean value)
+guint32 adapter_get_class(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- GError *error = NULL;
-
- GValue t = {0};
- g_value_init(&t, G_TYPE_BOOLEAN);
- g_value_set_boolean(&t, value);
- adapter_set_property(self, "Discoverable", &t, &error);
- g_value_unset(&t);
-
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Class", error);
+ if(prop == NULL)
+ return 0;
+ guint32 ret = g_variant_get_uint32(prop);
+ g_variant_unref(prop);
+ return ret;
}
-const guint32 adapter_get_discoverable_timeout(Adapter *self)
+gboolean adapter_get_discoverable(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->discoverable_timeout;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Discoverable", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
}
-void adapter_set_discoverable_timeout(Adapter *self, const guint32 value)
+void adapter_set_discoverable(Adapter *self, const gboolean value, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- GError *error = NULL;
-
- GValue t = {0};
- g_value_init(&t, G_TYPE_UINT);
- g_value_set_uint(&t, value);
- adapter_set_property(self, "DiscoverableTimeout", &t, &error);
- g_value_unset(&t);
-
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Discoverable", g_variant_new_boolean(value), error);
}
-const gboolean adapter_get_discovering(Adapter *self)
+guint32 adapter_get_discoverable_timeout(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->discovering;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "DiscoverableTimeout", error);
+ if(prop == NULL)
+ return 0;
+ guint32 ret = g_variant_get_uint32(prop);
+ g_variant_unref(prop);
+ return ret;
}
-const gchar *adapter_get_name(Adapter *self)
+void adapter_set_discoverable_timeout(Adapter *self, const guint32 value, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->name;
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, ADAPTER_DBUS_INTERFACE, "DiscoverableTimeout", g_variant_new_uint32(value), error);
}
-void adapter_set_name(Adapter *self, const gchar *value)
+gboolean adapter_get_discovering(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- GError *error = NULL;
-
- GValue t = {0};
- g_value_init(&t, G_TYPE_STRING);
- g_value_set_string(&t, value);
- adapter_set_property(self, "Name", &t, &error);
- g_value_unset(&t);
-
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Discovering", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
}
-const gboolean adapter_get_pairable(Adapter *self)
+const gchar *adapter_get_modalias(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->pairable;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Modalias", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
-void adapter_set_pairable(Adapter *self, const gboolean value)
+const gchar *adapter_get_name(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- GError *error = NULL;
-
- GValue t = {0};
- g_value_init(&t, G_TYPE_BOOLEAN);
- g_value_set_boolean(&t, value);
- adapter_set_property(self, "Pairable", &t, &error);
- g_value_unset(&t);
-
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Name", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
-const guint32 adapter_get_pairable_timeout(Adapter *self)
+gboolean adapter_get_pairable(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->pairable_timeout;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Pairable", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
}
-void adapter_set_pairable_timeout(Adapter *self, const guint32 value)
+void adapter_set_pairable(Adapter *self, const gboolean value, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- GError *error = NULL;
-
- GValue t = {0};
- g_value_init(&t, G_TYPE_UINT);
- g_value_set_uint(&t, value);
- adapter_set_property(self, "PairableTimeout", &t, &error);
- g_value_unset(&t);
-
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Pairable", g_variant_new_boolean(value), error);
}
-const gboolean adapter_get_powered(Adapter *self)
+guint32 adapter_get_pairable_timeout(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->powered;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "PairableTimeout", error);
+ if(prop == NULL)
+ return 0;
+ guint32 ret = g_variant_get_uint32(prop);
+ g_variant_unref(prop);
+ return ret;
}
-void adapter_set_powered(Adapter *self, const gboolean value)
+void adapter_set_pairable_timeout(Adapter *self, const guint32 value, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- GError *error = NULL;
-
- GValue t = {0};
- g_value_init(&t, G_TYPE_BOOLEAN);
- g_value_set_boolean(&t, value);
- adapter_set_property(self, "Powered", &t, &error);
- g_value_unset(&t);
-
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, ADAPTER_DBUS_INTERFACE, "PairableTimeout", g_variant_new_uint32(value), error);
}
-const gchar **adapter_get_uuids(Adapter *self)
+gboolean adapter_get_powered(Adapter *self, GError **error)
{
g_assert(ADAPTER_IS(self));
-
- return self->priv->uuids;
-}
-
-/* Signals handlers */
-static void device_created_handler(DBusGProxy *dbus_g_proxy, const gchar *device, gpointer data)
-{
- Adapter *self = ADAPTER(data);
-
- g_signal_emit(self, signals[DEVICE_CREATED], 0, device);
-}
-
-static void device_disappeared_handler(DBusGProxy *dbus_g_proxy, const gchar *address, gpointer data)
-{
- Adapter *self = ADAPTER(data);
-
- g_signal_emit(self, signals[DEVICE_DISAPPEARED], 0, address);
-}
-
-static void device_found_handler(DBusGProxy *dbus_g_proxy, const gchar *address, GHashTable *values, gpointer data)
-{
- Adapter *self = ADAPTER(data);
-
- g_signal_emit(self, signals[DEVICE_FOUND], 0, address, values);
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Powered", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
}
-static void device_removed_handler(DBusGProxy *dbus_g_proxy, const gchar *device, gpointer data)
+void adapter_set_powered(Adapter *self, const gboolean value, GError **error)
{
- Adapter *self = ADAPTER(data);
-
- g_signal_emit(self, signals[DEVICE_REMOVED], 0, device);
+ g_assert(ADAPTER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, ADAPTER_DBUS_INTERFACE, "Powered", g_variant_new_boolean(value), error);
}
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data)
+const gchar **adapter_get_uuids(Adapter *self, GError **error)
{
- Adapter *self = ADAPTER(data);
-
- if (g_strcmp0(name, "Address") == 0) {
- g_free(self->priv->address);
- self->priv->address = g_value_dup_string(value);
- } else if (g_strcmp0(name, "Class") == 0) {
- self->priv->class = g_value_get_uint(value);
- } else if (g_strcmp0(name, "Devices") == 0) {
- g_ptr_array_unref(self->priv->devices);
- self->priv->devices = g_value_dup_boxed(value);
- } else if (g_strcmp0(name, "Discoverable") == 0) {
- self->priv->discoverable = g_value_get_boolean(value);
- } else if (g_strcmp0(name, "DiscoverableTimeout") == 0) {
- self->priv->discoverable_timeout = g_value_get_uint(value);
- } else if (g_strcmp0(name, "Discovering") == 0) {
- self->priv->discovering = g_value_get_boolean(value);
- } else if (g_strcmp0(name, "Name") == 0) {
- g_free(self->priv->name);
- self->priv->name = g_value_dup_string(value);
- } else if (g_strcmp0(name, "Pairable") == 0) {
- self->priv->pairable = g_value_get_boolean(value);
- } else if (g_strcmp0(name, "PairableTimeout") == 0) {
- self->priv->pairable_timeout = g_value_get_uint(value);
- } else if (g_strcmp0(name, "Powered") == 0) {
- self->priv->powered = g_value_get_boolean(value);
- } else if (g_strcmp0(name, "UUIDs") == 0) {
- g_strfreev(self->priv->uuids);
- self->priv->uuids = (gchar **) g_value_dup_boxed(value);
- }
-
- g_signal_emit(self, signals[PROPERTY_CHANGED], 0, name, value);
+ g_assert(ADAPTER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, ADAPTER_DBUS_INTERFACE, "UUIDs", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar **ret = g_variant_get_strv(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
diff --git a/src/lib/bluez/adapter.h b/src/lib/bluez/adapter.h
index 22ee02f..97de77d 100644
--- a/src/lib/bluez/adapter.h
+++ b/src/lib/bluez/adapter.h
@@ -24,9 +24,14 @@
#ifndef __ADAPTER_H
#define __ADAPTER_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <glib-object.h>
-#define ADAPTER_DBUS_INTERFACE "org.bluez.Adapter"
+#define ADAPTER_DBUS_SERVICE "org.bluez"
+#define ADAPTER_DBUS_INTERFACE "org.bluez.Adapter1"
/*
* Type macros
@@ -57,39 +62,44 @@ struct _AdapterClass {
GType adapter_get_type(void) G_GNUC_CONST;
/*
+ * Constructor
+ */
+Adapter *adapter_new(const gchar *dbus_object_path);
+
+/*
* Method definitions
*/
-void adapter_cancel_device_creation(Adapter *self, const gchar *address, GError **error);
-gchar *adapter_create_device(Adapter *self, const gchar *address, GError **error);
-void adapter_create_paired_device_begin(Adapter *self, void (*AsyncNotifyFunc)(gpointer data), gpointer data, const gchar *address, const gchar *agent, const gchar *capability);
-gchar *adapter_create_paired_device_end(Adapter *self, GError **error);
-gchar *adapter_find_device(Adapter *self, const gchar *address, GError **error);
-GHashTable *adapter_get_properties(Adapter *self, GError **error);
-void adapter_register_agent(Adapter *self, const gchar *agent, const gchar *capability, GError **error);
+const gchar *adapter_get_dbus_object_path(Adapter *self);
+
void adapter_remove_device(Adapter *self, const gchar *device, GError **error);
-void adapter_set_property(Adapter *self, const gchar *name, const GValue *value, GError **error);
void adapter_start_discovery(Adapter *self, GError **error);
void adapter_stop_discovery(Adapter *self, GError **error);
-void adapter_unregister_agent(Adapter *self, const gchar *agent, GError **error);
-const gchar *adapter_get_dbus_object_path(Adapter *self);
-const gchar *adapter_get_address(Adapter *self);
-const guint32 adapter_get_class(Adapter *self);
-const GPtrArray *adapter_get_devices(Adapter *self);
-const gboolean adapter_get_discoverable(Adapter *self);
-void adapter_set_discoverable(Adapter *self, const gboolean value);
-const guint32 adapter_get_discoverable_timeout(Adapter *self);
-void adapter_set_discoverable_timeout(Adapter *self, const guint32 value);
-const gboolean adapter_get_discovering(Adapter *self);
-const gchar *adapter_get_name(Adapter *self);
-void adapter_set_name(Adapter *self, const gchar *value);
-const gboolean adapter_get_pairable(Adapter *self);
-void adapter_set_pairable(Adapter *self, const gboolean value);
-const guint32 adapter_get_pairable_timeout(Adapter *self);
-void adapter_set_pairable_timeout(Adapter *self, const guint32 value);
-const gboolean adapter_get_powered(Adapter *self);
-void adapter_set_powered(Adapter *self, const gboolean value);
-const gchar **adapter_get_uuids(Adapter *self);
+GVariant *adapter_get_properties(Adapter *self, GError **error);
+void adapter_set_property(Adapter *self, const gchar *name, const GVariant *value, GError **error);
+
+const gchar *adapter_get_address(Adapter *self, GError **error);
+const gchar *adapter_get_alias(Adapter *self, GError **error);
+void adapter_set_alias(Adapter *self, const gchar *value, GError **error);
+guint32 adapter_get_class(Adapter *self, GError **error);
+gboolean adapter_get_discoverable(Adapter *self, GError **error);
+void adapter_set_discoverable(Adapter *self, const gboolean value, GError **error);
+guint32 adapter_get_discoverable_timeout(Adapter *self, GError **error);
+void adapter_set_discoverable_timeout(Adapter *self, const guint32 value, GError **error);
+gboolean adapter_get_discovering(Adapter *self, GError **error);
+const gchar *adapter_get_modalias(Adapter *self, GError **error);
+const gchar *adapter_get_name(Adapter *self, GError **error);
+gboolean adapter_get_pairable(Adapter *self, GError **error);
+void adapter_set_pairable(Adapter *self, const gboolean value, GError **error);
+guint32 adapter_get_pairable_timeout(Adapter *self, GError **error);
+void adapter_set_pairable_timeout(Adapter *self, const guint32 value, GError **error);
+gboolean adapter_get_powered(Adapter *self, GError **error);
+void adapter_set_powered(Adapter *self, const gboolean value, GError **error);
+const gchar **adapter_get_uuids(Adapter *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
#endif /* __ADAPTER_H */
diff --git a/src/lib/bluez/agent.c b/src/lib/bluez/agent.c
deleted file mode 100644
index dc29706..0000000
--- a/src/lib/bluez/agent.c
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- *
- * bluez-tools - a set of tools to manage bluetooth devices for linux
- *
- * Copyright (C) 2010-2011 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 <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../helpers.h"
-
-#include "device.h"
-#include "agent.h"
-
-#define AGENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), AGENT_TYPE, AgentPrivate))
-
-struct _AgentPrivate {
- /* Properties */
- GHashTable *pin_hash_table; /* (extern) name|mac -> pin hash table */
- gboolean interactive; /* Interactive mode */
-};
-
-G_DEFINE_TYPE(Agent, agent, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_PIN_HASH_TABLE, /* write, construct only */
- PROP_INTERACTIVE /* write, construct only */
-};
-
-static void _agent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _agent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-enum {
- AGENT_RELEASED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void agent_dispose(GObject *gobject)
-{
- Agent *self = AGENT(gobject);
-
- dbus_g_connection_unregister_g_object(system_conn, gobject);
-
- /* Chain up to the parent class */
- G_OBJECT_CLASS(agent_parent_class)->dispose(gobject);
-}
-
-static void agent_class_init(AgentClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = agent_dispose;
-
- g_type_class_add_private(klass, sizeof(AgentPrivate));
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _agent_get_property;
- gobject_class->set_property = _agent_set_property;
-
- /* object PinHashTable [write, construct only] */
- pspec = g_param_spec_boxed("PinHashTable", "pin_hash_table", "Name|MAC -> PIN hash table", G_TYPE_HASH_TABLE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
- g_object_class_install_property(gobject_class, PROP_PIN_HASH_TABLE, pspec);
-
- /* boolean Interactive [write, construct only] */
- pspec = g_param_spec_boolean("Interactive", "interactive", "Interactive mode", TRUE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
- g_object_class_install_property(gobject_class, PROP_INTERACTIVE, pspec);
-
- /* Signals registation */
- signals[AGENT_RELEASED] = g_signal_new("AgentReleased",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-}
-
-static void agent_init(Agent *self)
-{
- self->priv = AGENT_GET_PRIVATE(self);
-
- g_assert(system_conn != NULL);
-
- /* Properties init */
- self->priv->pin_hash_table = NULL;
- self->priv->interactive = TRUE;
-
- dbus_g_connection_register_g_object(system_conn, AGENT_DBUS_PATH, G_OBJECT(self));
-}
-
-static void _agent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- Agent *self = AGENT(object);
-
- switch (property_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _agent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- Agent *self = AGENT(object);
-
- switch (property_id) {
- case PROP_PIN_HASH_TABLE:
- self->priv->pin_hash_table = g_value_get_boxed(value);
- break;
-
- case PROP_INTERACTIVE:
- self->priv->interactive = g_value_get_boolean(value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-/* Methods */
-
-static const gchar *find_device_pin(Agent *self, Device *device_obj)
-{
- if (self->priv->pin_hash_table) {
- const gchar *pin_by_addr = g_hash_table_lookup(self->priv->pin_hash_table, device_get_address(device_obj));
- const gchar *pin_by_alias = g_hash_table_lookup(self->priv->pin_hash_table, device_get_alias(device_obj));
- const gchar *pin_all = g_hash_table_lookup(self->priv->pin_hash_table, "*");
-
- if (pin_by_addr)
- return pin_by_addr;
- else if (pin_by_alias)
- return pin_by_alias;
- else if (pin_all)
- return pin_all;
- }
-
- return NULL;
-}
-
-gboolean agent_release(Agent *self, GError **error)
-{
- g_signal_emit(self, signals[AGENT_RELEASED], 0);
-
- return TRUE;
-}
-
-gboolean agent_request_pin_code(Agent *self, const gchar *device, gchar **ret, GError **error)
-{
- Device *device_obj = g_object_new(DEVICE_TYPE, "DBusObjectPath", device, NULL);
- const gchar *pin = find_device_pin(self, device_obj);
-
- if (self->priv->interactive)
- g_print("Device: %s (%s)\n", device_get_alias(device_obj), device_get_address(device_obj));
-
- g_object_unref(device_obj);
-
- /* Try to use found PIN */
- if (pin != NULL) {
- if (self->priv->interactive)
- g_print("PIN found\n");
-
- *ret = g_new0(gchar, 17);
- sscanf(pin, "%16s", *ret);
-
- return TRUE;
- } else if (self->priv->interactive) {
- g_print("Enter PIN code: ");
- *ret = g_new0(gchar, 17);
- errno = 0;
- if (scanf("%16s", *ret) == EOF && errno) {
- g_warning("%s\n", strerror(errno));
- }
-
- return TRUE;
- }
-
- return FALSE; // Request rejected
-}
-
-gboolean agent_request_passkey(Agent *self, const gchar *device, guint *ret, GError **error)
-{
- Device *device_obj = g_object_new(DEVICE_TYPE, "DBusObjectPath", device, NULL);
- const gchar *pin = find_device_pin(self, device_obj);
-
- if (self->priv->interactive)
- g_print("Device: %s (%s)\n", device_get_alias(device_obj), device_get_address(device_obj));
-
- g_object_unref(device_obj);
-
- /* Try to use found PIN */
- if (pin != NULL) {
- if (self->priv->interactive)
- g_print("Passkey found\n");
-
- sscanf(pin, "%u", ret);
-
- return TRUE;
- } else if (self->priv->interactive) {
- g_print("Enter passkey: ");
- errno = 0;
- if (scanf("%u", ret) == EOF && errno) {
- g_warning("%s\n", strerror(errno));
- }
-
- return TRUE;
- }
-
- return FALSE; // Request rejected
-}
-
-gboolean agent_display_passkey(Agent *self, const gchar *device, guint passkey, guint8 entered, GError **error)
-{
- Device *device_obj = g_object_new(DEVICE_TYPE, "DBusObjectPath", device, NULL);
- const gchar *pin = find_device_pin(self, device_obj);
-
- if (self->priv->interactive)
- g_print("Device: %s (%s)\n", device_get_alias(device_obj), device_get_address(device_obj));
-
- g_object_unref(device_obj);
-
- if (self->priv->interactive) {
- g_print("Passkey: %u, entered: %u\n", passkey, entered);
-
- return TRUE;
- } else if (pin != NULL) {
- /* OK, device found */
- return TRUE;
- }
-
- return FALSE; // Request rejected
-}
-
-gboolean agent_request_confirmation(Agent *self, const gchar *device, guint passkey, GError **error)
-{
- Device *device_obj = g_object_new(DEVICE_TYPE, "DBusObjectPath", device, NULL);
- const gchar *pin = find_device_pin(self, device_obj);
-
- if (self->priv->interactive)
- g_print("Device: %s (%s)\n", device_get_alias(device_obj), device_get_address(device_obj));
-
- g_object_unref(device_obj);
-
- /* Try to use found PIN */
- if (pin != NULL) {
- guint passkey_t;
- sscanf(pin, "%u", &passkey_t);
-
- if (g_strcmp0(pin, "*") == 0 || passkey_t == passkey) {
- if (self->priv->interactive)
- g_print("Passkey confirmed\n");
-
- return TRUE;
- } else {
- if (self->priv->interactive)
- g_print("Passkey rejected\n");
-
- // TODO: Fix error code
- if (error)
- *error = g_error_new(g_quark_from_static_string("org.bluez.Error.Rejected"), 0, "Passkey doesn't match");
- return FALSE;
- }
- } else if (self->priv->interactive) {
- g_print("Confirm passkey: %u (yes/no)? ", passkey);
- gchar yn[4] = {0,};
- errno = 0;
- if (scanf("%3s", yn) == EOF && errno) {
- g_warning("%s\n", strerror(errno));
- }
- if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) {
- return TRUE;
- } else {
- // TODO: Fix error code
- if (error)
- *error = g_error_new(g_quark_from_static_string("org.bluez.Error.Rejected"), 0, "Passkey doesn't match");
- return FALSE;
- }
- }
-
- return FALSE; // Request rejected
-}
-
-gboolean agent_authorize(Agent *self, const gchar *device, const gchar *uuid, GError **error)
-{
- Device *device_obj = g_object_new(DEVICE_TYPE, "DBusObjectPath", device, NULL);
- const gchar *pin = find_device_pin(self, device_obj);
-
- if (self->priv->interactive)
- g_print("Device: %s (%s)\n", device_get_alias(device_obj), device_get_address(device_obj));
-
- g_object_unref(device_obj);
-
- if (pin != NULL) {
- if (self->priv->interactive)
- g_print("Connection to %s authorized\n", uuid2name(uuid));
-
- return TRUE;
- } else if (self->priv->interactive) {
- g_print("Authorize a connection to: %s (yes/no)? ", uuid2name(uuid));
- gchar yn[4] = {0,};
- errno = 0;
- if (scanf("%3s", yn) == EOF && errno) {
- g_warning("%s\n", strerror(errno));
- }
- if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) {
- return TRUE;
- } else {
- // TODO: Fix error code
- if (error)
- *error = g_error_new(g_quark_from_static_string("org.bluez.Error.Rejected"), 0, "Connection rejected by user");
- return FALSE;
- }
- }
-
- return FALSE; // Request rejected
-}
-
-gboolean agent_confirm_mode_change(Agent *self, const gchar *mode, GError **error)
-{
- if (self->priv->interactive) {
- g_print("Confirm mode change: %s (yes/no)? ", mode);
- gchar yn[4] = {0,};
- errno = 0;
- if (scanf("%3s", yn) == EOF && errno) {
- g_warning("%s\n", strerror(errno));
- }
- if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) {
- return TRUE;
- } else {
- // TODO: Fix error code
- if (error)
- *error = g_error_new(g_quark_from_static_string("org.bluez.Error.Rejected"), 0, "Confirmation rejected by user");
- return FALSE;
- }
- }
-
- return TRUE; // Request accepted
-}
-
-gboolean agent_cancel(Agent *self, GError **error)
-{
- if (self->priv->interactive)
- g_print("Request cancelled\n");
-
- return TRUE;
-}
-
diff --git a/src/lib/bluez/agent.h b/src/lib/bluez/agent.h
deleted file mode 100644
index 10f4944..0000000
--- a/src/lib/bluez/agent.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- *
- * 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 __AGENT_H
-#define __AGENT_H
-
-#include <glib-object.h>
-#include <dbus/dbus-glib.h>
-
-#include "../marshallers.h"
-
-#define AGENT_DBUS_PATH "/Agent"
-
-/*
- * Type macros
- */
-#define AGENT_TYPE (agent_get_type())
-#define AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), AGENT_TYPE, Agent))
-#define AGENT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), AGENT_TYPE))
-#define AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), AGENT_TYPE, AgentClass))
-#define AGENT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), AGENT_TYPE))
-#define AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), AGENT_TYPE, AgentClass))
-
-typedef struct _Agent Agent;
-typedef struct _AgentClass AgentClass;
-typedef struct _AgentPrivate AgentPrivate;
-
-struct _Agent {
- GObject parent_instance;
-
- /*< private >*/
- AgentPrivate *priv;
-};
-
-struct _AgentClass {
- GObjectClass parent_class;
-};
-
-/* used by AGENT_TYPE */
-GType agent_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-gboolean agent_release(Agent *self, GError **error);
-gboolean agent_request_pin_code(Agent *self, const gchar *device, gchar **ret, GError **error);
-gboolean agent_request_passkey(Agent *self, const gchar *device, guint *ret, GError **error);
-gboolean agent_display_passkey(Agent *self, const gchar *device, guint passkey, guint8 entered, GError **error);
-gboolean agent_request_confirmation(Agent *self, const gchar *device, guint passkey, GError **error);
-gboolean agent_authorize(Agent *self, const gchar *device, const gchar *uuid, GError **error);
-gboolean agent_confirm_mode_change(Agent *self, const gchar *mode, GError **error);
-gboolean agent_cancel(Agent *self, GError **error);
-
-/* Glue code */
-static const DBusGMethodInfo dbus_glib_agent_methods[] = {
- { (GCallback) agent_release, g_cclosure_bt_marshal_BOOLEAN__POINTER, 0},
- { (GCallback) agent_request_pin_code, g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER_POINTER, 27},
- { (GCallback) agent_request_passkey, g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER_POINTER, 85},
- { (GCallback) agent_display_passkey, g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT_UCHAR_POINTER, 143},
- { (GCallback) agent_request_confirmation, g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT_POINTER, 212},
- { (GCallback) agent_authorize, g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_POINTER, 274},
- { (GCallback) agent_confirm_mode_change, g_cclosure_bt_marshal_BOOLEAN__STRING_POINTER, 323},
- { (GCallback) agent_cancel, g_cclosure_bt_marshal_BOOLEAN__POINTER, 369},
-};
-
-static const DBusGObjectInfo dbus_glib_agent_object_info = {
- 0,
- dbus_glib_agent_methods,
- 8,
- "org.bluez.Agent\0Release\0S\0\0org.bluez.Agent\0RequestPinCode\0S\0device\0I\0o\0arg1\0O\0F\0N\0s\0\0org.bluez.Agent\0RequestPasskey\0S\0device\0I\0o\0arg1\0O\0F\0N\0u\0\0org.bluez.Agent\0DisplayPasskey\0S\0device\0I\0o\0passkey\0I\0u\0entered\0I\0y\0\0org.bluez.Agent\0RequestConfirmation\0S\0device\0I\0o\0passkey\0I\0u\0\0org.bluez.Agent\0Authorize\0S\0device\0I\0o\0uuid\0I\0s\0\0org.bluez.Agent\0ConfirmModeChange\0S\0mode\0I\0s\0\0org.bluez.Agent\0Cancel\0S\0\0\0",
- "\0",
- "\0"
-};
-
-#endif /* __AGENT_H */
-
diff --git a/src/lib/bluez/agent_manager.c b/src/lib/bluez/agent_manager.c
new file mode 100644
index 0000000..9d501ff
--- /dev/null
+++ b/src/lib/bluez/agent_manager.c
@@ -0,0 +1,161 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "agent_manager.h"
+
+#define AGENT_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), AGENT_MANAGER_TYPE, AgentManagerPrivate))
+
+struct _AgentManagerPrivate {
+ GDBusProxy *proxy;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(AgentManager, agent_manager, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+};
+
+static void _agent_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _agent_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _agent_manager_create_gdbus_proxy(AgentManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void agent_manager_dispose(GObject *gobject)
+{
+ AgentManager *self = AGENT_MANAGER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(agent_manager_parent_class)->dispose(gobject);
+}
+
+static void agent_manager_finalize (GObject *gobject)
+{
+ AgentManager *self = AGENT_MANAGER(gobject);
+ G_OBJECT_CLASS(agent_manager_parent_class)->finalize(gobject);
+}
+
+static void agent_manager_class_init(AgentManagerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = agent_manager_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _agent_manager_get_property;
+ gobject_class->set_property = _agent_manager_set_property;
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void agent_manager_init(AgentManager *self)
+{
+ self->priv = agent_manager_get_instance_private (self);
+ self->priv->proxy = NULL;
+ g_assert(system_conn != NULL);
+ GError *error = NULL;
+ _agent_manager_create_gdbus_proxy(self, AGENT_MANAGER_DBUS_SERVICE, AGENT_MANAGER_DBUS_PATH, &error);
+ g_assert(error == NULL);
+}
+
+static void _agent_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ AgentManager *self = AGENT_MANAGER(object);
+
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _agent_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ AgentManager *self = AGENT_MANAGER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+
+ if (error != NULL)
+ g_critical("%s", error->message);
+
+ g_assert(error == NULL);
+}
+
+/* Constructor */
+AgentManager *agent_manager_new()
+{
+ return g_object_new(AGENT_MANAGER_TYPE, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _agent_manager_create_gdbus_proxy(AgentManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(AGENT_MANAGER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, AGENT_MANAGER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* void RegisterAgent(object agent, string capability) */
+void agent_manager_register_agent(AgentManager *self, const gchar *agent, const gchar *capability, GError **error)
+{
+ g_assert(AGENT_MANAGER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "RegisterAgent", g_variant_new ("(os)", agent, capability), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void RequestDefaultAgent(object agent) */
+void agent_manager_request_default_agent(AgentManager *self, const gchar *agent, GError **error)
+{
+ g_assert(AGENT_MANAGER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "RequestDefaultAgent", g_variant_new ("(o)", agent), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void UnregisterAgent(object agent) */
+void agent_manager_unregister_agent(AgentManager *self, const gchar *agent, GError **error)
+{
+ g_assert(AGENT_MANAGER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "UnregisterAgent", g_variant_new ("(o)", agent), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/agent_manager.h b/src/lib/bluez/agent_manager.h
new file mode 100644
index 0000000..42f4f5e
--- /dev/null
+++ b/src/lib/bluez/agent_manager.h
@@ -0,0 +1,82 @@
+/*
+ *
+ * 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 __AGENT_MANAGER_H
+#define __AGENT_MANAGER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define AGENT_MANAGER_DBUS_SERVICE "org.bluez"
+#define AGENT_MANAGER_DBUS_INTERFACE "org.bluez.AgentManager1"
+#define AGENT_MANAGER_DBUS_PATH "/org/bluez"
+
+/*
+ * Type macros
+ */
+#define AGENT_MANAGER_TYPE (agent_manager_get_type())
+#define AGENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), AGENT_MANAGER_TYPE, AgentManager))
+#define AGENT_MANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), AGENT_MANAGER_TYPE))
+#define AGENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), AGENT_MANAGER_TYPE, AgentManagerClass))
+#define AGENT_MANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), AGENT_MANAGER_TYPE))
+#define AGENT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), AGENT_MANAGER_TYPE, AgentManagerClass))
+
+typedef struct _AgentManager AgentManager;
+typedef struct _AgentManagerClass AgentManagerClass;
+typedef struct _AgentManagerPrivate AgentManagerPrivate;
+
+struct _AgentManager {
+ GObject parent_instance;
+
+ /*< private >*/
+ AgentManagerPrivate *priv;
+};
+
+struct _AgentManagerClass {
+ GObjectClass parent_class;
+};
+
+/* used by AGENT_MANAGER_TYPE */
+GType agent_manager_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+AgentManager *agent_manager_new();
+
+/*
+ * Method definitions
+ */
+void agent_manager_register_agent(AgentManager *self, const gchar *agent, const gchar *capability, GError **error);
+void agent_manager_request_default_agent(AgentManager *self, const gchar *agent, GError **error);
+void agent_manager_unregister_agent(AgentManager *self, const gchar *agent, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AGENT_MANAGER_H */
+
diff --git a/src/lib/bluez/alert.c b/src/lib/bluez/alert.c
new file mode 100644
index 0000000..43f4e5e
--- /dev/null
+++ b/src/lib/bluez/alert.c
@@ -0,0 +1,161 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "alert.h"
+
+#define ALERT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), ALERT_TYPE, AlertPrivate))
+
+struct _AlertPrivate {
+ GDBusProxy *proxy;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(Alert, alert, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+};
+
+static void _alert_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _alert_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _alert_create_gdbus_proxy(Alert *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void alert_dispose(GObject *gobject)
+{
+ Alert *self = ALERT(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(alert_parent_class)->dispose(gobject);
+}
+
+static void alert_finalize (GObject *gobject)
+{
+ Alert *self = ALERT(gobject);
+ G_OBJECT_CLASS(alert_parent_class)->finalize(gobject);
+}
+
+static void alert_class_init(AlertClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = alert_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _alert_get_property;
+ gobject_class->set_property = _alert_set_property;
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void alert_init(Alert *self)
+{
+ self->priv = alert_get_instance_private (self);
+ self->priv->proxy = NULL;
+ g_assert(system_conn != NULL);
+ GError *error = NULL;
+ _alert_create_gdbus_proxy(self, ALERT_DBUS_SERVICE, ALERT_DBUS_PATH, &error);
+ g_assert(error == NULL);
+}
+
+static void _alert_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ Alert *self = ALERT(object);
+
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _alert_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ Alert *self = ALERT(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+
+ if (error != NULL)
+ g_critical("%s", error->message);
+
+ g_assert(error == NULL);
+}
+
+/* Constructor */
+Alert *alert_new()
+{
+ return g_object_new(ALERT_TYPE, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _alert_create_gdbus_proxy(Alert *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(ALERT_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, ALERT_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* void NewAlert(string category, uint16 count, string description) */
+void alert_new_alert(Alert *self, const gchar *category, const guint16 count, const gchar *description, GError **error)
+{
+ g_assert(ALERT_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "NewAlert", g_variant_new ("(sqs)", category, count, description), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void RegisterAlert(string category, object agent) */
+void alert_register_alert(Alert *self, const gchar *category, const gchar *agent, GError **error)
+{
+ g_assert(ALERT_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "RegisterAlert", g_variant_new ("(so)", category, agent), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void UnreadAlert(string category, uint16 count) */
+void alert_unread_alert(Alert *self, const gchar *category, const guint16 count, GError **error)
+{
+ g_assert(ALERT_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "UnreadAlert", g_variant_new ("(sq)", category, count), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/alert.h b/src/lib/bluez/alert.h
new file mode 100644
index 0000000..28508dd
--- /dev/null
+++ b/src/lib/bluez/alert.h
@@ -0,0 +1,82 @@
+/*
+ *
+ * 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 __ALERT_H
+#define __ALERT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define ALERT_DBUS_SERVICE "org.bluez"
+#define ALERT_DBUS_INTERFACE "org.bluez.Alert1"
+#define ALERT_DBUS_PATH "/org/bluez"
+
+/*
+ * Type macros
+ */
+#define ALERT_TYPE (alert_get_type())
+#define ALERT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), ALERT_TYPE, Alert))
+#define ALERT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), ALERT_TYPE))
+#define ALERT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), ALERT_TYPE, AlertClass))
+#define ALERT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), ALERT_TYPE))
+#define ALERT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), ALERT_TYPE, AlertClass))
+
+typedef struct _Alert Alert;
+typedef struct _AlertClass AlertClass;
+typedef struct _AlertPrivate AlertPrivate;
+
+struct _Alert {
+ GObject parent_instance;
+
+ /*< private >*/
+ AlertPrivate *priv;
+};
+
+struct _AlertClass {
+ GObjectClass parent_class;
+};
+
+/* used by ALERT_TYPE */
+GType alert_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+Alert *alert_new();
+
+/*
+ * Method definitions
+ */
+void alert_new_alert(Alert *self, const gchar *category, const guint16 count, const gchar *description, GError **error);
+void alert_register_alert(Alert *self, const gchar *category, const gchar *agent, GError **error);
+void alert_unread_alert(Alert *self, const gchar *category, const guint16 count, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ALERT_H */
+
diff --git a/src/lib/bluez/alert_agent.c b/src/lib/bluez/alert_agent.c
new file mode 100644
index 0000000..ceb3cab
--- /dev/null
+++ b/src/lib/bluez/alert_agent.c
@@ -0,0 +1,183 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "alert_agent.h"
+
+#define ALERT_AGENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), ALERT_AGENT_TYPE, AlertAgentPrivate))
+
+struct _AlertAgentPrivate {
+ GDBusProxy *proxy;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(AlertAgent, alert_agent, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _alert_agent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _alert_agent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _alert_agent_create_gdbus_proxy(AlertAgent *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void alert_agent_dispose(GObject *gobject)
+{
+ AlertAgent *self = ALERT_AGENT(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(alert_agent_parent_class)->dispose(gobject);
+}
+
+static void alert_agent_finalize (GObject *gobject)
+{
+ AlertAgent *self = ALERT_AGENT(gobject);
+ G_OBJECT_CLASS(alert_agent_parent_class)->finalize(gobject);
+}
+
+static void alert_agent_class_init(AlertAgentClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = alert_agent_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _alert_agent_get_property;
+ gobject_class->set_property = _alert_agent_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "AlertAgent D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void alert_agent_init(AlertAgent *self)
+{
+ self->priv = alert_agent_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _alert_agent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ AlertAgent *self = ALERT_AGENT(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, alert_agent_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _alert_agent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ AlertAgent *self = ALERT_AGENT(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _alert_agent_create_gdbus_proxy(self, ALERT_AGENT_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+AlertAgent *alert_agent_new(const gchar *dbus_object_path)
+{
+ return g_object_new(ALERT_AGENT_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _alert_agent_create_gdbus_proxy(AlertAgent *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(ALERT_AGENT_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, ALERT_AGENT_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *alert_agent_get_dbus_object_path(AlertAgent *self)
+{
+ g_assert(ALERT_AGENT_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* void MuteOnce() */
+void alert_agent_mute_once(AlertAgent *self, GError **error)
+{
+ g_assert(ALERT_AGENT_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "MuteOnce", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Release() */
+void alert_agent_release(AlertAgent *self, GError **error)
+{
+ g_assert(ALERT_AGENT_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Release", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void SetRinger(string mode) */
+void alert_agent_set_ringer(AlertAgent *self, const gchar *mode, GError **error)
+{
+ g_assert(ALERT_AGENT_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "SetRinger", g_variant_new ("(s)", mode), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/alert_agent.h b/src/lib/bluez/alert_agent.h
new file mode 100644
index 0000000..ebba39d
--- /dev/null
+++ b/src/lib/bluez/alert_agent.h
@@ -0,0 +1,83 @@
+/*
+ *
+ * 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 __ALERT_AGENT_H
+#define __ALERT_AGENT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define ALERT_AGENT_DBUS_SERVICE "org.bluez"
+#define ALERT_AGENT_DBUS_INTERFACE "org.bluez.AlertAgent1"
+
+/*
+ * Type macros
+ */
+#define ALERT_AGENT_TYPE (alert_agent_get_type())
+#define ALERT_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), ALERT_AGENT_TYPE, AlertAgent))
+#define ALERT_AGENT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), ALERT_AGENT_TYPE))
+#define ALERT_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), ALERT_AGENT_TYPE, AlertAgentClass))
+#define ALERT_AGENT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), ALERT_AGENT_TYPE))
+#define ALERT_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), ALERT_AGENT_TYPE, AlertAgentClass))
+
+typedef struct _AlertAgent AlertAgent;
+typedef struct _AlertAgentClass AlertAgentClass;
+typedef struct _AlertAgentPrivate AlertAgentPrivate;
+
+struct _AlertAgent {
+ GObject parent_instance;
+
+ /*< private >*/
+ AlertAgentPrivate *priv;
+};
+
+struct _AlertAgentClass {
+ GObjectClass parent_class;
+};
+
+/* used by ALERT_AGENT_TYPE */
+GType alert_agent_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+AlertAgent *alert_agent_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *alert_agent_get_dbus_object_path(AlertAgent *self);
+
+void alert_agent_mute_once(AlertAgent *self, GError **error);
+void alert_agent_release(AlertAgent *self, GError **error);
+void alert_agent_set_ringer(AlertAgent *self, const gchar *mode, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ALERT_AGENT_H */
+
diff --git a/src/lib/bluez/audio.c b/src/lib/bluez/audio.c
deleted file mode 100644
index 8343bf5..0000000
--- a/src/lib/bluez/audio.c
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "audio.h"
-
-#define AUDIO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), AUDIO_TYPE, AudioPrivate))
-
-struct _AudioPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-
- /* Properties */
- gchar *state;
-};
-
-G_DEFINE_TYPE(Audio, audio, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
- PROP_STATE /* readonly */
-};
-
-static void _audio_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _audio_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-enum {
- PROPERTY_CHANGED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data);
-
-static void audio_dispose(GObject *gobject)
-{
- Audio *self = AUDIO(gobject);
-
- /* DBus signals disconnection */
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self);
-
- /* Properties free */
- g_free(self->priv->state);
-
- /* 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(audio_parent_class)->dispose(gobject);
-}
-
-static void audio_class_init(AudioClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = audio_dispose;
-
- g_type_class_add_private(klass, sizeof(AudioPrivate));
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _audio_get_property;
- gobject_class->set_property = _audio_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);
-
- /* string State [readonly] */
- pspec = g_param_spec_string("State", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_STATE, pspec);
-
- /* Signals registation */
- signals[PROPERTY_CHANGED] = g_signal_new("PropertyChanged",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_bt_marshal_VOID__STRING_BOXED,
- G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE);
-}
-
-static void audio_init(Audio *self)
-{
- self->priv = AUDIO_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(system_conn != NULL);
-}
-
-static void audio_post_init(Audio *self, const gchar *dbus_object_path)
-{
- 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(system_conn, "org.bluez", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", AUDIO_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", AUDIO_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, AUDIO_DBUS_INTERFACE);
-
- /* DBus signals connection */
-
- /* PropertyChanged(string name, variant value) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self, NULL);
-
- /* Properties init */
- GHashTable *properties = audio_get_properties(self, &error);
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
- g_assert(properties != NULL);
-
- /* string State [readonly] */
- if (g_hash_table_lookup(properties, "State")) {
- self->priv->state = g_value_dup_string(g_hash_table_lookup(properties, "State"));
- } else {
- self->priv->state = g_strdup("undefined");
- }
-
- g_hash_table_unref(properties);
-}
-
-static void _audio_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- Audio *self = AUDIO(object);
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- g_value_set_string(value, audio_get_dbus_object_path(self));
- break;
-
- case PROP_STATE:
- g_value_set_string(value, audio_get_state(self));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _audio_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- Audio *self = AUDIO(object);
- GError *error = NULL;
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- audio_post_init(self, g_value_get_string(value));
- 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);
-}
-
-/* Methods */
-
-/* void Connect() */
-void audio_connect(Audio *self, GError **error)
-{
- g_assert(AUDIO_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Connect", error, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void Disconnect() */
-void audio_disconnect(Audio *self, GError **error)
-{
- g_assert(AUDIO_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Disconnect", error, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* dict GetProperties() */
-GHashTable *audio_get_properties(Audio *self, GError **error)
-{
- g_assert(AUDIO_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;
-}
-
-/* Properties access methods */
-const gchar *audio_get_dbus_object_path(Audio *self)
-{
- g_assert(AUDIO_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
-}
-
-const gchar *audio_get_state(Audio *self)
-{
- g_assert(AUDIO_IS(self));
-
- return self->priv->state;
-}
-
-/* Signals handlers */
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data)
-{
- Audio *self = AUDIO(data);
-
- if (g_strcmp0(name, "State") == 0) {
- g_free(self->priv->state);
- self->priv->state = g_value_dup_string(value);
- }
-
- g_signal_emit(self, signals[PROPERTY_CHANGED], 0, name, value);
-}
-
diff --git a/src/lib/bluez/audio.h b/src/lib/bluez/audio.h
deleted file mode 100644
index 6d801f2..0000000
--- a/src/lib/bluez/audio.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *
- * 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 __AUDIO_H
-#define __AUDIO_H
-
-#include <glib-object.h>
-
-#define AUDIO_DBUS_INTERFACE "org.bluez.Audio"
-
-/*
- * Type macros
- */
-#define AUDIO_TYPE (audio_get_type())
-#define AUDIO(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), AUDIO_TYPE, Audio))
-#define AUDIO_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), AUDIO_TYPE))
-#define AUDIO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), AUDIO_TYPE, AudioClass))
-#define AUDIO_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), AUDIO_TYPE))
-#define AUDIO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), AUDIO_TYPE, AudioClass))
-
-typedef struct _Audio Audio;
-typedef struct _AudioClass AudioClass;
-typedef struct _AudioPrivate AudioPrivate;
-
-struct _Audio {
- GObject parent_instance;
-
- /*< private >*/
- AudioPrivate *priv;
-};
-
-struct _AudioClass {
- GObjectClass parent_class;
-};
-
-/* used by AUDIO_TYPE */
-GType audio_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-void audio_connect(Audio *self, GError **error);
-void audio_disconnect(Audio *self, GError **error);
-GHashTable *audio_get_properties(Audio *self, GError **error);
-
-const gchar *audio_get_dbus_object_path(Audio *self);
-const gchar *audio_get_state(Audio *self);
-
-#endif /* __AUDIO_H */
-
diff --git a/src/lib/bluez/cycling_speed.c b/src/lib/bluez/cycling_speed.c
new file mode 100644
index 0000000..d09468a
--- /dev/null
+++ b/src/lib/bluez/cycling_speed.c
@@ -0,0 +1,210 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "cycling_speed.h"
+
+#define CYCLING_SPEED_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), CYCLING_SPEED_TYPE, CyclingSpeedPrivate))
+
+struct _CyclingSpeedPrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(CyclingSpeed, cycling_speed, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _cycling_speed_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _cycling_speed_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _cycling_speed_create_gdbus_proxy(CyclingSpeed *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void cycling_speed_dispose(GObject *gobject)
+{
+ CyclingSpeed *self = CYCLING_SPEED(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(cycling_speed_parent_class)->dispose(gobject);
+}
+
+static void cycling_speed_finalize (GObject *gobject)
+{
+ CyclingSpeed *self = CYCLING_SPEED(gobject);
+ G_OBJECT_CLASS(cycling_speed_parent_class)->finalize(gobject);
+}
+
+static void cycling_speed_class_init(CyclingSpeedClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = cycling_speed_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _cycling_speed_get_property;
+ gobject_class->set_property = _cycling_speed_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "CyclingSpeed D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void cycling_speed_init(CyclingSpeed *self)
+{
+ self->priv = cycling_speed_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _cycling_speed_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ CyclingSpeed *self = CYCLING_SPEED(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, cycling_speed_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _cycling_speed_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ CyclingSpeed *self = CYCLING_SPEED(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _cycling_speed_create_gdbus_proxy(self, CYCLING_SPEED_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+CyclingSpeed *cycling_speed_new(const gchar *dbus_object_path)
+{
+ return g_object_new(CYCLING_SPEED_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _cycling_speed_create_gdbus_proxy(CyclingSpeed *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(CYCLING_SPEED_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, CYCLING_SPEED_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *cycling_speed_get_dbus_object_path(CyclingSpeed *self)
+{
+ g_assert(CYCLING_SPEED_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+
+
+/* Properties access methods */
+GVariant *cycling_speed_get_properties(CyclingSpeed *self, GError **error)
+{
+ g_assert(CYCLING_SPEED_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, CYCLING_SPEED_DBUS_INTERFACE, error);
+}
+
+void cycling_speed_set_property(CyclingSpeed *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(CYCLING_SPEED_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, CYCLING_SPEED_DBUS_INTERFACE, name, value, error);
+}
+
+gboolean cycling_speed_get_multiple_locations_supported(CyclingSpeed *self, GError **error)
+{
+ g_assert(CYCLING_SPEED_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, CYCLING_SPEED_DBUS_INTERFACE, "MultipleLocationsSupported", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+gboolean cycling_speed_get_wheel_revolution_data_supported(CyclingSpeed *self, GError **error)
+{
+ g_assert(CYCLING_SPEED_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, CYCLING_SPEED_DBUS_INTERFACE, "WheelRevolutionDataSupported", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/cycling_speed.h b/src/lib/bluez/cycling_speed.h
new file mode 100644
index 0000000..f60c16c
--- /dev/null
+++ b/src/lib/bluez/cycling_speed.h
@@ -0,0 +1,85 @@
+/*
+ *
+ * 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 __CYCLING_SPEED_H
+#define __CYCLING_SPEED_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define CYCLING_SPEED_DBUS_SERVICE "org.bluez"
+#define CYCLING_SPEED_DBUS_INTERFACE "org.bluez.CyclingSpeed1"
+
+/*
+ * Type macros
+ */
+#define CYCLING_SPEED_TYPE (cycling_speed_get_type())
+#define CYCLING_SPEED(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CYCLING_SPEED_TYPE, CyclingSpeed))
+#define CYCLING_SPEED_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CYCLING_SPEED_TYPE))
+#define CYCLING_SPEED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CYCLING_SPEED_TYPE, CyclingSpeedClass))
+#define CYCLING_SPEED_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CYCLING_SPEED_TYPE))
+#define CYCLING_SPEED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CYCLING_SPEED_TYPE, CyclingSpeedClass))
+
+typedef struct _CyclingSpeed CyclingSpeed;
+typedef struct _CyclingSpeedClass CyclingSpeedClass;
+typedef struct _CyclingSpeedPrivate CyclingSpeedPrivate;
+
+struct _CyclingSpeed {
+ GObject parent_instance;
+
+ /*< private >*/
+ CyclingSpeedPrivate *priv;
+};
+
+struct _CyclingSpeedClass {
+ GObjectClass parent_class;
+};
+
+/* used by CYCLING_SPEED_TYPE */
+GType cycling_speed_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+CyclingSpeed *cycling_speed_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *cycling_speed_get_dbus_object_path(CyclingSpeed *self);
+
+GVariant *cycling_speed_get_properties(CyclingSpeed *self, GError **error);
+void cycling_speed_set_property(CyclingSpeed *self, const gchar *name, const GVariant *value, GError **error);
+
+gboolean cycling_speed_get_multiple_locations_supported(CyclingSpeed *self, GError **error);
+gboolean cycling_speed_get_wheel_revolution_data_supported(CyclingSpeed *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CYCLING_SPEED_H */
+
diff --git a/src/lib/bluez/cycling_speed_manager.c b/src/lib/bluez/cycling_speed_manager.c
new file mode 100644
index 0000000..36e9e6a
--- /dev/null
+++ b/src/lib/bluez/cycling_speed_manager.c
@@ -0,0 +1,162 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "cycling_speed_manager.h"
+
+#define CYCLING_SPEED_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), CYCLING_SPEED_MANAGER_TYPE, CyclingSpeedManagerPrivate))
+
+struct _CyclingSpeedManagerPrivate {
+ GDBusProxy *proxy;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(CyclingSpeedManager, cycling_speed_manager, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _cycling_speed_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _cycling_speed_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _cycling_speed_manager_create_gdbus_proxy(CyclingSpeedManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void cycling_speed_manager_dispose(GObject *gobject)
+{
+ CyclingSpeedManager *self = CYCLING_SPEED_MANAGER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(cycling_speed_manager_parent_class)->dispose(gobject);
+}
+
+static void cycling_speed_manager_finalize (GObject *gobject)
+{
+ CyclingSpeedManager *self = CYCLING_SPEED_MANAGER(gobject);
+ G_OBJECT_CLASS(cycling_speed_manager_parent_class)->finalize(gobject);
+}
+
+static void cycling_speed_manager_class_init(CyclingSpeedManagerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = cycling_speed_manager_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _cycling_speed_manager_get_property;
+ gobject_class->set_property = _cycling_speed_manager_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "CyclingSpeedManager D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void cycling_speed_manager_init(CyclingSpeedManager *self)
+{
+ self->priv = cycling_speed_manager_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _cycling_speed_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ CyclingSpeedManager *self = CYCLING_SPEED_MANAGER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, cycling_speed_manager_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _cycling_speed_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ CyclingSpeedManager *self = CYCLING_SPEED_MANAGER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _cycling_speed_manager_create_gdbus_proxy(self, CYCLING_SPEED_MANAGER_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+CyclingSpeedManager *cycling_speed_manager_new(const gchar *dbus_object_path)
+{
+ return g_object_new(CYCLING_SPEED_MANAGER_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _cycling_speed_manager_create_gdbus_proxy(CyclingSpeedManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(CYCLING_SPEED_MANAGER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, CYCLING_SPEED_MANAGER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *cycling_speed_manager_get_dbus_object_path(CyclingSpeedManager *self)
+{
+ g_assert(CYCLING_SPEED_MANAGER_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
diff --git a/src/lib/bluez/cycling_speed_manager.h b/src/lib/bluez/cycling_speed_manager.h
new file mode 100644
index 0000000..dec0455
--- /dev/null
+++ b/src/lib/bluez/cycling_speed_manager.h
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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 __CYCLING_SPEED_MANAGER_H
+#define __CYCLING_SPEED_MANAGER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define CYCLING_SPEED_MANAGER_DBUS_SERVICE "org.bluez"
+#define CYCLING_SPEED_MANAGER_DBUS_INTERFACE "org.bluez.CyclingSpeedManager1"
+
+/*
+ * Type macros
+ */
+#define CYCLING_SPEED_MANAGER_TYPE (cycling_speed_manager_get_type())
+#define CYCLING_SPEED_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CYCLING_SPEED_MANAGER_TYPE, CyclingSpeedManager))
+#define CYCLING_SPEED_MANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CYCLING_SPEED_MANAGER_TYPE))
+#define CYCLING_SPEED_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CYCLING_SPEED_MANAGER_TYPE, CyclingSpeedManagerClass))
+#define CYCLING_SPEED_MANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CYCLING_SPEED_MANAGER_TYPE))
+#define CYCLING_SPEED_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CYCLING_SPEED_MANAGER_TYPE, CyclingSpeedManagerClass))
+
+typedef struct _CyclingSpeedManager CyclingSpeedManager;
+typedef struct _CyclingSpeedManagerClass CyclingSpeedManagerClass;
+typedef struct _CyclingSpeedManagerPrivate CyclingSpeedManagerPrivate;
+
+struct _CyclingSpeedManager {
+ GObject parent_instance;
+
+ /*< private >*/
+ CyclingSpeedManagerPrivate *priv;
+};
+
+struct _CyclingSpeedManagerClass {
+ GObjectClass parent_class;
+};
+
+/* used by CYCLING_SPEED_MANAGER_TYPE */
+GType cycling_speed_manager_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+CyclingSpeedManager *cycling_speed_manager_new(const gchar *dbus_object_path);
+const gchar *cycling_speed_manager_get_dbus_object_path(CyclingSpeedManager *self);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CYCLING_SPEED_MANAGER_H */
+
diff --git a/src/lib/bluez/device.c b/src/lib/bluez/device.c
index 7cc6bc0..0d9f8ec 100644
--- a/src/lib/bluez/device.c
+++ b/src/lib/bluez/device.c
@@ -24,339 +24,83 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
-
-#include <string.h>
-
+#include <gio/gio.h>
#include <glib.h>
-#include <dbus/dbus-glib.h>
+#include <string.h>
#include "../dbus-common.h"
-#include "../marshallers.h"
+#include "../properties.h"
#include "device.h"
#define DEVICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), DEVICE_TYPE, DevicePrivate))
struct _DevicePrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-
- /* Properties */
- gchar *adapter;
- gchar *address;
- gchar *alias;
- gboolean blocked;
- guint32 class;
- gboolean connected;
- gchar *icon;
- gboolean legacy_pairing;
- gchar *name;
- gboolean paired;
- GPtrArray *services;
- gboolean trusted;
- gchar **uuids;
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
};
-G_DEFINE_TYPE(Device, device, G_TYPE_OBJECT);
+G_DEFINE_TYPE_WITH_PRIVATE(Device, device, G_TYPE_OBJECT);
enum {
PROP_0,
-
- PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
- PROP_ADAPTER, /* readonly */
- PROP_ADDRESS, /* readonly */
- PROP_ALIAS, /* readwrite */
- PROP_BLOCKED, /* readwrite */
- PROP_CLASS, /* readonly */
- PROP_CONNECTED, /* readonly */
- PROP_ICON, /* readonly */
- PROP_LEGACY_PAIRING, /* readonly */
- PROP_NAME, /* readonly */
- PROP_PAIRED, /* readonly */
- PROP_SERVICES, /* readonly */
- PROP_TRUSTED, /* readwrite */
- PROP_UUIDS /* readonly */
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
};
static void _device_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void _device_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-enum {
- DISCONNECT_REQUESTED,
- PROPERTY_CHANGED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void disconnect_requested_handler(DBusGProxy *dbus_g_proxy, gpointer data);
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data);
+static void _device_create_gdbus_proxy(Device *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
static void device_dispose(GObject *gobject)
{
Device *self = DEVICE(gobject);
- /* DBus signals disconnection */
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "DisconnectRequested", G_CALLBACK(disconnect_requested_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self);
-
- /* Properties free */
- g_free(self->priv->adapter);
- g_free(self->priv->address);
- g_free(self->priv->alias);
- g_free(self->priv->icon);
- g_free(self->priv->name);
- g_ptr_array_unref(self->priv->services);
- g_strfreev(self->priv->uuids);
-
/* 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);
-
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
/* Chain up to the parent class */
G_OBJECT_CLASS(device_parent_class)->dispose(gobject);
}
+static void device_finalize (GObject *gobject)
+{
+ Device *self = DEVICE(gobject);
+ G_OBJECT_CLASS(device_parent_class)->finalize(gobject);
+}
+
static void device_class_init(DeviceClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = device_dispose;
- g_type_class_add_private(klass, sizeof(DevicePrivate));
-
/* Properties registration */
- GParamSpec *pspec;
+ GParamSpec *pspec = NULL;
gobject_class->get_property = _device_get_property;
gobject_class->set_property = _device_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);
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Device D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
-
- /* object Adapter [readonly] */
- pspec = g_param_spec_string("Adapter", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_ADAPTER, pspec);
-
- /* string Address [readonly] */
- pspec = g_param_spec_string("Address", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_ADDRESS, pspec);
-
- /* string Alias [readwrite] */
- pspec = g_param_spec_string("Alias", NULL, NULL, NULL, G_PARAM_READWRITE);
- g_object_class_install_property(gobject_class, PROP_ALIAS, pspec);
-
- /* boolean Blocked [readwrite] */
- pspec = g_param_spec_boolean("Blocked", NULL, NULL, FALSE, G_PARAM_READWRITE);
- g_object_class_install_property(gobject_class, PROP_BLOCKED, pspec);
-
- /* uint32 Class [readonly] */
- pspec = g_param_spec_uint("Class", NULL, NULL, 0, 0xFFFFFFFF, 0, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_CLASS, pspec);
-
- /* boolean Connected [readonly] */
- pspec = g_param_spec_boolean("Connected", NULL, NULL, FALSE, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_CONNECTED, pspec);
-
- /* string Icon [readonly] */
- pspec = g_param_spec_string("Icon", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_ICON, pspec);
-
- /* boolean LegacyPairing [readonly] */
- pspec = g_param_spec_boolean("LegacyPairing", NULL, NULL, FALSE, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_LEGACY_PAIRING, pspec);
-
- /* string Name [readonly] */
- pspec = g_param_spec_string("Name", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_NAME, pspec);
-
- /* boolean Paired [readonly] */
- pspec = g_param_spec_boolean("Paired", NULL, NULL, FALSE, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_PAIRED, pspec);
-
- /* array{object} Services [readonly] */
- pspec = g_param_spec_boxed("Services", NULL, NULL, G_TYPE_PTR_ARRAY, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_SERVICES, pspec);
-
- /* boolean Trusted [readwrite] */
- pspec = g_param_spec_boolean("Trusted", NULL, NULL, FALSE, G_PARAM_READWRITE);
- g_object_class_install_property(gobject_class, PROP_TRUSTED, pspec);
-
- /* array{string} UUIDs [readonly] */
- pspec = g_param_spec_boxed("UUIDs", NULL, NULL, G_TYPE_STRV, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_UUIDS, pspec);
-
- /* Signals registation */
- signals[DISCONNECT_REQUESTED] = g_signal_new("DisconnectRequested",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- signals[PROPERTY_CHANGED] = g_signal_new("PropertyChanged",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_bt_marshal_VOID__STRING_BOXED,
- G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE);
+ if (pspec)
+ g_param_spec_unref(pspec);
}
static void device_init(Device *self)
{
- self->priv = DEVICE_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
+ self->priv = device_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
g_assert(system_conn != NULL);
}
-static void device_post_init(Device *self, const gchar *dbus_object_path)
-{
- 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(system_conn, "org.bluez", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", DEVICE_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", DEVICE_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, DEVICE_DBUS_INTERFACE);
-
- /* DBus signals connection */
-
- /* DisconnectRequested() */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "DisconnectRequested", G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "DisconnectRequested", G_CALLBACK(disconnect_requested_handler), self, NULL);
-
- /* PropertyChanged(string name, variant value) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self, NULL);
-
- /* Properties init */
- GHashTable *properties = device_get_properties(self, &error);
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
- g_assert(properties != NULL);
-
- /* object Adapter [readonly] */
- if (g_hash_table_lookup(properties, "Adapter")) {
- self->priv->adapter = (gchar *) g_value_dup_boxed(g_hash_table_lookup(properties, "Adapter"));
- } else {
- self->priv->adapter = g_strdup("undefined");
- }
-
- /* string Address [readonly] */
- if (g_hash_table_lookup(properties, "Address")) {
- self->priv->address = g_value_dup_string(g_hash_table_lookup(properties, "Address"));
- } else {
- self->priv->address = g_strdup("undefined");
- }
-
- /* string Alias [readwrite] */
- if (g_hash_table_lookup(properties, "Alias")) {
- self->priv->alias = g_value_dup_string(g_hash_table_lookup(properties, "Alias"));
- } else {
- self->priv->alias = g_strdup("undefined");
- }
-
- /* boolean Blocked [readwrite] */
- if (g_hash_table_lookup(properties, "Blocked")) {
- self->priv->blocked = g_value_get_boolean(g_hash_table_lookup(properties, "Blocked"));
- } else {
- self->priv->blocked = FALSE;
- }
-
- /* uint32 Class [readonly] */
- if (g_hash_table_lookup(properties, "Class")) {
- self->priv->class = g_value_get_uint(g_hash_table_lookup(properties, "Class"));
- } else {
- self->priv->class = 0;
- }
-
- /* boolean Connected [readonly] */
- if (g_hash_table_lookup(properties, "Connected")) {
- self->priv->connected = g_value_get_boolean(g_hash_table_lookup(properties, "Connected"));
- } else {
- self->priv->connected = FALSE;
- }
-
- /* string Icon [readonly] */
- if (g_hash_table_lookup(properties, "Icon")) {
- self->priv->icon = g_value_dup_string(g_hash_table_lookup(properties, "Icon"));
- } else {
- self->priv->icon = g_strdup("undefined");
- }
-
- /* boolean LegacyPairing [readonly] */
- if (g_hash_table_lookup(properties, "LegacyPairing")) {
- self->priv->legacy_pairing = g_value_get_boolean(g_hash_table_lookup(properties, "LegacyPairing"));
- } else {
- self->priv->legacy_pairing = FALSE;
- }
-
- /* string Name [readonly] */
- 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");
- }
-
- /* boolean Paired [readonly] */
- if (g_hash_table_lookup(properties, "Paired")) {
- self->priv->paired = g_value_get_boolean(g_hash_table_lookup(properties, "Paired"));
- } else {
- self->priv->paired = FALSE;
- }
-
- /* array{object} Services [readonly] */
- if (g_hash_table_lookup(properties, "Services")) {
- self->priv->services = g_value_dup_boxed(g_hash_table_lookup(properties, "Services"));
- } else {
- self->priv->services = g_ptr_array_new();
- }
-
- /* boolean Trusted [readwrite] */
- if (g_hash_table_lookup(properties, "Trusted")) {
- self->priv->trusted = g_value_get_boolean(g_hash_table_lookup(properties, "Trusted"));
- } else {
- self->priv->trusted = FALSE;
- }
-
- /* array{string} UUIDs [readonly] */
- if (g_hash_table_lookup(properties, "UUIDs")) {
- self->priv->uuids = (gchar **) g_value_dup_boxed(g_hash_table_lookup(properties, "UUIDs"));
- } else {
- self->priv->uuids = g_new0(char *, 1);
- self->priv->uuids[0] = NULL;
- }
-
- g_hash_table_unref(properties);
-}
-
static void _device_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
Device *self = DEVICE(object);
@@ -366,58 +110,6 @@ static void _device_get_property(GObject *object, guint property_id, GValue *val
g_value_set_string(value, device_get_dbus_object_path(self));
break;
- case PROP_ADAPTER:
- g_value_set_string(value, device_get_adapter(self));
- break;
-
- case PROP_ADDRESS:
- g_value_set_string(value, device_get_address(self));
- break;
-
- case PROP_ALIAS:
- g_value_set_string(value, device_get_alias(self));
- break;
-
- case PROP_BLOCKED:
- g_value_set_boolean(value, device_get_blocked(self));
- break;
-
- case PROP_CLASS:
- g_value_set_uint(value, device_get_class(self));
- break;
-
- case PROP_CONNECTED:
- g_value_set_boolean(value, device_get_connected(self));
- break;
-
- case PROP_ICON:
- g_value_set_string(value, device_get_icon(self));
- break;
-
- case PROP_LEGACY_PAIRING:
- g_value_set_boolean(value, device_get_legacy_pairing(self));
- break;
-
- case PROP_NAME:
- g_value_set_string(value, device_get_name(self));
- break;
-
- case PROP_PAIRED:
- g_value_set_boolean(value, device_get_paired(self));
- break;
-
- case PROP_SERVICES:
- g_value_set_boxed(value, device_get_services(self));
- break;
-
- case PROP_TRUSTED:
- g_value_set_boolean(value, device_get_trusted(self));
- break;
-
- case PROP_UUIDS:
- g_value_set_boxed(value, device_get_uuids(self));
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
@@ -431,19 +123,8 @@ static void _device_set_property(GObject *object, guint property_id, const GValu
switch (property_id) {
case PROP_DBUS_OBJECT_PATH:
- device_post_init(self, g_value_get_string(value));
- break;
-
- case PROP_ALIAS:
- device_set_property(self, "Alias", value, &error);
- break;
-
- case PROP_BLOCKED:
- device_set_property(self, "Blocked", value, &error);
- break;
-
- case PROP_TRUSTED:
- device_set_property(self, "Trusted", value, &error);
+ self->priv->object_path = g_value_dup_string(value);
+ _device_create_gdbus_proxy(self, DEVICE_DBUS_SERVICE, self->priv->object_path, &error);
break;
default:
@@ -451,260 +132,320 @@ static void _device_set_property(GObject *object, guint property_id, const GValu
break;
}
- if (error != NULL) {
+ if (error != NULL)
g_critical("%s", error->message);
- }
+
g_assert(error == NULL);
}
-/* Methods */
+/* Constructor */
+Device *device_new(const gchar *dbus_object_path)
+{
+ return g_object_new(DEVICE_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
-/* void CancelDiscovery() */
-void device_cancel_discovery(Device *self, GError **error)
+/* Private DBus proxy creation */
+static void _device_create_gdbus_proxy(Device *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
{
g_assert(DEVICE_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, DEVICE_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "CancelDiscovery", error, G_TYPE_INVALID, G_TYPE_INVALID);
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
}
-/* void Disconnect() */
-void device_disconnect(Device *self, GError **error)
+/* Methods */
+
+/* Get DBus object path */
+const gchar *device_get_dbus_object_path(Device *self)
{
g_assert(DEVICE_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Disconnect", error, G_TYPE_INVALID, G_TYPE_INVALID);
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
}
-/* dict{u,s} DiscoverServices(string pattern) */
-GHashTable *device_discover_services(Device *self, const gchar *pattern, GError **error)
+/* void CancelPairing() */
+void device_cancel_pairing(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "CancelPairing", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
- GHashTable *ret = NULL;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "DiscoverServices", error, G_TYPE_STRING, pattern, G_TYPE_INVALID, DBUS_TYPE_G_UINT_STRING_HASHTABLE, &ret, G_TYPE_INVALID);
+/* void Connect() */
+void device_connect(Device *self, GError **error)
+{
+ g_assert(DEVICE_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Connect", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
- return ret;
+/* void ConnectProfile(string uuid) */
+void device_connect_profile(Device *self, const gchar *uuid, GError **error)
+{
+ g_assert(DEVICE_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "ConnectProfile", g_variant_new ("(s)", uuid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
}
-/* dict GetProperties() */
-GHashTable *device_get_properties(Device *self, GError **error)
+/* void Disconnect() */
+void device_disconnect(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Disconnect", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
- 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);
+/* void DisconnectProfile(string uuid) */
+void device_disconnect_profile(Device *self, const gchar *uuid, GError **error)
+{
+ g_assert(DEVICE_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "DisconnectProfile", g_variant_new ("(s)", uuid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
- return ret;
+/* void Pair() */
+void device_pair(Device *self, GError **error)
+{
+ g_assert(DEVICE_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Pair", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
}
-/* void SetProperty(string name, variant value) */
-void device_set_property(Device *self, const gchar *name, const GValue *value, GError **error)
+/* asynchronous call to void Pair() */
+void device_pair_async(Device *self, GAsyncReadyCallback callback, gpointer user_data)
{
g_assert(DEVICE_IS(self));
+ g_dbus_proxy_call (self->priv->proxy,
+ "Pair",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ callback,
+ user_data);
+}
- 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);
+/* finish asynchronous call to void Pair() */
+void device_pair_finish(Device *self, GAsyncResult *res, GError **error)
+{
+ g_assert(DEVICE_IS(self));
+ g_dbus_proxy_call_finish (self->priv->proxy,
+ res,
+ error);
+
}
/* Properties access methods */
-const gchar *device_get_dbus_object_path(Device *self)
+GVariant *device_get_properties(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, DEVICE_DBUS_INTERFACE, error);
}
-const gchar *device_get_adapter(Device *self)
+void device_set_property(Device *self, const gchar *name, const GVariant *value, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->adapter;
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, DEVICE_DBUS_INTERFACE, name, value, error);
}
-const gchar *device_get_address(Device *self)
+const gchar *device_get_adapter(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->address;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Adapter", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
-const gchar *device_get_alias(Device *self)
+const gchar *device_get_address(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->alias;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Address", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
-void device_set_alias(Device *self, const gchar *value)
+const gchar *device_get_alias(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- GError *error = NULL;
-
- GValue t = {0};
- g_value_init(&t, G_TYPE_STRING);
- g_value_set_string(&t, value);
- device_set_property(self, "Alias", &t, &error);
- g_value_unset(&t);
-
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Alias", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
-const gboolean device_get_blocked(Device *self)
+void device_set_alias(Device *self, const gchar *value, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->blocked;
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, DEVICE_DBUS_INTERFACE, "Alias", g_variant_new_string(value), error);
}
-void device_set_blocked(Device *self, const gboolean value)
+guint16 device_get_appearance(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- GError *error = NULL;
-
- GValue t = {0};
- g_value_init(&t, G_TYPE_BOOLEAN);
- g_value_set_boolean(&t, value);
- device_set_property(self, "Blocked", &t, &error);
- g_value_unset(&t);
-
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Appearance", error);
+ if(prop == NULL)
+ return 0;
+ guint16 ret = g_variant_get_uint16(prop);
+ g_variant_unref(prop);
+ return ret;
}
-const guint32 device_get_class(Device *self)
+gboolean device_get_blocked(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->class;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Blocked", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
}
-const gboolean device_get_connected(Device *self)
+void device_set_blocked(Device *self, const gboolean value, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->connected;
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, DEVICE_DBUS_INTERFACE, "Blocked", g_variant_new_boolean(value), error);
}
-const gchar *device_get_icon(Device *self)
+guint32 device_get_class(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->icon;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Class", error);
+ if(prop == NULL)
+ return 0;
+ guint32 ret = g_variant_get_uint32(prop);
+ g_variant_unref(prop);
+ return ret;
}
-const gboolean device_get_legacy_pairing(Device *self)
+gboolean device_get_connected(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->legacy_pairing;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Connected", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
}
-const gchar *device_get_name(Device *self)
+const gchar *device_get_icon(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->name;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Icon", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
-const gboolean device_get_paired(Device *self)
+gboolean device_get_legacy_pairing(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->paired;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "LegacyPairing", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
}
-const GPtrArray *device_get_services(Device *self)
+const gchar *device_get_modalias(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->services;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Modalias", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
-const gboolean device_get_trusted(Device *self)
+const gchar *device_get_name(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
-
- return self->priv->trusted;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Name", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
-void device_set_trusted(Device *self, const gboolean value)
+gboolean device_get_paired(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Paired", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
- GError *error = NULL;
-
- GValue t = {0};
- g_value_init(&t, G_TYPE_BOOLEAN);
- g_value_set_boolean(&t, value);
- device_set_property(self, "Trusted", &t, &error);
- g_value_unset(&t);
-
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
+gint16 device_get_rssi(Device *self, GError **error)
+{
+ g_assert(DEVICE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "RSSI", error);
+ if(prop == NULL)
+ return 0;
+ gint16 ret = g_variant_get_int16(prop);
+ g_variant_unref(prop);
+ return ret;
}
-const gchar **device_get_uuids(Device *self)
+gboolean device_get_trusted(Device *self, GError **error)
{
g_assert(DEVICE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "Trusted", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
- return self->priv->uuids;
-}
-
-/* Signals handlers */
-static void disconnect_requested_handler(DBusGProxy *dbus_g_proxy, gpointer data)
-{
- Device *self = DEVICE(data);
-
- g_signal_emit(self, signals[DISCONNECT_REQUESTED], 0);
-}
-
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data)
-{
- Device *self = DEVICE(data);
-
- if (g_strcmp0(name, "Adapter") == 0) {
- g_free(self->priv->adapter);
- self->priv->adapter = (gchar *) g_value_dup_boxed(value);
- } else if (g_strcmp0(name, "Address") == 0) {
- g_free(self->priv->address);
- self->priv->address = g_value_dup_string(value);
- } else if (g_strcmp0(name, "Alias") == 0) {
- g_free(self->priv->alias);
- self->priv->alias = g_value_dup_string(value);
- } else if (g_strcmp0(name, "Blocked") == 0) {
- self->priv->blocked = g_value_get_boolean(value);
- } else if (g_strcmp0(name, "Class") == 0) {
- self->priv->class = g_value_get_uint(value);
- } else if (g_strcmp0(name, "Connected") == 0) {
- self->priv->connected = g_value_get_boolean(value);
- } else if (g_strcmp0(name, "Icon") == 0) {
- g_free(self->priv->icon);
- self->priv->icon = g_value_dup_string(value);
- } else if (g_strcmp0(name, "LegacyPairing") == 0) {
- self->priv->legacy_pairing = g_value_get_boolean(value);
- } else if (g_strcmp0(name, "Name") == 0) {
- g_free(self->priv->name);
- self->priv->name = g_value_dup_string(value);
- } else if (g_strcmp0(name, "Paired") == 0) {
- self->priv->paired = g_value_get_boolean(value);
- } else if (g_strcmp0(name, "Services") == 0) {
- g_ptr_array_unref(self->priv->services);
- self->priv->services = g_value_dup_boxed(value);
- } else if (g_strcmp0(name, "Trusted") == 0) {
- self->priv->trusted = g_value_get_boolean(value);
- } else if (g_strcmp0(name, "UUIDs") == 0) {
- g_strfreev(self->priv->uuids);
- self->priv->uuids = (gchar **) g_value_dup_boxed(value);
- }
+void device_set_trusted(Device *self, const gboolean value, GError **error)
+{
+ g_assert(DEVICE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, DEVICE_DBUS_INTERFACE, "Trusted", g_variant_new_boolean(value), error);
+}
- g_signal_emit(self, signals[PROPERTY_CHANGED], 0, name, value);
+const gchar **device_get_uuids(Device *self, GError **error)
+{
+ g_assert(DEVICE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, DEVICE_DBUS_INTERFACE, "UUIDs", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar **ret = g_variant_get_strv(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
diff --git a/src/lib/bluez/device.h b/src/lib/bluez/device.h
index c4f6e2f..20242a2 100644
--- a/src/lib/bluez/device.h
+++ b/src/lib/bluez/device.h
@@ -24,9 +24,14 @@
#ifndef __DEVICE_H
#define __DEVICE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <glib-object.h>
-#define DEVICE_DBUS_INTERFACE "org.bluez.Device"
+#define DEVICE_DBUS_SERVICE "org.bluez"
+#define DEVICE_DBUS_INTERFACE "org.bluez.Device1"
/*
* Type macros
@@ -57,31 +62,49 @@ struct _DeviceClass {
GType device_get_type(void) G_GNUC_CONST;
/*
+ * Constructor
+ */
+Device *device_new(const gchar *dbus_object_path);
+
+/*
* Method definitions
*/
-void device_cancel_discovery(Device *self, GError **error);
+const gchar *device_get_dbus_object_path(Device *self);
+
+void device_cancel_pairing(Device *self, GError **error);
+void device_connect(Device *self, GError **error);
+void device_connect_profile(Device *self, const gchar *uuid, GError **error);
void device_disconnect(Device *self, GError **error);
-GHashTable *device_discover_services(Device *self, const gchar *pattern, GError **error);
-GHashTable *device_get_properties(Device *self, GError **error);
-void device_set_property(Device *self, const gchar *name, const GValue *value, GError **error);
+void device_disconnect_profile(Device *self, const gchar *uuid, GError **error);
+void device_pair(Device *self, GError **error);
+void device_pair_async(Device *self, GAsyncReadyCallback callback, gpointer user_data);
+void device_pair_finish(Device *self, GAsyncResult *res, GError **error);
-const gchar *device_get_dbus_object_path(Device *self);
-const gchar *device_get_adapter(Device *self);
-const gchar *device_get_address(Device *self);
-const gchar *device_get_alias(Device *self);
-void device_set_alias(Device *self, const gchar *value);
-const gboolean device_get_blocked(Device *self);
-void device_set_blocked(Device *self, const gboolean value);
-const guint32 device_get_class(Device *self);
-const gboolean device_get_connected(Device *self);
-const gchar *device_get_icon(Device *self);
-const gboolean device_get_legacy_pairing(Device *self);
-const gchar *device_get_name(Device *self);
-const gboolean device_get_paired(Device *self);
-const GPtrArray *device_get_services(Device *self);
-const gboolean device_get_trusted(Device *self);
-void device_set_trusted(Device *self, const gboolean value);
-const gchar **device_get_uuids(Device *self);
+GVariant *device_get_properties(Device *self, GError **error);
+void device_set_property(Device *self, const gchar *name, const GVariant *value, GError **error);
+
+const gchar *device_get_adapter(Device *self, GError **error);
+const gchar *device_get_address(Device *self, GError **error);
+const gchar *device_get_alias(Device *self, GError **error);
+void device_set_alias(Device *self, const gchar *value, GError **error);
+guint16 device_get_appearance(Device *self, GError **error);
+gboolean device_get_blocked(Device *self, GError **error);
+void device_set_blocked(Device *self, const gboolean value, GError **error);
+guint32 device_get_class(Device *self, GError **error);
+gboolean device_get_connected(Device *self, GError **error);
+const gchar *device_get_icon(Device *self, GError **error);
+gboolean device_get_legacy_pairing(Device *self, GError **error);
+const gchar *device_get_modalias(Device *self, GError **error);
+const gchar *device_get_name(Device *self, GError **error);
+gboolean device_get_paired(Device *self, GError **error);
+gint16 device_get_rssi(Device *self, GError **error);
+gboolean device_get_trusted(Device *self, GError **error);
+void device_set_trusted(Device *self, const gboolean value, GError **error);
+const gchar **device_get_uuids(Device *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
#endif /* __DEVICE_H */
diff --git a/src/lib/bluez/health_channel.c b/src/lib/bluez/health_channel.c
new file mode 100644
index 0000000..2b888fa
--- /dev/null
+++ b/src/lib/bluez/health_channel.c
@@ -0,0 +1,241 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "health_channel.h"
+
+#define HEALTH_CHANNEL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), HEALTH_CHANNEL_TYPE, HealthChannelPrivate))
+
+struct _HealthChannelPrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(HealthChannel, health_channel, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _health_channel_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _health_channel_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _health_channel_create_gdbus_proxy(HealthChannel *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void health_channel_dispose(GObject *gobject)
+{
+ HealthChannel *self = HEALTH_CHANNEL(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(health_channel_parent_class)->dispose(gobject);
+}
+
+static void health_channel_finalize (GObject *gobject)
+{
+ HealthChannel *self = HEALTH_CHANNEL(gobject);
+ G_OBJECT_CLASS(health_channel_parent_class)->finalize(gobject);
+}
+
+static void health_channel_class_init(HealthChannelClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = health_channel_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _health_channel_get_property;
+ gobject_class->set_property = _health_channel_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "HealthChannel D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void health_channel_init(HealthChannel *self)
+{
+ self->priv = health_channel_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _health_channel_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ HealthChannel *self = HEALTH_CHANNEL(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, health_channel_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _health_channel_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ HealthChannel *self = HEALTH_CHANNEL(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _health_channel_create_gdbus_proxy(self, HEALTH_CHANNEL_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+HealthChannel *health_channel_new(const gchar *dbus_object_path)
+{
+ return g_object_new(HEALTH_CHANNEL_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _health_channel_create_gdbus_proxy(HealthChannel *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(HEALTH_CHANNEL_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, HEALTH_CHANNEL_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *health_channel_get_dbus_object_path(HealthChannel *self)
+{
+ g_assert(HEALTH_CHANNEL_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* fd Acquire() */
+guint32 health_channel_acquire(HealthChannel *self, GError **error)
+{
+ g_assert(HEALTH_CHANNEL_IS(self));
+ guint32 ret = 0;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "Acquire", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return 0;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_get_uint32(proxy_ret);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* void Release() */
+void health_channel_release(HealthChannel *self, GError **error)
+{
+ g_assert(HEALTH_CHANNEL_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Release", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* Properties access methods */
+GVariant *health_channel_get_properties(HealthChannel *self, GError **error)
+{
+ g_assert(HEALTH_CHANNEL_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, HEALTH_CHANNEL_DBUS_INTERFACE, error);
+}
+
+void health_channel_set_property(HealthChannel *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(HEALTH_CHANNEL_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, HEALTH_CHANNEL_DBUS_INTERFACE, name, value, error);
+}
+
+const gchar *health_channel_get_application(HealthChannel *self, GError **error)
+{
+ g_assert(HEALTH_CHANNEL_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, HEALTH_CHANNEL_DBUS_INTERFACE, "Application", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *health_channel_get_device(HealthChannel *self, GError **error)
+{
+ g_assert(HEALTH_CHANNEL_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, HEALTH_CHANNEL_DBUS_INTERFACE, "Device", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *health_channel_get_channel_type(HealthChannel *self, GError **error)
+{
+ g_assert(HEALTH_CHANNEL_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, HEALTH_CHANNEL_DBUS_INTERFACE, "Type", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/health_channel.h b/src/lib/bluez/health_channel.h
new file mode 100644
index 0000000..4b2a438
--- /dev/null
+++ b/src/lib/bluez/health_channel.h
@@ -0,0 +1,90 @@
+/*
+ *
+ * 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 __HEALTH_CHANNEL_H
+#define __HEALTH_CHANNEL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define HEALTH_CHANNEL_DBUS_SERVICE "org.bluez"
+#define HEALTH_CHANNEL_DBUS_INTERFACE "org.bluez.HealthChannel1"
+
+/*
+ * Type macros
+ */
+#define HEALTH_CHANNEL_TYPE (health_channel_get_type())
+#define HEALTH_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), HEALTH_CHANNEL_TYPE, HealthChannel))
+#define HEALTH_CHANNEL_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), HEALTH_CHANNEL_TYPE))
+#define HEALTH_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), HEALTH_CHANNEL_TYPE, HealthChannelClass))
+#define HEALTH_CHANNEL_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), HEALTH_CHANNEL_TYPE))
+#define HEALTH_CHANNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), HEALTH_CHANNEL_TYPE, HealthChannelClass))
+
+typedef struct _HealthChannel HealthChannel;
+typedef struct _HealthChannelClass HealthChannelClass;
+typedef struct _HealthChannelPrivate HealthChannelPrivate;
+
+struct _HealthChannel {
+ GObject parent_instance;
+
+ /*< private >*/
+ HealthChannelPrivate *priv;
+};
+
+struct _HealthChannelClass {
+ GObjectClass parent_class;
+};
+
+/* used by HEALTH_CHANNEL_TYPE */
+GType health_channel_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+HealthChannel *health_channel_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *health_channel_get_dbus_object_path(HealthChannel *self);
+
+guint32 health_channel_acquire(HealthChannel *self, GError **error);
+void health_channel_release(HealthChannel *self, GError **error);
+
+GVariant *health_channel_get_properties(HealthChannel *self, GError **error);
+void health_channel_set_property(HealthChannel *self, const gchar *name, const GVariant *value, GError **error);
+
+const gchar *health_channel_get_application(HealthChannel *self, GError **error);
+const gchar *health_channel_get_device(HealthChannel *self, GError **error);
+// This has been renamed because 'health_channel_get_type' is already used by GLib
+const gchar *health_channel_get_channel_type(HealthChannel *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __HEALTH_CHANNEL_H */
+
diff --git a/src/lib/bluez/health_device.c b/src/lib/bluez/health_device.c
new file mode 100644
index 0000000..5ff5889
--- /dev/null
+++ b/src/lib/bluez/health_device.c
@@ -0,0 +1,231 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "health_device.h"
+
+#define HEALTH_DEVICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), HEALTH_DEVICE_TYPE, HealthDevicePrivate))
+
+struct _HealthDevicePrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(HealthDevice, health_device, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _health_device_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _health_device_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _health_device_create_gdbus_proxy(HealthDevice *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void health_device_dispose(GObject *gobject)
+{
+ HealthDevice *self = HEALTH_DEVICE(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(health_device_parent_class)->dispose(gobject);
+}
+
+static void health_device_finalize (GObject *gobject)
+{
+ HealthDevice *self = HEALTH_DEVICE(gobject);
+ G_OBJECT_CLASS(health_device_parent_class)->finalize(gobject);
+}
+
+static void health_device_class_init(HealthDeviceClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = health_device_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _health_device_get_property;
+ gobject_class->set_property = _health_device_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "HealthDevice D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void health_device_init(HealthDevice *self)
+{
+ self->priv = health_device_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _health_device_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ HealthDevice *self = HEALTH_DEVICE(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, health_device_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _health_device_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ HealthDevice *self = HEALTH_DEVICE(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _health_device_create_gdbus_proxy(self, HEALTH_DEVICE_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+HealthDevice *health_device_new(const gchar *dbus_object_path)
+{
+ return g_object_new(HEALTH_DEVICE_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _health_device_create_gdbus_proxy(HealthDevice *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(HEALTH_DEVICE_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, HEALTH_DEVICE_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *health_device_get_dbus_object_path(HealthDevice *self)
+{
+ g_assert(HEALTH_DEVICE_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* object CreateChannel(object application, string configuration) */
+const gchar *health_device_create_channel(HealthDevice *self, const gchar *application, const gchar *configuration, GError **error)
+{
+ g_assert(HEALTH_DEVICE_IS(self));
+ const gchar *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "CreateChannel", g_variant_new ("(os)", application, configuration), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_get_string(proxy_ret, NULL);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* void DestroyChannel(object channel) */
+void health_device_destroy_channel(HealthDevice *self, const gchar *channel, GError **error)
+{
+ g_assert(HEALTH_DEVICE_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "DestroyChannel", g_variant_new ("(o)", channel), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* boolean Echo() */
+gboolean health_device_echo(HealthDevice *self, GError **error)
+{
+ g_assert(HEALTH_DEVICE_IS(self));
+ gboolean ret = FALSE;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "Echo", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return FALSE;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_get_boolean(proxy_ret);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* Properties access methods */
+GVariant *health_device_get_properties(HealthDevice *self, GError **error)
+{
+ g_assert(HEALTH_DEVICE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, HEALTH_DEVICE_DBUS_INTERFACE, error);
+}
+
+void health_device_set_property(HealthDevice *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(HEALTH_DEVICE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, HEALTH_DEVICE_DBUS_INTERFACE, name, value, error);
+}
+
+const gchar *health_device_get_main_channel(HealthDevice *self, GError **error)
+{
+ g_assert(HEALTH_DEVICE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, HEALTH_DEVICE_DBUS_INTERFACE, "MainChannel", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/health_device.h b/src/lib/bluez/health_device.h
new file mode 100644
index 0000000..6cbd33b
--- /dev/null
+++ b/src/lib/bluez/health_device.h
@@ -0,0 +1,88 @@
+/*
+ *
+ * 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 __HEALTH_DEVICE_H
+#define __HEALTH_DEVICE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define HEALTH_DEVICE_DBUS_SERVICE "org.bluez"
+#define HEALTH_DEVICE_DBUS_INTERFACE "org.bluez.HealthDevice1"
+
+/*
+ * Type macros
+ */
+#define HEALTH_DEVICE_TYPE (health_device_get_type())
+#define HEALTH_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), HEALTH_DEVICE_TYPE, HealthDevice))
+#define HEALTH_DEVICE_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), HEALTH_DEVICE_TYPE))
+#define HEALTH_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), HEALTH_DEVICE_TYPE, HealthDeviceClass))
+#define HEALTH_DEVICE_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), HEALTH_DEVICE_TYPE))
+#define HEALTH_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), HEALTH_DEVICE_TYPE, HealthDeviceClass))
+
+typedef struct _HealthDevice HealthDevice;
+typedef struct _HealthDeviceClass HealthDeviceClass;
+typedef struct _HealthDevicePrivate HealthDevicePrivate;
+
+struct _HealthDevice {
+ GObject parent_instance;
+
+ /*< private >*/
+ HealthDevicePrivate *priv;
+};
+
+struct _HealthDeviceClass {
+ GObjectClass parent_class;
+};
+
+/* used by HEALTH_DEVICE_TYPE */
+GType health_device_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+HealthDevice *health_device_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *health_device_get_dbus_object_path(HealthDevice *self);
+
+const gchar *health_device_create_channel(HealthDevice *self, const gchar *application, const gchar *configuration, GError **error);
+void health_device_destroy_channel(HealthDevice *self, const gchar *channel, GError **error);
+gboolean health_device_echo(HealthDevice *self, GError **error);
+
+GVariant *health_device_get_properties(HealthDevice *self, GError **error);
+void health_device_set_property(HealthDevice *self, const gchar *name, const GVariant *value, GError **error);
+
+const gchar *health_device_get_main_channel(HealthDevice *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __HEALTH_DEVICE_H */
+
diff --git a/src/lib/bluez/health_manager.c b/src/lib/bluez/health_manager.c
new file mode 100644
index 0000000..1e8f724
--- /dev/null
+++ b/src/lib/bluez/health_manager.c
@@ -0,0 +1,161 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "health_manager.h"
+
+#define HEALTH_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), HEALTH_MANAGER_TYPE, HealthManagerPrivate))
+
+struct _HealthManagerPrivate {
+ GDBusProxy *proxy;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(HealthManager, health_manager, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+};
+
+static void _health_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _health_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _health_manager_create_gdbus_proxy(HealthManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void health_manager_dispose(GObject *gobject)
+{
+ HealthManager *self = HEALTH_MANAGER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(health_manager_parent_class)->dispose(gobject);
+}
+
+static void health_manager_finalize (GObject *gobject)
+{
+ HealthManager *self = HEALTH_MANAGER(gobject);
+ G_OBJECT_CLASS(health_manager_parent_class)->finalize(gobject);
+}
+
+static void health_manager_class_init(HealthManagerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = health_manager_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _health_manager_get_property;
+ gobject_class->set_property = _health_manager_set_property;
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void health_manager_init(HealthManager *self)
+{
+ self->priv = health_manager_get_instance_private (self);
+ self->priv->proxy = NULL;
+ g_assert(system_conn != NULL);
+ GError *error = NULL;
+ _health_manager_create_gdbus_proxy(self, HEALTH_MANAGER_DBUS_SERVICE, HEALTH_MANAGER_DBUS_PATH, &error);
+ g_assert(error == NULL);
+}
+
+static void _health_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ HealthManager *self = HEALTH_MANAGER(object);
+
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _health_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ HealthManager *self = HEALTH_MANAGER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+
+ if (error != NULL)
+ g_critical("%s", error->message);
+
+ g_assert(error == NULL);
+}
+
+/* Constructor */
+HealthManager *health_manager_new()
+{
+ return g_object_new(HEALTH_MANAGER_TYPE, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _health_manager_create_gdbus_proxy(HealthManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(HEALTH_MANAGER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, HEALTH_MANAGER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* object CreateApplication(dict config) */
+const gchar *health_manager_create_application(HealthManager *self, const GVariant *config, GError **error)
+{
+ g_assert(HEALTH_MANAGER_IS(self));
+ const gchar *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "CreateApplication", g_variant_new ("(@a{sv})", config), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_get_string(proxy_ret, NULL);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* void DestroyApplication(object application) */
+void health_manager_destroy_application(HealthManager *self, const gchar *application, GError **error)
+{
+ g_assert(HEALTH_MANAGER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "DestroyApplication", g_variant_new ("(o)", application), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/health_manager.h b/src/lib/bluez/health_manager.h
new file mode 100644
index 0000000..867c707
--- /dev/null
+++ b/src/lib/bluez/health_manager.h
@@ -0,0 +1,81 @@
+/*
+ *
+ * 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 __HEALTH_MANAGER_H
+#define __HEALTH_MANAGER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define HEALTH_MANAGER_DBUS_SERVICE "org.bluez"
+#define HEALTH_MANAGER_DBUS_INTERFACE "org.bluez.HealthManager1"
+#define HEALTH_MANAGER_DBUS_PATH "/org/bluez/"
+
+/*
+ * Type macros
+ */
+#define HEALTH_MANAGER_TYPE (health_manager_get_type())
+#define HEALTH_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), HEALTH_MANAGER_TYPE, HealthManager))
+#define HEALTH_MANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), HEALTH_MANAGER_TYPE))
+#define HEALTH_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), HEALTH_MANAGER_TYPE, HealthManagerClass))
+#define HEALTH_MANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), HEALTH_MANAGER_TYPE))
+#define HEALTH_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), HEALTH_MANAGER_TYPE, HealthManagerClass))
+
+typedef struct _HealthManager HealthManager;
+typedef struct _HealthManagerClass HealthManagerClass;
+typedef struct _HealthManagerPrivate HealthManagerPrivate;
+
+struct _HealthManager {
+ GObject parent_instance;
+
+ /*< private >*/
+ HealthManagerPrivate *priv;
+};
+
+struct _HealthManagerClass {
+ GObjectClass parent_class;
+};
+
+/* used by HEALTH_MANAGER_TYPE */
+GType health_manager_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+HealthManager *health_manager_new();
+
+/*
+ * Method definitions
+ */
+const gchar *health_manager_create_application(HealthManager *self, const GVariant *config, GError **error);
+void health_manager_destroy_application(HealthManager *self, const gchar *application, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __HEALTH_MANAGER_H */
+
diff --git a/src/lib/bluez/heart_rate.c b/src/lib/bluez/heart_rate.c
new file mode 100644
index 0000000..a0bcb0f
--- /dev/null
+++ b/src/lib/bluez/heart_rate.c
@@ -0,0 +1,198 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "heart_rate.h"
+
+#define HEART_RATE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), HEART_RATE_TYPE, HeartRatePrivate))
+
+struct _HeartRatePrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(HeartRate, heart_rate, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _heart_rate_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _heart_rate_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _heart_rate_create_gdbus_proxy(HeartRate *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void heart_rate_dispose(GObject *gobject)
+{
+ HeartRate *self = HEART_RATE(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(heart_rate_parent_class)->dispose(gobject);
+}
+
+static void heart_rate_finalize (GObject *gobject)
+{
+ HeartRate *self = HEART_RATE(gobject);
+ G_OBJECT_CLASS(heart_rate_parent_class)->finalize(gobject);
+}
+
+static void heart_rate_class_init(HeartRateClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = heart_rate_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _heart_rate_get_property;
+ gobject_class->set_property = _heart_rate_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "HeartRate D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void heart_rate_init(HeartRate *self)
+{
+ self->priv = heart_rate_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _heart_rate_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ HeartRate *self = HEART_RATE(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, heart_rate_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _heart_rate_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ HeartRate *self = HEART_RATE(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _heart_rate_create_gdbus_proxy(self, HEART_RATE_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+HeartRate *heart_rate_new(const gchar *dbus_object_path)
+{
+ return g_object_new(HEART_RATE_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _heart_rate_create_gdbus_proxy(HeartRate *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(HEART_RATE_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, HEART_RATE_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *heart_rate_get_dbus_object_path(HeartRate *self)
+{
+ g_assert(HEART_RATE_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+
+
+/* Properties access methods */
+GVariant *heart_rate_get_properties(HeartRate *self, GError **error)
+{
+ g_assert(HEART_RATE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, HEART_RATE_DBUS_INTERFACE, error);
+}
+
+void heart_rate_set_property(HeartRate *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(HEART_RATE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, HEART_RATE_DBUS_INTERFACE, name, value, error);
+}
+
+gboolean heart_rate_get_reset_supported(HeartRate *self, GError **error)
+{
+ g_assert(HEART_RATE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, HEART_RATE_DBUS_INTERFACE, "ResetSupported", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/heart_rate.h b/src/lib/bluez/heart_rate.h
new file mode 100644
index 0000000..1d794ea
--- /dev/null
+++ b/src/lib/bluez/heart_rate.h
@@ -0,0 +1,84 @@
+/*
+ *
+ * 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 __HEART_RATE_H
+#define __HEART_RATE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define HEART_RATE_DBUS_SERVICE "org.bluez"
+#define HEART_RATE_DBUS_INTERFACE "org.bluez.HeartRate1"
+
+/*
+ * Type macros
+ */
+#define HEART_RATE_TYPE (heart_rate_get_type())
+#define HEART_RATE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), HEART_RATE_TYPE, HeartRate))
+#define HEART_RATE_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), HEART_RATE_TYPE))
+#define HEART_RATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), HEART_RATE_TYPE, HeartRateClass))
+#define HEART_RATE_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), HEART_RATE_TYPE))
+#define HEART_RATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), HEART_RATE_TYPE, HeartRateClass))
+
+typedef struct _HeartRate HeartRate;
+typedef struct _HeartRateClass HeartRateClass;
+typedef struct _HeartRatePrivate HeartRatePrivate;
+
+struct _HeartRate {
+ GObject parent_instance;
+
+ /*< private >*/
+ HeartRatePrivate *priv;
+};
+
+struct _HeartRateClass {
+ GObjectClass parent_class;
+};
+
+/* used by HEART_RATE_TYPE */
+GType heart_rate_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+HeartRate *heart_rate_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *heart_rate_get_dbus_object_path(HeartRate *self);
+
+GVariant *heart_rate_get_properties(HeartRate *self, GError **error);
+void heart_rate_set_property(HeartRate *self, const gchar *name, const GVariant *value, GError **error);
+
+gboolean heart_rate_get_reset_supported(HeartRate *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __HEART_RATE_H */
+
diff --git a/src/lib/bluez/heart_rate_manager.c b/src/lib/bluez/heart_rate_manager.c
new file mode 100644
index 0000000..e07bfb3
--- /dev/null
+++ b/src/lib/bluez/heart_rate_manager.c
@@ -0,0 +1,162 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "heart_rate_manager.h"
+
+#define HEART_RATE_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), HEART_RATE_MANAGER_TYPE, HeartRateManagerPrivate))
+
+struct _HeartRateManagerPrivate {
+ GDBusProxy *proxy;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(HeartRateManager, heart_rate_manager, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _heart_rate_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _heart_rate_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _heart_rate_manager_create_gdbus_proxy(HeartRateManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void heart_rate_manager_dispose(GObject *gobject)
+{
+ HeartRateManager *self = HEART_RATE_MANAGER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(heart_rate_manager_parent_class)->dispose(gobject);
+}
+
+static void heart_rate_manager_finalize (GObject *gobject)
+{
+ HeartRateManager *self = HEART_RATE_MANAGER(gobject);
+ G_OBJECT_CLASS(heart_rate_manager_parent_class)->finalize(gobject);
+}
+
+static void heart_rate_manager_class_init(HeartRateManagerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = heart_rate_manager_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _heart_rate_manager_get_property;
+ gobject_class->set_property = _heart_rate_manager_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "HeartRateManager D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void heart_rate_manager_init(HeartRateManager *self)
+{
+ self->priv = heart_rate_manager_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _heart_rate_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ HeartRateManager *self = HEART_RATE_MANAGER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, heart_rate_manager_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _heart_rate_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ HeartRateManager *self = HEART_RATE_MANAGER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _heart_rate_manager_create_gdbus_proxy(self, HEART_RATE_MANAGER_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+HeartRateManager *heart_rate_manager_new(const gchar *dbus_object_path)
+{
+ return g_object_new(HEART_RATE_MANAGER_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _heart_rate_manager_create_gdbus_proxy(HeartRateManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(HEART_RATE_MANAGER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, HEART_RATE_MANAGER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *heart_rate_manager_get_dbus_object_path(HeartRateManager *self)
+{
+ g_assert(HEART_RATE_MANAGER_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
diff --git a/src/lib/bluez/heart_rate_manager.h b/src/lib/bluez/heart_rate_manager.h
new file mode 100644
index 0000000..2d5f840
--- /dev/null
+++ b/src/lib/bluez/heart_rate_manager.h
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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 __HEART_RATE_MANAGER_H
+#define __HEART_RATE_MANAGER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define HEART_RATE_MANAGER_DBUS_SERVICE "org.bluez"
+#define HEART_RATE_MANAGER_DBUS_INTERFACE "org.bluez.HeartRateManager1"
+
+/*
+ * Type macros
+ */
+#define HEART_RATE_MANAGER_TYPE (heart_rate_manager_get_type())
+#define HEART_RATE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), HEART_RATE_MANAGER_TYPE, HeartRateManager))
+#define HEART_RATE_MANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), HEART_RATE_MANAGER_TYPE))
+#define HEART_RATE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), HEART_RATE_MANAGER_TYPE, HeartRateManagerClass))
+#define HEART_RATE_MANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), HEART_RATE_MANAGER_TYPE))
+#define HEART_RATE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), HEART_RATE_MANAGER_TYPE, HeartRateManagerClass))
+
+typedef struct _HeartRateManager HeartRateManager;
+typedef struct _HeartRateManagerClass HeartRateManagerClass;
+typedef struct _HeartRateManagerPrivate HeartRateManagerPrivate;
+
+struct _HeartRateManager {
+ GObject parent_instance;
+
+ /*< private >*/
+ HeartRateManagerPrivate *priv;
+};
+
+struct _HeartRateManagerClass {
+ GObjectClass parent_class;
+};
+
+/* used by HEART_RATE_MANAGER_TYPE */
+GType heart_rate_manager_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+HeartRateManager *heart_rate_manager_new(const gchar *dbus_object_path);
+const gchar *heart_rate_manager_get_dbus_object_path(HeartRateManager *self);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __HEART_RATE_MANAGER_H */
+
diff --git a/src/lib/bluez/input.c b/src/lib/bluez/input.c
deleted file mode 100644
index 0ed19b2..0000000
--- a/src/lib/bluez/input.c
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "input.h"
-
-#define INPUT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), INPUT_TYPE, InputPrivate))
-
-struct _InputPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-
- /* Properties */
- gboolean connected;
-};
-
-G_DEFINE_TYPE(Input, input, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
- PROP_CONNECTED /* readonly */
-};
-
-static void _input_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _input_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-enum {
- PROPERTY_CHANGED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data);
-
-static void input_dispose(GObject *gobject)
-{
- Input *self = INPUT(gobject);
-
- /* DBus signals disconnection */
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self);
-
- /* Properties free */
- /* none */
-
- /* 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(input_parent_class)->dispose(gobject);
-}
-
-static void input_class_init(InputClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = input_dispose;
-
- g_type_class_add_private(klass, sizeof(InputPrivate));
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _input_get_property;
- gobject_class->set_property = _input_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 Connected [readonly] */
- pspec = g_param_spec_boolean("Connected", NULL, NULL, FALSE, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_CONNECTED, pspec);
-
- /* Signals registation */
- signals[PROPERTY_CHANGED] = g_signal_new("PropertyChanged",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_bt_marshal_VOID__STRING_BOXED,
- G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE);
-}
-
-static void input_init(Input *self)
-{
- self->priv = INPUT_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(system_conn != NULL);
-}
-
-static void input_post_init(Input *self, const gchar *dbus_object_path)
-{
- 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(system_conn, "org.bluez", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", INPUT_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", INPUT_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, INPUT_DBUS_INTERFACE);
-
- /* DBus signals connection */
-
- /* PropertyChanged(string name, variant value) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self, NULL);
-
- /* Properties init */
- GHashTable *properties = input_get_properties(self, &error);
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
- g_assert(properties != NULL);
-
- /* boolean Connected [readonly] */
- if (g_hash_table_lookup(properties, "Connected")) {
- self->priv->connected = g_value_get_boolean(g_hash_table_lookup(properties, "Connected"));
- } else {
- self->priv->connected = FALSE;
- }
-
- g_hash_table_unref(properties);
-}
-
-static void _input_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- Input *self = INPUT(object);
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- g_value_set_string(value, input_get_dbus_object_path(self));
- break;
-
- case PROP_CONNECTED:
- g_value_set_boolean(value, input_get_connected(self));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _input_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- Input *self = INPUT(object);
- GError *error = NULL;
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- input_post_init(self, g_value_get_string(value));
- 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);
-}
-
-/* Methods */
-
-/* void Connect() */
-void input_connect(Input *self, GError **error)
-{
- g_assert(INPUT_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Connect", error, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void Disconnect() */
-void input_disconnect(Input *self, GError **error)
-{
- g_assert(INPUT_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Disconnect", error, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* dict GetProperties() */
-GHashTable *input_get_properties(Input *self, GError **error)
-{
- g_assert(INPUT_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;
-}
-
-/* Properties access methods */
-const gchar *input_get_dbus_object_path(Input *self)
-{
- g_assert(INPUT_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
-}
-
-const gboolean input_get_connected(Input *self)
-{
- g_assert(INPUT_IS(self));
-
- return self->priv->connected;
-}
-
-/* Signals handlers */
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data)
-{
- Input *self = INPUT(data);
-
- if (g_strcmp0(name, "Connected") == 0) {
- self->priv->connected = g_value_get_boolean(value);
- }
-
- g_signal_emit(self, signals[PROPERTY_CHANGED], 0, name, value);
-}
-
diff --git a/src/lib/bluez/input.h b/src/lib/bluez/input.h
deleted file mode 100644
index 7bf2b86..0000000
--- a/src/lib/bluez/input.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *
- * 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 __INPUT_H
-#define __INPUT_H
-
-#include <glib-object.h>
-
-#define INPUT_DBUS_INTERFACE "org.bluez.Input"
-
-/*
- * Type macros
- */
-#define INPUT_TYPE (input_get_type())
-#define INPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), INPUT_TYPE, Input))
-#define INPUT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), INPUT_TYPE))
-#define INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), INPUT_TYPE, InputClass))
-#define INPUT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), INPUT_TYPE))
-#define INPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), INPUT_TYPE, InputClass))
-
-typedef struct _Input Input;
-typedef struct _InputClass InputClass;
-typedef struct _InputPrivate InputPrivate;
-
-struct _Input {
- GObject parent_instance;
-
- /*< private >*/
- InputPrivate *priv;
-};
-
-struct _InputClass {
- GObjectClass parent_class;
-};
-
-/* used by INPUT_TYPE */
-GType input_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-void input_connect(Input *self, GError **error);
-void input_disconnect(Input *self, GError **error);
-GHashTable *input_get_properties(Input *self, GError **error);
-
-const gchar *input_get_dbus_object_path(Input *self);
-const gboolean input_get_connected(Input *self);
-
-#endif /* __INPUT_H */
-
diff --git a/src/lib/bluez/manager.c b/src/lib/bluez/manager.c
deleted file mode 100644
index 53cc597..0000000
--- a/src/lib/bluez/manager.c
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "manager.h"
-
-#define MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), MANAGER_TYPE, ManagerPrivate))
-
-struct _ManagerPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-
- /* Properties */
- GPtrArray *adapters;
-};
-
-G_DEFINE_TYPE(Manager, manager, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_ADAPTERS /* readonly */
-};
-
-static void _manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-enum {
- ADAPTER_ADDED,
- ADAPTER_REMOVED,
- DEFAULT_ADAPTER_CHANGED,
- PROPERTY_CHANGED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void adapter_added_handler(DBusGProxy *dbus_g_proxy, const gchar *adapter, gpointer data);
-static void adapter_removed_handler(DBusGProxy *dbus_g_proxy, const gchar *adapter, gpointer data);
-static void default_adapter_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *adapter, gpointer data);
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data);
-
-static void manager_dispose(GObject *gobject)
-{
- Manager *self = MANAGER(gobject);
-
- /* DBus signals disconnection */
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "AdapterAdded", G_CALLBACK(adapter_added_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "AdapterRemoved", G_CALLBACK(adapter_removed_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "DefaultAdapterChanged", G_CALLBACK(default_adapter_changed_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self);
-
- /* Properties free */
- g_ptr_array_unref(self->priv->adapters);
-
- /* 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(manager_parent_class)->dispose(gobject);
-}
-
-static void manager_class_init(ManagerClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = manager_dispose;
-
- g_type_class_add_private(klass, sizeof(ManagerPrivate));
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _manager_get_property;
- gobject_class->set_property = _manager_set_property;
-
- /* array{object} Adapters [readonly] */
- pspec = g_param_spec_boxed("Adapters", NULL, NULL, G_TYPE_PTR_ARRAY, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_ADAPTERS, pspec);
-
- /* Signals registation */
- signals[ADAPTER_ADDED] = g_signal_new("AdapterAdded",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[ADAPTER_REMOVED] = g_signal_new("AdapterRemoved",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[DEFAULT_ADAPTER_CHANGED] = g_signal_new("DefaultAdapterChanged",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[PROPERTY_CHANGED] = g_signal_new("PropertyChanged",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_bt_marshal_VOID__STRING_BOXED,
- G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE);
-}
-
-static void manager_init(Manager *self)
-{
- self->priv = MANAGER_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(system_conn != NULL);
-
- GError *error = NULL;
-
- /* Getting introspection XML */
- self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", MANAGER_DBUS_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 *check_intf_regex_str = g_strconcat("<interface name=\"", MANAGER_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", MANAGER_DBUS_INTERFACE, MANAGER_DBUS_PATH);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
-
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE);
-
- /* DBus signals connection */
-
- /* AdapterAdded(object adapter) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "AdapterAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "AdapterAdded", G_CALLBACK(adapter_added_handler), self, NULL);
-
- /* AdapterRemoved(object adapter) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "AdapterRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "AdapterRemoved", G_CALLBACK(adapter_removed_handler), self, NULL);
-
- /* DefaultAdapterChanged(object adapter) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "DefaultAdapterChanged", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "DefaultAdapterChanged", G_CALLBACK(default_adapter_changed_handler), self, NULL);
-
- /* PropertyChanged(string name, variant value) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self, NULL);
-
- /* Properties init */
- GHashTable *properties = manager_get_properties(self, &error);
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
- g_assert(properties != NULL);
-
- /* array{object} Adapters [readonly] */
- if (g_hash_table_lookup(properties, "Adapters")) {
- self->priv->adapters = g_value_dup_boxed(g_hash_table_lookup(properties, "Adapters"));
- } else {
- self->priv->adapters = g_ptr_array_new();
- }
-
- g_hash_table_unref(properties);
-}
-
-static void _manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- Manager *self = MANAGER(object);
-
- switch (property_id) {
- case PROP_ADAPTERS:
- g_value_set_boxed(value, manager_get_adapters(self));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- Manager *self = MANAGER(object);
- GError *error = NULL;
-
- switch (property_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
-}
-
-/* Methods */
-
-/* object DefaultAdapter() */
-gchar *manager_default_adapter(Manager *self, GError **error)
-{
- g_assert(MANAGER_IS(self));
-
- gchar *ret = NULL;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "DefaultAdapter", error, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &ret, G_TYPE_INVALID);
-
- return ret;
-}
-
-/* object FindAdapter(string pattern) */
-gchar *manager_find_adapter(Manager *self, const gchar *pattern, GError **error)
-{
- g_assert(MANAGER_IS(self));
-
- gchar *ret = NULL;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "FindAdapter", error, G_TYPE_STRING, pattern, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &ret, G_TYPE_INVALID);
-
- return ret;
-}
-
-/* dict GetProperties() */
-GHashTable *manager_get_properties(Manager *self, GError **error)
-{
- g_assert(MANAGER_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;
-}
-
-/* Properties access methods */
-const GPtrArray *manager_get_adapters(Manager *self)
-{
- g_assert(MANAGER_IS(self));
-
- return self->priv->adapters;
-}
-
-/* Signals handlers */
-static void adapter_added_handler(DBusGProxy *dbus_g_proxy, const gchar *adapter, gpointer data)
-{
- Manager *self = MANAGER(data);
-
- g_signal_emit(self, signals[ADAPTER_ADDED], 0, adapter);
-}
-
-static void adapter_removed_handler(DBusGProxy *dbus_g_proxy, const gchar *adapter, gpointer data)
-{
- Manager *self = MANAGER(data);
-
- g_signal_emit(self, signals[ADAPTER_REMOVED], 0, adapter);
-}
-
-static void default_adapter_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *adapter, gpointer data)
-{
- Manager *self = MANAGER(data);
-
- g_signal_emit(self, signals[DEFAULT_ADAPTER_CHANGED], 0, adapter);
-}
-
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data)
-{
- Manager *self = MANAGER(data);
-
- if (g_strcmp0(name, "Adapters") == 0) {
- g_ptr_array_unref(self->priv->adapters);
- self->priv->adapters = g_value_dup_boxed(value);
- }
-
- g_signal_emit(self, signals[PROPERTY_CHANGED], 0, name, value);
-}
-
diff --git a/src/lib/bluez/manager.h b/src/lib/bluez/manager.h
deleted file mode 100644
index 66ab2b6..0000000
--- a/src/lib/bluez/manager.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *
- * 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 __MANAGER_H
-#define __MANAGER_H
-
-#include <glib-object.h>
-
-#define MANAGER_DBUS_PATH "/"
-#define MANAGER_DBUS_INTERFACE "org.bluez.Manager"
-
-/*
- * Type macros
- */
-#define MANAGER_TYPE (manager_get_type())
-#define MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MANAGER_TYPE, Manager))
-#define MANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MANAGER_TYPE))
-#define MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), MANAGER_TYPE, ManagerClass))
-#define MANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MANAGER_TYPE))
-#define MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MANAGER_TYPE, ManagerClass))
-
-typedef struct _Manager Manager;
-typedef struct _ManagerClass ManagerClass;
-typedef struct _ManagerPrivate ManagerPrivate;
-
-struct _Manager {
- GObject parent_instance;
-
- /*< private >*/
- ManagerPrivate *priv;
-};
-
-struct _ManagerClass {
- GObjectClass parent_class;
-};
-
-/* used by MANAGER_TYPE */
-GType manager_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-gchar *manager_default_adapter(Manager *self, GError **error);
-gchar *manager_find_adapter(Manager *self, const gchar *pattern, GError **error);
-GHashTable *manager_get_properties(Manager *self, GError **error);
-
-const GPtrArray *manager_get_adapters(Manager *self);
-
-#endif /* __MANAGER_H */
-
diff --git a/src/lib/bluez/media.c b/src/lib/bluez/media.c
new file mode 100644
index 0000000..befcae7
--- /dev/null
+++ b/src/lib/bluez/media.c
@@ -0,0 +1,190 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "media.h"
+
+#define MEDIA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), MEDIA_TYPE, MediaPrivate))
+
+struct _MediaPrivate {
+ GDBusProxy *proxy;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(Media, media, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _media_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _media_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _media_create_gdbus_proxy(Media *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void media_dispose(GObject *gobject)
+{
+ Media *self = MEDIA(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(media_parent_class)->dispose(gobject);
+}
+
+static void media_finalize (GObject *gobject)
+{
+ Media *self = MEDIA(gobject);
+ G_OBJECT_CLASS(media_parent_class)->finalize(gobject);
+}
+
+static void media_class_init(MediaClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = media_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _media_get_property;
+ gobject_class->set_property = _media_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Media D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void media_init(Media *self)
+{
+ self->priv = media_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _media_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ Media *self = MEDIA(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, media_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _media_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ Media *self = MEDIA(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _media_create_gdbus_proxy(self, MEDIA_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+Media *media_new(const gchar *dbus_object_path)
+{
+ return g_object_new(MEDIA_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _media_create_gdbus_proxy(Media *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(MEDIA_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, MEDIA_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *media_get_dbus_object_path(Media *self)
+{
+ g_assert(MEDIA_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* void RegisterEndpoint(object endpoint, dict properties) */
+void media_register_endpoint(Media *self, const gchar *endpoint, const GVariant *properties, GError **error)
+{
+ g_assert(MEDIA_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "RegisterEndpoint", g_variant_new ("(o@a{sv})", endpoint, properties), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void RegisterPlayer(object player, dict properties) */
+void media_register_player(Media *self, const gchar *player, const GVariant *properties, GError **error)
+{
+ g_assert(MEDIA_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "RegisterPlayer", g_variant_new ("(o@a{sv})", player, properties), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void UnregisterEndpoint(object endpoint) */
+void media_unregister_endpoint(Media *self, const gchar *endpoint, GError **error)
+{
+ g_assert(MEDIA_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "UnregisterEndpoint", g_variant_new ("(o)", endpoint), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void UnregisterPlayer(object player) */
+void media_unregister_player(Media *self, const gchar *player, GError **error)
+{
+ g_assert(MEDIA_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "UnregisterPlayer", g_variant_new ("(o)", player), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/media.h b/src/lib/bluez/media.h
new file mode 100644
index 0000000..ad508e2
--- /dev/null
+++ b/src/lib/bluez/media.h
@@ -0,0 +1,84 @@
+/*
+ *
+ * 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 __MEDIA_H
+#define __MEDIA_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define MEDIA_DBUS_SERVICE "org.bluez"
+#define MEDIA_DBUS_INTERFACE "org.bluez.Media1"
+
+/*
+ * Type macros
+ */
+#define MEDIA_TYPE (media_get_type())
+#define MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MEDIA_TYPE, Media))
+#define MEDIA_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MEDIA_TYPE))
+#define MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), MEDIA_TYPE, MediaClass))
+#define MEDIA_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MEDIA_TYPE))
+#define MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MEDIA_TYPE, MediaClass))
+
+typedef struct _Media Media;
+typedef struct _MediaClass MediaClass;
+typedef struct _MediaPrivate MediaPrivate;
+
+struct _Media {
+ GObject parent_instance;
+
+ /*< private >*/
+ MediaPrivate *priv;
+};
+
+struct _MediaClass {
+ GObjectClass parent_class;
+};
+
+/* used by MEDIA_TYPE */
+GType media_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+Media *media_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *media_get_dbus_object_path(Media *self);
+
+void media_register_endpoint(Media *self, const gchar *endpoint, const GVariant *properties, GError **error);
+void media_register_player(Media *self, const gchar *player, const GVariant *properties, GError **error);
+void media_unregister_endpoint(Media *self, const gchar *endpoint, GError **error);
+void media_unregister_player(Media *self, const gchar *player, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MEDIA_H */
+
diff --git a/src/lib/bluez/media_control.c b/src/lib/bluez/media_control.c
new file mode 100644
index 0000000..5d3913f
--- /dev/null
+++ b/src/lib/bluez/media_control.c
@@ -0,0 +1,259 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "media_control.h"
+
+#define MEDIA_CONTROL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), MEDIA_CONTROL_TYPE, MediaControlPrivate))
+
+struct _MediaControlPrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(MediaControl, media_control, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _media_control_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _media_control_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _media_control_create_gdbus_proxy(MediaControl *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void media_control_dispose(GObject *gobject)
+{
+ MediaControl *self = MEDIA_CONTROL(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(media_control_parent_class)->dispose(gobject);
+}
+
+static void media_control_finalize (GObject *gobject)
+{
+ MediaControl *self = MEDIA_CONTROL(gobject);
+ G_OBJECT_CLASS(media_control_parent_class)->finalize(gobject);
+}
+
+static void media_control_class_init(MediaControlClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = media_control_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _media_control_get_property;
+ gobject_class->set_property = _media_control_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "MediaControl D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void media_control_init(MediaControl *self)
+{
+ self->priv = media_control_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _media_control_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ MediaControl *self = MEDIA_CONTROL(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, media_control_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _media_control_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ MediaControl *self = MEDIA_CONTROL(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _media_control_create_gdbus_proxy(self, MEDIA_CONTROL_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+MediaControl *media_control_new(const gchar *dbus_object_path)
+{
+ return g_object_new(MEDIA_CONTROL_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _media_control_create_gdbus_proxy(MediaControl *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, MEDIA_CONTROL_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *media_control_get_dbus_object_path(MediaControl *self)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* void FastForward() */
+void media_control_fast_forward(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "FastForward", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Next() */
+void media_control_next(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Next", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Pause() */
+void media_control_pause(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Pause", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Play() */
+void media_control_play(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Play", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Previous() */
+void media_control_previous(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Previous", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Rewind() */
+void media_control_rewind(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Rewind", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Stop() */
+void media_control_stop(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Stop", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void VolumeDown() */
+void media_control_volume_down(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "VolumeDown", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void VolumeUp() */
+void media_control_volume_up(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "VolumeUp", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* Properties access methods */
+GVariant *media_control_get_properties(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, MEDIA_CONTROL_DBUS_INTERFACE, error);
+}
+
+void media_control_set_property(MediaControl *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, MEDIA_CONTROL_DBUS_INTERFACE, name, value, error);
+}
+
+gboolean media_control_get_connected(MediaControl *self, GError **error)
+{
+ g_assert(MEDIA_CONTROL_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_CONTROL_DBUS_INTERFACE, "Connected", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/media_control.h b/src/lib/bluez/media_control.h
new file mode 100644
index 0000000..bfc58a6
--- /dev/null
+++ b/src/lib/bluez/media_control.h
@@ -0,0 +1,94 @@
+/*
+ *
+ * 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 __MEDIA_CONTROL_H
+#define __MEDIA_CONTROL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define MEDIA_CONTROL_DBUS_SERVICE "org.bluez"
+#define MEDIA_CONTROL_DBUS_INTERFACE "org.bluez.MediaControl1"
+
+/*
+ * Type macros
+ */
+#define MEDIA_CONTROL_TYPE (media_control_get_type())
+#define MEDIA_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MEDIA_CONTROL_TYPE, MediaControl))
+#define MEDIA_CONTROL_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MEDIA_CONTROL_TYPE))
+#define MEDIA_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), MEDIA_CONTROL_TYPE, MediaControlClass))
+#define MEDIA_CONTROL_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MEDIA_CONTROL_TYPE))
+#define MEDIA_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MEDIA_CONTROL_TYPE, MediaControlClass))
+
+typedef struct _MediaControl MediaControl;
+typedef struct _MediaControlClass MediaControlClass;
+typedef struct _MediaControlPrivate MediaControlPrivate;
+
+struct _MediaControl {
+ GObject parent_instance;
+
+ /*< private >*/
+ MediaControlPrivate *priv;
+};
+
+struct _MediaControlClass {
+ GObjectClass parent_class;
+};
+
+/* used by MEDIA_CONTROL_TYPE */
+GType media_control_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+MediaControl *media_control_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *media_control_get_dbus_object_path(MediaControl *self);
+
+void media_control_fast_forward(MediaControl *self, GError **error);
+void media_control_next(MediaControl *self, GError **error);
+void media_control_pause(MediaControl *self, GError **error);
+void media_control_play(MediaControl *self, GError **error);
+void media_control_previous(MediaControl *self, GError **error);
+void media_control_rewind(MediaControl *self, GError **error);
+void media_control_stop(MediaControl *self, GError **error);
+void media_control_volume_down(MediaControl *self, GError **error);
+void media_control_volume_up(MediaControl *self, GError **error);
+
+GVariant *media_control_get_properties(MediaControl *self, GError **error);
+void media_control_set_property(MediaControl *self, const gchar *name, const GVariant *value, GError **error);
+
+gboolean media_control_get_connected(MediaControl *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MEDIA_CONTROL_H */
+
diff --git a/src/lib/bluez/media_player.c b/src/lib/bluez/media_player.c
new file mode 100644
index 0000000..ff9141a
--- /dev/null
+++ b/src/lib/bluez/media_player.c
@@ -0,0 +1,417 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "media_player.h"
+
+#define MEDIA_PLAYER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), MEDIA_PLAYER_TYPE, MediaPlayerPrivate))
+
+struct _MediaPlayerPrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(MediaPlayer, media_player, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _media_player_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _media_player_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _media_player_create_gdbus_proxy(MediaPlayer *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void media_player_dispose(GObject *gobject)
+{
+ MediaPlayer *self = MEDIA_PLAYER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(media_player_parent_class)->dispose(gobject);
+}
+
+static void media_player_finalize (GObject *gobject)
+{
+ MediaPlayer *self = MEDIA_PLAYER(gobject);
+ G_OBJECT_CLASS(media_player_parent_class)->finalize(gobject);
+}
+
+static void media_player_class_init(MediaPlayerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = media_player_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _media_player_get_property;
+ gobject_class->set_property = _media_player_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "MediaPlayer D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void media_player_init(MediaPlayer *self)
+{
+ self->priv = media_player_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _media_player_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ MediaPlayer *self = MEDIA_PLAYER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, media_player_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _media_player_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ MediaPlayer *self = MEDIA_PLAYER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _media_player_create_gdbus_proxy(self, MEDIA_PLAYER_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+MediaPlayer *media_player_new(const gchar *dbus_object_path)
+{
+ return g_object_new(MEDIA_PLAYER_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _media_player_create_gdbus_proxy(MediaPlayer *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, MEDIA_PLAYER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *media_player_get_dbus_object_path(MediaPlayer *self)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* void FastForward() */
+void media_player_fast_forward(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "FastForward", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Next() */
+void media_player_next(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Next", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Pause() */
+void media_player_pause(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Pause", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Play() */
+void media_player_play(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Play", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Previous() */
+void media_player_previous(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Previous", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Rewind() */
+void media_player_rewind(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Rewind", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Stop() */
+void media_player_stop(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Stop", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* Properties access methods */
+GVariant *media_player_get_properties(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, error);
+}
+
+void media_player_set_property(MediaPlayer *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, name, value, error);
+}
+
+gboolean media_player_get_browsable(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Browsable", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *media_player_get_device(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Device", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *media_player_get_equalizer(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Equalizer", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+void media_player_set_equalizer(MediaPlayer *self, const gchar *value, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Equalizer", g_variant_new_string(value), error);
+}
+
+const gchar *media_player_get_name(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Name", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+guint32 media_player_get_position(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Position", error);
+ if(prop == NULL)
+ return 0;
+ guint32 ret = g_variant_get_uint32(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *media_player_get_repeat(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Repeat", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+void media_player_set_repeat(MediaPlayer *self, const gchar *value, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Repeat", g_variant_new_string(value), error);
+}
+
+const gchar *media_player_get_scan(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Scan", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+void media_player_set_scan(MediaPlayer *self, const gchar *value, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Scan", g_variant_new_string(value), error);
+}
+
+gboolean media_player_get_searchable(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Searchable", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *media_player_get_shuffle(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Shuffle", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+void media_player_set_shuffle(MediaPlayer *self, const gchar *value, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Shuffle", g_variant_new_string(value), error);
+}
+
+const gchar *media_player_get_status(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Status", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *media_player_get_subtype(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Subtype", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+GVariant *media_player_get_track(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Track", error);
+ if(prop == NULL)
+ return NULL;
+ GVariant *ret = g_variant_ref_sink(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *media_player_get_player_type(MediaPlayer *self, GError **error)
+{
+ g_assert(MEDIA_PLAYER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, MEDIA_PLAYER_DBUS_INTERFACE, "Type", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/media_player.h b/src/lib/bluez/media_player.h
new file mode 100644
index 0000000..d0a8017
--- /dev/null
+++ b/src/lib/bluez/media_player.h
@@ -0,0 +1,109 @@
+/*
+ *
+ * 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 __MEDIA_PLAYER_H
+#define __MEDIA_PLAYER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define MEDIA_PLAYER_DBUS_SERVICE "org.bluez"
+#define MEDIA_PLAYER_DBUS_INTERFACE "org.bluez.MediaPlayer1"
+
+/*
+ * Type macros
+ */
+#define MEDIA_PLAYER_TYPE (media_player_get_type())
+#define MEDIA_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MEDIA_PLAYER_TYPE, MediaPlayer))
+#define MEDIA_PLAYER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MEDIA_PLAYER_TYPE))
+#define MEDIA_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), MEDIA_PLAYER_TYPE, MediaPlayerClass))
+#define MEDIA_PLAYER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MEDIA_PLAYER_TYPE))
+#define MEDIA_PLAYER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MEDIA_PLAYER_TYPE, MediaPlayerClass))
+
+typedef struct _MediaPlayer MediaPlayer;
+typedef struct _MediaPlayerClass MediaPlayerClass;
+typedef struct _MediaPlayerPrivate MediaPlayerPrivate;
+
+struct _MediaPlayer {
+ GObject parent_instance;
+
+ /*< private >*/
+ MediaPlayerPrivate *priv;
+};
+
+struct _MediaPlayerClass {
+ GObjectClass parent_class;
+};
+
+/* used by MEDIA_PLAYER_TYPE */
+GType media_player_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+MediaPlayer *media_player_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *media_player_get_dbus_object_path(MediaPlayer *self);
+
+void media_player_fast_forward(MediaPlayer *self, GError **error);
+void media_player_next(MediaPlayer *self, GError **error);
+void media_player_pause(MediaPlayer *self, GError **error);
+void media_player_play(MediaPlayer *self, GError **error);
+void media_player_previous(MediaPlayer *self, GError **error);
+void media_player_rewind(MediaPlayer *self, GError **error);
+void media_player_stop(MediaPlayer *self, GError **error);
+
+GVariant *media_player_get_properties(MediaPlayer *self, GError **error);
+void media_player_set_property(MediaPlayer *self, const gchar *name, const GVariant *value, GError **error);
+
+gboolean media_player_get_browsable(MediaPlayer *self, GError **error);
+const gchar *media_player_get_device(MediaPlayer *self, GError **error);
+const gchar *media_player_get_equalizer(MediaPlayer *self, GError **error);
+void media_player_set_equalizer(MediaPlayer *self, const gchar *value, GError **error);
+const gchar *media_player_get_name(MediaPlayer *self, GError **error);
+guint32 media_player_get_position(MediaPlayer *self, GError **error);
+const gchar *media_player_get_repeat(MediaPlayer *self, GError **error);
+void media_player_set_repeat(MediaPlayer *self, const gchar *value, GError **error);
+const gchar *media_player_get_scan(MediaPlayer *self, GError **error);
+void media_player_set_scan(MediaPlayer *self, const gchar *value, GError **error);
+gboolean media_player_get_searchable(MediaPlayer *self, GError **error);
+const gchar *media_player_get_shuffle(MediaPlayer *self, GError **error);
+void media_player_set_shuffle(MediaPlayer *self, const gchar *value, GError **error);
+const gchar *media_player_get_status(MediaPlayer *self, GError **error);
+const gchar *media_player_get_subtype(MediaPlayer *self, GError **error);
+GVariant *media_player_get_track(MediaPlayer *self, GError **error);
+// This has been renamed because 'media_player_get_type' is already used by GLib
+const gchar *media_player_get_player_type(MediaPlayer *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MEDIA_PLAYER_H */
+
diff --git a/src/lib/bluez/network.c b/src/lib/bluez/network.c
index 411bc0e..02a33fb 100644
--- a/src/lib/bluez/network.c
+++ b/src/lib/bluez/network.c
@@ -24,189 +24,83 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
-
-#include <string.h>
-
+#include <gio/gio.h>
#include <glib.h>
-#include <dbus/dbus-glib.h>
+#include <string.h>
#include "../dbus-common.h"
-#include "../marshallers.h"
+#include "../properties.h"
#include "network.h"
#define NETWORK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), NETWORK_TYPE, NetworkPrivate))
struct _NetworkPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-
- /* Properties */
- gboolean connected;
- gchar *interface;
- gchar *uuid;
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
};
-G_DEFINE_TYPE(Network, network, G_TYPE_OBJECT);
+G_DEFINE_TYPE_WITH_PRIVATE(Network, network, G_TYPE_OBJECT);
enum {
PROP_0,
-
- PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
- PROP_CONNECTED, /* readonly */
- PROP_INTERFACE, /* readonly */
- PROP_UUID /* readonly */
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
};
static void _network_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void _network_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-enum {
- PROPERTY_CHANGED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data);
+static void _network_create_gdbus_proxy(Network *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
static void network_dispose(GObject *gobject)
{
Network *self = NETWORK(gobject);
- /* DBus signals disconnection */
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self);
-
- /* Properties free */
- g_free(self->priv->interface);
- g_free(self->priv->uuid);
-
/* 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);
-
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
/* Chain up to the parent class */
G_OBJECT_CLASS(network_parent_class)->dispose(gobject);
}
+static void network_finalize (GObject *gobject)
+{
+ Network *self = NETWORK(gobject);
+ G_OBJECT_CLASS(network_parent_class)->finalize(gobject);
+}
+
static void network_class_init(NetworkClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = network_dispose;
- g_type_class_add_private(klass, sizeof(NetworkPrivate));
-
/* Properties registration */
- GParamSpec *pspec;
+ GParamSpec *pspec = NULL;
gobject_class->get_property = _network_get_property;
gobject_class->set_property = _network_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);
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Network 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 Connected [readonly] */
- pspec = g_param_spec_boolean("Connected", NULL, NULL, FALSE, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_CONNECTED, pspec);
-
- /* string Interface [readonly] */
- pspec = g_param_spec_string("Interface", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_INTERFACE, 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);
-
- /* Signals registation */
- signals[PROPERTY_CHANGED] = g_signal_new("PropertyChanged",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_bt_marshal_VOID__STRING_BOXED,
- G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE);
+ if (pspec)
+ g_param_spec_unref(pspec);
}
static void network_init(Network *self)
{
- self->priv = NETWORK_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
+ self->priv = network_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
g_assert(system_conn != NULL);
}
-static void network_post_init(Network *self, const gchar *dbus_object_path)
-{
- 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(system_conn, "org.bluez", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", NETWORK_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", NETWORK_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, NETWORK_DBUS_INTERFACE);
-
- /* DBus signals connection */
-
- /* PropertyChanged(string name, variant value) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self, NULL);
-
- /* Properties init */
- GHashTable *properties = network_get_properties(self, &error);
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
- g_assert(properties != NULL);
-
- /* boolean Connected [readonly] */
- if (g_hash_table_lookup(properties, "Connected")) {
- self->priv->connected = g_value_get_boolean(g_hash_table_lookup(properties, "Connected"));
- } else {
- self->priv->connected = FALSE;
- }
-
- /* string Interface [readonly] */
- if (g_hash_table_lookup(properties, "Interface")) {
- self->priv->interface = g_value_dup_string(g_hash_table_lookup(properties, "Interface"));
- } else {
- self->priv->interface = 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 _network_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
Network *self = NETWORK(object);
@@ -216,18 +110,6 @@ static void _network_get_property(GObject *object, guint property_id, GValue *va
g_value_set_string(value, network_get_dbus_object_path(self));
break;
- case PROP_CONNECTED:
- g_value_set_boolean(value, network_get_connected(self));
- break;
-
- case PROP_INTERFACE:
- g_value_set_string(value, network_get_interface(self));
- break;
-
- case PROP_UUID:
- g_value_set_string(value, network_get_uuid(self));
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
@@ -241,7 +123,8 @@ static void _network_set_property(GObject *object, guint property_id, const GVal
switch (property_id) {
case PROP_DBUS_OBJECT_PATH:
- network_post_init(self, g_value_get_string(value));
+ self->priv->object_path = g_value_dup_string(value);
+ _network_create_gdbus_proxy(self, NETWORK_DBUS_SERVICE, self->priv->object_path, &error);
break;
default:
@@ -249,88 +132,110 @@ static void _network_set_property(GObject *object, guint property_id, const GVal
break;
}
- if (error != NULL) {
+ if (error != NULL)
g_critical("%s", error->message);
- }
+
g_assert(error == NULL);
}
-/* Methods */
+/* Constructor */
+Network *network_new(const gchar *dbus_object_path)
+{
+ return g_object_new(NETWORK_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
-/* string Connect(string uuid) */
-gchar *network_connect(Network *self, const gchar *uuid, GError **error)
+/* Private DBus proxy creation */
+static void _network_create_gdbus_proxy(Network *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
{
g_assert(NETWORK_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, NETWORK_DBUS_INTERFACE, NULL, error);
- gchar *ret = NULL;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Connect", error, G_TYPE_STRING, uuid, G_TYPE_INVALID, G_TYPE_STRING, &ret, G_TYPE_INVALID);
+ if(self->priv->proxy == NULL)
+ return;
- return ret;
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
}
-/* void Disconnect() */
-void network_disconnect(Network *self, GError **error)
+/* Methods */
+
+/* Get DBus object path */
+const gchar *network_get_dbus_object_path(Network *self)
{
g_assert(NETWORK_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Disconnect", error, G_TYPE_INVALID, G_TYPE_INVALID);
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
}
-/* dict GetProperties() */
-GHashTable *network_get_properties(Network *self, GError **error)
+/* string Connect(string uuid) */
+const gchar *network_connect(Network *self, const gchar *uuid, GError **error)
{
g_assert(NETWORK_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);
-
+ const gchar *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "Connect", g_variant_new ("(s)", uuid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_get_string(proxy_ret, NULL);
+ g_variant_unref(proxy_ret);
return ret;
}
-/* Properties access methods */
-const gchar *network_get_dbus_object_path(Network *self)
+/* void Disconnect() */
+void network_disconnect(Network *self, GError **error)
{
g_assert(NETWORK_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
+ g_dbus_proxy_call_sync(self->priv->proxy, "Disconnect", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
}
-const gboolean network_get_connected(Network *self)
+/* Properties access methods */
+GVariant *network_get_properties(Network *self, GError **error)
{
g_assert(NETWORK_IS(self));
-
- return self->priv->connected;
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, NETWORK_DBUS_INTERFACE, error);
}
-const gchar *network_get_interface(Network *self)
+void network_set_property(Network *self, const gchar *name, const GVariant *value, GError **error)
{
g_assert(NETWORK_IS(self));
-
- return self->priv->interface;
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, NETWORK_DBUS_INTERFACE, name, value, error);
}
-const gchar *network_get_uuid(Network *self)
+gboolean network_get_connected(Network *self, GError **error)
{
g_assert(NETWORK_IS(self));
-
- return self->priv->uuid;
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, NETWORK_DBUS_INTERFACE, "Connected", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
}
-/* Signals handlers */
-static void property_changed_handler(DBusGProxy *dbus_g_proxy, const gchar *name, const GValue *value, gpointer data)
+const gchar *network_get_interface(Network *self, GError **error)
{
- Network *self = NETWORK(data);
-
- if (g_strcmp0(name, "Connected") == 0) {
- self->priv->connected = g_value_get_boolean(value);
- } else if (g_strcmp0(name, "Interface") == 0) {
- g_free(self->priv->interface);
- self->priv->interface = g_value_dup_string(value);
- } else if (g_strcmp0(name, "UUID") == 0) {
- g_free(self->priv->uuid);
- self->priv->uuid = g_value_dup_string(value);
- }
+ g_assert(NETWORK_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, NETWORK_DBUS_INTERFACE, "Interface", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
- g_signal_emit(self, signals[PROPERTY_CHANGED], 0, name, value);
+const gchar *network_get_uuid(Network *self, GError **error)
+{
+ g_assert(NETWORK_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, NETWORK_DBUS_INTERFACE, "UUID", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
}
diff --git a/src/lib/bluez/network.h b/src/lib/bluez/network.h
index ddeee5b..b8f597e 100644
--- a/src/lib/bluez/network.h
+++ b/src/lib/bluez/network.h
@@ -24,9 +24,14 @@
#ifndef __NETWORK_H
#define __NETWORK_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <glib-object.h>
-#define NETWORK_DBUS_INTERFACE "org.bluez.Network"
+#define NETWORK_DBUS_SERVICE "org.bluez"
+#define NETWORK_DBUS_INTERFACE "org.bluez.Network1"
/*
* Type macros
@@ -57,16 +62,28 @@ struct _NetworkClass {
GType network_get_type(void) G_GNUC_CONST;
/*
+ * Constructor
+ */
+Network *network_new(const gchar *dbus_object_path);
+
+/*
* Method definitions
*/
-gchar *network_connect(Network *self, const gchar *uuid, GError **error);
+const gchar *network_get_dbus_object_path(Network *self);
+
+const gchar *network_connect(Network *self, const gchar *uuid, GError **error);
void network_disconnect(Network *self, GError **error);
-GHashTable *network_get_properties(Network *self, GError **error);
-const gchar *network_get_dbus_object_path(Network *self);
-const gboolean network_get_connected(Network *self);
-const gchar *network_get_interface(Network *self);
-const gchar *network_get_uuid(Network *self);
+GVariant *network_get_properties(Network *self, GError **error);
+void network_set_property(Network *self, const gchar *name, const GVariant *value, GError **error);
+
+gboolean network_get_connected(Network *self, GError **error);
+const gchar *network_get_interface(Network *self, GError **error);
+const gchar *network_get_uuid(Network *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
#endif /* __NETWORK_H */
diff --git a/src/lib/bluez/network_server.c b/src/lib/bluez/network_server.c
index 3acf614..7affa42 100644
--- a/src/lib/bluez/network_server.c
+++ b/src/lib/bluez/network_server.c
@@ -24,107 +24,79 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
-
-#include <string.h>
-
+#include <gio/gio.h>
#include <glib.h>
-#include <dbus/dbus-glib.h>
+#include <string.h>
#include "../dbus-common.h"
-#include "../marshallers.h"
+#include "../properties.h"
#include "network_server.h"
#define NETWORK_SERVER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), NETWORK_SERVER_TYPE, NetworkServerPrivate))
struct _NetworkServerPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
+ GDBusProxy *proxy;
+ gchar *object_path;
};
-G_DEFINE_TYPE(NetworkServer, network_server, G_TYPE_OBJECT);
+G_DEFINE_TYPE_WITH_PRIVATE(NetworkServer, network_server, G_TYPE_OBJECT);
enum {
PROP_0,
-
PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
};
static void _network_server_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void _network_server_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+static void _network_server_create_gdbus_proxy(NetworkServer *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
static void network_server_dispose(GObject *gobject)
{
NetworkServer *self = NETWORK_SERVER(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);
-
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
/* Chain up to the parent class */
G_OBJECT_CLASS(network_server_parent_class)->dispose(gobject);
}
+static void network_server_finalize (GObject *gobject)
+{
+ NetworkServer *self = NETWORK_SERVER(gobject);
+ G_OBJECT_CLASS(network_server_parent_class)->finalize(gobject);
+}
+
static void network_server_class_init(NetworkServerClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = network_server_dispose;
- g_type_class_add_private(klass, sizeof(NetworkServerPrivate));
-
/* Properties registration */
- GParamSpec *pspec;
+ GParamSpec *pspec = NULL;
gobject_class->get_property = _network_server_get_property;
gobject_class->set_property = _network_server_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);
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "NetworkServer D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
}
static void network_server_init(NetworkServer *self)
{
- self->priv = NETWORK_SERVER_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
+ self->priv = network_server_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
g_assert(system_conn != NULL);
}
-static void network_server_post_init(NetworkServer *self, const gchar *dbus_object_path)
-{
- 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(system_conn, "org.bluez", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", NETWORK_SERVER_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", NETWORK_SERVER_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, NETWORK_SERVER_DBUS_INTERFACE);
-}
-
static void _network_server_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
NetworkServer *self = NETWORK_SERVER(object);
@@ -147,7 +119,8 @@ static void _network_server_set_property(GObject *object, guint property_id, con
switch (property_id) {
case PROP_DBUS_OBJECT_PATH:
- network_server_post_init(self, g_value_get_string(value));
+ self->priv->object_path = g_value_dup_string(value);
+ _network_server_create_gdbus_proxy(self, NETWORK_SERVER_DBUS_SERVICE, self->priv->object_path, &error);
break;
default:
@@ -155,35 +128,49 @@ static void _network_server_set_property(GObject *object, guint property_id, con
break;
}
- if (error != NULL) {
+ if (error != NULL)
g_critical("%s", error->message);
- }
+
g_assert(error == NULL);
}
-/* Methods */
+/* Constructor */
+NetworkServer *network_server_new(const gchar *dbus_object_path)
+{
+ return g_object_new(NETWORK_SERVER_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
-/* void Register(string uuid, string bridge) */
-void network_server_register(NetworkServer *self, const gchar *uuid, const gchar *bridge, GError **error)
+/* Private DBus proxy creation */
+static void _network_server_create_gdbus_proxy(NetworkServer *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
{
g_assert(NETWORK_SERVER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, NETWORK_SERVER_DBUS_INTERFACE, NULL, error);
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Register", error, G_TYPE_STRING, uuid, G_TYPE_STRING, bridge, G_TYPE_INVALID, G_TYPE_INVALID);
+ if(self->priv->proxy == NULL)
+ return;
}
-/* void Unregister(string uuid) */
-void network_server_unregister(NetworkServer *self, const gchar *uuid, GError **error)
+/* Methods */
+
+/* Get DBus object path */
+const gchar *network_server_get_dbus_object_path(NetworkServer *self)
{
g_assert(NETWORK_SERVER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Unregister", error, G_TYPE_STRING, uuid, G_TYPE_INVALID, G_TYPE_INVALID);
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
}
-/* Properties access methods */
-const gchar *network_server_get_dbus_object_path(NetworkServer *self)
+/* void Register(string uuid, string bridge) */
+void network_server_register(NetworkServer *self, const gchar *uuid, const gchar *bridge, GError **error)
{
g_assert(NETWORK_SERVER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Register", g_variant_new ("(ss)", uuid, bridge), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
+/* void Unregister(string uuid) */
+void network_server_unregister(NetworkServer *self, const gchar *uuid, GError **error)
+{
+ g_assert(NETWORK_SERVER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Unregister", g_variant_new ("(s)", uuid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
}
diff --git a/src/lib/bluez/network_server.h b/src/lib/bluez/network_server.h
index be2260f..51a9c31 100644
--- a/src/lib/bluez/network_server.h
+++ b/src/lib/bluez/network_server.h
@@ -24,9 +24,14 @@
#ifndef __NETWORK_SERVER_H
#define __NETWORK_SERVER_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <glib-object.h>
-#define NETWORK_SERVER_DBUS_INTERFACE "org.bluez.NetworkServer"
+#define NETWORK_SERVER_DBUS_SERVICE "org.bluez"
+#define NETWORK_SERVER_DBUS_INTERFACE "org.bluez.NetworkServer1"
/*
* Type macros
@@ -57,12 +62,21 @@ struct _NetworkServerClass {
GType network_server_get_type(void) G_GNUC_CONST;
/*
+ * Constructor
+ */
+NetworkServer *network_server_new(const gchar *dbus_object_path);
+
+/*
* Method definitions
*/
+const gchar *network_server_get_dbus_object_path(NetworkServer *self);
+
void network_server_register(NetworkServer *self, const gchar *uuid, const gchar *bridge, GError **error);
void network_server_unregister(NetworkServer *self, const gchar *uuid, GError **error);
-const gchar *network_server_get_dbus_object_path(NetworkServer *self);
+#ifdef __cplusplus
+}
+#endif
#endif /* __NETWORK_SERVER_H */
diff --git a/src/lib/bluez/obex/obex_agent_manager.c b/src/lib/bluez/obex/obex_agent_manager.c
new file mode 100644
index 0000000..99eac4d
--- /dev/null
+++ b/src/lib/bluez/obex/obex_agent_manager.c
@@ -0,0 +1,154 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../../dbus-common.h"
+#include "../../properties.h"
+
+#include "obex_agent_manager.h"
+
+#define OBEX_AGENT_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_AGENT_MANAGER_TYPE, ObexAgentManagerPrivate))
+
+struct _ObexAgentManagerPrivate {
+ GDBusProxy *proxy;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexAgentManager, obex_agent_manager, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+};
+
+static void _obex_agent_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_agent_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_agent_manager_create_gdbus_proxy(ObexAgentManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void obex_agent_manager_dispose(GObject *gobject)
+{
+ ObexAgentManager *self = OBEX_AGENT_MANAGER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_agent_manager_parent_class)->dispose(gobject);
+}
+
+static void obex_agent_manager_finalize (GObject *gobject)
+{
+ ObexAgentManager *self = OBEX_AGENT_MANAGER(gobject);
+ G_OBJECT_CLASS(obex_agent_manager_parent_class)->finalize(gobject);
+}
+
+static void obex_agent_manager_class_init(ObexAgentManagerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_agent_manager_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_agent_manager_get_property;
+ gobject_class->set_property = _obex_agent_manager_set_property;
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_agent_manager_init(ObexAgentManager *self)
+{
+ self->priv = obex_agent_manager_get_instance_private (self);
+ self->priv->proxy = NULL;
+ g_assert(session_conn != NULL);
+ GError *error = NULL;
+ _obex_agent_manager_create_gdbus_proxy(self, OBEX_AGENT_MANAGER_DBUS_SERVICE, OBEX_AGENT_MANAGER_DBUS_PATH, &error);
+ g_assert(error == NULL);
+}
+
+static void _obex_agent_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexAgentManager *self = OBEX_AGENT_MANAGER(object);
+
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_agent_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexAgentManager *self = OBEX_AGENT_MANAGER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+
+ if (error != NULL)
+ g_critical("%s", error->message);
+
+ g_assert(error == NULL);
+}
+
+/* Constructor */
+ObexAgentManager *obex_agent_manager_new()
+{
+ return g_object_new(OBEX_AGENT_MANAGER_TYPE, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _obex_agent_manager_create_gdbus_proxy(ObexAgentManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(OBEX_AGENT_MANAGER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, OBEX_AGENT_MANAGER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* void RegisterAgent(object agent) */
+void obex_agent_manager_register_agent(ObexAgentManager *self, const gchar *agent, GError **error)
+{
+ g_assert(OBEX_AGENT_MANAGER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "RegisterAgent", g_variant_new ("(o)", agent), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void UnregisterAgent(object agent) */
+void obex_agent_manager_unregister_agent(ObexAgentManager *self, const gchar *agent, GError **error)
+{
+ g_assert(OBEX_AGENT_MANAGER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "UnregisterAgent", g_variant_new ("(o)", agent), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/obex/obex_agent_manager.h b/src/lib/bluez/obex/obex_agent_manager.h
new file mode 100644
index 0000000..3c591df
--- /dev/null
+++ b/src/lib/bluez/obex/obex_agent_manager.h
@@ -0,0 +1,81 @@
+/*
+ *
+ * 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 __OBEX_AGENT_MANAGER_H
+#define __OBEX_AGENT_MANAGER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_AGENT_MANAGER_DBUS_SERVICE "org.bluez.obex"
+#define OBEX_AGENT_MANAGER_DBUS_INTERFACE "org.bluez.obex.AgentManager1"
+#define OBEX_AGENT_MANAGER_DBUS_PATH "/org/bluez/obex"
+
+/*
+ * Type macros
+ */
+#define OBEX_AGENT_MANAGER_TYPE (obex_agent_manager_get_type())
+#define OBEX_AGENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_AGENT_MANAGER_TYPE, ObexAgentManager))
+#define OBEX_AGENT_MANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_AGENT_MANAGER_TYPE))
+#define OBEX_AGENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_AGENT_MANAGER_TYPE, ObexAgentManagerClass))
+#define OBEX_AGENT_MANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_AGENT_MANAGER_TYPE))
+#define OBEX_AGENT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_AGENT_MANAGER_TYPE, ObexAgentManagerClass))
+
+typedef struct _ObexAgentManager ObexAgentManager;
+typedef struct _ObexAgentManagerClass ObexAgentManagerClass;
+typedef struct _ObexAgentManagerPrivate ObexAgentManagerPrivate;
+
+struct _ObexAgentManager {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexAgentManagerPrivate *priv;
+};
+
+struct _ObexAgentManagerClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_AGENT_MANAGER_TYPE */
+GType obex_agent_manager_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ObexAgentManager *obex_agent_manager_new();
+
+/*
+ * Method definitions
+ */
+void obex_agent_manager_register_agent(ObexAgentManager *self, const gchar *agent, GError **error);
+void obex_agent_manager_unregister_agent(ObexAgentManager *self, const gchar *agent, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_AGENT_MANAGER_H */
+
diff --git a/src/lib/bluez/obex/obex_client.c b/src/lib/bluez/obex/obex_client.c
new file mode 100644
index 0000000..02b65bb
--- /dev/null
+++ b/src/lib/bluez/obex/obex_client.c
@@ -0,0 +1,161 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../../dbus-common.h"
+#include "../../properties.h"
+
+#include "obex_client.h"
+
+#define OBEX_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_CLIENT_TYPE, ObexClientPrivate))
+
+struct _ObexClientPrivate {
+ GDBusProxy *proxy;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexClient, obex_client, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+};
+
+static void _obex_client_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_client_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_client_create_gdbus_proxy(ObexClient *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void obex_client_dispose(GObject *gobject)
+{
+ ObexClient *self = OBEX_CLIENT(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_client_parent_class)->dispose(gobject);
+}
+
+static void obex_client_finalize (GObject *gobject)
+{
+ ObexClient *self = OBEX_CLIENT(gobject);
+ G_OBJECT_CLASS(obex_client_parent_class)->finalize(gobject);
+}
+
+static void obex_client_class_init(ObexClientClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_client_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_client_get_property;
+ gobject_class->set_property = _obex_client_set_property;
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_client_init(ObexClient *self)
+{
+ self->priv = obex_client_get_instance_private (self);
+ self->priv->proxy = NULL;
+ g_assert(session_conn != NULL);
+ GError *error = NULL;
+ _obex_client_create_gdbus_proxy(self, OBEX_CLIENT_DBUS_SERVICE, OBEX_CLIENT_DBUS_PATH, &error);
+ g_assert(error == NULL);
+}
+
+static void _obex_client_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexClient *self = OBEX_CLIENT(object);
+
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_client_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexClient *self = OBEX_CLIENT(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+
+ if (error != NULL)
+ g_critical("%s", error->message);
+
+ g_assert(error == NULL);
+}
+
+/* Constructor */
+ObexClient *obex_client_new()
+{
+ return g_object_new(OBEX_CLIENT_TYPE, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _obex_client_create_gdbus_proxy(ObexClient *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(OBEX_CLIENT_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, OBEX_CLIENT_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* object CreateSession(string destination, dict args) */
+const gchar *obex_client_create_session(ObexClient *self, const gchar *destination, const GVariant *args, GError **error)
+{
+ g_assert(OBEX_CLIENT_IS(self));
+ const gchar *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "CreateSession", g_variant_new ("(s@a{sv})", destination, args), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_get_string(proxy_ret, NULL);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* void RemoveSession(object session) */
+void obex_client_remove_session(ObexClient *self, const gchar *session, GError **error)
+{
+ g_assert(OBEX_CLIENT_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "RemoveSession", g_variant_new ("(o)", session), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/obex/obex_client.h b/src/lib/bluez/obex/obex_client.h
new file mode 100644
index 0000000..a9bcee9
--- /dev/null
+++ b/src/lib/bluez/obex/obex_client.h
@@ -0,0 +1,81 @@
+/*
+ *
+ * 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 __OBEX_CLIENT_H
+#define __OBEX_CLIENT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_CLIENT_DBUS_SERVICE "org.bluez.obex"
+#define OBEX_CLIENT_DBUS_INTERFACE "org.bluez.obex.Client1"
+#define OBEX_CLIENT_DBUS_PATH "/org/bluez/obex"
+
+/*
+ * Type macros
+ */
+#define OBEX_CLIENT_TYPE (obex_client_get_type())
+#define OBEX_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_CLIENT_TYPE, ObexClient))
+#define OBEX_CLIENT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_CLIENT_TYPE))
+#define OBEX_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_CLIENT_TYPE, ObexClientClass))
+#define OBEX_CLIENT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_CLIENT_TYPE))
+#define OBEX_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_CLIENT_TYPE, ObexClientClass))
+
+typedef struct _ObexClient ObexClient;
+typedef struct _ObexClientClass ObexClientClass;
+typedef struct _ObexClientPrivate ObexClientPrivate;
+
+struct _ObexClient {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexClientPrivate *priv;
+};
+
+struct _ObexClientClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_CLIENT_TYPE */
+GType obex_client_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ObexClient *obex_client_new();
+
+/*
+ * Method definitions
+ */
+const gchar *obex_client_create_session(ObexClient *self, const gchar *destination, const GVariant *args, GError **error);
+void obex_client_remove_session(ObexClient *self, const gchar *session, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_CLIENT_H */
+
diff --git a/src/lib/bluez/obex/obex_file_transfer.c b/src/lib/bluez/obex/obex_file_transfer.c
new file mode 100644
index 0000000..2d3dafe
--- /dev/null
+++ b/src/lib/bluez/obex/obex_file_transfer.c
@@ -0,0 +1,236 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../../dbus-common.h"
+#include "../../properties.h"
+
+#include "obex_file_transfer.h"
+
+#define OBEX_FILE_TRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_FILE_TRANSFER_TYPE, ObexFileTransferPrivate))
+
+struct _ObexFileTransferPrivate {
+ GDBusProxy *proxy;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexFileTransfer, obex_file_transfer, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _obex_file_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_file_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_file_transfer_create_gdbus_proxy(ObexFileTransfer *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void obex_file_transfer_dispose(GObject *gobject)
+{
+ ObexFileTransfer *self = OBEX_FILE_TRANSFER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_file_transfer_parent_class)->dispose(gobject);
+}
+
+static void obex_file_transfer_finalize (GObject *gobject)
+{
+ ObexFileTransfer *self = OBEX_FILE_TRANSFER(gobject);
+ G_OBJECT_CLASS(obex_file_transfer_parent_class)->finalize(gobject);
+}
+
+static void obex_file_transfer_class_init(ObexFileTransferClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_file_transfer_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_file_transfer_get_property;
+ gobject_class->set_property = _obex_file_transfer_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ObexFileTransfer D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_file_transfer_init(ObexFileTransfer *self)
+{
+ self->priv = obex_file_transfer_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
+ g_assert(session_conn != NULL);
+}
+
+static void _obex_file_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexFileTransfer *self = OBEX_FILE_TRANSFER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, obex_file_transfer_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_file_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexFileTransfer *self = OBEX_FILE_TRANSFER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _obex_file_transfer_create_gdbus_proxy(self, OBEX_FILE_TRANSFER_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ObexFileTransfer *obex_file_transfer_new(const gchar *dbus_object_path)
+{
+ return g_object_new(OBEX_FILE_TRANSFER_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _obex_file_transfer_create_gdbus_proxy(ObexFileTransfer *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(OBEX_FILE_TRANSFER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, OBEX_FILE_TRANSFER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *obex_file_transfer_get_dbus_object_path(ObexFileTransfer *self)
+{
+ g_assert(OBEX_FILE_TRANSFER_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* void ChangeFolder(string folder) */
+void obex_file_transfer_change_folder(ObexFileTransfer *self, const gchar *folder, GError **error)
+{
+ g_assert(OBEX_FILE_TRANSFER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "ChangeFolder", g_variant_new ("(s)", folder), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void CopyFile(string sourcefile, string targetfile) */
+void obex_file_transfer_copy_file(ObexFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error)
+{
+ g_assert(OBEX_FILE_TRANSFER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "CopyFile", g_variant_new ("(ss)", sourcefile, targetfile), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void CreateFolder(string folder) */
+void obex_file_transfer_create_folder(ObexFileTransfer *self, const gchar *folder, GError **error)
+{
+ g_assert(OBEX_FILE_TRANSFER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "CreateFolder", g_variant_new ("(s)", folder), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Delete(string file) */
+void obex_file_transfer_delete(ObexFileTransfer *self, const gchar *file, GError **error)
+{
+ g_assert(OBEX_FILE_TRANSFER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Delete", g_variant_new ("(s)", file), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* object, dict GetFile(string targetfile, string sourcefile) */
+GVariant *obex_file_transfer_get_file(ObexFileTransfer *self, const gchar *targetfile, const gchar *sourcefile, GError **error)
+{
+ g_assert(OBEX_FILE_TRANSFER_IS(self));
+ GVariant *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "GetFile", g_variant_new ("(ss)", targetfile, sourcefile), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ ret = g_variant_ref_sink(proxy_ret);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* array{dict} ListFolder() */
+GVariant *obex_file_transfer_list_folder(ObexFileTransfer *self, GError **error)
+{
+ g_assert(OBEX_FILE_TRANSFER_IS(self));
+ GVariant *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "ListFolder", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_ref_sink(proxy_ret);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* void MoveFile(string sourcefile, string targetfile) */
+void obex_file_transfer_move_file(ObexFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error)
+{
+ g_assert(OBEX_FILE_TRANSFER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "MoveFile", g_variant_new ("(ss)", sourcefile, targetfile), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* object, dict PutFile(string sourcefile, string targetfile) */
+GVariant *obex_file_transfer_put_file(ObexFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error)
+{
+ g_assert(OBEX_FILE_TRANSFER_IS(self));
+ GVariant *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "PutFile", g_variant_new ("(ss)", targetfile, sourcefile), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ ret = g_variant_ref_sink(proxy_ret);
+ g_variant_unref(proxy_ret);
+ return ret;
+} \ No newline at end of file
diff --git a/src/lib/bluez/obex/obex_file_transfer.h b/src/lib/bluez/obex/obex_file_transfer.h
new file mode 100644
index 0000000..a908701
--- /dev/null
+++ b/src/lib/bluez/obex/obex_file_transfer.h
@@ -0,0 +1,88 @@
+/*
+ *
+ * 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 __OBEX_FILE_TRANSFER_H
+#define __OBEX_FILE_TRANSFER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_FILE_TRANSFER_DBUS_SERVICE "org.bluez.obex"
+#define OBEX_FILE_TRANSFER_DBUS_INTERFACE "org.bluez.obex.FileTransfer"
+
+/*
+ * Type macros
+ */
+#define OBEX_FILE_TRANSFER_TYPE (obex_file_transfer_get_type())
+#define OBEX_FILE_TRANSFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_FILE_TRANSFER_TYPE, ObexFileTransfer))
+#define OBEX_FILE_TRANSFER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_FILE_TRANSFER_TYPE))
+#define OBEX_FILE_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_FILE_TRANSFER_TYPE, ObexFileTransferClass))
+#define OBEX_FILE_TRANSFER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_FILE_TRANSFER_TYPE))
+#define OBEX_FILE_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_FILE_TRANSFER_TYPE, ObexFileTransferClass))
+
+typedef struct _ObexFileTransfer ObexFileTransfer;
+typedef struct _ObexFileTransferClass ObexFileTransferClass;
+typedef struct _ObexFileTransferPrivate ObexFileTransferPrivate;
+
+struct _ObexFileTransfer {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexFileTransferPrivate *priv;
+};
+
+struct _ObexFileTransferClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_FILE_TRANSFER_TYPE */
+GType obex_file_transfer_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ObexFileTransfer *obex_file_transfer_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *obex_file_transfer_get_dbus_object_path(ObexFileTransfer *self);
+
+void obex_file_transfer_change_folder(ObexFileTransfer *self, const gchar *folder, GError **error);
+void obex_file_transfer_copy_file(ObexFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error);
+void obex_file_transfer_create_folder(ObexFileTransfer *self, const gchar *folder, GError **error);
+void obex_file_transfer_delete(ObexFileTransfer *self, const gchar *file, GError **error);
+GVariant *obex_file_transfer_get_file(ObexFileTransfer *self, const gchar *targetfile, const gchar *sourcefile, GError **error);
+GVariant *obex_file_transfer_list_folder(ObexFileTransfer *self, GError **error);
+void obex_file_transfer_move_file(ObexFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error);
+GVariant *obex_file_transfer_put_file(ObexFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_FILE_TRANSFER_H */
+
diff --git a/src/lib/bluez/obex/obex_message.c b/src/lib/bluez/obex/obex_message.c
new file mode 100644
index 0000000..10947ae
--- /dev/null
+++ b/src/lib/bluez/obex/obex_message.c
@@ -0,0 +1,380 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../../dbus-common.h"
+#include "../../properties.h"
+
+#include "obex_message.h"
+
+#define OBEX_MESSAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_MESSAGE_TYPE, ObexMessagePrivate))
+
+struct _ObexMessagePrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexMessage, obex_message, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _obex_message_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_message_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_message_create_gdbus_proxy(ObexMessage *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void obex_message_dispose(GObject *gobject)
+{
+ ObexMessage *self = OBEX_MESSAGE(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_message_parent_class)->dispose(gobject);
+}
+
+static void obex_message_finalize (GObject *gobject)
+{
+ ObexMessage *self = OBEX_MESSAGE(gobject);
+ G_OBJECT_CLASS(obex_message_parent_class)->finalize(gobject);
+}
+
+static void obex_message_class_init(ObexMessageClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_message_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_message_get_property;
+ gobject_class->set_property = _obex_message_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ObexMessage D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_message_init(ObexMessage *self)
+{
+ self->priv = obex_message_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(session_conn != NULL);
+}
+
+static void _obex_message_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexMessage *self = OBEX_MESSAGE(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, obex_message_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_message_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexMessage *self = OBEX_MESSAGE(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _obex_message_create_gdbus_proxy(self, OBEX_MESSAGE_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ObexMessage *obex_message_new(const gchar *dbus_object_path)
+{
+ return g_object_new(OBEX_MESSAGE_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _obex_message_create_gdbus_proxy(ObexMessage *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, OBEX_MESSAGE_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "session", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *obex_message_get_dbus_object_path(ObexMessage *self)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+
+
+/* Properties access methods */
+GVariant *obex_message_get_properties(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, error);
+}
+
+void obex_message_set_property(ObexMessage *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, name, value, error);
+}
+
+void obex_message_set_deleted(ObexMessage *self, const gboolean value, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Deleted", g_variant_new_boolean(value), error);
+}
+
+const gchar *obex_message_get_folder(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Folder", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+gboolean obex_message_get_priority(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Priority", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+gboolean obex_message_get_protected(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Protected", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+gboolean obex_message_get_read(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Read", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+void obex_message_set_read(ObexMessage *self, const gboolean value, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Read", g_variant_new_boolean(value), error);
+}
+
+const gchar *obex_message_get_recipient(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Recipient", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_message_get_recipient_address(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "RecipientAddress", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_message_get_reply_to(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "ReplyTo", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_message_get_sender(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Sender", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_message_get_sender_address(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "SenderAddress", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+gboolean obex_message_get_sent(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Sent", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+guint64 obex_message_get_size(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Size", error);
+ if(prop == NULL)
+ return 0;
+ guint64 ret = g_variant_get_uint64(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_message_get_status(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Status", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_message_get_subject(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Subject", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_message_get_timestamp(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Timestamp", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_message_get_message_type(ObexMessage *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_MESSAGE_DBUS_INTERFACE, "Type", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/obex/obex_message.h b/src/lib/bluez/obex/obex_message.h
new file mode 100644
index 0000000..c5164c5
--- /dev/null
+++ b/src/lib/bluez/obex/obex_message.h
@@ -0,0 +1,101 @@
+/*
+ *
+ * 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 __OBEX_MESSAGE_H
+#define __OBEX_MESSAGE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_MESSAGE_DBUS_SERVICE "org.bluez.obex"
+#define OBEX_MESSAGE_DBUS_INTERFACE "org.bluez.obex.Message1"
+
+/*
+ * Type macros
+ */
+#define OBEX_MESSAGE_TYPE (obex_message_get_type())
+#define OBEX_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_MESSAGE_TYPE, ObexMessage))
+#define OBEX_MESSAGE_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_MESSAGE_TYPE))
+#define OBEX_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_MESSAGE_TYPE, ObexMessageClass))
+#define OBEX_MESSAGE_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_MESSAGE_TYPE))
+#define OBEX_MESSAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_MESSAGE_TYPE, ObexMessageClass))
+
+typedef struct _ObexMessage ObexMessage;
+typedef struct _ObexMessageClass ObexMessageClass;
+typedef struct _ObexMessagePrivate ObexMessagePrivate;
+
+struct _ObexMessage {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexMessagePrivate *priv;
+};
+
+struct _ObexMessageClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_MESSAGE_TYPE */
+GType obex_message_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ObexMessage *obex_message_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *obex_message_get_dbus_object_path(ObexMessage *self);
+
+GVariant *obex_message_get_properties(ObexMessage *self, GError **error);
+void obex_message_set_property(ObexMessage *self, const gchar *name, const GVariant *value, GError **error);
+
+void obex_message_set_deleted(ObexMessage *self, const gboolean value, GError **error);
+const gchar *obex_message_get_folder(ObexMessage *self, GError **error);
+gboolean obex_message_get_priority(ObexMessage *self, GError **error);
+gboolean obex_message_get_protected(ObexMessage *self, GError **error);
+gboolean obex_message_get_read(ObexMessage *self, GError **error);
+void obex_message_set_read(ObexMessage *self, const gboolean value, GError **error);
+const gchar *obex_message_get_recipient(ObexMessage *self, GError **error);
+const gchar *obex_message_get_recipient_address(ObexMessage *self, GError **error);
+const gchar *obex_message_get_reply_to(ObexMessage *self, GError **error);
+const gchar *obex_message_get_sender(ObexMessage *self, GError **error);
+const gchar *obex_message_get_sender_address(ObexMessage *self, GError **error);
+gboolean obex_message_get_sent(ObexMessage *self, GError **error);
+guint64 obex_message_get_size(ObexMessage *self, GError **error);
+const gchar *obex_message_get_status(ObexMessage *self, GError **error);
+const gchar *obex_message_get_subject(ObexMessage *self, GError **error);
+const gchar *obex_message_get_timestamp(ObexMessage *self, GError **error);
+// This has been renamed because 'obex_message_get_type' is already used by GLib
+const gchar *obex_message_get_message_type(ObexMessage *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_MESSAGE_H */
+
diff --git a/src/lib/bluez/obex/obex_message_access.c b/src/lib/bluez/obex/obex_message_access.c
new file mode 100644
index 0000000..66f43fe
--- /dev/null
+++ b/src/lib/bluez/obex/obex_message_access.c
@@ -0,0 +1,204 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../../dbus-common.h"
+#include "../../properties.h"
+
+#include "obex_message_access.h"
+
+#define OBEX_MESSAGE_ACCESS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_MESSAGE_ACCESS_TYPE, ObexMessageAccessPrivate))
+
+struct _ObexMessageAccessPrivate {
+ GDBusProxy *proxy;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexMessageAccess, obex_message_access, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _obex_message_access_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_message_access_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_message_access_create_gdbus_proxy(ObexMessageAccess *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void obex_message_access_dispose(GObject *gobject)
+{
+ ObexMessageAccess *self = OBEX_MESSAGE_ACCESS(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_message_access_parent_class)->dispose(gobject);
+}
+
+static void obex_message_access_finalize (GObject *gobject)
+{
+ ObexMessageAccess *self = OBEX_MESSAGE_ACCESS(gobject);
+ G_OBJECT_CLASS(obex_message_access_parent_class)->finalize(gobject);
+}
+
+static void obex_message_access_class_init(ObexMessageAccessClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_message_access_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_message_access_get_property;
+ gobject_class->set_property = _obex_message_access_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ObexMessageAccess D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_message_access_init(ObexMessageAccess *self)
+{
+ self->priv = obex_message_access_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
+ g_assert(session_conn != NULL);
+}
+
+static void _obex_message_access_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexMessageAccess *self = OBEX_MESSAGE_ACCESS(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, obex_message_access_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_message_access_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexMessageAccess *self = OBEX_MESSAGE_ACCESS(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _obex_message_access_create_gdbus_proxy(self, OBEX_MESSAGE_ACCESS_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ObexMessageAccess *obex_message_access_new(const gchar *dbus_object_path)
+{
+ return g_object_new(OBEX_MESSAGE_ACCESS_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _obex_message_access_create_gdbus_proxy(ObexMessageAccess *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(OBEX_MESSAGE_ACCESS_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, OBEX_MESSAGE_ACCESS_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *obex_message_access_get_dbus_object_path(ObexMessageAccess *self)
+{
+ g_assert(OBEX_MESSAGE_ACCESS_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* array{string} ListFilterFields() */
+const gchar **obex_message_access_list_filter_fields(ObexMessageAccess *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_ACCESS_IS(self));
+ const gchar **ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "ListFilterFields", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_get_strv(proxy_ret, NULL);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* array{dict} ListFolders(dict filter) */
+GVariant *obex_message_access_list_folders(ObexMessageAccess *self, const GVariant *filter, GError **error)
+{
+ g_assert(OBEX_MESSAGE_ACCESS_IS(self));
+ GVariant *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "ListFolders", g_variant_new ("(@a{sv})", filter), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_ref_sink(proxy_ret);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* void SetFolder(string name) */
+void obex_message_access_set_folder(ObexMessageAccess *self, const gchar *name, GError **error)
+{
+ g_assert(OBEX_MESSAGE_ACCESS_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "SetFolder", g_variant_new ("(s)", name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void UpdateInbox(void) */
+void obex_message_access_update_inbox(ObexMessageAccess *self, GError **error)
+{
+ g_assert(OBEX_MESSAGE_ACCESS_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "UpdateInbox", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/obex/obex_message_access.h b/src/lib/bluez/obex/obex_message_access.h
new file mode 100644
index 0000000..f68bab2
--- /dev/null
+++ b/src/lib/bluez/obex/obex_message_access.h
@@ -0,0 +1,84 @@
+/*
+ *
+ * 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 __OBEX_MESSAGE_ACCESS_H
+#define __OBEX_MESSAGE_ACCESS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_MESSAGE_ACCESS_DBUS_SERVICE "org.bluez.obex"
+#define OBEX_MESSAGE_ACCESS_DBUS_INTERFACE "org.bluez.obex.MessageAccess1"
+
+/*
+ * Type macros
+ */
+#define OBEX_MESSAGE_ACCESS_TYPE (obex_message_access_get_type())
+#define OBEX_MESSAGE_ACCESS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_MESSAGE_ACCESS_TYPE, ObexMessageAccess))
+#define OBEX_MESSAGE_ACCESS_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_MESSAGE_ACCESS_TYPE))
+#define OBEX_MESSAGE_ACCESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_MESSAGE_ACCESS_TYPE, ObexMessageAccessClass))
+#define OBEX_MESSAGE_ACCESS_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_MESSAGE_ACCESS_TYPE))
+#define OBEX_MESSAGE_ACCESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_MESSAGE_ACCESS_TYPE, ObexMessageAccessClass))
+
+typedef struct _ObexMessageAccess ObexMessageAccess;
+typedef struct _ObexMessageAccessClass ObexMessageAccessClass;
+typedef struct _ObexMessageAccessPrivate ObexMessageAccessPrivate;
+
+struct _ObexMessageAccess {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexMessageAccessPrivate *priv;
+};
+
+struct _ObexMessageAccessClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_MESSAGE_ACCESS_TYPE */
+GType obex_message_access_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ObexMessageAccess *obex_message_access_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *obex_message_access_get_dbus_object_path(ObexMessageAccess *self);
+
+const gchar **obex_message_access_list_filter_fields(ObexMessageAccess *self, GError **error);
+GVariant *obex_message_access_list_folders(ObexMessageAccess *self, const GVariant *filter, GError **error);
+void obex_message_access_set_folder(ObexMessageAccess *self, const gchar *name, GError **error);
+void obex_message_access_update_inbox(ObexMessageAccess *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_MESSAGE_ACCESS_H */
+
diff --git a/src/lib/bluez/obex/obex_object_push.c b/src/lib/bluez/obex/obex_object_push.c
new file mode 100644
index 0000000..a86aa36
--- /dev/null
+++ b/src/lib/bluez/obex/obex_object_push.c
@@ -0,0 +1,197 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../../dbus-common.h"
+#include "../../properties.h"
+
+#include "obex_object_push.h"
+
+#define OBEX_OBJECT_PUSH_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_OBJECT_PUSH_TYPE, ObexObjectPushPrivate))
+
+struct _ObexObjectPushPrivate {
+ GDBusProxy *proxy;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexObjectPush, obex_object_push, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _obex_object_push_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_object_push_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_object_push_create_gdbus_proxy(ObexObjectPush *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void obex_object_push_dispose(GObject *gobject)
+{
+ ObexObjectPush *self = OBEX_OBJECT_PUSH(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_object_push_parent_class)->dispose(gobject);
+}
+
+static void obex_object_push_finalize (GObject *gobject)
+{
+ ObexObjectPush *self = OBEX_OBJECT_PUSH(gobject);
+ G_OBJECT_CLASS(obex_object_push_parent_class)->finalize(gobject);
+}
+
+static void obex_object_push_class_init(ObexObjectPushClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_object_push_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_object_push_get_property;
+ gobject_class->set_property = _obex_object_push_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ObexObjectPush D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_object_push_init(ObexObjectPush *self)
+{
+ self->priv = obex_object_push_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
+ g_assert(session_conn != NULL);
+}
+
+static void _obex_object_push_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexObjectPush *self = OBEX_OBJECT_PUSH(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, obex_object_push_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_object_push_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexObjectPush *self = OBEX_OBJECT_PUSH(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _obex_object_push_create_gdbus_proxy(self, OBEX_OBJECT_PUSH_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ObexObjectPush *obex_object_push_new(const gchar *dbus_object_path)
+{
+ return g_object_new(OBEX_OBJECT_PUSH_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _obex_object_push_create_gdbus_proxy(ObexObjectPush *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(OBEX_OBJECT_PUSH_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, OBEX_OBJECT_PUSH_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *obex_object_push_get_dbus_object_path(ObexObjectPush *self)
+{
+ g_assert(OBEX_OBJECT_PUSH_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+GVariant *obex_object_push_exchange_business_cards(ObexObjectPush *self, const gchar *clientfile, const gchar *targetfile, GError **error)
+{
+ g_assert(OBEX_OBJECT_PUSH_IS(self));
+ GVariant *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "ExchangeBusinessCards", g_variant_new ("(ss)", clientfile, targetfile), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ ret = g_variant_ref_sink(proxy_ret);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+GVariant *obex_object_push_pull_business_card(ObexObjectPush *self, const gchar *targetfile, GError **error)
+{
+ g_assert(OBEX_OBJECT_PUSH_IS(self));
+ GVariant *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "PullBusinessCard", g_variant_new ("(s)", targetfile), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ ret = g_variant_ref_sink(proxy_ret);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+GVariant *obex_object_push_send_file(ObexObjectPush *self, const gchar *sourcefile, GError **error)
+{
+ g_assert(OBEX_OBJECT_PUSH_IS(self));
+ GVariant *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "SendFile", g_variant_new ("(s)", sourcefile), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ ret = g_variant_ref_sink(proxy_ret);
+ g_variant_unref(proxy_ret);
+ return ret;
+} \ No newline at end of file
diff --git a/src/lib/bluez/obex/obex_object_push.h b/src/lib/bluez/obex/obex_object_push.h
new file mode 100644
index 0000000..7fb302a
--- /dev/null
+++ b/src/lib/bluez/obex/obex_object_push.h
@@ -0,0 +1,79 @@
+/*
+ *
+ * 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 __OBEX_OBJECT_PUSH_H
+#define __OBEX_OBJECT_PUSH_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_OBJECT_PUSH_DBUS_SERVICE "org.bluez.obex"
+#define OBEX_OBJECT_PUSH_DBUS_INTERFACE "org.bluez.obex.ObjectPush1"
+
+/*
+ * Type macros
+ */
+#define OBEX_OBJECT_PUSH_TYPE (obex_object_push_get_type())
+#define OBEX_OBJECT_PUSH(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_OBJECT_PUSH_TYPE, ObexObjectPush))
+#define OBEX_OBJECT_PUSH_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_OBJECT_PUSH_TYPE))
+#define OBEX_OBJECT_PUSH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_OBJECT_PUSH_TYPE, ObexObjectPushClass))
+#define OBEX_OBJECT_PUSH_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_OBJECT_PUSH_TYPE))
+#define OBEX_OBJECT_PUSH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_OBJECT_PUSH_TYPE, ObexObjectPushClass))
+
+typedef struct _ObexObjectPush ObexObjectPush;
+typedef struct _ObexObjectPushClass ObexObjectPushClass;
+typedef struct _ObexObjectPushPrivate ObexObjectPushPrivate;
+
+struct _ObexObjectPush {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexObjectPushPrivate *priv;
+};
+
+struct _ObexObjectPushClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_OBJECT_PUSH_TYPE */
+GType obex_object_push_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ObexObjectPush *obex_object_push_new(const gchar *dbus_object_path);
+const gchar *obex_object_push_get_dbus_object_path(ObexObjectPush *self);
+
+GVariant *obex_object_push_exchange_business_cards(ObexObjectPush *self, const gchar *clientfile, const gchar *targetfile, GError **error);
+GVariant *obex_object_push_pull_business_card(ObexObjectPush *self, const gchar *targetfile, GError **error);
+GVariant *obex_object_push_send_file(ObexObjectPush *self, const gchar *sourcefile, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_OBJECT_PUSH_H */
+
diff --git a/src/lib/bluez/obex/obex_phonebook_access.c b/src/lib/bluez/obex/obex_phonebook_access.c
new file mode 100644
index 0000000..6d8db0c
--- /dev/null
+++ b/src/lib/bluez/obex/obex_phonebook_access.c
@@ -0,0 +1,197 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../../dbus-common.h"
+#include "../../properties.h"
+
+#include "obex_phonebook_access.h"
+
+#define OBEX_PHONEBOOK_ACCESS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_PHONEBOOK_ACCESS_TYPE, ObexPhonebookAccessPrivate))
+
+struct _ObexPhonebookAccessPrivate {
+ GDBusProxy *proxy;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexPhonebookAccess, obex_phonebook_access, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _obex_phonebook_access_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_phonebook_access_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_phonebook_access_create_gdbus_proxy(ObexPhonebookAccess *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void obex_phonebook_access_dispose(GObject *gobject)
+{
+ ObexPhonebookAccess *self = OBEX_PHONEBOOK_ACCESS(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_phonebook_access_parent_class)->dispose(gobject);
+}
+
+static void obex_phonebook_access_finalize (GObject *gobject)
+{
+ ObexPhonebookAccess *self = OBEX_PHONEBOOK_ACCESS(gobject);
+ G_OBJECT_CLASS(obex_phonebook_access_parent_class)->finalize(gobject);
+}
+
+static void obex_phonebook_access_class_init(ObexPhonebookAccessClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_phonebook_access_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_phonebook_access_get_property;
+ gobject_class->set_property = _obex_phonebook_access_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ObexPhonebookAccess D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_phonebook_access_init(ObexPhonebookAccess *self)
+{
+ self->priv = obex_phonebook_access_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
+ g_assert(session_conn != NULL);
+}
+
+static void _obex_phonebook_access_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexPhonebookAccess *self = OBEX_PHONEBOOK_ACCESS(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, obex_phonebook_access_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_phonebook_access_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexPhonebookAccess *self = OBEX_PHONEBOOK_ACCESS(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _obex_phonebook_access_create_gdbus_proxy(self, OBEX_PHONEBOOK_ACCESS_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ObexPhonebookAccess *obex_phonebook_access_new(const gchar *dbus_object_path)
+{
+ return g_object_new(OBEX_PHONEBOOK_ACCESS_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _obex_phonebook_access_create_gdbus_proxy(ObexPhonebookAccess *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(OBEX_PHONEBOOK_ACCESS_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, OBEX_PHONEBOOK_ACCESS_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *obex_phonebook_access_get_dbus_object_path(ObexPhonebookAccess *self)
+{
+ g_assert(OBEX_PHONEBOOK_ACCESS_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* uint16 GetSize() */
+guint16 obex_phonebook_access_get_size(ObexPhonebookAccess *self, GError **error)
+{
+ g_assert(OBEX_PHONEBOOK_ACCESS_IS(self));
+ guint16 ret = 0;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "GetSize", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return 0;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_get_uint16(proxy_ret);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* array{string} ListFilterFields() */
+const gchar **obex_phonebook_access_list_filter_fields(ObexPhonebookAccess *self, GError **error)
+{
+ g_assert(OBEX_PHONEBOOK_ACCESS_IS(self));
+ const gchar **ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "ListFilterFields", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_get_strv(proxy_ret, NULL);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* void Select(string location, string phonebook) */
+void obex_phonebook_access_select(ObexPhonebookAccess *self, const gchar *location, const gchar *phonebook, GError **error)
+{
+ g_assert(OBEX_PHONEBOOK_ACCESS_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Select", g_variant_new ("(ss)", location, phonebook), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/obex/obex_phonebook_access.h b/src/lib/bluez/obex/obex_phonebook_access.h
new file mode 100644
index 0000000..4b7f853
--- /dev/null
+++ b/src/lib/bluez/obex/obex_phonebook_access.h
@@ -0,0 +1,83 @@
+/*
+ *
+ * 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 __OBEX_PHONEBOOK_ACCESS_H
+#define __OBEX_PHONEBOOK_ACCESS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_PHONEBOOK_ACCESS_DBUS_SERVICE "org.bluez.obex"
+#define OBEX_PHONEBOOK_ACCESS_DBUS_INTERFACE "org.bluez.obex.PhonebookAccess1"
+
+/*
+ * Type macros
+ */
+#define OBEX_PHONEBOOK_ACCESS_TYPE (obex_phonebook_access_get_type())
+#define OBEX_PHONEBOOK_ACCESS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_PHONEBOOK_ACCESS_TYPE, ObexPhonebookAccess))
+#define OBEX_PHONEBOOK_ACCESS_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_PHONEBOOK_ACCESS_TYPE))
+#define OBEX_PHONEBOOK_ACCESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_PHONEBOOK_ACCESS_TYPE, ObexPhonebookAccessClass))
+#define OBEX_PHONEBOOK_ACCESS_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_PHONEBOOK_ACCESS_TYPE))
+#define OBEX_PHONEBOOK_ACCESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_PHONEBOOK_ACCESS_TYPE, ObexPhonebookAccessClass))
+
+typedef struct _ObexPhonebookAccess ObexPhonebookAccess;
+typedef struct _ObexPhonebookAccessClass ObexPhonebookAccessClass;
+typedef struct _ObexPhonebookAccessPrivate ObexPhonebookAccessPrivate;
+
+struct _ObexPhonebookAccess {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexPhonebookAccessPrivate *priv;
+};
+
+struct _ObexPhonebookAccessClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_PHONEBOOK_ACCESS_TYPE */
+GType obex_phonebook_access_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ObexPhonebookAccess *obex_phonebook_access_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *obex_phonebook_access_get_dbus_object_path(ObexPhonebookAccess *self);
+
+guint16 obex_phonebook_access_get_size(ObexPhonebookAccess *self, GError **error);
+const gchar **obex_phonebook_access_list_filter_fields(ObexPhonebookAccess *self, GError **error);
+void obex_phonebook_access_select(ObexPhonebookAccess *self, const gchar *location, const gchar *phonebook, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_PHONEBOOK_ACCESS_H */
+
diff --git a/src/lib/bluez/obex/obex_session.c b/src/lib/bluez/obex/obex_session.c
new file mode 100644
index 0000000..e313ae9
--- /dev/null
+++ b/src/lib/bluez/obex/obex_session.c
@@ -0,0 +1,258 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../../dbus-common.h"
+#include "../../properties.h"
+
+#include "obex_session.h"
+
+#define OBEX_SESSION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_SESSION_TYPE, ObexSessionPrivate))
+
+struct _ObexSessionPrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexSession, obex_session, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _obex_session_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_session_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_session_create_gdbus_proxy(ObexSession *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void obex_session_dispose(GObject *gobject)
+{
+ ObexSession *self = OBEX_SESSION(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_session_parent_class)->dispose(gobject);
+}
+
+static void obex_session_finalize (GObject *gobject)
+{
+ ObexSession *self = OBEX_SESSION(gobject);
+ G_OBJECT_CLASS(obex_session_parent_class)->finalize(gobject);
+}
+
+static void obex_session_class_init(ObexSessionClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_session_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_session_get_property;
+ gobject_class->set_property = _obex_session_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ObexSession D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_session_init(ObexSession *self)
+{
+ self->priv = obex_session_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(session_conn != NULL);
+}
+
+static void _obex_session_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexSession *self = OBEX_SESSION(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, obex_session_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_session_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexSession *self = OBEX_SESSION(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _obex_session_create_gdbus_proxy(self, OBEX_SESSION_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ObexSession *obex_session_new(const gchar *dbus_object_path)
+{
+ return g_object_new(OBEX_SESSION_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _obex_session_create_gdbus_proxy(ObexSession *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(OBEX_SESSION_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, OBEX_SESSION_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "session", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *obex_session_get_dbus_object_path(ObexSession *self)
+{
+ g_assert(OBEX_SESSION_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* string GetCapabilities() */
+const gchar *obex_session_get_capabilities(ObexSession *self, GError **error)
+{
+ g_assert(OBEX_SESSION_IS(self));
+ const gchar *ret = NULL;
+ GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "GetCapabilities", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (proxy_ret != NULL)
+ return NULL;
+ proxy_ret = g_variant_get_child_value(proxy_ret, 0);
+ ret = g_variant_get_string(proxy_ret, NULL);
+ g_variant_unref(proxy_ret);
+ return ret;
+}
+
+/* Properties access methods */
+GVariant *obex_session_get_properties(ObexSession *self, GError **error)
+{
+ g_assert(OBEX_SESSION_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, OBEX_SESSION_DBUS_INTERFACE, error);
+}
+
+void obex_session_set_property(ObexSession *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(OBEX_SESSION_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, OBEX_SESSION_DBUS_INTERFACE, name, value, error);
+}
+
+guint8 obex_session_get_channel(ObexSession *self, GError **error)
+{
+ g_assert(OBEX_SESSION_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_SESSION_DBUS_INTERFACE, "Channel", error);
+ if(prop == NULL)
+ return 0;
+ guchar ret = g_variant_get_byte(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_session_get_destination(ObexSession *self, GError **error)
+{
+ g_assert(OBEX_SESSION_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_SESSION_DBUS_INTERFACE, "Destination", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_session_get_root(ObexSession *self, GError **error)
+{
+ g_assert(OBEX_SESSION_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_SESSION_DBUS_INTERFACE, "Root", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_session_get_source(ObexSession *self, GError **error)
+{
+ g_assert(OBEX_SESSION_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_SESSION_DBUS_INTERFACE, "Source", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_session_get_target(ObexSession *self, GError **error)
+{
+ g_assert(OBEX_SESSION_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_SESSION_DBUS_INTERFACE, "Target", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/obex/obex_session.h b/src/lib/bluez/obex/obex_session.h
new file mode 100644
index 0000000..da4dca4
--- /dev/null
+++ b/src/lib/bluez/obex/obex_session.h
@@ -0,0 +1,90 @@
+/*
+ *
+ * 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 __OBEX_SESSION_H
+#define __OBEX_SESSION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_SESSION_DBUS_SERVICE "org.bluez.obex"
+#define OBEX_SESSION_DBUS_INTERFACE "org.bluez.obex.Session1"
+
+/*
+ * Type macros
+ */
+#define OBEX_SESSION_TYPE (obex_session_get_type())
+#define OBEX_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_SESSION_TYPE, ObexSession))
+#define OBEX_SESSION_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_SESSION_TYPE))
+#define OBEX_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_SESSION_TYPE, ObexSessionClass))
+#define OBEX_SESSION_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_SESSION_TYPE))
+#define OBEX_SESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_SESSION_TYPE, ObexSessionClass))
+
+typedef struct _ObexSession ObexSession;
+typedef struct _ObexSessionClass ObexSessionClass;
+typedef struct _ObexSessionPrivate ObexSessionPrivate;
+
+struct _ObexSession {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexSessionPrivate *priv;
+};
+
+struct _ObexSessionClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_SESSION_TYPE */
+GType obex_session_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ObexSession *obex_session_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *obex_session_get_dbus_object_path(ObexSession *self);
+
+const gchar *obex_session_get_capabilities(ObexSession *self, GError **error);
+
+GVariant *obex_session_get_properties(ObexSession *self, GError **error);
+void obex_session_set_property(ObexSession *self, const gchar *name, const GVariant *value, GError **error);
+
+guint8 obex_session_get_channel(ObexSession *self, GError **error);
+const gchar *obex_session_get_destination(ObexSession *self, GError **error);
+const gchar *obex_session_get_root(ObexSession *self, GError **error);
+const gchar *obex_session_get_source(ObexSession *self, GError **error);
+const gchar *obex_session_get_target(ObexSession *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_SESSION_H */
+
diff --git a/src/lib/bluez/obex/obex_synchronization.c b/src/lib/bluez/obex/obex_synchronization.c
new file mode 100644
index 0000000..7c6da22
--- /dev/null
+++ b/src/lib/bluez/obex/obex_synchronization.c
@@ -0,0 +1,169 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../../dbus-common.h"
+#include "../../properties.h"
+
+#include "obex_synchronization.h"
+
+#define OBEX_SYNCHRONIZATION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_SYNCHRONIZATION_TYPE, ObexSynchronizationPrivate))
+
+struct _ObexSynchronizationPrivate {
+ GDBusProxy *proxy;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexSynchronization, obex_synchronization, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _obex_synchronization_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_synchronization_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_synchronization_create_gdbus_proxy(ObexSynchronization *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void obex_synchronization_dispose(GObject *gobject)
+{
+ ObexSynchronization *self = OBEX_SYNCHRONIZATION(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_synchronization_parent_class)->dispose(gobject);
+}
+
+static void obex_synchronization_finalize (GObject *gobject)
+{
+ ObexSynchronization *self = OBEX_SYNCHRONIZATION(gobject);
+ G_OBJECT_CLASS(obex_synchronization_parent_class)->finalize(gobject);
+}
+
+static void obex_synchronization_class_init(ObexSynchronizationClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_synchronization_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_synchronization_get_property;
+ gobject_class->set_property = _obex_synchronization_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ObexSynchronization D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_synchronization_init(ObexSynchronization *self)
+{
+ self->priv = obex_synchronization_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
+ g_assert(session_conn != NULL);
+}
+
+static void _obex_synchronization_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexSynchronization *self = OBEX_SYNCHRONIZATION(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, obex_synchronization_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_synchronization_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexSynchronization *self = OBEX_SYNCHRONIZATION(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _obex_synchronization_create_gdbus_proxy(self, OBEX_SYNCHRONIZATION_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ObexSynchronization *obex_synchronization_new(const gchar *dbus_object_path)
+{
+ return g_object_new(OBEX_SYNCHRONIZATION_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _obex_synchronization_create_gdbus_proxy(ObexSynchronization *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(OBEX_SYNCHRONIZATION_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, OBEX_SYNCHRONIZATION_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *obex_synchronization_get_dbus_object_path(ObexSynchronization *self)
+{
+ g_assert(OBEX_SYNCHRONIZATION_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* void SetLocation(string location) */
+void obex_synchronization_set_location(ObexSynchronization *self, const gchar *location, GError **error)
+{
+ g_assert(OBEX_SYNCHRONIZATION_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "SetLocation", g_variant_new ("(s)", location), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/obex/obex_synchronization.h b/src/lib/bluez/obex/obex_synchronization.h
new file mode 100644
index 0000000..d1fab05
--- /dev/null
+++ b/src/lib/bluez/obex/obex_synchronization.h
@@ -0,0 +1,81 @@
+/*
+ *
+ * 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 __OBEX_SYNCHRONIZATION_H
+#define __OBEX_SYNCHRONIZATION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_SYNCHRONIZATION_DBUS_SERVICE "org.bluez.obex"
+#define OBEX_SYNCHRONIZATION_DBUS_INTERFACE "org.bluez.obex.Synchronization1"
+
+/*
+ * Type macros
+ */
+#define OBEX_SYNCHRONIZATION_TYPE (obex_synchronization_get_type())
+#define OBEX_SYNCHRONIZATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_SYNCHRONIZATION_TYPE, ObexSynchronization))
+#define OBEX_SYNCHRONIZATION_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_SYNCHRONIZATION_TYPE))
+#define OBEX_SYNCHRONIZATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_SYNCHRONIZATION_TYPE, ObexSynchronizationClass))
+#define OBEX_SYNCHRONIZATION_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_SYNCHRONIZATION_TYPE))
+#define OBEX_SYNCHRONIZATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_SYNCHRONIZATION_TYPE, ObexSynchronizationClass))
+
+typedef struct _ObexSynchronization ObexSynchronization;
+typedef struct _ObexSynchronizationClass ObexSynchronizationClass;
+typedef struct _ObexSynchronizationPrivate ObexSynchronizationPrivate;
+
+struct _ObexSynchronization {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexSynchronizationPrivate *priv;
+};
+
+struct _ObexSynchronizationClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_SYNCHRONIZATION_TYPE */
+GType obex_synchronization_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ObexSynchronization *obex_synchronization_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *obex_synchronization_get_dbus_object_path(ObexSynchronization *self);
+
+void obex_synchronization_set_location(ObexSynchronization *self, const gchar *location, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_SYNCHRONIZATION_H */
+
diff --git a/src/lib/bluez/obex/obex_transfer.c b/src/lib/bluez/obex/obex_transfer.c
new file mode 100644
index 0000000..a6a165c
--- /dev/null
+++ b/src/lib/bluez/obex/obex_transfer.c
@@ -0,0 +1,301 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../../dbus-common.h"
+#include "../../properties.h"
+
+#include "obex_transfer.h"
+
+#define OBEX_TRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_TRANSFER_TYPE, ObexTransferPrivate))
+
+struct _ObexTransferPrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexTransfer, obex_transfer, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _obex_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_transfer_create_gdbus_proxy(ObexTransfer *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void obex_transfer_dispose(GObject *gobject)
+{
+ ObexTransfer *self = OBEX_TRANSFER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_transfer_parent_class)->dispose(gobject);
+}
+
+static void obex_transfer_finalize (GObject *gobject)
+{
+ ObexTransfer *self = OBEX_TRANSFER(gobject);
+ G_OBJECT_CLASS(obex_transfer_parent_class)->finalize(gobject);
+}
+
+static void obex_transfer_class_init(ObexTransferClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_transfer_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_transfer_get_property;
+ gobject_class->set_property = _obex_transfer_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ObexTransfer D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_transfer_init(ObexTransfer *self)
+{
+ self->priv = obex_transfer_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(session_conn != NULL);
+}
+
+static void _obex_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexTransfer *self = OBEX_TRANSFER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, obex_transfer_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexTransfer *self = OBEX_TRANSFER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _obex_transfer_create_gdbus_proxy(self, OBEX_TRANSFER_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ObexTransfer *obex_transfer_new(const gchar *dbus_object_path)
+{
+ return g_object_new(OBEX_TRANSFER_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _obex_transfer_create_gdbus_proxy(ObexTransfer *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, OBEX_TRANSFER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "session", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *obex_transfer_get_dbus_object_path(ObexTransfer *self)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* void Cancel() */
+void obex_transfer_cancel(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Cancel", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Resume() */
+void obex_transfer_resume(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Resume", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void Suspend() */
+void obex_transfer_suspend(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Suspend", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* Properties access methods */
+GVariant *obex_transfer_get_properties(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, OBEX_TRANSFER_DBUS_INTERFACE, error);
+}
+
+void obex_transfer_set_property(ObexTransfer *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, OBEX_TRANSFER_DBUS_INTERFACE, name, value, error);
+}
+
+const gchar *obex_transfer_get_filename(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_TRANSFER_DBUS_INTERFACE, "Filename", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_transfer_get_name(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_TRANSFER_DBUS_INTERFACE, "Name", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_transfer_get_session(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_TRANSFER_DBUS_INTERFACE, "Session", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+guint64 obex_transfer_get_size(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_TRANSFER_DBUS_INTERFACE, "Size", error);
+ if(prop == NULL)
+ return 0;
+ guint64 ret = g_variant_get_uint64(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_transfer_get_status(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_TRANSFER_DBUS_INTERFACE, "Status", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+guint64 obex_transfer_get_time(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_TRANSFER_DBUS_INTERFACE, "Time", error);
+ if(prop == NULL)
+ return 0;
+ guint64 ret = g_variant_get_uint64(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+guint64 obex_transfer_get_transferred(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_TRANSFER_DBUS_INTERFACE, "Transferred", error);
+ if(prop == NULL)
+ return 0;
+ guint64 ret = g_variant_get_uint64(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *obex_transfer_get_transfer_type(ObexTransfer *self, GError **error)
+{
+ g_assert(OBEX_TRANSFER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, OBEX_TRANSFER_DBUS_INTERFACE, "Type", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/obex/obex_transfer.h b/src/lib/bluez/obex/obex_transfer.h
new file mode 100644
index 0000000..7996b08
--- /dev/null
+++ b/src/lib/bluez/obex/obex_transfer.h
@@ -0,0 +1,96 @@
+/*
+ *
+ * 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 __OBEX_TRANSFER_H
+#define __OBEX_TRANSFER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_TRANSFER_DBUS_SERVICE "org.bluez.obex"
+#define OBEX_TRANSFER_DBUS_INTERFACE "org.bluez.obex.Transfer1"
+
+/*
+ * Type macros
+ */
+#define OBEX_TRANSFER_TYPE (obex_transfer_get_type())
+#define OBEX_TRANSFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_TRANSFER_TYPE, ObexTransfer))
+#define OBEX_TRANSFER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_TRANSFER_TYPE))
+#define OBEX_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_TRANSFER_TYPE, ObexTransferClass))
+#define OBEX_TRANSFER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_TRANSFER_TYPE))
+#define OBEX_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_TRANSFER_TYPE, ObexTransferClass))
+
+typedef struct _ObexTransfer ObexTransfer;
+typedef struct _ObexTransferClass ObexTransferClass;
+typedef struct _ObexTransferPrivate ObexTransferPrivate;
+
+struct _ObexTransfer {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexTransferPrivate *priv;
+};
+
+struct _ObexTransferClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_TRANSFER_TYPE */
+GType obex_transfer_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ObexTransfer *obex_transfer_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *obex_transfer_get_dbus_object_path(ObexTransfer *self);
+
+void obex_transfer_cancel(ObexTransfer *self, GError **error);
+void obex_transfer_resume(ObexTransfer *self, GError **error);
+void obex_transfer_suspend(ObexTransfer *self, GError **error);
+
+GVariant *obex_transfer_get_properties(ObexTransfer *self, GError **error);
+void obex_transfer_set_property(ObexTransfer *self, const gchar *name, const GVariant *value, GError **error);
+
+const gchar *obex_transfer_get_filename(ObexTransfer *self, GError **error);
+const gchar *obex_transfer_get_name(ObexTransfer *self, GError **error);
+const gchar *obex_transfer_get_session(ObexTransfer *self, GError **error);
+guint64 obex_transfer_get_size(ObexTransfer *self, GError **error);
+const gchar *obex_transfer_get_status(ObexTransfer *self, GError **error);
+guint64 obex_transfer_get_time(ObexTransfer *self, GError **error);
+guint64 obex_transfer_get_transferred(ObexTransfer *self, GError **error);
+// This has been renamed because 'obex_transfer_get_type' is already used by GLib
+const gchar *obex_transfer_get_transfer_type(ObexTransfer *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_TRANSFER_H */
+
diff --git a/src/lib/bluez/profile_manager.c b/src/lib/bluez/profile_manager.c
new file mode 100644
index 0000000..4857338
--- /dev/null
+++ b/src/lib/bluez/profile_manager.c
@@ -0,0 +1,154 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "profile_manager.h"
+
+#define PROFILE_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PROFILE_MANAGER_TYPE, ProfileManagerPrivate))
+
+struct _ProfileManagerPrivate {
+ GDBusProxy *proxy;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ProfileManager, profile_manager, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+};
+
+static void _profile_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _profile_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _profile_manager_create_gdbus_proxy(ProfileManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void profile_manager_dispose(GObject *gobject)
+{
+ ProfileManager *self = PROFILE_MANAGER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(profile_manager_parent_class)->dispose(gobject);
+}
+
+static void profile_manager_finalize (GObject *gobject)
+{
+ ProfileManager *self = PROFILE_MANAGER(gobject);
+ G_OBJECT_CLASS(profile_manager_parent_class)->finalize(gobject);
+}
+
+static void profile_manager_class_init(ProfileManagerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = profile_manager_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _profile_manager_get_property;
+ gobject_class->set_property = _profile_manager_set_property;
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void profile_manager_init(ProfileManager *self)
+{
+ self->priv = profile_manager_get_instance_private (self);
+ self->priv->proxy = NULL;
+ g_assert(system_conn != NULL);
+ GError *error = NULL;
+ _profile_manager_create_gdbus_proxy(self, PROFILE_MANAGER_DBUS_SERVICE, PROFILE_MANAGER_DBUS_PATH, &error);
+ g_assert(error == NULL);
+}
+
+static void _profile_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ProfileManager *self = PROFILE_MANAGER(object);
+
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _profile_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ProfileManager *self = PROFILE_MANAGER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+
+ if (error != NULL)
+ g_critical("%s", error->message);
+
+ g_assert(error == NULL);
+}
+
+/* Constructor */
+ProfileManager *profile_manager_new()
+{
+ return g_object_new(PROFILE_MANAGER_TYPE, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _profile_manager_create_gdbus_proxy(ProfileManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(PROFILE_MANAGER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, PROFILE_MANAGER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* void RegisterProfile(object profile, string uuid, dict options) */
+void profile_manager_register_profile(ProfileManager *self, const gchar *profile, const gchar *uuid, const GVariant *options, GError **error)
+{
+ g_assert(PROFILE_MANAGER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "RegisterProfile", g_variant_new ("(os@a{sv})", profile, uuid, options), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* void UnregisterProfile(object profile) */
+void profile_manager_unregister_profile(ProfileManager *self, const gchar *profile, GError **error)
+{
+ g_assert(PROFILE_MANAGER_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "UnregisterProfile", g_variant_new ("(o)", profile), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
diff --git a/src/lib/bluez/profile_manager.h b/src/lib/bluez/profile_manager.h
new file mode 100644
index 0000000..ed72105
--- /dev/null
+++ b/src/lib/bluez/profile_manager.h
@@ -0,0 +1,81 @@
+/*
+ *
+ * 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 __PROFILE_MANAGER_H
+#define __PROFILE_MANAGER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define PROFILE_MANAGER_DBUS_SERVICE "org.bluez"
+#define PROFILE_MANAGER_DBUS_INTERFACE "org.bluez.ProfileManager1"
+#define PROFILE_MANAGER_DBUS_PATH "/org/bluez"
+
+/*
+ * Type macros
+ */
+#define PROFILE_MANAGER_TYPE (profile_manager_get_type())
+#define PROFILE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PROFILE_MANAGER_TYPE, ProfileManager))
+#define PROFILE_MANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PROFILE_MANAGER_TYPE))
+#define PROFILE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PROFILE_MANAGER_TYPE, ProfileManagerClass))
+#define PROFILE_MANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PROFILE_MANAGER_TYPE))
+#define PROFILE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PROFILE_MANAGER_TYPE, ProfileManagerClass))
+
+typedef struct _ProfileManager ProfileManager;
+typedef struct _ProfileManagerClass ProfileManagerClass;
+typedef struct _ProfileManagerPrivate ProfileManagerPrivate;
+
+struct _ProfileManager {
+ GObject parent_instance;
+
+ /*< private >*/
+ ProfileManagerPrivate *priv;
+};
+
+struct _ProfileManagerClass {
+ GObjectClass parent_class;
+};
+
+/* used by PROFILE_MANAGER_TYPE */
+GType profile_manager_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ProfileManager *profile_manager_new();
+
+/*
+ * Method definitions
+ */
+void profile_manager_register_profile(ProfileManager *self, const gchar *profile, const gchar *uuid, const GVariant *options, GError **error);
+void profile_manager_unregister_profile(ProfileManager *self, const gchar *profile, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PROFILE_MANAGER_H */
+
diff --git a/src/lib/bluez/proximity_monitor.c b/src/lib/bluez/proximity_monitor.c
new file mode 100644
index 0000000..95cc1d8
--- /dev/null
+++ b/src/lib/bluez/proximity_monitor.c
@@ -0,0 +1,236 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "proximity_monitor.h"
+
+#define PROXIMITY_MONITOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PROXIMITY_MONITOR_TYPE, ProximityMonitorPrivate))
+
+struct _ProximityMonitorPrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ProximityMonitor, proximity_monitor, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _proximity_monitor_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _proximity_monitor_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _proximity_monitor_create_gdbus_proxy(ProximityMonitor *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void proximity_monitor_dispose(GObject *gobject)
+{
+ ProximityMonitor *self = PROXIMITY_MONITOR(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(proximity_monitor_parent_class)->dispose(gobject);
+}
+
+static void proximity_monitor_finalize (GObject *gobject)
+{
+ ProximityMonitor *self = PROXIMITY_MONITOR(gobject);
+ G_OBJECT_CLASS(proximity_monitor_parent_class)->finalize(gobject);
+}
+
+static void proximity_monitor_class_init(ProximityMonitorClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = proximity_monitor_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _proximity_monitor_get_property;
+ gobject_class->set_property = _proximity_monitor_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ProximityMonitor D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void proximity_monitor_init(ProximityMonitor *self)
+{
+ self->priv = proximity_monitor_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _proximity_monitor_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ProximityMonitor *self = PROXIMITY_MONITOR(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, proximity_monitor_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _proximity_monitor_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ProximityMonitor *self = PROXIMITY_MONITOR(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _proximity_monitor_create_gdbus_proxy(self, PROXIMITY_MONITOR_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ProximityMonitor *proximity_monitor_new(const gchar *dbus_object_path)
+{
+ return g_object_new(PROXIMITY_MONITOR_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _proximity_monitor_create_gdbus_proxy(ProximityMonitor *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(PROXIMITY_MONITOR_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, PROXIMITY_MONITOR_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *proximity_monitor_get_dbus_object_path(ProximityMonitor *self)
+{
+ g_assert(PROXIMITY_MONITOR_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+
+
+/* Properties access methods */
+GVariant *proximity_monitor_get_properties(ProximityMonitor *self, GError **error)
+{
+ g_assert(PROXIMITY_MONITOR_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, PROXIMITY_MONITOR_DBUS_INTERFACE, error);
+}
+
+void proximity_monitor_set_property(ProximityMonitor *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(PROXIMITY_MONITOR_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, PROXIMITY_MONITOR_DBUS_INTERFACE, name, value, error);
+}
+
+const gchar *proximity_monitor_get_immediate_alert_level(ProximityMonitor *self, GError **error)
+{
+ g_assert(PROXIMITY_MONITOR_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, PROXIMITY_MONITOR_DBUS_INTERFACE, "ImmediateAlertLevel", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+void proximity_monitor_set_immediate_alert_level(ProximityMonitor *self, const gchar *value, GError **error)
+{
+ g_assert(PROXIMITY_MONITOR_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, PROXIMITY_MONITOR_DBUS_INTERFACE, "ImmediateAlertLevel", g_variant_new_string(value), error);
+}
+
+const gchar *proximity_monitor_get_link_loss_alert_level(ProximityMonitor *self, GError **error)
+{
+ g_assert(PROXIMITY_MONITOR_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, PROXIMITY_MONITOR_DBUS_INTERFACE, "LinkLossAlertLevel", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+void proximity_monitor_set_link_loss_alert_level(ProximityMonitor *self, const gchar *value, GError **error)
+{
+ g_assert(PROXIMITY_MONITOR_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, PROXIMITY_MONITOR_DBUS_INTERFACE, "LinkLossAlertLevel", g_variant_new_string(value), error);
+}
+
+const gchar *proximity_monitor_get_signal_level(ProximityMonitor *self, GError **error)
+{
+ g_assert(PROXIMITY_MONITOR_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, PROXIMITY_MONITOR_DBUS_INTERFACE, "SignalLevel", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/proximity_monitor.h b/src/lib/bluez/proximity_monitor.h
new file mode 100644
index 0000000..ffa5df2
--- /dev/null
+++ b/src/lib/bluez/proximity_monitor.h
@@ -0,0 +1,88 @@
+/*
+ *
+ * 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 __PROXIMITY_MONITOR_H
+#define __PROXIMITY_MONITOR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define PROXIMITY_MONITOR_DBUS_SERVICE "org.bluez"
+#define PROXIMITY_MONITOR_DBUS_INTERFACE "org.bluez.ProximityMonitor1"
+
+/*
+ * Type macros
+ */
+#define PROXIMITY_MONITOR_TYPE (proximity_monitor_get_type())
+#define PROXIMITY_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PROXIMITY_MONITOR_TYPE, ProximityMonitor))
+#define PROXIMITY_MONITOR_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PROXIMITY_MONITOR_TYPE))
+#define PROXIMITY_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PROXIMITY_MONITOR_TYPE, ProximityMonitorClass))
+#define PROXIMITY_MONITOR_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PROXIMITY_MONITOR_TYPE))
+#define PROXIMITY_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PROXIMITY_MONITOR_TYPE, ProximityMonitorClass))
+
+typedef struct _ProximityMonitor ProximityMonitor;
+typedef struct _ProximityMonitorClass ProximityMonitorClass;
+typedef struct _ProximityMonitorPrivate ProximityMonitorPrivate;
+
+struct _ProximityMonitor {
+ GObject parent_instance;
+
+ /*< private >*/
+ ProximityMonitorPrivate *priv;
+};
+
+struct _ProximityMonitorClass {
+ GObjectClass parent_class;
+};
+
+/* used by PROXIMITY_MONITOR_TYPE */
+GType proximity_monitor_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ProximityMonitor *proximity_monitor_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *proximity_monitor_get_dbus_object_path(ProximityMonitor *self);
+
+GVariant *proximity_monitor_get_properties(ProximityMonitor *self, GError **error);
+void proximity_monitor_set_property(ProximityMonitor *self, const gchar *name, const GVariant *value, GError **error);
+
+const gchar *proximity_monitor_get_immediate_alert_level(ProximityMonitor *self, GError **error);
+void proximity_monitor_set_immediate_alert_level(ProximityMonitor *self, const gchar *value, GError **error);
+const gchar *proximity_monitor_get_link_loss_alert_level(ProximityMonitor *self, GError **error);
+void proximity_monitor_set_link_loss_alert_level(ProximityMonitor *self, const gchar *value, GError **error);
+const gchar *proximity_monitor_get_signal_level(ProximityMonitor *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PROXIMITY_MONITOR_H */
+
diff --git a/src/lib/bluez/proximity_reporter.c b/src/lib/bluez/proximity_reporter.c
new file mode 100644
index 0000000..2b6a2b0
--- /dev/null
+++ b/src/lib/bluez/proximity_reporter.c
@@ -0,0 +1,210 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "proximity_reporter.h"
+
+#define PROXIMITY_REPORTER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PROXIMITY_REPORTER_TYPE, ProximityReporterPrivate))
+
+struct _ProximityReporterPrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ProximityReporter, proximity_reporter, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _proximity_reporter_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _proximity_reporter_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _proximity_reporter_create_gdbus_proxy(ProximityReporter *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void proximity_reporter_dispose(GObject *gobject)
+{
+ ProximityReporter *self = PROXIMITY_REPORTER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(proximity_reporter_parent_class)->dispose(gobject);
+}
+
+static void proximity_reporter_finalize (GObject *gobject)
+{
+ ProximityReporter *self = PROXIMITY_REPORTER(gobject);
+ G_OBJECT_CLASS(proximity_reporter_parent_class)->finalize(gobject);
+}
+
+static void proximity_reporter_class_init(ProximityReporterClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = proximity_reporter_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _proximity_reporter_get_property;
+ gobject_class->set_property = _proximity_reporter_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ProximityReporter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void proximity_reporter_init(ProximityReporter *self)
+{
+ self->priv = proximity_reporter_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _proximity_reporter_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ProximityReporter *self = PROXIMITY_REPORTER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, proximity_reporter_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _proximity_reporter_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ProximityReporter *self = PROXIMITY_REPORTER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _proximity_reporter_create_gdbus_proxy(self, PROXIMITY_REPORTER_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ProximityReporter *proximity_reporter_new(const gchar *dbus_object_path)
+{
+ return g_object_new(PROXIMITY_REPORTER_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _proximity_reporter_create_gdbus_proxy(ProximityReporter *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(PROXIMITY_REPORTER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, PROXIMITY_REPORTER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *proximity_reporter_get_dbus_object_path(ProximityReporter *self)
+{
+ g_assert(PROXIMITY_REPORTER_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+
+
+/* Properties access methods */
+GVariant *proximity_reporter_get_properties(ProximityReporter *self, GError **error)
+{
+ g_assert(PROXIMITY_REPORTER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, PROXIMITY_REPORTER_DBUS_INTERFACE, error);
+}
+
+void proximity_reporter_set_property(ProximityReporter *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(PROXIMITY_REPORTER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, PROXIMITY_REPORTER_DBUS_INTERFACE, name, value, error);
+}
+
+const gchar *proximity_reporter_get_immediate_alert_level(ProximityReporter *self, GError **error)
+{
+ g_assert(PROXIMITY_REPORTER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, PROXIMITY_REPORTER_DBUS_INTERFACE, "ImmediateAlertLevel", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
+const gchar *proximity_reporter_get_link_loss_alert_level(ProximityReporter *self, GError **error)
+{
+ g_assert(PROXIMITY_REPORTER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, PROXIMITY_REPORTER_DBUS_INTERFACE, "LinkLossAlertLevel", error);
+ if(prop == NULL)
+ return NULL;
+ const gchar *ret = g_variant_get_string(prop, NULL);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/proximity_reporter.h b/src/lib/bluez/proximity_reporter.h
new file mode 100644
index 0000000..99a2498
--- /dev/null
+++ b/src/lib/bluez/proximity_reporter.h
@@ -0,0 +1,85 @@
+/*
+ *
+ * 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 __PROXIMITY_REPORTER_H
+#define __PROXIMITY_REPORTER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define PROXIMITY_REPORTER_DBUS_SERVICE "org.bluez"
+#define PROXIMITY_REPORTER_DBUS_INTERFACE "org.bluez.ProximityReporter1"
+
+/*
+ * Type macros
+ */
+#define PROXIMITY_REPORTER_TYPE (proximity_reporter_get_type())
+#define PROXIMITY_REPORTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PROXIMITY_REPORTER_TYPE, ProximityReporter))
+#define PROXIMITY_REPORTER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PROXIMITY_REPORTER_TYPE))
+#define PROXIMITY_REPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PROXIMITY_REPORTER_TYPE, ProximityReporterClass))
+#define PROXIMITY_REPORTER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PROXIMITY_REPORTER_TYPE))
+#define PROXIMITY_REPORTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PROXIMITY_REPORTER_TYPE, ProximityReporterClass))
+
+typedef struct _ProximityReporter ProximityReporter;
+typedef struct _ProximityReporterClass ProximityReporterClass;
+typedef struct _ProximityReporterPrivate ProximityReporterPrivate;
+
+struct _ProximityReporter {
+ GObject parent_instance;
+
+ /*< private >*/
+ ProximityReporterPrivate *priv;
+};
+
+struct _ProximityReporterClass {
+ GObjectClass parent_class;
+};
+
+/* used by PROXIMITY_REPORTER_TYPE */
+GType proximity_reporter_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ProximityReporter *proximity_reporter_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *proximity_reporter_get_dbus_object_path(ProximityReporter *self);
+
+GVariant *proximity_reporter_get_properties(ProximityReporter *self, GError **error);
+void proximity_reporter_set_property(ProximityReporter *self, const gchar *name, const GVariant *value, GError **error);
+
+const gchar *proximity_reporter_get_immediate_alert_level(ProximityReporter *self, GError **error);
+const gchar *proximity_reporter_get_link_loss_alert_level(ProximityReporter *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PROXIMITY_REPORTER_H */
+
diff --git a/src/lib/bluez/serial.c b/src/lib/bluez/serial.c
deleted file mode 100644
index 03f9e4e..0000000
--- a/src/lib/bluez/serial.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "serial.h"
-
-#define SERIAL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), SERIAL_TYPE, SerialPrivate))
-
-struct _SerialPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-};
-
-G_DEFINE_TYPE(Serial, serial, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
-};
-
-static void _serial_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _serial_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-static void serial_dispose(GObject *gobject)
-{
- Serial *self = SERIAL(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(serial_parent_class)->dispose(gobject);
-}
-
-static void serial_class_init(SerialClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = serial_dispose;
-
- g_type_class_add_private(klass, sizeof(SerialPrivate));
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _serial_get_property;
- gobject_class->set_property = _serial_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);
-}
-
-static void serial_init(Serial *self)
-{
- self->priv = SERIAL_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(system_conn != NULL);
-}
-
-static void serial_post_init(Serial *self, const gchar *dbus_object_path)
-{
- 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(system_conn, "org.bluez", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", SERIAL_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", SERIAL_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, SERIAL_DBUS_INTERFACE);
-}
-
-static void _serial_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- Serial *self = SERIAL(object);
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- g_value_set_string(value, serial_get_dbus_object_path(self));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _serial_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- Serial *self = SERIAL(object);
- GError *error = NULL;
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- serial_post_init(self, g_value_get_string(value));
- 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);
-}
-
-/* Methods */
-
-/* string Connect(string pattern) */
-gchar *serial_connect(Serial *self, const gchar *pattern, GError **error)
-{
- g_assert(SERIAL_IS(self));
-
- gchar *ret = NULL;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Connect", error, G_TYPE_STRING, pattern, G_TYPE_INVALID, G_TYPE_STRING, &ret, G_TYPE_INVALID);
-
- return ret;
-}
-
-/* void Disconnect(string device) */
-void serial_disconnect(Serial *self, const gchar *device, GError **error)
-{
- g_assert(SERIAL_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Disconnect", error, G_TYPE_STRING, device, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* Properties access methods */
-const gchar *serial_get_dbus_object_path(Serial *self)
-{
- g_assert(SERIAL_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
-}
-
diff --git a/src/lib/bluez/serial.h b/src/lib/bluez/serial.h
deleted file mode 100644
index d9f850b..0000000
--- a/src/lib/bluez/serial.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- *
- * 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 __SERIAL_H
-#define __SERIAL_H
-
-#include <glib-object.h>
-
-#define SERIAL_DBUS_INTERFACE "org.bluez.Serial"
-
-/*
- * Type macros
- */
-#define SERIAL_TYPE (serial_get_type())
-#define SERIAL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SERIAL_TYPE, Serial))
-#define SERIAL_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SERIAL_TYPE))
-#define SERIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SERIAL_TYPE, SerialClass))
-#define SERIAL_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SERIAL_TYPE))
-#define SERIAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), SERIAL_TYPE, SerialClass))
-
-typedef struct _Serial Serial;
-typedef struct _SerialClass SerialClass;
-typedef struct _SerialPrivate SerialPrivate;
-
-struct _Serial {
- GObject parent_instance;
-
- /*< private >*/
- SerialPrivate *priv;
-};
-
-struct _SerialClass {
- GObjectClass parent_class;
-};
-
-/* used by SERIAL_TYPE */
-GType serial_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-gchar *serial_connect(Serial *self, const gchar *pattern, GError **error);
-void serial_disconnect(Serial *self, const gchar *device, GError **error);
-
-const gchar *serial_get_dbus_object_path(Serial *self);
-
-#endif /* __SERIAL_H */
-
diff --git a/src/lib/bluez/sim_access.c b/src/lib/bluez/sim_access.c
new file mode 100644
index 0000000..2c585c7
--- /dev/null
+++ b/src/lib/bluez/sim_access.c
@@ -0,0 +1,203 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "sim_access.h"
+
+#define SIM_ACCESS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), SIM_ACCESS_TYPE, SimAccessPrivate))
+
+struct _SimAccessPrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(SimAccess, sim_access, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _sim_access_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _sim_access_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _sim_access_create_gdbus_proxy(SimAccess *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void sim_access_dispose(GObject *gobject)
+{
+ SimAccess *self = SIM_ACCESS(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(sim_access_parent_class)->dispose(gobject);
+}
+
+static void sim_access_finalize (GObject *gobject)
+{
+ SimAccess *self = SIM_ACCESS(gobject);
+ G_OBJECT_CLASS(sim_access_parent_class)->finalize(gobject);
+}
+
+static void sim_access_class_init(SimAccessClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = sim_access_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _sim_access_get_property;
+ gobject_class->set_property = _sim_access_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "SimAccess D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void sim_access_init(SimAccess *self)
+{
+ self->priv = sim_access_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _sim_access_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ SimAccess *self = SIM_ACCESS(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, sim_access_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _sim_access_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ SimAccess *self = SIM_ACCESS(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _sim_access_create_gdbus_proxy(self, SIM_ACCESS_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+SimAccess *sim_access_new(const gchar *dbus_object_path)
+{
+ return g_object_new(SIM_ACCESS_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _sim_access_create_gdbus_proxy(SimAccess *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(SIM_ACCESS_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, SIM_ACCESS_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *sim_access_get_dbus_object_path(SimAccess *self)
+{
+ g_assert(SIM_ACCESS_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+/* void Disconnect() */
+void sim_access_disconnect(SimAccess *self, GError **error)
+{
+ g_assert(SIM_ACCESS_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Disconnect", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+/* Properties access methods */
+GVariant *sim_access_get_properties(SimAccess *self, GError **error)
+{
+ g_assert(SIM_ACCESS_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, SIM_ACCESS_DBUS_INTERFACE, error);
+}
+
+void sim_access_set_property(SimAccess *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(SIM_ACCESS_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, SIM_ACCESS_DBUS_INTERFACE, name, value, error);
+}
+
+gboolean sim_access_get_connected(SimAccess *self, GError **error)
+{
+ g_assert(SIM_ACCESS_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, SIM_ACCESS_DBUS_INTERFACE, "Connected", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/sim_access.h b/src/lib/bluez/sim_access.h
new file mode 100644
index 0000000..0c2a874
--- /dev/null
+++ b/src/lib/bluez/sim_access.h
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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 __SIM_ACCESS_H
+#define __SIM_ACCESS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define SIM_ACCESS_DBUS_SERVICE "org.bluez"
+#define SIM_ACCESS_DBUS_INTERFACE "org.bluez.SimAccess1"
+
+/*
+ * Type macros
+ */
+#define SIM_ACCESS_TYPE (sim_access_get_type())
+#define SIM_ACCESS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SIM_ACCESS_TYPE, SimAccess))
+#define SIM_ACCESS_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SIM_ACCESS_TYPE))
+#define SIM_ACCESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SIM_ACCESS_TYPE, SimAccessClass))
+#define SIM_ACCESS_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SIM_ACCESS_TYPE))
+#define SIM_ACCESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), SIM_ACCESS_TYPE, SimAccessClass))
+
+typedef struct _SimAccess SimAccess;
+typedef struct _SimAccessClass SimAccessClass;
+typedef struct _SimAccessPrivate SimAccessPrivate;
+
+struct _SimAccess {
+ GObject parent_instance;
+
+ /*< private >*/
+ SimAccessPrivate *priv;
+};
+
+struct _SimAccessClass {
+ GObjectClass parent_class;
+};
+
+/* used by SIM_ACCESS_TYPE */
+GType sim_access_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+SimAccess *sim_access_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *sim_access_get_dbus_object_path(SimAccess *self);
+
+void sim_access_disconnect(SimAccess *self, GError **error);
+
+GVariant *sim_access_get_properties(SimAccess *self, GError **error);
+void sim_access_set_property(SimAccess *self, const gchar *name, const GVariant *value, GError **error);
+
+gboolean sim_access_get_connected(SimAccess *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SIM_ACCESS_H */
+
diff --git a/src/lib/bluez/thermometer.c b/src/lib/bluez/thermometer.c
new file mode 100644
index 0000000..6e0bd20
--- /dev/null
+++ b/src/lib/bluez/thermometer.c
@@ -0,0 +1,198 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "thermometer.h"
+
+#define THERMOMETER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), THERMOMETER_TYPE, ThermometerPrivate))
+
+struct _ThermometerPrivate {
+ GDBusProxy *proxy;
+ Properties *properties;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(Thermometer, thermometer, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _thermometer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _thermometer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _thermometer_create_gdbus_proxy(Thermometer *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void thermometer_dispose(GObject *gobject)
+{
+ Thermometer *self = THERMOMETER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Properties free */
+ g_clear_object(&self->priv->properties);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(thermometer_parent_class)->dispose(gobject);
+}
+
+static void thermometer_finalize (GObject *gobject)
+{
+ Thermometer *self = THERMOMETER(gobject);
+ G_OBJECT_CLASS(thermometer_parent_class)->finalize(gobject);
+}
+
+static void thermometer_class_init(ThermometerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = thermometer_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _thermometer_get_property;
+ gobject_class->set_property = _thermometer_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Thermometer D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void thermometer_init(Thermometer *self)
+{
+ self->priv = thermometer_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->properties = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _thermometer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ Thermometer *self = THERMOMETER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, thermometer_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _thermometer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ Thermometer *self = THERMOMETER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _thermometer_create_gdbus_proxy(self, THERMOMETER_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+Thermometer *thermometer_new(const gchar *dbus_object_path)
+{
+ return g_object_new(THERMOMETER_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _thermometer_create_gdbus_proxy(Thermometer *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(THERMOMETER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, THERMOMETER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+
+ self->priv->properties = g_object_new(PROPERTIES_TYPE, "DBusType", "system", "DBusServiceName", dbus_service_name, "DBusObjectPath", dbus_object_path, NULL);
+ g_assert(self->priv->properties != NULL);
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *thermometer_get_dbus_object_path(Thermometer *self)
+{
+ g_assert(THERMOMETER_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+
+
+/* Properties access methods */
+GVariant *thermometer_get_properties(Thermometer *self, GError **error)
+{
+ g_assert(THERMOMETER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ return properties_get_all(self->priv->properties, THERMOMETER_DBUS_INTERFACE, error);
+}
+
+void thermometer_set_property(Thermometer *self, const gchar *name, const GVariant *value, GError **error)
+{
+ g_assert(THERMOMETER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ properties_set(self->priv->properties, THERMOMETER_DBUS_INTERFACE, name, value, error);
+}
+
+gboolean thermometer_get_intermediate(Thermometer *self, GError **error)
+{
+ g_assert(THERMOMETER_IS(self));
+ g_assert(self->priv->properties != NULL);
+ GVariant *prop = properties_get(self->priv->properties, THERMOMETER_DBUS_INTERFACE, "Intermediate", error);
+ if(prop == NULL)
+ return FALSE;
+ gboolean ret = g_variant_get_boolean(prop);
+ g_variant_unref(prop);
+ return ret;
+}
+
diff --git a/src/lib/bluez/thermometer.h b/src/lib/bluez/thermometer.h
new file mode 100644
index 0000000..c3acb30
--- /dev/null
+++ b/src/lib/bluez/thermometer.h
@@ -0,0 +1,84 @@
+/*
+ *
+ * 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 __THERMOMETER_H
+#define __THERMOMETER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define THERMOMETER_DBUS_SERVICE "org.bluez"
+#define THERMOMETER_DBUS_INTERFACE "org.bluez.Thermometer1"
+
+/*
+ * Type macros
+ */
+#define THERMOMETER_TYPE (thermometer_get_type())
+#define THERMOMETER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), THERMOMETER_TYPE, Thermometer))
+#define THERMOMETER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), THERMOMETER_TYPE))
+#define THERMOMETER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), THERMOMETER_TYPE, ThermometerClass))
+#define THERMOMETER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), THERMOMETER_TYPE))
+#define THERMOMETER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), THERMOMETER_TYPE, ThermometerClass))
+
+typedef struct _Thermometer Thermometer;
+typedef struct _ThermometerClass ThermometerClass;
+typedef struct _ThermometerPrivate ThermometerPrivate;
+
+struct _Thermometer {
+ GObject parent_instance;
+
+ /*< private >*/
+ ThermometerPrivate *priv;
+};
+
+struct _ThermometerClass {
+ GObjectClass parent_class;
+};
+
+/* used by THERMOMETER_TYPE */
+GType thermometer_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+Thermometer *thermometer_new(const gchar *dbus_object_path);
+
+/*
+ * Method definitions
+ */
+const gchar *thermometer_get_dbus_object_path(Thermometer *self);
+
+GVariant *thermometer_get_properties(Thermometer *self, GError **error);
+void thermometer_set_property(Thermometer *self, const gchar *name, const GVariant *value, GError **error);
+
+gboolean thermometer_get_intermediate(Thermometer *self, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __THERMOMETER_H */
+
diff --git a/src/lib/bluez/thermometer_manager.c b/src/lib/bluez/thermometer_manager.c
new file mode 100644
index 0000000..1f5c376
--- /dev/null
+++ b/src/lib/bluez/thermometer_manager.c
@@ -0,0 +1,162 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <string.h>
+
+#include "../dbus-common.h"
+#include "../properties.h"
+
+#include "thermometer_manager.h"
+
+#define THERMOMETER_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), THERMOMETER_MANAGER_TYPE, ThermometerManagerPrivate))
+
+struct _ThermometerManagerPrivate {
+ GDBusProxy *proxy;
+ gchar *object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ThermometerManager, thermometer_manager, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
+};
+
+static void _thermometer_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _thermometer_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _thermometer_manager_create_gdbus_proxy(ThermometerManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error);
+
+static void thermometer_manager_dispose(GObject *gobject)
+{
+ ThermometerManager *self = THERMOMETER_MANAGER(gobject);
+
+ /* Proxy free */
+ g_clear_object (&self->priv->proxy);
+ /* Object path free */
+ g_free(self->priv->object_path);
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(thermometer_manager_parent_class)->dispose(gobject);
+}
+
+static void thermometer_manager_finalize (GObject *gobject)
+{
+ ThermometerManager *self = THERMOMETER_MANAGER(gobject);
+ G_OBJECT_CLASS(thermometer_manager_parent_class)->finalize(gobject);
+}
+
+static void thermometer_manager_class_init(ThermometerManagerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = thermometer_manager_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _thermometer_manager_get_property;
+ gobject_class->set_property = _thermometer_manager_set_property;
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "ThermometerManager D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec);
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void thermometer_manager_init(ThermometerManager *self)
+{
+ self->priv = thermometer_manager_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->object_path = NULL;
+ g_assert(system_conn != NULL);
+}
+
+static void _thermometer_manager_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ThermometerManager *self = THERMOMETER_MANAGER(object);
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, thermometer_manager_get_dbus_object_path(self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _thermometer_manager_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ThermometerManager *self = THERMOMETER_MANAGER(object);
+ GError *error = NULL;
+
+ switch (property_id) {
+ case PROP_DBUS_OBJECT_PATH:
+ self->priv->object_path = g_value_dup_string(value);
+ _thermometer_manager_create_gdbus_proxy(self, THERMOMETER_MANAGER_DBUS_SERVICE, self->priv->object_path, &error);
+ 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);
+}
+
+/* Constructor */
+ThermometerManager *thermometer_manager_new(const gchar *dbus_object_path)
+{
+ return g_object_new(THERMOMETER_MANAGER_TYPE, "DBusObjectPath", dbus_object_path, NULL);
+}
+
+/* Private DBus proxy creation */
+static void _thermometer_manager_create_gdbus_proxy(ThermometerManager *self, const gchar *dbus_service_name, const gchar *dbus_object_path, GError **error)
+{
+ g_assert(THERMOMETER_MANAGER_IS(self));
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, THERMOMETER_MANAGER_DBUS_INTERFACE, NULL, error);
+
+ if(self->priv->proxy == NULL)
+ return;
+}
+
+/* Methods */
+
+/* Get DBus object path */
+const gchar *thermometer_manager_get_dbus_object_path(ThermometerManager *self)
+{
+ g_assert(THERMOMETER_MANAGER_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
diff --git a/src/lib/bluez/thermometer_manager.h b/src/lib/bluez/thermometer_manager.h
new file mode 100644
index 0000000..5bed406
--- /dev/null
+++ b/src/lib/bluez/thermometer_manager.h
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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 __THERMOMETER_MANAGER_H
+#define __THERMOMETER_MANAGER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define THERMOMETER_MANAGER_DBUS_SERVICE "org.bluez"
+#define THERMOMETER_MANAGER_DBUS_INTERFACE "org.bluez.ThermometerManager1"
+
+/*
+ * Type macros
+ */
+#define THERMOMETER_MANAGER_TYPE (thermometer_manager_get_type())
+#define THERMOMETER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), THERMOMETER_MANAGER_TYPE, ThermometerManager))
+#define THERMOMETER_MANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), THERMOMETER_MANAGER_TYPE))
+#define THERMOMETER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), THERMOMETER_MANAGER_TYPE, ThermometerManagerClass))
+#define THERMOMETER_MANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), THERMOMETER_MANAGER_TYPE))
+#define THERMOMETER_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), THERMOMETER_MANAGER_TYPE, ThermometerManagerClass))
+
+typedef struct _ThermometerManager ThermometerManager;
+typedef struct _ThermometerManagerClass ThermometerManagerClass;
+typedef struct _ThermometerManagerPrivate ThermometerManagerPrivate;
+
+struct _ThermometerManager {
+ GObject parent_instance;
+
+ /*< private >*/
+ ThermometerManagerPrivate *priv;
+};
+
+struct _ThermometerManagerClass {
+ GObjectClass parent_class;
+};
+
+/* used by THERMOMETER_MANAGER_TYPE */
+GType thermometer_manager_get_type(void) G_GNUC_CONST;
+
+/*
+ * Constructor
+ */
+ThermometerManager *thermometer_manager_new(const gchar *dbus_object_path);
+const gchar *thermometer_manager_get_dbus_object_path(ThermometerManager *self);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __THERMOMETER_MANAGER_H */
+
diff --git a/src/lib/dbus-common.c b/src/lib/dbus-common.c
index 1ebc56d..bca4039 100644
--- a/src/lib/dbus-common.c
+++ b/src/lib/dbus-common.c
@@ -1,102 +1,63 @@
-/*
- *
- * 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 <glib.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
#include "bluez-api.h"
-#ifdef OBEX_SUPPORT
-#include "obexd-api.h"
-#endif
#include "dbus-common.h"
-DBusGConnection *session_conn = NULL;
-DBusGConnection *system_conn = NULL;
+GDBusConnection *session_conn = NULL;
+GDBusConnection *system_conn = NULL;
static gboolean dbus_initialized = FALSE;
void dbus_init()
{
- /* Marshallers registration
- * Used for signals
- */
- dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__STRING_BOXED, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
- dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__INT_INT, G_TYPE_NONE, G_TYPE_INT, G_TYPE_INT, G_TYPE_INVALID);
- dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__BOXED_BOOLEAN, G_TYPE_NONE, G_TYPE_VALUE, G_TYPE_BOOLEAN, G_TYPE_INVALID);
-
- /* Agents installation */
- dbus_g_object_type_install_info(AGENT_TYPE, &dbus_glib_agent_object_info);
-#ifdef OBEX_SUPPORT
- dbus_g_object_type_install_info(OBEXAGENT_TYPE, &dbus_glib_obexagent_object_info);
-#endif
-
- dbus_initialized = TRUE;
+ dbus_initialized = TRUE;
}
gboolean dbus_session_connect(GError **error)
{
- g_assert(dbus_initialized == TRUE);
+ g_assert(dbus_initialized == TRUE);
- session_conn = dbus_g_bus_get(DBUS_BUS_SESSION, error);
- if (!session_conn) {
- return FALSE;
- }
+ session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error);
+ if (!session_conn)
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
void dbus_session_disconnect()
{
- dbus_g_connection_unref(session_conn);
+ g_object_unref(session_conn);
}
gboolean dbus_system_connect(GError **error)
{
- g_assert(dbus_initialized == TRUE);
+ g_assert(dbus_initialized == TRUE);
- system_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, error);
- if (!system_conn) {
- return FALSE;
- }
+ system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
+ if (!system_conn)
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
void dbus_system_disconnect()
{
- dbus_g_connection_unref(system_conn);
+ g_object_unref(system_conn);
}
void dbus_disconnect()
{
- if (system_conn)
- dbus_g_connection_unref(system_conn);
- if (session_conn)
- dbus_g_connection_unref(session_conn);
+ if (system_conn)
+ dbus_system_disconnect();
+ if (session_conn)
+ dbus_session_disconnect();
}
-
diff --git a/src/lib/dbus-common.h b/src/lib/dbus-common.h
index ad4e210..a9bacdf 100644
--- a/src/lib/dbus-common.h
+++ b/src/lib/dbus-common.h
@@ -1,38 +1,14 @@
-/*
- *
- * 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 DBUS_COMMON_H
+#define DBUS_COMMON_H
-#ifndef __DBUS_COMMON_H
-#define __DBUS_COMMON_H
+#ifdef __cplusplus
+extern "C" {
+#endif
-#include <glib.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
-#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
-#define DBUS_TYPE_G_UINT_STRING_HASHTABLE (dbus_g_type_get_map("GHashTable", G_TYPE_UINT, G_TYPE_STRING))
-#define DBUS_TYPE_G_HASH_TABLE_ARRAY (dbus_g_type_get_collection("GPtrArray", DBUS_TYPE_G_STRING_VARIANT_HASHTABLE))
-
-extern DBusGConnection *session_conn;
-extern DBusGConnection *system_conn;
+extern GDBusConnection *session_conn;
+extern GDBusConnection *system_conn;
void dbus_init();
gboolean dbus_session_connect(GError **error);
@@ -41,5 +17,9 @@ gboolean dbus_system_connect(GError **error);
void dbus_system_disconnect();
void dbus_disconnect();
-#endif /* __DBUS_COMMON_H */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* DBUS_COMMON_H */
diff --git a/src/lib/helpers.c b/src/lib/helpers.c
index 9dea90f..7402807 100644
--- a/src/lib/helpers.c
+++ b/src/lib/helpers.c
@@ -31,81 +31,82 @@
#include <sys/stat.h>
#include <errno.h>
+#include <gio/gio.h>
#include <glib.h>
-#include <dbus/dbus-glib.h>
#include "dbus-common.h"
#include "helpers.h"
/* UUID Name lookup table */
-typedef struct {
- gchar *uuid;
- gchar *name;
- gchar *alt_name;
+typedef struct
+{
+ gchar *uuid;
+ gchar *name;
+ gchar *alt_name;
} uuid_name_lookup_table_t;
static uuid_name_lookup_table_t uuid_name_lookup_table[] = {
- {"00001000-0000-1000-8000-00805F9B34FB", "ServiceDiscoveryServer", NULL},
- {"00001001-0000-1000-8000-00805F9B34FB", "BrowseGroupDescriptor", NULL},
- {"00001002-0000-1000-8000-00805F9B34FB", "PublicBrowseGroup", NULL},
- {"00001101-0000-1000-8000-00805F9B34FB", "SerialPort", "Serial"},
- {"00001102-0000-1000-8000-00805F9B34FB", "LANAccessUsingPPP", NULL},
- {"00001103-0000-1000-8000-00805F9B34FB", "DialupNetworking", "DUN"},
- {"00001104-0000-1000-8000-00805F9B34FB", "IrMCSync", NULL},
- {"00001105-0000-1000-8000-00805F9B34FB", "OBEXObjectPush", NULL},
- {"00001106-0000-1000-8000-00805F9B34FB", "OBEXFileTransfer", NULL},
- {"00001107-0000-1000-8000-00805F9B34FB", "IrMCSyncCommand", NULL},
- {"00001108-0000-1000-8000-00805F9B34FB", "Headset", NULL},
- {"00001109-0000-1000-8000-00805F9B34FB", "CordlessTelephony", NULL},
- {"0000110A-0000-1000-8000-00805F9B34FB", "AudioSource", NULL},
- {"0000110B-0000-1000-8000-00805F9B34FB", "AudioSink", NULL},
- {"0000110C-0000-1000-8000-00805F9B34FB", "AVRemoteControlTarget", NULL},
- {"0000110D-0000-1000-8000-00805F9B34FB", "AdvancedAudioDistribution", "A2DP"},
- {"0000110E-0000-1000-8000-00805F9B34FB", "AVRemoteControl", NULL},
- {"0000110F-0000-1000-8000-00805F9B34FB", "VideoConferencing", NULL},
- {"00001110-0000-1000-8000-00805F9B34FB", "Intercom", NULL},
- {"00001111-0000-1000-8000-00805F9B34FB", "Fax", NULL},
- {"00001112-0000-1000-8000-00805F9B34FB", "HeadsetAudioGateway", NULL},
- {"00001113-0000-1000-8000-00805F9B34FB", "WAP", NULL},
- {"00001114-0000-1000-8000-00805F9B34FB", "WAPClient", NULL},
- {"00001115-0000-1000-8000-00805F9B34FB", "PANU", NULL},
- {"00001116-0000-1000-8000-00805F9B34FB", "NAP", NULL},
- {"00001117-0000-1000-8000-00805F9B34FB", "GN", NULL},
- {"00001118-0000-1000-8000-00805F9B34FB", "DirectPrinting", NULL},
- {"00001119-0000-1000-8000-00805F9B34FB", "ReferencePrinting", NULL},
- {"0000111A-0000-1000-8000-00805F9B34FB", "Imaging", NULL},
- {"0000111B-0000-1000-8000-00805F9B34FB", "ImagingResponder", NULL},
- {"0000111C-0000-1000-8000-00805F9B34FB", "ImagingAutomaticArchive", NULL},
- {"0000111D-0000-1000-8000-00805F9B34FB", "ImagingReferenceObjects", NULL},
- {"0000111E-0000-1000-8000-00805F9B34FB", "Handsfree", NULL},
- {"0000111F-0000-1000-8000-00805F9B34FB", "HandsfreeAudioGateway", NULL},
- {"00001120-0000-1000-8000-00805F9B34FB", "DirectPrintingReferenceObjects", NULL},
- {"00001121-0000-1000-8000-00805F9B34FB", "ReflectedUI", NULL},
- {"00001122-0000-1000-8000-00805F9B34FB", "BasicPringing", NULL},
- {"00001123-0000-1000-8000-00805F9B34FB", "PrintingStatus", NULL},
- {"00001124-0000-1000-8000-00805F9B34FB", "HumanInterfaceDevice", "HID"},
- {"00001125-0000-1000-8000-00805F9B34FB", "HardcopyCableReplacement", NULL},
- {"00001126-0000-1000-8000-00805F9B34FB", "HCRPrint", NULL},
- {"00001127-0000-1000-8000-00805F9B34FB", "HCRScan", NULL},
- {"00001128-0000-1000-8000-00805F9B34FB", "CommonISDNAccess", NULL},
- {"00001129-0000-1000-8000-00805F9B34FB", "VideoConferencingGW", NULL},
- {"0000112A-0000-1000-8000-00805F9B34FB", "UDIMT", NULL},
- {"0000112B-0000-1000-8000-00805F9B34FB", "UDITA", NULL},
- {"0000112C-0000-1000-8000-00805F9B34FB", "AudioVideo", NULL},
- {"00001200-0000-1000-8000-00805F9B34FB", "PnPInformation", NULL},
- {"00001201-0000-1000-8000-00805F9B34FB", "GenericNetworking", NULL},
- {"00001202-0000-1000-8000-00805F9B34FB", "GenericFileTransfer", NULL},
- {"00001203-0000-1000-8000-00805F9B34FB", "GenericAudio", NULL},
- {"00001204-0000-1000-8000-00805F9B34FB", "GenericTelephony", NULL},
- {"00001205-0000-1000-8000-00805F9B34FB", "UPnP", NULL},
- {"00001206-0000-1000-8000-00805F9B34FB", "UPnPIp", NULL},
- {"00001300-0000-1000-8000-00805F9B34FB", "ESdpUPnPIpPan", NULL},
- {"00001301-0000-1000-8000-00805F9B34FB", "ESdpUPnPIpLap", NULL},
- {"00001302-0000-1000-8000-00805F9B34FB", "EdpUPnpIpL2CAP", NULL},
-
- // Custom:
- {"0000112F-0000-1000-8000-00805F9B34FB", "PhoneBookAccess", NULL},
- {"831C4071-7BC8-4A9C-A01C-15DF25A4ADBC", "ActiveSync", NULL},
+ {"00001000-0000-1000-8000-00805F9B34FB", "ServiceDiscoveryServer", NULL},
+ {"00001001-0000-1000-8000-00805F9B34FB", "BrowseGroupDescriptor", NULL},
+ {"00001002-0000-1000-8000-00805F9B34FB", "PublicBrowseGroup", NULL},
+ {"00001101-0000-1000-8000-00805F9B34FB", "SerialPort", "Serial"},
+ {"00001102-0000-1000-8000-00805F9B34FB", "LANAccessUsingPPP", NULL},
+ {"00001103-0000-1000-8000-00805F9B34FB", "DialupNetworking", "DUN"},
+ {"00001104-0000-1000-8000-00805F9B34FB", "IrMCSync", NULL},
+ {"00001105-0000-1000-8000-00805F9B34FB", "OBEXObjectPush", NULL},
+ {"00001106-0000-1000-8000-00805F9B34FB", "OBEXFileTransfer", NULL},
+ {"00001107-0000-1000-8000-00805F9B34FB", "IrMCSyncCommand", NULL},
+ {"00001108-0000-1000-8000-00805F9B34FB", "Headset", NULL},
+ {"00001109-0000-1000-8000-00805F9B34FB", "CordlessTelephony", NULL},
+ {"0000110A-0000-1000-8000-00805F9B34FB", "AudioSource", NULL},
+ {"0000110B-0000-1000-8000-00805F9B34FB", "AudioSink", NULL},
+ {"0000110C-0000-1000-8000-00805F9B34FB", "AVRemoteControlTarget", NULL},
+ {"0000110D-0000-1000-8000-00805F9B34FB", "AdvancedAudioDistribution", "A2DP"},
+ {"0000110E-0000-1000-8000-00805F9B34FB", "AVRemoteControl", NULL},
+ {"0000110F-0000-1000-8000-00805F9B34FB", "VideoConferencing", NULL},
+ {"00001110-0000-1000-8000-00805F9B34FB", "Intercom", NULL},
+ {"00001111-0000-1000-8000-00805F9B34FB", "Fax", NULL},
+ {"00001112-0000-1000-8000-00805F9B34FB", "HeadsetAudioGateway", NULL},
+ {"00001113-0000-1000-8000-00805F9B34FB", "WAP", NULL},
+ {"00001114-0000-1000-8000-00805F9B34FB", "WAPClient", NULL},
+ {"00001115-0000-1000-8000-00805F9B34FB", "PANU", NULL},
+ {"00001116-0000-1000-8000-00805F9B34FB", "NAP", NULL},
+ {"00001117-0000-1000-8000-00805F9B34FB", "GN", NULL},
+ {"00001118-0000-1000-8000-00805F9B34FB", "DirectPrinting", NULL},
+ {"00001119-0000-1000-8000-00805F9B34FB", "ReferencePrinting", NULL},
+ {"0000111A-0000-1000-8000-00805F9B34FB", "Imaging", NULL},
+ {"0000111B-0000-1000-8000-00805F9B34FB", "ImagingResponder", NULL},
+ {"0000111C-0000-1000-8000-00805F9B34FB", "ImagingAutomaticArchive", NULL},
+ {"0000111D-0000-1000-8000-00805F9B34FB", "ImagingReferenceObjects", NULL},
+ {"0000111E-0000-1000-8000-00805F9B34FB", "Handsfree", NULL},
+ {"0000111F-0000-1000-8000-00805F9B34FB", "HandsfreeAudioGateway", NULL},
+ {"00001120-0000-1000-8000-00805F9B34FB", "DirectPrintingReferenceObjects", NULL},
+ {"00001121-0000-1000-8000-00805F9B34FB", "ReflectedUI", NULL},
+ {"00001122-0000-1000-8000-00805F9B34FB", "BasicPringing", NULL},
+ {"00001123-0000-1000-8000-00805F9B34FB", "PrintingStatus", NULL},
+ {"00001124-0000-1000-8000-00805F9B34FB", "HumanInterfaceDevice", "HID"},
+ {"00001125-0000-1000-8000-00805F9B34FB", "HardcopyCableReplacement", NULL},
+ {"00001126-0000-1000-8000-00805F9B34FB", "HCRPrint", NULL},
+ {"00001127-0000-1000-8000-00805F9B34FB", "HCRScan", NULL},
+ {"00001128-0000-1000-8000-00805F9B34FB", "CommonISDNAccess", NULL},
+ {"00001129-0000-1000-8000-00805F9B34FB", "VideoConferencingGW", NULL},
+ {"0000112A-0000-1000-8000-00805F9B34FB", "UDIMT", NULL},
+ {"0000112B-0000-1000-8000-00805F9B34FB", "UDITA", NULL},
+ {"0000112C-0000-1000-8000-00805F9B34FB", "AudioVideo", NULL},
+ {"00001200-0000-1000-8000-00805F9B34FB", "PnPInformation", NULL},
+ {"00001201-0000-1000-8000-00805F9B34FB", "GenericNetworking", NULL},
+ {"00001202-0000-1000-8000-00805F9B34FB", "GenericFileTransfer", NULL},
+ {"00001203-0000-1000-8000-00805F9B34FB", "GenericAudio", NULL},
+ {"00001204-0000-1000-8000-00805F9B34FB", "GenericTelephony", NULL},
+ {"00001205-0000-1000-8000-00805F9B34FB", "UPnP", NULL},
+ {"00001206-0000-1000-8000-00805F9B34FB", "UPnPIp", NULL},
+ {"00001300-0000-1000-8000-00805F9B34FB", "ESdpUPnPIpPan", NULL},
+ {"00001301-0000-1000-8000-00805F9B34FB", "ESdpUPnPIpLap", NULL},
+ {"00001302-0000-1000-8000-00805F9B34FB", "EdpUPnpIpL2CAP", NULL},
+
+ // Custom:
+ {"0000112F-0000-1000-8000-00805F9B34FB", "PhoneBookAccess", NULL},
+ {"831C4071-7BC8-4A9C-A01C-15DF25A4ADBC", "ActiveSync", NULL},
};
#define UUID_NAME_LOOKUP_TABLE_SIZE \
@@ -113,232 +114,346 @@ static uuid_name_lookup_table_t uuid_name_lookup_table[] = {
const gchar *uuid2name(const gchar *uuid)
{
- if (uuid == NULL || strlen(uuid) == 0)
- return NULL;
+ if (uuid == NULL || strlen(uuid) == 0)
+ return NULL;
- for (int i = 0; i < UUID_NAME_LOOKUP_TABLE_SIZE; i++) {
- if (g_ascii_strcasecmp(uuid_name_lookup_table[i].uuid, uuid) == 0)
- return uuid_name_lookup_table[i].name;
- }
+ for (int i = 0; i < UUID_NAME_LOOKUP_TABLE_SIZE; i++)
+ {
+ if (g_ascii_strcasecmp(uuid_name_lookup_table[i].uuid, uuid) == 0)
+ return uuid_name_lookup_table[i].name;
+ }
- return uuid;
+ return uuid;
}
const gchar *name2uuid(const gchar *name)
{
- if (name == NULL || strlen(name) == 0)
- return NULL;
-
- for (int i = 0; i < UUID_NAME_LOOKUP_TABLE_SIZE; i++) {
- if (
- g_ascii_strcasecmp(uuid_name_lookup_table[i].name, name) == 0 ||
- (uuid_name_lookup_table[i].alt_name && g_ascii_strcasecmp(uuid_name_lookup_table[i].alt_name, name) == 0)
- )
- return uuid_name_lookup_table[i].uuid;
- }
-
- return name;
+ if (name == NULL || strlen(name) == 0)
+ return NULL;
+
+ for (int i = 0; i < UUID_NAME_LOOKUP_TABLE_SIZE; i++)
+ {
+ if (
+ g_ascii_strcasecmp(uuid_name_lookup_table[i].name, name) == 0 ||
+ (uuid_name_lookup_table[i].alt_name && g_ascii_strcasecmp(uuid_name_lookup_table[i].alt_name, name) == 0)
+ )
+ return uuid_name_lookup_table[i].uuid;
+ }
+
+ return name;
}
int xtoi(const gchar *str)
{
- int i = 0;
- sscanf(str, "0x%x", &i);
- return i;
+ int i = 0;
+ sscanf(str, "0x%x", &i);
+ return i;
}
Adapter *find_adapter(const gchar *name, GError **error)
{
- gchar *adapter_path = NULL;
- Adapter *adapter = NULL;
-
- Manager *manager = g_object_new(MANAGER_TYPE, NULL);
-
- // If name is null or empty - return default adapter
- if (name == NULL || strlen(name) == 0) {
- adapter_path = manager_default_adapter(manager, error);
- if (adapter_path) {
- adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", adapter_path, NULL);
- }
- } else {
- // Try to find by id
- adapter_path = manager_find_adapter(manager, name, error);
-
- // Found
- if (adapter_path) {
- adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", adapter_path, NULL);
- } else {
- // Try to find by name
- const GPtrArray *adapters_list = manager_get_adapters(manager);
- g_assert(adapters_list != NULL);
- for (int i = 0; i < adapters_list->len; i++) {
- adapter_path = g_ptr_array_index(adapters_list, i);
- adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", adapter_path, NULL);
- adapter_path = NULL;
-
- if (g_strcmp0(name, adapter_get_name(adapter)) == 0) {
- if (error) {
- g_error_free(*error);
- *error = NULL;
- }
- break;
- }
-
- g_object_unref(adapter);
- adapter = NULL;
- }
- }
- }
-
- g_object_unref(manager);
- if (adapter_path) g_free(adapter_path);
-
- return adapter;
+ gchar *adapter_path = NULL;
+ Adapter *adapter = NULL;
+
+ Manager *manager = g_object_new(MANAGER_TYPE, NULL);
+
+ // If name is null or empty - return default adapter
+ if (name == NULL || strlen(name) == 0)
+ {
+ adapter_path = (gchar *) manager_default_adapter(manager, error);
+ if (adapter_path)
+ {
+ // adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", adapter_path, NULL);
+ adapter = adapter_new(adapter_path);
+ }
+ }
+ else
+ {
+ // Try to find by id
+ adapter_path = (gchar *) manager_find_adapter(manager, name, error);
+
+ // Found
+ if (adapter_path)
+ {
+ // adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", adapter_path, NULL);
+ adapter = adapter_new(adapter_path);
+ }
+ else
+ {
+ // Try to find by name
+ const GPtrArray *adapters_list = manager_get_adapters(manager);
+ g_assert(adapters_list != NULL);
+ for (int i = 0; i < adapters_list->len; i++)
+ {
+ adapter_path = g_ptr_array_index(adapters_list, i);
+ // adapter = g_object_new(ADAPTER_TYPE, "DBusObjectPath", adapter_path, NULL);
+ adapter = adapter_new(adapter_path);
+ adapter_path = NULL;
+
+ if (g_strcmp0(name, adapter_get_name(adapter, error)) == 0)
+ {
+ if (error)
+ {
+ g_error_free(*error);
+ *error = NULL;
+ }
+ break;
+ }
+
+ g_object_unref(adapter);
+ adapter = NULL;
+ }
+ }
+ }
+
+ g_object_unref(manager);
+ if (adapter_path) g_free(adapter_path);
+
+ return adapter;
}
Device *find_device(Adapter *adapter, const gchar *name, GError **error)
{
- g_assert(adapter != NULL && ADAPTER_IS(adapter));
- g_assert(name != NULL && strlen(name) > 0);
-
- gchar *device_path = NULL;
- Device *device = NULL;
-
- // Try to find by MAC
- device_path = adapter_find_device(adapter, name, error);
-
- // Found
- if (device_path) {
- device = g_object_new(DEVICE_TYPE, "DBusObjectPath", device_path, NULL);
- } else {
- // Try to find by name
- const GPtrArray *devices_list = adapter_get_devices(adapter);
- g_assert(devices_list != NULL);
- for (int i = 0; i < devices_list->len; i++) {
- device_path = g_ptr_array_index(devices_list, i);
- device = g_object_new(DEVICE_TYPE, "DBusObjectPath", device_path, NULL);
- device_path = NULL;
-
- if (g_strcmp0(name, device_get_name(device)) == 0 || g_strcmp0(name, device_get_alias(device)) == 0) {
- if (error) {
- g_error_free(*error);
- *error = NULL;
- }
- break;
- }
-
- g_object_unref(device);
- device = NULL;
- }
- }
-
- if (device_path) g_free(device_path);
-
- return device;
+ g_assert(adapter != NULL && ADAPTER_IS(adapter));
+ g_assert(name != NULL && strlen(name) > 0);
+
+ Device *device = NULL;
+
+ Manager *manager = g_object_new(MANAGER_TYPE, NULL);
+
+ GVariant *objects = manager_get_managed_objects(manager, error);
+
+ g_clear_object(&manager);
+
+ if(!objects)
+ {
+ return NULL;
+ }
+
+ const gchar *object_path;
+ GVariant *ifaces_and_properties;
+ GVariantIter i;
+
+ g_variant_iter_init(&i, objects);
+ while (g_variant_iter_next(&i, "{&o@a{sa{sv}}}", &object_path, &ifaces_and_properties) && device == NULL)
+ {
+ GVariant *properties = NULL;
+
+ if(g_variant_lookup(ifaces_and_properties, DEVICE_DBUS_INTERFACE, "@a{sv}", &properties))
+ {
+ gchar *adapter_path = NULL;
+ if(g_variant_lookup(properties, "Adapter", "o", &adapter_path))
+ {
+ if(g_strcmp0(adapter_path, adapter_get_dbus_object_path(adapter)) == 0)
+ {
+ // Now check if this is the device we are looking for.
+
+ // Try to find by MAC
+ gchar *address = NULL;
+
+ if(g_variant_lookup(properties, "Address", "s", &address))
+ {
+ if(g_strcmp0(g_ascii_strdown(address, -1), g_ascii_strdown(name, -1)) == 0)
+ {
+ device = device_new(object_path);
+ }
+ g_free(address);
+ }
+
+ // Try to find by name or alias
+ if(!device)
+ {
+ gchar *device_name = NULL;
+ gchar *device_alias = NULL;
+ g_variant_lookup(properties, "Name", "s", &device_name);
+ g_variant_lookup(properties, "Alias", "s", &device_alias);
+
+ if (g_strcmp0(name, device_name) == 0 || g_strcmp0(name, device_alias) == 0) {
+ device = device_new(object_path);
+ }
+
+ g_free(device_alias);
+ g_free(device_name);
+ }
+ }
+ g_free(adapter_path);
+ }
+ g_variant_unref(properties);
+ }
+ g_variant_unref(ifaces_and_properties);
+ }
+ g_variant_unref(objects);
+
+ return device;
}
gboolean intf_supported(const gchar *dbus_service_name, const gchar *dbus_object_path, const gchar *intf_name)
{
- g_assert(dbus_service_name != NULL && strlen(dbus_service_name) > 0);
- g_assert(dbus_object_path != NULL && strlen(dbus_object_path) > 0);
- g_assert(intf_name != NULL && strlen(intf_name) > 0);
-
- gboolean supported = FALSE;
- DBusGConnection *conn = NULL;
-
- if (g_strcmp0(dbus_service_name, BLUEZ_DBUS_NAME) == 0) {
- conn = system_conn;
-#ifdef OBEX_SUPPORT
- } else if (g_strcmp0(dbus_service_name, OBEXS_DBUS_NAME) == 0 || g_strcmp0(dbus_service_name, OBEXC_DBUS_NAME) == 0) {
- conn = session_conn;
-#endif
- } else {
- return FALSE;
- }
- g_assert(conn != NULL);
-
- gchar *check_intf_regex_str = g_strconcat("<interface name=\"", intf_name, "\">", NULL);
-
- /* Getting introspection XML */
- DBusGProxy *introspection_g_proxy = dbus_g_proxy_new_for_name(conn, dbus_service_name, dbus_object_path, "org.freedesktop.DBus.Introspectable");
- gchar *introspection_xml = NULL;
- GError *error = NULL;
- if (!dbus_g_proxy_call(introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &introspection_xml, G_TYPE_INVALID)) {
+ g_assert(dbus_service_name != NULL && strlen(dbus_service_name) > 0);
+ g_assert(dbus_object_path != NULL && strlen(dbus_object_path) > 0);
+ g_assert(intf_name != NULL && strlen(intf_name) > 0);
+
+ gboolean supported = FALSE;
+ GDBusConnection *conn = NULL;
+
+ if (g_strcmp0(dbus_service_name, BLUEZ_DBUS_SERVICE_NAME) == 0)
+ {
+ conn = system_conn;
+ }
+ else if (g_strcmp0(dbus_service_name, BLUEZ_OBEX_DBUS_SERVICE_NAME) == 0)
+ {
+ conn = session_conn;
+ }
+ else
+ {
+ return FALSE;
+ }
+ g_assert(conn != NULL);
+
+ gchar *check_intf_regex_str = g_strconcat("<interface name=\"", intf_name, "\">", NULL);
+
+ /* Getting introspection XML */
+ GError *error = NULL;
+ GDBusProxy *introspection_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_service_name, dbus_object_path, "org.freedesktop.DBus.Introspectable", NULL, &error);
+ g_assert(introspection_proxy != NULL);
+ GVariant *introspection_ret = g_dbus_proxy_call_sync(introspection_proxy, "Introspect", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ gchar *introspection_xml = NULL;
+ if (!introspection_ret)
+ {
#if 0
- g_critical("%s", error->message);
+ g_critical("%s", error->message);
#else
- g_error_free(error);
- error = NULL;
- introspection_xml = g_strdup("null");
+ g_error_free(error);
+ error = NULL;
+ introspection_xml = g_strdup("null");
#endif
- }
- g_assert(error == NULL);
-
- if (g_regex_match_simple(check_intf_regex_str, introspection_xml, 0, 0)) {
- supported = TRUE;
- }
-
- g_free(check_intf_regex_str);
- g_free(introspection_xml);
- g_object_unref(introspection_g_proxy);
-
- return supported;
+ }
+ else
+ {
+ introspection_xml = (gchar *) g_variant_get_string(g_variant_get_child_value(introspection_ret, 0), NULL);
+ }
+ g_assert(error == NULL);
+
+ if (g_regex_match_simple(check_intf_regex_str, introspection_xml, 0, 0))
+ {
+ supported = TRUE;
+ }
+
+ g_free(check_intf_regex_str);
+ g_free(introspection_xml);
+ if(introspection_ret)
+ g_variant_unref(introspection_ret);
+ g_object_unref(introspection_proxy);
+
+ return supported;
}
gboolean is_file(const gchar *filename, GError **error)
{
- g_assert(filename != NULL && strlen(filename) > 0);
-
- struct stat buf;
- if (stat(filename, &buf) != 0) {
- if (error) {
- *error = g_error_new(g_quark_from_string("bluez-tools"), 1, "%s: %s", g_strdup(filename), strerror(errno));
- }
- return FALSE;
- }
-
- if (!S_ISREG(buf.st_mode)) {
- if (error) {
- *error = g_error_new(g_quark_from_string("bluez-tools"), 2, "%s: Invalid file", g_strdup(filename));
- }
- return FALSE;
- }
-
- return TRUE;
+ g_assert(filename != NULL && strlen(filename) > 0);
+
+ struct stat buf;
+ if (stat(filename, &buf) != 0)
+ {
+ if (error)
+ {
+ *error = g_error_new(g_quark_from_string("bluez-tools"), 1, "%s: %s", g_strdup(filename), strerror(errno));
+ }
+ return FALSE;
+ }
+
+ if (!S_ISREG(buf.st_mode))
+ {
+ if (error)
+ {
+ *error = g_error_new(g_quark_from_string("bluez-tools"), 2, "%s: Invalid file", g_strdup(filename));
+ }
+ return FALSE;
+ }
+
+ return TRUE;
}
gboolean is_dir(const gchar *dirname, GError **error)
{
- g_assert(dirname != NULL && strlen(dirname) > 0);
-
- struct stat buf;
- if (stat(dirname, &buf) != 0) {
- if (error) {
- *error = g_error_new(g_quark_from_string("bluez-tools"), 1, "%s: %s", g_strdup(dirname), strerror(errno));
- }
- return FALSE;
- }
-
- if (!S_ISDIR(buf.st_mode)) {
- if (error) {
- *error = g_error_new(g_quark_from_string("bluez-tools"), 2, "%s: Invalid directory", g_strdup(dirname));
- }
- return FALSE;
- }
-
- return TRUE;
+ g_assert(dirname != NULL && strlen(dirname) > 0);
+
+ struct stat buf;
+ if (stat(dirname, &buf) != 0)
+ {
+ if (error)
+ {
+ *error = g_error_new(g_quark_from_string("bluez-tools"), 1, "%s: %s", g_strdup(dirname), strerror(errno));
+ }
+ return FALSE;
+ }
+
+ if (!S_ISDIR(buf.st_mode))
+ {
+ if (error)
+ {
+ *error = g_error_new(g_quark_from_string("bluez-tools"), 2, "%s: Invalid directory", g_strdup(dirname));
+ }
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean read_access(const gchar *path, GError **error)
+{
+ if(g_access(path, F_OK) != 0)
+ {
+ if (error)
+ {
+ *error = g_error_new(g_quark_from_string("bluez-tools"), 3, "%s: No such file or directory", g_strdup(path));
+ }
+ return FALSE;
+ }
+ if(g_access(path, R_OK | F_OK) != 0)
+ {
+ if (error)
+ {
+ *error = g_error_new(g_quark_from_string("bluez-tools"), 4, "%s: Read permission denied", g_strdup(path));
+ }
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean write_access(const gchar *path, GError **error)
+{
+ if(g_access(path, F_OK) != 0)
+ {
+ if (error)
+ {
+ *error = g_error_new(g_quark_from_string("bluez-tools"), 3, "%s: No such file or directory", g_strdup(path));
+ }
+ return FALSE;
+ }
+ if(g_access(path, W_OK | F_OK) != 0)
+ {
+ if (error)
+ {
+ *error = g_error_new(g_quark_from_string("bluez-tools"), 5, "%s: Write permission denied", g_strdup(path));
+ }
+ return FALSE;
+ }
+
+ return TRUE;
}
gchar *get_absolute_path(const gchar *path)
{
- if (g_path_is_absolute(path)) {
- return g_strdup(path);
- }
+ if (g_path_is_absolute(path))
+ {
+ return g_strdup(path);
+ }
- gchar *current_dir = g_get_current_dir();
- gchar *abs_path = g_build_filename(current_dir, path, NULL);
- g_free(current_dir);
+ gchar *current_dir = g_get_current_dir();
+ gchar *abs_path = g_build_filename(current_dir, path, NULL);
+ g_free(current_dir);
- return abs_path;
+ return abs_path;
}
-
diff --git a/src/lib/helpers.h b/src/lib/helpers.h
index eed1e6c..344410e 100644
--- a/src/lib/helpers.h
+++ b/src/lib/helpers.h
@@ -24,14 +24,11 @@
#ifndef __HELPERS_H
#define __HELPERS_H
-#include <stdio.h>
-
#include <glib.h>
+#include <stdio.h>
+#include <string.h>
#include "bluez-api.h"
-#ifdef OBEX_SUPPORT
-#include "obexd-api.h"
-#endif
/* DBus helpers */
gboolean intf_supported(const gchar *dbus_service_name, const gchar *dbus_object_path, const gchar *intf_name);
@@ -43,7 +40,7 @@ Device *find_device(Adapter *adapter, const gchar *name, GError **error);
/* Others helpers */
#define exit_if_error(error) G_STMT_START{ \
if (error) { \
- g_printerr("%s: %s\n", (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION && dbus_g_error_get_name(error) != NULL && strlen(dbus_g_error_get_name(error)) ? dbus_g_error_get_name(error) : "Error"), error->message); \
+ g_printerr("%s: %s\n", (error->domain == G_DBUS_ERROR && g_dbus_error_get_remote_error(error) != NULL && strlen(g_dbus_error_get_remote_error(error)) ? g_dbus_error_get_remote_error(error) : "Error"), error->message); \
exit(EXIT_FAILURE); \
}; }G_STMT_END
@@ -57,7 +54,8 @@ const gchar *name2uuid(const gchar *name);
/* FS helpers */
gboolean is_file(const gchar *filename, GError **error);
gboolean is_dir(const gchar *dirname, GError **error);
+gboolean read_access(const gchar *path, GError **error);
+gboolean write_access(const gchar *path, GError **error);
gchar *get_absolute_path(const gchar *path);
#endif /* __HELPERS_H */
-
diff --git a/src/lib/manager.c b/src/lib/manager.c
new file mode 100644
index 0000000..5286a3a
--- /dev/null
+++ b/src/lib/manager.c
@@ -0,0 +1,276 @@
+#include <gio/gio.h>
+#include "bluez-api.h"
+#include "dbus-common.h"
+#include "manager.h"
+
+struct _ManagerPrivate
+{
+ GDBusProxy *proxy;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(Manager, manager, G_TYPE_OBJECT)
+
+static void manager_dispose (GObject *gobject)
+{
+ Manager *self = MANAGER (gobject);
+
+ /* In dispose(), you are supposed to free all types referenced from this
+ * object which might themselves hold a reference to self. Generally,
+ * the most simple solution is to unref all members on which you own a
+ * reference.
+ */
+
+ /* dispose() might be called multiple times, so we must guard against
+ * calling g_object_unref() on an invalid GObject by setting the member
+ * NULL; g_clear_object() does this for us, atomically.
+ */
+ // g_clear_object (&self->priv->an_object);
+ g_clear_object (&self->priv->proxy);
+
+
+ /* Always chain up to the parent class; there is no need to check if
+ * the parent class implements the dispose() virtual function: it is
+ * always guaranteed to do so
+ */
+ G_OBJECT_CLASS (manager_parent_class)->dispose (gobject);
+}
+
+static void manager_finalize (GObject *gobject)
+{
+ Manager *self = MANAGER(gobject);
+
+ // g_free(self->priv->a_string);
+
+ /* Always chain up to the parent class; as with dispose(), finalize()
+ * is guaranteed to exist on the parent's class virtual function table
+ */
+ G_OBJECT_CLASS (manager_parent_class)->finalize (gobject);
+}
+
+static void manager_class_init(ManagerClass *klass)
+{
+}
+
+static void manager_init(Manager *self)
+{
+ self->priv = manager_get_instance_private(self);
+ GError *error = NULL;
+
+ g_assert(system_conn != NULL);
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, BLUEZ_DBUS_SERVICE_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE, NULL, &error);
+
+ if (self->priv->proxy == NULL)
+ {
+ g_critical("%s", error->message);
+ }
+ g_assert(error == NULL);
+}
+
+Manager *manager_new()
+{
+ return g_object_new(MANAGER_TYPE, NULL);
+}
+
+GVariant *manager_get_managed_objects(Manager *self, GError **error)
+{
+ g_assert(MANAGER_IS(self));
+
+ GVariant *retVal = NULL;
+ retVal = g_dbus_proxy_call_sync(self->priv->proxy, "GetManagedObjects", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+
+ if (retVal != NULL)
+ retVal = g_variant_get_child_value(retVal, 0);
+
+ return retVal;
+}
+
+const gchar *manager_default_adapter(Manager *self, GError **error)
+{
+ g_assert(MANAGER_IS(self));
+
+ GVariant *objects = NULL;
+ objects = manager_get_managed_objects(self, error);
+ if (objects == NULL)
+ return NULL;
+
+ const gchar *object_path;
+ GVariant *ifaces_and_properties;
+ GVariantIter i;
+
+ g_variant_iter_init(&i, objects);
+ while (g_variant_iter_next(&i, "{&o@a{sa{sv}}}", &object_path, &ifaces_and_properties))
+ {
+ const gchar *interface_name;
+ GVariant *properties;
+ GVariantIter ii;
+ g_variant_iter_init(&ii, ifaces_and_properties);
+ while (g_variant_iter_next(&ii, "{&s@a{sv}}", &interface_name, &properties))
+ {
+ if (g_strstr_len(g_ascii_strdown(interface_name, -1), -1, "adapter"))
+ {
+ const gchar *retVal = g_strdup(object_path);
+ g_variant_unref(properties);
+ g_variant_unref(ifaces_and_properties);
+ g_variant_unref(objects);
+ return retVal;
+ }
+ g_variant_unref(properties);
+ }
+ g_variant_unref(ifaces_and_properties);
+ }
+ g_variant_unref(objects);
+
+ return NULL;
+}
+
+const gchar *manager_find_adapter(Manager *self, const gchar *pattern, GError **error)
+{
+ g_assert(MANAGER_IS(self));
+
+ GVariant *objects = NULL;
+ objects = manager_get_managed_objects(self, error);
+ if (objects == NULL)
+ return NULL;
+
+ const gchar *object_path;
+ GVariant *ifaces_and_properties;
+ GVariantIter i;
+
+ g_variant_iter_init(&i, objects);
+ while (g_variant_iter_next(&i, "{&o@a{sa{sv}}}", &object_path, &ifaces_and_properties))
+ {
+ const gchar *interface_name;
+ GVariant *properties;
+ GVariantIter ii;
+ g_variant_iter_init(&ii, ifaces_and_properties);
+ while (g_variant_iter_next(&ii, "{&s@a{sv}}", &interface_name, &properties))
+ {
+ if (g_strstr_len(g_ascii_strdown(interface_name, -1), -1, "adapter"))
+ {
+ const gchar *object_base_name = g_path_get_basename(object_path);
+ if (g_strstr_len(g_ascii_strdown(object_base_name, -1), -1, g_ascii_strdown(pattern, -1)))
+ {
+ const gchar *retVal = g_strdup(object_path);
+ g_variant_unref(properties);
+ g_variant_unref(ifaces_and_properties);
+ g_variant_unref(objects);
+ return retVal;
+ }
+ const gchar *address = g_variant_get_string(g_variant_lookup_value(properties, "Address", NULL), NULL);
+ if (g_strstr_len(g_ascii_strdown(address, -1), -1, g_ascii_strdown(pattern, -1)))
+ {
+ gchar *retVal = g_strdup(object_path);
+ g_variant_unref(properties);
+ g_variant_unref(ifaces_and_properties);
+ g_variant_unref(objects);
+ return retVal;
+ }
+ }
+ g_variant_unref(properties);
+ }
+ g_variant_unref(ifaces_and_properties);
+ }
+ g_variant_unref(objects);
+
+ return NULL;
+}
+
+GPtrArray *manager_get_adapters(Manager *self)
+{
+ g_assert(MANAGER_IS(self));
+
+ GVariant *objects = NULL;
+ GError *error = NULL;
+ objects = manager_get_managed_objects(self, &error);
+ if (objects == NULL)
+ {
+ g_critical("%s", error->message);
+ g_error_free(error);
+ return NULL;
+ }
+
+ GPtrArray *adapter_array = g_ptr_array_new();
+
+ const gchar *object_path;
+ GVariant *ifaces_and_properties;
+ GVariantIter i;
+
+ g_variant_iter_init(&i, objects);
+ while (g_variant_iter_next(&i, "{&o@a{sa{sv}}}", &object_path, &ifaces_and_properties))
+ {
+ const gchar *interface_name;
+ GVariant *properties;
+ GVariantIter ii;
+ g_variant_iter_init(&ii, ifaces_and_properties);
+ while (g_variant_iter_next(&ii, "{&s@a{sv}}", &interface_name, &properties))
+ {
+ if (g_strstr_len(g_ascii_strdown(interface_name, -1), -1, "adapter"))
+ g_ptr_array_add(adapter_array, (gpointer) g_strdup(object_path));
+ g_variant_unref(properties);
+ }
+ g_variant_unref(ifaces_and_properties);
+ }
+ g_variant_unref(objects);
+
+ return adapter_array;
+}
+
+const gchar **manager_get_devices(Manager *self, const gchar *adapter_pattern)
+{
+ g_assert(MANAGER_IS(self));
+
+ GVariant *objects = NULL;
+ GError *error = NULL;
+ objects = manager_get_managed_objects(self, &error);
+ if (objects == NULL)
+ {
+ g_critical("%s", error->message);
+ g_error_free(error);
+ return NULL;
+ }
+
+ GRegex *adapter_regex = g_regex_new(adapter_pattern, 0, 0, &error);
+ if (adapter_regex == NULL)
+ {
+ g_critical("%s", error->message);
+ g_error_free(error);
+ }
+
+ GPtrArray *device_array = g_ptr_array_new();
+
+ const gchar *object_path;
+ GVariant *ifaces_and_properties;
+ GVariantIter i;
+
+ g_variant_iter_init(&i, objects);
+ while (g_variant_iter_next(&i, "{&o@a{sa{sv}}}", &object_path, &ifaces_and_properties))
+ {
+ const gchar *interface_name;
+ GVariant *properties;
+ GVariantIter ii;
+ g_variant_iter_init(&ii, ifaces_and_properties);
+ while (g_variant_iter_next(&ii, "{&s@a{sv}}", &interface_name, &properties))
+ {
+ if (g_strcmp0(interface_name, "org.bluez.Device1") == 0)
+ {
+ const gchar *adapter_prop = g_variant_get_string(g_variant_lookup_value(properties, "Adapter", G_VARIANT_TYPE_OBJECT_PATH), NULL);
+ if(g_regex_match(adapter_regex, adapter_prop, 0, NULL))
+ g_ptr_array_add(device_array, (gpointer) g_strdup(object_path));
+ }
+ g_variant_unref(properties);
+ }
+ g_variant_unref(ifaces_and_properties);
+ }
+ g_variant_unref(objects);
+
+ g_regex_unref(adapter_regex);
+
+ if(device_array->len > 0)
+ {
+ // Top it off with a NULL pointer
+ g_ptr_array_add(device_array, (gpointer) NULL);
+ return (const gchar**) g_ptr_array_free(device_array, FALSE);
+ }
+ else
+ return NULL;
+} \ No newline at end of file
diff --git a/src/lib/manager.h b/src/lib/manager.h
new file mode 100644
index 0000000..0c9e052
--- /dev/null
+++ b/src/lib/manager.h
@@ -0,0 +1,67 @@
+#ifndef MANAGER_H
+#define MANAGER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+ /*
+ * Potentially, include other headers on which this header depends.
+ */
+
+ /*
+ * Type macros.
+ */
+#define MANAGER_TYPE (manager_get_type ())
+#define MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MANAGER_TYPE, Manager))
+#define MANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MANAGER_TYPE))
+#define MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MANAGER_TYPE, ManagerClass))
+#define MANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MANAGER_TYPE))
+#define MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MANAGER_TYPE, ManagerClass))
+
+#define MANAGER_DBUS_PATH "/"
+#define MANAGER_DBUS_INTERFACE "org.freedesktop.DBus.ObjectManager"
+
+ typedef struct _Manager Manager;
+ typedef struct _ManagerPrivate ManagerPrivate;
+ typedef struct _ManagerClass ManagerClass;
+
+ struct _Manager {
+ /* Parent instance structure */
+ GObject parent_instance;
+
+ /* instance members */
+ ManagerPrivate *priv;
+ };
+
+ struct _ManagerClass {
+ /* Parent class structure */
+ GObjectClass parent_class;
+
+ /* class members */
+ };
+
+ /* used by MANAGER_TYPE */
+ GType manager_get_type(void);
+
+ /*
+ * Constructor
+ */
+ Manager *manager_new();
+
+ /*
+ * Method definitions.
+ */
+ GVariant *manager_get_managed_objects(Manager *self, GError **error);
+ const gchar *manager_default_adapter(Manager *self, GError **error);
+ const gchar *manager_find_adapter(Manager *self, const gchar *pattern, GError **error);
+ GPtrArray *manager_get_adapters(Manager *self);
+ const gchar **manager_get_devices(Manager *self, const gchar *adapter_pattern);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MANAGER_H */
+
diff --git a/src/lib/marshallers.c b/src/lib/marshallers.c
deleted file mode 100644
index c88186e..0000000
--- a/src/lib/marshallers.c
+++ /dev/null
@@ -1,588 +0,0 @@
-
-#include <glib-object.h>
-
-
-#ifdef G_ENABLE_DEBUG
-#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
-#define g_marshal_value_peek_char(v) g_value_get_char (v)
-#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)
-#define g_marshal_value_peek_int(v) g_value_get_int (v)
-#define g_marshal_value_peek_uint(v) g_value_get_uint (v)
-#define g_marshal_value_peek_long(v) g_value_get_long (v)
-#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)
-#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)
-#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)
-#define g_marshal_value_peek_enum(v) g_value_get_enum (v)
-#define g_marshal_value_peek_flags(v) g_value_get_flags (v)
-#define g_marshal_value_peek_float(v) g_value_get_float (v)
-#define g_marshal_value_peek_double(v) g_value_get_double (v)
-#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)
-#define g_marshal_value_peek_param(v) g_value_get_param (v)
-#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)
-#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)
-#define g_marshal_value_peek_object(v) g_value_get_object (v)
-#else /* !G_ENABLE_DEBUG */
-/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
- * Do not access GValues directly in your code. Instead, use the
- * g_value_get_*() functions
- */
-#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int
-#define g_marshal_value_peek_char(v) (v)->data[0].v_int
-#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint
-#define g_marshal_value_peek_int(v) (v)->data[0].v_int
-#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint
-#define g_marshal_value_peek_long(v) (v)->data[0].v_long
-#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong
-#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64
-#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64
-#define g_marshal_value_peek_enum(v) (v)->data[0].v_long
-#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong
-#define g_marshal_value_peek_float(v) (v)->data[0].v_float
-#define g_marshal_value_peek_double(v) (v)->data[0].v_double
-#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer
-#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer
-#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer
-#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer
-#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
-#endif /* !G_ENABLE_DEBUG */
-
-
-/* VOID:STRING,BOXED (lib/marshallers.list:2) */
-void
-g_cclosure_bt_marshal_VOID__STRING_BOXED (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef void (*GMarshalFunc_VOID__STRING_BOXED) (gpointer data1,
- gpointer arg_1,
- gpointer arg_2,
- gpointer data2);
- register GMarshalFunc_VOID__STRING_BOXED callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
-
- g_return_if_fail (n_param_values == 3);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_VOID__STRING_BOXED) (marshal_data ? marshal_data : cc->callback);
-
- callback (data1,
- g_marshal_value_peek_string (param_values + 1),
- g_marshal_value_peek_boxed (param_values + 2),
- data2);
-}
-
-/* BOOLEAN:POINTER (lib/marshallers.list:5) */
-void
-g_cclosure_bt_marshal_BOOLEAN__POINTER (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef gboolean (*GMarshalFunc_BOOLEAN__POINTER) (gpointer data1,
- gpointer arg_1,
- gpointer data2);
- register GMarshalFunc_BOOLEAN__POINTER callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
- gboolean v_return;
-
- g_return_if_fail (return_value != NULL);
- g_return_if_fail (n_param_values == 2);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_BOOLEAN__POINTER) (marshal_data ? marshal_data : cc->callback);
-
- v_return = callback (data1,
- g_marshal_value_peek_pointer (param_values + 1),
- data2);
-
- g_value_set_boolean (return_value, v_return);
-}
-
-/* BOOLEAN:BOXED,POINTER,POINTER (lib/marshallers.list:6) */
-void
-g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER_POINTER (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_POINTER_POINTER) (gpointer data1,
- gpointer arg_1,
- gpointer arg_2,
- gpointer arg_3,
- gpointer data2);
- register GMarshalFunc_BOOLEAN__BOXED_POINTER_POINTER callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
- gboolean v_return;
-
- g_return_if_fail (return_value != NULL);
- g_return_if_fail (n_param_values == 4);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_BOOLEAN__BOXED_POINTER_POINTER) (marshal_data ? marshal_data : cc->callback);
-
- v_return = callback (data1,
- g_marshal_value_peek_boxed (param_values + 1),
- g_marshal_value_peek_pointer (param_values + 2),
- g_marshal_value_peek_pointer (param_values + 3),
- data2);
-
- g_value_set_boolean (return_value, v_return);
-}
-
-/* BOOLEAN:BOXED,UINT,UCHAR,POINTER (lib/marshallers.list:7) */
-void
-g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT_UCHAR_POINTER (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_UINT_UCHAR_POINTER) (gpointer data1,
- gpointer arg_1,
- guint arg_2,
- guchar arg_3,
- gpointer arg_4,
- gpointer data2);
- register GMarshalFunc_BOOLEAN__BOXED_UINT_UCHAR_POINTER callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
- gboolean v_return;
-
- g_return_if_fail (return_value != NULL);
- g_return_if_fail (n_param_values == 5);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_BOOLEAN__BOXED_UINT_UCHAR_POINTER) (marshal_data ? marshal_data : cc->callback);
-
- v_return = callback (data1,
- g_marshal_value_peek_boxed (param_values + 1),
- g_marshal_value_peek_uint (param_values + 2),
- g_marshal_value_peek_uchar (param_values + 3),
- g_marshal_value_peek_pointer (param_values + 4),
- data2);
-
- g_value_set_boolean (return_value, v_return);
-}
-
-/* BOOLEAN:BOXED,UINT,POINTER (lib/marshallers.list:8) */
-void
-g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT_POINTER (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_UINT_POINTER) (gpointer data1,
- gpointer arg_1,
- guint arg_2,
- gpointer arg_3,
- gpointer data2);
- register GMarshalFunc_BOOLEAN__BOXED_UINT_POINTER callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
- gboolean v_return;
-
- g_return_if_fail (return_value != NULL);
- g_return_if_fail (n_param_values == 4);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_BOOLEAN__BOXED_UINT_POINTER) (marshal_data ? marshal_data : cc->callback);
-
- v_return = callback (data1,
- g_marshal_value_peek_boxed (param_values + 1),
- g_marshal_value_peek_uint (param_values + 2),
- g_marshal_value_peek_pointer (param_values + 3),
- data2);
-
- g_value_set_boolean (return_value, v_return);
-}
-
-/* BOOLEAN:BOXED,STRING,POINTER (lib/marshallers.list:9) */
-void
-g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_POINTER (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_STRING_POINTER) (gpointer data1,
- gpointer arg_1,
- gpointer arg_2,
- gpointer arg_3,
- gpointer data2);
- register GMarshalFunc_BOOLEAN__BOXED_STRING_POINTER callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
- gboolean v_return;
-
- g_return_if_fail (return_value != NULL);
- g_return_if_fail (n_param_values == 4);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_BOOLEAN__BOXED_STRING_POINTER) (marshal_data ? marshal_data : cc->callback);
-
- v_return = callback (data1,
- g_marshal_value_peek_boxed (param_values + 1),
- g_marshal_value_peek_string (param_values + 2),
- g_marshal_value_peek_pointer (param_values + 3),
- data2);
-
- g_value_set_boolean (return_value, v_return);
-}
-
-/* BOOLEAN:STRING,POINTER (lib/marshallers.list:10) */
-void
-g_cclosure_bt_marshal_BOOLEAN__STRING_POINTER (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef gboolean (*GMarshalFunc_BOOLEAN__STRING_POINTER) (gpointer data1,
- gpointer arg_1,
- gpointer arg_2,
- gpointer data2);
- register GMarshalFunc_BOOLEAN__STRING_POINTER callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
- gboolean v_return;
-
- g_return_if_fail (return_value != NULL);
- g_return_if_fail (n_param_values == 3);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_BOOLEAN__STRING_POINTER) (marshal_data ? marshal_data : cc->callback);
-
- v_return = callback (data1,
- g_marshal_value_peek_string (param_values + 1),
- g_marshal_value_peek_pointer (param_values + 2),
- data2);
-
- g_value_set_boolean (return_value, v_return);
-}
-
-/* VOID:INT,INT (lib/marshallers.list:13) */
-void
-g_cclosure_bt_marshal_VOID__INT_INT (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef void (*GMarshalFunc_VOID__INT_INT) (gpointer data1,
- gint arg_1,
- gint arg_2,
- gpointer data2);
- register GMarshalFunc_VOID__INT_INT callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
-
- g_return_if_fail (n_param_values == 3);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_VOID__INT_INT) (marshal_data ? marshal_data : cc->callback);
-
- callback (data1,
- g_marshal_value_peek_int (param_values + 1),
- g_marshal_value_peek_int (param_values + 2),
- data2);
-}
-
-/* VOID:STRING,BOOLEAN (lib/marshallers.list:16) */
-void
-g_cclosure_bt_marshal_VOID__STRING_BOOLEAN (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef void (*GMarshalFunc_VOID__STRING_BOOLEAN) (gpointer data1,
- gpointer arg_1,
- gboolean arg_2,
- gpointer data2);
- register GMarshalFunc_VOID__STRING_BOOLEAN callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
-
- g_return_if_fail (n_param_values == 3);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_VOID__STRING_BOOLEAN) (marshal_data ? marshal_data : cc->callback);
-
- callback (data1,
- g_marshal_value_peek_string (param_values + 1),
- g_marshal_value_peek_boolean (param_values + 2),
- data2);
-}
-
-/* VOID:BOXED,BOOLEAN (lib/marshallers.list:17) */
-void
-g_cclosure_bt_marshal_VOID__BOXED_BOOLEAN (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef void (*GMarshalFunc_VOID__BOXED_BOOLEAN) (gpointer data1,
- gpointer arg_1,
- gboolean arg_2,
- gpointer data2);
- register GMarshalFunc_VOID__BOXED_BOOLEAN callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
-
- g_return_if_fail (n_param_values == 3);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_VOID__BOXED_BOOLEAN) (marshal_data ? marshal_data : cc->callback);
-
- callback (data1,
- g_marshal_value_peek_boxed (param_values + 1),
- g_marshal_value_peek_boolean (param_values + 2),
- data2);
-}
-
-/* BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER (lib/marshallers.list:20) */
-void
-g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_POINTER_POINTER (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_POINTER_POINTER) (gpointer data1,
- gpointer arg_1,
- gpointer arg_2,
- gpointer arg_3,
- gpointer arg_4,
- gint arg_5,
- gint arg_6,
- gpointer arg_7,
- gpointer arg_8,
- gpointer data2);
- register GMarshalFunc_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_POINTER_POINTER callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
- gboolean v_return;
-
- g_return_if_fail (return_value != NULL);
- g_return_if_fail (n_param_values == 9);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_POINTER_POINTER) (marshal_data ? marshal_data : cc->callback);
-
- v_return = callback (data1,
- g_marshal_value_peek_boxed (param_values + 1),
- g_marshal_value_peek_string (param_values + 2),
- g_marshal_value_peek_string (param_values + 3),
- g_marshal_value_peek_string (param_values + 4),
- g_marshal_value_peek_int (param_values + 5),
- g_marshal_value_peek_int (param_values + 6),
- g_marshal_value_peek_pointer (param_values + 7),
- g_marshal_value_peek_pointer (param_values + 8),
- data2);
-
- g_value_set_boolean (return_value, v_return);
-}
-
-/* BOOLEAN:BOXED,UINT64,POINTER (lib/marshallers.list:23) */
-void
-g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT64_POINTER (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_UINT64_POINTER) (gpointer data1,
- gpointer arg_1,
- guint64 arg_2,
- gpointer arg_3,
- gpointer data2);
- register GMarshalFunc_BOOLEAN__BOXED_UINT64_POINTER callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
- gboolean v_return;
-
- g_return_if_fail (return_value != NULL);
- g_return_if_fail (n_param_values == 4);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_BOOLEAN__BOXED_UINT64_POINTER) (marshal_data ? marshal_data : cc->callback);
-
- v_return = callback (data1,
- g_marshal_value_peek_boxed (param_values + 1),
- g_marshal_value_peek_uint64 (param_values + 2),
- g_marshal_value_peek_pointer (param_values + 3),
- data2);
-
- g_value_set_boolean (return_value, v_return);
-}
-
-/* BOOLEAN:BOXED,POINTER (lib/marshallers.list:24) */
-void
-g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER (GClosure *closure,
- GValue *return_value G_GNUC_UNUSED,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint G_GNUC_UNUSED,
- gpointer marshal_data)
-{
- typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_POINTER) (gpointer data1,
- gpointer arg_1,
- gpointer arg_2,
- gpointer data2);
- register GMarshalFunc_BOOLEAN__BOXED_POINTER callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
- gboolean v_return;
-
- g_return_if_fail (return_value != NULL);
- g_return_if_fail (n_param_values == 3);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_peek_pointer (param_values + 0);
- }
- else
- {
- data1 = g_value_peek_pointer (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_BOOLEAN__BOXED_POINTER) (marshal_data ? marshal_data : cc->callback);
-
- v_return = callback (data1,
- g_marshal_value_peek_boxed (param_values + 1),
- g_marshal_value_peek_pointer (param_values + 2),
- data2);
-
- g_value_set_boolean (return_value, v_return);
-}
-
diff --git a/src/lib/marshallers.h b/src/lib/marshallers.h
deleted file mode 100644
index 510e605..0000000
--- a/src/lib/marshallers.h
+++ /dev/null
@@ -1,116 +0,0 @@
-
-#ifndef __g_cclosure_bt_marshal_MARSHAL_H__
-#define __g_cclosure_bt_marshal_MARSHAL_H__
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-/* VOID:STRING,BOXED (lib/marshallers.list:2) */
-extern void g_cclosure_bt_marshal_VOID__STRING_BOXED (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* BOOLEAN:POINTER (lib/marshallers.list:5) */
-extern void g_cclosure_bt_marshal_BOOLEAN__POINTER (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* BOOLEAN:BOXED,POINTER,POINTER (lib/marshallers.list:6) */
-extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER_POINTER (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* BOOLEAN:BOXED,UINT,UCHAR,POINTER (lib/marshallers.list:7) */
-extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT_UCHAR_POINTER (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* BOOLEAN:BOXED,UINT,POINTER (lib/marshallers.list:8) */
-extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT_POINTER (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* BOOLEAN:BOXED,STRING,POINTER (lib/marshallers.list:9) */
-extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_POINTER (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* BOOLEAN:STRING,POINTER (lib/marshallers.list:10) */
-extern void g_cclosure_bt_marshal_BOOLEAN__STRING_POINTER (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* VOID:INT,INT (lib/marshallers.list:13) */
-extern void g_cclosure_bt_marshal_VOID__INT_INT (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* VOID:STRING,BOOLEAN (lib/marshallers.list:16) */
-extern void g_cclosure_bt_marshal_VOID__STRING_BOOLEAN (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* VOID:BOXED,BOOLEAN (lib/marshallers.list:17) */
-extern void g_cclosure_bt_marshal_VOID__BOXED_BOOLEAN (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER (lib/marshallers.list:20) */
-extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_POINTER_POINTER (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* BOOLEAN:BOXED,UINT64,POINTER (lib/marshallers.list:23) */
-extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT64_POINTER (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-/* BOOLEAN:BOXED,POINTER (lib/marshallers.list:24) */
-extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-G_END_DECLS
-
-#endif /* __g_cclosure_bt_marshal_MARSHAL_H__ */
-
diff --git a/src/lib/marshallers.list b/src/lib/marshallers.list
deleted file mode 100644
index 87edb09..0000000
--- a/src/lib/marshallers.list
+++ /dev/null
@@ -1,25 +0,0 @@
-# [bluez]
-VOID:STRING,BOXED
-
-# Used by Agent
-BOOLEAN:POINTER
-BOOLEAN:BOXED,POINTER,POINTER
-BOOLEAN:BOXED,UINT,UCHAR,POINTER
-BOOLEAN:BOXED,UINT,POINTER
-BOOLEAN:BOXED,STRING,POINTER
-BOOLEAN:STRING,POINTER
-
-# [obexd]
-VOID:INT,INT
-
-# equals
-VOID:STRING,BOOLEAN
-VOID:BOXED,BOOLEAN
-
-# Used by OBEXAgent
-BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER
-#BOOLEAN:POINTER
-#BOOLEAN:BOXED,POINTER,POINTER
-BOOLEAN:BOXED,UINT64,POINTER
-BOOLEAN:BOXED,POINTER
-#BOOLEAN:BOXED,STRING,POINTER
diff --git a/src/lib/obex_agent.c b/src/lib/obex_agent.c
new file mode 100644
index 0000000..f835f04
--- /dev/null
+++ b/src/lib/obex_agent.c
@@ -0,0 +1,296 @@
+/*
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "dbus-common.h"
+#include "helpers.h"
+#include "properties.h"
+
+#include "obex_agent.h"
+#include "bluez/obex/obex_transfer.h"
+
+#define OBEX_AGENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEX_AGENT_TYPE, ObexAgentPrivate))
+
+struct _ObexAgentPrivate {
+ gchar *root_folder;
+ gchar *current_name;
+ guint registration_id;
+ void (*agent_released_callback)(ObexAgent *, gpointer);
+ gpointer user_data;
+ void (*agent_approved_callback)(ObexAgent *, const gchar *, const gchar *, const guint64, gpointer);
+ gpointer approved_user_data;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ObexAgent, obex_agent, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_ROOT_FOLDER, /* readwrite, construct only */
+};
+
+static const gchar *_obex_agent_introspect_xml = "<node name=\"/org/blueztools/obex\">\n\t<interface name=\"org.bluez.obex.Agent1\">\n\t\t<method name=\"Release\">\n\t\t</method>\n\t\t<method name=\"AuthorizePush\">\n\t\t\t<arg name=\"transfer\" direction=\"in\" type=\"o\"/>\n\t\t\t<arg name=\"filepath\" direction=\"out\" type=\"s\"/>\n\t\t</method>\n\t\t<method name=\"Cancel\">\n\t\t</method>\n\t</interface>\n</node>\n";
+
+/* Client API */
+static gboolean _update_progress = FALSE;
+
+static void _obex_agent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void _obex_agent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+static void _obex_agent_method_call_func(GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data);
+static void _obex_agent_g_destroy_notify(gpointer data);
+
+static void obex_agent_dispose(GObject *gobject)
+{
+ ObexAgent *self = OBEX_AGENT(gobject);
+
+ if(self->priv->registration_id)
+ g_dbus_connection_unregister_object(session_conn, self->priv->registration_id);
+ /* Root folder free */
+ g_free(self->priv->root_folder);
+ /* callback free */
+ if(self->priv->agent_released_callback)
+ self->priv->agent_released_callback = NULL;
+ /* user data free */
+ if(self->priv->user_data)
+ self->priv->user_data = NULL;
+ /* callback free */
+ if(self->priv->agent_approved_callback)
+ self->priv->agent_approved_callback = NULL;
+ /* user data free */
+ if(self->priv->approved_user_data)
+ self->priv->approved_user_data = NULL;
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(obex_agent_parent_class)->dispose(gobject);
+}
+
+static void obex_agent_finalize (GObject *gobject)
+{
+ ObexAgent *self = OBEX_AGENT(gobject);
+ G_OBJECT_CLASS(obex_agent_parent_class)->finalize(gobject);
+}
+
+static void obex_agent_class_init(ObexAgentClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = obex_agent_dispose;
+
+ /* Properties registration */
+ GParamSpec *pspec = NULL;
+
+ gobject_class->get_property = _obex_agent_get_property;
+ gobject_class->set_property = _obex_agent_set_property;
+
+ /* string RootFolder [readwrite, construct only] */
+ pspec = g_param_spec_string("RootFolder", "root_folder", "Root folder location", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(gobject_class, PROP_ROOT_FOLDER, pspec);
+
+ if (pspec)
+ g_param_spec_unref(pspec);
+}
+
+static void obex_agent_init(ObexAgent *self)
+{
+ self->priv = obex_agent_get_instance_private(self);
+ g_assert(session_conn != NULL);
+ self->priv->registration_id = 0;
+ self->priv->root_folder = NULL;
+ self->priv->agent_released_callback = NULL;
+ self->priv->user_data = NULL;
+ self->priv->agent_approved_callback = NULL;
+ self->priv->approved_user_data = NULL;
+
+ GError *error = NULL;
+ GDBusInterfaceVTable obex_agent_table;
+ memset(&obex_agent_table, 0x0, sizeof(obex_agent_table));
+
+ GDBusNodeInfo *obex_agent_node_info = g_dbus_node_info_new_for_xml(_obex_agent_introspect_xml, &error);
+ g_assert(error == NULL);
+ GDBusInterfaceInfo *obex_agent_interface_info = g_dbus_node_info_lookup_interface(obex_agent_node_info, OBEX_AGENT_DBUS_INTERFACE);
+ obex_agent_table.method_call = _obex_agent_method_call_func;
+ self->priv->registration_id = g_dbus_connection_register_object(session_conn, OBEX_AGENT_DBUS_PATH, obex_agent_interface_info, &obex_agent_table, self, _obex_agent_g_destroy_notify, &error);
+ g_assert(error == NULL);
+ g_assert(self->priv->registration_id != 0);
+ g_dbus_node_info_unref(obex_agent_node_info);
+}
+
+static void _obex_agent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ ObexAgent *self = OBEX_AGENT(object);
+
+ switch (property_id) {
+ case PROP_ROOT_FOLDER:
+ g_value_set_string(value, self->priv->root_folder);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void _obex_agent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ ObexAgent *self = OBEX_AGENT(object);
+
+ switch (property_id) {
+ case PROP_ROOT_FOLDER:
+ self->priv->root_folder = g_value_dup_string(value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+/* Constructor */
+ObexAgent *obex_agent_new(const gchar *root_folder)
+{
+ return g_object_new(OBEX_AGENT_TYPE, "RootFolder", root_folder, NULL);
+}
+/* Methods */
+static void _obex_agent_method_call_func(GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ g_assert(user_data != NULL);
+ ObexAgent *self = user_data;
+
+ if (g_strcmp0(method_name, "AuthorizePush") == 0)
+ {
+ const gchar *transfer = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
+ if (intf_supported(OBEX_TRANSFER_DBUS_SERVICE, transfer, OBEX_TRANSFER_DBUS_INTERFACE))
+ {
+ ObexTransfer *transfer_t = obex_transfer_new(transfer);
+ g_print("[Transfer Request]\n");
+ g_print(" Name: %s\n", obex_transfer_get_name(transfer_t, NULL));
+ g_print(" Size: %llu bytes\n", obex_transfer_get_size(transfer_t, NULL));
+ // Filename seems to be always NULL
+ // g_print(" Filename: %s\n", obex_transfer_get_filename(transfer_t, NULL));
+ const gchar *filename = obex_transfer_get_name(transfer_t, NULL);
+ const guint64 size = obex_transfer_get_size(transfer_t, NULL);
+ g_object_unref(transfer_t);
+
+ gchar yn[4] = {0,};
+ g_print("Accept (yes/no)? ");
+ errno = 0;
+ if (scanf("%3s", yn) == EOF && errno)
+ {
+ g_warning("%s\n", strerror(errno));
+ }
+ if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0)
+ {
+ // IMPORTANT NOTE!
+ // OBEX CANNOT WRITE FILES OUTSIDE OF /home/<user>/.cache/obexd
+ // GVariant *ret = g_variant_new("(s)", g_build_filename(self->priv->root_folder, filename, NULL));
+ // This will store the file in /home/<user>/.cache/obexd
+ GVariant *ret = g_variant_new("(s)", filename);
+ // g_print("invocation return value: %s\n", g_variant_print(ret, TRUE));
+
+ // Call the callback to handle the filename and size
+ if(self->priv->agent_approved_callback)
+ (*self->priv->agent_approved_callback)(self, transfer, filename, size, self->priv->approved_user_data);
+
+ // Return string
+ g_dbus_method_invocation_return_value(invocation, ret);
+ return;
+ }
+ else
+ {
+ // Return error
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.obex.Error.Rejected", "File transfer rejected");
+ return;
+ }
+ }
+ else
+ {
+ g_print("Error: Unknown transfer request\n");
+ // Return error
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.obex.Error.Rejected", "File transfer rejected");
+ return;
+ }
+ }
+ else if (g_strcmp0(method_name, "Cancel") == 0)
+ {
+ g_print("Request cancelled\n");
+ // Return void
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ return;
+ }
+ else if (g_strcmp0(method_name, "Release") == 0)
+ {
+ if (_update_progress)
+ {
+ g_print("\n");
+ _update_progress = FALSE;
+ }
+
+ g_print("OBEXAgent released\n");
+
+ (*self->priv->agent_released_callback)(self, self->priv->user_data);
+
+ // Return void
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ return;
+ }
+}
+
+static void _obex_agent_g_destroy_notify(gpointer data)
+{
+ g_free(data);
+}
+
+void obex_agent_set_release_callback(ObexAgent *self, ObexAgentReleasedCallback callback_function, gpointer user_data)
+{
+ g_assert(OBEX_AGENT_IS(self));
+ self->priv->agent_released_callback = callback_function;
+ self->priv->user_data = user_data;
+}
+
+void obex_agent_clear_release_callback(ObexAgent *self)
+{
+ g_assert(OBEX_AGENT_IS(self));
+ self->priv->agent_released_callback = NULL;
+ self->priv->user_data = NULL;
+}
+
+void obex_agent_set_approved_callback(ObexAgent *self, ObexAgentApprovedCallback callback_function, gpointer user_data)
+{
+ g_assert(OBEX_AGENT_IS(self));
+ self->priv->agent_approved_callback = callback_function;
+ self->priv->approved_user_data = user_data;
+}
+
+void obex_agent_clear_approved_callback(ObexAgent *self)
+{
+ g_assert(OBEX_AGENT_IS(self));
+ self->priv->agent_approved_callback = NULL;
+ self->priv->approved_user_data = NULL;
+} \ No newline at end of file
diff --git a/src/lib/obex_agent.h b/src/lib/obex_agent.h
new file mode 100644
index 0000000..981dc46
--- /dev/null
+++ b/src/lib/obex_agent.h
@@ -0,0 +1,92 @@
+/*
+ *
+ * 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 __OBEX_AGENT_H
+#define __OBEX_AGENT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+
+#define OBEX_AGENT_DBUS_SERVICE "org.blueztools"
+#define OBEX_AGENT_DBUS_INTERFACE "org.bluez.obex.Agent1"
+#define OBEX_AGENT_DBUS_PATH "/org/blueztools/obex"
+
+/*
+ * Type macros
+ */
+#define OBEX_AGENT_TYPE (obex_agent_get_type())
+#define OBEX_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEX_AGENT_TYPE, ObexAgent))
+#define OBEX_AGENT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEX_AGENT_TYPE))
+#define OBEX_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEX_AGENT_TYPE, ObexAgentClass))
+#define OBEX_AGENT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEX_AGENT_TYPE))
+#define OBEX_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEX_AGENT_TYPE, ObexAgentClass))
+
+typedef struct _ObexAgent ObexAgent;
+typedef struct _ObexAgentClass ObexAgentClass;
+typedef struct _ObexAgentPrivate ObexAgentPrivate;
+
+struct _ObexAgent {
+ GObject parent_instance;
+
+ /*< private >*/
+ ObexAgentPrivate *priv;
+};
+
+struct _ObexAgentClass {
+ GObjectClass parent_class;
+};
+
+/* used by OBEX_AGENT_TYPE */
+GType obex_agent_get_type(void) G_GNUC_CONST;
+
+// agent released callback pointer function
+typedef void (*ObexAgentReleasedCallback)(ObexAgent *obex_agent, gpointer user_data);
+
+// agent approved callback pointer function
+typedef void (*ObexAgentApprovedCallback)(ObexAgent *obex_agent, const gchar* obex_transfer_path, const gchar *name, const guint64 size, gpointer user_data);
+
+/*
+ * Constructor
+ */
+ObexAgent *obex_agent_new(const gchar *root_folder);
+
+/*
+ * Method definitions
+ */
+void obex_agent_progress(ObexAgent *self, const gchar *transfer, guint64 transferred, GError **error);
+
+void obex_agent_set_release_callback(ObexAgent *self, ObexAgentReleasedCallback callback_function, gpointer user_data);
+void obex_agent_clear_release_callback(ObexAgent *self);
+
+void obex_agent_set_approved_callback(ObexAgent *self, ObexAgentApprovedCallback callback_function, gpointer user_data);
+void obex_agent_clear_approved_callback(ObexAgent *self);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_AGENT_H */
+
diff --git a/src/lib/obexd/obexagent.c b/src/lib/obexd/obexagent.c
deleted file mode 100644
index a684154..0000000
--- a/src/lib/obexd/obexagent.c
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- *
- * 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 <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../helpers.h"
-
-#include "obexclient_transfer.h"
-#include "obexagent.h"
-
-#define OBEXAGENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXAGENT_TYPE, OBEXAgentPrivate))
-
-struct _OBEXAgentPrivate {
- /* Unused */
- DBusGProxy *proxy;
-
- /* Properties */
- gchar *root_folder;
-};
-
-G_DEFINE_TYPE(OBEXAgent, obexagent, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_ROOT_FOLDER, /* readwrite, construct only */
-};
-
-static void _obexagent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _obexagent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-enum {
- OBEXAGENT_RELEASED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void obexagent_dispose(GObject *gobject)
-{
- OBEXAgent *self = OBEXAGENT(gobject);
-
- dbus_g_connection_unregister_g_object(session_conn, gobject);
-
- /* Proxy free */
- //g_object_unref(self->priv->proxy);
-
- /* Properties free */
- g_free(self->priv->root_folder);
-
- /* Chain up to the parent class */
- G_OBJECT_CLASS(obexagent_parent_class)->dispose(gobject);
-}
-
-static void obexagent_class_init(OBEXAgentClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = obexagent_dispose;
-
- g_type_class_add_private(klass, sizeof(OBEXAgentPrivate));
-
- /* Signals registation */
- signals[OBEXAGENT_RELEASED] = g_signal_new("AgentReleased",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _obexagent_get_property;
- gobject_class->set_property = _obexagent_set_property;
-
- /* string RootFolder [readwrite, construct only] */
- pspec = g_param_spec_string("RootFolder", "root_folder", "Root folder location", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
- g_object_class_install_property(gobject_class, PROP_ROOT_FOLDER, pspec);
-}
-
-static void obexagent_init(OBEXAgent *self)
-{
- self->priv = OBEXAGENT_GET_PRIVATE(self);
-
- g_assert(session_conn != NULL);
-
- /* Properties init */
- self->priv->root_folder = NULL;
-
- dbus_g_connection_register_g_object(session_conn, OBEXAGENT_DBUS_PATH, G_OBJECT(self));
- g_print("OBEXAgent registered\n");
-}
-
-static void _obexagent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- OBEXAgent *self = OBEXAGENT(object);
-
- switch (property_id) {
- case PROP_ROOT_FOLDER:
- g_value_set_string(value, self->priv->root_folder);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _obexagent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- OBEXAgent *self = OBEXAGENT(object);
-
- switch (property_id) {
- case PROP_ROOT_FOLDER:
- self->priv->root_folder = g_value_dup_string(value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-/* Methods */
-
-/* Server API */
-gboolean obexagent_authorize(OBEXAgent *self, const gchar *transfer, const gchar *bt_address, const gchar *name, const gchar *type, gint length, gint time, gchar **ret, GError **error)
-{
- g_assert(self->priv->root_folder != NULL && strlen(self->priv->root_folder) > 0);
-
- *ret = NULL;
- g_print("[ObjectPush Request]\n");
- g_print(" Address: %s\n", bt_address);
- g_print(" Name: %s\n", name);
- if (type && strlen(type)) {
- g_print(" Type: %s\n", type);
- }
- g_print(" Length: %d bytes\n", length);
- /*if (time) {
- g_print(" Time: %d\n", time);
- }*/
-
- gchar yn[4] = {0,};
- g_print("Accept (yes/no)? ");
- errno = 0;
- if (scanf("%3s", yn) == EOF && errno) {
- g_warning("%s\n", strerror(errno));
- }
- if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) {
- if (!g_path_is_absolute(self->priv->root_folder)) {
- gchar *abs_path = get_absolute_path(self->priv->root_folder);
- *ret = g_build_filename(abs_path, name, NULL);
- g_free(abs_path);
- } else {
- *ret = g_build_filename(self->priv->root_folder, name, NULL);
- }
-
- return TRUE;
- } else {
- // TODO: Fix error code
- if (error)
- *error = g_error_new(g_quark_from_static_string("org.openobex.Error.Rejected"), 0, "File transfer rejected");
- return FALSE;
- }
-}
-
-gboolean obexagent_cancel(OBEXAgent *self, GError **error)
-{
- g_print("Request cancelled\n");
- return TRUE;
-}
-
-/* Client API */
-static gboolean update_progress = FALSE;
-
-gboolean obexagent_release(OBEXAgent *self, GError **error)
-{
- if (update_progress) {
- g_print("\n");
- update_progress = FALSE;
- }
-
- g_print("OBEXAgent released\n");
-
- g_signal_emit(self, signals[OBEXAGENT_RELEASED], 0);
-
- return TRUE;
-}
-
-gboolean obexagent_request(OBEXAgent *self, const gchar *transfer, gchar **ret, GError **error)
-{
- *ret = NULL;
-
- if (intf_supported(OBEXC_DBUS_NAME, transfer, OBEXCLIENT_TRANSFER_DBUS_INTERFACE)) {
- OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL);
- g_print("[Transfer Request]\n");
- g_print(" Name: %s\n", obexclient_transfer_get_name(transfer_t));
- g_print(" Size: %llu bytes\n", obexclient_transfer_get_size(transfer_t));
- g_print(" Filename: %s\n", obexclient_transfer_get_filename(transfer_t));
- g_object_unref(transfer_t);
-
- gchar yn[4] = {0,};
- g_print("Accept (yes/no)? ");
- errno = 0;
- if (scanf("%3s", yn) == EOF && errno) {
- g_warning("%s\n", strerror(errno));
- }
- if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) {
- return TRUE;
- } else {
- // TODO: Fix error code
- if (error)
- *error = g_error_new(g_quark_from_static_string("org.openobex.Error.Rejected"), 0, "File transfer rejected");
- return FALSE;
- }
- } else {
- g_print("Error: Unknown transfer request\n");
- // TODO: Fix error code
- if (error)
- *error = g_error_new(g_quark_from_static_string("org.openobex.Error.Rejected"), 0, "File transfer rejected");
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean obexagent_progress(OBEXAgent *self, const gchar *transfer, guint64 transferred, GError **error)
-{
- if (intf_supported(OBEXC_DBUS_NAME, transfer, OBEXCLIENT_TRANSFER_DBUS_INTERFACE)) {
- OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL);
- guint64 total = obexclient_transfer_get_size(transfer_t);
-
- guint pp = (transferred / (gfloat) total)*100;
-
- if (!update_progress) {
- g_print("[Transfer#%s] Progress: %3u%%", obexclient_transfer_get_name(transfer_t), pp);
- update_progress = TRUE;
- } else {
- g_print("\b\b\b\b%3u%%", pp);
- }
-
- if (pp == 100) {
- g_print("\n");
- update_progress = FALSE;
- }
-
- g_object_unref(transfer_t);
- }
-
- return TRUE;
-}
-
-gboolean obexagent_complete(OBEXAgent *self, const gchar *transfer, GError **error)
-{
- if (update_progress) {
- g_print("\n");
- update_progress = FALSE;
- }
-
- if (intf_supported(OBEXC_DBUS_NAME, transfer, OBEXCLIENT_TRANSFER_DBUS_INTERFACE)) {
- OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL);
- g_print("[Transfer#%s] Completed\n", obexclient_transfer_get_name(transfer_t));
- g_object_unref(transfer_t);
- }
-
- return TRUE;
-}
-
-gboolean obexagent_error(OBEXAgent *self, const gchar *transfer, const gchar *message, GError **error)
-{
- if (update_progress) {
- g_print("\n");
- update_progress = FALSE;
- }
-
- g_print("[Transfer] Error: %s\n", message);
-
- /*
- * Transfer interface does not exists
- * Code commented
- *
- if (intf_supported(OBEXC_DBUS_NAME, transfer, OBEXCLIENT_TRANSFER_DBUS_INTERFACE)) {
- OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL);
- g_print("[Transfer#%s] Error: %s\n", obexclient_transfer_get_name(transfer_t), message);
- g_object_unref(transfer_t);
- }
- */
-
- return TRUE;
-}
-
diff --git a/src/lib/obexd/obexagent.h b/src/lib/obexd/obexagent.h
deleted file mode 100644
index b94fb2c..0000000
--- a/src/lib/obexd/obexagent.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- *
- * 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 __OBEXAGENT_H
-#define __OBEXAGENT_H
-
-#include <glib-object.h>
-#include <dbus/dbus-glib.h>
-
-#include "../marshallers.h"
-
-#define OBEXAGENT_DBUS_PATH "/ObexAgent"
-
-/*
- * Type macros
- */
-#define OBEXAGENT_TYPE (obexagent_get_type())
-#define OBEXAGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXAGENT_TYPE, OBEXAgent))
-#define OBEXAGENT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXAGENT_TYPE))
-#define OBEXAGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXAGENT_TYPE, OBEXAgentClass))
-#define OBEXAGENT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXAGENT_TYPE))
-#define OBEXAGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXAGENT_TYPE, OBEXAgentClass))
-
-typedef struct _OBEXAgent OBEXAgent;
-typedef struct _OBEXAgentClass OBEXAgentClass;
-typedef struct _OBEXAgentPrivate OBEXAgentPrivate;
-
-struct _OBEXAgent {
- GObject parent_instance;
-
- /*< private >*/
- OBEXAgentPrivate *priv;
-};
-
-struct _OBEXAgentClass {
- GObjectClass parent_class;
-};
-
-/* used by OBEXAGENT_TYPE */
-GType obexagent_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-
-/* Server API */
-gboolean obexagent_authorize(OBEXAgent *self, const gchar *transfer, const gchar *bt_address, const gchar *name, const gchar *type, gint length, gint time, gchar **ret, GError **error);
-gboolean obexagent_cancel(OBEXAgent *self, GError **error);
-
-/* Client API */
-gboolean obexagent_release(OBEXAgent *self, GError **error);
-gboolean obexagent_request(OBEXAgent *self, const gchar *transfer, gchar **ret, GError **error);
-gboolean obexagent_progress(OBEXAgent *self, const gchar *transfer, guint64 transferred, GError **error);
-gboolean obexagent_complete(OBEXAgent *self, const gchar *transfer, GError **error);
-gboolean obexagent_error(OBEXAgent *self, const gchar *transfer, const gchar *message, GError **error);
-
-/* Glue code */
-static const DBusGMethodInfo dbus_glib_obexagent_methods[] = {
- { (GCallback) obexagent_authorize, g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_POINTER_POINTER, 0},
- { (GCallback) obexagent_cancel, g_cclosure_bt_marshal_BOOLEAN__POINTER, 111},
- { (GCallback) obexagent_release, g_cclosure_bt_marshal_BOOLEAN__POINTER, 140},
- { (GCallback) obexagent_request, g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER_POINTER, 170},
- { (GCallback) obexagent_progress, g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT64_POINTER, 226},
- { (GCallback) obexagent_complete, g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER, 286},
- { (GCallback) obexagent_error, g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_POINTER, 330},
-};
-
-static const DBusGObjectInfo dbus_glib_obexagent_object_info = {
- 0,
- dbus_glib_obexagent_methods,
- 7,
- "org.openobex.Agent\0Authorize\0S\0transfer\0I\0o\0bt_address\0I\0s\0name\0I\0s\0type\0I\0s\0length\0I\0i\0time\0I\0i\0arg6\0O\0F\0N\0s\0\0org.openobex.Agent\0Cancel\0S\0\0org.openobex.Agent\0Release\0S\0\0org.openobex.Agent\0Request\0S\0transfer\0I\0o\0arg1\0O\0F\0N\0s\0\0org.openobex.Agent\0Progress\0S\0transfer\0I\0o\0transferred\0I\0t\0\0org.openobex.Agent\0Complete\0S\0transfer\0I\0o\0\0org.openobex.Agent\0Error\0S\0transfer\0I\0o\0message\0I\0s\0\0\0",
- "\0",
- "\0"
-};
-
-#endif /* __OBEXAGENT_H */
-
diff --git a/src/lib/obexd/obexclient.c b/src/lib/obexd/obexclient.c
deleted file mode 100644
index d8cfa78..0000000
--- a/src/lib/obexd/obexclient.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "obexclient.h"
-
-#define OBEXCLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXCLIENT_TYPE, OBEXClientPrivate))
-
-struct _OBEXClientPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-};
-
-G_DEFINE_TYPE(OBEXClient, obexclient, G_TYPE_OBJECT);
-
-static void obexclient_dispose(GObject *gobject)
-{
- OBEXClient *self = OBEXCLIENT(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(obexclient_parent_class)->dispose(gobject);
-}
-
-static void obexclient_class_init(OBEXClientClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = obexclient_dispose;
-
- g_type_class_add_private(klass, sizeof(OBEXClientPrivate));
-}
-
-static void obexclient_init(OBEXClient *self)
-{
- self->priv = OBEXCLIENT_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(session_conn != NULL);
-
- GError *error = NULL;
-
- /* Getting introspection XML */
- self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", OBEXCLIENT_DBUS_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 *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXCLIENT_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXCLIENT_DBUS_INTERFACE, OBEXCLIENT_DBUS_PATH);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
-
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", OBEXCLIENT_DBUS_PATH, OBEXCLIENT_DBUS_INTERFACE);
-}
-
-/* Methods */
-
-/* object CreateSession(dict device) */
-gchar *obexclient_create_session(OBEXClient *self, const GHashTable *device, GError **error)
-{
- g_assert(OBEXCLIENT_IS(self));
-
- gchar *ret = NULL;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "CreateSession", error, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, device, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &ret, G_TYPE_INVALID);
-
- return ret;
-}
-
-/* void ExchangeBusinessCards(dict device, string clientfile, string file) */
-void obexclient_exchange_business_cards(OBEXClient *self, const GHashTable *device, const gchar *clientfile, const gchar *file, GError **error)
-{
- g_assert(OBEXCLIENT_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "ExchangeBusinessCards", error, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, device, G_TYPE_STRING, clientfile, G_TYPE_STRING, file, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* string GetCapabilities(dict device) */
-gchar *obexclient_get_capabilities(OBEXClient *self, const GHashTable *device, GError **error)
-{
- g_assert(OBEXCLIENT_IS(self));
-
- gchar *ret = NULL;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetCapabilities", error, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, device, G_TYPE_INVALID, G_TYPE_STRING, &ret, G_TYPE_INVALID);
-
- return ret;
-}
-
-/* void PullBusinessCard(dict device, string file) */
-void obexclient_pull_business_card(OBEXClient *self, const GHashTable *device, const gchar *file, GError **error)
-{
- g_assert(OBEXCLIENT_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "PullBusinessCard", error, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, device, G_TYPE_STRING, file, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void RemoveSession(object session) */
-void obexclient_remove_session(OBEXClient *self, const gchar *session, GError **error)
-{
- g_assert(OBEXCLIENT_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "RemoveSession", error, DBUS_TYPE_G_OBJECT_PATH, session, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void SendFiles(dict device, array{string} files, object agent) */
-void obexclient_send_files(OBEXClient *self, const GHashTable *device, const gchar **files, const gchar *agent, GError **error)
-{
- g_assert(OBEXCLIENT_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "SendFiles", error, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, device, G_TYPE_STRV, files, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
diff --git a/src/lib/obexd/obexclient.h b/src/lib/obexd/obexclient.h
deleted file mode 100644
index d999b76..0000000
--- a/src/lib/obexd/obexclient.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- *
- * 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 __OBEXCLIENT_H
-#define __OBEXCLIENT_H
-
-#include <glib-object.h>
-
-#define OBEXCLIENT_DBUS_PATH "/"
-#define OBEXCLIENT_DBUS_INTERFACE "org.openobex.Client"
-
-/*
- * Type macros
- */
-#define OBEXCLIENT_TYPE (obexclient_get_type())
-#define OBEXCLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXCLIENT_TYPE, OBEXClient))
-#define OBEXCLIENT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXCLIENT_TYPE))
-#define OBEXCLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXCLIENT_TYPE, OBEXClientClass))
-#define OBEXCLIENT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXCLIENT_TYPE))
-#define OBEXCLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXCLIENT_TYPE, OBEXClientClass))
-
-typedef struct _OBEXClient OBEXClient;
-typedef struct _OBEXClientClass OBEXClientClass;
-typedef struct _OBEXClientPrivate OBEXClientPrivate;
-
-struct _OBEXClient {
- GObject parent_instance;
-
- /*< private >*/
- OBEXClientPrivate *priv;
-};
-
-struct _OBEXClientClass {
- GObjectClass parent_class;
-};
-
-/* used by OBEXCLIENT_TYPE */
-GType obexclient_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-gchar *obexclient_create_session(OBEXClient *self, const GHashTable *device, GError **error);
-void obexclient_exchange_business_cards(OBEXClient *self, const GHashTable *device, const gchar *clientfile, const gchar *file, GError **error);
-gchar *obexclient_get_capabilities(OBEXClient *self, const GHashTable *device, GError **error);
-void obexclient_pull_business_card(OBEXClient *self, const GHashTable *device, const gchar *file, GError **error);
-void obexclient_remove_session(OBEXClient *self, const gchar *session, GError **error);
-void obexclient_send_files(OBEXClient *self, const GHashTable *device, const gchar **files, const gchar *agent, GError **error);
-
-#endif /* __OBEXCLIENT_H */
-
diff --git a/src/lib/obexd/obexclient_file_transfer.c b/src/lib/obexd/obexclient_file_transfer.c
deleted file mode 100644
index 05fa36d..0000000
--- a/src/lib/obexd/obexclient_file_transfer.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "obexclient_file_transfer.h"
-
-#define OBEXCLIENT_FILE_TRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXCLIENT_FILE_TRANSFER_TYPE, OBEXClientFileTransferPrivate))
-
-struct _OBEXClientFileTransferPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-};
-
-G_DEFINE_TYPE(OBEXClientFileTransfer, obexclient_file_transfer, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
-};
-
-static void _obexclient_file_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _obexclient_file_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-static void obexclient_file_transfer_dispose(GObject *gobject)
-{
- OBEXClientFileTransfer *self = OBEXCLIENT_FILE_TRANSFER(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(obexclient_file_transfer_parent_class)->dispose(gobject);
-}
-
-static void obexclient_file_transfer_class_init(OBEXClientFileTransferClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = obexclient_file_transfer_dispose;
-
- g_type_class_add_private(klass, sizeof(OBEXClientFileTransferPrivate));
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _obexclient_file_transfer_get_property;
- gobject_class->set_property = _obexclient_file_transfer_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);
-}
-
-static void obexclient_file_transfer_init(OBEXClientFileTransfer *self)
-{
- self->priv = OBEXCLIENT_FILE_TRANSFER_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(session_conn != NULL);
-}
-
-static void obexclient_file_transfer_post_init(OBEXClientFileTransfer *self, const gchar *dbus_object_path)
-{
- 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(session_conn, "org.openobex.client", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXCLIENT_FILE_TRANSFER_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXCLIENT_FILE_TRANSFER_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", dbus_object_path, OBEXCLIENT_FILE_TRANSFER_DBUS_INTERFACE);
-}
-
-static void _obexclient_file_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- OBEXClientFileTransfer *self = OBEXCLIENT_FILE_TRANSFER(object);
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- g_value_set_string(value, obexclient_file_transfer_get_dbus_object_path(self));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _obexclient_file_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- OBEXClientFileTransfer *self = OBEXCLIENT_FILE_TRANSFER(object);
- GError *error = NULL;
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- obexclient_file_transfer_post_init(self, g_value_get_string(value));
- 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);
-}
-
-/* Methods */
-
-/* void ChangeFolder(string folder) */
-void obexclient_file_transfer_change_folder(OBEXClientFileTransfer *self, const gchar *folder, GError **error)
-{
- g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "ChangeFolder", error, G_TYPE_STRING, folder, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void CopyFile(string sourcefile, string targetfile) */
-void obexclient_file_transfer_copy_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error)
-{
- g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "CopyFile", error, G_TYPE_STRING, sourcefile, G_TYPE_STRING, targetfile, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void CreateFolder(string folder) */
-void obexclient_file_transfer_create_folder(OBEXClientFileTransfer *self, const gchar *folder, GError **error)
-{
- g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "CreateFolder", error, G_TYPE_STRING, folder, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void Delete(string file) */
-void obexclient_file_transfer_delete(OBEXClientFileTransfer *self, const gchar *file, GError **error)
-{
- g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Delete", error, G_TYPE_STRING, file, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void GetFile(string targetfile, string sourcefile) */
-void obexclient_file_transfer_get_file(OBEXClientFileTransfer *self, const gchar *targetfile, const gchar *sourcefile, GError **error)
-{
- g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetFile", error, G_TYPE_STRING, targetfile, G_TYPE_STRING, sourcefile, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* array{dict} ListFolder() */
-GPtrArray *obexclient_file_transfer_list_folder(OBEXClientFileTransfer *self, GError **error)
-{
- g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self));
-
- GPtrArray *ret = NULL;
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "ListFolder", error, G_TYPE_INVALID, DBUS_TYPE_G_HASH_TABLE_ARRAY, &ret, G_TYPE_INVALID);
-
- return ret;
-}
-
-/* void MoveFile(string sourcefile, string targetfile) */
-void obexclient_file_transfer_move_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error)
-{
- g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "MoveFile", error, G_TYPE_STRING, sourcefile, G_TYPE_STRING, targetfile, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void PutFile(string sourcefile, string targetfile) */
-void obexclient_file_transfer_put_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error)
-{
- g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "PutFile", error, G_TYPE_STRING, sourcefile, G_TYPE_STRING, targetfile, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* Properties access methods */
-const gchar *obexclient_file_transfer_get_dbus_object_path(OBEXClientFileTransfer *self)
-{
- g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
-}
-
diff --git a/src/lib/obexd/obexclient_file_transfer.h b/src/lib/obexd/obexclient_file_transfer.h
deleted file mode 100644
index 5e796b2..0000000
--- a/src/lib/obexd/obexclient_file_transfer.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- *
- * 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 __OBEXCLIENT_FILE_TRANSFER_H
-#define __OBEXCLIENT_FILE_TRANSFER_H
-
-#include <glib-object.h>
-
-#define OBEXCLIENT_FILE_TRANSFER_DBUS_INTERFACE "org.openobex.FileTransfer"
-
-/*
- * Type macros
- */
-#define OBEXCLIENT_FILE_TRANSFER_TYPE (obexclient_file_transfer_get_type())
-#define OBEXCLIENT_FILE_TRANSFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXCLIENT_FILE_TRANSFER_TYPE, OBEXClientFileTransfer))
-#define OBEXCLIENT_FILE_TRANSFER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXCLIENT_FILE_TRANSFER_TYPE))
-#define OBEXCLIENT_FILE_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXCLIENT_FILE_TRANSFER_TYPE, OBEXClientFileTransferClass))
-#define OBEXCLIENT_FILE_TRANSFER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXCLIENT_FILE_TRANSFER_TYPE))
-#define OBEXCLIENT_FILE_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXCLIENT_FILE_TRANSFER_TYPE, OBEXClientFileTransferClass))
-
-typedef struct _OBEXClientFileTransfer OBEXClientFileTransfer;
-typedef struct _OBEXClientFileTransferClass OBEXClientFileTransferClass;
-typedef struct _OBEXClientFileTransferPrivate OBEXClientFileTransferPrivate;
-
-struct _OBEXClientFileTransfer {
- GObject parent_instance;
-
- /*< private >*/
- OBEXClientFileTransferPrivate *priv;
-};
-
-struct _OBEXClientFileTransferClass {
- GObjectClass parent_class;
-};
-
-/* used by OBEXCLIENT_FILE_TRANSFER_TYPE */
-GType obexclient_file_transfer_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-void obexclient_file_transfer_change_folder(OBEXClientFileTransfer *self, const gchar *folder, GError **error);
-void obexclient_file_transfer_copy_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error);
-void obexclient_file_transfer_create_folder(OBEXClientFileTransfer *self, const gchar *folder, GError **error);
-void obexclient_file_transfer_delete(OBEXClientFileTransfer *self, const gchar *file, GError **error);
-void obexclient_file_transfer_get_file(OBEXClientFileTransfer *self, const gchar *targetfile, const gchar *sourcefile, GError **error);
-GPtrArray *obexclient_file_transfer_list_folder(OBEXClientFileTransfer *self, GError **error);
-void obexclient_file_transfer_move_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error);
-void obexclient_file_transfer_put_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error);
-
-const gchar *obexclient_file_transfer_get_dbus_object_path(OBEXClientFileTransfer *self);
-
-#endif /* __OBEXCLIENT_FILE_TRANSFER_H */
-
diff --git a/src/lib/obexd/obexclient_session.c b/src/lib/obexd/obexclient_session.c
deleted file mode 100644
index a5b52f8..0000000
--- a/src/lib/obexd/obexclient_session.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "obexclient_session.h"
-
-#define OBEXCLIENT_SESSION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXCLIENT_SESSION_TYPE, OBEXClientSessionPrivate))
-
-struct _OBEXClientSessionPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-
- /* Properties */
- guchar channel;
- gchar *destination;
- gchar *source;
-};
-
-G_DEFINE_TYPE(OBEXClientSession, obexclient_session, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
- PROP_CHANNEL, /* readonly */
- PROP_DESTINATION, /* readonly */
- PROP_SOURCE /* readonly */
-};
-
-static void _obexclient_session_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _obexclient_session_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-static void obexclient_session_dispose(GObject *gobject)
-{
- OBEXClientSession *self = OBEXCLIENT_SESSION(gobject);
-
- /* Properties free */
- g_free(self->priv->destination);
- g_free(self->priv->source);
-
- /* 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(obexclient_session_parent_class)->dispose(gobject);
-}
-
-static void obexclient_session_class_init(OBEXClientSessionClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = obexclient_session_dispose;
-
- g_type_class_add_private(klass, sizeof(OBEXClientSessionPrivate));
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _obexclient_session_get_property;
- gobject_class->set_property = _obexclient_session_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);
-
- /* byte Channel [readonly] */
- pspec = g_param_spec_uchar("Channel", NULL, NULL, 0, 0xFF, 0, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_CHANNEL, pspec);
-
- /* string Destination [readonly] */
- pspec = g_param_spec_string("Destination", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_DESTINATION, pspec);
-
- /* string Source [readonly] */
- pspec = g_param_spec_string("Source", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_SOURCE, pspec);
-}
-
-static void obexclient_session_init(OBEXClientSession *self)
-{
- self->priv = OBEXCLIENT_SESSION_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(session_conn != NULL);
-}
-
-static void obexclient_session_post_init(OBEXClientSession *self, const gchar *dbus_object_path)
-{
- 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(session_conn, "org.openobex.client", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXCLIENT_SESSION_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXCLIENT_SESSION_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", dbus_object_path, OBEXCLIENT_SESSION_DBUS_INTERFACE);
-
- /* Properties init */
- GHashTable *properties = obexclient_session_get_properties(self, &error);
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
- g_assert(properties != NULL);
-
- /* byte Channel [readonly] */
- if (g_hash_table_lookup(properties, "Channel")) {
- self->priv->channel = g_value_get_uchar(g_hash_table_lookup(properties, "Channel"));
- } else {
- self->priv->channel = 0;
- }
-
- /* string Destination [readonly] */
- if (g_hash_table_lookup(properties, "Destination")) {
- self->priv->destination = g_value_dup_string(g_hash_table_lookup(properties, "Destination"));
- } else {
- self->priv->destination = g_strdup("undefined");
- }
-
- /* string Source [readonly] */
- if (g_hash_table_lookup(properties, "Source")) {
- self->priv->source = g_value_dup_string(g_hash_table_lookup(properties, "Source"));
- } else {
- self->priv->source = g_strdup("undefined");
- }
-
- g_hash_table_unref(properties);
-}
-
-static void _obexclient_session_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- OBEXClientSession *self = OBEXCLIENT_SESSION(object);
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- g_value_set_string(value, obexclient_session_get_dbus_object_path(self));
- break;
-
- case PROP_CHANNEL:
- g_value_set_uchar(value, obexclient_session_get_channel(self));
- break;
-
- case PROP_DESTINATION:
- g_value_set_string(value, obexclient_session_get_destination(self));
- break;
-
- case PROP_SOURCE:
- g_value_set_string(value, obexclient_session_get_source(self));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _obexclient_session_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- OBEXClientSession *self = OBEXCLIENT_SESSION(object);
- GError *error = NULL;
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- obexclient_session_post_init(self, g_value_get_string(value));
- 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);
-}
-
-/* Methods */
-
-/* void AssignAgent(object agent) */
-void obexclient_session_assign_agent(OBEXClientSession *self, const gchar *agent, GError **error)
-{
- g_assert(OBEXCLIENT_SESSION_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "AssignAgent", error, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* dict GetProperties() */
-GHashTable *obexclient_session_get_properties(OBEXClientSession *self, GError **error)
-{
- g_assert(OBEXCLIENT_SESSION_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 ReleaseAgent(object agent) */
-void obexclient_session_release_agent(OBEXClientSession *self, const gchar *agent, GError **error)
-{
- g_assert(OBEXCLIENT_SESSION_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "ReleaseAgent", error, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* Properties access methods */
-const gchar *obexclient_session_get_dbus_object_path(OBEXClientSession *self)
-{
- g_assert(OBEXCLIENT_SESSION_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
-}
-
-const guchar obexclient_session_get_channel(OBEXClientSession *self)
-{
- g_assert(OBEXCLIENT_SESSION_IS(self));
-
- return self->priv->channel;
-}
-
-const gchar *obexclient_session_get_destination(OBEXClientSession *self)
-{
- g_assert(OBEXCLIENT_SESSION_IS(self));
-
- return self->priv->destination;
-}
-
-const gchar *obexclient_session_get_source(OBEXClientSession *self)
-{
- g_assert(OBEXCLIENT_SESSION_IS(self));
-
- return self->priv->source;
-}
-
diff --git a/src/lib/obexd/obexclient_session.h b/src/lib/obexd/obexclient_session.h
deleted file mode 100644
index 87af06d..0000000
--- a/src/lib/obexd/obexclient_session.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- *
- * 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 __OBEXCLIENT_SESSION_H
-#define __OBEXCLIENT_SESSION_H
-
-#include <glib-object.h>
-
-#define OBEXCLIENT_SESSION_DBUS_INTERFACE "org.openobex.Session"
-
-/*
- * Type macros
- */
-#define OBEXCLIENT_SESSION_TYPE (obexclient_session_get_type())
-#define OBEXCLIENT_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXCLIENT_SESSION_TYPE, OBEXClientSession))
-#define OBEXCLIENT_SESSION_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXCLIENT_SESSION_TYPE))
-#define OBEXCLIENT_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXCLIENT_SESSION_TYPE, OBEXClientSessionClass))
-#define OBEXCLIENT_SESSION_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXCLIENT_SESSION_TYPE))
-#define OBEXCLIENT_SESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXCLIENT_SESSION_TYPE, OBEXClientSessionClass))
-
-typedef struct _OBEXClientSession OBEXClientSession;
-typedef struct _OBEXClientSessionClass OBEXClientSessionClass;
-typedef struct _OBEXClientSessionPrivate OBEXClientSessionPrivate;
-
-struct _OBEXClientSession {
- GObject parent_instance;
-
- /*< private >*/
- OBEXClientSessionPrivate *priv;
-};
-
-struct _OBEXClientSessionClass {
- GObjectClass parent_class;
-};
-
-/* used by OBEXCLIENT_SESSION_TYPE */
-GType obexclient_session_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-void obexclient_session_assign_agent(OBEXClientSession *self, const gchar *agent, GError **error);
-GHashTable *obexclient_session_get_properties(OBEXClientSession *self, GError **error);
-void obexclient_session_release_agent(OBEXClientSession *self, const gchar *agent, GError **error);
-
-const gchar *obexclient_session_get_dbus_object_path(OBEXClientSession *self);
-const guchar obexclient_session_get_channel(OBEXClientSession *self);
-const gchar *obexclient_session_get_destination(OBEXClientSession *self);
-const gchar *obexclient_session_get_source(OBEXClientSession *self);
-
-#endif /* __OBEXCLIENT_SESSION_H */
-
diff --git a/src/lib/obexd/obexclient_transfer.c b/src/lib/obexd/obexclient_transfer.c
deleted file mode 100644
index 68c4bf3..0000000
--- a/src/lib/obexd/obexclient_transfer.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "obexclient_transfer.h"
-
-#define OBEXCLIENT_TRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXCLIENT_TRANSFER_TYPE, OBEXClientTransferPrivate))
-
-struct _OBEXClientTransferPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-
- /* Properties */
- gchar *filename;
- gchar *name;
- guint64 size;
-};
-
-G_DEFINE_TYPE(OBEXClientTransfer, obexclient_transfer, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
- PROP_FILENAME, /* readonly */
- PROP_NAME, /* readonly */
- PROP_SIZE /* readonly */
-};
-
-static void _obexclient_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _obexclient_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-static void obexclient_transfer_dispose(GObject *gobject)
-{
- OBEXClientTransfer *self = OBEXCLIENT_TRANSFER(gobject);
-
- /* Properties free */
- g_free(self->priv->filename);
- g_free(self->priv->name);
-
- /* 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(obexclient_transfer_parent_class)->dispose(gobject);
-}
-
-static void obexclient_transfer_class_init(OBEXClientTransferClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = obexclient_transfer_dispose;
-
- g_type_class_add_private(klass, sizeof(OBEXClientTransferPrivate));
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _obexclient_transfer_get_property;
- gobject_class->set_property = _obexclient_transfer_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);
-
- /* string Filename [readonly] */
- pspec = g_param_spec_string("Filename", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_FILENAME, pspec);
-
- /* string Name [readonly] */
- pspec = g_param_spec_string("Name", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_NAME, pspec);
-
- /* uint64 Size [readonly] */
- pspec = g_param_spec_uint64("Size", NULL, NULL, 0, 0xFFFFFFFFFFFFFFFF, 0, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_SIZE, pspec);
-}
-
-static void obexclient_transfer_init(OBEXClientTransfer *self)
-{
- self->priv = OBEXCLIENT_TRANSFER_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(session_conn != NULL);
-}
-
-static void obexclient_transfer_post_init(OBEXClientTransfer *self, const gchar *dbus_object_path)
-{
- 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(session_conn, "org.openobex.client", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXCLIENT_TRANSFER_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXCLIENT_TRANSFER_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", dbus_object_path, OBEXCLIENT_TRANSFER_DBUS_INTERFACE);
-
- /* Properties init */
- GHashTable *properties = obexclient_transfer_get_properties(self, &error);
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
- g_assert(properties != NULL);
-
- /* string Filename [readonly] */
- if (g_hash_table_lookup(properties, "Filename")) {
- self->priv->filename = g_value_dup_string(g_hash_table_lookup(properties, "Filename"));
- } else {
- self->priv->filename = g_strdup("undefined");
- }
-
- /* string Name [readonly] */
- 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");
- }
-
- /* uint64 Size [readonly] */
- if (g_hash_table_lookup(properties, "Size")) {
- self->priv->size = g_value_get_uint64(g_hash_table_lookup(properties, "Size"));
- } else {
- self->priv->size = 0;
- }
-
- g_hash_table_unref(properties);
-}
-
-static void _obexclient_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- OBEXClientTransfer *self = OBEXCLIENT_TRANSFER(object);
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- g_value_set_string(value, obexclient_transfer_get_dbus_object_path(self));
- break;
-
- case PROP_FILENAME:
- g_value_set_string(value, obexclient_transfer_get_filename(self));
- break;
-
- case PROP_NAME:
- g_value_set_string(value, obexclient_transfer_get_name(self));
- break;
-
- case PROP_SIZE:
- g_value_set_uint64(value, obexclient_transfer_get_size(self));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _obexclient_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- OBEXClientTransfer *self = OBEXCLIENT_TRANSFER(object);
- GError *error = NULL;
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- obexclient_transfer_post_init(self, g_value_get_string(value));
- 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);
-}
-
-/* Methods */
-
-/* void Cancel() */
-void obexclient_transfer_cancel(OBEXClientTransfer *self, GError **error)
-{
- g_assert(OBEXCLIENT_TRANSFER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Cancel", error, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* dict GetProperties() */
-GHashTable *obexclient_transfer_get_properties(OBEXClientTransfer *self, GError **error)
-{
- g_assert(OBEXCLIENT_TRANSFER_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;
-}
-
-/* Properties access methods */
-const gchar *obexclient_transfer_get_dbus_object_path(OBEXClientTransfer *self)
-{
- g_assert(OBEXCLIENT_TRANSFER_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
-}
-
-const gchar *obexclient_transfer_get_filename(OBEXClientTransfer *self)
-{
- g_assert(OBEXCLIENT_TRANSFER_IS(self));
-
- return self->priv->filename;
-}
-
-const gchar *obexclient_transfer_get_name(OBEXClientTransfer *self)
-{
- g_assert(OBEXCLIENT_TRANSFER_IS(self));
-
- return self->priv->name;
-}
-
-const guint64 obexclient_transfer_get_size(OBEXClientTransfer *self)
-{
- g_assert(OBEXCLIENT_TRANSFER_IS(self));
-
- return self->priv->size;
-}
-
diff --git a/src/lib/obexd/obexclient_transfer.h b/src/lib/obexd/obexclient_transfer.h
deleted file mode 100644
index f84fd69..0000000
--- a/src/lib/obexd/obexclient_transfer.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- *
- * 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 __OBEXCLIENT_TRANSFER_H
-#define __OBEXCLIENT_TRANSFER_H
-
-#include <glib-object.h>
-
-#define OBEXCLIENT_TRANSFER_DBUS_INTERFACE "org.openobex.Transfer"
-
-/*
- * Type macros
- */
-#define OBEXCLIENT_TRANSFER_TYPE (obexclient_transfer_get_type())
-#define OBEXCLIENT_TRANSFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXCLIENT_TRANSFER_TYPE, OBEXClientTransfer))
-#define OBEXCLIENT_TRANSFER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXCLIENT_TRANSFER_TYPE))
-#define OBEXCLIENT_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXCLIENT_TRANSFER_TYPE, OBEXClientTransferClass))
-#define OBEXCLIENT_TRANSFER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXCLIENT_TRANSFER_TYPE))
-#define OBEXCLIENT_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXCLIENT_TRANSFER_TYPE, OBEXClientTransferClass))
-
-typedef struct _OBEXClientTransfer OBEXClientTransfer;
-typedef struct _OBEXClientTransferClass OBEXClientTransferClass;
-typedef struct _OBEXClientTransferPrivate OBEXClientTransferPrivate;
-
-struct _OBEXClientTransfer {
- GObject parent_instance;
-
- /*< private >*/
- OBEXClientTransferPrivate *priv;
-};
-
-struct _OBEXClientTransferClass {
- GObjectClass parent_class;
-};
-
-/* used by OBEXCLIENT_TRANSFER_TYPE */
-GType obexclient_transfer_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-void obexclient_transfer_cancel(OBEXClientTransfer *self, GError **error);
-GHashTable *obexclient_transfer_get_properties(OBEXClientTransfer *self, GError **error);
-
-const gchar *obexclient_transfer_get_dbus_object_path(OBEXClientTransfer *self);
-const gchar *obexclient_transfer_get_filename(OBEXClientTransfer *self);
-const gchar *obexclient_transfer_get_name(OBEXClientTransfer *self);
-const guint64 obexclient_transfer_get_size(OBEXClientTransfer *self);
-
-#endif /* __OBEXCLIENT_TRANSFER_H */
-
diff --git a/src/lib/obexd/obexmanager.c b/src/lib/obexd/obexmanager.c
deleted file mode 100644
index 1e3e0d4..0000000
--- a/src/lib/obexd/obexmanager.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "obexmanager.h"
-
-#define OBEXMANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXMANAGER_TYPE, OBEXManagerPrivate))
-
-struct _OBEXManagerPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-};
-
-G_DEFINE_TYPE(OBEXManager, obexmanager, G_TYPE_OBJECT);
-
-enum {
- SESSION_CREATED,
- SESSION_REMOVED,
- TRANSFER_COMPLETED,
- TRANSFER_STARTED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void session_created_handler(DBusGProxy *dbus_g_proxy, const gchar *session, gpointer data);
-static void session_removed_handler(DBusGProxy *dbus_g_proxy, const gchar *session, gpointer data);
-static void transfer_completed_handler(DBusGProxy *dbus_g_proxy, const gchar *transfer, const gboolean success, gpointer data);
-static void transfer_started_handler(DBusGProxy *dbus_g_proxy, const gchar *transfer, gpointer data);
-
-static void obexmanager_dispose(GObject *gobject)
-{
- OBEXManager *self = OBEXMANAGER(gobject);
-
- /* DBus signals disconnection */
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "SessionCreated", G_CALLBACK(session_created_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "SessionRemoved", G_CALLBACK(session_removed_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "TransferCompleted", G_CALLBACK(transfer_completed_handler), self);
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "TransferStarted", G_CALLBACK(transfer_started_handler), self);
-
- /* 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(obexmanager_parent_class)->dispose(gobject);
-}
-
-static void obexmanager_class_init(OBEXManagerClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = obexmanager_dispose;
-
- g_type_class_add_private(klass, sizeof(OBEXManagerPrivate));
-
- /* Signals registation */
- signals[SESSION_CREATED] = g_signal_new("SessionCreated",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[SESSION_REMOVED] = g_signal_new("SessionRemoved",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[TRANSFER_COMPLETED] = g_signal_new("TransferCompleted",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_bt_marshal_VOID__STRING_BOOLEAN,
- G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_BOOLEAN);
-
- signals[TRANSFER_STARTED] = g_signal_new("TransferStarted",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-}
-
-static void obexmanager_init(OBEXManager *self)
-{
- self->priv = OBEXMANAGER_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(session_conn != NULL);
-
- GError *error = NULL;
-
- /* Getting introspection XML */
- self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex", OBEXMANAGER_DBUS_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 *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXMANAGER_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXMANAGER_DBUS_INTERFACE, OBEXMANAGER_DBUS_PATH);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
-
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex", OBEXMANAGER_DBUS_PATH, OBEXMANAGER_DBUS_INTERFACE);
-
- /* DBus signals connection */
-
- /* SessionCreated(object session) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "SessionCreated", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "SessionCreated", G_CALLBACK(session_created_handler), self, NULL);
-
- /* SessionRemoved(object session) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "SessionRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "SessionRemoved", G_CALLBACK(session_removed_handler), self, NULL);
-
- /* TransferCompleted(object transfer, boolean success) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "TransferCompleted", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_BOOLEAN, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "TransferCompleted", G_CALLBACK(transfer_completed_handler), self, NULL);
-
- /* TransferStarted(object transfer) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "TransferStarted", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "TransferStarted", G_CALLBACK(transfer_started_handler), self, NULL);
-}
-
-/* Methods */
-
-/* void RegisterAgent(object agent) */
-void obexmanager_register_agent(OBEXManager *self, const gchar *agent, GError **error)
-{
- g_assert(OBEXMANAGER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "RegisterAgent", error, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* void UnregisterAgent(object agent) */
-void obexmanager_unregister_agent(OBEXManager *self, const gchar *agent, GError **error)
-{
- g_assert(OBEXMANAGER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "UnregisterAgent", error, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* Signals handlers */
-static void session_created_handler(DBusGProxy *dbus_g_proxy, const gchar *session, gpointer data)
-{
- OBEXManager *self = OBEXMANAGER(data);
-
- g_signal_emit(self, signals[SESSION_CREATED], 0, session);
-}
-
-static void session_removed_handler(DBusGProxy *dbus_g_proxy, const gchar *session, gpointer data)
-{
- OBEXManager *self = OBEXMANAGER(data);
-
- g_signal_emit(self, signals[SESSION_REMOVED], 0, session);
-}
-
-static void transfer_completed_handler(DBusGProxy *dbus_g_proxy, const gchar *transfer, const gboolean success, gpointer data)
-{
- OBEXManager *self = OBEXMANAGER(data);
-
- g_signal_emit(self, signals[TRANSFER_COMPLETED], 0, transfer, success);
-}
-
-static void transfer_started_handler(DBusGProxy *dbus_g_proxy, const gchar *transfer, gpointer data)
-{
- OBEXManager *self = OBEXMANAGER(data);
-
- g_signal_emit(self, signals[TRANSFER_STARTED], 0, transfer);
-}
-
diff --git a/src/lib/obexd/obexmanager.h b/src/lib/obexd/obexmanager.h
deleted file mode 100644
index 203fe59..0000000
--- a/src/lib/obexd/obexmanager.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- *
- * 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 __OBEXMANAGER_H
-#define __OBEXMANAGER_H
-
-#include <glib-object.h>
-
-#define OBEXMANAGER_DBUS_PATH "/"
-#define OBEXMANAGER_DBUS_INTERFACE "org.openobex.Manager"
-
-/*
- * Type macros
- */
-#define OBEXMANAGER_TYPE (obexmanager_get_type())
-#define OBEXMANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXMANAGER_TYPE, OBEXManager))
-#define OBEXMANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXMANAGER_TYPE))
-#define OBEXMANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXMANAGER_TYPE, OBEXManagerClass))
-#define OBEXMANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXMANAGER_TYPE))
-#define OBEXMANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXMANAGER_TYPE, OBEXManagerClass))
-
-typedef struct _OBEXManager OBEXManager;
-typedef struct _OBEXManagerClass OBEXManagerClass;
-typedef struct _OBEXManagerPrivate OBEXManagerPrivate;
-
-struct _OBEXManager {
- GObject parent_instance;
-
- /*< private >*/
- OBEXManagerPrivate *priv;
-};
-
-struct _OBEXManagerClass {
- GObjectClass parent_class;
-};
-
-/* used by OBEXMANAGER_TYPE */
-GType obexmanager_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-void obexmanager_register_agent(OBEXManager *self, const gchar *agent, GError **error);
-void obexmanager_unregister_agent(OBEXManager *self, const gchar *agent, GError **error);
-
-#endif /* __OBEXMANAGER_H */
-
diff --git a/src/lib/obexd/obexsession.c b/src/lib/obexd/obexsession.c
deleted file mode 100644
index 48380cf..0000000
--- a/src/lib/obexd/obexsession.c
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "obexsession.h"
-
-#define OBEXSESSION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXSESSION_TYPE, OBEXSessionPrivate))
-
-struct _OBEXSessionPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-
- /* Properties */
- gchar *address;
-};
-
-G_DEFINE_TYPE(OBEXSession, obexsession, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */
- PROP_ADDRESS /* readonly */
-};
-
-static void _obexsession_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _obexsession_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-static void obexsession_dispose(GObject *gobject)
-{
- OBEXSession *self = OBEXSESSION(gobject);
-
- /* Properties free */
- g_free(self->priv->address);
-
- /* 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(obexsession_parent_class)->dispose(gobject);
-}
-
-static void obexsession_class_init(OBEXSessionClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = obexsession_dispose;
-
- g_type_class_add_private(klass, sizeof(OBEXSessionPrivate));
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _obexsession_get_property;
- gobject_class->set_property = _obexsession_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);
-
- /* string Address [readonly] */
- pspec = g_param_spec_string("Address", NULL, NULL, NULL, G_PARAM_READABLE);
- g_object_class_install_property(gobject_class, PROP_ADDRESS, pspec);
-}
-
-static void obexsession_init(OBEXSession *self)
-{
- self->priv = OBEXSESSION_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(session_conn != NULL);
-}
-
-static void obexsession_post_init(OBEXSession *self, const gchar *dbus_object_path)
-{
- 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(session_conn, "org.openobex", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXSESSION_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXSESSION_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex", dbus_object_path, OBEXSESSION_DBUS_INTERFACE);
-
- /* Properties init */
- GHashTable *properties = obexsession_get_properties(self, &error);
- if (error != NULL) {
- g_critical("%s", error->message);
- }
- g_assert(error == NULL);
- g_assert(properties != NULL);
-
- /* string Address [readonly] */
- if (g_hash_table_lookup(properties, "Address")) {
- self->priv->address = g_value_dup_string(g_hash_table_lookup(properties, "Address"));
- } else {
- self->priv->address = g_strdup("undefined");
- }
-
- g_hash_table_unref(properties);
-}
-
-static void _obexsession_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- OBEXSession *self = OBEXSESSION(object);
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- g_value_set_string(value, obexsession_get_dbus_object_path(self));
- break;
-
- case PROP_ADDRESS:
- g_value_set_string(value, obexsession_get_address(self));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _obexsession_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- OBEXSession *self = OBEXSESSION(object);
- GError *error = NULL;
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- obexsession_post_init(self, g_value_get_string(value));
- 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);
-}
-
-/* Methods */
-
-/* dict GetProperties() */
-GHashTable *obexsession_get_properties(OBEXSession *self, GError **error)
-{
- g_assert(OBEXSESSION_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;
-}
-
-/* Properties access methods */
-const gchar *obexsession_get_dbus_object_path(OBEXSession *self)
-{
- g_assert(OBEXSESSION_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
-}
-
-const gchar *obexsession_get_address(OBEXSession *self)
-{
- g_assert(OBEXSESSION_IS(self));
-
- return self->priv->address;
-}
-
diff --git a/src/lib/obexd/obexsession.h b/src/lib/obexd/obexsession.h
deleted file mode 100644
index d39e15f..0000000
--- a/src/lib/obexd/obexsession.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- *
- * 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 __OBEXSESSION_H
-#define __OBEXSESSION_H
-
-#include <glib-object.h>
-
-#define OBEXSESSION_DBUS_INTERFACE "org.openobex.Session"
-
-/*
- * Type macros
- */
-#define OBEXSESSION_TYPE (obexsession_get_type())
-#define OBEXSESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXSESSION_TYPE, OBEXSession))
-#define OBEXSESSION_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXSESSION_TYPE))
-#define OBEXSESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXSESSION_TYPE, OBEXSessionClass))
-#define OBEXSESSION_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXSESSION_TYPE))
-#define OBEXSESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXSESSION_TYPE, OBEXSessionClass))
-
-typedef struct _OBEXSession OBEXSession;
-typedef struct _OBEXSessionClass OBEXSessionClass;
-typedef struct _OBEXSessionPrivate OBEXSessionPrivate;
-
-struct _OBEXSession {
- GObject parent_instance;
-
- /*< private >*/
- OBEXSessionPrivate *priv;
-};
-
-struct _OBEXSessionClass {
- GObjectClass parent_class;
-};
-
-/* used by OBEXSESSION_TYPE */
-GType obexsession_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-GHashTable *obexsession_get_properties(OBEXSession *self, GError **error);
-
-const gchar *obexsession_get_dbus_object_path(OBEXSession *self);
-const gchar *obexsession_get_address(OBEXSession *self);
-
-#endif /* __OBEXSESSION_H */
-
diff --git a/src/lib/obexd/obextransfer.c b/src/lib/obexd/obextransfer.c
deleted file mode 100644
index 78dcf52..0000000
--- a/src/lib/obexd/obextransfer.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- *
- * 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 <string.h>
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "../dbus-common.h"
-#include "../marshallers.h"
-
-#include "obextransfer.h"
-
-#define OBEXTRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXTRANSFER_TYPE, OBEXTransferPrivate))
-
-struct _OBEXTransferPrivate {
- DBusGProxy *dbus_g_proxy;
-
- /* Introspection data */
- DBusGProxy *introspection_g_proxy;
- gchar *introspection_xml;
-};
-
-G_DEFINE_TYPE(OBEXTransfer, obextransfer, G_TYPE_OBJECT);
-
-enum {
- PROP_0,
-
- PROP_DBUS_OBJECT_PATH /* readwrite, construct only */
-};
-
-static void _obextransfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void _obextransfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-enum {
- PROGRESS,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void progress_handler(DBusGProxy *dbus_g_proxy, const gint32 total, const gint32 transfered, gpointer data);
-
-static void obextransfer_dispose(GObject *gobject)
-{
- OBEXTransfer *self = OBEXTRANSFER(gobject);
-
- /* DBus signals disconnection */
- dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "Progress", G_CALLBACK(progress_handler), self);
-
- /* 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(obextransfer_parent_class)->dispose(gobject);
-}
-
-static void obextransfer_class_init(OBEXTransferClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->dispose = obextransfer_dispose;
-
- g_type_class_add_private(klass, sizeof(OBEXTransferPrivate));
-
- /* Properties registration */
- GParamSpec *pspec;
-
- gobject_class->get_property = _obextransfer_get_property;
- gobject_class->set_property = _obextransfer_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);
-
- /* Signals registation */
- signals[PROGRESS] = g_signal_new("Progress",
- G_TYPE_FROM_CLASS(gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0, NULL, NULL,
- g_cclosure_bt_marshal_VOID__INT_INT,
- G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
-}
-
-static void obextransfer_init(OBEXTransfer *self)
-{
- self->priv = OBEXTRANSFER_GET_PRIVATE(self);
-
- /* DBusGProxy init */
- self->priv->dbus_g_proxy = NULL;
-
- g_assert(session_conn != NULL);
-}
-
-static void obextransfer_post_init(OBEXTransfer *self, const gchar *dbus_object_path)
-{
- 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(session_conn, "org.openobex", 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 *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXTRANSFER_DBUS_INTERFACE, "\">", NULL);
- if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
- g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXTRANSFER_DBUS_INTERFACE, dbus_object_path);
- g_assert(FALSE);
- }
- g_free(check_intf_regex_str);
- self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex", dbus_object_path, OBEXTRANSFER_DBUS_INTERFACE);
-
- /* DBus signals connection */
-
- /* Progress(int32 total, int32 transfered) */
- dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "Progress", G_TYPE_INT, G_TYPE_INT, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "Progress", G_CALLBACK(progress_handler), self, NULL);
-}
-
-static void _obextransfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- OBEXTransfer *self = OBEXTRANSFER(object);
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- g_value_set_string(value, obextransfer_get_dbus_object_path(self));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
-}
-
-static void _obextransfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- OBEXTransfer *self = OBEXTRANSFER(object);
- GError *error = NULL;
-
- switch (property_id) {
- case PROP_DBUS_OBJECT_PATH:
- obextransfer_post_init(self, g_value_get_string(value));
- 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);
-}
-
-/* Methods */
-
-/* void Cancel() */
-void obextransfer_cancel(OBEXTransfer *self, GError **error)
-{
- g_assert(OBEXTRANSFER_IS(self));
-
- dbus_g_proxy_call(self->priv->dbus_g_proxy, "Cancel", error, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/* Properties access methods */
-const gchar *obextransfer_get_dbus_object_path(OBEXTransfer *self)
-{
- g_assert(OBEXTRANSFER_IS(self));
-
- return dbus_g_proxy_get_path(self->priv->dbus_g_proxy);
-}
-
-/* Signals handlers */
-static void progress_handler(DBusGProxy *dbus_g_proxy, const gint32 total, const gint32 transfered, gpointer data)
-{
- OBEXTransfer *self = OBEXTRANSFER(data);
-
- g_signal_emit(self, signals[PROGRESS], 0, total, transfered);
-}
-
diff --git a/src/lib/obexd/obextransfer.h b/src/lib/obexd/obextransfer.h
deleted file mode 100644
index 99f3084..0000000
--- a/src/lib/obexd/obextransfer.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- *
- * 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 __OBEXTRANSFER_H
-#define __OBEXTRANSFER_H
-
-#include <glib-object.h>
-
-#define OBEXTRANSFER_DBUS_INTERFACE "org.openobex.Transfer"
-
-/*
- * Type macros
- */
-#define OBEXTRANSFER_TYPE (obextransfer_get_type())
-#define OBEXTRANSFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXTRANSFER_TYPE, OBEXTransfer))
-#define OBEXTRANSFER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXTRANSFER_TYPE))
-#define OBEXTRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXTRANSFER_TYPE, OBEXTransferClass))
-#define OBEXTRANSFER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXTRANSFER_TYPE))
-#define OBEXTRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXTRANSFER_TYPE, OBEXTransferClass))
-
-typedef struct _OBEXTransfer OBEXTransfer;
-typedef struct _OBEXTransferClass OBEXTransferClass;
-typedef struct _OBEXTransferPrivate OBEXTransferPrivate;
-
-struct _OBEXTransfer {
- GObject parent_instance;
-
- /*< private >*/
- OBEXTransferPrivate *priv;
-};
-
-struct _OBEXTransferClass {
- GObjectClass parent_class;
-};
-
-/* used by OBEXTRANSFER_TYPE */
-GType obextransfer_get_type(void) G_GNUC_CONST;
-
-/*
- * Method definitions
- */
-void obextransfer_cancel(OBEXTransfer *self, GError **error);
-
-const gchar *obextransfer_get_dbus_object_path(OBEXTransfer *self);
-
-#endif /* __OBEXTRANSFER_H */
-
diff --git a/src/lib/properties.c b/src/lib/properties.c
new file mode 100644
index 0000000..8b913d5
--- /dev/null
+++ b/src/lib/properties.c
@@ -0,0 +1,269 @@
+#include <gio/gio.h>
+#include "dbus-common.h"
+#include "properties.h"
+
+struct _PropertiesPrivate
+{
+ GDBusProxy *proxy;
+
+ // a{sa{sv}}
+ GVariant *dict_interfaces;
+
+ gchar *dbus_type;
+ gchar *dbus_service_name;
+ gchar *dbus_object_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (Properties, properties, G_TYPE_OBJECT)
+
+enum
+{
+ PROP_0,
+
+ PROP_DBUS_TYPE,
+ PROP_DBUS_SERVICE_NAME,
+ PROP_DBUS_OBJECT_PATH,
+
+ N_PROPERTIES
+};
+
+/* Keep a pointer to the properties definition */
+static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
+
+/*
+ * Private method definitions
+ */
+static void _properties_create_gdbus_proxy(Properties *self, GError **error);
+
+/*
+ * Methods
+ */
+static void _properties_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ Properties *self = PROPERTIES(object);
+ GError *error = NULL;
+
+ switch (property_id)
+ {
+// case PROP_EXAMPLE:
+// g_free(self->priv->example);
+// self->priv->example = g_value_dup_string(value);
+// g_print("example: %s\n", self->priv->example);
+// break;
+
+ case PROP_DBUS_TYPE:
+ if(self->priv->dbus_type)
+ g_free(self->priv->dbus_type);
+ self->priv->dbus_type = g_value_dup_string(value);
+ // _properties_set_dbus_object_path(self, g_value_dup_string(value), &error);
+ _properties_create_gdbus_proxy(self, &error);
+ break;
+
+ case PROP_DBUS_SERVICE_NAME:
+ if(self->priv->dbus_service_name)
+ g_free(self->priv->dbus_service_name);
+ self->priv->dbus_service_name = g_value_dup_string(value);
+ // _properties_set_dbus_object_path(self, g_value_dup_string(value), &error);
+ _properties_create_gdbus_proxy(self, &error);
+ break;
+
+ case PROP_DBUS_OBJECT_PATH:
+ if(self->priv->dbus_object_path)
+ g_free(self->priv->dbus_object_path);
+ self->priv->dbus_object_path = g_value_dup_string(value);
+ // _properties_set_dbus_object_path(self, g_value_dup_string(value), &error);
+ _properties_create_gdbus_proxy(self, &error);
+ break;
+
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+
+ g_assert(error == NULL);
+}
+
+static void _properties_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ Properties *self = PROPERTIES(object);
+
+ switch (property_id)
+ {
+// case PROP_EXAMPLE:
+// g_value_set_string(value, self->priv->example);
+// break;
+
+ case PROP_DBUS_TYPE:
+ g_value_set_string(value, properties_get_dbus_type(self));
+ break;
+
+ case PROP_DBUS_SERVICE_NAME:
+ g_value_set_string(value, properties_get_dbus_service_name(self));
+ break;
+
+ case PROP_DBUS_OBJECT_PATH:
+ g_value_set_string(value, properties_get_dbus_object_path(self));
+ break;
+
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void properties_dispose (GObject *gobject)
+{
+ Properties *self = PROPERTIES (gobject);
+
+ /* In dispose(), you are supposed to free all types referenced from this
+ * object which might themselves hold a reference to self. Generally,
+ * the most simple solution is to unref all members on which you own a
+ * reference.
+ */
+
+ /* dispose() might be called multiple times, so we must guard against
+ * calling g_object_unref() on an invalid GObject by setting the member
+ * NULL; g_clear_object() does this for us, atomically.
+ */
+ // g_clear_object (&self->priv->an_object);
+ g_clear_object (&self->priv->proxy);
+ if(self->priv->dict_interfaces != NULL)
+ g_variant_unref(self->priv->dict_interfaces);
+
+
+ /* Always chain up to the parent class; there is no need to check if
+ * the parent class implements the dispose() virtual function: it is
+ * always guaranteed to do so
+ */
+ G_OBJECT_CLASS (properties_parent_class)->dispose (gobject);
+}
+
+static void properties_finalize (GObject *gobject)
+{
+ Properties *self = PROPERTIES(gobject);
+
+ // g_free(self->priv->a_string);
+
+ /* Always chain up to the parent class; as with dispose(), finalize()
+ * is guaranteed to exist on the parent's class virtual function table
+ */
+ G_OBJECT_CLASS (properties_parent_class)->finalize (gobject);
+}
+
+static void properties_class_init (PropertiesClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->get_property = _properties_get_property;
+ gobject_class->set_property = _properties_set_property;
+
+ /* object DBusType [readwrite, construct only] */
+ obj_properties[PROP_DBUS_TYPE] =
+ g_param_spec_string ("DBusType",
+ "dbus_type",
+ "Properties D-Bus connection type",
+ NULL /* default value */,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE);
+
+ /* object DBusServiceName [readwrite, construct only] */
+ obj_properties[PROP_DBUS_SERVICE_NAME] =
+ g_param_spec_string ("DBusServiceName",
+ "dbus_service_name",
+ "Properties D-Bus service name",
+ NULL /* default value */,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE);
+
+ /* object DBusObjectPath [readwrite, construct only] */
+ obj_properties[PROP_DBUS_OBJECT_PATH] =
+ g_param_spec_string ("DBusObjectPath",
+ "dbus_object_path",
+ "Properties D-Bus object path",
+ NULL /* default value */,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (gobject_class,
+ N_PROPERTIES,
+ obj_properties);
+}
+
+static void properties_init (Properties *self)
+{
+ self->priv = properties_get_instance_private (self);
+ self->priv->proxy = NULL;
+ self->priv->dict_interfaces = NULL;
+ self->priv->dbus_type = NULL;
+ self->priv->dbus_service_name = NULL;
+ self->priv->dbus_object_path = NULL;
+}
+
+static void _properties_create_gdbus_proxy(Properties *self, GError **error)
+{
+ if(self->priv->dbus_type && self->priv->dbus_service_name && self->priv->dbus_object_path)
+ {
+ if(g_ascii_strcasecmp(g_ascii_strdown(self->priv->dbus_type, -1), "system") == 0)
+ {
+ g_assert(system_conn != NULL);
+ self->priv->proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, self->priv->dbus_service_name, self->priv->dbus_object_path, PROPERTIES_DBUS_INTERFACE, NULL, error);
+ }
+ else if(g_ascii_strcasecmp(g_ascii_strdown(self->priv->dbus_type, -1), "session") == 0)
+ {
+ g_assert(session_conn != NULL);
+ self->priv->proxy = g_dbus_proxy_new_sync(session_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, self->priv->dbus_service_name, self->priv->dbus_object_path, PROPERTIES_DBUS_INTERFACE, NULL, error);
+ }
+ else
+ g_error("Invalid DBus connection type: %s", self->priv->dbus_type);
+ }
+}
+
+const gchar *properties_get_dbus_type(Properties *self)
+{
+ g_assert(PROPERTIES_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return self->priv->dbus_type;
+}
+
+const gchar *properties_get_dbus_service_name(Properties *self)
+{
+ g_assert(PROPERTIES_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_name(self->priv->proxy);
+}
+
+const gchar *properties_get_dbus_object_path(Properties *self)
+{
+ g_assert(PROPERTIES_IS(self));
+ g_assert(self->priv->proxy != NULL);
+ return g_dbus_proxy_get_object_path(self->priv->proxy);
+}
+
+GVariant *properties_get(Properties *self, const gchar *interface_name, const gchar *property_name, GError **error)
+{
+ g_assert(PROPERTIES_IS(self));
+ GVariant *retVal = g_dbus_proxy_call_sync(self->priv->proxy, "Get", g_variant_new("(ss)", interface_name, property_name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (retVal == NULL)
+ return NULL;
+ retVal = g_variant_get_child_value(retVal, 0);
+ retVal = g_variant_get_variant(retVal);
+ return retVal;
+}
+
+void properties_set(Properties *self, const gchar *interface_name, const gchar *property_name, const GVariant *value, GError **error)
+{
+ g_assert(PROPERTIES_IS(self));
+ g_dbus_proxy_call_sync(self->priv->proxy, "Set", g_variant_new("(ssv)", interface_name, property_name, value), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+}
+
+GVariant *properties_get_all(Properties *self, const gchar *interface_name, GError **error)
+{
+ g_assert(PROPERTIES_IS(self));
+ GVariant *retVal = g_dbus_proxy_call_sync(self->priv->proxy, "GetAll", g_variant_new("(s)", interface_name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+ if (retVal == NULL)
+ return NULL;
+ retVal = g_variant_get_child_value(retVal, 0);
+ return retVal;
+} \ No newline at end of file
diff --git a/src/lib/properties.h b/src/lib/properties.h
new file mode 100644
index 0000000..389f042
--- /dev/null
+++ b/src/lib/properties.h
@@ -0,0 +1,61 @@
+#ifndef PROPERTIES_H
+#define PROPERTIES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib-object.h>
+/*
+ * Potentially, include other headers on which this header depends.
+ */
+
+/*
+ * Type macros.
+ */
+#define PROPERTIES_TYPE (properties_get_type ())
+#define PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PROPERTIES_TYPE, Properties))
+#define PROPERTIES_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PROPERTIES_TYPE))
+#define PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PROPERTIES_TYPE, PropertiesClass))
+#define PROPERTIES_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PROPERTIES_TYPE))
+#define PROPERTIES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PROPERTIES_TYPE, PropertiesClass))
+
+#define PROPERTIES_DBUS_INTERFACE "org.freedesktop.DBus.Properties"
+
+typedef struct _Properties Properties;
+typedef struct _PropertiesPrivate PropertiesPrivate;
+typedef struct _PropertiesClass PropertiesClass;
+
+struct _Properties {
+ /* Parent instance structure */
+ GObject parent_instance;
+
+ /* instance members */
+ PropertiesPrivate *priv;
+};
+
+struct _PropertiesClass {
+ /* Parent class structure */
+ GObjectClass parent_class;
+
+ /* class members */
+};
+
+/* used by PROPERTIES_TYPE */
+GType properties_get_type(void);
+
+/*
+ * Method definitions.
+ */
+const gchar *properties_get_dbus_type(Properties *self);
+const gchar *properties_get_dbus_service_name(Properties *self);
+const gchar *properties_get_dbus_object_path(Properties *self);
+GVariant *properties_get(Properties *self, const gchar *interface_name, const gchar *property_name, GError **error);
+void properties_set(Properties *self, const gchar *interface_name, const gchar *property_name, const GVariant *value, GError **error);
+GVariant *properties_get_all(Properties *self, const gchar *interface_name, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PROPERTIES_H */ \ No newline at end of file