e_bluez_element_print(stderr, element);
return 1;
}
+
+static int
+_on_device_found(void *data, int type, void *info)
+{
+ E_Bluez_Device_Found *device = info;
+ printf("!!! %s\n", device->adapter->path);
+ printf(":::DeviceFound %s\n", device->name);
+ e_bluez_element_array_print(stderr, device->array);
+ printf("\n");
+
+ e_bluez_adapter_device_found_free(device);
+ return 1;
+}
+
static int
_on_cmd_quit(char *cmd, char *args)
{
ecore_event_handler_add(E_BLUEZ_EVENT_ELEMENT_DEL, _on_element_del, NULL);
ecore_event_handler_add(E_BLUEZ_EVENT_ELEMENT_UPDATED,
_on_element_updated, NULL);
+ ecore_event_handler_add(E_BLUEZ_EVENT_DEVICE_FOUND,
+ _on_device_found, NULL);
ecore_main_fd_handler_add
(0, ECORE_FD_READ | ECORE_FD_ERROR, _on_input, NULL, NULL, NULL);
extern int E_BLUEZ_EVENT_ELEMENT_ADD;
extern int E_BLUEZ_EVENT_ELEMENT_DEL;
extern int E_BLUEZ_EVENT_ELEMENT_UPDATED;
+ extern int E_BLUEZ_EVENT_DEVICE_FOUND;
typedef struct _E_Bluez_Element E_Bluez_Element;
+ typedef struct _E_Bluez_Array E_Bluez_Array;
+ typedef struct _E_Bluez_Device_Found E_Bluez_Device_Found;
struct _E_Bluez_Element
{
const char *path;
const char *interface;
E_DBus_Signal_Handler *signal_handler;
+ E_DBus_Signal_Handler *device_found_handler;
Eina_Inlist *props;
/* private */
int _references;
};
+ struct _E_Bluez_Array
+ {
+ int type;
+ Eina_Array *array;
+ };
+
+ struct _E_Bluez_Device_Found
+ {
+ E_Bluez_Element *adapter;
+ const char *name;
+ E_Bluez_Array *array;
+ };
+
/* General Public API */
EAPI unsigned int e_bluez_system_init(E_DBus_Connection *edbus_conn) EINA_ARG_NONNULL(1);
EAPI unsigned int e_bluez_system_shutdown(void);
EAPI bool e_bluez_manager_default_adapter(E_DBus_Method_Return_Cb cb, void *data) EINA_WARN_UNUSED_RESULT;
/* Adapter Methods */
+ EAPI void e_bluez_adapter_device_found_free(E_Bluez_Device_Found *device) EINA_ARG_NONNULL(1);
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 int e_bluez_element_unref(E_Bluez_Element *element) EINA_ARG_NONNULL(1);
EAPI void e_bluez_element_print(FILE *fp, const E_Bluez_Element *element) EINA_ARG_NONNULL(1, 2);
-
+ EAPI void e_bluez_element_array_print(FILE *fp, E_Bluez_Array *array);
EAPI bool e_bluez_element_properties_sync(E_Bluez_Element *element) EINA_ARG_NONNULL(1);
EAPI bool e_bluez_element_properties_sync_full(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1);
EAPI int E_BLUEZ_EVENT_ELEMENT_ADD = 0;
EAPI int E_BLUEZ_EVENT_ELEMENT_DEL = 0;
EAPI int E_BLUEZ_EVENT_ELEMENT_UPDATED = 0;
+EAPI int E_BLUEZ_EVENT_DEVICE_FOUND = 0;
const char *e_bluez_iface_manager = NULL;
const char *e_bluez_iface_adapter = NULL;
* - E_BLUEZ_EVENT_ELEMENT_DEL: element was deleted.
* - E_BLUEZ_EVENT_ELEMENT_UPDATED: element was updated (properties
* or state changed).
+ * - E_BLUEZ_EVENT_DEVICE_FOUND: a device was found, raised after calling
+ * Adapter.StartDiscorvery()
*
* Manager IN/OUT events do not provide any event information, just
* tells you that system is usable or not. After manager is out, all
E_BLUEZ_EVENT_ELEMENT_DEL = ecore_event_type_new();
if (E_BLUEZ_EVENT_ELEMENT_UPDATED == 0)
E_BLUEZ_EVENT_ELEMENT_UPDATED = ecore_event_type_new();
+ if (E_BLUEZ_EVENT_DEVICE_FOUND == 0)
+ E_BLUEZ_EVENT_DEVICE_FOUND = ecore_event_type_new();
if (e_bluez_iface_manager == NULL)
e_bluez_iface_manager = eina_stringshare_add("org.bluez.Manager");
#include "e_bluez_private.h"
+static void
+_device_found_callback(void *data, DBusMessage *msg)
+{
+ E_Bluez_Element *element = (E_Bluez_Element *)data;
+ E_Bluez_Device_Found *device;
+ DBusMessageIter itr;
+ int t;
+ char *name = NULL;
+ void *value = NULL;
+
+ DBG("Device found %s", element->path);
+
+ if (!_dbus_callback_check_and_init(msg, &itr, NULL))
+ return;
+
+ device = calloc(sizeof(E_Bluez_Device_Found), 1);
+ if (!device) {
+ ERR("No memory to alocate E_Bluez_Device_Found");
+ return;
+ }
+
+ t = dbus_message_iter_get_arg_type(&itr);
+ if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
+ {
+ ERR("missing device name in DeviceFound");
+ return;
+ }
+ dbus_message_iter_get_basic(&itr, &name);
+
+ dbus_message_iter_next(&itr);
+ t = dbus_message_iter_get_arg_type(&itr);
+ if (!_dbus_iter_type_check(t, DBUS_TYPE_ARRAY))
+ {
+ ERR("missing array in DeviceFound");
+ return;
+ }
+
+ value = e_bluez_element_iter_get_array(&itr, name);
+
+ if (!value)
+ return;
+
+ device->name = eina_stringshare_add(name);
+ device->adapter = element;
+ device->array = value;
+
+ ecore_event_add(E_BLUEZ_EVENT_DEVICE_FOUND, device, NULL, NULL);
+}
+
+/**
+ * Free a E_Bluez_Device_Found struct
+ *
+ * @param device the struct to be freed
+ */
+void
+e_bluez_adapter_device_found_free(E_Bluez_Device_Found *device)
+{
+ EINA_SAFETY_ON_NULL_RETURN(device);
+
+ eina_stringshare_del(device->name);
+ e_bluez_element_array_free(device->array, NULL);
+}
+
/**
* Register new agent for handling user requests.
*
EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
+ element->device_found_handler =
+ e_dbus_signal_handler_add
+ (e_bluez_conn, e_bluez_system_bus_name_get(),
+ element->path, element->interface, "DeviceFound",
+ _device_found_callback, element);
+
return e_bluez_element_call_full(element, name, NULL,
&element->_pending.start_discovery, cb, data);
}
static Eina_Hash *elements = NULL;
-typedef struct _E_Bluez_Array E_Bluez_Array;
typedef struct _E_Bluez_Element_Pending E_Bluez_Element_Pending;
typedef struct _E_Bluez_Element_Call_Data E_Bluez_Element_Call_Data;
typedef struct _E_Bluez_Element_Property E_Bluez_Element_Property;
typedef struct _E_Bluez_Element_Listener E_Bluez_Element_Listener;
typedef struct _E_Bluez_Element_Dict_Entry E_Bluez_Element_Dict_Entry;
-struct _E_Bluez_Array
-{
- int type;
- Eina_Array *array;
-};
-
struct _E_Bluez_Element_Pending
{
EINA_INLIST;
union {
bool boolean;
const char *str;
+ short i16;
unsigned short u16;
unsigned int u32;
unsigned char byte;
e_bluez_element_unref(element);
}
-static void
+void
e_bluez_element_event_add(int event_type, E_Bluez_Element *element)
{
e_bluez_element_ref(element);
{
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_BYTE:
+ case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
case DBUS_TYPE_UINT32:
break;
case DBUS_TYPE_BYTE:
entry->value.byte = (unsigned char)(long)value;
break;
+ case DBUS_TYPE_INT16:
+ entry->value.i16 = (short)(long)value;
+ break;
case DBUS_TYPE_UINT16:
entry->value.u16 = (unsigned short)(long)value;
break;
return NULL;
}
-static void
-_e_bluez_element_array_free(E_Bluez_Array *array, E_Bluez_Array *new __UNUSED__)
+void
+e_bluez_element_array_free(E_Bluez_Array *array, E_Bluez_Array *new __UNUSED__)
{
Eina_Array_Iterator iterator;
unsigned int i;
{
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_BYTE:
+ case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
case DBUS_TYPE_UINT32:
break;
eina_stringshare_del(property->value.path);
break;
case DBUS_TYPE_ARRAY:
- _e_bluez_element_array_free(property->value.array, NULL);
+ e_bluez_element_array_free(property->value.array, NULL);
break;
default:
ERR("don't know how to free value of property type %c (%d)",
if (property->value.array)
{
_e_bluez_element_array_match(property->value.array, data, property->name);
- _e_bluez_element_array_free(property->value.array, data);
+ e_bluez_element_array_free(property->value.array, data);
}
property->value.array = data;
changed = 1;
return 1;
}
-static void
-_e_bluez_element_array_print(FILE *fp, E_Bluez_Array *array)
+void
+e_bluez_element_array_print(FILE *fp, E_Bluez_Array *array)
{
Eina_Array_Iterator iterator;
unsigned int i;
case DBUS_TYPE_STRING:
fprintf(fp, "\"%s\", ", entry->value.str);
break;
+ case DBUS_TYPE_BOOLEAN:
+ fprintf(fp, "%hhu, ",
+ entry->value.boolean);
+ break;
case DBUS_TYPE_BYTE:
fprintf(fp, "%#02hhx (\"%c\"), ",
entry->value.byte, entry->value.byte);
break;
+ case DBUS_TYPE_INT16:
+ fprintf(fp, "%#04hx (%hi), ",
+ entry->value.i16, entry->value.i16);
+ break;
case DBUS_TYPE_UINT16:
fprintf(fp, "%#04hx (%hu), ",
entry->value.u16, entry->value.u16);
fprintf(fp, "%u", p->value.u32);
break;
case DBUS_TYPE_ARRAY:
- _e_bluez_element_array_print(fp, p->value.array);
+ e_bluez_element_array_print(fp, p->value.array);
break;
default:
fputs("don't know how to print type", fp);
return 1;
}
-static E_Bluez_Array *
-_e_bluez_element_iter_get_array(DBusMessageIter *itr, const char *key)
+E_Bluez_Array *
+e_bluez_element_iter_get_array(DBusMessageIter *itr, const char *key)
{
E_Bluez_Array *array;
DBusMessageIter e_itr;
dbus_message_iter_recurse(&e_itr, &v_itr);
t = dbus_message_iter_get_arg_type(&v_itr);
if (t == DBUS_TYPE_ARRAY)
- value = _e_bluez_element_iter_get_array(&v_itr, key);
+ value = e_bluez_element_iter_get_array(&v_itr, key);
else if (t != DBUS_TYPE_INVALID) {
dbus_message_iter_get_basic(&v_itr, &value);
} else {
case DBUS_TYPE_BYTE:
*(unsigned char *)value = entry->value.byte;
return 1;
+ case DBUS_TYPE_INT16:
+ *(short *)value = entry->value.i16;
+ return 1;
case DBUS_TYPE_UINT16:
*(unsigned short *)value = entry->value.u16;
return 1;
t = dbus_message_iter_get_arg_type(&v_itr);
if (t == DBUS_TYPE_ARRAY)
- value = _e_bluez_element_iter_get_array(&v_itr, name);
+ value = e_bluez_element_iter_get_array(&v_itr, name);
else if (t != DBUS_TYPE_INVALID)
dbus_message_iter_get_basic(&v_itr, &value);
else
void e_bluez_element_unregister(E_Bluez_Element *element);
bool e_bluez_element_message_send(E_Bluez_Element *element, const char *method_name, E_DBus_Method_Return_Cb cb, DBusMessage *msg, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data);
+E_Bluez_Array *e_bluez_element_iter_get_array(DBusMessageIter *itr, const char *key);
+void e_bluez_element_event_add(int event_type, E_Bluez_Element *element);
+void e_bluez_element_array_free(E_Bluez_Array *array, E_Bluez_Array *new __UNUSED__);
bool e_bluez_element_call_full(E_Bluez_Element *element, const char *method_name, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data);
bool e_bluez_element_call_with_path(E_Bluez_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data);