enlightenment/src/modules/bluez4/agent.c

262 lines
8.7 KiB
C
Raw Normal View History

#include <inttypes.h>
#include "e.h"
#include "ebluez4.h"
#include "agent.h"
#define AGENT_INTERFACE "org.bluez.Agent"
#define BLUEZ_ERROR_FAILED "org.bluez.Error.Failed"
2013-04-23 08:08:29 -07:00
#define GET_ERROR_MSG "eldbus_message_arguments_get() error"
#define BLUEZ_ERROR_REJECTED "org.bluez.Error.Rejected"
#define REJECTED_MSG "Request was rejected"
2013-04-23 08:08:29 -07:00
static Eldbus_Connection *bluez_conn;
static char buf[1024];
/* Local Functions */
static void
2013-04-23 08:08:29 -07:00
_reply(Eldbus_Message *message, Eldbus_Message *reply)
{
2013-04-23 08:08:29 -07:00
eldbus_connection_send(bluez_conn, reply, NULL, NULL, -1);
eldbus_message_unref(message);
}
static void
_pincode_ok(void *data, char *text)
{
2013-04-23 08:08:29 -07:00
Eldbus_Message *message = data;
Eldbus_Message *reply = eldbus_message_method_return_new(message);
eldbus_message_arguments_append(reply, "s", text);
_reply(message, reply);
}
static void
_passkey_ok(void *data, char *text)
{
2013-04-23 08:08:29 -07:00
Eldbus_Message *message = data;
uint32_t passkey = (uint32_t)atoi(text);
2013-04-23 08:08:29 -07:00
Eldbus_Message *reply = eldbus_message_method_return_new(message);
eldbus_message_arguments_append(reply, "u", passkey);
_reply(message, reply);
}
static void
_cancel(void *data)
{
2013-04-23 08:08:29 -07:00
Eldbus_Message *message = data;
Eldbus_Message *reply = eldbus_message_error_new(message,
BLUEZ_ERROR_REJECTED, REJECTED_MSG);
_reply(message, reply);
}
static E_Dialog *
_create_dialog(const char *title, const char *msg,
const char *icon, const char *class)
{
E_Dialog *dialog;
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
dialog = e_dialog_new(NULL, title, class);
2013-04-28 13:49:16 -07:00
e_dialog_title_set(dialog, _(title));
e_dialog_icon_set(dialog, icon, 64);
e_dialog_text_set(dialog, msg);
return dialog;
}
static void
_display_msg(const char *title, const char *msg)
{
E_Dialog *dialog = _create_dialog(title, msg, "view-hidden-files",
"display");
2013-04-28 13:49:16 -07:00
e_dialog_button_add(dialog, _("OK"), NULL, NULL, NULL);
e_dialog_show(dialog);
}
static void
2013-04-23 08:08:29 -07:00
_reply_and_del_dialog(Eldbus_Message *reply, E_Dialog *dialog)
{
Eldbus_Message *message;
if (!dialog) return;
if (!(message = dialog->data)) return;
_reply(message, reply);
e_object_del(E_OBJECT(dialog));
}
static void
2014-05-07 02:23:09 -07:00
_reject(void *data EINA_UNUSED, E_Dialog *dialog)
{
2013-04-23 08:08:29 -07:00
const Eldbus_Message *msg = dialog->data;
Eldbus_Message *reply = eldbus_message_error_new(msg, BLUEZ_ERROR_REJECTED,
REJECTED_MSG);
_reply_and_del_dialog(reply, dialog);
}
static void
_close(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
E_Dialog *dialog = data;
_reject(NULL, dialog);
}
static void
_ok(void *data EINA_UNUSED, E_Dialog *dialog)
{
const Eldbus_Message *msg = dialog->data;
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
evas_object_event_callback_del_full(dialog->win, EVAS_CALLBACK_DEL, _close, dialog);
_reply_and_del_dialog(reply, dialog);
}
static void
_ask(const char *title, const char *ask_msg, const char *ok_label,
2013-04-23 08:08:29 -07:00
Eldbus_Message *eldbus_message)
{
E_Dialog *dialog = _create_dialog(title, ask_msg, "dialog-ask", "ask");
2013-04-23 08:08:29 -07:00
dialog->data = eldbus_message;
evas_object_event_callback_add(dialog->win, EVAS_CALLBACK_DEL, _close, dialog);
e_dialog_button_add(dialog, ok_label, NULL, _ok, NULL);
2013-04-28 13:49:16 -07:00
e_dialog_button_add(dialog, _("Reject"), NULL, _reject, NULL);
e_dialog_show(dialog);
}
/* Implementation of agent API */
2013-04-23 08:08:29 -07:00
static Eldbus_Message *
2014-05-07 02:23:09 -07:00
_agent_release(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *message)
{
DBG("Agent Released.");
2013-04-23 08:08:29 -07:00
return eldbus_message_method_return_new(message);
}
2013-04-23 08:08:29 -07:00
static Eldbus_Message *
2014-05-07 02:23:09 -07:00
_agent_request_pin_code(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *message)
{
2013-04-23 08:08:29 -07:00
Eldbus_Message *msg = (Eldbus_Message *)message;
eldbus_message_ref(msg);
2013-04-28 13:49:16 -07:00
e_entry_dialog_show(_("Pin Code Requested"), NULL,
_("Enter the PinCode above. It should have 1-16 "
"characters and can be alphanumeric."), "0000",
_("OK"), _("Cancel"), _pincode_ok, _cancel, msg);
return NULL;
}
2013-04-23 08:08:29 -07:00
static Eldbus_Message *
2014-05-07 02:23:09 -07:00
_agent_request_passkey(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *message)
{
2013-04-23 08:08:29 -07:00
Eldbus_Message *msg = (Eldbus_Message *)message;
eldbus_message_ref(msg);
2013-04-28 13:49:16 -07:00
e_entry_dialog_show(_("Passkey Requested"), NULL,
_("Enter the Passkey above. "
"It should be a numeric value between 0-999999."),
"0", _("OK"), _("Cancel"), _passkey_ok, _cancel, msg);
return NULL;
}
2013-04-23 08:08:29 -07:00
static Eldbus_Message *
2014-05-07 02:23:09 -07:00
_agent_display_passkey(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *message)
{
const char *device;
uint32_t passkey;
uint16_t entered;
Device *dev;
2013-04-23 08:08:29 -07:00
if(!eldbus_message_arguments_get(message, "ouq", &device, &passkey, &entered))
return eldbus_message_error_new(message, BLUEZ_ERROR_FAILED, GET_ERROR_MSG);
dev = eina_list_search_unsorted(ctxt->devices, ebluez4_dev_path_cmp, device);
2013-04-28 13:49:16 -07:00
snprintf(buf, sizeof(buf), _("%d keys were typed on %s. Passkey is %06d"),
entered, dev->name, passkey);
2013-04-28 13:49:16 -07:00
_display_msg(N_("Display Passkey"), buf);
2013-04-23 08:08:29 -07:00
return eldbus_message_method_return_new(message);
}
2013-04-23 08:08:29 -07:00
static Eldbus_Message *
2014-05-07 02:23:09 -07:00
_agent_display_pin_code(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *message)
{
const char *device, *pincode;
Device *dev;
2013-04-23 08:08:29 -07:00
if(!eldbus_message_arguments_get(message, "os", &device, &pincode))
return eldbus_message_error_new(message, BLUEZ_ERROR_FAILED, GET_ERROR_MSG);
dev = eina_list_search_unsorted(ctxt->devices, ebluez4_dev_path_cmp, device);
2013-04-28 13:49:16 -07:00
snprintf(buf, sizeof(buf), _("Pincode for %s is %s"), dev->name, pincode);
_display_msg(N_("Display Pincode"), buf);
2013-04-23 08:08:29 -07:00
return eldbus_message_method_return_new(message);
}
2013-04-23 08:08:29 -07:00
static Eldbus_Message *
2014-05-07 02:23:09 -07:00
_agent_request_confirmation(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *message)
{
const char *device;
uint32_t passkey;
Device *dev;
2013-04-23 08:08:29 -07:00
if(!eldbus_message_arguments_get(message, "ou", &device, &passkey))
return eldbus_message_error_new(message, BLUEZ_ERROR_FAILED, GET_ERROR_MSG);
dev = eina_list_search_unsorted(ctxt->devices, ebluez4_dev_path_cmp, device);
2013-04-28 13:49:16 -07:00
snprintf(buf, sizeof(buf), _("%06d is the passkey presented in %s?"),
passkey, dev->name);
2013-04-23 08:08:29 -07:00
eldbus_message_ref((Eldbus_Message *)message);
2013-04-28 13:49:16 -07:00
_ask(N_("Confirm Request"), buf, _("Confirm"), (Eldbus_Message *)message);
return NULL;
}
2013-04-23 08:08:29 -07:00
static Eldbus_Message *
2014-05-07 02:23:09 -07:00
_agent_authorize(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *message)
{
const char *device, *uuid;
Device *dev;
2013-04-23 08:08:29 -07:00
if(!eldbus_message_arguments_get(message, "os", &device, &uuid))
return eldbus_message_error_new(message, BLUEZ_ERROR_FAILED, GET_ERROR_MSG);
dev = eina_list_search_unsorted(ctxt->devices, ebluez4_dev_path_cmp, device);
2013-04-28 13:49:16 -07:00
snprintf(buf, sizeof(buf), _("Grant permission for %s to connect?"),
dev->name);
2013-04-23 08:08:29 -07:00
eldbus_message_ref((Eldbus_Message *)message);
2013-04-28 13:49:16 -07:00
_ask(N_("Authorize Connection"), buf, _("Grant"), (Eldbus_Message *)message);
return NULL;
}
2013-04-23 08:08:29 -07:00
static Eldbus_Message *
2014-05-07 02:23:09 -07:00
_agent_cancel(const Eldbus_Service_Interface *iface EINA_UNUSED,
const Eldbus_Message *message)
{
DBG("Request canceled.");
2013-04-23 08:08:29 -07:00
return eldbus_message_method_return_new(message);
}
2013-04-23 08:08:29 -07:00
static const Eldbus_Method agent_methods[] = {
{ "Release", NULL, NULL, _agent_release, 0 },
2013-04-23 08:08:29 -07:00
{ "RequestPinCode", ELDBUS_ARGS({"o", "device"}),
ELDBUS_ARGS({"s", "pincode"}), _agent_request_pin_code, 0 },
2013-04-23 08:08:29 -07:00
{ "RequestPasskey", ELDBUS_ARGS({"o", "device"}),
ELDBUS_ARGS({"u", "passkey"}), _agent_request_passkey, 0 },
{ "DisplayPasskey",
2013-04-23 08:08:29 -07:00
ELDBUS_ARGS({"o", "device"},{"u", "passkey"},{"q", "entered"}),
NULL, _agent_display_passkey, 0 },
2013-04-23 08:08:29 -07:00
{ "DisplayPinCode", ELDBUS_ARGS({"o", "device"},{"s", "pincode"}),
NULL, _agent_display_pin_code, 0 },
2013-04-23 08:08:29 -07:00
{ "RequestConfirmation", ELDBUS_ARGS({"o", "device"},{"u", "passkey"}),
NULL, _agent_request_confirmation, 0 },
2013-04-23 08:08:29 -07:00
{ "Authorize", ELDBUS_ARGS({"o", "device"},{"s", "uuid"}),
NULL, _agent_authorize, 0 },
{ "Cancel", NULL, NULL, _agent_cancel, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
2013-04-23 08:08:29 -07:00
static const Eldbus_Service_Interface_Desc agent_iface = {
AGENT_INTERFACE, agent_methods, NULL, NULL, NULL, NULL
};
/* Public Functions */
2013-04-23 08:08:29 -07:00
void ebluez4_register_agent_interfaces(Eldbus_Connection *conn)
{
bluez_conn = conn;
2013-04-23 08:08:29 -07:00
eldbus_service_interface_register(conn, AGENT_PATH, &agent_iface);
eldbus_service_interface_register(conn, REMOTE_AGENT_PATH, &agent_iface);
}