bluez5 support - a new module with gadget etc.

Summary:
bluez4 support is now basically dead. nothing ships it anymore. bluez5
is a new api that is rather different so new code. also a new gui with
more complete features etc.

not everything is done as i'd like. need:

1. many more icons for device types (60-70 maybe?)
2. a few specific custom icons for some action buttons (like
pair/unpair)
3. icons for group headers
4. gadget status - the gagdte itself displays zero status. it's a
button to display a popup. that's all.

Reviewers: zmike!

Subscribers: devilhorns, cedric

Tags: #enlightenment-git

Differential Revision: https://phab.enlightenment.org/D6148
This commit is contained in:
Carsten Haitzler 2018-05-10 13:52:06 +09:00
parent 05d3f2d393
commit 2e5be79c45
17 changed files with 3008 additions and 1 deletions

View File

@ -111,6 +111,10 @@ option('bluez4',
type: 'boolean',
value: true,
description: 'enable bluez4 module: (default=true)')
option('bluez5',
type: 'boolean',
value: true,
description: 'enable bluez5 module: (default=true)')
option('clock',
type: 'boolean',
value: true,

View File

@ -1525,6 +1525,44 @@ e_config_load(void)
CONFIG_VERSION_UPDATE_INFO(25);
e_config_save_queue();
}
CONFIG_VERSION_CHECK(26)
{
// move from bluez4 to bluez5 automatically. you can manually
// move back if that works better for you...
Eina_List *l, *ll;
E_Config_Module *em;
E_Config_Gadcon *gc;
E_Config_Gadcon_Client *gcc;
EINA_LIST_FOREACH(e_config->modules, l, em)
{
if (!em->enabled) continue;
if (!em->name) continue;
if (eina_streq(em->name, "bluez4"))
{
eina_stringshare_replace(&(em->name), "bluez5");
}
}
EINA_LIST_FOREACH(e_config->gadcons, l, gc)
{
EINA_LIST_FOREACH(gc->clients, ll, gcc)
{
if (!gcc->name) continue;
if (!strncmp(gcc->name, "bluez4", 6))
{
char *tmp = strdup(gcc->name);
if (tmp)
{
tmp[5] = '5';
eina_stringshare_replace(&(gcc->name), tmp);
free(tmp);
}
}
}
}
CONFIG_VERSION_UPDATE_INFO(26);
e_config_save_queue();
}
}
elm_config_profile_set(_e_config_profile);
if (!e_config->remember_internal_fm_windows)

View File

@ -46,7 +46,7 @@ typedef enum
/* increment this whenever a new set of config values are added but the users
* config doesn't need to be wiped - simply new values need to be put in
*/
#define E_CONFIG_FILE_GENERATION 25
#define E_CONFIG_FILE_GENERATION 26
#define E_CONFIG_FILE_VERSION ((E_CONFIG_FILE_EPOCH * 1000000) + E_CONFIG_FILE_GENERATION)
#define E_CONFIG_BINDINGS_VERSION 0 // DO NOT INCREMENT UNLESS YOU WANT TO WIPE ALL BINDINGS!!!!!

View File

@ -997,6 +997,7 @@ _e_module_whitelist_check(void)
"backlight",
"battery",
"bluez4",
"bluez5",
"clock",
"conf",
"conf_applications",

109
src/modules/bluez5/bz.c Normal file
View File

@ -0,0 +1,109 @@
#include "e_mod_main.h"
Eldbus_Connection *bz_conn = NULL;
static Ecore_Timer *owner_gain_timer = NULL;
/////////////////////////////////////////////////////////////////////////////
static Eina_Bool
cb_name_owner_new(void *data EINA_UNUSED)
{
owner_gain_timer = NULL;
bz_obj_init();
bz_agent_init();
return EINA_FALSE;
}
static void
cb_name_owner_changed(void *data EINA_UNUSED,
const char *bus EINA_UNUSED,
const char *from EINA_UNUSED,
const char *to)
{
static Eina_Bool first = EINA_TRUE;
if (to[0])
{
if (owner_gain_timer) ecore_timer_del(owner_gain_timer);
// on first start try and re-init quickly because we get a name
// owner change even if all is good when we register to listen for it,
// so start fast
if (first)
owner_gain_timer = ecore_timer_add(0.1, cb_name_owner_new, NULL);
// but if we gegt a name owner change later it's probably because
// bluez was restarted or crashed. a new bz daemon will (or should)
// come up. so re-init more slowly here giving the daemon some time
// to come up before pestering it.
else
owner_gain_timer = ecore_timer_add(1.0, cb_name_owner_new, NULL);
first = EINA_FALSE;
}
else
{
if (owner_gain_timer) ecore_timer_del(owner_gain_timer);
owner_gain_timer = NULL;
ebluze5_popup_clear();
bz_agent_shutdown();
bz_obj_shutdown();
}
}
static void
cb_obj_add(Obj *o)
{
if (o->type == BZ_OBJ_ADAPTER)
{
o->fn_change = ebluez5_popup_adapter_change;
o->fn_del = ebluez5_popup_adapter_del;
ebluez5_popup_adapter_add(o);
return;
}
if (o->type == BZ_OBJ_DEVICE)
{
o->fn_change = ebluez5_popup_device_change;
o->fn_del = ebluez5_popup_device_del;
ebluez5_popup_device_add(o);
return;
}
}
void
bz_init(void)
{
bz_conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
bz_obj_add_func_set(cb_obj_add);
bz_agent_release_func_set(ebluez5_agent_agent_release);
bz_agent_cancel_func_set(ebluez5_agent_agent_cancel);
bz_agent_req_pin_func_set(ebluez5_agent_agent_req_pin);
bz_agent_disp_pin_func_set(ebluez5_agent_agent_disp_pin);
bz_agent_req_pass_func_set(ebluez5_agent_req_pass);
bz_agent_disp_pass_func_set(ebluez5_agent_disp_pass);
bz_agent_req_confirm_func_set(ebluez5_agent_req_confirm);
bz_agent_req_auth_func_set(ebluez5_agent_req_auth);
bz_agent_auth_service_func_set(ebluez5_agent_auth_service);
eldbus_name_owner_changed_callback_add(bz_conn, "org.bluez",
cb_name_owner_changed,
NULL, EINA_TRUE);
}
void
bz_shutdown(void)
{
eldbus_name_owner_changed_callback_del(bz_conn, "org.bluez",
cb_name_owner_changed, NULL);
bz_agent_release_func_set(NULL);
bz_agent_cancel_func_set(NULL);
bz_agent_req_pin_func_set(NULL);
bz_agent_disp_pin_func_set(NULL);
bz_agent_req_pass_func_set(NULL);
bz_agent_disp_pass_func_set(NULL);
bz_agent_req_confirm_func_set(NULL);
bz_agent_req_auth_func_set(NULL);
bz_agent_auth_service_func_set(NULL);
bz_obj_add_func_set(NULL);
ebluze5_popup_clear();
bz_agent_shutdown();
bz_obj_shutdown();
eldbus_connection_unref(bz_conn);
bz_conn = NULL;
}

