[maemo-commits] [maemo-commits] r18589 - in projects/connectivity/maemo-bluez-compat/trunk: debian src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Wed Jun 3 17:04:19 EEST 2009
- Previous message: [maemo-commits] r18588 - in projects/haf/trunk/fontconfig: . debian
- Next message: [maemo-commits] r18590 - projects/connectivity/maemo-bluez-compat/trunk/src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: jh Date: 2009-06-03 17:04:15 +0300 (Wed, 03 Jun 2009) New Revision: 18589 Added: projects/connectivity/maemo-bluez-compat/trunk/src/dbus-common.c projects/connectivity/maemo-bluez-compat/trunk/src/dbus-common.h projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud.c projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud.py projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore.c projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore.py projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs.c projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs.py Removed: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs Modified: projects/connectivity/maemo-bluez-compat/trunk/debian/control projects/connectivity/maemo-bluez-compat/trunk/src/Makefile.am Log: Add initial C-versions of the python scripts Modified: projects/connectivity/maemo-bluez-compat/trunk/debian/control =================================================================== --- projects/connectivity/maemo-bluez-compat/trunk/debian/control 2009-06-03 13:47:22 UTC (rev 18588) +++ projects/connectivity/maemo-bluez-compat/trunk/debian/control 2009-06-03 14:04:15 UTC (rev 18589) @@ -8,7 +8,7 @@ Package: maemo-bluez-compat Section: net Architecture: any -Depends: ${shlibs:Depends}, bluez (>= 4.22), python2.5, python2.5-dbus, sudo +Depends: ${shlibs:Depends}, bluez (>= 4.22), sudo Description: Maemo compatibility tools for BlueZ This package contais a some programs and scripts which help integrate BlueZ to the Maemo environment. Modified: projects/connectivity/maemo-bluez-compat/trunk/src/Makefile.am =================================================================== --- projects/connectivity/maemo-bluez-compat/trunk/src/Makefile.am 2009-06-03 13:47:22 UTC (rev 18588) +++ projects/connectivity/maemo-bluez-compat/trunk/src/Makefile.am 2009-06-03 14:04:15 UTC (rev 18589) @@ -1,5 +1,15 @@ MAINTAINERCLEANFILES = Makefile.in -bin_SCRIPTS = maemo-bluez-cud maemo-bluez-restore maemo-bluez-rfs +bin_PROGRAMS = maemo-bluez-rfs maemo-bluez-restore maemo-bluez-cud -EXTRA_DIST = maemo-bluez-cud maemo-bluez-restore maemo-bluez-rfs +maemo_bluez_rfs_SOURCES = dbus-common.h dbus-common.c maemo-bluez-rfs.c +maemo_bluez_restore_SOURCES = dbus-common.h dbus-common.c maemo-bluez-restore.c +maemo_bluez_cud_SOURCES = dbus-common.h dbus-common.c maemo-bluez-cud.c + +maemo_bluez_rfs_LDADD = @COMMON_LIBS@ +maemo_bluez_restore_LDADD = @COMMON_LIBS@ +maemo_bluez_cud_LDADD = @COMMON_LIBS@ + +AM_CFLAGS = @COMMON_CFLAGS@ + +EXTRA_DIST = maemo-bluez-cud.py maemo-bluez-restore.py maemo-bluez-rfs.py Added: projects/connectivity/maemo-bluez-compat/trunk/src/dbus-common.c =================================================================== --- projects/connectivity/maemo-bluez-compat/trunk/src/dbus-common.c 2009-06-03 13:47:22 UTC (rev 18588) +++ projects/connectivity/maemo-bluez-compat/trunk/src/dbus-common.c 2009-06-03 14:04:15 UTC (rev 18589) @@ -0,0 +1,171 @@ +#include <stdlib.h> + +#include "dbus-common.h" + +#define BLUEZ_SERVICE "org.bluez" + +#define BLUEZ_MANAGER_PATH "/" +#define BLUEZ_MANAGER_INTERFACE "org.bluez.Manager" +#define BLUEZ_ADAPTER_INTERFACE "org.bluez.Adapter" + + +DBusGProxy* bluez_get_manager(DBusGConnection *connection) +{ + return dbus_g_proxy_new_for_name(connection, BLUEZ_SERVICE, + BLUEZ_MANAGER_PATH, + BLUEZ_MANAGER_INTERFACE); +} + + +DBusGProxy* manager_get_default_adapter(DBusGProxy *manager, + DBusGConnection *connection) +{ + GError *error = NULL; + const gchar* adapter_path; + + if (!dbus_g_proxy_call(manager, "DefaultAdapter", &error, G_TYPE_INVALID, + DBUS_TYPE_G_OBJECT_PATH, &adapter_path, G_TYPE_INVALID)) { + + g_debug("Couldn't get DefaultAdapter: %s", error->message); + g_error_free(error); + return NULL; + } + + return dbus_g_proxy_new_for_name(connection, BLUEZ_SERVICE, adapter_path, + BLUEZ_ADAPTER_INTERFACE); +} + +void adapter_set_property_string(DBusGProxy* adapter, const gchar* attribute, + const gchar* value) +{ + GError *error = NULL; + GValue g_value = {0}; + + g_value_init(&g_value, G_TYPE_STRING); + g_value_set_string(&g_value, value); + + if (dbus_g_proxy_call(adapter, "SetProperty", &error,G_TYPE_STRING, + attribute, G_TYPE_VALUE, &g_value, + G_TYPE_INVALID, G_TYPE_INVALID ) != TRUE) { + g_debug("Couldn't set string Properties: %s", error->message); + g_error_free(error); + } + g_value_unset(&g_value); +} + +const gchar* adapter_get_property_string(DBusGProxy* adapter, + const gchar* attribute) +{ + GHashTable *table; + GError *error = NULL; + GValue *value; + if (dbus_g_proxy_call(adapter, "GetProperties", &error, G_TYPE_INVALID, + dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), + &table, G_TYPE_INVALID) != FALSE) { + value = g_hash_table_lookup(table, attribute); + return g_value_get_string(value); + } else { + g_debug("Couldn't get string Properties: %s", error->message); + g_error_free(error); + return NULL; + } +} + +void adapter_set_property_boolean(DBusGProxy* adapter, const gchar* attribute, + const gboolean value) +{ + GError *error = NULL; + GValue g_value = {0}; + + g_value_init(&g_value, G_TYPE_BOOLEAN); + g_value_set_boolean(&g_value, value); + + if (dbus_g_proxy_call(adapter, "SetProperty", &error, G_TYPE_STRING, + attribute, G_TYPE_VALUE, &g_value, + G_TYPE_INVALID, G_TYPE_INVALID) != TRUE) { + g_debug("Couldn't set boolean Properties: %s", error->message); + g_error_free(error); + } + g_value_unset(&g_value); +} + +gboolean adapter_get_property_boolean(DBusGProxy* adapter, + const gchar* attribute) +{ + GHashTable *table; + GError *error = NULL; + gboolean ret; + GValue *value; + if (dbus_g_proxy_call (adapter, "GetProperties", &error, G_TYPE_INVALID, + dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, + G_TYPE_VALUE), &table, G_TYPE_INVALID) != FALSE) { + value = g_hash_table_lookup(table, attribute); + ret = g_value_get_boolean(value); + return ret; + } else { + g_debug("Couldn't get boolean Properties: %s", error->message); + g_error_free(error); + return FALSE; + } +} + +void adapter_set_property_uint(DBusGProxy* adapter,const gchar* attribute, + guint value) +{ + GError *error = NULL; + GValue g_value = {0}; + + g_value_init(&g_value, G_TYPE_UINT); + g_value_set_uint(&g_value, value); + + if (dbus_g_proxy_call(adapter, "SetProperty", &error, G_TYPE_STRING, + attribute, G_TYPE_VALUE, &g_value, + G_TYPE_INVALID, G_TYPE_INVALID) != TRUE) { + g_debug("Couldn't set int Properties: %s", error->message); + if (error != NULL) + g_error_free(error); + } + g_value_unset(&g_value); +} + +guint adapter_get_property_uint(DBusGProxy* adapter, const gchar* attribute) +{ + GHashTable *table; + GError *error = NULL; + guint ret; + GValue *value; + if (dbus_g_proxy_call(adapter, "GetProperties", &error, G_TYPE_INVALID, + dbus_g_type_get_map("GHashTable", G_TYPE_STRING, + G_TYPE_VALUE), &table, G_TYPE_INVALID) != FALSE) { + value = g_hash_table_lookup(table, attribute); + ret = g_value_get_uint(value); + return ret; + } else { + g_debug("Couldn't get int Properties: %s", error->message); + if (error != NULL) + g_error_free(error); + return 0; + } +} + +GPtrArray* adapter_get_property_objectpath_array(DBusGProxy* adapter, + const gchar* attribute) +{ + GHashTable *table; + GError *error = NULL; + GPtrArray *ret; + GValue *value; + if (dbus_g_proxy_call(adapter, "GetProperties", &error, G_TYPE_INVALID, + dbus_g_type_get_map("GHashTable", G_TYPE_STRING, + G_TYPE_VALUE), &table, G_TYPE_INVALID) != FALSE) { + value = g_hash_table_lookup(table, attribute); + ret = g_value_get_boxed(value); + return ret; + } else { + g_debug("Couldn't get object array Properties: %s", + error->message); + if (error != NULL) + g_error_free(error); + return NULL; + } +} Added: projects/connectivity/maemo-bluez-compat/trunk/src/dbus-common.h =================================================================== --- projects/connectivity/maemo-bluez-compat/trunk/src/dbus-common.h 2009-06-03 13:47:22 UTC (rev 18588) +++ projects/connectivity/maemo-bluez-compat/trunk/src/dbus-common.h 2009-06-03 14:04:15 UTC (rev 18589) @@ -0,0 +1,23 @@ + +#ifndef DBUS_COMMON_H +#define DBUS_COMMON_H + +#include <dbus/dbus-glib.h> +#include <glib.h> + +DBusGProxy* bluez_get_manager(DBusGConnection *connection); +DBusGProxy* manager_get_default_adapter(DBusGProxy *manager, + DBusGConnection *connection); +void adapter_set_property_string(DBusGProxy* adapter, const gchar* attribute, + const gchar* value); +const gchar* adapter_get_property_string(DBusGProxy* adapter, + const gchar* attribute); +gboolean adapter_get_property_boolean(DBusGProxy* adapter, const gchar* attribute); +void adapter_set_property_boolean(DBusGProxy* adapter, const gchar* attribute, + const gboolean value); +void adapter_set_property_uint(DBusGProxy* adapter, const gchar* attribute, + guint value); +guint adapter_get_property_uint(DBusGProxy* adapter,const gchar* attribute); +GPtrArray* adapter_get_property_objectpath_array(DBusGProxy* adapter, + const gchar* attribute); +#endif Deleted: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud =================================================================== --- projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud 2009-06-03 13:47:22 UTC (rev 18588) +++ projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud 2009-06-03 14:04:15 UTC (rev 18589) @@ -1,28 +0,0 @@ -#!/usr/bin/python2.5 - -import dbus -import sys - -if len(sys.argv) < 2: - print "Usage: %s <product name>" % sys.argv[0] - sys.exit(1) - -bus = dbus.SystemBus() - -manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager") -adapter = dbus.Interface(bus.get_object("org.bluez", manager.DefaultAdapter()), - "org.bluez.Adapter") - -properties = adapter.GetProperties() -powered = properties["Powered"] - -if not powered: - adapter.SetProperty("Powered", True) - -for device in properties["Devices"]: - adapter.RemoveDevice(device) - -adapter.SetProperty("Name", sys.argv[1]) -adapter.SetProperty("Discoverable", False) -adapter.SetProperty("DiscoverableTimeout", dbus.UInt32(0)) -adapter.SetProperty("Powered", False) Added: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud.c =================================================================== --- projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud.c 2009-06-03 13:47:22 UTC (rev 18588) +++ projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud.c 2009-06-03 14:04:15 UTC (rev 18589) @@ -0,0 +1,70 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + +#include "dbus-common.h" + +int main(int argc, char* argv[]) +{ + GError *error; + DBusGConnection *conn; + DBusGProxy *manager; + DBusGProxy *adapter; + GPtrArray *devices; + guint i; + gchar *product_name; + gboolean powered; + + if (argc < 2) { + g_debug("Usage: %s <product name>", argv[0]); + exit(EXIT_FAILURE); + } + + g_type_init(); + error = NULL; + conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + + if (error != NULL) { + g_debug("Couldn't connect to bus: %s", error->message); + g_error_free(error); + exit(EXIT_FAILURE); + } + + manager = bluez_get_manager(conn); + adapter = manager_get_default_adapter(manager, conn); + + if (manager != NULL) + g_object_unref(manager); + + product_name = argv[1]; + powered = adapter_get_property_boolean(adapter, "Powered"); + + if (!powered) + adapter_set_property_boolean(adapter, "Powered", TRUE); + + devices = adapter_get_property_objectpath_array(adapter, "Devices"); + + for (i = 0; i < devices->len; ++i) { + dbus_g_proxy_call(adapter, "RemoveDevice", &error, + DBUS_TYPE_G_OBJECT_PATH, + g_ptr_array_index(devices, i), + G_TYPE_INVALID, G_TYPE_INVALID); + + if (error != NULL) { + g_debug("error removing device: %s", error->message); + g_error_free(error); + } + } + + adapter_set_property_string(adapter, "Name", product_name); + adapter_set_property_boolean(adapter, "Discoverable", FALSE); + adapter_set_property_uint(adapter, "DiscoverableTimeout", 0); + adapter_set_property_boolean(adapter, "Powered", FALSE); + + if (adapter) + g_object_unref(adapter); + + exit(EXIT_SUCCESS); +} Copied: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud.py (from rev 18588, projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud) Property changes on: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-cud.py ___________________________________________________________________ Name: svn:executable + * Name: svn:mergeinfo + Deleted: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore =================================================================== --- projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore 2009-06-03 13:47:22 UTC (rev 18588) +++ projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore 2009-06-03 14:04:15 UTC (rev 18589) @@ -1,27 +0,0 @@ -#!/usr/bin/python2.5 - -import sys -import dbus - -if len(sys.argv) < 3: - print "Usage %s <name> <mode>" % sys.argv[0] - sys.exit(1) - -bus = dbus.SystemBus() - -manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager") -adapter = dbus.Interface(bus.get_object("org.bluez", manager.DefaultAdapter()), - "org.bluez.Adapter") -adapter.SetProperty("Name", sys.argv[1]) - -if sys.argv[2] == "off": - adapter.SetProperty("Powered", False) - sys.exit(0) - -adapter.SetProperty("Powered", True) - -if sys.argv[2] == "discoverable": - adapter.SetProperty("Discoverable", True) -elif sys.argv[2] == "connectable": - adapter.SetProperty("Discoverable", False) - Added: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore.c =================================================================== --- projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore.c 2009-06-03 13:47:22 UTC (rev 18588) +++ projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore.c 2009-06-03 14:04:15 UTC (rev 18589) @@ -0,0 +1,55 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "dbus-common.h" + +int main(int argc, char** argv) +{ + GError *error; + DBusGConnection *conn; + DBusGProxy *manager; + DBusGProxy *adapter; + const gchar *name; + const gchar *mode; + + if (argc < 3) { + g_debug("Usage %s <name> <mode>", argv[0]); + exit(EXIT_FAILURE); + } + + g_type_init(); + error = NULL; + conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + + if (error != NULL) { + g_debug("Couldn't connect to bus: %s", error->message); + g_error_free(error); + exit(EXIT_FAILURE); + } + + name = argv[1]; + mode = argv[2]; + manager = bluez_get_manager(conn); + adapter = manager_get_default_adapter(manager, conn); + + if (manager != NULL) + g_object_unref(manager); + + adapter_set_property_string(adapter, "Name", name); + + if (g_ascii_strncasecmp(mode, "off", sizeof(mode)) == 0) { + adapter_set_property_boolean(adapter, "Powered", FALSE); + exit(EXIT_SUCCESS); + } + + adapter_set_property_boolean(adapter, "Powered", TRUE); + + if (g_ascii_strncasecmp(mode, "discoverable", sizeof(mode)) == 0) + adapter_set_property_boolean(adapter, "Discoverable", TRUE); + else if (g_ascii_strncasecmp(mode, "connectable", sizeof(mode)) == 0) + adapter_set_property_boolean(adapter, "Discoverable", FALSE); + + exit(EXIT_SUCCESS); +} Copied: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore.py (from rev 18588, projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore) Property changes on: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-restore.py ___________________________________________________________________ Name: svn:executable + * Name: svn:mergeinfo + Deleted: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs =================================================================== --- projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs 2009-06-03 13:47:22 UTC (rev 18588) +++ projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs 2009-06-03 14:04:15 UTC (rev 18589) @@ -1,20 +0,0 @@ -#!/usr/bin/python2.5 - -import dbus -import sys - -if len(sys.argv) < 2: - print "Usage: %s <product name>" % sys.argv[0] - sys.exit(1) - -bus = dbus.SystemBus() - -manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager") -adapter = dbus.Interface(bus.get_object("org.bluez", manager.DefaultAdapter()), - "org.bluez.Adapter") -adapter.SetProperty("Powered", True) -adapter.SetProperty("Discoverable", False) -adapter.SetProperty("DiscoverableTimeout", dbus.UInt32(0)) -adapter.SetProperty("Name", sys.argv[1]) -adapter.SetProperty("Powered", False) - Added: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs.c =================================================================== --- projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs.c 2009-06-03 13:47:22 UTC (rev 18588) +++ projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs.c 2009-06-03 14:04:15 UTC (rev 18589) @@ -0,0 +1,51 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <glib.h> +#include <dbus/dbus-glib.h> + +#include "dbus-common.h" + +int main(int argc, char* argv[]) +{ + GError *error; + DBusGConnection *conn; + DBusGProxy *manager; + DBusGProxy *adapter; + gchar *product_name; + + if (argc < 2 ) { + g_debug("Usage: %s <product name>", argv[0]); + exit(EXIT_FAILURE); + } + + g_type_init(); + error = NULL; + conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + + if (error != NULL) { + g_debug("Couldn't connect to bus: %s", error->message); + g_error_free(error); + exit(EXIT_FAILURE); + } + + manager = bluez_get_manager(conn); + adapter = manager_get_default_adapter(manager, conn); + if (manager != NULL) + g_object_unref(manager); + + product_name = argv[1]; + + adapter_set_property_boolean(adapter, "Powered", TRUE); + adapter_set_property_string(adapter, "Name", product_name); + adapter_set_property_boolean(adapter, "Discoverable", FALSE); + adapter_set_property_uint(adapter, "DiscoverableTimeout", 0); + adapter_set_property_boolean(adapter, "Powered", FALSE); + + if (adapter != NULL) + g_object_unref(adapter); + + exit(EXIT_SUCCESS); +} Copied: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs.py (from rev 18588, projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs) Property changes on: projects/connectivity/maemo-bluez-compat/trunk/src/maemo-bluez-rfs.py ___________________________________________________________________ Name: svn:executable + * Name: svn:mergeinfo +
- Previous message: [maemo-commits] r18588 - in projects/haf/trunk/fontconfig: . debian
- Next message: [maemo-commits] r18590 - projects/connectivity/maemo-bluez-compat/trunk/src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]