couple of missing getters and fixes, consts...
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 12 Mar 2010 13:50:09 +0000 (13:50 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 12 Mar 2010 13:50:09 +0000 (13:50 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/e_dbus@47159 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/bluez/E_Bluez.h
src/lib/bluez/e_bluez_adapter.c
src/lib/bluez/e_bluez_device.c

index f3c99cc..87cc1a7 100644 (file)
@@ -40,6 +40,7 @@ extern "C" {
   extern int E_BLUEZ_EVENT_ELEMENT_DEL;
   extern int E_BLUEZ_EVENT_ELEMENT_UPDATED;
   extern int E_BLUEZ_EVENT_DEVICE_FOUND;
+  // TODO: extern int E_BLUEZ_EVENT_DEVICE_DISAPPEARED;
 
   typedef struct _E_Bluez_Element E_Bluez_Element;
   typedef struct _E_Bluez_Array E_Bluez_Array;
@@ -78,9 +79,9 @@ extern "C" {
 
   struct _E_Bluez_Device_Found
   {
-         E_Bluez_Element *adapter;
-         const char *name;
-         E_Bluez_Array *array;
+     E_Bluez_Element *adapter;
+     const char *name;
+     E_Bluez_Array *array;
   };
 
   /* General Public API */
@@ -92,28 +93,33 @@ extern "C" {
   EAPI Eina_Bool e_bluez_manager_default_adapter(E_DBus_Method_Return_Cb cb, void *data) EINA_WARN_UNUSED_RESULT;
 
   /* Adapter Methods */
-  EAPI Eina_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 Eina_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 Eina_Bool e_bluez_adapter_address_get(E_Bluez_Element *element, const char **address) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
-  EAPI Eina_Bool e_bluez_adapter_name_get(E_Bluez_Element *element, const char **name) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+  EAPI E_Bluez_Element *e_bluez_adapter_get(const char *path) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+
+  EAPI Eina_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, 2) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_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, 2) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_Bool e_bluez_adapter_address_get(const E_Bluez_Element *element, const char **address) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_Bool e_bluez_adapter_name_get(const E_Bluez_Element *element, const char **name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
   EAPI Eina_Bool e_bluez_adapter_name_set(E_Bluez_Element *element, const char *name, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1,2) EINA_WARN_UNUSED_RESULT;
-  EAPI Eina_Bool e_bluez_adapter_powered_get(E_Bluez_Element *element, Eina_Bool *powered) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_Bool e_bluez_adapter_powered_get(const E_Bluez_Element *element, Eina_Bool *powered) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
   EAPI Eina_Bool e_bluez_adapter_powered_set(E_Bluez_Element *profile, Eina_Bool powered, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
-  EAPI Eina_Bool e_bluez_adapter_discoverable_get(E_Bluez_Element *element, Eina_Bool *discoverable) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
-  EAPI Eina_Bool e_bluez_adapter_discoverable_set(E_Bluez_Element *profile, Eina_Bool discoverable, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_Bool e_bluez_adapter_discoverable_get(const E_Bluez_Element *element, Eina_Bool *discoverable) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_Bool e_bluez_adapter_discoverable_set(E_Bluez_Element *profile, Eina_Bool discoverable, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
   EAPI Eina_Bool e_bluez_adapter_discoverable_timeout_get(const E_Bluez_Element *element, unsigned int *timeout) EINA_ARG_NONNULL(1,2) EINA_WARN_UNUSED_RESULT;
   EAPI Eina_Bool e_bluez_adapter_discoverable_timeout_set(E_Bluez_Element *element, unsigned int timeout, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
-  EAPI Eina_Bool e_bluez_adapter_discovering_get(E_Bluez_Element *element, Eina_Bool *discovering) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_Bool e_bluez_adapter_discovering_get(const E_Bluez_Element *element, Eina_Bool *discovering) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
   EAPI Eina_Bool e_bluez_adapter_start_discovery(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
   EAPI Eina_Bool e_bluez_adapter_stop_discovery(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
-  EAPI Eina_Bool e_bluez_adapter_create_paired_device(E_Bluez_Element *element, const char *object_path, const char *capability, const char *device, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1,2,4) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_Bool e_bluez_adapter_create_paired_device(E_Bluez_Element *element, const char *object_path, const char *capability, const char *device, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT;
 
   /* Device Found Methods */
   EAPI void e_bluez_devicefound_free(E_Bluez_Device_Found *device) EINA_ARG_NONNULL(1);
   EAPI const char *e_bluez_devicefound_alias_get(const E_Bluez_Device_Found *device) EINA_ARG_NONNULL(1);
 
   /* Devices Methods */
-  EAPI Eina_Bool e_bluez_device_name_get(E_Bluez_Element *element, const char **name) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+  EAPI E_Bluez_Element *e_bluez_device_get(const char *path) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_Bool e_bluez_device_name_get(const E_Bluez_Element *element, const char **name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_Bool e_bluez_device_alias_get(const E_Bluez_Element *element, const char **alias) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
+  EAPI Eina_Bool e_bluez_device_paired_get(const E_Bluez_Element *element, Eina_Bool *paired) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
 
   /* Low-Level API:
    *
index 3f529fd..68af9ab 100644 (file)
@@ -1,5 +1,25 @@
 #include "e_bluez_private.h"
 
+E_Bluez_Element *
+e_bluez_adapter_get(const char *path)
+{
+   E_Bluez_Element *adapter;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL);
+
+   adapter = e_bluez_element_get(path);
+   if (!adapter)
+     return NULL;
+
+   if (!e_bluez_element_is_adapter(adapter))
+     {
+       WRN("path '%s' is not a adapter!", path);
+       return NULL;
+     }
+
+   return adapter;
+}
+
 static void
 _device_found_callback(void *data, DBusMessage *msg)
 {
@@ -69,6 +89,7 @@ e_bluez_adapter_agent_register(E_Bluez_Element *element, const char *object_path
 {
    const char name[] = "RegisterAgent";
 
+   EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, 0);
 
    return e_bluez_element_call_with_path_and_string
@@ -116,7 +137,7 @@ e_bluez_adapter_agent_unregister(E_Bluez_Element *element, const char *object_pa
  * @return 1 on success, 0 otherwise.
  */
 Eina_Bool
-e_bluez_adapter_address_get(E_Bluez_Element *element, const char **address)
+e_bluez_adapter_address_get(const E_Bluez_Element *element, const char **address)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0);
@@ -140,7 +161,7 @@ e_bluez_adapter_address_get(E_Bluez_Element *element, const char **address)
  * @return 1 on success, 0 otherwise.
  */
 Eina_Bool
-e_bluez_adapter_name_get(E_Bluez_Element *element, const char **name)
+e_bluez_adapter_name_get(const E_Bluez_Element *element, const char **name)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0);
@@ -185,7 +206,7 @@ e_bluez_adapter_name_set(E_Bluez_Element *element, const char *name, E_DBus_Meth
  * @see e_bluez_adapter_powered_set()
  */
 Eina_Bool
-e_bluez_adapter_powered_get(E_Bluez_Element *element, Eina_Bool *powered)
+e_bluez_adapter_powered_get(const E_Bluez_Element *element, Eina_Bool *powered)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(powered, 0);
@@ -227,7 +248,7 @@ e_bluez_adapter_powered_set(E_Bluez_Element *element, Eina_Bool powered, E_DBus_
  * @see e_bluez_adapter_discoverable_set()
  */
 Eina_Bool
-e_bluez_adapter_discoverable_get(E_Bluez_Element *element, Eina_Bool *discoverable)
+e_bluez_adapter_discoverable_get(const E_Bluez_Element *element, Eina_Bool *discoverable)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(discoverable, 0);
@@ -316,7 +337,7 @@ e_bluez_adapter_discoverable_timeout_set(E_Bluez_Element *element, unsigned int
  * @see e_bluez_adapter_discovering_set()
  */
 Eina_Bool
-e_bluez_adapter_discovering_get(E_Bluez_Element *element, Eina_Bool *discovering)
+e_bluez_adapter_discovering_get(const E_Bluez_Element *element, Eina_Bool *discovering)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(discovering, 0);
index 61c7be4..3f68c4a 100644 (file)
@@ -1,5 +1,25 @@
 #include "e_bluez_private.h"
 
+E_Bluez_Element *
+e_bluez_device_get(const char *path)
+{
+   E_Bluez_Element *device;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL);
+
+   device = e_bluez_element_get(path);
+   if (!device)
+     return NULL;
+
+   if (!e_bluez_element_is_device(device))
+     {
+       WRN("path '%s' is not a device!", path);
+       return NULL;
+     }
+
+   return device;
+}
+
 /**
  * Get property "Name" value.
  *
  * @return 1 on success, 0 otherwise.
  */
 Eina_Bool
-e_bluez_device_name_get(E_Bluez_Element *element, const char **name)
+e_bluez_device_name_get(const E_Bluez_Element *element, const char **name)
 {
+   EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0);
 
    return e_bluez_element_property_get_stringshared
      (element, e_bluez_prop_name, NULL, name);
 }
+
+/**
+ * Get property "Alias" 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.
+ */
+Eina_Bool
+e_bluez_device_alias_get(const E_Bluez_Element *element, const char **alias)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(alias, 0);
+
+   return e_bluez_element_property_get_stringshared
+     (element, e_bluez_prop_alias, NULL, alias);
+}
+
+/**
+ * Get property "Paired" 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 powered where to store the property value, must be a pointer
+ *        to boolean (Eina_Bool *).
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+Eina_Bool
+e_bluez_device_paired_get(const E_Bluez_Element *element, Eina_Bool *paired)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(paired, 0);
+
+   return e_bluez_element_property_get_stringshared
+     (element, e_bluez_prop_paired, NULL, paired);
+}