234
src/modules/bluez5/bz.h Normal file
View File

@ -0,0 +1,234 @@
#ifndef BZ_H
# define BZ_H
# include <Elementary.h>
typedef enum {
BZ_OBJ_UNKNOWN,
BZ_OBJ_BLUEZ,
BZ_OBJ_ADAPTER,
BZ_OBJ_DEVICE
} Obj_Type;
typedef struct _Obj Obj;
struct _Obj {
//// internal object data
Eldbus_Proxy *proxy;
Eldbus_Proxy *prop_proxy;
Eldbus_Signal_Handler *prop_sig;
unsigned int ref;
Eina_Bool in_table : 1;
Eina_Bool add_called : 1;
//// public data to read
const char *path;
Obj_Type type;
//// data to be set by users of the obj
void *data; // custom data
void (*fn_change) (Obj *o);
void (*fn_del) (Obj *o);
//// obj properties
Eina_Array *uuids;
const char *address;
const char *address_type;
const char *name;
const char *icon;
const char *alias;
const char *adapter;
const char *modalias;
unsigned int klass;
unsigned short appearance;
unsigned short txpower;
short rssi;
Eina_Bool paired : 1;
Eina_Bool connected : 1;
Eina_Bool trusted : 1;
Eina_Bool blocked : 1;
Eina_Bool legacy_pairing : 1;
Eina_Bool services_resolved : 1;
//// adapter specific properties
unsigned int discoverable_timeout;
unsigned int pairable_timeout;
Eina_Bool discoverable : 1;
Eina_Bool discovering : 1;
Eina_Bool pairable : 1;
Eina_Bool powered : 1;
//// agent data for when devices ask to pair etc.
const char *agent_request;
Eldbus_Message *agent_msg_ok;
Eldbus_Message *agent_msg_err;
void (*agent_entry_fn) (Eldbus_Message *msg, const char *str);
Eina_Bool agent_alert : 1;
};
#define BZ_OBJ_CLASS_SERVICE_LIMITED_DISCOVERABLE (1 << 13)
#define BZ_OBJ_CLASS_SERVICE_POSITIONING_BIT (1 << 16)
#define BZ_OBJ_CLASS_SERVICE_NETWORKING_BIT (1 << 17)
#define BZ_OBJ_CLASS_SERVICE_RENDERING_BIT (1 << 18)
#define BZ_OBJ_CLASS_SERVICE_CAPTURING_BIT (1 << 19)
#define BZ_OBJ_CLASS_SERVICE_OBJECT_TRANSFER_BIT (1 << 20)
#define BZ_OBJ_CLASS_SERVICE_AUDIO_BIT (1 << 21)
#define BZ_OBJ_CLASS_SERVICE_TELEPHONY_BIT (1 << 22)
#define BZ_OBJ_CLASS_SERVICE_INFORMATION_BIT (1 << 23)
#define BZ_OBJ_CLASS_MAJ_MASK (0x1f << 8)
#define BZ_OBJ_CLASS_MAJ_MISC ( 0 << 8)
#define BZ_OBJ_CLASS_MAJ_COMPUTER ( 1 << 8)
#define BZ_OBJ_CLASS_MAJ_PHONE ( 2 << 8)
#define BZ_OBJ_CLASS_MAJ_LAN ( 3 << 8)
#define BZ_OBJ_CLASS_MAJ_AV ( 4 << 8)
#define BZ_OBJ_CLASS_MAJ_PERIPHERAL ( 5 << 8)
#define BZ_OBJ_CLASS_MAJ_IMAGING ( 6 << 8)
#define BZ_OBJ_CLASS_MAJ_WEARABLE ( 7 << 8)
#define BZ_OBJ_CLASS_MAJ_TOY ( 8 << 8)
#define BZ_OBJ_CLASS_MAJ_HEALTH ( 9 << 8)
#define BZ_OBJ_CLASS_MIN_COMPUTER_MASK (0x3f << 2)
#define BZ_OBJ_CLASS_MIN_COMPUTER_DESKTOP ( 1 << 2)
#define BZ_OBJ_CLASS_MIN_COMPUTER_SERVER ( 2 << 2)
#define BZ_OBJ_CLASS_MIN_COMPUTER_LAPTOP ( 3 << 2)
#define BZ_OBJ_CLASS_MIN_COMPUTER_CLAMSHELL ( 4 << 2)
#define BZ_OBJ_CLASS_MIN_COMPUTER_PDA ( 5 << 2)
#define BZ_OBJ_CLASS_MIN_COMPUTER_WEARABLE ( 6 << 2)
#define BZ_OBJ_CLASS_MIN_COMPUTER_TABLET ( 7 << 2)
#define BZ_OBJ_CLASS_MIN_PHONE_MASK (0x3f << 2)
#define BZ_OBJ_CLASS_MIN_PHONE_CELL ( 1 << 2)
#define BZ_OBJ_CLASS_MIN_PHONE_CORDLESS ( 2 << 2)
#define BZ_OBJ_CLASS_MIN_PHONE_SMARTPHONE ( 3 << 2)
#define BZ_OBJ_CLASS_MIN_PHONE_WIRED ( 4 << 2)
#define BZ_OBJ_CLASS_MIN_PHONE_ISDN ( 5 << 2)
#define BZ_OBJ_CLASS_MIN_LAN_MASK (0x07 << 5)
#define BZ_OBJ_CLASS_MIN_LAN_AVAIL_7 ( 0 << 5)
#define BZ_OBJ_CLASS_MIN_LAN_AVAIL_6 ( 1 << 5)
#define BZ_OBJ_CLASS_MIN_LAN_AVAIL_5 ( 2 << 5)
#define BZ_OBJ_CLASS_MIN_LAN_AVAIL_4 ( 3 << 5)
#define BZ_OBJ_CLASS_MIN_LAN_AVAIL_3 ( 4 << 5)
#define BZ_OBJ_CLASS_MIN_LAN_AVAIL_2 ( 5 << 5)
#define BZ_OBJ_CLASS_MIN_LAN_AVAIL_1 ( 6 << 5)
#define BZ_OBJ_CLASS_MIN_LAN_AVAIL_0 ( 7 << 5)
#define BZ_OBJ_CLASS_MIN_AV_MASK (0x3f << 2)
#define BZ_OBJ_CLASS_MIN_AV_WEARABLE_HEADSET ( 1 << 2)
#define BZ_OBJ_CLASS_MIN_AV_HANDS_FREE ( 2 << 2)
#define BZ_OBJ_CLASS_MIN_AV_MIC ( 4 << 2)
#define BZ_OBJ_CLASS_MIN_AV_SPEAKER ( 5 << 2)
#define BZ_OBJ_CLASS_MIN_AV_HEADPHONES ( 6 << 2)
#define BZ_OBJ_CLASS_MIN_AV_PORTABLE_AUDIO ( 7 << 2)
#define BZ_OBJ_CLASS_MIN_AV_CAR_AUDIO ( 8 << 2)
#define BZ_OBJ_CLASS_MIN_AV_SET_TOP_BOX ( 9 << 2)
#define BZ_OBJ_CLASS_MIN_AV_HIFI_AUDIO (10 << 2)
#define BZ_OBJ_CLASS_MIN_AV_VCR (11 << 2)
#define BZ_OBJ_CLASS_MIN_AV_VIDEO_CAMERA (12 << 2)
#define BZ_OBJ_CLASS_MIN_AV_CAMCORDER (13 << 2)
#define BZ_OBJ_CLASS_MIN_AV_VIDEO_MONITOR (14 << 2)
#define BZ_OBJ_CLASS_MIN_AV_VIDEO_DISPLAY_SPEAKER (15 << 2)
#define BZ_OBJ_CLASS_MIN_AV_VIDEO_CONFERENCE (16 << 2)
#define BZ_OBJ_CLASS_MIN_AV_GAMING (18 << 2)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_KEYBOARD_BIT ( 1 << 6)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_MOUSE_BIT ( 1 << 7)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_MASK2 (0x0f << 2)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_JOYSTICK ( 1 << 2)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_GAMEPAD ( 2 << 2)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_REMOTE ( 3 << 2)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_SENSING ( 4 << 2)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_DIGITIZER_TAB ( 5 << 2)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_CARD_READER ( 6 << 2)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_PEN ( 7 << 2)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_SCANNER ( 8 << 2)
#define BZ_OBJ_CLASS_MIN_PERIPHERAL_WAND ( 9 << 2)
#define BZ_OBJ_CLASS_MIN_IMAGING_DISPLAY_BIT ( 1 << 4)
#define BZ_OBJ_CLASS_MIN_IMAGING_CAMERA_BIT ( 1 << 5)
#define BZ_OBJ_CLASS_MIN_IMAGING_SCANNER_BIT ( 1 << 6)
#define BZ_OBJ_CLASS_MIN_IMAGING_PRINTER_BIT ( 1 << 7)
#define BZ_OBJ_CLASS_MIN_WEARABLE_MASK (0x3f << 2)
#define BZ_OBJ_CLASS_MIN_WEARABLE_WATCH ( 1 << 2)
#define BZ_OBJ_CLASS_MIN_WEARABLE_PAGER ( 2 << 2)
#define BZ_OBJ_CLASS_MIN_WEARABLE_JACKET ( 3 << 2)
#define BZ_OBJ_CLASS_MIN_WEARABLE_HELMET ( 4 << 2)
#define BZ_OBJ_CLASS_MIN_WEARABLE_GLASSES ( 5 << 2)
#define BZ_OBJ_CLASS_MIN_TOY_MASK (0x3f << 2)
#define BZ_OBJ_CLASS_MIN_TOY_ROBOT ( 1 << 2)
#define BZ_OBJ_CLASS_MIN_TOY_VEHICLE ( 2 << 2)
#define BZ_OBJ_CLASS_MIN_TOY_DOLL ( 3 << 2)
#define BZ_OBJ_CLASS_MIN_TOY_CONTROLLER ( 4 << 2)
#define BZ_OBJ_CLASS_MIN_TOY_GAME ( 5 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_MASK (0x3f << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_BLOOD_PRESSURE ( 1 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_THERMOMETER ( 2 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_SCALES ( 3 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_GLUCOSE ( 4 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_PULSE_OXIMITER ( 5 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_HEART_RATE ( 6 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_HEALTH_DATA_DISP ( 7 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_STEP ( 8 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_BODY_COMPOSITION ( 9 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_PEAK_FLOW (10 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_MEDICATION (11 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_KNEE_PROSTHESIS (12 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_ANKLE_PROSTHESIS (13 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_GENERIC_HEALTH (14 << 2)
#define BZ_OBJ_CLASS_MIN_HEALTH_PRESONAL_MOBILITY (15 << 2)
extern Eldbus_Connection *bz_conn;
void bz_init(void);
void bz_shutdown(void);
Obj *bz_obj_add(const char *path);
Obj *bz_obj_find(const char *path);
void bz_obj_power_on(Obj *o);
void bz_obj_power_off(Obj *o);
void bz_obj_discoverable(Obj *o);
void bz_obj_undiscoverable(Obj *o);
void bz_obj_pairable(Obj *o);
void bz_obj_unpairable(Obj *o);
void bz_obj_trust(Obj *o);
void bz_obj_distrust(Obj *o);
void bz_obj_pair(Obj *o);
void bz_obj_pair_cancel(Obj *o);
void bz_obj_connect(Obj *o);
void bz_obj_disconnect(Obj *o);
void bz_obj_remove(Obj *o);
void bz_obj_profile_connect(Obj *o, const char *uuid);
void bz_obj_profile_disconnect(Obj *o, const char *uuid);
void bz_obj_ref(Obj *o);
void bz_obj_unref(Obj *o);
void bz_obj_discover_start(Obj *o);
void bz_obj_discover_stop(Obj *o);
void bz_obj_agent_request(Obj *o, const char *req, void (*fn) (Eldbus_Message *msg, const char *str), Eldbus_Message *ok_msg, Eldbus_Message *err_msg);
void bz_obj_init(void);
void bz_obj_shutdown(void);
void bz_obj_add_func_set(void (*fn) (Obj *o));
void bz_agent_msg_reply(Eldbus_Message *msg);
void bz_agent_msg_drop(Eldbus_Message *msg);
Eldbus_Message *bz_agent_msg_err(Eldbus_Message *msg);
Eldbus_Message *bz_agent_msg_ok(Eldbus_Message *msg);
const char *bz_agent_msg_path(Eldbus_Message *msg);
const char *bz_agent_msg_path_str(Eldbus_Message *msg, const char **str);
const char *bz_agent_msg_path_u32(Eldbus_Message *msg, unsigned int *u32);
const char *bz_agent_msg_path_u32_u16(Eldbus_Message *msg, unsigned int *u32, unsigned short *u16);
void bz_agent_msg_str_add(Eldbus_Message *msg, const char *str);
void bz_agent_msg_u32_add(Eldbus_Message *msg, unsigned int u32);
void bz_agent_init(void);
void bz_agent_shutdown(void);
void bz_agent_release_func_set(void (*fn) (void));
void bz_agent_cancel_func_set(void (*fn) (void));
void bz_agent_req_pin_func_set(void (*fn) (Eldbus_Message *msg));
void bz_agent_disp_pin_func_set(void (*fn) (Eldbus_Message *msg));
void bz_agent_req_pass_func_set(void (*fn) (Eldbus_Message *msg));
void bz_agent_disp_pass_func_set(void (*fn) (Eldbus_Message *msg));
void bz_agent_req_confirm_func_set(void (*fn) (Eldbus_Message *msg));
void bz_agent_req_auth_func_set(void (*fn) (Eldbus_Message *msg));
void bz_agent_auth_service_func_set(void (*fn) (Eldbus_Message *msg));
#endif

