diff options
author | Alexander Orlenko <zxteam@gmail.com> | 2010-08-07 00:45:45 +1100 |
---|---|---|
committer | Alexander Orlenko <zxteam@gmail.com> | 2010-08-07 00:45:45 +1100 |
commit | da8f4e34ae3c1bbff5d46a8a44cf42c6f12c3221 (patch) | |
tree | c6fe1f2cc6f104dfb307b3d7203d43d64a3c800a /src | |
parent | 75eae0453ceffc4507fc6a5aca7aebebfcd8c521 (diff) | |
download | bluez-tools-da8f4e34ae3c1bbff5d46a8a44cf42c6f12c3221.tar.gz |
A lot of refactoring
Returning to obexd api
ODS (obex-data-server support) freezed
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 76 | ||||
-rw-r--r-- | src/lib/bluez-api.h (renamed from src/lib/bluez-dbus.h) | 40 | ||||
-rw-r--r-- | src/lib/bluez/adapter.c (renamed from src/lib/adapter.c) | 19 | ||||
-rw-r--r-- | src/lib/bluez/adapter.h (renamed from src/lib/adapter.h) | 2 | ||||
-rw-r--r-- | src/lib/bluez/agent.c (renamed from src/lib/agent.c) | 9 | ||||
-rw-r--r-- | src/lib/bluez/agent.h (renamed from src/lib/agent.h) | 20 | ||||
-rw-r--r-- | src/lib/bluez/audio.c (renamed from src/lib/audio.c) | 17 | ||||
-rw-r--r-- | src/lib/bluez/audio.h (renamed from src/lib/audio.h) | 2 | ||||
-rw-r--r-- | src/lib/bluez/device.c (renamed from src/lib/device.c) | 17 | ||||
-rw-r--r-- | src/lib/bluez/device.h (renamed from src/lib/device.h) | 2 | ||||
-rw-r--r-- | src/lib/bluez/input.c (renamed from src/lib/input.c) | 17 | ||||
-rw-r--r-- | src/lib/bluez/input.h (renamed from src/lib/input.h) | 2 | ||||
-rw-r--r-- | src/lib/bluez/manager.c (renamed from src/lib/manager.c) | 17 | ||||
-rw-r--r-- | src/lib/bluez/manager.h (renamed from src/lib/manager.h) | 4 | ||||
-rw-r--r-- | src/lib/bluez/network.c (renamed from src/lib/network.c) | 17 | ||||
-rw-r--r-- | src/lib/bluez/network.h (renamed from src/lib/network.h) | 2 | ||||
-rw-r--r-- | src/lib/bluez/network_server.c | 184 | ||||
-rw-r--r-- | src/lib/bluez/network_server.h | 68 | ||||
-rw-r--r-- | src/lib/bluez/serial.c (renamed from src/lib/serial.c) | 15 | ||||
-rw-r--r-- | src/lib/bluez/serial.h (renamed from src/lib/serial.h) | 2 | ||||
-rw-r--r-- | src/lib/dbus-common.c | 59 | ||||
-rw-r--r-- | src/lib/dbus-common.h | 13 | ||||
-rw-r--r-- | src/lib/helpers.c | 3 | ||||
-rw-r--r-- | src/lib/helpers.h | 19 | ||||
-rw-r--r-- | src/lib/marshallers.c | 631 | ||||
-rw-r--r-- | src/lib/marshallers.h | 180 | ||||
-rw-r--r-- | src/lib/marshallers.list | 34 | ||||
-rw-r--r-- | src/lib/network_hub.c | 318 | ||||
-rw-r--r-- | src/lib/network_hub.h | 73 | ||||
-rw-r--r-- | src/lib/network_peer.c | 318 | ||||
-rw-r--r-- | src/lib/network_peer.h | 73 | ||||
-rw-r--r-- | src/lib/network_router.c | 318 | ||||
-rw-r--r-- | src/lib/network_router.h | 73 | ||||
-rw-r--r-- | src/lib/obexd-api.h | 44 | ||||
-rw-r--r-- | src/lib/obexd/obexagent.c | 175 | ||||
-rw-r--r-- | src/lib/obexd/obexagent.h | 98 | ||||
-rw-r--r-- | src/lib/obexd/obexclient.c | 153 | ||||
-rw-r--r-- | src/lib/obexd/obexclient.h | 71 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_file_transfer.c | 235 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_file_transfer.h | 74 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_session.c | 283 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_session.h | 72 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_transfer.c | 275 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_transfer.h | 71 | ||||
-rw-r--r-- | src/lib/obexd/obexmanager.c | 213 | ||||
-rw-r--r-- | src/lib/obexd/obexmanager.h | 67 | ||||
-rw-r--r-- | src/lib/obexd/obexsession.c | 218 | ||||
-rw-r--r-- | src/lib/obexd/obexsession.h | 68 | ||||
-rw-r--r-- | src/lib/obexd/obextransfer.c | 211 | ||||
-rw-r--r-- | src/lib/obexd/obextransfer.h | 67 | ||||
-rw-r--r-- | src/lib/ods-api.h | 40 | ||||
-rw-r--r-- | src/lib/ods/obexmanager.c (renamed from src/lib/obexmanager.c) | 17 | ||||
-rw-r--r-- | src/lib/ods/obexmanager.h (renamed from src/lib/obexmanager.h) | 4 | ||||
-rw-r--r-- | src/lib/ods/obexserver.c (renamed from src/lib/obexserver.c) | 17 | ||||
-rw-r--r-- | src/lib/ods/obexserver.h (renamed from src/lib/obexserver.h) | 2 | ||||
-rw-r--r-- | src/lib/ods/obexserver_session.c (renamed from src/lib/obexserver_session.c) | 21 | ||||
-rw-r--r-- | src/lib/ods/obexserver_session.h (renamed from src/lib/obexserver_session.h) | 2 | ||||
-rw-r--r-- | src/lib/ods/obexsession.c (renamed from src/lib/obexsession.c) | 21 | ||||
-rw-r--r-- | src/lib/ods/obexsession.h (renamed from src/lib/obexsession.h) | 2 |
59 files changed, 3484 insertions, 1681 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 81878a2..5ba6fed 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,9 +1,9 @@ -AM_CPPFLAGS = $(DBUS_CFLAGS) $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) $(GIO_CFLAGS) $(DBUS_GLIB_CFLAGS) -AM_LDFLAGS = $(DBUS_LIBS) $(GLIB_LIBS) $(GOBJECT_LIBS) $(GIO_LIBS) $(DBUS_GLIB_LIBS) +AM_CPPFLAGS = $(DBUS_CFLAGS) $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS) +AM_LDFLAGS = $(DBUS_LIBS) $(GLIB_LIBS) $(DBUS_GLIB_LIBS) +# Marshallers generation BUILT_SOURCES = lib/marshallers.c lib/marshallers.h - -GENMARSHAL_FLAGS = --prefix="g_cclosure_bluez_marshal" --g-fatal-warnings +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 @@ -11,38 +11,46 @@ lib/marshallers.h: lib/marshallers.list 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 \ + 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/network.c lib/bluez/network.h \ + lib/bluez/network_server.c lib/bluez/network_server.h \ + lib/bluez/serial.c lib/bluez/serial.h + +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 + +ods_sources = lib/ods/obexmanager.c lib/ods/obexmanager.h \ + lib/ods/obexserver.c lib/ods/obexserver.h \ + lib/ods/obexserver_session.c lib/ods/obexserver_session.h \ + lib/ods/obexsession.c lib/ods/obexsession.h + lib_sources = lib/marshallers.c lib/marshallers.h \ lib/dbus-common.c lib/dbus-common.h \ lib/helpers.c lib/helpers.h \ - lib/bluez-dbus.h \ - lib/adapter.c lib/adapter.h \ - lib/agent.c lib/agent.h \ - lib/audio.c lib/audio.h \ - lib/device.c lib/device.h \ - lib/input.c lib/input.h \ - lib/manager.c lib/manager.h \ - lib/network.c lib/network.h \ - lib/network_hub.c lib/network_hub.h \ - lib/network_peer.c lib/network_peer.h \ - lib/network_router.c lib/network_router.h \ - lib/serial.c lib/serial.h \ - lib/sdp.c lib/sdp.h - -obex_sources = lib/obexmanager.c lib/obexmanager.h \ - lib/obexsession.c lib/obexsession.h \ - lib/obexserver.c lib/obexserver.h \ - lib/obexserver_session.c lib/obexserver_session.h + lib/sdp.c lib/sdp.h \ + lib/bluez-api.h lib/obexd-api.h lib/ods-api.h bin_PROGRAMS = bt-monitor bt-adapter bt-agent bt-device bt-input bt-audio bt-network bt-serial bt-obex -bt_monitor_SOURCES = $(lib_sources) bt-monitor.c -bt_adapter_SOURCES = ${lib_sources} bt-adapter.c -bt_agent_SOURCES = $(lib_sources) bt-agent.c -bt_device_SOURCES = $(lib_sources) bt-device.c -bt_input_SOURCES = $(lib_sources) bt-input.c -bt_audio_SOURCES = $(lib_sources) bt-audio.c -bt_network_SOURCES = $(lib_sources) bt-network.c -bt_serial_SOURCES = $(lib_sources) bt-serial.c -bt_obex_SOURCES = $(lib_sources) $(obex_sources) bt-obex.c - -CLEANFILES = Makefile.in lib/marshallers.c lib/marshallers.h - +bt_monitor_SOURCES = $(lib_sources) $(bluez_sources) bt-monitor.c +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_input_SOURCES = $(lib_sources) $(bluez_sources) bt-input.c +bt_audio_SOURCES = $(lib_sources) $(bluez_sources) bt-audio.c +bt_network_SOURCES = $(lib_sources) $(bluez_sources) bt-network.c +bt_serial_SOURCES = $(lib_sources) $(bluez_sources) bt-serial.c +bt_obex_SOURCES = $(lib_sources) $(bluez_sources) $(ods_sources) bt-obex.c + +CLEANFILES = Makefile.in \ + lib/marshallers.c lib/marshallers.h diff --git a/src/lib/bluez-dbus.h b/src/lib/bluez-api.h index 47f46e2..56ecae6 100644 --- a/src/lib/bluez-dbus.h +++ b/src/lib/bluez-api.h @@ -21,37 +21,25 @@ * */ -#ifndef __BLUEZ_DBUS_H -#define __BLUEZ_DBUS_H +#ifndef __BLUEZ_API_H +#define __BLUEZ_API_H /* Global includes */ #include <glib.h> #include <dbus/dbus-glib.h> -/* Local includes */ -#include "dbus-common.h" -#include "helpers.h" -#include "marshallers.h" -#include "sdp.h" +#define BLUEZ_DBUS_NAME "org.bluez" -/* Bluez DBus Interfaces */ -#include "adapter.h" -#include "agent.h" -#include "audio.h" -#include "device.h" -#include "input.h" -#include "manager.h" -#include "network.h" -#include "network_hub.h" -#include "network_peer.h" -#include "network_router.h" -#include "serial.h" +/* BlueZ DBus API */ +#include "bluez/adapter.h" +#include "bluez/agent.h" +#include "bluez/audio.h" +#include "bluez/device.h" +#include "bluez/input.h" +#include "bluez/manager.h" +#include "bluez/network.h" +#include "bluez/network_server.h" +#include "bluez/serial.h" -/* OBEX DBus Interfaces */ -#include "obexmanager.h" -#include "obexsession.h" -#include "obexserver.h" -#include "obexserver_session.h" - -#endif /* __BLUEZ_DBUS_H */ +#endif /* __BLUEZ_API_H */ diff --git a/src/lib/adapter.c b/src/lib/bluez/adapter.c index 2f7042f..d0140aa 100644 --- a/src/lib/adapter.c +++ b/src/lib/bluez/adapter.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.h" +#include "../dbus-common.h" +#include "../marshallers.h" + #include "adapter.h" #define ADAPTER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), ADAPTER_TYPE, AdapterPrivate)) @@ -207,7 +208,7 @@ static void adapter_class_init(AdapterClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_BOXED, + 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", @@ -221,7 +222,7 @@ static void adapter_class_init(AdapterClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_BOXED, + g_cclosure_bt_marshal_VOID__STRING_BOXED, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE); } @@ -232,7 +233,7 @@ static void adapter_init(Adapter *self) /* Async calls init */ self->priv->create_paired_device_call = NULL; - g_assert(conn != NULL); + g_assert(system_conn != NULL); } static void adapter_post_init(Adapter *self, const gchar *dbus_object_path) @@ -244,20 +245,20 @@ static void adapter_post_init(Adapter *self, const gchar *dbus_object_path) GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", dbus_object_path, "org.freedesktop.DBus.Introspectable"); + 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=\"", BLUEZ_DBUS_ADAPTER_INTERFACE, "\">", 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\"", BLUEZ_DBUS_ADAPTER_INTERFACE, dbus_object_path); + 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(conn, "org.bluez", dbus_object_path, BLUEZ_DBUS_ADAPTER_INTERFACE); + self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, ADAPTER_DBUS_INTERFACE); /* DBus signals connection */ diff --git a/src/lib/adapter.h b/src/lib/bluez/adapter.h index 2d4a82c..d94675b 100644 --- a/src/lib/adapter.h +++ b/src/lib/bluez/adapter.h @@ -26,7 +26,7 @@ #include <glib-object.h> -#define BLUEZ_DBUS_ADAPTER_INTERFACE "org.bluez.Adapter" +#define ADAPTER_DBUS_INTERFACE "org.bluez.Adapter" /* * Type macros diff --git a/src/lib/agent.c b/src/lib/bluez/agent.c index b18f316..e150521 100644 --- a/src/lib/agent.c +++ b/src/lib/bluez/agent.c @@ -30,8 +30,9 @@ #include <string.h> #include <glib.h> -#include "dbus-common.h" -#include "helpers.h" +#include "../dbus-common.h" +#include "../helpers.h" + #include "device.h" #include "agent.h" @@ -56,7 +57,7 @@ static void agent_dispose(GObject *gobject) { Agent *self = AGENT(gobject); - dbus_g_connection_unregister_g_object(conn, gobject); + dbus_g_connection_unregister_g_object(system_conn, gobject); /* Proxy free */ //g_object_unref(self->priv->proxy); @@ -88,7 +89,7 @@ static void agent_init(Agent *self) g_assert(conn != NULL); - dbus_g_connection_register_g_object(conn, DBUS_AGENT_PATH, G_OBJECT(self)); + dbus_g_connection_register_g_object(system_conn, AGENT_DBUS_PATH, G_OBJECT(self)); g_print("Agent registered\n"); } diff --git a/src/lib/agent.h b/src/lib/bluez/agent.h index 7fbad37..10f4944 100644 --- a/src/lib/agent.h +++ b/src/lib/bluez/agent.h @@ -27,9 +27,9 @@ #include <glib-object.h> #include <dbus/dbus-glib.h> -#include "marshallers.h" +#include "../marshallers.h" -#define DBUS_AGENT_PATH "/Agent" +#define AGENT_DBUS_PATH "/Agent" /* * Type macros @@ -73,14 +73,14 @@ gboolean agent_cancel(Agent *self, GError **error); /* Glue code */ static const DBusGMethodInfo dbus_glib_agent_methods[] = { - { (GCallback) agent_release, g_cclosure_bluez_marshal_BOOLEAN__POINTER, 0}, - { (GCallback) agent_request_pin_code, g_cclosure_bluez_marshal_BOOLEAN__BOXED_POINTER_POINTER, 27}, - { (GCallback) agent_request_passkey, g_cclosure_bluez_marshal_BOOLEAN__BOXED_POINTER_POINTER, 85}, - { (GCallback) agent_display_passkey, g_cclosure_bluez_marshal_BOOLEAN__BOXED_UINT_UCHAR_POINTER, 143}, - { (GCallback) agent_request_confirmation, g_cclosure_bluez_marshal_BOOLEAN__BOXED_UINT_POINTER, 212}, - { (GCallback) agent_authorize, g_cclosure_bluez_marshal_BOOLEAN__BOXED_STRING_POINTER, 274}, - { (GCallback) agent_confirm_mode_change, g_cclosure_bluez_marshal_BOOLEAN__STRING_POINTER, 323}, - { (GCallback) agent_cancel, g_cclosure_bluez_marshal_BOOLEAN__POINTER, 369}, + { (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 = { diff --git a/src/lib/audio.c b/src/lib/bluez/audio.c index 602904a..d4abcbf 100644 --- a/src/lib/audio.c +++ b/src/lib/bluez/audio.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.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)) @@ -115,7 +116,7 @@ static void audio_class_init(AudioClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_BOXED, + g_cclosure_bt_marshal_VOID__STRING_BOXED, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE); } @@ -123,7 +124,7 @@ static void audio_init(Audio *self) { self->priv = AUDIO_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); } static void audio_post_init(Audio *self, const gchar *dbus_object_path) @@ -135,20 +136,20 @@ static void audio_post_init(Audio *self, const gchar *dbus_object_path) GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", dbus_object_path, "org.freedesktop.DBus.Introspectable"); + 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=\"", BLUEZ_DBUS_AUDIO_INTERFACE, "\">", 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\"", BLUEZ_DBUS_AUDIO_INTERFACE, dbus_object_path); + 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(conn, "org.bluez", dbus_object_path, BLUEZ_DBUS_AUDIO_INTERFACE); + self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, AUDIO_DBUS_INTERFACE); /* DBus signals connection */ diff --git a/src/lib/audio.h b/src/lib/bluez/audio.h index f5e4da0..6d801f2 100644 --- a/src/lib/audio.h +++ b/src/lib/bluez/audio.h @@ -26,7 +26,7 @@ #include <glib-object.h> -#define BLUEZ_DBUS_AUDIO_INTERFACE "org.bluez.Audio" +#define AUDIO_DBUS_INTERFACE "org.bluez.Audio" /* * Type macros diff --git a/src/lib/device.c b/src/lib/bluez/device.c index fdc9920..12c9017 100644 --- a/src/lib/device.c +++ b/src/lib/bluez/device.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.h" +#include "../dbus-common.h" +#include "../marshallers.h" + #include "device.h" #define DEVICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), DEVICE_TYPE, DevicePrivate)) @@ -223,7 +224,7 @@ static void device_class_init(DeviceClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_BOXED, + g_cclosure_bt_marshal_VOID__STRING_BOXED, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE); } @@ -231,7 +232,7 @@ static void device_init(Device *self) { self->priv = DEVICE_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); } static void device_post_init(Device *self, const gchar *dbus_object_path) @@ -243,20 +244,20 @@ static void device_post_init(Device *self, const gchar *dbus_object_path) GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", dbus_object_path, "org.freedesktop.DBus.Introspectable"); + 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=\"", BLUEZ_DBUS_DEVICE_INTERFACE, "\">", 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\"", BLUEZ_DBUS_DEVICE_INTERFACE, dbus_object_path); + 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(conn, "org.bluez", dbus_object_path, BLUEZ_DBUS_DEVICE_INTERFACE); + self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, DEVICE_DBUS_INTERFACE); /* DBus signals connection */ diff --git a/src/lib/device.h b/src/lib/bluez/device.h index f689bdd..b13e750 100644 --- a/src/lib/device.h +++ b/src/lib/bluez/device.h @@ -26,7 +26,7 @@ #include <glib-object.h> -#define BLUEZ_DBUS_DEVICE_INTERFACE "org.bluez.Device" +#define DEVICE_DBUS_INTERFACE "org.bluez.Device" /* * Type macros diff --git a/src/lib/input.c b/src/lib/bluez/input.c index 3ec39bf..cff4b71 100644 --- a/src/lib/input.c +++ b/src/lib/bluez/input.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.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)) @@ -115,7 +116,7 @@ static void input_class_init(InputClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_BOXED, + g_cclosure_bt_marshal_VOID__STRING_BOXED, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE); } @@ -123,7 +124,7 @@ static void input_init(Input *self) { self->priv = INPUT_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); } static void input_post_init(Input *self, const gchar *dbus_object_path) @@ -135,20 +136,20 @@ static void input_post_init(Input *self, const gchar *dbus_object_path) GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", dbus_object_path, "org.freedesktop.DBus.Introspectable"); + 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=\"", BLUEZ_DBUS_INPUT_INTERFACE, "\">", 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\"", BLUEZ_DBUS_INPUT_INTERFACE, dbus_object_path); + 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(conn, "org.bluez", dbus_object_path, BLUEZ_DBUS_INPUT_INTERFACE); + self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, INPUT_DBUS_INTERFACE); /* DBus signals connection */ diff --git a/src/lib/input.h b/src/lib/bluez/input.h index 0dd7b17..7bf2b86 100644 --- a/src/lib/input.h +++ b/src/lib/bluez/input.h @@ -26,7 +26,7 @@ #include <glib-object.h> -#define BLUEZ_DBUS_INPUT_INTERFACE "org.bluez.Input" +#define INPUT_DBUS_INTERFACE "org.bluez.Input" /* * Type macros diff --git a/src/lib/manager.c b/src/lib/bluez/manager.c index 523d133..df50ca3 100644 --- a/src/lib/manager.c +++ b/src/lib/bluez/manager.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.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)) @@ -140,7 +141,7 @@ static void manager_class_init(ManagerClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_BOXED, + g_cclosure_bt_marshal_VOID__STRING_BOXED, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE); } @@ -148,26 +149,26 @@ static void manager_init(Manager *self) { self->priv = MANAGER_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", BLUEZ_DBUS_MANAGER_PATH, "org.freedesktop.DBus.Introspectable"); + 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=\"", BLUEZ_DBUS_MANAGER_INTERFACE, "\">", 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\"", BLUEZ_DBUS_MANAGER_INTERFACE, BLUEZ_DBUS_MANAGER_PATH); + 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(conn, "org.bluez", BLUEZ_DBUS_MANAGER_PATH, BLUEZ_DBUS_MANAGER_INTERFACE); + self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE); /* DBus signals connection */ diff --git a/src/lib/manager.h b/src/lib/bluez/manager.h index 770fd5e..66ab2b6 100644 --- a/src/lib/manager.h +++ b/src/lib/bluez/manager.h @@ -26,8 +26,8 @@ #include <glib-object.h> -#define BLUEZ_DBUS_MANAGER_PATH "/" -#define BLUEZ_DBUS_MANAGER_INTERFACE "org.bluez.Manager" +#define MANAGER_DBUS_PATH "/" +#define MANAGER_DBUS_INTERFACE "org.bluez.Manager" /* * Type macros diff --git a/src/lib/network.c b/src/lib/bluez/network.c index ce8dd0e..b6e27e6 100644 --- a/src/lib/network.c +++ b/src/lib/bluez/network.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.h" +#include "../dbus-common.h" +#include "../marshallers.h" + #include "network.h" #define NETWORK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), NETWORK_TYPE, NetworkPrivate)) @@ -128,7 +129,7 @@ static void network_class_init(NetworkClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_BOXED, + g_cclosure_bt_marshal_VOID__STRING_BOXED, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE); } @@ -136,7 +137,7 @@ static void network_init(Network *self) { self->priv = NETWORK_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); } static void network_post_init(Network *self, const gchar *dbus_object_path) @@ -148,20 +149,20 @@ static void network_post_init(Network *self, const gchar *dbus_object_path) GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", dbus_object_path, "org.freedesktop.DBus.Introspectable"); + 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=\"", BLUEZ_DBUS_NETWORK_INTERFACE, "\">", 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\"", BLUEZ_DBUS_NETWORK_INTERFACE, dbus_object_path); + 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(conn, "org.bluez", dbus_object_path, BLUEZ_DBUS_NETWORK_INTERFACE); + self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, NETWORK_DBUS_INTERFACE); /* DBus signals connection */ diff --git a/src/lib/network.h b/src/lib/bluez/network.h index b0af8f2..ddeee5b 100644 --- a/src/lib/network.h +++ b/src/lib/bluez/network.h @@ -26,7 +26,7 @@ #include <glib-object.h> -#define BLUEZ_DBUS_NETWORK_INTERFACE "org.bluez.Network" +#define NETWORK_DBUS_INTERFACE "org.bluez.Network" /* * Type macros diff --git a/src/lib/bluez/network_server.c b/src/lib/bluez/network_server.c new file mode 100644 index 0000000..cccecd3 --- /dev/null +++ b/src/lib/bluez/network_server.c @@ -0,0 +1,184 @@ +/* + * + * 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 <string.h> + +#include "../dbus-common.h" +#include "../marshallers.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; +}; + +G_DEFINE_TYPE(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_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); + + /* Chain up to the parent class */ + G_OBJECT_CLASS(network_server_parent_class)->dispose(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; + + 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); + g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); +} + +static void network_server_init(NetworkServer *self) +{ + self->priv = NETWORK_SERVER_GET_PRIVATE(self); + + 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); + + switch (property_id) { + case PROP_DBUS_OBJECT_PATH: + g_value_set_string(value, network_server_get_dbus_object_path(self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); + break; + } +} + +static void _network_server_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + NetworkServer *self = NETWORK_SERVER(object); + GError *error = NULL; + + switch (property_id) { + case PROP_DBUS_OBJECT_PATH: + network_server_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 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)); + + 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); +} + +/* void Unregister(string uuid) */ +void network_server_unregister(NetworkServer *self, const gchar *uuid, GError **error) +{ + 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); +} + +/* Properties access methods */ +const gchar *network_server_get_dbus_object_path(NetworkServer *self) +{ + g_assert(NETWORK_SERVER_IS(self)); + + return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); +} + diff --git a/src/lib/bluez/network_server.h b/src/lib/bluez/network_server.h new file mode 100644 index 0000000..be2260f --- /dev/null +++ b/src/lib/bluez/network_server.h @@ -0,0 +1,68 @@ +/* + * + * 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 __NETWORK_SERVER_H +#define __NETWORK_SERVER_H + +#include <glib-object.h> + +#define NETWORK_SERVER_DBUS_INTERFACE "org.bluez.NetworkServer" + +/* + * Type macros + */ +#define NETWORK_SERVER_TYPE (network_server_get_type()) +#define NETWORK_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NETWORK_SERVER_TYPE, NetworkServer)) +#define NETWORK_SERVER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NETWORK_SERVER_TYPE)) +#define NETWORK_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), NETWORK_SERVER_TYPE, NetworkServerClass)) +#define NETWORK_SERVER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NETWORK_SERVER_TYPE)) +#define NETWORK_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), NETWORK_SERVER_TYPE, NetworkServerClass)) + +typedef struct _NetworkServer NetworkServer; +typedef struct _NetworkServerClass NetworkServerClass; +typedef struct _NetworkServerPrivate NetworkServerPrivate; + +struct _NetworkServer { + GObject parent_instance; + + /*< private >*/ + NetworkServerPrivate *priv; +}; + +struct _NetworkServerClass { + GObjectClass parent_class; +}; + +/* used by NETWORK_SERVER_TYPE */ +GType network_server_get_type(void) G_GNUC_CONST; + +/* + * Method definitions + */ +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); + +#endif /* __NETWORK_SERVER_H */ + diff --git a/src/lib/serial.c b/src/lib/bluez/serial.c index 747a15d..7cab666 100644 --- a/src/lib/serial.c +++ b/src/lib/bluez/serial.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.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)) @@ -91,7 +92,7 @@ static void serial_init(Serial *self) { self->priv = SERIAL_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); } static void serial_post_init(Serial *self, const gchar *dbus_object_path) @@ -103,20 +104,20 @@ static void serial_post_init(Serial *self, const gchar *dbus_object_path) GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", dbus_object_path, "org.freedesktop.DBus.Introspectable"); + 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=\"", BLUEZ_DBUS_SERIAL_INTERFACE, "\">", 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\"", BLUEZ_DBUS_SERIAL_INTERFACE, dbus_object_path); + 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(conn, "org.bluez", dbus_object_path, BLUEZ_DBUS_SERIAL_INTERFACE); + 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) diff --git a/src/lib/serial.h b/src/lib/bluez/serial.h index 97b071b..d9f850b 100644 --- a/src/lib/serial.h +++ b/src/lib/bluez/serial.h @@ -26,7 +26,7 @@ #include <glib-object.h> -#define BLUEZ_DBUS_SERIAL_INTERFACE "org.bluez.Serial" +#define SERIAL_DBUS_INTERFACE "org.bluez.Serial" /* * Type macros diff --git a/src/lib/dbus-common.c b/src/lib/dbus-common.c index f80ea11..1951131 100644 --- a/src/lib/dbus-common.c +++ b/src/lib/dbus-common.c @@ -25,35 +25,60 @@ #include <config.h> #endif -#include "marshallers.h" -#include "agent.h" +#include "bluez-api.h" +#include "obexd-api.h" +#include "ods-api.h" + #include "dbus-common.h" -DBusGConnection *conn = NULL; +DBusGConnection *session_conn = NULL; +DBusGConnection *system_conn = NULL; -gboolean dbus_connect(GError **error) +void dbus_init() { - conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, error); - if (!conn) { - return FALSE; - } - /* Marshallers registration * Used for signals */ - dbus_g_object_register_marshaller(g_cclosure_bluez_marshal_VOID__UINT64, G_TYPE_NONE, G_TYPE_UINT64, G_TYPE_INVALID); - dbus_g_object_register_marshaller(g_cclosure_bluez_marshal_VOID__STRING_BOXED, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); - dbus_g_object_register_marshaller(g_cclosure_bluez_marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_object_register_marshaller(g_cclosure_bluez_marshal_VOID__STRING_STRING_UINT64, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID); - dbus_g_object_register_marshaller(g_cclosure_bluez_marshal_VOID__BOXED_STRING_STRING, G_TYPE_NONE, G_TYPE_VALUE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + 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__STRING_BOOLEAN, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__UINT64, G_TYPE_NONE, G_TYPE_UINT64, G_TYPE_INVALID); + dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__STRING_STRING_UINT64, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID); + dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__BOXED_STRING_STRING, G_TYPE_NONE, G_TYPE_VALUE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); - /* Agent installation */ + /* Agents installation */ dbus_g_object_type_install_info(AGENT_TYPE, &dbus_glib_agent_object_info); + dbus_g_object_type_install_info(OBEXAGENT_TYPE, &dbus_glib_obexagent_object_info); +} + +gboolean dbus_session_connect(GError **error) +{ + session_conn = dbus_g_bus_get(DBUS_BUS_SESSION, error); + if (!session_conn) { + return FALSE; + } + + return TRUE; +} + +void dbus_session_disconnect() +{ + dbus_g_connection_unref(session_conn); +} + +gboolean dbus_system_connect(GError **error) +{ + system_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, error); + if (!system_conn) { + return FALSE; + } return TRUE; } -void dbus_disconnect() +void dbus_system_disconnect() { - dbus_g_connection_unref(conn); + dbus_g_connection_unref(system_conn); } + diff --git a/src/lib/dbus-common.h b/src/lib/dbus-common.h index c6a38be..a6d979f 100644 --- a/src/lib/dbus-common.h +++ b/src/lib/dbus-common.h @@ -27,16 +27,17 @@ #include <glib.h> #include <dbus/dbus-glib.h> -#define BLUEZ_DBUS_NAME "org.bluez" -#define OBEX_DBUS_NAME "org.openobex" - #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 *conn; +extern DBusGConnection *session_conn; +extern DBusGConnection *system_conn; -gboolean dbus_connect(GError **error); -void dbus_disconnect(); +void dbus_init(); +gboolean dbus_session_connect(GError **error); +void dbus_session_disconnect(); +gboolean dbus_system_connect(GError **error); +void dbus_system_disconnect(); #endif /* __DBUS_COMMON_H */ diff --git a/src/lib/helpers.c b/src/lib/helpers.c index 8dd2a41..a310a97 100644 --- a/src/lib/helpers.c +++ b/src/lib/helpers.c @@ -30,9 +30,10 @@ #include <string.h> #include "dbus-common.h" -#include "manager.h" #include "helpers.h" +#include "bluez-api.h" + /* UUID Name lookup table */ typedef struct { gchar *uuid; diff --git a/src/lib/helpers.h b/src/lib/helpers.h index c7d7c95..5e1c573 100644 --- a/src/lib/helpers.h +++ b/src/lib/helpers.h @@ -27,22 +27,9 @@ #include <stdio.h> #include <glib.h> -/* Bluez DBus Interfaces */ -#include "adapter.h" -#include "device.h" -#include "audio.h" -#include "input.h" -#include "network.h" -#include "network_hub.h" -#include "network_peer.h" -#include "network_router.h" -#include "serial.h" - -/* OBEX DBus Interfaces */ -#include "obexmanager.h" -#include "obexsession.h" -#include "obexserver.h" -#include "obexserver_session.h" +#include "bluez-api.h" +#include "obexd-api.h" +#include "ods-api.h" enum { DEVICE_INTF, diff --git a/src/lib/marshallers.c b/src/lib/marshallers.c index 559fa61..4fecca4 100644 --- a/src/lib/marshallers.c +++ b/src/lib/marshallers.c @@ -47,49 +47,14 @@ #endif /* !G_ENABLE_DEBUG */ -/* VOID:UINT64 (lib/marshallers.list:1) */ -void -g_cclosure_bluez_marshal_VOID__UINT64 (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__UINT64) (gpointer data1, - guint64 arg_1, - gpointer data2); - register GMarshalFunc_VOID__UINT64 callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - 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_VOID__UINT64) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_uint64 (param_values + 1), - data2); -} - /* VOID:STRING,BOXED (lib/marshallers.list:2) */ void -g_cclosure_bluez_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) +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, @@ -119,24 +84,25 @@ g_cclosure_bluez_marshal_VOID__STRING_BOXED (GClosure *closure, data2); } -/* VOID:STRING,STRING (lib/marshallers.list:3) */ +/* BOOLEAN:POINTER (lib/marshallers.list:5) */ void -g_cclosure_bluez_marshal_VOID__STRING_STRING (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) +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 void (*GMarshalFunc_VOID__STRING_STRING) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer data2); - register GMarshalFunc_VOID__STRING_STRING callback; + 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 (n_param_values == 3); + g_return_if_fail (return_value != NULL); + g_return_if_fail (n_param_values == 2); if (G_CCLOSURE_SWAP_DATA (closure)) { @@ -148,32 +114,35 @@ g_cclosure_bluez_marshal_VOID__STRING_STRING (GClosure *closure, data1 = g_value_peek_pointer (param_values + 0); data2 = closure->data; } - callback = (GMarshalFunc_VOID__STRING_STRING) (marshal_data ? marshal_data : cc->callback); + callback = (GMarshalFunc_BOOLEAN__POINTER) (marshal_data ? marshal_data : cc->callback); - callback (data1, - g_marshal_value_peek_string (param_values + 1), - g_marshal_value_peek_string (param_values + 2), - data2); + v_return = callback (data1, + g_marshal_value_peek_pointer (param_values + 1), + data2); + + g_value_set_boolean (return_value, v_return); } -/* VOID:STRING,STRING,UINT64 (lib/marshallers.list:4) */ +/* BOOLEAN:BOXED,POINTER,POINTER (lib/marshallers.list:6) */ void -g_cclosure_bluez_marshal_VOID__STRING_STRING_UINT64 (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) +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 void (*GMarshalFunc_VOID__STRING_STRING_UINT64) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - guint64 arg_3, - gpointer data2); - register GMarshalFunc_VOID__STRING_STRING_UINT64 callback; + 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)) @@ -186,34 +155,39 @@ g_cclosure_bluez_marshal_VOID__STRING_STRING_UINT64 (GClosure *closure, data1 = g_value_peek_pointer (param_values + 0); data2 = closure->data; } - callback = (GMarshalFunc_VOID__STRING_STRING_UINT64) (marshal_data ? marshal_data : cc->callback); + callback = (GMarshalFunc_BOOLEAN__BOXED_POINTER_POINTER) (marshal_data ? marshal_data : cc->callback); - callback (data1, - g_marshal_value_peek_string (param_values + 1), - g_marshal_value_peek_string (param_values + 2), - g_marshal_value_peek_uint64 (param_values + 3), - data2); + 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); } -/* VOID:STRING,STRING,STRING (lib/marshallers.list:5) */ +/* BOOLEAN:BOXED,UINT,UCHAR,POINTER (lib/marshallers.list:7) */ void -g_cclosure_bluez_marshal_VOID__STRING_STRING_STRING (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) +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 void (*GMarshalFunc_VOID__STRING_STRING_STRING) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer arg_3, - gpointer data2); - register GMarshalFunc_VOID__STRING_STRING_STRING callback; + 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 (n_param_values == 4); + g_return_if_fail (return_value != NULL); + g_return_if_fail (n_param_values == 5); if (G_CCLOSURE_SWAP_DATA (closure)) { @@ -225,33 +199,38 @@ g_cclosure_bluez_marshal_VOID__STRING_STRING_STRING (GClosure *closure, data1 = g_value_peek_pointer (param_values + 0); data2 = closure->data; } - callback = (GMarshalFunc_VOID__STRING_STRING_STRING) (marshal_data ? marshal_data : cc->callback); + callback = (GMarshalFunc_BOOLEAN__BOXED_UINT_UCHAR_POINTER) (marshal_data ? marshal_data : cc->callback); - callback (data1, - g_marshal_value_peek_string (param_values + 1), - g_marshal_value_peek_string (param_values + 2), - g_marshal_value_peek_string (param_values + 3), - data2); + 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); } -/* VOID:BOXED,STRING,STRING (lib/marshallers.list:6) */ +/* BOOLEAN:BOXED,UINT,POINTER (lib/marshallers.list:8) */ void -g_cclosure_bluez_marshal_VOID__BOXED_STRING_STRING (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) +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 void (*GMarshalFunc_VOID__BOXED_STRING_STRING) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer arg_3, - gpointer data2); - register GMarshalFunc_VOID__BOXED_STRING_STRING callback; + 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)) @@ -264,34 +243,38 @@ g_cclosure_bluez_marshal_VOID__BOXED_STRING_STRING (GClosure *closure, data1 = g_value_peek_pointer (param_values + 0); data2 = closure->data; } - callback = (GMarshalFunc_VOID__BOXED_STRING_STRING) (marshal_data ? marshal_data : cc->callback); + callback = (GMarshalFunc_BOOLEAN__BOXED_UINT_POINTER) (marshal_data ? marshal_data : cc->callback); - 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), - data2); + 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:POINTER (lib/marshallers.list:9) */ +/* BOOLEAN:BOXED,STRING,POINTER (lib/marshallers.list:9) */ void -g_cclosure_bluez_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) +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__POINTER) (gpointer data1, - gpointer arg_1, - gpointer data2); - register GMarshalFunc_BOOLEAN__POINTER callback; + 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 == 2); + g_return_if_fail (n_param_values == 4); if (G_CCLOSURE_SWAP_DATA (closure)) { @@ -303,10 +286,12 @@ g_cclosure_bluez_marshal_BOOLEAN__POINTER (GClosure *closure, data1 = g_value_peek_pointer (param_values + 0); data2 = closure->data; } - callback = (GMarshalFunc_BOOLEAN__POINTER) (marshal_data ? marshal_data : cc->callback); + callback = (GMarshalFunc_BOOLEAN__BOXED_STRING_POINTER) (marshal_data ? marshal_data : cc->callback); v_return = callback (data1, - g_marshal_value_peek_pointer (param_values + 1), + 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); @@ -314,12 +299,12 @@ g_cclosure_bluez_marshal_BOOLEAN__POINTER (GClosure *closure, /* BOOLEAN:STRING,POINTER (lib/marshallers.list:10) */ void -g_cclosure_bluez_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) +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, @@ -353,27 +338,106 @@ g_cclosure_bluez_marshal_BOOLEAN__STRING_POINTER (GClosure *closure, g_value_set_boolean (return_value, v_return); } -/* BOOLEAN:BOXED,STRING,POINTER (lib/marshallers.list:11) */ +/* VOID:INT,INT (lib/marshallers.list:13) */ void -g_cclosure_bluez_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) +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 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; + 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:14) */ +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); +} + +/* BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER (lib/marshallers.list:17) */ +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 == 4); + g_return_if_fail (n_param_values == 9); if (G_CCLOSURE_SWAP_DATA (closure)) { @@ -385,32 +449,37 @@ g_cclosure_bluez_marshal_BOOLEAN__BOXED_STRING_POINTER (GClosure *closure, data1 = g_value_peek_pointer (param_values + 0); data2 = closure->data; } - callback = (GMarshalFunc_BOOLEAN__BOXED_STRING_POINTER) (marshal_data ? marshal_data : cc->callback); + 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_pointer (param_values + 3), + 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,POINTER,POINTER (lib/marshallers.list:12) */ +/* BOOLEAN:BOXED,UINT64,POINTER (lib/marshallers.list:20) */ void -g_cclosure_bluez_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) +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_POINTER_POINTER) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer arg_3, - gpointer data2); - register GMarshalFunc_BOOLEAN__BOXED_POINTER_POINTER callback; + 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; @@ -428,38 +497,37 @@ g_cclosure_bluez_marshal_BOOLEAN__BOXED_POINTER_POINTER (GClosure *closure, data1 = g_value_peek_pointer (param_values + 0); data2 = closure->data; } - callback = (GMarshalFunc_BOOLEAN__BOXED_POINTER_POINTER) (marshal_data ? marshal_data : cc->callback); + 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_pointer (param_values + 2), + 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,UINT,POINTER (lib/marshallers.list:13) */ +/* BOOLEAN:BOXED,POINTER (lib/marshallers.list:21) */ void -g_cclosure_bluez_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) +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_UINT_POINTER) (gpointer data1, - gpointer arg_1, - guint arg_2, - gpointer arg_3, - gpointer data2); - register GMarshalFunc_BOOLEAN__BOXED_UINT_POINTER callback; + 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 == 4); + g_return_if_fail (n_param_values == 3); if (G_CCLOSURE_SWAP_DATA (closure)) { @@ -471,39 +539,34 @@ g_cclosure_bluez_marshal_BOOLEAN__BOXED_UINT_POINTER (GClosure *closure, data1 = g_value_peek_pointer (param_values + 0); data2 = closure->data; } - callback = (GMarshalFunc_BOOLEAN__BOXED_UINT_POINTER) (marshal_data ? marshal_data : cc->callback); + 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_uint (param_values + 2), - g_marshal_value_peek_pointer (param_values + 3), + g_marshal_value_peek_pointer (param_values + 2), data2); g_value_set_boolean (return_value, v_return); } -/* BOOLEAN:BOXED,UINT,UCHAR,POINTER (lib/marshallers.list:14) */ +/* VOID:STRING,STRING (lib/marshallers.list:25) */ void -g_cclosure_bluez_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) +g_cclosure_bt_marshal_VOID__STRING_STRING (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; + typedef void (*GMarshalFunc_VOID__STRING_STRING) (gpointer data1, + gpointer arg_1, + gpointer arg_2, + gpointer data2); + register GMarshalFunc_VOID__STRING_STRING 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); + g_return_if_fail (n_param_values == 3); if (G_CCLOSURE_SWAP_DATA (closure)) { @@ -515,15 +578,163 @@ g_cclosure_bluez_marshal_BOOLEAN__BOXED_UINT_UCHAR_POINTER (GClosure *closur data1 = g_value_peek_pointer (param_values + 0); data2 = closure->data; } - callback = (GMarshalFunc_BOOLEAN__BOXED_UINT_UCHAR_POINTER) (marshal_data ? marshal_data : cc->callback); + callback = (GMarshalFunc_VOID__STRING_STRING) (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); + callback (data1, + g_marshal_value_peek_string (param_values + 1), + g_marshal_value_peek_string (param_values + 2), + data2); +} - g_value_set_boolean (return_value, v_return); +/* VOID:UINT64 (lib/marshallers.list:26) */ +void +g_cclosure_bt_marshal_VOID__UINT64 (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__UINT64) (gpointer data1, + guint64 arg_1, + gpointer data2); + register GMarshalFunc_VOID__UINT64 callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + + 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_VOID__UINT64) (marshal_data ? marshal_data : cc->callback); + + callback (data1, + g_marshal_value_peek_uint64 (param_values + 1), + data2); +} + +/* VOID:STRING,STRING,UINT64 (lib/marshallers.list:27) */ +void +g_cclosure_bt_marshal_VOID__STRING_STRING_UINT64 (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_STRING_UINT64) (gpointer data1, + gpointer arg_1, + gpointer arg_2, + guint64 arg_3, + gpointer data2); + register GMarshalFunc_VOID__STRING_STRING_UINT64 callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + + 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_VOID__STRING_STRING_UINT64) (marshal_data ? marshal_data : cc->callback); + + callback (data1, + g_marshal_value_peek_string (param_values + 1), + g_marshal_value_peek_string (param_values + 2), + g_marshal_value_peek_uint64 (param_values + 3), + data2); +} + +/* VOID:STRING,STRING,STRING (lib/marshallers.list:30) */ +void +g_cclosure_bt_marshal_VOID__STRING_STRING_STRING (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_STRING_STRING) (gpointer data1, + gpointer arg_1, + gpointer arg_2, + gpointer arg_3, + gpointer data2); + register GMarshalFunc_VOID__STRING_STRING_STRING callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + + 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_VOID__STRING_STRING_STRING) (marshal_data ? marshal_data : cc->callback); + + callback (data1, + g_marshal_value_peek_string (param_values + 1), + g_marshal_value_peek_string (param_values + 2), + g_marshal_value_peek_string (param_values + 3), + data2); +} + +/* VOID:BOXED,STRING,STRING (lib/marshallers.list:31) */ +void +g_cclosure_bt_marshal_VOID__BOXED_STRING_STRING (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_STRING_STRING) (gpointer data1, + gpointer arg_1, + gpointer arg_2, + gpointer arg_3, + gpointer data2); + register GMarshalFunc_VOID__BOXED_STRING_STRING callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + + 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_VOID__BOXED_STRING_STRING) (marshal_data ? marshal_data : cc->callback); + + 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), + data2); } diff --git a/src/lib/marshallers.h b/src/lib/marshallers.h index e8d2427..3076e1c 100644 --- a/src/lib/marshallers.h +++ b/src/lib/marshallers.h @@ -1,108 +1,148 @@ -#ifndef __g_cclosure_bluez_marshal_MARSHAL_H__ -#define __g_cclosure_bluez_marshal_MARSHAL_H__ +#ifndef __g_cclosure_bt_marshal_MARSHAL_H__ +#define __g_cclosure_bt_marshal_MARSHAL_H__ #include <glib-object.h> G_BEGIN_DECLS -/* VOID:UINT64 (lib/marshallers.list:1) */ -extern void g_cclosure_bluez_marshal_VOID__UINT64 (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - /* VOID:STRING,BOXED (lib/marshallers.list:2) */ -extern void g_cclosure_bluez_marshal_VOID__STRING_BOXED (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* VOID:STRING,STRING (lib/marshallers.list:3) */ -extern void g_cclosure_bluez_marshal_VOID__STRING_STRING (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); +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); -/* VOID:STRING,STRING,UINT64 (lib/marshallers.list:4) */ -extern void g_cclosure_bluez_marshal_VOID__STRING_STRING_UINT64 (GClosure *closure, +/* 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); -/* VOID:STRING,STRING,STRING (lib/marshallers.list:5) */ -extern void g_cclosure_bluez_marshal_VOID__STRING_STRING_STRING (GClosure *closure, +/* 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:14) */ +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); + +/* BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER (lib/marshallers.list:17) */ +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:20) */ +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); -/* VOID:BOXED,STRING,STRING (lib/marshallers.list:6) */ -extern void g_cclosure_bluez_marshal_VOID__BOXED_STRING_STRING (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:21) */ +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); -/* BOOLEAN:POINTER (lib/marshallers.list:9) */ -extern void g_cclosure_bluez_marshal_BOOLEAN__POINTER (GClosure *closure, +/* VOID:STRING,STRING (lib/marshallers.list:25) */ +extern void g_cclosure_bt_marshal_VOID__STRING_STRING (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_bluez_marshal_BOOLEAN__STRING_POINTER (GClosure *closure, +/* VOID:UINT64 (lib/marshallers.list:26) */ +extern void g_cclosure_bt_marshal_VOID__UINT64 (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +/* VOID:STRING,STRING,UINT64 (lib/marshallers.list:27) */ +extern void g_cclosure_bt_marshal_VOID__STRING_STRING_UINT64 (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:11) */ -extern void g_cclosure_bluez_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:BOXED,POINTER,POINTER (lib/marshallers.list:12) */ -extern void g_cclosure_bluez_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,POINTER (lib/marshallers.list:13) */ -extern void g_cclosure_bluez_marshal_BOOLEAN__BOXED_UINT_POINTER (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); +/* VOID:STRING,STRING,STRING (lib/marshallers.list:30) */ +extern void g_cclosure_bt_marshal_VOID__STRING_STRING_STRING (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:14) */ -extern void g_cclosure_bluez_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); +/* VOID:BOXED,STRING,STRING (lib/marshallers.list:31) */ +extern void g_cclosure_bt_marshal_VOID__BOXED_STRING_STRING (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_bluez_marshal_MARSHAL_H__ */ +#endif /* __g_cclosure_bt_marshal_MARSHAL_H__ */ diff --git a/src/lib/marshallers.list b/src/lib/marshallers.list index 03b73b4..21aed8c 100644 --- a/src/lib/marshallers.list +++ b/src/lib/marshallers.list @@ -1,15 +1,31 @@ -VOID:UINT64 +# [bluez] VOID:STRING,BOXED -VOID:STRING,STRING -VOID:STRING,STRING,UINT64 -VOID:STRING,STRING,STRING -VOID:BOXED,STRING,STRING -# Used by agent +# Used by Agent BOOLEAN:POINTER -BOOLEAN:STRING,POINTER -BOOLEAN:BOXED,STRING,POINTER BOOLEAN:BOXED,POINTER,POINTER -BOOLEAN:BOXED,UINT,POINTER BOOLEAN:BOXED,UINT,UCHAR,POINTER +BOOLEAN:BOXED,UINT,POINTER +BOOLEAN:BOXED,STRING,POINTER +BOOLEAN:STRING,POINTER + +# [obexd] +VOID:INT,INT +VOID:STRING,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 +# [ods] +VOID:STRING,STRING +VOID:UINT64 +VOID:STRING,STRING,UINT64 + +# equals +VOID:STRING,STRING,STRING +VOID:BOXED,STRING,STRING diff --git a/src/lib/network_hub.c b/src/lib/network_hub.c deleted file mode 100644 index 16c7044..0000000 --- a/src/lib/network_hub.c +++ /dev/null @@ -1,318 +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 <glib.h> -#include <string.h> - -#include "dbus-common.h" -#include "marshallers.h" -#include "network_hub.h" - -#define NETWORK_HUB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), NETWORK_HUB_TYPE, NetworkHubPrivate)) - -struct _NetworkHubPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; - - /* Properties */ - gboolean enabled; - gchar *name; - gchar *uuid; -}; - -G_DEFINE_TYPE(NetworkHub, network_hub, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */ - PROP_ENABLED, /* readwrite */ - PROP_NAME, /* readwrite */ - PROP_UUID /* readonly */ -}; - -static void _network_hub_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _network_hub_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -static void network_hub_dispose(GObject *gobject) -{ - NetworkHub *self = NETWORK_HUB(gobject); - - /* Properties free */ - g_free(self->priv->name); - 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); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(network_hub_parent_class)->dispose(gobject); -} - -static void network_hub_class_init(NetworkHubClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = network_hub_dispose; - - g_type_class_add_private(klass, sizeof(NetworkHubPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _network_hub_get_property; - gobject_class->set_property = _network_hub_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); - - /* boolean Enabled [readwrite] */ - pspec = g_param_spec_boolean("Enabled", NULL, NULL, FALSE, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_ENABLED, pspec); - - /* string Name [readwrite] */ - pspec = g_param_spec_string("Name", NULL, NULL, NULL, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_NAME, pspec); - - /* string Uuid [readonly] */ - pspec = g_param_spec_string("Uuid", NULL, NULL, NULL, G_PARAM_READABLE); - g_object_class_install_property(gobject_class, PROP_UUID, pspec); -} - -static void network_hub_init(NetworkHub *self) -{ - self->priv = NETWORK_HUB_GET_PRIVATE(self); - - g_assert(conn != NULL); -} - -static void network_hub_post_init(NetworkHub *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(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=\"", BLUEZ_DBUS_NETWORK_HUB_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\"", BLUEZ_DBUS_NETWORK_HUB_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", dbus_object_path, BLUEZ_DBUS_NETWORK_HUB_INTERFACE); - - /* Properties init */ - GHashTable *properties = network_hub_get_properties(self, &error); - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - g_assert(properties != NULL); - - /* boolean Enabled [readwrite] */ - if (g_hash_table_lookup(properties, "Enabled")) { - self->priv->enabled = g_value_get_boolean(g_hash_table_lookup(properties, "Enabled")); - } else { - self->priv->enabled = FALSE; - } - - /* string Name [readwrite] */ - if (g_hash_table_lookup(properties, "Name")) { - self->priv->name = g_value_dup_string(g_hash_table_lookup(properties, "Name")); - } else { - self->priv->name = g_strdup("undefined"); - } - - /* string Uuid [readonly] */ - if (g_hash_table_lookup(properties, "Uuid")) { - self->priv->uuid = g_value_dup_string(g_hash_table_lookup(properties, "Uuid")); - } else { - self->priv->uuid = g_strdup("undefined"); - } - - g_hash_table_unref(properties); -} - -static void _network_hub_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - NetworkHub *self = NETWORK_HUB(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, network_hub_get_dbus_object_path(self)); - break; - - case PROP_ENABLED: - g_value_set_boolean(value, network_hub_get_enabled(self)); - break; - - case PROP_NAME: - g_value_set_string(value, network_hub_get_name(self)); - break; - - case PROP_UUID: - g_value_set_string(value, network_hub_get_uuid(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _network_hub_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - NetworkHub *self = NETWORK_HUB(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - network_hub_post_init(self, g_value_get_string(value)); - break; - - case PROP_ENABLED: - network_hub_set_property(self, "Enabled", value, &error); - break; - - case PROP_NAME: - network_hub_set_property(self, "Name", value, &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); -} - -/* Methods */ - -/* dict GetProperties() */ -GHashTable *network_hub_get_properties(NetworkHub *self, GError **error) -{ - g_assert(NETWORK_HUB_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetProperties", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void SetProperty(string name, variant value) */ -void network_hub_set_property(NetworkHub *self, const gchar *name, const GValue *value, GError **error) -{ - g_assert(NETWORK_HUB_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "SetProperty", error, G_TYPE_STRING, name, G_TYPE_VALUE, value, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* Properties access methods */ -const gchar *network_hub_get_dbus_object_path(NetworkHub *self) -{ - g_assert(NETWORK_HUB_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - -const gboolean network_hub_get_enabled(NetworkHub *self) -{ - g_assert(NETWORK_HUB_IS(self)); - - return self->priv->enabled; -} - -void network_hub_set_enabled(NetworkHub *self, const gboolean value) -{ - g_assert(NETWORK_HUB_IS(self)); - - GError *error = NULL; - - GValue t = {0}; - g_value_init(&t, G_TYPE_BOOLEAN); - g_value_set_boolean(&t, value); - network_hub_set_property(self, "Enabled", &t, &error); - g_value_unset(&t); - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -const gchar *network_hub_get_name(NetworkHub *self) -{ - g_assert(NETWORK_HUB_IS(self)); - - return self->priv->name; -} - -void network_hub_set_name(NetworkHub *self, const gchar *value) -{ - g_assert(NETWORK_HUB_IS(self)); - - GError *error = NULL; - - GValue t = {0}; - g_value_init(&t, G_TYPE_STRING); - g_value_set_string(&t, value); - network_hub_set_property(self, "Name", &t, &error); - g_value_unset(&t); - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -const gchar *network_hub_get_uuid(NetworkHub *self) -{ - g_assert(NETWORK_HUB_IS(self)); - - return self->priv->uuid; -} - diff --git a/src/lib/network_hub.h b/src/lib/network_hub.h deleted file mode 100644 index f989e5e..0000000 --- a/src/lib/network_hub.h +++ /dev/null @@ -1,73 +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 __NETWORK_HUB_H -#define __NETWORK_HUB_H - -#include <glib-object.h> - -#define BLUEZ_DBUS_NETWORK_HUB_INTERFACE "org.bluez.NetworkHub" - -/* - * Type macros - */ -#define NETWORK_HUB_TYPE (network_hub_get_type()) -#define NETWORK_HUB(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NETWORK_HUB_TYPE, NetworkHub)) -#define NETWORK_HUB_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NETWORK_HUB_TYPE)) -#define NETWORK_HUB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), NETWORK_HUB_TYPE, NetworkHubClass)) -#define NETWORK_HUB_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NETWORK_HUB_TYPE)) -#define NETWORK_HUB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), NETWORK_HUB_TYPE, NetworkHubClass)) - -typedef struct _NetworkHub NetworkHub; -typedef struct _NetworkHubClass NetworkHubClass; -typedef struct _NetworkHubPrivate NetworkHubPrivate; - -struct _NetworkHub { - GObject parent_instance; - - /*< private >*/ - NetworkHubPrivate *priv; -}; - -struct _NetworkHubClass { - GObjectClass parent_class; -}; - -/* used by NETWORK_HUB_TYPE */ -GType network_hub_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -GHashTable *network_hub_get_properties(NetworkHub *self, GError **error); -void network_hub_set_property(NetworkHub *self, const gchar *name, const GValue *value, GError **error); - -const gchar *network_hub_get_dbus_object_path(NetworkHub *self); -const gboolean network_hub_get_enabled(NetworkHub *self); -void network_hub_set_enabled(NetworkHub *self, const gboolean value); -const gchar *network_hub_get_name(NetworkHub *self); -void network_hub_set_name(NetworkHub *self, const gchar *value); -const gchar *network_hub_get_uuid(NetworkHub *self); - -#endif /* __NETWORK_HUB_H */ - diff --git a/src/lib/network_peer.c b/src/lib/network_peer.c deleted file mode 100644 index 99ad9b3..0000000 --- a/src/lib/network_peer.c +++ /dev/null @@ -1,318 +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 <glib.h> -#include <string.h> - -#include "dbus-common.h" -#include "marshallers.h" -#include "network_peer.h" - -#define NETWORK_PEER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), NETWORK_PEER_TYPE, NetworkPeerPrivate)) - -struct _NetworkPeerPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; - - /* Properties */ - gboolean enabled; - gchar *name; - gchar *uuid; -}; - -G_DEFINE_TYPE(NetworkPeer, network_peer, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */ - PROP_ENABLED, /* readwrite */ - PROP_NAME, /* readwrite */ - PROP_UUID /* readonly */ -}; - -static void _network_peer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _network_peer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -static void network_peer_dispose(GObject *gobject) -{ - NetworkPeer *self = NETWORK_PEER(gobject); - - /* Properties free */ - g_free(self->priv->name); - 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); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(network_peer_parent_class)->dispose(gobject); -} - -static void network_peer_class_init(NetworkPeerClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = network_peer_dispose; - - g_type_class_add_private(klass, sizeof(NetworkPeerPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _network_peer_get_property; - gobject_class->set_property = _network_peer_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); - - /* boolean Enabled [readwrite] */ - pspec = g_param_spec_boolean("Enabled", NULL, NULL, FALSE, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_ENABLED, pspec); - - /* string Name [readwrite] */ - pspec = g_param_spec_string("Name", NULL, NULL, NULL, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_NAME, pspec); - - /* string Uuid [readonly] */ - pspec = g_param_spec_string("Uuid", NULL, NULL, NULL, G_PARAM_READABLE); - g_object_class_install_property(gobject_class, PROP_UUID, pspec); -} - -static void network_peer_init(NetworkPeer *self) -{ - self->priv = NETWORK_PEER_GET_PRIVATE(self); - - g_assert(conn != NULL); -} - -static void network_peer_post_init(NetworkPeer *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(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=\"", BLUEZ_DBUS_NETWORK_PEER_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\"", BLUEZ_DBUS_NETWORK_PEER_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", dbus_object_path, BLUEZ_DBUS_NETWORK_PEER_INTERFACE); - - /* Properties init */ - GHashTable *properties = network_peer_get_properties(self, &error); - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - g_assert(properties != NULL); - - /* boolean Enabled [readwrite] */ - if (g_hash_table_lookup(properties, "Enabled")) { - self->priv->enabled = g_value_get_boolean(g_hash_table_lookup(properties, "Enabled")); - } else { - self->priv->enabled = FALSE; - } - - /* string Name [readwrite] */ - if (g_hash_table_lookup(properties, "Name")) { - self->priv->name = g_value_dup_string(g_hash_table_lookup(properties, "Name")); - } else { - self->priv->name = g_strdup("undefined"); - } - - /* string Uuid [readonly] */ - if (g_hash_table_lookup(properties, "Uuid")) { - self->priv->uuid = g_value_dup_string(g_hash_table_lookup(properties, "Uuid")); - } else { - self->priv->uuid = g_strdup("undefined"); - } - - g_hash_table_unref(properties); -} - -static void _network_peer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - NetworkPeer *self = NETWORK_PEER(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, network_peer_get_dbus_object_path(self)); - break; - - case PROP_ENABLED: - g_value_set_boolean(value, network_peer_get_enabled(self)); - break; - - case PROP_NAME: - g_value_set_string(value, network_peer_get_name(self)); - break; - - case PROP_UUID: - g_value_set_string(value, network_peer_get_uuid(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _network_peer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - NetworkPeer *self = NETWORK_PEER(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - network_peer_post_init(self, g_value_get_string(value)); - break; - - case PROP_ENABLED: - network_peer_set_property(self, "Enabled", value, &error); - break; - - case PROP_NAME: - network_peer_set_property(self, "Name", value, &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); -} - -/* Methods */ - -/* dict GetProperties() */ -GHashTable *network_peer_get_properties(NetworkPeer *self, GError **error) -{ - g_assert(NETWORK_PEER_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetProperties", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void SetProperty(string name, variant value) */ -void network_peer_set_property(NetworkPeer *self, const gchar *name, const GValue *value, GError **error) -{ - g_assert(NETWORK_PEER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "SetProperty", error, G_TYPE_STRING, name, G_TYPE_VALUE, value, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* Properties access methods */ -const gchar *network_peer_get_dbus_object_path(NetworkPeer *self) -{ - g_assert(NETWORK_PEER_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - -const gboolean network_peer_get_enabled(NetworkPeer *self) -{ - g_assert(NETWORK_PEER_IS(self)); - - return self->priv->enabled; -} - -void network_peer_set_enabled(NetworkPeer *self, const gboolean value) -{ - g_assert(NETWORK_PEER_IS(self)); - - GError *error = NULL; - - GValue t = {0}; - g_value_init(&t, G_TYPE_BOOLEAN); - g_value_set_boolean(&t, value); - network_peer_set_property(self, "Enabled", &t, &error); - g_value_unset(&t); - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -const gchar *network_peer_get_name(NetworkPeer *self) -{ - g_assert(NETWORK_PEER_IS(self)); - - return self->priv->name; -} - -void network_peer_set_name(NetworkPeer *self, const gchar *value) -{ - g_assert(NETWORK_PEER_IS(self)); - - GError *error = NULL; - - GValue t = {0}; - g_value_init(&t, G_TYPE_STRING); - g_value_set_string(&t, value); - network_peer_set_property(self, "Name", &t, &error); - g_value_unset(&t); - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -const gchar *network_peer_get_uuid(NetworkPeer *self) -{ - g_assert(NETWORK_PEER_IS(self)); - - return self->priv->uuid; -} - diff --git a/src/lib/network_peer.h b/src/lib/network_peer.h deleted file mode 100644 index 6ef5746..0000000 --- a/src/lib/network_peer.h +++ /dev/null @@ -1,73 +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 __NETWORK_PEER_H -#define __NETWORK_PEER_H - -#include <glib-object.h> - -#define BLUEZ_DBUS_NETWORK_PEER_INTERFACE "org.bluez.NetworkPeer" - -/* - * Type macros - */ -#define NETWORK_PEER_TYPE (network_peer_get_type()) -#define NETWORK_PEER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NETWORK_PEER_TYPE, NetworkPeer)) -#define NETWORK_PEER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NETWORK_PEER_TYPE)) -#define NETWORK_PEER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), NETWORK_PEER_TYPE, NetworkPeerClass)) -#define NETWORK_PEER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NETWORK_PEER_TYPE)) -#define NETWORK_PEER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), NETWORK_PEER_TYPE, NetworkPeerClass)) - -typedef struct _NetworkPeer NetworkPeer; -typedef struct _NetworkPeerClass NetworkPeerClass; -typedef struct _NetworkPeerPrivate NetworkPeerPrivate; - -struct _NetworkPeer { - GObject parent_instance; - - /*< private >*/ - NetworkPeerPrivate *priv; -}; - -struct _NetworkPeerClass { - GObjectClass parent_class; -}; - -/* used by NETWORK_PEER_TYPE */ -GType network_peer_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -GHashTable *network_peer_get_properties(NetworkPeer *self, GError **error); -void network_peer_set_property(NetworkPeer *self, const gchar *name, const GValue *value, GError **error); - -const gchar *network_peer_get_dbus_object_path(NetworkPeer *self); -const gboolean network_peer_get_enabled(NetworkPeer *self); -void network_peer_set_enabled(NetworkPeer *self, const gboolean value); -const gchar *network_peer_get_name(NetworkPeer *self); -void network_peer_set_name(NetworkPeer *self, const gchar *value); -const gchar *network_peer_get_uuid(NetworkPeer *self); - -#endif /* __NETWORK_PEER_H */ - diff --git a/src/lib/network_router.c b/src/lib/network_router.c deleted file mode 100644 index c125390..0000000 --- a/src/lib/network_router.c +++ /dev/null @@ -1,318 +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 <glib.h> -#include <string.h> - -#include "dbus-common.h" -#include "marshallers.h" -#include "network_router.h" - -#define NETWORK_ROUTER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), NETWORK_ROUTER_TYPE, NetworkRouterPrivate)) - -struct _NetworkRouterPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; - - /* Properties */ - gboolean enabled; - gchar *name; - gchar *uuid; -}; - -G_DEFINE_TYPE(NetworkRouter, network_router, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */ - PROP_ENABLED, /* readwrite */ - PROP_NAME, /* readwrite */ - PROP_UUID /* readonly */ -}; - -static void _network_router_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _network_router_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -static void network_router_dispose(GObject *gobject) -{ - NetworkRouter *self = NETWORK_ROUTER(gobject); - - /* Properties free */ - g_free(self->priv->name); - 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); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(network_router_parent_class)->dispose(gobject); -} - -static void network_router_class_init(NetworkRouterClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = network_router_dispose; - - g_type_class_add_private(klass, sizeof(NetworkRouterPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _network_router_get_property; - gobject_class->set_property = _network_router_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); - - /* boolean Enabled [readwrite] */ - pspec = g_param_spec_boolean("Enabled", NULL, NULL, FALSE, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_ENABLED, pspec); - - /* string Name [readwrite] */ - pspec = g_param_spec_string("Name", NULL, NULL, NULL, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_NAME, pspec); - - /* string Uuid [readonly] */ - pspec = g_param_spec_string("Uuid", NULL, NULL, NULL, G_PARAM_READABLE); - g_object_class_install_property(gobject_class, PROP_UUID, pspec); -} - -static void network_router_init(NetworkRouter *self) -{ - self->priv = NETWORK_ROUTER_GET_PRIVATE(self); - - g_assert(conn != NULL); -} - -static void network_router_post_init(NetworkRouter *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(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=\"", BLUEZ_DBUS_NETWORK_ROUTER_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\"", BLUEZ_DBUS_NETWORK_ROUTER_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", dbus_object_path, BLUEZ_DBUS_NETWORK_ROUTER_INTERFACE); - - /* Properties init */ - GHashTable *properties = network_router_get_properties(self, &error); - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - g_assert(properties != NULL); - - /* boolean Enabled [readwrite] */ - if (g_hash_table_lookup(properties, "Enabled")) { - self->priv->enabled = g_value_get_boolean(g_hash_table_lookup(properties, "Enabled")); - } else { - self->priv->enabled = FALSE; - } - - /* string Name [readwrite] */ - if (g_hash_table_lookup(properties, "Name")) { - self->priv->name = g_value_dup_string(g_hash_table_lookup(properties, "Name")); - } else { - self->priv->name = g_strdup("undefined"); - } - - /* string Uuid [readonly] */ - if (g_hash_table_lookup(properties, "Uuid")) { - self->priv->uuid = g_value_dup_string(g_hash_table_lookup(properties, "Uuid")); - } else { - self->priv->uuid = g_strdup("undefined"); - } - - g_hash_table_unref(properties); -} - -static void _network_router_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - NetworkRouter *self = NETWORK_ROUTER(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, network_router_get_dbus_object_path(self)); - break; - - case PROP_ENABLED: - g_value_set_boolean(value, network_router_get_enabled(self)); - break; - - case PROP_NAME: - g_value_set_string(value, network_router_get_name(self)); - break; - - case PROP_UUID: - g_value_set_string(value, network_router_get_uuid(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _network_router_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - NetworkRouter *self = NETWORK_ROUTER(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - network_router_post_init(self, g_value_get_string(value)); - break; - - case PROP_ENABLED: - network_router_set_property(self, "Enabled", value, &error); - break; - - case PROP_NAME: - network_router_set_property(self, "Name", value, &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); -} - -/* Methods */ - -/* dict GetProperties() */ -GHashTable *network_router_get_properties(NetworkRouter *self, GError **error) -{ - g_assert(NETWORK_ROUTER_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetProperties", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void SetProperty(string name, variant value) */ -void network_router_set_property(NetworkRouter *self, const gchar *name, const GValue *value, GError **error) -{ - g_assert(NETWORK_ROUTER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "SetProperty", error, G_TYPE_STRING, name, G_TYPE_VALUE, value, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* Properties access methods */ -const gchar *network_router_get_dbus_object_path(NetworkRouter *self) -{ - g_assert(NETWORK_ROUTER_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - -const gboolean network_router_get_enabled(NetworkRouter *self) -{ - g_assert(NETWORK_ROUTER_IS(self)); - - return self->priv->enabled; -} - -void network_router_set_enabled(NetworkRouter *self, const gboolean value) -{ - g_assert(NETWORK_ROUTER_IS(self)); - - GError *error = NULL; - - GValue t = {0}; - g_value_init(&t, G_TYPE_BOOLEAN); - g_value_set_boolean(&t, value); - network_router_set_property(self, "Enabled", &t, &error); - g_value_unset(&t); - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -const gchar *network_router_get_name(NetworkRouter *self) -{ - g_assert(NETWORK_ROUTER_IS(self)); - - return self->priv->name; -} - -void network_router_set_name(NetworkRouter *self, const gchar *value) -{ - g_assert(NETWORK_ROUTER_IS(self)); - - GError *error = NULL; - - GValue t = {0}; - g_value_init(&t, G_TYPE_STRING); - g_value_set_string(&t, value); - network_router_set_property(self, "Name", &t, &error); - g_value_unset(&t); - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -const gchar *network_router_get_uuid(NetworkRouter *self) -{ - g_assert(NETWORK_ROUTER_IS(self)); - - return self->priv->uuid; -} - diff --git a/src/lib/network_router.h b/src/lib/network_router.h deleted file mode 100644 index a163608..0000000 --- a/src/lib/network_router.h +++ /dev/null @@ -1,73 +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 __NETWORK_ROUTER_H -#define __NETWORK_ROUTER_H - -#include <glib-object.h> - -#define BLUEZ_DBUS_NETWORK_ROUTER_INTERFACE "org.bluez.NetworkRouter" - -/* - * Type macros - */ -#define NETWORK_ROUTER_TYPE (network_router_get_type()) -#define NETWORK_ROUTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NETWORK_ROUTER_TYPE, NetworkRouter)) -#define NETWORK_ROUTER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NETWORK_ROUTER_TYPE)) -#define NETWORK_ROUTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), NETWORK_ROUTER_TYPE, NetworkRouterClass)) -#define NETWORK_ROUTER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NETWORK_ROUTER_TYPE)) -#define NETWORK_ROUTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), NETWORK_ROUTER_TYPE, NetworkRouterClass)) - -typedef struct _NetworkRouter NetworkRouter; -typedef struct _NetworkRouterClass NetworkRouterClass; -typedef struct _NetworkRouterPrivate NetworkRouterPrivate; - -struct _NetworkRouter { - GObject parent_instance; - - /*< private >*/ - NetworkRouterPrivate *priv; -}; - -struct _NetworkRouterClass { - GObjectClass parent_class; -}; - -/* used by NETWORK_ROUTER_TYPE */ -GType network_router_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -GHashTable *network_router_get_properties(NetworkRouter *self, GError **error); -void network_router_set_property(NetworkRouter *self, const gchar *name, const GValue *value, GError **error); - -const gchar *network_router_get_dbus_object_path(NetworkRouter *self); -const gboolean network_router_get_enabled(NetworkRouter *self); -void network_router_set_enabled(NetworkRouter *self, const gboolean value); -const gchar *network_router_get_name(NetworkRouter *self); -void network_router_set_name(NetworkRouter *self, const gchar *value); -const gchar *network_router_get_uuid(NetworkRouter *self); - -#endif /* __NETWORK_ROUTER_H */ - diff --git a/src/lib/obexd-api.h b/src/lib/obexd-api.h new file mode 100644 index 0000000..e299530 --- /dev/null +++ b/src/lib/obexd-api.h @@ -0,0 +1,44 @@ +/* + * + * 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 __OBEXD_API_H +#define __OBEXD_API_H + +/* Global includes */ +#include <glib.h> +#include <dbus/dbus-glib.h> + +#define OBEXD_DBUS_NAME "org.openobex" + +/* 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 /* __OBEXD_API_H */ + diff --git a/src/lib/obexd/obexagent.c b/src/lib/obexd/obexagent.c new file mode 100644 index 0000000..cdf954c --- /dev/null +++ b/src/lib/obexd/obexagent.c @@ -0,0 +1,175 @@ +/* + * + * 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-common.h" + +#include "obexclient_transfer.h" +#include "obexagent.h" + +#define OBEXAGENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXAGENT_TYPE, OBEXAgentPrivate)) + +struct _OBEXAgentPrivate { + DBusGProxy *proxy; +}; + +G_DEFINE_TYPE(OBEXAgent, obexagent, G_TYPE_OBJECT); + +static void obexagent_dispose(GObject *gobject) +{ + OBEXAgent *self = OBEXAGENT(gobject); + + dbus_g_connection_unregister_g_object(session_conn, gobject); + + /* 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)); +} + +static void obexagent_init(OBEXAgent *self) +{ + self->priv = OBEXAGENT_GET_PRIVATE(self); + + g_assert(conn != NULL); + + dbus_g_connection_register_g_object(session_conn, OBEXAGENT_DBUS_PATH, G_OBJECT(self)); + + g_print("OBEX Agent registered\n"); +} + +/* Methods */ + +/* Agent 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) +{ + *ret = NULL; + g_print("[Bluetooth ObjectPush request]\n"); + OBEXClientTransfer *transfer_obj = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); + g_print(" Transfer: %s (%llu bytes), %s\n", obexclient_transfer_get_name(transfer_obj), obexclient_transfer_get_size(transfer_obj), obexclient_transfer_get_filename(transfer_obj)); + g_object_unref(transfer_obj); + g_print(" Address: %s\n", bt_address); + g_print(" Name: %s\n", name); + g_print(" Type: %s\n", type); + g_print(" Length: %d\n", length); + 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) { + *ret = g_strdup("/home/zak/obp.ext"); + 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; + } + + return TRUE; +} + +gboolean obexagent_cancel(OBEXAgent *self, GError **error) +{ + g_print("Request cancelled\n"); + return TRUE; +} + +/* Client API */ +gboolean obexagent_release(OBEXAgent *self, GError **error) +{ + g_print("OBEX Agent released\n"); + return TRUE; +} + +gboolean obexagent_request(OBEXAgent *self, const gchar *transfer, gchar **ret, GError **error) +{ + *ret = NULL; + OBEXClientTransfer *transfer_obj = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); + g_print("Transfer: %s (%llu bytes), %s\n", obexclient_transfer_get_name(transfer_obj), obexclient_transfer_get_size(transfer_obj), obexclient_transfer_get_filename(transfer_obj)); + g_object_unref(transfer_obj); + + 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; + } + + return TRUE; +} + +gboolean obexagent_progress(OBEXAgent *self, const gchar *transfer, guint64 transferred, GError **error) +{ + OBEXClientTransfer *transfer_obj = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); + g_print("Transfer progress: %s (%llu/%llu bytes), %s\n", obexclient_transfer_get_name(transfer_obj), transferred, obexclient_transfer_get_size(transfer_obj), obexclient_transfer_get_filename(transfer_obj)); + g_object_unref(transfer_obj); + + return TRUE; +} + +gboolean obexagent_complete(OBEXAgent *self, const gchar *transfer, GError **error) +{ + OBEXClientTransfer *transfer_obj = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); + g_print("Transfer complete: %s (%llu bytes), %s\n", obexclient_transfer_get_name(transfer_obj), obexclient_transfer_get_size(transfer_obj), obexclient_transfer_get_filename(transfer_obj)); + g_object_unref(transfer_obj); + + return TRUE; +} + +gboolean obexagent_error(OBEXAgent *self, const gchar *transfer, const gchar *message, GError **error) +{ + OBEXClientTransfer *transfer_obj = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); + g_print("Transfer error: %s (%llu bytes), %s: %s\n", obexclient_transfer_get_name(transfer_obj), obexclient_transfer_get_size(transfer_obj), obexclient_transfer_get_filename(transfer_obj), message); + g_object_unref(transfer_obj); + + return TRUE; +} + diff --git a/src/lib/obexd/obexagent.h b/src/lib/obexd/obexagent.h new file mode 100644 index 0000000..997ac6d --- /dev/null +++ b/src/lib/obexd/obexagent.h @@ -0,0 +1,98 @@ +/* + * + * 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 + */ + +/* Agent 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 new file mode 100644 index 0000000..ba78633 --- /dev/null +++ b/src/lib/obexd/obexclient.c @@ -0,0 +1,153 @@ +/* + * + * 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 <string.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); + + 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 new file mode 100644 index 0000000..d999b76 --- /dev/null +++ b/src/lib/obexd/obexclient.h @@ -0,0 +1,71 @@ +/* + * + * bluez-tools - a set of tools to manage bluetooth devices for linux + * + * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __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 new file mode 100644 index 0000000..60f44dd --- /dev/null +++ b/src/lib/obexd/obexclient_file_transfer.c @@ -0,0 +1,235 @@ +/* + * + * 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 <string.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); + + 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 new file mode 100644 index 0000000..5e796b2 --- /dev/null +++ b/src/lib/obexd/obexclient_file_transfer.h @@ -0,0 +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 + * + */ + +#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 new file mode 100644 index 0000000..810536c --- /dev/null +++ b/src/lib/obexd/obexclient_session.c @@ -0,0 +1,283 @@ +/* + * + * 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 <string.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); + + 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 new file mode 100644 index 0000000..87af06d --- /dev/null +++ b/src/lib/obexd/obexclient_session.h @@ -0,0 +1,72 @@ +/* + * + * 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 new file mode 100644 index 0000000..04f7444 --- /dev/null +++ b/src/lib/obexd/obexclient_transfer.c @@ -0,0 +1,275 @@ +/* + * + * 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 <string.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); + + 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 new file mode 100644 index 0000000..f84fd69 --- /dev/null +++ b/src/lib/obexd/obexclient_transfer.h @@ -0,0 +1,71 @@ +/* + * + * bluez-tools - a set of tools to manage bluetooth devices for linux + * + * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __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 new file mode 100644 index 0000000..f17292d --- /dev/null +++ b/src/lib/obexd/obexmanager.c @@ -0,0 +1,213 @@ +/* + * + * 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 <string.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); + + 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 new file mode 100644 index 0000000..203fe59 --- /dev/null +++ b/src/lib/obexd/obexmanager.h @@ -0,0 +1,67 @@ +/* + * + * 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 new file mode 100644 index 0000000..8883c1d --- /dev/null +++ b/src/lib/obexd/obexsession.c @@ -0,0 +1,218 @@ +/* + * + * 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 <string.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); + + 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 new file mode 100644 index 0000000..d39e15f --- /dev/null +++ b/src/lib/obexd/obexsession.h @@ -0,0 +1,68 @@ +/* + * + * 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 new file mode 100644 index 0000000..bb08db9 --- /dev/null +++ b/src/lib/obexd/obextransfer.c @@ -0,0 +1,211 @@ +/* + * + * 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 <string.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); + + 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 new file mode 100644 index 0000000..99f3084 --- /dev/null +++ b/src/lib/obexd/obextransfer.h @@ -0,0 +1,67 @@ +/* + * + * 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/ods-api.h b/src/lib/ods-api.h new file mode 100644 index 0000000..b0644f3 --- /dev/null +++ b/src/lib/ods-api.h @@ -0,0 +1,40 @@ +/* + * + * 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 __ODS_API_H +#define __ODS_API_H + +/* Global includes */ +#include <glib.h> +#include <dbus/dbus-glib.h> + +#define ODS_DBUS_NAME "org.openobex" + +/* ODS DBus API */ +#include "ods/obexmanager.h" +#include "ods/obexserver.h" +#include "ods/obexserver_session.h" +#include "ods/obexsession.h" + +#endif /* __ODS_API_H */ + diff --git a/src/lib/obexmanager.c b/src/lib/ods/obexmanager.c index 576e36c..3eb7b10 100644 --- a/src/lib/obexmanager.c +++ b/src/lib/ods/obexmanager.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.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)) @@ -98,7 +99,7 @@ static void obexmanager_class_init(OBEXManagerClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_STRING_STRING, + g_cclosure_bt_marshal_VOID__STRING_STRING_STRING, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); signals[SESSION_CONNECTED] = g_signal_new("SessionConnected", @@ -113,26 +114,26 @@ static void obexmanager_init(OBEXManager *self) { self->priv = OBEXMANAGER_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.openobex", BLUEZ_DBUS_OBEXMANAGER_PATH, "org.freedesktop.DBus.Introspectable"); + self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(system_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=\"", BLUEZ_DBUS_OBEXMANAGER_INTERFACE, "\">", 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\"", BLUEZ_DBUS_OBEXMANAGER_INTERFACE, BLUEZ_DBUS_OBEXMANAGER_PATH); + 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(conn, "org.openobex", BLUEZ_DBUS_OBEXMANAGER_PATH, BLUEZ_DBUS_OBEXMANAGER_INTERFACE); + self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", OBEXMANAGER_DBUS_PATH, OBEXMANAGER_DBUS_INTERFACE); /* DBus signals connection */ diff --git a/src/lib/obexmanager.h b/src/lib/ods/obexmanager.h index f5964f2..20e12ea 100644 --- a/src/lib/obexmanager.h +++ b/src/lib/ods/obexmanager.h @@ -26,8 +26,8 @@ #include <glib-object.h> -#define BLUEZ_DBUS_OBEXMANAGER_PATH "/org/openobex" -#define BLUEZ_DBUS_OBEXMANAGER_INTERFACE "org.openobex.Manager" +#define OBEXMANAGER_DBUS_PATH "/org/openobex" +#define OBEXMANAGER_DBUS_INTERFACE "org.openobex.Manager" /* * Type macros diff --git a/src/lib/obexserver.c b/src/lib/ods/obexserver.c index df07a68..ab968b2 100644 --- a/src/lib/obexserver.c +++ b/src/lib/ods/obexserver.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.h" +#include "../dbus-common.h" +#include "../marshallers.h" + #include "obexserver.h" #define OBEXSERVER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXSERVER_TYPE, OBEXServerPrivate)) @@ -126,7 +127,7 @@ static void obexserver_class_init(OBEXServerClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_STRING, + g_cclosure_bt_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); signals[SESSION_CREATED] = g_signal_new("SessionCreated", @@ -162,7 +163,7 @@ static void obexserver_init(OBEXServer *self) { self->priv = OBEXSERVER_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); } static void obexserver_post_init(OBEXServer *self, const gchar *dbus_object_path) @@ -174,20 +175,20 @@ static void obexserver_post_init(OBEXServer *self, const gchar *dbus_object_path GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.openobex", dbus_object_path, "org.freedesktop.DBus.Introspectable"); + self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(system_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=\"", BLUEZ_DBUS_OBEXSERVER_INTERFACE, "\">", NULL); + gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXSERVER_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\"", BLUEZ_DBUS_OBEXSERVER_INTERFACE, dbus_object_path); + g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXSERVER_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(conn, "org.openobex", dbus_object_path, BLUEZ_DBUS_OBEXSERVER_INTERFACE); + self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", dbus_object_path, OBEXSERVER_DBUS_INTERFACE); /* DBus signals connection */ diff --git a/src/lib/obexserver.h b/src/lib/ods/obexserver.h index dfea764..f4a3c60 100644 --- a/src/lib/obexserver.h +++ b/src/lib/ods/obexserver.h @@ -26,7 +26,7 @@ #include <glib-object.h> -#define BLUEZ_DBUS_OBEXSERVER_INTERFACE "org.openobex.Server" +#define OBEXSERVER_DBUS_INTERFACE "org.openobex.Server" /* * Type macros diff --git a/src/lib/obexserver_session.c b/src/lib/ods/obexserver_session.c index 45f493f..5920517 100644 --- a/src/lib/obexserver_session.c +++ b/src/lib/ods/obexserver_session.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.h" +#include "../dbus-common.h" +#include "../marshallers.h" + #include "obexserver_session.h" #define OBEXSERVER_SESSION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXSERVER_SESSION_TYPE, OBEXServerSessionPrivate)) @@ -133,7 +134,7 @@ static void obexserver_session_class_init(OBEXServerSessionClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_STRING, + g_cclosure_bt_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); signals[TRANSFER_COMPLETED] = g_signal_new("TransferCompleted", @@ -147,14 +148,14 @@ static void obexserver_session_class_init(OBEXServerSessionClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__UINT64, + g_cclosure_bt_marshal_VOID__UINT64, G_TYPE_NONE, 1, G_TYPE_UINT64); 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_bluez_marshal_VOID__STRING_STRING_UINT64, + g_cclosure_bt_marshal_VOID__STRING_STRING_UINT64, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64); } @@ -162,7 +163,7 @@ static void obexserver_session_init(OBEXServerSession *self) { self->priv = OBEXSERVER_SESSION_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); } static void obexserver_session_post_init(OBEXServerSession *self, const gchar *dbus_object_path) @@ -174,20 +175,20 @@ static void obexserver_session_post_init(OBEXServerSession *self, const gchar *d GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.openobex", dbus_object_path, "org.freedesktop.DBus.Introspectable"); + self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(system_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=\"", BLUEZ_DBUS_OBEXSERVER_SESSION_INTERFACE, "\">", NULL); + gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXSERVER_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\"", BLUEZ_DBUS_OBEXSERVER_SESSION_INTERFACE, dbus_object_path); + g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXSERVER_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(conn, "org.openobex", dbus_object_path, BLUEZ_DBUS_OBEXSERVER_SESSION_INTERFACE); + self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", dbus_object_path, OBEXSERVER_SESSION_DBUS_INTERFACE); /* DBus signals connection */ diff --git a/src/lib/obexserver_session.h b/src/lib/ods/obexserver_session.h index 53072cd..c1be188 100644 --- a/src/lib/obexserver_session.h +++ b/src/lib/ods/obexserver_session.h @@ -26,7 +26,7 @@ #include <glib-object.h> -#define BLUEZ_DBUS_OBEXSERVER_SESSION_INTERFACE "org.openobex.ServerSession" +#define OBEXSERVER_SESSION_DBUS_INTERFACE "org.openobex.ServerSession" /* * Type macros diff --git a/src/lib/obexsession.c b/src/lib/ods/obexsession.c index 368a622..2fde069 100644 --- a/src/lib/obexsession.c +++ b/src/lib/ods/obexsession.c @@ -28,8 +28,9 @@ #include <glib.h> #include <string.h> -#include "dbus-common.h" -#include "marshallers.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)) @@ -143,7 +144,7 @@ static void obexsession_class_init(OBEXSessionClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__STRING_STRING, + g_cclosure_bt_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); signals[TRANSFER_COMPLETED] = g_signal_new("TransferCompleted", @@ -157,14 +158,14 @@ static void obexsession_class_init(OBEXSessionClass *klass) G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - g_cclosure_bluez_marshal_VOID__UINT64, + g_cclosure_bt_marshal_VOID__UINT64, G_TYPE_NONE, 1, G_TYPE_UINT64); 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_bluez_marshal_VOID__STRING_STRING_UINT64, + g_cclosure_bt_marshal_VOID__STRING_STRING_UINT64, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64); } @@ -172,7 +173,7 @@ static void obexsession_init(OBEXSession *self) { self->priv = OBEXSESSION_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); } static void obexsession_post_init(OBEXSession *self, const gchar *dbus_object_path) @@ -184,20 +185,20 @@ static void obexsession_post_init(OBEXSession *self, const gchar *dbus_object_pa GError *error = NULL; /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(conn, "org.openobex", dbus_object_path, "org.freedesktop.DBus.Introspectable"); + self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(system_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=\"", BLUEZ_DBUS_OBEXSESSION_INTERFACE, "\">", 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\"", BLUEZ_DBUS_OBEXSESSION_INTERFACE, dbus_object_path); + 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(conn, "org.openobex", dbus_object_path, BLUEZ_DBUS_OBEXSESSION_INTERFACE); + self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", dbus_object_path, OBEXSESSION_DBUS_INTERFACE); /* DBus signals connection */ diff --git a/src/lib/obexsession.h b/src/lib/ods/obexsession.h index a42ff67..93289bf 100644 --- a/src/lib/obexsession.h +++ b/src/lib/ods/obexsession.h @@ -26,7 +26,7 @@ #include <glib-object.h> -#define BLUEZ_DBUS_OBEXSESSION_INTERFACE "org.openobex.Session" +#define OBEXSESSION_DBUS_INTERFACE "org.openobex.Session" /* * Type macros |