diff options
Diffstat (limited to 'src/lib/obexd')
-rw-r--r-- | src/lib/obexd/obexagent.c | 323 | ||||
-rw-r--r-- | src/lib/obexd/obexagent.h | 98 | ||||
-rw-r--r-- | src/lib/obexd/obexclient.c | 158 | ||||
-rw-r--r-- | src/lib/obexd/obexclient.h | 71 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_file_transfer.c | 240 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_file_transfer.h | 74 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_session.c | 288 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_session.h | 72 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_transfer.c | 280 | ||||
-rw-r--r-- | src/lib/obexd/obexclient_transfer.h | 71 | ||||
-rw-r--r-- | src/lib/obexd/obexmanager.c | 218 | ||||
-rw-r--r-- | src/lib/obexd/obexmanager.h | 67 | ||||
-rw-r--r-- | src/lib/obexd/obexsession.c | 223 | ||||
-rw-r--r-- | src/lib/obexd/obexsession.h | 68 | ||||
-rw-r--r-- | src/lib/obexd/obextransfer.c | 216 | ||||
-rw-r--r-- | src/lib/obexd/obextransfer.h | 67 |
16 files changed, 0 insertions, 2534 deletions
diff --git a/src/lib/obexd/obexagent.c b/src/lib/obexd/obexagent.c deleted file mode 100644 index a684154..0000000 --- a/src/lib/obexd/obexagent.c +++ /dev/null @@ -1,323 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <string.h> -#include <errno.h> - -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include "../dbus-common.h" -#include "../helpers.h" - -#include "obexclient_transfer.h" -#include "obexagent.h" - -#define OBEXAGENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXAGENT_TYPE, OBEXAgentPrivate)) - -struct _OBEXAgentPrivate { - /* Unused */ - DBusGProxy *proxy; - - /* Properties */ - gchar *root_folder; -}; - -G_DEFINE_TYPE(OBEXAgent, obexagent, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_ROOT_FOLDER, /* readwrite, construct only */ -}; - -static void _obexagent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _obexagent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -enum { - OBEXAGENT_RELEASED, - - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0}; - -static void obexagent_dispose(GObject *gobject) -{ - OBEXAgent *self = OBEXAGENT(gobject); - - dbus_g_connection_unregister_g_object(session_conn, gobject); - - /* Proxy free */ - //g_object_unref(self->priv->proxy); - - /* Properties free */ - g_free(self->priv->root_folder); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexagent_parent_class)->dispose(gobject); -} - -static void obexagent_class_init(OBEXAgentClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexagent_dispose; - - g_type_class_add_private(klass, sizeof(OBEXAgentPrivate)); - - /* Signals registation */ - signals[OBEXAGENT_RELEASED] = g_signal_new("AgentReleased", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _obexagent_get_property; - gobject_class->set_property = _obexagent_set_property; - - /* string RootFolder [readwrite, construct only] */ - pspec = g_param_spec_string("RootFolder", "root_folder", "Root folder location", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_ROOT_FOLDER, pspec); -} - -static void obexagent_init(OBEXAgent *self) -{ - self->priv = OBEXAGENT_GET_PRIVATE(self); - - g_assert(session_conn != NULL); - - /* Properties init */ - self->priv->root_folder = NULL; - - dbus_g_connection_register_g_object(session_conn, OBEXAGENT_DBUS_PATH, G_OBJECT(self)); - g_print("OBEXAgent registered\n"); -} - -static void _obexagent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - OBEXAgent *self = OBEXAGENT(object); - - switch (property_id) { - case PROP_ROOT_FOLDER: - g_value_set_string(value, self->priv->root_folder); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _obexagent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - OBEXAgent *self = OBEXAGENT(object); - - switch (property_id) { - case PROP_ROOT_FOLDER: - self->priv->root_folder = g_value_dup_string(value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -/* Methods */ - -/* Server API */ -gboolean obexagent_authorize(OBEXAgent *self, const gchar *transfer, const gchar *bt_address, const gchar *name, const gchar *type, gint length, gint time, gchar **ret, GError **error) -{ - g_assert(self->priv->root_folder != NULL && strlen(self->priv->root_folder) > 0); - - *ret = NULL; - g_print("[ObjectPush Request]\n"); - g_print(" Address: %s\n", bt_address); - g_print(" Name: %s\n", name); - if (type && strlen(type)) { - g_print(" Type: %s\n", type); - } - g_print(" Length: %d bytes\n", length); - /*if (time) { - g_print(" Time: %d\n", time); - }*/ - - gchar yn[4] = {0,}; - g_print("Accept (yes/no)? "); - errno = 0; - if (scanf("%3s", yn) == EOF && errno) { - g_warning("%s\n", strerror(errno)); - } - if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) { - if (!g_path_is_absolute(self->priv->root_folder)) { - gchar *abs_path = get_absolute_path(self->priv->root_folder); - *ret = g_build_filename(abs_path, name, NULL); - g_free(abs_path); - } else { - *ret = g_build_filename(self->priv->root_folder, name, NULL); - } - - return TRUE; - } else { - // TODO: Fix error code - if (error) - *error = g_error_new(g_quark_from_static_string("org.openobex.Error.Rejected"), 0, "File transfer rejected"); - return FALSE; - } -} - -gboolean obexagent_cancel(OBEXAgent *self, GError **error) -{ - g_print("Request cancelled\n"); - return TRUE; -} - -/* Client API */ -static gboolean update_progress = FALSE; - -gboolean obexagent_release(OBEXAgent *self, GError **error) -{ - if (update_progress) { - g_print("\n"); - update_progress = FALSE; - } - - g_print("OBEXAgent released\n"); - - g_signal_emit(self, signals[OBEXAGENT_RELEASED], 0); - - return TRUE; -} - -gboolean obexagent_request(OBEXAgent *self, const gchar *transfer, gchar **ret, GError **error) -{ - *ret = NULL; - - if (intf_supported(OBEXC_DBUS_NAME, transfer, OBEXCLIENT_TRANSFER_DBUS_INTERFACE)) { - OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); - g_print("[Transfer Request]\n"); - g_print(" Name: %s\n", obexclient_transfer_get_name(transfer_t)); - g_print(" Size: %llu bytes\n", obexclient_transfer_get_size(transfer_t)); - g_print(" Filename: %s\n", obexclient_transfer_get_filename(transfer_t)); - g_object_unref(transfer_t); - - gchar yn[4] = {0,}; - g_print("Accept (yes/no)? "); - errno = 0; - if (scanf("%3s", yn) == EOF && errno) { - g_warning("%s\n", strerror(errno)); - } - if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) { - return TRUE; - } else { - // TODO: Fix error code - if (error) - *error = g_error_new(g_quark_from_static_string("org.openobex.Error.Rejected"), 0, "File transfer rejected"); - return FALSE; - } - } else { - g_print("Error: Unknown transfer request\n"); - // TODO: Fix error code - if (error) - *error = g_error_new(g_quark_from_static_string("org.openobex.Error.Rejected"), 0, "File transfer rejected"); - return FALSE; - } - - return TRUE; -} - -gboolean obexagent_progress(OBEXAgent *self, const gchar *transfer, guint64 transferred, GError **error) -{ - if (intf_supported(OBEXC_DBUS_NAME, transfer, OBEXCLIENT_TRANSFER_DBUS_INTERFACE)) { - OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); - guint64 total = obexclient_transfer_get_size(transfer_t); - - guint pp = (transferred / (gfloat) total)*100; - - if (!update_progress) { - g_print("[Transfer#%s] Progress: %3u%%", obexclient_transfer_get_name(transfer_t), pp); - update_progress = TRUE; - } else { - g_print("\b\b\b\b%3u%%", pp); - } - - if (pp == 100) { - g_print("\n"); - update_progress = FALSE; - } - - g_object_unref(transfer_t); - } - - return TRUE; -} - -gboolean obexagent_complete(OBEXAgent *self, const gchar *transfer, GError **error) -{ - if (update_progress) { - g_print("\n"); - update_progress = FALSE; - } - - if (intf_supported(OBEXC_DBUS_NAME, transfer, OBEXCLIENT_TRANSFER_DBUS_INTERFACE)) { - OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); - g_print("[Transfer#%s] Completed\n", obexclient_transfer_get_name(transfer_t)); - g_object_unref(transfer_t); - } - - return TRUE; -} - -gboolean obexagent_error(OBEXAgent *self, const gchar *transfer, const gchar *message, GError **error) -{ - if (update_progress) { - g_print("\n"); - update_progress = FALSE; - } - - g_print("[Transfer] Error: %s\n", message); - - /* - * Transfer interface does not exists - * Code commented - * - if (intf_supported(OBEXC_DBUS_NAME, transfer, OBEXCLIENT_TRANSFER_DBUS_INTERFACE)) { - OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); - g_print("[Transfer#%s] Error: %s\n", obexclient_transfer_get_name(transfer_t), message); - g_object_unref(transfer_t); - } - */ - - return TRUE; -} - diff --git a/src/lib/obexd/obexagent.h b/src/lib/obexd/obexagent.h deleted file mode 100644 index b94fb2c..0000000 --- a/src/lib/obexd/obexagent.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXAGENT_H -#define __OBEXAGENT_H - -#include <glib-object.h> -#include <dbus/dbus-glib.h> - -#include "../marshallers.h" - -#define OBEXAGENT_DBUS_PATH "/ObexAgent" - -/* - * Type macros - */ -#define OBEXAGENT_TYPE (obexagent_get_type()) -#define OBEXAGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXAGENT_TYPE, OBEXAgent)) -#define OBEXAGENT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXAGENT_TYPE)) -#define OBEXAGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXAGENT_TYPE, OBEXAgentClass)) -#define OBEXAGENT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXAGENT_TYPE)) -#define OBEXAGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXAGENT_TYPE, OBEXAgentClass)) - -typedef struct _OBEXAgent OBEXAgent; -typedef struct _OBEXAgentClass OBEXAgentClass; -typedef struct _OBEXAgentPrivate OBEXAgentPrivate; - -struct _OBEXAgent { - GObject parent_instance; - - /*< private >*/ - OBEXAgentPrivate *priv; -}; - -struct _OBEXAgentClass { - GObjectClass parent_class; -}; - -/* used by OBEXAGENT_TYPE */ -GType obexagent_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ - -/* Server API */ -gboolean obexagent_authorize(OBEXAgent *self, const gchar *transfer, const gchar *bt_address, const gchar *name, const gchar *type, gint length, gint time, gchar **ret, GError **error); -gboolean obexagent_cancel(OBEXAgent *self, GError **error); - -/* Client API */ -gboolean obexagent_release(OBEXAgent *self, GError **error); -gboolean obexagent_request(OBEXAgent *self, const gchar *transfer, gchar **ret, GError **error); -gboolean obexagent_progress(OBEXAgent *self, const gchar *transfer, guint64 transferred, GError **error); -gboolean obexagent_complete(OBEXAgent *self, const gchar *transfer, GError **error); -gboolean obexagent_error(OBEXAgent *self, const gchar *transfer, const gchar *message, GError **error); - -/* Glue code */ -static const DBusGMethodInfo dbus_glib_obexagent_methods[] = { - { (GCallback) obexagent_authorize, g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_POINTER_POINTER, 0}, - { (GCallback) obexagent_cancel, g_cclosure_bt_marshal_BOOLEAN__POINTER, 111}, - { (GCallback) obexagent_release, g_cclosure_bt_marshal_BOOLEAN__POINTER, 140}, - { (GCallback) obexagent_request, g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER_POINTER, 170}, - { (GCallback) obexagent_progress, g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT64_POINTER, 226}, - { (GCallback) obexagent_complete, g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER, 286}, - { (GCallback) obexagent_error, g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_POINTER, 330}, -}; - -static const DBusGObjectInfo dbus_glib_obexagent_object_info = { - 0, - dbus_glib_obexagent_methods, - 7, - "org.openobex.Agent\0Authorize\0S\0transfer\0I\0o\0bt_address\0I\0s\0name\0I\0s\0type\0I\0s\0length\0I\0i\0time\0I\0i\0arg6\0O\0F\0N\0s\0\0org.openobex.Agent\0Cancel\0S\0\0org.openobex.Agent\0Release\0S\0\0org.openobex.Agent\0Request\0S\0transfer\0I\0o\0arg1\0O\0F\0N\0s\0\0org.openobex.Agent\0Progress\0S\0transfer\0I\0o\0transferred\0I\0t\0\0org.openobex.Agent\0Complete\0S\0transfer\0I\0o\0\0org.openobex.Agent\0Error\0S\0transfer\0I\0o\0message\0I\0s\0\0\0", - "\0", - "\0" -}; - -#endif /* __OBEXAGENT_H */ - diff --git a/src/lib/obexd/obexclient.c b/src/lib/obexd/obexclient.c deleted file mode 100644 index d8cfa78..0000000 --- a/src/lib/obexd/obexclient.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obexclient.h" - -#define OBEXCLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXCLIENT_TYPE, OBEXClientPrivate)) - -struct _OBEXClientPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; -}; - -G_DEFINE_TYPE(OBEXClient, obexclient, G_TYPE_OBJECT); - -static void obexclient_dispose(GObject *gobject) -{ - OBEXClient *self = OBEXCLIENT(gobject); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexclient_parent_class)->dispose(gobject); -} - -static void obexclient_class_init(OBEXClientClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexclient_dispose; - - g_type_class_add_private(klass, sizeof(OBEXClientPrivate)); -} - -static void obexclient_init(OBEXClient *self) -{ - self->priv = OBEXCLIENT_GET_PRIVATE(self); - - /* DBusGProxy init */ - self->priv->dbus_g_proxy = NULL; - - g_assert(session_conn != NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", OBEXCLIENT_DBUS_PATH, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXCLIENT_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXCLIENT_DBUS_INTERFACE, OBEXCLIENT_DBUS_PATH); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", OBEXCLIENT_DBUS_PATH, OBEXCLIENT_DBUS_INTERFACE); -} - -/* Methods */ - -/* object CreateSession(dict device) */ -gchar *obexclient_create_session(OBEXClient *self, const GHashTable *device, GError **error) -{ - g_assert(OBEXCLIENT_IS(self)); - - gchar *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "CreateSession", error, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, device, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void ExchangeBusinessCards(dict device, string clientfile, string file) */ -void obexclient_exchange_business_cards(OBEXClient *self, const GHashTable *device, const gchar *clientfile, const gchar *file, GError **error) -{ - g_assert(OBEXCLIENT_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "ExchangeBusinessCards", error, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, device, G_TYPE_STRING, clientfile, G_TYPE_STRING, file, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* string GetCapabilities(dict device) */ -gchar *obexclient_get_capabilities(OBEXClient *self, const GHashTable *device, GError **error) -{ - g_assert(OBEXCLIENT_IS(self)); - - gchar *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetCapabilities", error, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, device, G_TYPE_INVALID, G_TYPE_STRING, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void PullBusinessCard(dict device, string file) */ -void obexclient_pull_business_card(OBEXClient *self, const GHashTable *device, const gchar *file, GError **error) -{ - g_assert(OBEXCLIENT_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "PullBusinessCard", error, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, device, G_TYPE_STRING, file, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void RemoveSession(object session) */ -void obexclient_remove_session(OBEXClient *self, const gchar *session, GError **error) -{ - g_assert(OBEXCLIENT_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "RemoveSession", error, DBUS_TYPE_G_OBJECT_PATH, session, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void SendFiles(dict device, array{string} files, object agent) */ -void obexclient_send_files(OBEXClient *self, const GHashTable *device, const gchar **files, const gchar *agent, GError **error) -{ - g_assert(OBEXCLIENT_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "SendFiles", error, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, device, G_TYPE_STRV, files, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID); -} - diff --git a/src/lib/obexd/obexclient.h b/src/lib/obexd/obexclient.h deleted file mode 100644 index d999b76..0000000 --- a/src/lib/obexd/obexclient.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXCLIENT_H -#define __OBEXCLIENT_H - -#include <glib-object.h> - -#define OBEXCLIENT_DBUS_PATH "/" -#define OBEXCLIENT_DBUS_INTERFACE "org.openobex.Client" - -/* - * Type macros - */ -#define OBEXCLIENT_TYPE (obexclient_get_type()) -#define OBEXCLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXCLIENT_TYPE, OBEXClient)) -#define OBEXCLIENT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXCLIENT_TYPE)) -#define OBEXCLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXCLIENT_TYPE, OBEXClientClass)) -#define OBEXCLIENT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXCLIENT_TYPE)) -#define OBEXCLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXCLIENT_TYPE, OBEXClientClass)) - -typedef struct _OBEXClient OBEXClient; -typedef struct _OBEXClientClass OBEXClientClass; -typedef struct _OBEXClientPrivate OBEXClientPrivate; - -struct _OBEXClient { - GObject parent_instance; - - /*< private >*/ - OBEXClientPrivate *priv; -}; - -struct _OBEXClientClass { - GObjectClass parent_class; -}; - -/* used by OBEXCLIENT_TYPE */ -GType obexclient_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -gchar *obexclient_create_session(OBEXClient *self, const GHashTable *device, GError **error); -void obexclient_exchange_business_cards(OBEXClient *self, const GHashTable *device, const gchar *clientfile, const gchar *file, GError **error); -gchar *obexclient_get_capabilities(OBEXClient *self, const GHashTable *device, GError **error); -void obexclient_pull_business_card(OBEXClient *self, const GHashTable *device, const gchar *file, GError **error); -void obexclient_remove_session(OBEXClient *self, const gchar *session, GError **error); -void obexclient_send_files(OBEXClient *self, const GHashTable *device, const gchar **files, const gchar *agent, GError **error); - -#endif /* __OBEXCLIENT_H */ - diff --git a/src/lib/obexd/obexclient_file_transfer.c b/src/lib/obexd/obexclient_file_transfer.c deleted file mode 100644 index 05fa36d..0000000 --- a/src/lib/obexd/obexclient_file_transfer.c +++ /dev/null @@ -1,240 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obexclient_file_transfer.h" - -#define OBEXCLIENT_FILE_TRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXCLIENT_FILE_TRANSFER_TYPE, OBEXClientFileTransferPrivate)) - -struct _OBEXClientFileTransferPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; -}; - -G_DEFINE_TYPE(OBEXClientFileTransfer, obexclient_file_transfer, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH /* readwrite, construct only */ -}; - -static void _obexclient_file_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _obexclient_file_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -static void obexclient_file_transfer_dispose(GObject *gobject) -{ - OBEXClientFileTransfer *self = OBEXCLIENT_FILE_TRANSFER(gobject); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexclient_file_transfer_parent_class)->dispose(gobject); -} - -static void obexclient_file_transfer_class_init(OBEXClientFileTransferClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexclient_file_transfer_dispose; - - g_type_class_add_private(klass, sizeof(OBEXClientFileTransferPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _obexclient_file_transfer_get_property; - gobject_class->set_property = _obexclient_file_transfer_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); -} - -static void obexclient_file_transfer_init(OBEXClientFileTransfer *self) -{ - self->priv = OBEXCLIENT_FILE_TRANSFER_GET_PRIVATE(self); - - /* DBusGProxy init */ - self->priv->dbus_g_proxy = NULL; - - g_assert(session_conn != NULL); -} - -static void obexclient_file_transfer_post_init(OBEXClientFileTransfer *self, const gchar *dbus_object_path) -{ - g_assert(dbus_object_path != NULL); - g_assert(strlen(dbus_object_path) > 0); - g_assert(self->priv->dbus_g_proxy == NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", dbus_object_path, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXCLIENT_FILE_TRANSFER_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXCLIENT_FILE_TRANSFER_DBUS_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", dbus_object_path, OBEXCLIENT_FILE_TRANSFER_DBUS_INTERFACE); -} - -static void _obexclient_file_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - OBEXClientFileTransfer *self = OBEXCLIENT_FILE_TRANSFER(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, obexclient_file_transfer_get_dbus_object_path(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _obexclient_file_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - OBEXClientFileTransfer *self = OBEXCLIENT_FILE_TRANSFER(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - obexclient_file_transfer_post_init(self, g_value_get_string(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -/* Methods */ - -/* void ChangeFolder(string folder) */ -void obexclient_file_transfer_change_folder(OBEXClientFileTransfer *self, const gchar *folder, GError **error) -{ - g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "ChangeFolder", error, G_TYPE_STRING, folder, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void CopyFile(string sourcefile, string targetfile) */ -void obexclient_file_transfer_copy_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error) -{ - g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "CopyFile", error, G_TYPE_STRING, sourcefile, G_TYPE_STRING, targetfile, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void CreateFolder(string folder) */ -void obexclient_file_transfer_create_folder(OBEXClientFileTransfer *self, const gchar *folder, GError **error) -{ - g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "CreateFolder", error, G_TYPE_STRING, folder, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void Delete(string file) */ -void obexclient_file_transfer_delete(OBEXClientFileTransfer *self, const gchar *file, GError **error) -{ - g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Delete", error, G_TYPE_STRING, file, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void GetFile(string targetfile, string sourcefile) */ -void obexclient_file_transfer_get_file(OBEXClientFileTransfer *self, const gchar *targetfile, const gchar *sourcefile, GError **error) -{ - g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetFile", error, G_TYPE_STRING, targetfile, G_TYPE_STRING, sourcefile, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* array{dict} ListFolder() */ -GPtrArray *obexclient_file_transfer_list_folder(OBEXClientFileTransfer *self, GError **error) -{ - g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self)); - - GPtrArray *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "ListFolder", error, G_TYPE_INVALID, DBUS_TYPE_G_HASH_TABLE_ARRAY, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void MoveFile(string sourcefile, string targetfile) */ -void obexclient_file_transfer_move_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error) -{ - g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "MoveFile", error, G_TYPE_STRING, sourcefile, G_TYPE_STRING, targetfile, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void PutFile(string sourcefile, string targetfile) */ -void obexclient_file_transfer_put_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error) -{ - g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "PutFile", error, G_TYPE_STRING, sourcefile, G_TYPE_STRING, targetfile, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* Properties access methods */ -const gchar *obexclient_file_transfer_get_dbus_object_path(OBEXClientFileTransfer *self) -{ - g_assert(OBEXCLIENT_FILE_TRANSFER_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - diff --git a/src/lib/obexd/obexclient_file_transfer.h b/src/lib/obexd/obexclient_file_transfer.h deleted file mode 100644 index 5e796b2..0000000 --- a/src/lib/obexd/obexclient_file_transfer.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXCLIENT_FILE_TRANSFER_H -#define __OBEXCLIENT_FILE_TRANSFER_H - -#include <glib-object.h> - -#define OBEXCLIENT_FILE_TRANSFER_DBUS_INTERFACE "org.openobex.FileTransfer" - -/* - * Type macros - */ -#define OBEXCLIENT_FILE_TRANSFER_TYPE (obexclient_file_transfer_get_type()) -#define OBEXCLIENT_FILE_TRANSFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXCLIENT_FILE_TRANSFER_TYPE, OBEXClientFileTransfer)) -#define OBEXCLIENT_FILE_TRANSFER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXCLIENT_FILE_TRANSFER_TYPE)) -#define OBEXCLIENT_FILE_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXCLIENT_FILE_TRANSFER_TYPE, OBEXClientFileTransferClass)) -#define OBEXCLIENT_FILE_TRANSFER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXCLIENT_FILE_TRANSFER_TYPE)) -#define OBEXCLIENT_FILE_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXCLIENT_FILE_TRANSFER_TYPE, OBEXClientFileTransferClass)) - -typedef struct _OBEXClientFileTransfer OBEXClientFileTransfer; -typedef struct _OBEXClientFileTransferClass OBEXClientFileTransferClass; -typedef struct _OBEXClientFileTransferPrivate OBEXClientFileTransferPrivate; - -struct _OBEXClientFileTransfer { - GObject parent_instance; - - /*< private >*/ - OBEXClientFileTransferPrivate *priv; -}; - -struct _OBEXClientFileTransferClass { - GObjectClass parent_class; -}; - -/* used by OBEXCLIENT_FILE_TRANSFER_TYPE */ -GType obexclient_file_transfer_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -void obexclient_file_transfer_change_folder(OBEXClientFileTransfer *self, const gchar *folder, GError **error); -void obexclient_file_transfer_copy_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error); -void obexclient_file_transfer_create_folder(OBEXClientFileTransfer *self, const gchar *folder, GError **error); -void obexclient_file_transfer_delete(OBEXClientFileTransfer *self, const gchar *file, GError **error); -void obexclient_file_transfer_get_file(OBEXClientFileTransfer *self, const gchar *targetfile, const gchar *sourcefile, GError **error); -GPtrArray *obexclient_file_transfer_list_folder(OBEXClientFileTransfer *self, GError **error); -void obexclient_file_transfer_move_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error); -void obexclient_file_transfer_put_file(OBEXClientFileTransfer *self, const gchar *sourcefile, const gchar *targetfile, GError **error); - -const gchar *obexclient_file_transfer_get_dbus_object_path(OBEXClientFileTransfer *self); - -#endif /* __OBEXCLIENT_FILE_TRANSFER_H */ - diff --git a/src/lib/obexd/obexclient_session.c b/src/lib/obexd/obexclient_session.c deleted file mode 100644 index a5b52f8..0000000 --- a/src/lib/obexd/obexclient_session.c +++ /dev/null @@ -1,288 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obexclient_session.h" - -#define OBEXCLIENT_SESSION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXCLIENT_SESSION_TYPE, OBEXClientSessionPrivate)) - -struct _OBEXClientSessionPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; - - /* Properties */ - guchar channel; - gchar *destination; - gchar *source; -}; - -G_DEFINE_TYPE(OBEXClientSession, obexclient_session, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */ - PROP_CHANNEL, /* readonly */ - PROP_DESTINATION, /* readonly */ - PROP_SOURCE /* readonly */ -}; - -static void _obexclient_session_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _obexclient_session_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -static void obexclient_session_dispose(GObject *gobject) -{ - OBEXClientSession *self = OBEXCLIENT_SESSION(gobject); - - /* Properties free */ - g_free(self->priv->destination); - g_free(self->priv->source); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexclient_session_parent_class)->dispose(gobject); -} - -static void obexclient_session_class_init(OBEXClientSessionClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexclient_session_dispose; - - g_type_class_add_private(klass, sizeof(OBEXClientSessionPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _obexclient_session_get_property; - gobject_class->set_property = _obexclient_session_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); - - /* byte Channel [readonly] */ - pspec = g_param_spec_uchar("Channel", NULL, NULL, 0, 0xFF, 0, G_PARAM_READABLE); - g_object_class_install_property(gobject_class, PROP_CHANNEL, pspec); - - /* string Destination [readonly] */ - pspec = g_param_spec_string("Destination", NULL, NULL, NULL, G_PARAM_READABLE); - g_object_class_install_property(gobject_class, PROP_DESTINATION, pspec); - - /* string Source [readonly] */ - pspec = g_param_spec_string("Source", NULL, NULL, NULL, G_PARAM_READABLE); - g_object_class_install_property(gobject_class, PROP_SOURCE, pspec); -} - -static void obexclient_session_init(OBEXClientSession *self) -{ - self->priv = OBEXCLIENT_SESSION_GET_PRIVATE(self); - - /* DBusGProxy init */ - self->priv->dbus_g_proxy = NULL; - - g_assert(session_conn != NULL); -} - -static void obexclient_session_post_init(OBEXClientSession *self, const gchar *dbus_object_path) -{ - g_assert(dbus_object_path != NULL); - g_assert(strlen(dbus_object_path) > 0); - g_assert(self->priv->dbus_g_proxy == NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", dbus_object_path, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXCLIENT_SESSION_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXCLIENT_SESSION_DBUS_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", dbus_object_path, OBEXCLIENT_SESSION_DBUS_INTERFACE); - - /* Properties init */ - GHashTable *properties = obexclient_session_get_properties(self, &error); - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - g_assert(properties != NULL); - - /* byte Channel [readonly] */ - if (g_hash_table_lookup(properties, "Channel")) { - self->priv->channel = g_value_get_uchar(g_hash_table_lookup(properties, "Channel")); - } else { - self->priv->channel = 0; - } - - /* string Destination [readonly] */ - if (g_hash_table_lookup(properties, "Destination")) { - self->priv->destination = g_value_dup_string(g_hash_table_lookup(properties, "Destination")); - } else { - self->priv->destination = g_strdup("undefined"); - } - - /* string Source [readonly] */ - if (g_hash_table_lookup(properties, "Source")) { - self->priv->source = g_value_dup_string(g_hash_table_lookup(properties, "Source")); - } else { - self->priv->source = g_strdup("undefined"); - } - - g_hash_table_unref(properties); -} - -static void _obexclient_session_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - OBEXClientSession *self = OBEXCLIENT_SESSION(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, obexclient_session_get_dbus_object_path(self)); - break; - - case PROP_CHANNEL: - g_value_set_uchar(value, obexclient_session_get_channel(self)); - break; - - case PROP_DESTINATION: - g_value_set_string(value, obexclient_session_get_destination(self)); - break; - - case PROP_SOURCE: - g_value_set_string(value, obexclient_session_get_source(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _obexclient_session_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - OBEXClientSession *self = OBEXCLIENT_SESSION(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - obexclient_session_post_init(self, g_value_get_string(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -/* Methods */ - -/* void AssignAgent(object agent) */ -void obexclient_session_assign_agent(OBEXClientSession *self, const gchar *agent, GError **error) -{ - g_assert(OBEXCLIENT_SESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "AssignAgent", error, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* dict GetProperties() */ -GHashTable *obexclient_session_get_properties(OBEXClientSession *self, GError **error) -{ - g_assert(OBEXCLIENT_SESSION_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetProperties", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void ReleaseAgent(object agent) */ -void obexclient_session_release_agent(OBEXClientSession *self, const gchar *agent, GError **error) -{ - g_assert(OBEXCLIENT_SESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "ReleaseAgent", error, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* Properties access methods */ -const gchar *obexclient_session_get_dbus_object_path(OBEXClientSession *self) -{ - g_assert(OBEXCLIENT_SESSION_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - -const guchar obexclient_session_get_channel(OBEXClientSession *self) -{ - g_assert(OBEXCLIENT_SESSION_IS(self)); - - return self->priv->channel; -} - -const gchar *obexclient_session_get_destination(OBEXClientSession *self) -{ - g_assert(OBEXCLIENT_SESSION_IS(self)); - - return self->priv->destination; -} - -const gchar *obexclient_session_get_source(OBEXClientSession *self) -{ - g_assert(OBEXCLIENT_SESSION_IS(self)); - - return self->priv->source; -} - diff --git a/src/lib/obexd/obexclient_session.h b/src/lib/obexd/obexclient_session.h deleted file mode 100644 index 87af06d..0000000 --- a/src/lib/obexd/obexclient_session.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXCLIENT_SESSION_H -#define __OBEXCLIENT_SESSION_H - -#include <glib-object.h> - -#define OBEXCLIENT_SESSION_DBUS_INTERFACE "org.openobex.Session" - -/* - * Type macros - */ -#define OBEXCLIENT_SESSION_TYPE (obexclient_session_get_type()) -#define OBEXCLIENT_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXCLIENT_SESSION_TYPE, OBEXClientSession)) -#define OBEXCLIENT_SESSION_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXCLIENT_SESSION_TYPE)) -#define OBEXCLIENT_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXCLIENT_SESSION_TYPE, OBEXClientSessionClass)) -#define OBEXCLIENT_SESSION_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXCLIENT_SESSION_TYPE)) -#define OBEXCLIENT_SESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXCLIENT_SESSION_TYPE, OBEXClientSessionClass)) - -typedef struct _OBEXClientSession OBEXClientSession; -typedef struct _OBEXClientSessionClass OBEXClientSessionClass; -typedef struct _OBEXClientSessionPrivate OBEXClientSessionPrivate; - -struct _OBEXClientSession { - GObject parent_instance; - - /*< private >*/ - OBEXClientSessionPrivate *priv; -}; - -struct _OBEXClientSessionClass { - GObjectClass parent_class; -}; - -/* used by OBEXCLIENT_SESSION_TYPE */ -GType obexclient_session_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -void obexclient_session_assign_agent(OBEXClientSession *self, const gchar *agent, GError **error); -GHashTable *obexclient_session_get_properties(OBEXClientSession *self, GError **error); -void obexclient_session_release_agent(OBEXClientSession *self, const gchar *agent, GError **error); - -const gchar *obexclient_session_get_dbus_object_path(OBEXClientSession *self); -const guchar obexclient_session_get_channel(OBEXClientSession *self); -const gchar *obexclient_session_get_destination(OBEXClientSession *self); -const gchar *obexclient_session_get_source(OBEXClientSession *self); - -#endif /* __OBEXCLIENT_SESSION_H */ - diff --git a/src/lib/obexd/obexclient_transfer.c b/src/lib/obexd/obexclient_transfer.c deleted file mode 100644 index 68c4bf3..0000000 --- a/src/lib/obexd/obexclient_transfer.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obexclient_transfer.h" - -#define OBEXCLIENT_TRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXCLIENT_TRANSFER_TYPE, OBEXClientTransferPrivate)) - -struct _OBEXClientTransferPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; - - /* Properties */ - gchar *filename; - gchar *name; - guint64 size; -}; - -G_DEFINE_TYPE(OBEXClientTransfer, obexclient_transfer, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */ - PROP_FILENAME, /* readonly */ - PROP_NAME, /* readonly */ - PROP_SIZE /* readonly */ -}; - -static void _obexclient_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _obexclient_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -static void obexclient_transfer_dispose(GObject *gobject) -{ - OBEXClientTransfer *self = OBEXCLIENT_TRANSFER(gobject); - - /* Properties free */ - g_free(self->priv->filename); - g_free(self->priv->name); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexclient_transfer_parent_class)->dispose(gobject); -} - -static void obexclient_transfer_class_init(OBEXClientTransferClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexclient_transfer_dispose; - - g_type_class_add_private(klass, sizeof(OBEXClientTransferPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _obexclient_transfer_get_property; - gobject_class->set_property = _obexclient_transfer_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); - - /* string Filename [readonly] */ - pspec = g_param_spec_string("Filename", NULL, NULL, NULL, G_PARAM_READABLE); - g_object_class_install_property(gobject_class, PROP_FILENAME, pspec); - - /* string Name [readonly] */ - pspec = g_param_spec_string("Name", NULL, NULL, NULL, G_PARAM_READABLE); - g_object_class_install_property(gobject_class, PROP_NAME, pspec); - - /* uint64 Size [readonly] */ - pspec = g_param_spec_uint64("Size", NULL, NULL, 0, 0xFFFFFFFFFFFFFFFF, 0, G_PARAM_READABLE); - g_object_class_install_property(gobject_class, PROP_SIZE, pspec); -} - -static void obexclient_transfer_init(OBEXClientTransfer *self) -{ - self->priv = OBEXCLIENT_TRANSFER_GET_PRIVATE(self); - - /* DBusGProxy init */ - self->priv->dbus_g_proxy = NULL; - - g_assert(session_conn != NULL); -} - -static void obexclient_transfer_post_init(OBEXClientTransfer *self, const gchar *dbus_object_path) -{ - g_assert(dbus_object_path != NULL); - g_assert(strlen(dbus_object_path) > 0); - g_assert(self->priv->dbus_g_proxy == NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", dbus_object_path, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXCLIENT_TRANSFER_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXCLIENT_TRANSFER_DBUS_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex.client", dbus_object_path, OBEXCLIENT_TRANSFER_DBUS_INTERFACE); - - /* Properties init */ - GHashTable *properties = obexclient_transfer_get_properties(self, &error); - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - g_assert(properties != NULL); - - /* string Filename [readonly] */ - if (g_hash_table_lookup(properties, "Filename")) { - self->priv->filename = g_value_dup_string(g_hash_table_lookup(properties, "Filename")); - } else { - self->priv->filename = g_strdup("undefined"); - } - - /* string Name [readonly] */ - if (g_hash_table_lookup(properties, "Name")) { - self->priv->name = g_value_dup_string(g_hash_table_lookup(properties, "Name")); - } else { - self->priv->name = g_strdup("undefined"); - } - - /* uint64 Size [readonly] */ - if (g_hash_table_lookup(properties, "Size")) { - self->priv->size = g_value_get_uint64(g_hash_table_lookup(properties, "Size")); - } else { - self->priv->size = 0; - } - - g_hash_table_unref(properties); -} - -static void _obexclient_transfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - OBEXClientTransfer *self = OBEXCLIENT_TRANSFER(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, obexclient_transfer_get_dbus_object_path(self)); - break; - - case PROP_FILENAME: - g_value_set_string(value, obexclient_transfer_get_filename(self)); - break; - - case PROP_NAME: - g_value_set_string(value, obexclient_transfer_get_name(self)); - break; - - case PROP_SIZE: - g_value_set_uint64(value, obexclient_transfer_get_size(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _obexclient_transfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - OBEXClientTransfer *self = OBEXCLIENT_TRANSFER(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - obexclient_transfer_post_init(self, g_value_get_string(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -/* Methods */ - -/* void Cancel() */ -void obexclient_transfer_cancel(OBEXClientTransfer *self, GError **error) -{ - g_assert(OBEXCLIENT_TRANSFER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Cancel", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* dict GetProperties() */ -GHashTable *obexclient_transfer_get_properties(OBEXClientTransfer *self, GError **error) -{ - g_assert(OBEXCLIENT_TRANSFER_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetProperties", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* Properties access methods */ -const gchar *obexclient_transfer_get_dbus_object_path(OBEXClientTransfer *self) -{ - g_assert(OBEXCLIENT_TRANSFER_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - -const gchar *obexclient_transfer_get_filename(OBEXClientTransfer *self) -{ - g_assert(OBEXCLIENT_TRANSFER_IS(self)); - - return self->priv->filename; -} - -const gchar *obexclient_transfer_get_name(OBEXClientTransfer *self) -{ - g_assert(OBEXCLIENT_TRANSFER_IS(self)); - - return self->priv->name; -} - -const guint64 obexclient_transfer_get_size(OBEXClientTransfer *self) -{ - g_assert(OBEXCLIENT_TRANSFER_IS(self)); - - return self->priv->size; -} - diff --git a/src/lib/obexd/obexclient_transfer.h b/src/lib/obexd/obexclient_transfer.h deleted file mode 100644 index f84fd69..0000000 --- a/src/lib/obexd/obexclient_transfer.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXCLIENT_TRANSFER_H -#define __OBEXCLIENT_TRANSFER_H - -#include <glib-object.h> - -#define OBEXCLIENT_TRANSFER_DBUS_INTERFACE "org.openobex.Transfer" - -/* - * Type macros - */ -#define OBEXCLIENT_TRANSFER_TYPE (obexclient_transfer_get_type()) -#define OBEXCLIENT_TRANSFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXCLIENT_TRANSFER_TYPE, OBEXClientTransfer)) -#define OBEXCLIENT_TRANSFER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXCLIENT_TRANSFER_TYPE)) -#define OBEXCLIENT_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXCLIENT_TRANSFER_TYPE, OBEXClientTransferClass)) -#define OBEXCLIENT_TRANSFER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXCLIENT_TRANSFER_TYPE)) -#define OBEXCLIENT_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXCLIENT_TRANSFER_TYPE, OBEXClientTransferClass)) - -typedef struct _OBEXClientTransfer OBEXClientTransfer; -typedef struct _OBEXClientTransferClass OBEXClientTransferClass; -typedef struct _OBEXClientTransferPrivate OBEXClientTransferPrivate; - -struct _OBEXClientTransfer { - GObject parent_instance; - - /*< private >*/ - OBEXClientTransferPrivate *priv; -}; - -struct _OBEXClientTransferClass { - GObjectClass parent_class; -}; - -/* used by OBEXCLIENT_TRANSFER_TYPE */ -GType obexclient_transfer_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -void obexclient_transfer_cancel(OBEXClientTransfer *self, GError **error); -GHashTable *obexclient_transfer_get_properties(OBEXClientTransfer *self, GError **error); - -const gchar *obexclient_transfer_get_dbus_object_path(OBEXClientTransfer *self); -const gchar *obexclient_transfer_get_filename(OBEXClientTransfer *self); -const gchar *obexclient_transfer_get_name(OBEXClientTransfer *self); -const guint64 obexclient_transfer_get_size(OBEXClientTransfer *self); - -#endif /* __OBEXCLIENT_TRANSFER_H */ - diff --git a/src/lib/obexd/obexmanager.c b/src/lib/obexd/obexmanager.c deleted file mode 100644 index 1e3e0d4..0000000 --- a/src/lib/obexd/obexmanager.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obexmanager.h" - -#define OBEXMANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXMANAGER_TYPE, OBEXManagerPrivate)) - -struct _OBEXManagerPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; -}; - -G_DEFINE_TYPE(OBEXManager, obexmanager, G_TYPE_OBJECT); - -enum { - SESSION_CREATED, - SESSION_REMOVED, - TRANSFER_COMPLETED, - TRANSFER_STARTED, - - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0}; - -static void session_created_handler(DBusGProxy *dbus_g_proxy, const gchar *session, gpointer data); -static void session_removed_handler(DBusGProxy *dbus_g_proxy, const gchar *session, gpointer data); -static void transfer_completed_handler(DBusGProxy *dbus_g_proxy, const gchar *transfer, const gboolean success, gpointer data); -static void transfer_started_handler(DBusGProxy *dbus_g_proxy, const gchar *transfer, gpointer data); - -static void obexmanager_dispose(GObject *gobject) -{ - OBEXManager *self = OBEXMANAGER(gobject); - - /* DBus signals disconnection */ - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "SessionCreated", G_CALLBACK(session_created_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "SessionRemoved", G_CALLBACK(session_removed_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "TransferCompleted", G_CALLBACK(transfer_completed_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "TransferStarted", G_CALLBACK(transfer_started_handler), self); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexmanager_parent_class)->dispose(gobject); -} - -static void obexmanager_class_init(OBEXManagerClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexmanager_dispose; - - g_type_class_add_private(klass, sizeof(OBEXManagerPrivate)); - - /* Signals registation */ - signals[SESSION_CREATED] = g_signal_new("SessionCreated", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); - - signals[SESSION_REMOVED] = g_signal_new("SessionRemoved", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); - - signals[TRANSFER_COMPLETED] = g_signal_new("TransferCompleted", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_bt_marshal_VOID__STRING_BOOLEAN, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_BOOLEAN); - - signals[TRANSFER_STARTED] = g_signal_new("TransferStarted", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); -} - -static void obexmanager_init(OBEXManager *self) -{ - self->priv = OBEXMANAGER_GET_PRIVATE(self); - - /* DBusGProxy init */ - self->priv->dbus_g_proxy = NULL; - - g_assert(session_conn != NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex", OBEXMANAGER_DBUS_PATH, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXMANAGER_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXMANAGER_DBUS_INTERFACE, OBEXMANAGER_DBUS_PATH); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex", OBEXMANAGER_DBUS_PATH, OBEXMANAGER_DBUS_INTERFACE); - - /* DBus signals connection */ - - /* SessionCreated(object session) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "SessionCreated", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "SessionCreated", G_CALLBACK(session_created_handler), self, NULL); - - /* SessionRemoved(object session) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "SessionRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "SessionRemoved", G_CALLBACK(session_removed_handler), self, NULL); - - /* TransferCompleted(object transfer, boolean success) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "TransferCompleted", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "TransferCompleted", G_CALLBACK(transfer_completed_handler), self, NULL); - - /* TransferStarted(object transfer) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "TransferStarted", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "TransferStarted", G_CALLBACK(transfer_started_handler), self, NULL); -} - -/* Methods */ - -/* void RegisterAgent(object agent) */ -void obexmanager_register_agent(OBEXManager *self, const gchar *agent, GError **error) -{ - g_assert(OBEXMANAGER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "RegisterAgent", error, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void UnregisterAgent(object agent) */ -void obexmanager_unregister_agent(OBEXManager *self, const gchar *agent, GError **error) -{ - g_assert(OBEXMANAGER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "UnregisterAgent", error, DBUS_TYPE_G_OBJECT_PATH, agent, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* Signals handlers */ -static void session_created_handler(DBusGProxy *dbus_g_proxy, const gchar *session, gpointer data) -{ - OBEXManager *self = OBEXMANAGER(data); - - g_signal_emit(self, signals[SESSION_CREATED], 0, session); -} - -static void session_removed_handler(DBusGProxy *dbus_g_proxy, const gchar *session, gpointer data) -{ - OBEXManager *self = OBEXMANAGER(data); - - g_signal_emit(self, signals[SESSION_REMOVED], 0, session); -} - -static void transfer_completed_handler(DBusGProxy *dbus_g_proxy, const gchar *transfer, const gboolean success, gpointer data) -{ - OBEXManager *self = OBEXMANAGER(data); - - g_signal_emit(self, signals[TRANSFER_COMPLETED], 0, transfer, success); -} - -static void transfer_started_handler(DBusGProxy *dbus_g_proxy, const gchar *transfer, gpointer data) -{ - OBEXManager *self = OBEXMANAGER(data); - - g_signal_emit(self, signals[TRANSFER_STARTED], 0, transfer); -} - diff --git a/src/lib/obexd/obexmanager.h b/src/lib/obexd/obexmanager.h deleted file mode 100644 index 203fe59..0000000 --- a/src/lib/obexd/obexmanager.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXMANAGER_H -#define __OBEXMANAGER_H - -#include <glib-object.h> - -#define OBEXMANAGER_DBUS_PATH "/" -#define OBEXMANAGER_DBUS_INTERFACE "org.openobex.Manager" - -/* - * Type macros - */ -#define OBEXMANAGER_TYPE (obexmanager_get_type()) -#define OBEXMANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXMANAGER_TYPE, OBEXManager)) -#define OBEXMANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXMANAGER_TYPE)) -#define OBEXMANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXMANAGER_TYPE, OBEXManagerClass)) -#define OBEXMANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXMANAGER_TYPE)) -#define OBEXMANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXMANAGER_TYPE, OBEXManagerClass)) - -typedef struct _OBEXManager OBEXManager; -typedef struct _OBEXManagerClass OBEXManagerClass; -typedef struct _OBEXManagerPrivate OBEXManagerPrivate; - -struct _OBEXManager { - GObject parent_instance; - - /*< private >*/ - OBEXManagerPrivate *priv; -}; - -struct _OBEXManagerClass { - GObjectClass parent_class; -}; - -/* used by OBEXMANAGER_TYPE */ -GType obexmanager_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -void obexmanager_register_agent(OBEXManager *self, const gchar *agent, GError **error); -void obexmanager_unregister_agent(OBEXManager *self, const gchar *agent, GError **error); - -#endif /* __OBEXMANAGER_H */ - diff --git a/src/lib/obexd/obexsession.c b/src/lib/obexd/obexsession.c deleted file mode 100644 index 48380cf..0000000 --- a/src/lib/obexd/obexsession.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obexsession.h" - -#define OBEXSESSION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXSESSION_TYPE, OBEXSessionPrivate)) - -struct _OBEXSessionPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; - - /* Properties */ - gchar *address; -}; - -G_DEFINE_TYPE(OBEXSession, obexsession, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH, /* readwrite, construct only */ - PROP_ADDRESS /* readonly */ -}; - -static void _obexsession_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _obexsession_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -static void obexsession_dispose(GObject *gobject) -{ - OBEXSession *self = OBEXSESSION(gobject); - - /* Properties free */ - g_free(self->priv->address); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexsession_parent_class)->dispose(gobject); -} - -static void obexsession_class_init(OBEXSessionClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexsession_dispose; - - g_type_class_add_private(klass, sizeof(OBEXSessionPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _obexsession_get_property; - gobject_class->set_property = _obexsession_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); - - /* string Address [readonly] */ - pspec = g_param_spec_string("Address", NULL, NULL, NULL, G_PARAM_READABLE); - g_object_class_install_property(gobject_class, PROP_ADDRESS, pspec); -} - -static void obexsession_init(OBEXSession *self) -{ - self->priv = OBEXSESSION_GET_PRIVATE(self); - - /* DBusGProxy init */ - self->priv->dbus_g_proxy = NULL; - - g_assert(session_conn != NULL); -} - -static void obexsession_post_init(OBEXSession *self, const gchar *dbus_object_path) -{ - g_assert(dbus_object_path != NULL); - g_assert(strlen(dbus_object_path) > 0); - g_assert(self->priv->dbus_g_proxy == NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex", dbus_object_path, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXSESSION_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXSESSION_DBUS_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex", dbus_object_path, OBEXSESSION_DBUS_INTERFACE); - - /* Properties init */ - GHashTable *properties = obexsession_get_properties(self, &error); - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - g_assert(properties != NULL); - - /* string Address [readonly] */ - if (g_hash_table_lookup(properties, "Address")) { - self->priv->address = g_value_dup_string(g_hash_table_lookup(properties, "Address")); - } else { - self->priv->address = g_strdup("undefined"); - } - - g_hash_table_unref(properties); -} - -static void _obexsession_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - OBEXSession *self = OBEXSESSION(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, obexsession_get_dbus_object_path(self)); - break; - - case PROP_ADDRESS: - g_value_set_string(value, obexsession_get_address(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _obexsession_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - OBEXSession *self = OBEXSESSION(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - obexsession_post_init(self, g_value_get_string(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -/* Methods */ - -/* dict GetProperties() */ -GHashTable *obexsession_get_properties(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetProperties", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* Properties access methods */ -const gchar *obexsession_get_dbus_object_path(OBEXSession *self) -{ - g_assert(OBEXSESSION_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - -const gchar *obexsession_get_address(OBEXSession *self) -{ - g_assert(OBEXSESSION_IS(self)); - - return self->priv->address; -} - diff --git a/src/lib/obexd/obexsession.h b/src/lib/obexd/obexsession.h deleted file mode 100644 index d39e15f..0000000 --- a/src/lib/obexd/obexsession.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXSESSION_H -#define __OBEXSESSION_H - -#include <glib-object.h> - -#define OBEXSESSION_DBUS_INTERFACE "org.openobex.Session" - -/* - * Type macros - */ -#define OBEXSESSION_TYPE (obexsession_get_type()) -#define OBEXSESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXSESSION_TYPE, OBEXSession)) -#define OBEXSESSION_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXSESSION_TYPE)) -#define OBEXSESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXSESSION_TYPE, OBEXSessionClass)) -#define OBEXSESSION_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXSESSION_TYPE)) -#define OBEXSESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXSESSION_TYPE, OBEXSessionClass)) - -typedef struct _OBEXSession OBEXSession; -typedef struct _OBEXSessionClass OBEXSessionClass; -typedef struct _OBEXSessionPrivate OBEXSessionPrivate; - -struct _OBEXSession { - GObject parent_instance; - - /*< private >*/ - OBEXSessionPrivate *priv; -}; - -struct _OBEXSessionClass { - GObjectClass parent_class; -}; - -/* used by OBEXSESSION_TYPE */ -GType obexsession_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -GHashTable *obexsession_get_properties(OBEXSession *self, GError **error); - -const gchar *obexsession_get_dbus_object_path(OBEXSession *self); -const gchar *obexsession_get_address(OBEXSession *self); - -#endif /* __OBEXSESSION_H */ - diff --git a/src/lib/obexd/obextransfer.c b/src/lib/obexd/obextransfer.c deleted file mode 100644 index 78dcf52..0000000 --- a/src/lib/obexd/obextransfer.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obextransfer.h" - -#define OBEXTRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXTRANSFER_TYPE, OBEXTransferPrivate)) - -struct _OBEXTransferPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; -}; - -G_DEFINE_TYPE(OBEXTransfer, obextransfer, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH /* readwrite, construct only */ -}; - -static void _obextransfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _obextransfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -enum { - PROGRESS, - - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0}; - -static void progress_handler(DBusGProxy *dbus_g_proxy, const gint32 total, const gint32 transfered, gpointer data); - -static void obextransfer_dispose(GObject *gobject) -{ - OBEXTransfer *self = OBEXTRANSFER(gobject); - - /* DBus signals disconnection */ - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "Progress", G_CALLBACK(progress_handler), self); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obextransfer_parent_class)->dispose(gobject); -} - -static void obextransfer_class_init(OBEXTransferClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obextransfer_dispose; - - g_type_class_add_private(klass, sizeof(OBEXTransferPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _obextransfer_get_property; - gobject_class->set_property = _obextransfer_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); - - /* Signals registation */ - signals[PROGRESS] = g_signal_new("Progress", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_bt_marshal_VOID__INT_INT, - G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); -} - -static void obextransfer_init(OBEXTransfer *self) -{ - self->priv = OBEXTRANSFER_GET_PRIVATE(self); - - /* DBusGProxy init */ - self->priv->dbus_g_proxy = NULL; - - g_assert(session_conn != NULL); -} - -static void obextransfer_post_init(OBEXTransfer *self, const gchar *dbus_object_path) -{ - g_assert(dbus_object_path != NULL); - g_assert(strlen(dbus_object_path) > 0); - g_assert(self->priv->dbus_g_proxy == NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex", dbus_object_path, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXTRANSFER_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXTRANSFER_DBUS_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(session_conn, "org.openobex", dbus_object_path, OBEXTRANSFER_DBUS_INTERFACE); - - /* DBus signals connection */ - - /* Progress(int32 total, int32 transfered) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "Progress", G_TYPE_INT, G_TYPE_INT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "Progress", G_CALLBACK(progress_handler), self, NULL); -} - -static void _obextransfer_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - OBEXTransfer *self = OBEXTRANSFER(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, obextransfer_get_dbus_object_path(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _obextransfer_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - OBEXTransfer *self = OBEXTRANSFER(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - obextransfer_post_init(self, g_value_get_string(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -/* Methods */ - -/* void Cancel() */ -void obextransfer_cancel(OBEXTransfer *self, GError **error) -{ - g_assert(OBEXTRANSFER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Cancel", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* Properties access methods */ -const gchar *obextransfer_get_dbus_object_path(OBEXTransfer *self) -{ - g_assert(OBEXTRANSFER_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - -/* Signals handlers */ -static void progress_handler(DBusGProxy *dbus_g_proxy, const gint32 total, const gint32 transfered, gpointer data) -{ - OBEXTransfer *self = OBEXTRANSFER(data); - - g_signal_emit(self, signals[PROGRESS], 0, total, transfered); -} - diff --git a/src/lib/obexd/obextransfer.h b/src/lib/obexd/obextransfer.h deleted file mode 100644 index 99f3084..0000000 --- a/src/lib/obexd/obextransfer.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXTRANSFER_H -#define __OBEXTRANSFER_H - -#include <glib-object.h> - -#define OBEXTRANSFER_DBUS_INTERFACE "org.openobex.Transfer" - -/* - * Type macros - */ -#define OBEXTRANSFER_TYPE (obextransfer_get_type()) -#define OBEXTRANSFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXTRANSFER_TYPE, OBEXTransfer)) -#define OBEXTRANSFER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXTRANSFER_TYPE)) -#define OBEXTRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXTRANSFER_TYPE, OBEXTransferClass)) -#define OBEXTRANSFER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXTRANSFER_TYPE)) -#define OBEXTRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXTRANSFER_TYPE, OBEXTransferClass)) - -typedef struct _OBEXTransfer OBEXTransfer; -typedef struct _OBEXTransferClass OBEXTransferClass; -typedef struct _OBEXTransferPrivate OBEXTransferPrivate; - -struct _OBEXTransfer { - GObject parent_instance; - - /*< private >*/ - OBEXTransferPrivate *priv; -}; - -struct _OBEXTransferClass { - GObjectClass parent_class; -}; - -/* used by OBEXTRANSFER_TYPE */ -GType obextransfer_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -void obextransfer_cancel(OBEXTransfer *self, GError **error); - -const gchar *obextransfer_get_dbus_object_path(OBEXTransfer *self); - -#endif /* __OBEXTRANSFER_H */ - |