From: barbieri Date: Sat, 13 Feb 2010 12:35:25 +0000 (+0000) Subject: e_dbus/bluez: Initial support to get and set individual properties X-Git-Tag: 2.0_alpha~43^2~285 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c39669110d99120824f2eb3628195ab07df5290;p=framework%2Fuifw%2Fedbus.git e_dbus/bluez: Initial support to get and set individual properties Only 3 methods are suportted right now: _bluez_device_name_get, e_bluez_adapter_powered_set, e_bluez_adapter_address_get. One should refer to the BlueZ doc to look what's missing to implement. By: "Gustavo F. Padovan" E17 module should be coming soon! git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/e_dbus@46137 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/src/bin/e_dbus_bluez_test.c b/src/bin/e_dbus_bluez_test.c index 3750666..a526dcc 100644 --- a/src/bin/e_dbus_bluez_test.c +++ b/src/bin/e_dbus_bluez_test.c @@ -260,6 +260,7 @@ _on_cmd_manager_get(char *cmd, char *args) e_bluez_element_print(stderr, element); return 1; } +/* Adapter Commands */ static int _on_cmd_adapter_register_agent(char *cmd, char *args) @@ -315,6 +316,69 @@ _on_cmd_adapter_unregister_agent(char *cmd, char *args) return 1; } + +static int +_on_cmd_adapter_get_address(char *cmd, char *args) +{ + const char *address; + char *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_adapter_address_get(element, &address)) + printf(":::Adapter address = \"%s\"\n", address); + else + fputs("ERROR: can't get adapter address\n", stderr); + return 1; +} + +static int +_on_cmd_adapter_set_powered(char *cmd, char *args) +{ + char *next_args; + bool powered; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (!args) + { + fputs("ERROR: missing the powered value\n", stderr); + return 1; + } + + powered = !!atol(next_args); + + if (e_bluez_adapter_powered_set + (element, powered, _method_success_check, "adapter_set_powered")) + printf(":::Adapter %s Powered set to %hhu\n", element->path, powered); + else + fputs("ERROR: can't set device powered\n", stderr); + return 1; +} + +/* Devices Commands */ + +static int +_on_cmd_device_get_name(char *cmd, char *args) +{ + const char *name; + char *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_device_name_get(element, &name)) + printf(":::Device name = \"%s\"\n", name); + else + fputs("ERROR: can't get device name\n", stderr); + return 1; +} + static int _on_input(void *data, Ecore_Fd_Handler *fd_handler) { @@ -333,6 +397,9 @@ _on_input(void *data, Ecore_Fd_Handler *fd_handler) {"manager_get", _on_cmd_manager_get}, {"adapter_register_agent", _on_cmd_adapter_register_agent}, {"adapter_unregister_agent", _on_cmd_adapter_unregister_agent}, + {"adapter_get_address", _on_cmd_adapter_get_address}, + {"adapter_set_powered", _on_cmd_adapter_set_powered}, + {"device_get_name", _on_cmd_device_get_name}, {NULL, NULL} }; diff --git a/src/lib/bluez/E_Bluez.h b/src/lib/bluez/E_Bluez.h index 1066230..d444b39 100644 --- a/src/lib/bluez/E_Bluez.h +++ b/src/lib/bluez/E_Bluez.h @@ -74,6 +74,13 @@ extern "C" { /* Adapter Methods */ EAPI bool e_bluez_adapter_agent_register(E_Bluez_Element *element, const char *object_path, const char *capability, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; EAPI bool e_bluez_adapter_agent_unregister(E_Bluez_Element *element, const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_bluez_adapter_address_get(E_Bluez_Element *element, const char **address) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_bluez_adapter_powered_set(E_Bluez_Element *profile, bool powered, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + + /* Devices Methods */ + EAPI bool e_bluez_device_name_get(E_Bluez_Element *element, const char **name) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; /* Low-Level API: * diff --git a/src/lib/bluez/Makefile.am b/src/lib/bluez/Makefile.am index c5c7791..d69b481 100644 --- a/src/lib/bluez/Makefile.am +++ b/src/lib/bluez/Makefile.am @@ -15,7 +15,8 @@ e_bluez_private.h \ e_bluez.c \ e_bluez_element.c \ e_bluez_manager.c \ -e_bluez_adapter.c +e_bluez_adapter.c \ +e_bluez_device.c libebluez_la_LIBADD = \ @EDBUS_LIBS@ @EVAS_LIBS@ \ diff --git a/src/lib/bluez/e_bluez.c b/src/lib/bluez/e_bluez.c index ad5f7cd..3af1c33 100644 --- a/src/lib/bluez/e_bluez.c +++ b/src/lib/bluez/e_bluez.c @@ -23,6 +23,22 @@ EAPI int E_BLUEZ_EVENT_ELEMENT_UPDATED = 0; const char *e_bluez_iface_manager = NULL; const char *e_bluez_iface_adapter = NULL; const char *e_bluez_iface_device = NULL; +const char *e_bluez_prop_address = NULL; +const char *e_bluez_prop_name = NULL; +const char *e_bluez_prop_alias = NULL; +const char *e_bluez_prop_class = NULL; +const char *e_bluez_prop_icon = NULL; +const char *e_bluez_prop_paired = NULL; +const char *e_bluez_prop_trusted = NULL; +const char *e_bluez_prop_connected = NULL; +const char *e_bluez_prop_uuids = NULL; +const char *e_bluez_prop_powered = NULL; +const char *e_bluez_prop_discoverable = NULL; +const char *e_bluez_prop_pairable = NULL; +const char *e_bluez_prop_discoverabletimeout = NULL; +const char *e_bluez_prop_pairabletimeout = NULL; +const char *e_bluez_prop_discovering = NULL; +const char *e_bluez_prop_devices = NULL; int _e_dbus_bluez_log_dom = -1; @@ -222,6 +238,38 @@ e_bluez_system_init(E_DBus_Connection *edbus_conn) e_bluez_iface_adapter = eina_stringshare_add("org.bluez.Adapter"); if (e_bluez_iface_device == NULL) e_bluez_iface_device = eina_stringshare_add("org.bluez.Device"); + if (e_bluez_prop_address == NULL) + e_bluez_prop_address = eina_stringshare_add("Address"); + if (e_bluez_prop_name == NULL) + e_bluez_prop_name = eina_stringshare_add("Name"); + if (e_bluez_prop_alias == NULL) + e_bluez_prop_alias = eina_stringshare_add("Alias"); + if (e_bluez_prop_class == NULL) + e_bluez_prop_class = eina_stringshare_add("Class"); + if (e_bluez_prop_icon == NULL) + e_bluez_prop_icon = eina_stringshare_add("Icon"); + if (e_bluez_prop_paired == NULL) + e_bluez_prop_paired = eina_stringshare_add("Paired"); + if (e_bluez_prop_trusted == NULL) + e_bluez_prop_trusted = eina_stringshare_add("Trusted"); + if (e_bluez_prop_connected == NULL) + e_bluez_prop_connected = eina_stringshare_add("Connected"); + if (e_bluez_prop_uuids == NULL) + e_bluez_prop_uuids = eina_stringshare_add("UUIDs"); + if (e_bluez_prop_powered == NULL) + e_bluez_prop_powered = eina_stringshare_add("Powered"); + if (e_bluez_prop_discoverable == NULL) + e_bluez_prop_discoverable = eina_stringshare_add("Discoverable"); + if (e_bluez_prop_pairable == NULL) + e_bluez_prop_pairable = eina_stringshare_add("Pairable"); + if (e_bluez_prop_discoverabletimeout == NULL) + e_bluez_prop_discoverabletimeout = eina_stringshare_add("DiscoverableTimeout"); + if (e_bluez_prop_pairabletimeout == NULL) + e_bluez_prop_pairabletimeout = eina_stringshare_add("PairableTimeout"); + if (e_bluez_prop_discovering == NULL) + e_bluez_prop_discovering = eina_stringshare_add("Discovering"); + if (e_bluez_prop_devices == NULL) + e_bluez_prop_devices = eina_stringshare_add("Devices"); e_bluez_conn = edbus_conn; cb_name_owner_changed = e_dbus_signal_handler_add @@ -270,5 +318,21 @@ e_bluez_system_shutdown(void) _stringshare_del(&e_bluez_iface_manager); _stringshare_del(&e_bluez_iface_adapter); _stringshare_del(&e_bluez_iface_device); + _stringshare_del(&e_bluez_prop_address); + _stringshare_del(&e_bluez_prop_name); + _stringshare_del(&e_bluez_prop_alias); + _stringshare_del(&e_bluez_prop_class); + _stringshare_del(&e_bluez_prop_icon); + _stringshare_del(&e_bluez_prop_paired); + _stringshare_del(&e_bluez_prop_trusted); + _stringshare_del(&e_bluez_prop_connected); + _stringshare_del(&e_bluez_prop_uuids); + _stringshare_del(&e_bluez_prop_powered); + _stringshare_del(&e_bluez_prop_discoverable); + _stringshare_del(&e_bluez_prop_pairable); + _stringshare_del(&e_bluez_prop_discoverabletimeout); + _stringshare_del(&e_bluez_prop_pairabletimeout); + _stringshare_del(&e_bluez_prop_discovering); + _stringshare_del(&e_bluez_prop_devices); return 0; } diff --git a/src/lib/bluez/e_bluez_adapter.c b/src/lib/bluez/e_bluez_adapter.c index f8e8ce3..7c4f36a 100644 --- a/src/lib/bluez/e_bluez_adapter.c +++ b/src/lib/bluez/e_bluez_adapter.c @@ -50,3 +50,45 @@ e_bluez_adapter_agent_unregister(E_Bluez_Element *element, const char *object_pa (element, name, object_path, NULL, &element->_pending.agent_unregister, cb, data); } + +/** + * Get property "Address" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param address where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_bluez_adapter_address_get(E_Bluez_Element *element, const char **address) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0); + + return e_bluez_element_property_get_stringshared + (element, e_bluez_prop_address, NULL, address); +} + +/** + * Call method SetProperty("Powered", powered) at the given element on server. + * + * + * @param powered value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_bluez_adapter_powered_set(E_Bluez_Element *profile, bool offline, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0); + return e_bluez_element_property_set_full + (profile, e_bluez_prop_powered, DBUS_TYPE_BOOLEAN, + &offline, cb, data); +} diff --git a/src/lib/bluez/e_bluez_private.h b/src/lib/bluez/e_bluez_private.h index 801ae45..323541f 100644 --- a/src/lib/bluez/e_bluez_private.h +++ b/src/lib/bluez/e_bluez_private.h @@ -31,6 +31,22 @@ static const char manager_path[] = "/"; extern const char *e_bluez_iface_manager; extern const char *e_bluez_iface_adapter; extern const char *e_bluez_iface_device; +extern const char *e_bluez_prop_address; +extern const char *e_bluez_prop_name; +extern const char *e_bluez_prop_alias; +extern const char *e_bluez_prop_class; +extern const char *e_bluez_prop_icon; +extern const char *e_bluez_prop_paired; +extern const char *e_bluez_prop_trusted; +extern const char *e_bluez_prop_connected; +extern const char *e_bluez_prop_uuids; +extern const char *e_bluez_prop_powered; +extern const char *e_bluez_prop_discoverable; +extern const char *e_bluez_prop_pairable; +extern const char *e_bluez_prop_discoverabletimeout; +extern const char *e_bluez_prop_pairabletimeout; +extern const char *e_bluez_prop_discovering; +extern const char *e_bluez_prop_devices; extern int _e_dbus_bluez_log_dom;