View File

@ -0,0 +1,346 @@
#include "bz.h"
#include "e.h"
static Eldbus_Service_Interface *agent_iface = NULL;
static Eldbus_Proxy *agent_proxy = NULL;
static void (*fn_release) (void) = NULL;
static void (*fn_cancel) (void) = NULL;
static void (*fn_req_pin) (Eldbus_Message *msg) = NULL;
static void (*fn_disp_pin) (Eldbus_Message *msg) = NULL;
static void (*fn_req_pass) (Eldbus_Message *msg) = NULL;
static void (*fn_disp_pass) (Eldbus_Message *msg) = NULL;
static void (*fn_req_confirm) (Eldbus_Message *msg) = NULL;
static void (*fn_req_auth) (Eldbus_Message *msg) = NULL;
static void (*fn_auth_service) (Eldbus_Message *msg) = NULL;
static Eldbus_Message *
cb_agent_release(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *msg)
{
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
if (fn_release) fn_release();
return reply;
}
static Eldbus_Message *
cb_agent_cancel(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *msg)
{
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
if (fn_cancel) fn_cancel();
return reply;
}
static Eldbus_Message *
cb_agent_request_pin_code(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *msg)
{
if (fn_req_pin) fn_req_pin((Eldbus_Message *)msg);
return NULL;
}
static Eldbus_Message *
cb_agent_display_pin_code(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *msg)
{
if (fn_disp_pin) fn_disp_pin((Eldbus_Message *)msg);
return NULL;
}
static Eldbus_Message *
cb_agent_request_pass_key(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *msg)
{
if (fn_req_pass) fn_req_pass((Eldbus_Message *)msg);
return NULL;
}
static Eldbus_Message *
cb_agent_display_pass_key(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *msg)
{
if (fn_disp_pass) fn_disp_pass((Eldbus_Message *)msg);
return NULL;
}
static Eldbus_Message *
cb_agent_request_confirmation(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *msg)
{
if (fn_req_confirm) fn_req_confirm((Eldbus_Message *)msg);
return NULL;
}
static Eldbus_Message *
cb_agent_request_authorization(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *msg)
{
if (fn_req_auth) fn_req_auth((Eldbus_Message *)msg);
return NULL;
}
static Eldbus_Message *
cb_agent_authorize_service(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *msg)
{
if (fn_auth_service) fn_auth_service((Eldbus_Message *)msg);
return NULL;
/* Not done yet... don't even know what services are with bt...
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
const char *path = NULL, *uuid = NULL;
printf("Agent authorize service\n");
if (!eldbus_message_arguments_get(msg, "os", &path, &uuid)) return reply;
printf(" %s %s\n", path, uuid);
// if ok return this reply, or make it an error...
// reply = eldbus_message_error_new(msg, "org.bluez.Error.Rejected", "");
return reply;
// really return NULL and defer above reply with:
// eldbus_connection_send(bz_conn, reply, NULL, NULL, -1);
*/
}
static void
cb_default(void *data EINA_UNUSED, const Eldbus_Message *msg,
Eldbus_Pending *pending EINA_UNUSED)
{
const char *name, *text;
if (eldbus_message_error_get(msg, &name, &text))
{
// XXX: should have a visual e log...
e_util_dialog_show(_("Bluetooth"),
_("Could not register default agent:<br>%s %s"),
name, text);
return;
}
}
static void
cb_register(void *data EINA_UNUSED, const Eldbus_Message *msg,
Eldbus_Pending *pending EINA_UNUSED)
{
const char *name, *text;
if (eldbus_message_error_get(msg, &name, &text))
{
// XXX: should have a visual e log...
e_util_dialog_show(_("Bluetooth"),
_("Could not register agent:<br>%s %s\n"),
name, text);
return;
}
if (!agent_proxy) return;
eldbus_proxy_call(agent_proxy, "RequestDefaultAgent",
cb_default, NULL, -1,
"o", "/org/enlightenment/bluez5/agent");
}
static void
cb_unregister(void *data EINA_UNUSED, const Eldbus_Message *msg,
Eldbus_Pending *pending EINA_UNUSED)
{
const char *name, *text;
if (agent_proxy)
{
eldbus_proxy_unref(agent_proxy);
agent_proxy = NULL;
}
if (agent_iface)
{
eldbus_service_object_unregister(agent_iface);
agent_iface = NULL;
}
if (eldbus_message_error_get(msg, &name, &text))
{
// just debug for developers
printf("Could not unregister agent.\n %s:\n %s\n", name, text);
return;
}
}
static const Eldbus_Method agent_methods[] = {
{ "Release", NULL, NULL, cb_agent_release, 0 },
{ "RequestPinCode", ELDBUS_ARGS({ "o", "device" }), ELDBUS_ARGS({ "s", "pincode" }), cb_agent_request_pin_code, 0 },
{ "DisplayPinCode", ELDBUS_ARGS({ "o", "device" }, { "s", "pincode" }), NULL, cb_agent_display_pin_code, 0 },
{ "RequestPasskey", ELDBUS_ARGS({ "o", "device" }), ELDBUS_ARGS({ "u", "passkey" }), cb_agent_request_pass_key, 0 },
{ "DisplayPasskey", ELDBUS_ARGS({ "o", "device" }, { "u", "passkey" }, { "q", "entered" }), NULL, cb_agent_display_pass_key, 0 },
{ "RequestConfirmation", ELDBUS_ARGS({ "o", "device" }, { "u", "passkey" }), NULL, cb_agent_request_confirmation, 0 },
{ "RequestAuthorization", ELDBUS_ARGS({ "o", "device" }), NULL, cb_agent_request_authorization, 0 },
{ "AuthorizeService", ELDBUS_ARGS({ "o", "device" }, { "s", "uuid" }), NULL, cb_agent_authorize_service, 0 },
{ "Cancel", NULL, NULL, cb_agent_cancel, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
static const Eldbus_Service_Interface_Desc agent_desc = {
"org.bluez.Agent1", agent_methods, NULL, NULL, NULL, NULL
};
void
bz_agent_msg_reply(Eldbus_Message *msg)
{
if (!bz_conn)
{
eldbus_message_unref(msg);
return;
}
eldbus_connection_send(bz_conn, msg, NULL, NULL, -1);
}
void
bz_agent_msg_drop(Eldbus_Message *msg)
{
eldbus_message_unref(msg);
}
Eldbus_Message *
bz_agent_msg_err(Eldbus_Message *msg)
{
return eldbus_message_error_new(msg, "org.bluez.Error.Rejected", "");
}
Eldbus_Message *
bz_agent_msg_ok(Eldbus_Message *msg)
{
return eldbus_message_method_return_new(msg);
}
const char *
bz_agent_msg_path(Eldbus_Message *msg)
{
const char *s = NULL;
if (!eldbus_message_arguments_get(msg, "o", &s)) return NULL;
return s;
}
const char *
bz_agent_msg_path_str(Eldbus_Message *msg, const char **str)
{
const char *s = NULL, *s2 = NULL;
if (!eldbus_message_arguments_get(msg, "os", &s, &s2)) return NULL;
if (str) *str = s2;
return s;
}
const char *
bz_agent_msg_path_u32(Eldbus_Message *msg, unsigned int *u32)
{
const char *s = NULL;
unsigned int uu32 = 0;
if (!eldbus_message_arguments_get(msg, "ou", &s, &uu32)) return NULL;
if (u32) *u32 = uu32;
return s;
}
const char *
bz_agent_msg_path_u32_u16(Eldbus_Message *msg, unsigned int *u32, unsigned short *u16)
{
const char *s = NULL;
unsigned int uu32 = 0;
unsigned short uu16 = 0;
if (!eldbus_message_arguments_get(msg, "ouq", &s, &uu32, &uu16)) return NULL;
if (u32) *u32 = uu32;
if (u16) *u16 = uu16;
return s;
}
void
bz_agent_msg_str_add(Eldbus_Message *msg, const char *str)
{
eldbus_message_arguments_append(msg, "s", str);
}
void
bz_agent_msg_u32_add(Eldbus_Message *msg, unsigned int u32)
{
eldbus_message_arguments_append(msg, "u", &u32);
}
void
bz_agent_init(void)
{
Eldbus_Object *obj;
obj = eldbus_object_get(bz_conn, "org.bluez", "/org/bluez");
agent_proxy = eldbus_proxy_get(obj, "org.bluez.AgentManager1");
agent_iface = eldbus_service_interface_register
(bz_conn, "/org/enlightenment/bluez5/agent", &agent_desc);
if (agent_proxy)
eldbus_proxy_call(agent_proxy, "RegisterAgent",
cb_register, NULL, -1,
"os", "/org/enlightenment/bluez5/agent",
"KeyboardDisplay");
else
e_util_dialog_show(_("Bluetooth"),
_("Could not call RegisterAgent\n"));
}
void
bz_agent_shutdown(void)
{
if (!agent_proxy) return;
eldbus_proxy_call(agent_proxy, "UnregisterAgent",
cb_unregister, NULL, -1,
"o", "/org/enlightenment/bluez5/agent");
}
void
bz_agent_release_func_set(void (*fn) (void))
{
fn_release = fn;
}
void
bz_agent_cancel_func_set(void (*fn) (void))
{
fn_cancel = fn;
}
void
bz_agent_req_pin_func_set(void (*fn) (Eldbus_Message *msg))
{
fn_req_pin = fn;
}
void
bz_agent_disp_pin_func_set(void (*fn) (Eldbus_Message *msg))
{
fn_disp_pin = fn;
}
void
bz_agent_req_pass_func_set(void (*fn) (Eldbus_Message *msg))
{
fn_req_pass = fn;
}
void
bz_agent_disp_pass_func_set(void (*fn) (Eldbus_Message *msg))
{
fn_disp_pass = fn;
}
void
bz_agent_req_confirm_func_set(void (*fn) (Eldbus_Message *msg))
{
fn_req_confirm = fn;
}
void
bz_agent_req_auth_func_set(void (*fn) (Eldbus_Message *msg))
{
fn_req_auth = fn;
}
void
bz_agent_auth_service_func_set(void (*fn) (Eldbus_Message *msg))
{
fn_auth_service = fn;
}

760
src/modules/bluez5/bz_obj.c Normal file
View File

@ -0,0 +1,760 @@
#include "bz.h"
static Eldbus_Proxy *objman_proxy = NULL;
static Eldbus_Signal_Handler *sig_ifadd = NULL;
static Eldbus_Signal_Handler *sig_ifdel = NULL;
static Eldbus_Pending *pend_getobj = NULL;
static Eina_Hash *obj_table = NULL;
static void (*fn_obj_add) (Obj *o) = NULL;
/*
static void
cb_obj_prop_mandata(void *data, const void *key, Eldbus_Message_Iter *var)
{
Obj *o = data;
unsigned short *skey = key;
printf(" M KEY %x\n", (int)*skey);
}
*/
static void
cb_obj_prop_entry(void *data, const void *key, Eldbus_Message_Iter *var)
{
Obj *o = data;
const char *skey = key;
if (!strcmp(skey, "Paired"))
{
Eina_Bool val = EINA_FALSE;
if (eldbus_message_iter_arguments_get(var, "b", &val))
o->paired = val;
}
if (!strcmp(skey, "Connected"))
{
Eina_Bool val = EINA_FALSE;
if (eldbus_message_iter_arguments_get(var, "b", &val))
o->connected = val;
}
if (!strcmp(skey, "Trusted"))
{
Eina_Bool val = EINA_FALSE;
if (eldbus_message_iter_arguments_get(var, "b", &val))
o->trusted = val;
}
if (!strcmp(skey, "Blocked"))
{
Eina_Bool val = EINA_FALSE;
if (eldbus_message_iter_arguments_get(var, "b", &val))
o->blocked = val;
}
if (!strcmp(skey, "LegacyPairing"))
{
Eina_Bool val = EINA_FALSE;
if (eldbus_message_iter_arguments_get(var, "b", &val))
o->legacy_pairing = val;
}
if (!strcmp(skey, "ServicesResolved"))
{
Eina_Bool val = EINA_FALSE;
if (eldbus_message_iter_arguments_get(var, "b", &val))
o->services_resolved = val;
}
if (!strcmp(skey, "Address"))
{
const char *val = NULL;
if (eldbus_message_iter_arguments_get(var, "s", &val))
o->address = eina_stringshare_add(val);
}
if (!strcmp(skey, "AddressType"))
{
const char *val = NULL;
if (eldbus_message_iter_arguments_get(var, "s", &val))
o->address_type = eina_stringshare_add(val);
}
if (!strcmp(skey, "Name"))
{
const char *val = NULL;
if (eldbus_message_iter_arguments_get(var, "s", &val))
o->name = eina_stringshare_add(val);
}
if (!strcmp(skey, "Icon"))
{
const char *val = NULL;
if (eldbus_message_iter_arguments_get(var, "s", &val))
o->icon = eina_stringshare_add(val);
}
if (!strcmp(skey, "Alias"))
{
const char *val = NULL;
if (eldbus_message_iter_arguments_get(var, "s", &val))
o->alias = eina_stringshare_add(val);
}
if (!strcmp(skey, "Modalias"))
{
const char *val = NULL;
if (eldbus_message_iter_arguments_get(var, "s", &val))
o->modalias = eina_stringshare_add(val);
}
if (!strcmp(skey, "Adapter"))
{
const char *val = NULL;
if (eldbus_message_iter_arguments_get(var, "o", &val))
o->adapter = eina_stringshare_add(val);
}
if (!strcmp(skey, "Class"))
{
unsigned int val = 0;
if (eldbus_message_iter_arguments_get(var, "u", &val))
o->klass = val;
}
if (!strcmp(skey, "Appearance"))
{
unsigned short val = 0;
if (eldbus_message_iter_arguments_get(var, "q", &val))
o->appearance = val;
}
if (!strcmp(skey, "RSSI"))
{
short val = 0;
if (eldbus_message_iter_arguments_get(var, "n", &val))
o->rssi = val;
}
if (!strcmp(skey, "TxPower"))
{
unsigned short val = 0;
if (eldbus_message_iter_arguments_get(var, "n", &val))
o->txpower = val;
}
if (!strcmp(skey, "UUIDs"))
{
Eldbus_Message_Iter *array = NULL;
if (eldbus_message_iter_arguments_get(var, "as", &array))
{
const char *val = NULL;
while (eldbus_message_iter_get_and_next(array, 's', &val))
{
if (!o->uuids) o->uuids = eina_array_new(1);
eina_array_push(o->uuids, eina_stringshare_add(val));
}
}
}
if (!strcmp(skey, "Discoverable"))
{
Eina_Bool val = EINA_FALSE;
if (eldbus_message_iter_arguments_get(var, "b", &val))
o->discoverable = val;
}
if (!strcmp(skey, "Discovering"))
{
Eina_Bool val = EINA_FALSE;
if (eldbus_message_iter_arguments_get(var, "b", &val))
o->discovering = val;
}
if (!strcmp(skey, "Pairable"))
{
Eina_Bool val = EINA_FALSE;
if (eldbus_message_iter_arguments_get(var, "b", &val))
o->pairable = val;
}
if (!strcmp(skey, "Powered"))
{
Eina_Bool val = EINA_FALSE;
if (eldbus_message_iter_arguments_get(var, "b", &val))
o->powered = val;
}
if (!strcmp(skey, "DiscoverableTimeout"))
{
unsigned int val = 0;
if (eldbus_message_iter_arguments_get(var, "u", &val))
o->discoverable_timeout = val;
}
if (!strcmp(skey, "PairableTimeout"))
{
unsigned int val = 0;
if (eldbus_message_iter_arguments_get(var, "u", &val))
o->pairable_timeout = val;
}
// dict ManufacturerData [readonly, optional]
// Manufacturer specific advertisement data. Keys are
// 16 bits Manufacturer ID followed by its byte array
// value.
/*
if (!strcmp(skey, "ManufacturerData"))
{
Eldbus_Message_Iter *array = NULL;
if (eldbus_message_iter_arguments_get(var, "a{qv}", &array))
eldbus_message_iter_dict_iterate(array, "qv", cb_obj_prop_mandata, o);
}
*/
// dict ServiceData [readonly, optional]
// Service advertisement data. Keys are the UUIDs in
// string format followed by its byte array value.
//
// array{byte} AdvertisingFlags [readonly, experimental]
// The Advertising Data Flags of the remote device.
//
// dict AdvertisingData [readonly, experimental]
// The Advertising Data of the remote device. Keys are
// are 8 bits AD Type followed by data as byte array.
}
static void
_obj_clear(Obj *o)
{
o->paired = EINA_FALSE;
o->connected = EINA_FALSE;
o->trusted = EINA_FALSE;
o->blocked = EINA_FALSE;
o->legacy_pairing = EINA_FALSE;
o->services_resolved = EINA_FALSE;
eina_stringshare_del(o->address);
o->address = NULL;
eina_stringshare_del(o->address_type);
o->address_type = NULL;
eina_stringshare_del(o->name);
o->name = NULL;
eina_stringshare_del(o->icon);
o->icon = NULL;
eina_stringshare_del(o->alias);
o->alias = NULL;
eina_stringshare_del(o->adapter);
o->adapter = NULL;
eina_stringshare_del(o->modalias);
o->modalias = NULL;
eina_stringshare_del(o->modalias);
o->modalias = NULL;
o->klass = 0;
o->appearance = 0;
o->txpower = 0;
o->rssi = 0;
if (o->uuids)
{
const char *val;
while ((val = eina_array_pop(o->uuids)))
eina_stringshare_del(val);
eina_array_free(o->uuids);
o->uuids = NULL;
}
}
#define ERR_PRINT(str) \
do { const char *name, *text; \
if (eldbus_message_error_get(msg, &name, &text)) { \
printf("Error: %s.\n %s:\n %s\n", str, name, text); \
return; \
} \
} while(0)
static void
cb_obj_prop(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
{
Obj *o = data;
Eldbus_Message_Iter *array;
if (eldbus_message_error_get(msg, NULL, NULL)) return;
_obj_clear(o);
if (eldbus_message_arguments_get(msg, "a{sv}", &array))
eldbus_message_iter_dict_iterate(array, "sv", cb_obj_prop_entry, o);
bz_obj_ref(o);
if (!o->add_called)
{
o->add_called = EINA_TRUE;
if (fn_obj_add) fn_obj_add(o);
}
if (o->fn_change) o->fn_change(o);
bz_obj_unref(o);
}
static void
cb_obj_prop_changed(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED)
{
Obj *o = data;
if (!o->proxy) return;
eldbus_proxy_property_get_all(o->proxy, cb_obj_prop, o);
}
Obj *
bz_obj_add(const char *path)
{
Eldbus_Object *obj;
Obj *o = calloc(1, sizeof(Obj));
o->ref = 1;
o->path = eina_stringshare_add(path);
obj = eldbus_object_get(bz_conn, "org.bluez", o->path);
o->type = BZ_OBJ_UNKNOWN;
o->in_table = EINA_TRUE;
eina_hash_add(obj_table, o->path, o);
if (!strcmp(o->path, "/org/bluez"))
{
o->proxy = eldbus_proxy_get(obj, "org.bluez.AgentManager1");
o->type = BZ_OBJ_BLUEZ;
o->add_called = EINA_TRUE;
bz_obj_ref(o);
if (fn_obj_add) fn_obj_add(o);
bz_obj_unref(o);
goto done;
}
// all devices are /org/bluez/XXX/dev_XXX so look for /dev_
else if (strstr(o->path, "/dev_"))
{
o->proxy = eldbus_proxy_get(obj, "org.bluez.Device1");
o->type = BZ_OBJ_DEVICE;
if (o->proxy)
{
eldbus_proxy_property_get_all(o->proxy, cb_obj_prop, o);
o->prop_proxy = eldbus_proxy_get(obj,
"org.freedesktop.DBus.Properties");
if (o->prop_proxy)
o->prop_sig = eldbus_proxy_signal_handler_add(o->prop_proxy,
"PropertiesChanged",
cb_obj_prop_changed, o);
}
goto done;
}
// all dadapters begin with /org/bluez/
else if (!strncmp(o->path, "/org/bluez/", 11))
{
o->proxy = eldbus_proxy_get(obj, "org.bluez.Adapter1");
o->type = BZ_OBJ_ADAPTER;
if (o->proxy)
{
eldbus_proxy_property_get_all(o->proxy, cb_obj_prop, o);
o->prop_proxy = eldbus_proxy_get(obj,
"org.freedesktop.DBus.Properties");
if (o->prop_proxy)
o->prop_sig = eldbus_proxy_signal_handler_add(o->prop_proxy,
"PropertiesChanged",
cb_obj_prop_changed, o);
}
goto done;
}
done:
return o;
}
Obj *
bz_obj_find(const char *path)
{
return eina_hash_find(obj_table, path);
}
static void
cb_power_on(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Power On");
}
void
bz_obj_power_on(Obj *o)
{
Eina_Bool val = EINA_TRUE;
if (!o->proxy) return;
eldbus_proxy_property_set
(o->proxy, "Powered", "b", (void *)(uintptr_t)val, cb_power_on, o);
}
static void
cb_power_off(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Power Off");
}
void
bz_obj_power_off(Obj *o)
{
Eina_Bool val = EINA_FALSE;
if (!o->proxy) return;
eldbus_proxy_property_set
(o->proxy, "Powered", "b", (void *)(uintptr_t)val, cb_power_off, o);
}
static void
cb_discoverable(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Discoverable");
}
void
bz_obj_discoverable(Obj *o)
{
Eina_Bool val = EINA_TRUE;
if (!o->proxy) return;
eldbus_proxy_property_set
(o->proxy, "Discoverable", "b", (void *)(uintptr_t)val, cb_discoverable, o);
}
static void
cb_undiscoverable(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Undiscoverable");
}
void
bz_obj_undiscoverable(Obj *o)
{
Eina_Bool val = EINA_FALSE;
if (!o->proxy) return;
eldbus_proxy_property_set
(o->proxy, "Discoverable", "b", (void *)(uintptr_t)val, cb_undiscoverable, o);
}
static void
cb_pairable(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Pairable");
}
void
bz_obj_pairable(Obj *o)
{
Eina_Bool val = EINA_TRUE;
if (!o->proxy) return;
eldbus_proxy_property_set
(o->proxy, "Pairable", "b", (void *)(uintptr_t)val, cb_pairable, o);
}
static void
cb_unpairable(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Unpairable");
}
void
bz_obj_unpairable(Obj *o)
{
Eina_Bool val = EINA_FALSE;
if (!o->proxy) return;
eldbus_proxy_property_set
(o->proxy, "Pairable", "b", (void *)(uintptr_t)val, cb_unpairable, o);
}
static void
cb_trust(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Trust");
}
void
bz_obj_trust(Obj *o)
{
Eina_Bool val = EINA_TRUE;
if (!o->proxy) return;
eldbus_proxy_property_set
(o->proxy, "Trusted", "b", (void *)(uintptr_t)val, cb_trust, o);
}
static void
cb_distrust(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Distrust");
}
void
bz_obj_distrust(Obj *o)
{
Eina_Bool val = EINA_FALSE;
if (!o->proxy) return;
eldbus_proxy_property_set
(o->proxy, "Trusted", "b", (void *)(uintptr_t)val, cb_distrust, o);
}
static void
cb_pair(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Pair");
}
void
bz_obj_pair(Obj *o)
{
if (!o->proxy) return;
eldbus_proxy_call(o->proxy, "Pair", cb_pair, o, -1, "");
}
static void
cb_pair_cancel(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Pair Cancel");
}
void
bz_obj_pair_cancel(Obj *o)
{
if (!o->proxy) return;
eldbus_proxy_call
(o->proxy, "CancelPairing", cb_pair_cancel, o, -1, "");
}
static void
cb_connect(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Connect");
}
void
bz_obj_connect(Obj *o)
{
if (!o->proxy) return;
eldbus_proxy_call
(o->proxy, "Connect", cb_connect, o, -1, "");
}
static void
cb_disconnect(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Disconnect");
}
void
bz_obj_disconnect(Obj *o)
{
if (!o->proxy) return;
eldbus_proxy_call
(o->proxy, "Disconnect", cb_disconnect, o, -1, "");
}
/*
void
bz_obj_profile_connect(Obj *o, const char *uuid)
{
if (!o->proxy) return;
eldbus_proxy_call(o->proxy, "ConnectProfile", NULL, NULL, -1, "s", uuid);
}
void
bz_obj_profile_disconnect(Obj *o, const char *uuid)
{
if (!o->proxy) return;
eldbus_proxy_call(o->proxy, "DisconnectProfile", NULL, NULL, -1, "s", uuid);
}
*/
static void
cb_remove(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Remove");
}
void
bz_obj_remove(Obj *o)
{
if (o->adapter)
{
Obj *adapter = bz_obj_find(o->adapter);
if (adapter)
{
if (!adapter->proxy) return;
eldbus_proxy_call(adapter->proxy, "RemoveDevice",
cb_remove, adapter, -1,
"o", o->path);
}
}
}
void
bz_obj_ref(Obj *o)
{
o->ref++;
}
void
bz_obj_unref(Obj *o)
{
o->ref--;
if (o->ref > 0) return;
if (o->in_table)
{
o->in_table = EINA_FALSE;
eina_hash_del(obj_table, o->path, o);
}
_obj_clear(o);
if (o->prop_sig)
{
eldbus_signal_handler_del(o->prop_sig);
o->prop_sig = NULL;
}
if (o->proxy)
{
eldbus_proxy_unref(o->proxy);
o->proxy = NULL;
}
if (o->prop_proxy)
{
eldbus_proxy_unref(o->prop_proxy);
o->prop_proxy = NULL;
}
if (o->path)
{
eina_stringshare_del(o->path);
o->path = NULL;
}
if (o->agent_request)
{
eina_stringshare_del(o->agent_request);
o->agent_request = NULL;
}
if (o->agent_msg_err)
{
bz_agent_msg_drop(o->agent_msg_err);
o->agent_msg_err = NULL;
}
if (o->agent_msg_ok)
{
bz_agent_msg_drop(o->agent_msg_ok);
o->agent_msg_ok = NULL;
}
free(o);
}
static void
cb_discovery_start(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Discovery Start");
}
void
bz_obj_discover_start(Obj *o)
{
if (!o->proxy) return;
eldbus_proxy_call
(o->proxy, "StartDiscovery", cb_discovery_start, o, -1, "");
}
static void
cb_discovery_stop(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
{
ERR_PRINT("Discovery Stop");
}
void
bz_obj_discover_stop(Obj *o)
{
if (!o->proxy) return;
eldbus_proxy_call
(o->proxy, "StopDiscovery", cb_discovery_stop, o, -1, "");
}
void
bz_obj_agent_request(Obj *o, const char *req, void (*fn) (Eldbus_Message *msg, const char *str), Eldbus_Message *msg_ok, Eldbus_Message *msg_err)
{
if (o->agent_msg_ok) bz_agent_msg_drop(o->agent_msg_ok);
if (o->agent_msg_err) bz_agent_msg_reply(o->agent_msg_err);
o->agent_msg_ok = msg_ok;
o->agent_msg_err = msg_err;
o->agent_entry_fn = fn;
o->agent_alert = EINA_TRUE;
eina_stringshare_replace(&(o->agent_request), req);
bz_obj_ref(o);
if (o->fn_change) o->fn_change(o);
bz_obj_unref(o);
}
static void
cb_obj_add(void *data EINA_UNUSED, const Eldbus_Message *msg)
{
const char *path = NULL;
if (!eldbus_message_arguments_get(msg, "o", &path)) return;
if (bz_obj_find(path)) return;
bz_obj_add(path);
}
static void
cb_obj_del(void *data EINA_UNUSED, const Eldbus_Message *msg)
{
Obj *o;
const char *path = NULL;
if (!eldbus_message_arguments_get(msg, "o", &path)) return;
o = bz_obj_find(path);
if (o)
{
bz_obj_ref(o);
if (o->fn_del) o->fn_del(o);
bz_obj_unref(o);
bz_obj_unref(o);
}
}
static void
cb_getobj(void *data EINA_UNUSED, const Eldbus_Message *msg,
Eldbus_Pending *pending EINA_UNUSED)
{
Eldbus_Message_Iter *prop, *dict;
pend_getobj = NULL;
ERR_PRINT("Get Objects");
if (eldbus_message_arguments_get(msg, "a{oa{sa{sv}}}", &prop))
{
while (eldbus_message_iter_get_and_next(prop, 'e', &dict))
{
const char *path;
path = NULL;
if (!eldbus_message_iter_arguments_get(dict, "o", &path))
{
return;
}
bz_obj_add(path);
}
}
}
static void
_obj_hash_free(Obj *o)
{
o->in_table = 0;
bz_obj_unref(o);
}
void
bz_obj_init(void)
{
Eldbus_Object *obj;
obj_table = eina_hash_string_superfast_new((void *)_obj_hash_free);
obj = eldbus_object_get(bz_conn, "org.bluez", "/");
objman_proxy = eldbus_proxy_get(obj, "org.freedesktop.DBus.ObjectManager");
sig_ifadd = eldbus_proxy_signal_handler_add(objman_proxy, "InterfacesAdded",
cb_obj_add, NULL);
sig_ifdel = eldbus_proxy_signal_handler_add(objman_proxy, "InterfacesRemoved",
cb_obj_del, NULL);
pend_getobj = eldbus_proxy_call(objman_proxy, "GetManagedObjects",
cb_getobj, NULL, -1, "");