diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2018-10-30 19:41:53 -0700 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2018-11-12 03:58:47 -0800 |
commit | 93f9937300ce2ae1f45d3362d6c1a3180e0743a8 (patch) | |
tree | 49983702697c8f0437b7fcff22b0255d3ced0e13 | |
parent | 45d4198af0c314cdcd3d489429953a5b93de988b (diff) |
binding: bluetooth: initial commit of binding rewrite
Bug-AGL: SPEC-1630
Change-Id: I33cfec70283fa29f47b76f9e6be3e8e6cd6a2f54
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
27 files changed, 3609 insertions, 8881 deletions
diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index b545da1..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "conf.d/app-templates"] - path = conf.d/app-templates - url = https://gerrit.automotivelinux.org/gerrit/apps/app-templates @@ -1,2 +0,0 @@ -autocmd BufEnter,BufNew *.c set ts=4 sw=4 expandtab -autocmd BufEnter,BufNew *.h set ts=4 sw=4 expandtab diff --git a/README.md b/README.md new file mode 100644 index 0000000..ed9deeb --- /dev/null +++ b/README.md @@ -0,0 +1,217 @@ +# Bluetooth Service + +## Overview + +Bluetooth service uses the respective BlueZ package to connect to bluetooth devices + +## Verbs + +| Name | Description | JSON Response | +|--------------------|---------------------------------------------------------|-------------------------------------------------------------------------| +| subscribe | subscribe to bluetooth events | *Request:* {"value": "device_changes"} | +| unsubscribe | unsubscribe to bluetooth events | *Request:* {"value": "device_changes"} | +| managed_objects | retrieve managed bluetooth devices | see managed_objects verb section | +| adapter_state | retrieve or change adapter scan settings | see adapter_state verb section | +| connect | connect to already paired device | see connect/disconnect verb section | +| disconnect | disconnect to already connected device | see connect/disconnect verb section | +| pair | initialize a pairing request | *Request:* {"device":"/org/bluez/hci0/dev_88_0F_10_96_D3_20"} | +| cancel_pairing | cancel an outgoing pair request | | +| confirm_pairing | confirm incoming/outgoing bluetooth pairing pincode | *Request:* {"pincode": 31415} | +| remove_device | remove already paired device | *Request:* {"device": "/org/bluez/hci0/dev/dev_88_0F_10_96_D3_20"} | + + +### managed_objects verb + +This verb allows an client to get initial paired devices, and discovered unpaired devices before subscriptio to *devices_changed* event. + +<pre> +{ + "response": { + "adapters": [ + { + "path": "/org/bluez/hci0", + "properties": { + "address": "00:1A:7D:DA:71:0F", + "powered": true, + "discoverable": true, + "discoverabletimeout": 180, + "pairable": true, + "pairabletimeout": 0, + "discovering": true, + "uuids": [ + "00001112-0000-1000-8000-00805f9b34fb", + "00001801-0000-1000-8000-00805f9b34fb", + "0000110e-0000-1000-8000-00805f9b34fb", + "00001800-0000-1000-8000-00805f9b34fb", + "00001200-0000-1000-8000-00805f9b34fb", + "0000110c-0000-1000-8000-00805f9b34fb", + "0000110b-0000-1000-8000-00805f9b34fb", + "0000110a-0000-1000-8000-00805f9b34fb", + "0000111e-0000-1000-8000-00805f9b34fb", + "0000111f-0000-1000-8000-00805f9b34fb", + "00001108-0000-1000-8000-00805f9b34fb" + ] + } + } + ], + "devices": [ + { + "path": "/org/bluez/hci0/dev_F8_34_41_DA_BA_46", + "properties": { + "address": "F8:34:41:DA:BA:46", + "name": "roguebox", + "alias": "roguebox", + "class": 1835276, + "icon": "computer", + "paired": false, + "trusted": false, + "blocked": false, + "legacypairing": false, + "rssi": -63, + "connected": false, + "uuids": [ + "0000110e-0000-1000-8000-00805f9b34fb", + "0000110c-0000-1000-8000-00805f9b34fb", + "00001112-0000-1000-8000-00805f9b34fb", + "00001108-0000-1000-8000-00805f9b34fb", + "00001133-0000-1000-8000-00805f9b34fb", + "00001132-0000-1000-8000-00805f9b34fb", + "0000112f-0000-1000-8000-00805f9b34fb", + "00001104-0000-1000-8000-00805f9b34fb", + "00001106-0000-1000-8000-00805f9b34fb", + "00001105-0000-1000-8000-00805f9b34fb", + "0000110a-0000-1000-8000-00805f9b34fb", + "0000110b-0000-1000-8000-00805f9b34fb", + "00005005-0000-1000-8000-0002ee000001" + ], + "modalias": "usb:v1D6Bp0246d0530", + "adapter": "/org/bluez/hci0", + "txpower": 12, + "servicesresolved": false + } + }, + { + "path": "/org/bluez/hci0/dev_67_13_E2_57_29_0F", + "properties": { + "address": "68:13:E2:57:29:0F", + "alias": "67-13-E2-57-29-0F", + "paired": false, + "trusted": false, + "blocked": false, + "legacypairing": false, + "rssi": -69, + "connected": false, + "uuids": [], + "adapter": "/org/bluez/hci0", + "servicesresolved": false + } + }, +... +</pre> + + +### adapter_state verb + +adapter_state verb allows setting and retrieving of requested adapter settings: + +| Name | Description | +|-----------------|------------------------------------------------------------------| +| adapter | Must be the bluez path to the adapter (i.e. /org/bluez/hci0) | +| discovery | Discover nearby broadcasting devices | +| discoverable | Allow other devices to detect this device | +| powered | Adapter power state (optional, rfkill should be disabled already | + + +### connect/disconnect verbs + +NOTE: uuid in this respect is not related to the afb framework but the Bluetooth profile UUID + +To connect/disconnect using the respective verb with all known and authenticated profiles: + +<pre> + {"device": "/org/bluez/hci0/dev_88_0F_10_96_D3_20"} +</pre> + +To do the same for the respective device, verb, and for singular profile + +<pre> + {"device": "/org/bluez/hci0/dev_88_0F_10_96_D3_20", "uuid": "0000110e-0000-1000-8000-00805f9b34fb"} +</pre> + +## Events + +| Name | Description | JSON Event Data | +|-------------------|------------------------------------------|-------------------------------------------| +| device_changes | report on bluetooth devices | see device_changes event section | +| agent | PIN from BlueZ agent for confirmation | see agent event section | + + +### device_changes event + +Sample of discovering a new device event: + +<pre> +{ + "device": "/org/bluez/hci0/dev_88_0F_10_96_D3_20", + "action": "added", + "properties": { + "address": "88:0F:10:96:D3:20", + "name": "MI_SCALE", + "alias": "MI_SCALE", + "class": 7995916, + "icon": "phone", + "paired": false, + "trusted": false, + "blocked": false, + "legacypairing": false, + "rssi": -55, + "connected": false, + "uuids": [ + "00001200-0000-1000-8000-00805f9b34fb", + "0000111f-0000-1000-8000-00805f9b34fb", + "0000112f-0000-1000-8000-00805f9b34fb", + "0000110a-0000-1000-8000-00805f9b34fb", + "0000110c-0000-1000-8000-00805f9b34fb", + "00001116-0000-1000-8000-00805f9b34fb", + "00001132-0000-1000-8000-00805f9b34fb", + "00000000-deca-fade-deca-deafdecacafe", + "02030302-1d19-415f-86f2-22a2106a0a77", + "2d8d2466-e14d-451c-88bc-7301abea291a" + ], + "adapter": "/org/bluez/hci0", + "servicesresolved": false + } +} +</pre> + +Changed status events for a deivce: + +<pre> +{ + "path": "/org/bluez/hci0/dev_88_0F_10_96_D3_20", + "action": "changed", + "properties": { + "connected": true + } +} +</pre> + +### agent event + +After pairing request agent will send event for a pincode that must be confirmed on both sides: + +<pre> +{ + "action": "request_confirmation", + "device": "/org/bluez/hci0/dev_88_OF_10_96_D3_20", + "pincode": 327142 +} +</pre> + +If pairing is canceled or fails: + +<pre> +{ + "action": "canceled_pairing" +} +</pre> diff --git a/binding-bluetooth/bluetooth-agent.c b/binding-bluetooth/bluetooth-agent.c deleted file mode 100644 index 3420167..0000000 --- a/binding-bluetooth/bluetooth-agent.c +++ /dev/null @@ -1,755 +0,0 @@ -/* Copyright 2016 ALPS ELECTRIC CO., LTD. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <gio/gio.h> - -#include "bluetooth-agent.h" - -#ifdef AGENT_THREAD - -#include <pthread.h> - -static GMainLoop *agentLoop = NULL; -#endif - -static GDBusConnection *system_conn = NULL; -static gboolean agent_registered = FALSE; -static const char *agent_capability = NULL; -static Agent_RegisterCallback_t agent_RegisterCallback = { 0 }; -static AGENTOrgBluezAgent1 * agnet_interface = NULL; - -static struct Agent_Node *agent_event = NULL; - - -static void agent_event_auto_release(struct Agent_Node *event) -{ - if (NULL == event ){ - return; - } - g_dbus_method_invocation_return_dbus_error (event->invocation, - ERROR_BLUEZ_REJECT, ""); - g_free(event); -} - -/* - * Store the agent event - */ -static void agent_event_new(AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, int type) -{ - LOGD("\n"); - if(NULL !=agent_event ) - { - agent_event_auto_release(agent_event); - } - agent_event = g_malloc0(sizeof(struct Agent_Node)); - agent_event->type = type; - agent_event->object = object; - agent_event->invocation = invocation; - -} - - -/* - * agent api - * - * Methods : void Release() - * This method gets called when the service daemon - * unregisters the agent. An agent can use it to do - * cleanup tasks. There is no need to unregister the - * agent, because when this method gets called it has - * already been unregistered. - */ -static gboolean -on_handle_Release (AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - gpointer user_data) -{ - LOGD("\n"); - - //gboolean ret = FALSE; - - if (NULL != agent_RegisterCallback.agent_Release) - { - agent_RegisterCallback.agent_Release(); - } - - agent_org_bluez_agent1_complete_release(object, invocation); - - g_dbus_interface_skeleton_unexport( - G_DBUS_INTERFACE_SKELETON(agnet_interface)); - - g_object_unref(agnet_interface); - agent_registered = FALSE; - -#ifdef AGENT_THREAD - if(agentLoop){ - g_main_loop_quit(agentLoop); - } -#endif - - return TRUE; -} - -/* - * agent api - * Methods : string RequestPinCode(object device) - * - * This method gets called when the service daemon - * needs to get the passkey for an authentication. - * - * The return value should be a string of 1-16 characters - * length. The string can be alphanumeric. - */ -static gboolean -on_handle_RequestPinCode (AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *device, - gpointer user_data) -{ - - LOGD("device:%s.\n",device); - - gboolean ret = FALSE; - const gchar *error = ERROR_BLUEZ_REJECT; - gchar *response; - - if (NULL != agent_RegisterCallback.agent_RequestPinCode) - { - ret = agent_RegisterCallback.agent_RequestPinCode (device, - &response, &error); - } - - if (TRUE == ret) - { - agent_org_bluez_agent1_complete_request_pin_code(object, - invocation, response); - g_free(response); - - } - else - { - g_dbus_method_invocation_return_dbus_error (invocation, error, ""); - } - - return TRUE; -} - -/* - * agent api - * Methods : void DisplayPinCode(object device, string pincode) - * - * This method gets called when the service daemon - * needs to display a pincode for an authentication. - */ -static gboolean -on_handle_DisplayPinCode (AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *device, - const gchar *pincode, - gpointer user_data) -{ - - LOGD("device:%s,pincode:%s.\n",device, pincode); - - gboolean ret = FALSE; - const gchar *error = ERROR_BLUEZ_REJECT; - - if (NULL != agent_RegisterCallback.agent_DisplayPinCode) - { - ret = agent_RegisterCallback.agent_DisplayPinCode(device, - pincode, &error); - } - - if (TRUE == ret) - { - agent_org_bluez_agent1_complete_display_pin_code(object, invocation); - } - else - { - g_dbus_method_invocation_return_dbus_error (invocation, error, ""); - } - - return TRUE; -} - - -/* - * agent api - * Methods : uint32 RequestPasskey(object device) - * - * This method gets called when the service daemon - * needs to get the passkey for an authentication. - * - * The return value should be a numeric value - * between 0-999999. - */ -static gboolean -on_handle_RequestPasskey (AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *device, - gpointer user_data) -{ - - LOGD("device:%s.\n",device); - - gboolean ret = FALSE; - const gchar *error = ERROR_BLUEZ_REJECT; - guint passkey; - - if (NULL != agent_RegisterCallback.agent_RequestPasskey) - { - ret = agent_RegisterCallback.agent_RequestPasskey(device, - &passkey, &error); - } - - if (TRUE == ret) - { - agent_org_bluez_agent1_complete_request_passkey(object, - invocation, passkey); - } - else - { - g_dbus_method_invocation_return_dbus_error (invocation, error, ""); - } - - return TRUE; - -} - - -/* - * agent api - * Methods : void DisplayPasskey(object device, uint32 passkey, uint16 entered) - * - * This method gets called when the service daemon - * needs to display a passkey for an authentication. - * - * The entered parameter indicates the number of already - * typed keys on the remote side. - */ -static gboolean -on_handle_DisplayPasskey (AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *device, - guint passkey, - guint16 entered, - gpointer user_data) -{ - - LOGD("device:%s,passkey:%d,entered:%d.\n",device, passkey, entered); - - //gboolean ret = FALSE; - - if (NULL != agent_RegisterCallback.agent_DisplayPasskey) - { - agent_RegisterCallback.agent_DisplayPasskey(device, passkey, entered); - } - - agent_org_bluez_agent1_complete_display_passkey(object, invocation); - - - return TRUE; - -} - -/* - * agent api - * Methods : void RequestConfirmation(object device, uint32 passkey) - * - * This method gets called when the service daemon - * needs to confirm a passkey for an authentication. - * - * To confirm the value it should return an empty reply - * or an error in case the passkey is invalid. - */ -static gboolean -on_handle_RequestConfirmation (AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *device, - guint passkey, - gpointer user_data) -{ - LOGD("device:%s,passkey:%d.\n", device, passkey); - - gboolean ret = FALSE; - const gchar *error = ERROR_BLUEZ_REJECT; - - if (NULL != agent_RegisterCallback.agent_RequestConfirmation) - { - ret = agent_RegisterCallback.agent_RequestConfirmation(device, - passkey, &error); - } - LOGD("ret %d\n",ret); - if (TRUE == ret) - { - agent_event_new(object, invocation,REQUEST_CONFIRMATION); - //agent_org_bluez_agent1_complete_request_confirmation(object, - // invocation); - } - else - { - g_dbus_method_invocation_return_dbus_error (invocation, error, ""); - } - - return TRUE; -} - -/* - * agent api - * Methods : void RequestAuthorization(object device) - * - * This method gets called to request the user to - * authorize an incoming pairing attempt which - * would in other circumstances trigger the just-works - * model. - */ -static gboolean -on_handle_RequestAuthorization (AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *device, - gpointer user_data) -{ - LOGD("device:%s.\n",device); - - gboolean ret = FALSE; - const gchar *error = ERROR_BLUEZ_REJECT; - - if (NULL != agent_RegisterCallback.agent_RequestAuthorization) - { - ret = agent_RegisterCallback.agent_RequestAuthorization(device,&error); - } - - if (TRUE == ret) - { - agent_org_bluez_agent1_complete_request_authorization(object, - invocation); - } - else - { - g_dbus_method_invocation_return_dbus_error (invocation, error, ""); - } - - return TRUE; -} - -/* - * agent api - * Methods : void AuthorizeService(object device, string uuid) - * - * This method gets called when the service daemon - * needs to authorize a connection/service request. - */ -static gboolean -on_handle_AuthorizeService (AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *device, - const gchar *uuid, - gpointer user_data) -{ - - LOGD("device:%s.uuid:%s\n",device,uuid); - - gboolean ret = FALSE; - const gchar *error = ERROR_BLUEZ_REJECT; - - if (NULL != agent_RegisterCallback.agent_AuthorizeService) - { - ret = agent_RegisterCallback.agent_AuthorizeService(device, - uuid, &error); - } - - if (TRUE == ret) - { - agent_org_bluez_agent1_complete_authorize_service(object, invocation); - } - else - { - g_dbus_method_invocation_return_dbus_error (invocation, error, ""); - } - - return TRUE; -} - -/* - * agent api - * Methods : void Cancel() - * - * This method gets called to indicate that the agent - * request failed before a reply was returned. - */ -static gboolean -on_handle_Cancel (AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - gpointer user_data) -{ - LOGD("\n"); - - if (NULL != agent_RegisterCallback.agent_Cancel) - { - agent_RegisterCallback.agent_Cancel(); - } - - agent_org_bluez_agent1_complete_cancel(object, invocation); - - return TRUE; - -} - -/* - * agent init - * init the dbus and register the agent to bluez - */ -static int create_and_register_agent(const char *capability) -{ - GError *error = NULL; - gboolean ret; - GVariant *value; - - LOGD("%s\n",capability); - - if (agent_registered == TRUE) { - LOGD("Agent is already registered\n"); - return -1; - } - - system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - - if (error) - { - LOGE("errr:%s",error->message); - g_error_free(error); - - return -1; - } - - agent_capability = capability; - - agnet_interface = agent_org_bluez_agent1_skeleton_new (); - - g_signal_connect (agnet_interface, - "handle-release", - G_CALLBACK (on_handle_Release), - NULL); - - g_signal_connect (agnet_interface, - "handle-request-pin-code", - G_CALLBACK (on_handle_RequestPinCode), - NULL); - - g_signal_connect (agnet_interface, - "handle-display-pin-code", - G_CALLBACK (on_handle_DisplayPinCode), - NULL); - - g_signal_connect (agnet_interface, - "handle-request-passkey", - G_CALLBACK (on_handle_RequestPasskey), - NULL); - - g_signal_connect (agnet_interface, - "handle-display-passkey", - G_CALLBACK (on_handle_DisplayPasskey), - NULL); - - g_signal_connect (agnet_interface, - "handle-request-confirmation", - G_CALLBACK (on_handle_RequestConfirmation), - NULL); - - g_signal_connect (agnet_interface, - "handle-request-authorization", - G_CALLBACK (on_handle_RequestAuthorization), - NULL); - - g_signal_connect (agnet_interface, - "handle-authorize-service", - G_CALLBACK (on_handle_AuthorizeService), - NULL); - - g_signal_connect (agnet_interface, - "handle-cancel", - G_CALLBACK (on_handle_Cancel), - NULL); - - ret = g_dbus_interface_skeleton_export ( - G_DBUS_INTERFACE_SKELETON (agnet_interface), - system_conn, - AGENT_PATH, - &error); - - if (FALSE == ret) - { - LOGE("errr:%s",error->message); - g_error_free(error); - g_object_unref(system_conn); - - return -1; - } - - value = g_dbus_connection_call_sync(system_conn, BLUEZ_SERVICE, - AGENT_PATH, AGENT_MANAGER_INTERFACE, - "RegisterAgent", g_variant_new("(os)", AGENT_PATH, - agent_capability), - NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, - NULL, &error); - - if (NULL == value) { - LOGE ("RegisterAgent Err: %s", error->message); - g_error_free(error); - - g_dbus_interface_skeleton_unexport( - G_DBUS_INTERFACE_SKELETON(agnet_interface)); - - g_object_unref(system_conn); - return -1; - } - - g_variant_unref(value); - - value = g_dbus_connection_call_sync(system_conn, BLUEZ_SERVICE, - AGENT_PATH, AGENT_MANAGER_INTERFACE, - "RequestDefaultAgent", g_variant_new("(o)", AGENT_PATH), - NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, - NULL, &error); - - if (NULL == value) { - LOGE ("RequestDefaultAgent Err: %s", error->message); - g_error_free(error); - - g_dbus_interface_skeleton_unexport( - G_DBUS_INTERFACE_SKELETON(agnet_interface)); - - g_object_unref(system_conn); - return -1; - } - - g_variant_unref(value); - - agent_capability = NULL; - - agent_registered = TRUE; - - return 0; -} - -#ifdef AGENT_THREAD -/* - * agent thread function - */ -static void *agent_event_loop_thread(const char *capability) -{ - - agentLoop = g_main_loop_new(NULL, FALSE); - guint id; - GError *error = NULL; - gboolean ret; - - ret = create_and_register_agent(capability); - - if (0 == ret) - { - LOGD("g_main_loop_run\n"); - g_main_loop_run(agentLoop); - - - } - - g_main_loop_unref(agentLoop); - agentLoop = NULL; - LOGD("exit...\n"); -} -#endif - - -/* --- PUBLIC FUNCTIONS --- */ - - -/* - * start agent. - * Returns: 0 - success or other errors - */ -int agent_register(const char *capability) -{ - int ret = 0; - LOGD("\n"); - - if (agent_registered == TRUE) { - LOGD("Agent is already registered\n"); - return -1; - } - -#ifdef AGENT_THREAD - pthread_t thread_id; - pthread_create(&thread_id, NULL, agent_event_loop_thread, capability); - pthread_setname_np(thread_id, "agent"); - -#else - ret = create_and_register_agent(capability); -#endif - - return ret; -} - -/* - * stop agent. - * Returns: 0 - success or other errors - */ -int stop_agent() -{ - GError *error = NULL; - GVariant *value; - - LOGD("\n"); - - if (agent_registered == FALSE) { - LOGD("No agent is registered\n"); - return -1; - } - - value = g_dbus_connection_call_sync(system_conn, BLUEZ_SERVICE, - AGENT_PATH, AGENT_MANAGER_INTERFACE, - "UnregisterAgent", g_variant_new("(o)", AGENT_PATH ), - NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, - NULL, &error); - - if (NULL == value) { - LOGE ("Error UnregisterAgent: %s", error->message); - g_error_free(error); - - return -1; - } - - g_dbus_interface_skeleton_unexport( - G_DBUS_INTERFACE_SKELETON(agnet_interface)); - - g_object_unref(agnet_interface); - - g_object_unref(system_conn); - - agent_registered = FALSE; - - memset(&agent_RegisterCallback, 0, sizeof(Agent_RegisterCallback_t)); - -#ifdef AGENT_THREAD - if(agentLoop){ - g_main_loop_quit(agentLoop); - } -#endif - - return 0; -} - -/* - * Register Agent Callback function - */ -void agent_API_register(const Agent_RegisterCallback_t* pstRegisterCallback) -{ - LOGD("\n"); - - if (NULL != pstRegisterCallback) - { - if (NULL != pstRegisterCallback->agent_Release) - { - agent_RegisterCallback.agent_Release = - pstRegisterCallback->agent_Release; - } - - if (NULL != pstRegisterCallback->agent_RequestPinCode) - { - agent_RegisterCallback.agent_RequestPinCode = - pstRegisterCallback->agent_RequestPinCode; - } - - if (NULL != pstRegisterCallback->agent_DisplayPinCode) - { - agent_RegisterCallback.agent_DisplayPinCode = - pstRegisterCallback->agent_DisplayPinCode; - } - - if (NULL != pstRegisterCallback->agent_RequestPasskey) - { - agent_RegisterCallback.agent_RequestPasskey = - pstRegisterCallback->agent_RequestPasskey; - } - - if (NULL != pstRegisterCallback->agent_DisplayPasskey) - { - agent_RegisterCallback.agent_DisplayPasskey = - pstRegisterCallback->agent_DisplayPasskey; - } - - if (NULL != pstRegisterCallback->agent_RequestConfirmation) - { - agent_RegisterCallback.agent_RequestConfirmation = - pstRegisterCallback->agent_RequestConfirmation; - } - - if (NULL != pstRegisterCallback->agent_RequestAuthorization) - { - agent_RegisterCallback.agent_RequestAuthorization = - pstRegisterCallback->agent_RequestAuthorization; - } - - if (NULL != pstRegisterCallback->agent_AuthorizeService) - { - agent_RegisterCallback.agent_AuthorizeService = - pstRegisterCallback->agent_AuthorizeService; - } - - if (NULL != pstRegisterCallback->agent_Cancel) - { - agent_RegisterCallback.agent_Cancel = - pstRegisterCallback->agent_Cancel; - } - - } - -} - -/* - * Send the agent event "RequestConfirmation" reply - */ -int agent_send_confirmation(gboolean confirmation) -{ - if (NULL == agent_event) - { - LOGW("Not agent event"); - return -1; - } - LOGD("%d-%d\n", confirmation, agent_event->type); - - if (REQUEST_CONFIRMATION != agent_event->type) - { - return -1; - } - - if (TRUE == confirmation){ - agent_org_bluez_agent1_complete_request_confirmation(agent_event->object, - agent_event->invocation); - }else{ - g_dbus_method_invocation_return_dbus_error (agent_event->invocation, - ERROR_BLUEZ_REJECT, ""); - } - - g_free(agent_event); - agent_event = NULL; - return 0; -} -/****************************** The End Of File ******************************/ - diff --git a/binding-bluetooth/bluetooth-agent.h b/binding-bluetooth/bluetooth-agent.h deleted file mode 100644 index 2b4b78a..0000000 --- a/binding-bluetooth/bluetooth-agent.h +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright 2016 ALPS ELECTRIC CO., LTD. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#ifndef BLUETOOTH_AGENT_H -#define BLUETOOTH_AGENT_H - -#include <glib.h> -#include <gio/gio.h> -#include <glib-object.h> - -#include "lib_agent.h" -#include "bluetooth-manager.h" - -//#define AGENT_THREAD -#define REQUEST_PINCCODE 1 -#define REQUEST_PASSKEY 2 -#define REQUEST_CONFIRMATION 3 -#define REQUEST_AUTHORIZATION 4 - -struct Agent_Node -{ - int type; - AGENTOrgBluezAgent1 *object; - GDBusMethodInvocation *invocation; -}; - -typedef struct tagAgent_RegisterCallback -{ - void (*agent_Release)(void); - gboolean (*agent_RequestPinCode) (const gchar *device, gchar **pincode, const gchar **error); - gboolean (*agent_DisplayPinCode)(const gchar *device, const gchar *pincode, const gchar **error); - gboolean (*agent_RequestPasskey)(const gchar *device, guint *passkey, const gchar **error); - void (*agent_DisplayPasskey)(const gchar *device, guint passkey, guint16 entered); - gboolean (*agent_RequestConfirmation)(const gchar *device, guint passkey, const gchar **error); - gboolean (*agent_RequestAuthorization)(const gchar *device, const gchar **error); - gboolean (*agent_AuthorizeService)(const gchar *device, const gchar *uuid, const gchar **error); - void (*agent_Cancel)(void); -}Agent_RegisterCallback_t; - - - -/* --- PUBLIC FUNCTIONS --- */ -void agent_API_register(const Agent_RegisterCallback_t* pstRegisterCallback); - -int agent_register(const char *capability); -int stop_agent(); - -int agent_send_confirmation(gboolean confirmation); - -#endif /* BLUETOOTH_AGENT_H */ - - -/****************************** The End Of File ******************************/ - diff --git a/binding-bluetooth/bluetooth-api.c b/binding-bluetooth/bluetooth-api.c deleted file mode 100644 index 3f32db1..0000000 --- a/binding-bluetooth/bluetooth-api.c +++ /dev/null @@ -1,914 +0,0 @@ -/* Copyright 2016 ALPS ELECTRIC CO., LTD. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#define _GNU_SOURCE - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <json-c/json.h> - -#define AFB_BINDING_VERSION 2 -#include <afb/afb-binding.h> - -#include "bluetooth-manager.h" -#include "bluetooth-agent.h" -#include "bluetooth-api.h" - -struct event -{ - struct event *next; - struct afb_event event; - char name[]; -}; - -static struct event *events = NULL; - -/* searchs the event of name */ -static struct event *event_get(const char *name) -{ - struct event *e = events; - while(e && strcmp(e->name, name)) - e = e->next; - return e; -} - -/* creates the event of name */ -static int event_add(const char *name) -{ - struct event *e; - - /* check valid name */ - e = event_get(name); - if (e) return -1; - - /* creation */ - e = malloc(strlen(name) + sizeof *e + 1); - if (!e) return -1; - strcpy(e->name, name); - - /* make the event */ - e->event = afb_daemon_make_event(name); - if (!e->event.closure) { free(e); return -1; } - - /* link */ - e->next = events; - events = e; - return 0; -} - -static int event_subscribe(struct afb_req request, const char *name) -{ - struct event *e; - e = event_get(name); - return e ? afb_req_subscribe(request, e->event) : -1; -} - -static int event_unsubscribe(struct afb_req request, const char *name) -{ - struct event *e; - e = event_get(name); - return e ? afb_req_unsubscribe(request, e->event) : -1; -} - -static int event_push(struct json_object *args, const char *name) -{ - struct event *e; - e = event_get(name); - return e ? afb_event_push(e->event, json_object_get(args)) : -1; -} - -static json_object *new_json_object_parse_avrcp(struct btd_device *BDdevice, unsigned int filter) -{ - json_object *jresp = json_object_new_object(); - json_object *jstring = NULL; - - if (BD_AVRCP_TITLE & filter) - { - if (BDdevice->avrcp_title) - { - jstring = json_object_new_string(BDdevice->avrcp_title); - } - else - { - jstring = json_object_new_string(""); - } - json_object_object_add(jresp, "Title", jstring); - } - - if (BD_AVRCP_ARTIST & filter) - { - if (BDdevice->avrcp_artist) - { - jstring = json_object_new_string(BDdevice->avrcp_artist); - } - else - { - jstring = json_object_new_string(""); - } - json_object_object_add(jresp, "Artist", jstring); - } - - if (BD_AVRCP_STATUS & filter) - { - if (BDdevice->avrcp_status) - { - jstring = json_object_new_string(BDdevice->avrcp_status); - } - else - { - jstring = json_object_new_string(""); - } - json_object_object_add(jresp, "Status", jstring); - } - - if (BD_AVRCP_DURATION & filter) - { - json_object_object_add(jresp, "Duration", - json_object_new_int(BDdevice->avrcp_duration)); - } - - if (BD_AVRCP_POSITION & filter) - { - json_object_object_add(jresp, "Position", - json_object_new_int(BDdevice->avrcp_position)); - } - - return jresp; -} - -/* create device json object*/ -static json_object *new_json_object_from_device(struct btd_device *BDdevice, unsigned int filter) -{ - json_object *jresp = json_object_new_object(); - json_object *jstring = NULL; - - if (BD_PATH & filter) - { - if (BDdevice->path) - { - gchar **str; - - jstring = json_object_new_string(BDdevice->path); - json_object_object_add(jresp, "Path", jstring); - - str = g_strsplit(BDdevice->path, "/", 0); - jstring = json_object_new_string(str[3]); - g_strfreev(str); - - json_object_object_add(jresp, "Adapter", jstring); - } - } - - if (BD_ADDER & filter) - { - if (BDdevice->bdaddr) - { - jstring = json_object_new_string(BDdevice->bdaddr); - } - else - { - jstring = json_object_new_string(""); - } - json_object_object_add(jresp, "Address", jstring); - } - - if (BD_NAME & filter) - { - if (BDdevice->name) - { - jstring = json_object_new_string(BDdevice->name); - } - else - { - jstring = json_object_new_string(""); - } - json_object_object_add(jresp, "Name", jstring); - } - - if (BD_PAIRED & filter) - { - jstring = (TRUE == BDdevice->paired) ? - json_object_new_string("True"):json_object_new_string("False"); - json_object_object_add(jresp, "Paired", jstring); - } - - if (BD_TRUSTED & filter) - { - jstring = (TRUE == BDdevice->trusted) ? - json_object_new_string("True"):json_object_new_string("False"); - json_object_object_add(jresp, "Trusted", jstring); - } - - if (BD_ACLCONNECTED & filter) - { - jstring = (TRUE == BDdevice->connected) ? - json_object_new_string("True"):json_object_new_string("False"); - json_object_object_add(jresp, "Connected", jstring); - } - - if (BD_AVCONNECTED & filter) - { - jstring = (TRUE == BDdevice->avconnected) ? - json_object_new_string("True"):json_object_new_string("False"); - json_object_object_add(jresp, "AVPConnected", jstring); - - if (BDdevice->avconnected) - { - jstring = new_json_object_parse_avrcp(BDdevice, filter); - json_object_object_add(jresp, "Metadata", jstring); - } - } - - if (BD_TRANSPORT_STATE & filter) - { - jstring = BDdevice->transport_state ? - json_object_new_string(BDdevice->transport_state) : - json_object_new_string("none"); - json_object_object_add(jresp, "TransportState", jstring); - } - - if (BD_TRANSPORT_VOLUME & filter) - { - json_object_object_add(jresp, "TransportVolume", - json_object_new_int(BDdevice->transport_volume)); - } - - if (BD_HFPCONNECTED & filter) - { - gpointer found = NULL; - - if (BDdevice->connected) - found = g_list_find_custom(BDdevice->uuids, HFP_UUID, strcmp); - - json_object_object_add(jresp, "HFPConnected", - json_object_new_string(found ? "True": "False")); - } - - if (BD_UUID_PROFILES & filter) - { - GList *list = BDdevice->uuids; - - if (list) - { - json_object *jarray = json_object_new_array(); - - for (;list;list=list->next) - { - jstring = json_object_new_string(list->data); - json_object_array_add(jarray, jstring); - } - json_object_object_add(jresp, "UUIDs", jarray); - } - } - - return jresp; -} - -/**/ -static void bt_power (struct afb_req request) -{ - LOGD("\n"); - - const char *value = afb_req_value (request, "value"); - json_object *jresp = NULL; - int ret = 0; - - jresp = json_object_new_object(); - - /* no "?value=" parameter : return current state */ - if (!value) { - gboolean power_value; - ret = adapter_get_powered(&power_value); - - if (0==ret) - { - (TRUE==power_value)?json_object_object_add (jresp, "power", json_object_new_string ("on")) - : json_object_object_add (jresp, "power", json_object_new_string ("off")); - } - else - { - afb_req_fail (request, "failed", "Unable to get power status"); - return; - } - - } - - /* "?value=" parameter is "1" or "true" */ - else if ( atoi(value) == 1 || !strcasecmp(value, "true") ) - { - if (adapter_set_powered (TRUE)) - { - afb_req_fail (request,"failed","no more radio devices available"); - return; - } - json_object_object_add (jresp, "power", json_object_new_string ("on")); - } - - /* "?value=" parameter is "0" or "false" */ - else if ( atoi(value) == 0 || !strcasecmp(value, "false") ) - { - if (adapter_set_powered (FALSE)) - { - afb_req_fail (request, "failed", "Unable to release radio device"); - return; - } - - json_object_object_add (jresp, "power", json_object_new_string("off")); - } - else - { - afb_req_fail (request, "failed", "Invalid value"); - return; - } - - afb_req_success (request, jresp, "Radio - Power set"); -} - -/**/ -static void bt_start_discovery (struct afb_req request) -{ - LOGD("\n"); - int ret = 0; - - ret = adapter_start_discovery(); - - if (ret) - { - afb_req_fail (request, "failed", "Unable to start discovery"); - return; - } - - afb_req_success (request, NULL, NULL); -} - -/**/ -static void bt_stop_discovery (struct afb_req request) -{ - LOGD("\n"); - int ret = 0; - - ret = adapter_stop_discovery(); - - if (ret) - { - afb_req_fail (request, "failed", "Unable to stop discovery"); - return; - } - - afb_req_success (request, NULL, NULL); -} - - -/**/ -static void bt_discovery_result (struct afb_req request) -{ - LOGD("\n"); - GSList *list = NULL; - GSList *tmp = NULL; - //adapter_update_devices(); - list = adapter_get_devices_list(); - if (NULL == list) - { - afb_req_fail (request, "failed", "No find devices"); - return; - } - - json_object *jresp = json_object_new_object(); - json_object *my_array = json_object_new_array(); - - tmp = list; - for(;tmp;tmp=tmp->next) - { - struct btd_device *BDdevice = tmp->data; - //LOGD("\n%s\t%s\n",BDdevice->bdaddr,BDdevice->name); - - unsigned int filter = BD_ADDER|BD_NAME|BD_PATH|BD_PAIRED|BD_ACLCONNECTED|BD_AVCONNECTED|BD_HFPCONNECTED|BD_UUID_PROFILES; - - json_object *jresp = new_json_object_from_device(BDdevice, filter); - - json_object_array_add(my_array, jresp); - } - - adapter_devices_list_free(list); - - json_object_object_add(jresp, "list", my_array); - - afb_req_success(request, jresp, "BT - Scan Result is Displayed"); -} - -/**/ -static void bt_pair (struct afb_req request) -{ - LOGD("\n"); - - const char *value = afb_req_value (request, "value"); - int ret = 0; - - if (NULL == value) - { - afb_req_fail (request, "failed", "Please Input the Device Address"); - return; - } - - ret = device_pair(value); - if (0 == ret) - { - afb_req_success (request, NULL, NULL); - } - else - { - afb_req_fail (request, "failed", "Device pairing failed"); - } - -} - -/**/ -static void bt_cancel_pairing (struct afb_req request) -{ - LOGD("\n"); - - const char *value = afb_req_value (request, "value"); - int ret = 0; - - if (NULL == value) - { - afb_req_fail (request, "failed", "Please Input the Device Address"); - return; - } - - ret = device_cancelPairing(value); - if (0 == ret) - { - afb_req_success (request, NULL, NULL); - } - else - { - afb_req_fail (request, "failed", "Device cancel pairing failed"); - } - -} - -/**/ -static void bt_connect (struct afb_req request) -{ - LOGD("\n"); - - const char *value = afb_req_value (request, "value"); - const char *uuid = afb_req_value (request, "uuid"); - int ret = 0; - - if (NULL == value) - { - afb_req_fail (request, "failed", "Please Input the Device Address"); - return; - } - - ret = device_connect(value, uuid); - - if (0 == ret) - { - json_object *jresp = json_object_new_object(); - json_object *jstring; - - jstring = json_object_new_string("connected"); - json_object_object_add(jresp, "Status", jstring); - - jstring = json_object_new_string(value); - json_object_object_add(jresp, "Address", jstring); - - if (uuid) { - jstring = json_object_new_string(uuid); - json_object_object_add(jresp, "UUID", jstring); - } - - event_push(jresp, "connection"); - afb_req_success (request, NULL, NULL); - } - else - { - afb_req_fail (request, "failed", "Device connect failed"); - } - -} - -/**/ -static void bt_disconnect (struct afb_req request) -{ - LOGD("\n"); - - const char *value = afb_req_value (request, "value"); - const char *uuid = afb_req_value (request, "uuid"); - int ret = 0; - - if (NULL == value) - { - afb_req_fail (request, "failed", "Please Input the Device Address"); - return; - } - - ret = device_disconnect(value, uuid); - if (0 == ret) - { - json_object *jresp = json_object_new_object(); - json_object *jstring; - - jstring = json_object_new_string("disconnected"); - json_object_object_add(jresp, "Status", jstring); - - jstring = json_object_new_string(value); - json_object_object_add(jresp, "Address", jstring); - - if (uuid) { - jstring = json_object_new_string(uuid); - json_object_object_add(jresp, "UUID", jstring); - } - - event_push(jresp, "connection"); - afb_req_success (request, NULL, NULL); - } - else - { - afb_req_fail (request, "failed", "Device disconnect failed"); - } - -} - -/**/ -static void bt_remove_device (struct afb_req request) -{ - LOGD("\n"); - - const char *value = afb_req_value (request, "value"); - int ret = 0; - - if (NULL == value) - { - afb_req_fail (request, "failed", "Please Input the Device Address"); - return; - } - - ret = adapter_remove_device(value); - if (0 == ret) - { - afb_req_success (request, NULL, NULL); - } - else - { - afb_req_fail (request, "failed", "Remove Device failed"); - } - -} - -static void bt_device_priorities_cb (json_object *array, gchar *str) -{ - json_object_array_add(array, json_object_new_string(str)); -} - -static void bt_device_priorities (struct afb_req request) -{ - json_object *jarray = json_object_new_array(); - - device_priority_list(&bt_device_priorities_cb, jarray); - - afb_req_success(request, jarray, "Display paired device priority"); -} - -/**/ -static void bt_set_device_property (struct afb_req request) -{ - LOGD("\n"); - - const char *address = afb_req_value (request, "Address"); - const char *property = afb_req_value (request, "Property"); - const char *value = afb_req_value (request, "value"); - int ret = 0; - GSList *list = NULL; - - if (NULL == address || NULL==property || NULL==value) - { - afb_req_fail (request, "failed", "Please Check Input Parameter"); - return; - } - - ret = device_set_property(address, property, value); - if (0 == ret) - { - afb_req_success (request, NULL, NULL); - } - else - { - afb_req_fail (request, "failed", "Device set property failed"); - } - -} - -/**/ -static void bt_set_property (struct afb_req request) -{ - LOGD("\n"); - - const char *property = afb_req_value (request, "Property"); - const char *value = afb_req_value (request, "value"); - int ret = 0; - gboolean setvalue; - - - if (NULL==property || NULL==value) - { - afb_req_fail (request, "failed", "Please Check Input Parameter"); - return; - } - - - if ( atoi(value) == 1 || !strcasecmp(value, "true") ) - { - ret = adapter_set_property (property, TRUE); - - } - - /* "?value=" parameter is "0" or "false" */ - else if ( atoi(value) == 0 || !strcasecmp(value, "false") ) - { - ret = adapter_set_property (property, FALSE); - } - else - { - afb_req_fail (request, "failed", "Invalid value"); - return; - } - - if (0 == ret) - { - afb_req_success (request, NULL, NULL); - } - else - { - afb_req_fail (request, "failed", "Bluetooth set property failed"); - } - -} - -/**/ -static void bt_set_avrcp_controls (struct afb_req request) -{ - LOGD("\n"); - - const char *address = afb_req_value (request, "Address"); - const char *value = afb_req_value (request, "value"); - int ret = 0; - GSList *list = NULL; - - if (NULL==value) - { - afb_req_fail (request, "failed", "Please Check Input Parameter"); - return; - } - - if (NULL == address) - { - list = adapter_get_devices_list(); - if (NULL == list) - { - afb_req_fail (request, "failed", "No find devices"); - return; - } - - for (;list;list=list->next) - { - struct btd_device *BDdevice = list->data; - //LOGD("\n%s\t%s\n",BDdevice->bdaddr,BDdevice->name); - if (BDdevice->avconnected) - { - address = BDdevice->bdaddr; - break; - } - } - } - - ret = device_call_avrcp_method(address, value); - if (0 == ret) - { - afb_req_success (request, NULL, NULL); - } - else - { - afb_req_fail (request, "failed", "Bluetooth set avrcp control failed"); - } -} - -static void subscribe(struct afb_req request) -{ - const char *name = afb_req_value(request, "value"); - - if (name == NULL) - afb_req_fail(request, "failed", "bad arguments"); - else if (0 != event_subscribe(request, name)) - afb_req_fail(request, "failed", "subscription error"); - else - afb_req_success(request, NULL, NULL); -} - -static void unsubscribe(struct afb_req request) -{ - const char *name = afb_req_value(request, "value"); - - if (name == NULL) - afb_req_fail(request, "failed", "bad arguments"); - else if (0 != event_unsubscribe(request, name)) - afb_req_fail(request, "failed", "unsubscription error"); - else - afb_req_success(request, NULL, NULL); -} - -/* - * broadcast new device - */ -void bt_broadcast_device_added(struct btd_device *BDdevice) -{ - unsigned int filter = BD_ADDER|BD_NAME|BD_PATH|BD_PAIRED|BD_ACLCONNECTED|BD_AVCONNECTED|BD_HFPCONNECTED|BD_UUID_PROFILES; - int ret; - json_object *jresp = new_json_object_from_device(BDdevice, filter); - - LOGD("\n"); - ret = event_push(jresp,"device_added"); - LOGD("%d\n",ret); -} - -/* - * broadcast device removed - */ -void bt_broadcast_device_removed(struct btd_device *BDdevice) -{ - unsigned int filter = BD_ADDER|BD_PATH; - int ret; - json_object *jresp = new_json_object_from_device(BDdevice, filter); - - LOGD("\n"); - ret = event_push(jresp,"device_removed"); - LOGD("%d\n",ret); -} - - -/* - * broadcast device updated - */ -void bt_broadcast_device_properties_change(struct btd_device *BDdevice) -{ - - unsigned int filter = BD_ADDER|BD_NAME|BD_PATH|BD_PAIRED|BD_ACLCONNECTED|BD_AVCONNECTED|BD_HFPCONNECTED|BD_AVRCP_TITLE|BD_AVRCP_ARTIST|BD_AVRCP_STATUS|BD_AVRCP_DURATION|BD_AVRCP_POSITION|BD_TRANSPORT_STATE|BD_TRANSPORT_VOLUME|BD_UUID_PROFILES; - - int ret; - json_object *jresp = new_json_object_from_device(BDdevice, filter); - - LOGD("\n"); - ret = event_push(jresp,"device_updated"); - LOGD("%d\n",ret); -} - -/* - * broadcast request confirmation - */ -gboolean bt_request_confirmation(const gchar *device, guint passkey) -{ - json_object *jresp = json_object_new_object(); - json_object *jstring = NULL; - int ret; - - jstring = json_object_new_string(device); - json_object_object_add(jresp, "Address", jstring); - jstring = json_object_new_int(passkey); - json_object_object_add(jresp, "Passkey", jstring); - - ret = event_push(jresp,"request_confirmation"); - - LOGD("%d\n",ret); - - if (ret >0) { - return TRUE; - }else { - return FALSE; - } - -} - -static void bt_send_confirmation(struct afb_req request) -{ - const char *value = afb_req_value(request, "value"); - int ret; - gboolean confirmation; - - if (!value) { - afb_req_fail (request, "failed", "Unable to get value status"); - return; - } - - /* "?value=" parameter is "1" or "yes" */ - else if ( atoi(value) == 1 || !strcasecmp(value, "yes") ) - { - ret = agent_send_confirmation (TRUE); - } - - /* "?value=" parameter is "0" or "no" */ - else if ( atoi(value) == 0 || !strcasecmp(value, "no") ) - { - ret = agent_send_confirmation (TRUE); - } - else - { - afb_req_fail (request, "failed", "Invalid value"); - return; - } - - if ( 0==ret) { - afb_req_success(request, NULL, NULL); - }else { - afb_req_success(request, "failed", "fail"); - } - -} - -static void bt_version(struct afb_req request) -{ - json_object *jresp = json_object_new_object(); - - json_object_object_add(jresp, "version", json_object_new_string("1.0")); - - afb_req_success(request, jresp, "Bluetooth - Binding version"); -} - -/* - * array of the verbs exported to afb-daemon - */ -static const struct afb_verb_v2 binding_verbs[]= { -/* VERB'S NAME FUNCTION TO CALL SHORT DESCRIPTION */ -{ .verb = "power", .callback = bt_power, .info = "Set Bluetooth Power ON or OFF" }, -{ .verb = "start_discovery", .callback = bt_start_discovery, .info = "Start discovery" }, -{ .verb = "stop_discovery", .callback = bt_stop_discovery, .info = "Stop discovery" }, -{ .verb = "discovery_result", .callback = bt_discovery_result, .info = "Get discovery result" }, -{ .verb = "remove_device", .callback = bt_remove_device, .info = "Remove the special device" }, -{ .verb = "pair", .callback = bt_pair, .info = "Pair to special device" }, -{ .verb = "cancel_pair", .callback = bt_cancel_pairing, .info = "Cancel the pairing process" }, -{ .verb = "connect", .callback = bt_connect, .info = "Connect to special device" }, -{ .verb = "disconnect", .callback = bt_disconnect, .info = "Disconnect special device" }, -{ .verb = "device_priorities", .callback = bt_device_priorities, .info = "Get BT paired device priorites" }, -{ .verb = "set_device_property", .callback = bt_set_device_property, .info = "Set special device property" }, -{ .verb = "set_property", .callback = bt_set_property, .info = "Set Bluetooth property" }, -{ .verb = "set_avrcp_controls", .callback = bt_set_avrcp_controls, .info = "Set Bluetooth AVRCP controls" }, -{ .verb = "send_confirmation", .callback = bt_send_confirmation, .info = "Send Confirmation" }, -{ .verb = "subscribe", .callback = subscribe, .info = "subscribes to the event of 'value'"}, -{ .verb = "unsubscribe", .callback = unsubscribe, .info = "unsubscribes to the event of 'value'"}, -{ .verb = "version", .callback = bt_version, .info = "report the binder version API"}, - -{ } /* marker for end of the array */ -}; - -/* - * activation function for registering the binding called by afb-daemon - */ - -static int init() -{ - Binding_RegisterCallback_t API_Callback; - API_Callback.binding_device_added = bt_broadcast_device_added; - API_Callback.binding_device_removed = bt_broadcast_device_removed; - API_Callback.binding_device_properties_changed = bt_broadcast_device_properties_change; - API_Callback.binding_request_confirmation = bt_request_confirmation; - BindingAPIRegister(&API_Callback); - - // register binding events - event_add("connection"); - event_add("request_confirmation"); - event_add("device_added"); - event_add("device_removed"); - event_add("device_updated"); - - return BluetoothManagerInit(); -} - -/* - * description of the binding for afb-daemon - */ -const struct afb_binding_v2 afbBindingV2 = -{ - .specification = "Application Framework Binder - Bluetooth Manager plugin", - .api = "Bluetooth-Manager", - .verbs = binding_verbs, - .init = init, -}; - -/***************************** The End Of File ******************************/ - diff --git a/binding-bluetooth/bluetooth-api.h b/binding-bluetooth/bluetooth-api.h deleted file mode 100644 index 55a9095..0000000 --- a/binding-bluetooth/bluetooth-api.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2016 ALPS ELECTRIC CO., LTD. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#ifndef BLUETOOTH_API_H -#define BLUETOOTH_API_H - - -#define LEFT_SHIFT(shift) (0x00000001ul << (shift) ) - -#define BD_NONE 0x00000000 -#define BD_PATH LEFT_SHIFT(0) -#define BD_ADDER LEFT_SHIFT(1) -#define BD_NAME LEFT_SHIFT(2) -#define BD_ALIAS LEFT_SHIFT(3) -#define BD_PAIRED LEFT_SHIFT(4) -#define BD_TRUSTED LEFT_SHIFT(5) -#define BD_BLOCKED LEFT_SHIFT(6) -#define BD_ACLCONNECTED LEFT_SHIFT(7) -#define BD_AVCONNECTED LEFT_SHIFT(8) -#define BD_HFPCONNECTED LEFT_SHIFT(9) -#define BD_LEGACYPAIRING LEFT_SHIFT(10) -#define BD_RSSI LEFT_SHIFT(11) -#define BD_AVRCP_TITLE LEFT_SHIFT(12) -#define BD_AVRCP_ARTIST LEFT_SHIFT(13) -#define BD_AVRCP_STATUS LEFT_SHIFT(14) -#define BD_AVRCP_DURATION LEFT_SHIFT(15) -#define BD_AVRCP_POSITION LEFT_SHIFT(16) -#define BD_TRANSPORT_STATE LEFT_SHIFT(17) -#define BD_TRANSPORT_VOLUME LEFT_SHIFT(18) -#define BD_UUID_PROFILES LEFT_SHIFT(19) - - -/* -------------- PLUGIN DEFINITIONS ----------------- */ - -typedef struct { - void *bt_server; /* handle to implementation */ - unsigned int index; /* currently selected media file */ -} BtCtxHandleT; - -#define HFP_UUID "0000111f-0000-1000-8000-00805f9b34fb" - -#endif /* BLUETOOTH_API_H */ - - - -/****************************** The End Of File ******************************/ - - diff --git a/binding-bluetooth/bluetooth-manager.c b/binding-bluetooth/bluetooth-manager.c deleted file mode 100644 index fd80f10..0000000 --- a/binding-bluetooth/bluetooth-manager.c +++ /dev/null @@ -1,1981 +0,0 @@ -/* Copyright 2016 ALPS ELECTRIC CO., LTD. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <pthread.h> -#include <fcntl.h> -#include <glib.h> -#include <gio/gio.h> -#include <glib/gstdio.h> -#include <glib-object.h> -#include <syslog.h> -#include <linux/rfkill.h> -#include <sys/socket.h> -#include <sys/time.h> - -#include "bluetooth-manager.h" -#include "bluez-client.h" -#include "bluetooth-agent.h" - -static Client cli = { 0 }; -static Binding_RegisterCallback_t g_RegisterCallback = { 0 }; -static stBluetoothManage BluetoothManage = { 0 }; -static FILE *logfp= NULL; - -/* ------ LOCAL FUNCTIONS --------- */ -void BluetoothManage_InitFlag_Set(gboolean value) -{ - g_mutex_lock(&(BluetoothManage.m)); - BluetoothManage.inited = value; - g_mutex_unlock(&(BluetoothManage.m)); -} - -gboolean BluetoothManage_InitFlag_Get(void) -{ - gboolean inited; - - g_mutex_lock(&(BluetoothManage.m)); - inited = BluetoothManage.inited; - g_mutex_unlock(&(BluetoothManage.m)); - - return inited; -} - -void devices_list_lock(void) -{ - g_mutex_lock(&(BluetoothManage.m)); -} - -void devices_list_unlock(void) -{ - g_mutex_unlock(&(BluetoothManage.m)); -} - -gchar *bt_priority_path() -{ - gchar *path = g_build_filename(g_get_user_config_dir(), "bluetooth", NULL); - gchar *file; - - g_mkdir(path, 0664); - - file = g_build_filename(path, "priorities.lst", NULL); - g_free(path); - - return file; -} - -void bt_remove_priority(gchar *bdaddr) -{ - LOGD("\n"); - FILE *fp; - GSList *item, *tmp; - gchar *path; - - LOGD("bd_addr: %s\n", bdaddr); - - devices_list_lock(); - - item = g_slist_find_custom(BluetoothManage.priorities, bdaddr, g_strcmp0); - if (item == NULL) - { - devices_list_unlock(); - return; - } - g_free(item->data); - tmp = BluetoothManage.priorities = g_slist_remove_link(BluetoothManage.priorities, item); - - path = bt_priority_path(); - fp = g_fopen(path, "w"); - g_free(path); - - if (fp == NULL) - { - devices_list_unlock(); - return; - } - - while (tmp && tmp->data) - { - fputs(tmp->data, fp); - fputs("\n", fp); - tmp = tmp->next; - } - - fclose(fp); - - devices_list_unlock(); -} - -void bt_save_priority(gchar *bdaddr) -{ - LOGD("\n"); - FILE *fp; - gchar *path; - - LOGD("bd_addr: %s\n", bdaddr); - - devices_list_lock(); - - if (g_slist_find(BluetoothManage.priorities, bdaddr)) - { - devices_list_unlock(); - return; - } - - path = bt_priority_path(); - fp = g_fopen(path, "a+"); - g_free(path); - - if (fp == NULL) - { - devices_list_unlock(); - return; - } - - fputs(bdaddr, fp); - fputs("\n", fp); - fclose(fp); - - BluetoothManage.priorities = g_slist_append(BluetoothManage.priorities, g_strdup(bdaddr)); - - devices_list_unlock(); -} - -GSList *bt_priority_list() -{ - LOGD("\n"); - FILE *fp; - GSList *list = NULL; - gchar *path; - gchar bdaddr[18]; - - devices_list_lock(); - - path = bt_priority_path(); - - fp = g_fopen(path, "r"); - g_free(path); - - if (fp == NULL) - { - devices_list_unlock(); - return NULL; - } - - while (fscanf(fp, "%17s\n", &bdaddr) == 1) - { - LOGD("Found priority device %s\n", bdaddr); - list = g_slist_append(list, g_strdup(bdaddr)); - } - - devices_list_unlock(); - - return list; -} - -int device_priority_list(void *(object_cb)(void *, gchar *), void *ptr) -{ - GSList *tmp; - - devices_list_lock(); - - tmp = BluetoothManage.priorities; - - while (tmp) - { - object_cb(ptr, tmp->data); - tmp = tmp->next; - } - - devices_list_unlock(); - - return 0; -} - -static int device_path_cmp(struct btd_device * device, const gchar* pPath ) -{ - return !g_str_has_prefix (pPath, device->path); -} - -/* - * search device by path - * Returns the first found btd_device or NULL if it is not found - */ -struct btd_device *devices_list_find_device_by_path(const gchar* pPath) -{ - GSList * temp; - - temp = g_slist_find_custom (BluetoothManage.device, pPath, - (GCompareFunc)device_path_cmp); - - if (temp) { - return temp->data; - } - - return NULL; - -} - - -static int device_bdaddr_cmp(struct btd_device * device, const gchar* pBDaddr ) -{ - return g_strcmp0 (device->bdaddr, pBDaddr); -} - -/* - * search device by path - * Returns the first found btd_device or NULL if it is not found - */ -struct btd_device *devices_list_find_device_by_bdaddr(const gchar* pBDaddr) -{ - GSList * temp; - - temp = g_slist_find_custom (BluetoothManage.device, pBDaddr, - (GCompareFunc)device_bdaddr_cmp); - - if (temp) { - return temp->data; - } - - return NULL; - -} - - -/* - * make a copy of each element - * And, to entirely free the new btd_device, you could do: device_free - */ -struct btd_device *device_copy(struct btd_device* device) -{ - struct btd_device * temp; - - if (NULL == device) { - return NULL; - } - - temp = g_malloc0(sizeof(struct btd_device)); - temp->path = g_strdup(device->path); - temp->bdaddr = g_strdup(device->bdaddr); - temp->name = g_strdup(device->name); - temp->paired = device->paired; - temp->trusted = device->trusted; - temp->connected = device->connected; - temp->avconnected = device->avconnected; - temp->hfpconnected = device->hfpconnected; - temp->uuids = g_list_copy_deep(device->uuids, g_strdup, NULL); - - return temp; -} - -/* - * Frees all of the memory - */ -void device_free(struct btd_device* device) -{ - - if (NULL == device) { - return ; - } - D_PRINTF("device %p\n",device); - if (device->path) { - D_PRINTF("path:%s\n",device->path); - g_free(device->path); - device->path = NULL; - } - if (device->bdaddr) { - D_PRINTF("bdaddr:%s\n",device->bdaddr); - g_free(device->bdaddr); - device->bdaddr = NULL; - } - if (device->name) { - D_PRINTF("name:%s\n",device->name); - g_free(device->name); - device->name = NULL; - } - - if (device->avrcp_title) { - D_PRINTF("avrcp_title:%s\n",device->avrcp_title); - g_free(device->avrcp_title); - device->avrcp_title = NULL; - } - - if (device->avrcp_artist) { - D_PRINTF("avrcp_artist:%s\n",device->avrcp_artist); - g_free(device->avrcp_artist); - device->avrcp_artist = NULL; - } - - if (device->avrcp_status) { - D_PRINTF("avrcp_status:%s\n",device->avrcp_status); - g_free(device->avrcp_status); - device->avrcp_status = NULL; - } - - if (device->transport_state) { - D_PRINTF("transport_state:%s\n",device->transport_state); - g_free(device->transport_state); - device->transport_state = NULL; - } - - if (device->uuids) { - D_PRINTF("uuids: xxx\n"); - g_list_free_full(device->uuids, g_free); - device->uuids = NULL; - } - - g_free(device); -} - -void device_print(struct btd_device *BDdevice) -{ - g_print("device %p\n",BDdevice); - g_print("bdaddr\t\t:%s\n",BDdevice->bdaddr); - g_print("name\t\t:%s\n",BDdevice->name); - g_print("trusted\t\t:%d\n",BDdevice->trusted); - g_print("paired\t\t:%d\n",BDdevice->paired); - - g_print("connected\t:%d\n",BDdevice->connected); - g_print("AVPconnected\t:%d\n",BDdevice->avconnected); - g_print("HFPconnected\t:%d\n",BDdevice->hfpconnected); -} - -/* - * remove all the devices - */ -void devices_list_cleanup() -{ - LOGD("\n"); - GSList * temp = BluetoothManage.device; - while (temp) { - struct btd_device *BDdevice = temp->data; - temp = temp->next; - - BluetoothManage.device = g_slist_remove_all(BluetoothManage.device, - BDdevice); - - device_free(BDdevice); - } -} - -/* - * Print all the devices - */ -void devices_list_print() -{ - LOGD("\n"); - GSList * temp = BluetoothManage.device; - while (temp) { - struct btd_device *BDdevice = temp->data; - temp = temp->next; - g_print("----------------------------------------\n"); - device_print(BDdevice); - } - g_print("----------------------------------------\n"); -} - -/* - * update device from Interfcace org.bluez.MediaControl1 properties - */ -static int device_update_from_MediaControl1(struct btd_device *device, - GVariant *value) -{ - GVariantIter iter; - const gchar *key; - GVariant *subValue; - - if ((NULL==device) || (NULL==value)) - { - return -1; - } - - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "{&sv}", &key, &subValue)) - { - //gchar *s = g_variant_print (subValue, TRUE); - //g_print (" %s -> %s\n", key, s); - //g_free (s); - - gboolean value_b = FALSE;//b gboolean - //gchar value_c = 0; - //guchar value_y = 0;//y guchar - //gint16 value_n = 0;//n gint16 - //guint16 value_q = 0;//q guint16 - //gint32 value_i = 0;//i gint32 - //guint32 value_u = 0;//u guint32 - //gint64 value_x = 0;//x gint64 - //guint64 value_t = 0;//t guint64 - //gint32 value_h = 0;//h gint32 - //gdouble value_d = 0.0;//d gdouble - gchar *str;//d gdouble - - if (0==g_strcmp0(key,"Connected")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("Connected %d\n",value_b); - device->avconnected = value_b; - }else if (0==g_strcmp0(key,"Player")) { - g_variant_get(subValue, "o", &str ); - D_PRINTF("Player Object %s\n",str); - } - } - - return 0; -} - -/* - * update device from Interface org.bluez.MediaTransport1 properties - */ -static int device_update_from_MediaTransport1(struct btd_device *device, - GVariant *value) -{ - GVariantIter iter; - const gchar *key; - GVariant *subValue; - - if ((NULL==device) || (NULL==value)) - { - return -1; - } - - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "{&sv}", &key, &subValue)) - { - //gchar *s = g_variant_print (subValue, TRUE); - //g_print (" %s -> %s\n", key, s); - //g_free (s); - - //gboolean value_b = FALSE;//b gboolean - //gchar value_c = 0; - //guchar value_y = 0;//y guchar - //gint16 value_n = 0;//n gint16 - guint16 value_q = 0;//q guint16 - //gint32 value_i = 0;//i gint32 - //guint32 value_u = 0;//u guint32 - //gint64 value_x = 0;//x gint64 - //guint64 value_t = 0;//t guint64 - //gint32 value_h = 0;//h gint32 - //gdouble value_d = 0.0;//d gdouble - gchar *str;//d gdouble - - if (0==g_strcmp0(key,"State")) { - g_variant_get(subValue, "s", &str); - D_PRINTF("State %s\n", str); - if (device->transport_state) - free(device->transport_state); - device->transport_state = g_strdup(str); - } else if (0==g_strcmp0(key,"Volume")) { - g_variant_get(subValue, "q", &value_q); - D_PRINTF("Volume %d\n", value_q); - device->transport_volume = value_q; - } - } - - return 0; -} - - -static int device_update_from_Track(struct btd_device *device, - GVariant *value) -{ - GVariantIter iter; - const gchar *key; - GVariant *subValue; - - if ((NULL==device) || (NULL==value)) - { - return -1; - } - - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "{&sv}", &key, &subValue)) - { - //gchar *s = g_variant_print (subValue, TRUE); - //g_print (" %s -> %s\n", key, s); - //g_free (s); - - gboolean value_b = FALSE;//b gboolean - //gchar value_c = 0; - //guchar value_y = 0;//y guchar - //gint16 value_n = 0;//n gint16 - //guint16 value_q = 0;//q guint16 - //gint32 value_i = 0;//i gint32 - guint32 value_u = 0;//u guint32 - //gint64 value_x = 0;//x gint64 - //guint64 value_t = 0;//t guint64 - //gint32 value_h = 0;//h gint32 - //gdouble value_d = 0.0;//d gdouble - gchar *str;//d gdouble - - if (0==g_strcmp0(key,"Title")) { - g_variant_get(subValue, "s", &str); - D_PRINTF("Title %s\n", str); - if (device->avrcp_title) - free(device->avrcp_title); - device->avrcp_title = g_strdup(str); - } else if (0==g_strcmp0(key,"Artist")) { - g_variant_get(subValue, "s", &str); - D_PRINTF("Artist %s\n", str); - if (device->avrcp_artist) - free(device->avrcp_artist); - device->avrcp_artist = g_strdup(str); - } else if (0==g_strcmp0(key,"Duration")) { - g_variant_get(subValue, "u", &value_u); - D_PRINTF("Duration %u\n", value_u); - device->avrcp_duration = value_u; - } - } - - return 0; -} - -/* - * update device from Interface org.bluez.MediaPlayer1 properties - */ -static int device_update_from_MediaPlayer1(struct btd_device *device, - GVariant *value) -{ - GVariantIter iter; - const gchar *key; - GVariant *subValue; - - if ((NULL==device) || (NULL==value)) - { - return -1; - } - - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "{&sv}", &key, &subValue)) - { - //gchar *s = g_variant_print (subValue, TRUE); - //g_print (" %s -> %s\n", key, s); - //g_free (s); - - gboolean value_b = FALSE;//b gboolean - //gchar value_c = 0; - //guchar value_y = 0;//y guchar - //gint16 value_n = 0;//n gint16 - //guint16 value_q = 0;//q guint16 - //gint32 value_i = 0;//i gint32 - guint32 value_u = 0;//u guint32 - //gint64 value_x = 0;//x gint64 - //guint64 value_t = 0;//t guint64 - //gint32 value_h = 0;//h gint32 - //gdouble value_d = 0.0;//d gdouble - gchar *str;//d gdouble - - if (0==g_strcmp0(key,"Status")) { - g_variant_get(subValue, "s", &str); - D_PRINTF("Status %s\n", str); - if (device->avrcp_status) - free(device->avrcp_status); - device->avrcp_status = g_strdup(str); - } else if (0==g_strcmp0(key,"Position")) { - g_variant_get(subValue, "u", &value_u); - D_PRINTF("Position %d\n", value_u); - device->avrcp_position = value_u; - } else if (0==g_strcmp0(key,"Track")) { - device_update_from_Track(device, subValue); - } - } - - return 0; -} - -/* - * update device from Interfcace org.bluez.Device1 properties - */ -static int device_update_from_Device1(struct btd_device *device, - GVariant *value) -{ - if ((NULL==device) || (NULL==value)) - { - return -1; - } - - GVariantIter iter; - const gchar *key; - GVariant *subValue; - - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "{&sv}", &key, &subValue)) - { - //gchar *s = g_variant_print (subValue, TRUE); - //g_print (" %s -> %s\n", key, s); - //g_free (s); - - gboolean value_b = FALSE;//b gboolean - //gchar value_c = 0; - //guchar value_y = 0;//y guchar - //gint16 value_n = 0;//n gint16 - //guint16 value_q = 0;//q guint16 - //gint32 value_i = 0;//i gint32 - //guint32 value_u = 0;//u guint32 - //gint64 value_x = 0;//x gint64 - //guint64 value_t = 0;//t guint64 - //gint32 value_h = 0;//h gint32 - //gdouble value_d = 0.0;//d gdouble - gchar *str;//d gdouble - - if (0==g_strcmp0(key,"Address")) { - g_variant_get(subValue, "s", &str ); - D_PRINTF("Address %s\n",str); - - if (device->bdaddr) - g_free (device->bdaddr); - - device->bdaddr = g_strdup(str); - - g_free (str); - str = NULL; - - }else if (0==g_strcmp0(key,"Name")) { - g_variant_get(subValue, "s", &str ); - D_PRINTF("Name %s\n",str); - - if (device->name) - g_free (device->name); - - device->name = g_strdup(str); - - g_free (str); - str = NULL; - - }else if (0==g_strcmp0(key,"Paired")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("Paired %d\n",value_b); - device->paired = value_b; - }else if (0==g_strcmp0(key,"Trusted")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("Trusted %d\n",value_b); - device->trusted = value_b; - }else if (0==g_strcmp0(key,"Connected")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("Connected %d\n",value_b); - device->connected = value_b; - } - } - - return 0; - -} -#if 0 -/* - * update device from Interfcace org.bluez.MediaControl1 properties - */ -static int bluez_mediacontrol1_properties_update(struct bt_device *device, - GVariant *value) -{ - GVariantIter iter; - const gchar *key; - GVariant *subValue; - - if ((NULL==device) || (NULL==value)) - { - return -1; - } - - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "{&sv}", &key, &subValue)) - { - //gchar *s = g_variant_print (subValue, TRUE); - //g_print (" %s -> %s\n", key, s); - //g_free (s); - - gboolean value_b = FALSE;//b gboolean - //gchar value_c = 0; - //guchar value_y = 0;//y guchar - gint16 value_n = 0;//n gint16 - //guint16 value_q = 0;//q guint16 - //gint32 value_i = 0;//i gint32 - //guint32 value_u = 0;//u guint32 - //gint64 value_x = 0;//x gint64 - //guint64 value_t = 0;//t guint64 - //gint32 value_h = 0;//h gint32 - //gdouble value_d = 0.0;//d gdouble - gchar *str;//d gdouble - - if (0==g_strcmp0(key,"Connected")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("Connected %d\n",value_b); - device->avconnected = value_b; - - }else if (0==g_strcmp0(key,"Player")) { - g_variant_get(subValue, "o", &str ); - D_PRINTF("Player Object %s\n",str); - - } - } - - return 0; - -} -#endif - -/* - * make a copy of each element - */ -struct btd_device *device_copy_from_bluez(struct bt_device* device) -{ - struct btd_device * temp; - - if (NULL == device) { - return NULL; - } - - temp = g_malloc0(sizeof(struct btd_device)); - temp->path = g_strdup(device->path); - temp->bdaddr = g_strdup(device->bdaddr); - temp->name = g_strdup(device->name); - temp->paired = device->paired; - temp->trusted = device->trusted; - temp->connected = device->connected; - temp->avconnected = device->avconnected; - temp->uuids = g_list_copy_deep(device->uuids, g_strdup, NULL); - - return temp; -} - -/* - * Force Update the device list - * Call <method>GetManagedObjects - * Returns: 0 - success or other errors - */ -int devices_list_update(void) -{ - LOGD("\n"); - - GSList* list; - GSList* tmp; - list = GetBluezDevicesList(); - - if (NULL == list) - { - return -1; - } - - tmp = list; - - devices_list_lock(); - - devices_list_cleanup(); - - while(tmp) - { - struct bt_device *BDdevice = tmp->data; - tmp = tmp->next; - - struct btd_device * new_device = device_copy_from_bluez(BDdevice); - - if (new_device) - { - //BluetoothManage.device = g_slist_prepend(BluetoothManage.device, new_device); - BluetoothManage.device = - g_slist_append(BluetoothManage.device, new_device); - } - - } - - FreeBluezDevicesList(list); - - devices_list_unlock(); - - - return 0; -} - - -/* - * notify::name-owner callback function - */ -static void bluez_device_added_cb(struct bt_device *device) -{ - LOGD("\n"); - - struct btd_device * new_device; - - if (NULL == device) - { - return; - } - - new_device = device_copy_from_bluez(device); - - devices_list_lock(); - - //BluetoothManage.device = g_slist_prepend(BluetoothManage.device, new_device); - BluetoothManage.device = g_slist_append(BluetoothManage.device,new_device); - if (NULL != g_RegisterCallback.binding_device_added) - { - g_RegisterCallback.binding_device_added(new_device); - } - - devices_list_unlock(); - -} - -/* - * object-removed callback function - */ -static void bluez_device_removed_cb (const gchar *path) -{ - struct btd_device *device; - - LOGD("%s\n",path); - - devices_list_lock(); - - device = devices_list_find_device_by_path(path); - - if (device) { - BluetoothManage.device = g_slist_remove_all(BluetoothManage.device, - device); - - if (NULL != g_RegisterCallback.binding_device_removed) - { - g_RegisterCallback.binding_device_removed(device); - } - - device_free(device); - } - - devices_list_unlock(); - -} - -/* - * BLUEZ interface-proxy-properties-changed callback function - */ -static void -bluez_device_properties_changed_cb (const gchar *pObjecPath, - const gchar *pInterface, - GVariant *properties) -{ - - struct btd_device *device; - -#if 0 - gchar *s; - g_print ("Path:%s, Interface:%s\n",pObjecPath, pInterface); - g_print ("type '%s'\n", g_variant_get_type_string (properties)); - s = g_variant_print (properties, TRUE); - g_print (" %s\n", s); - g_free (s); -#endif - - LOGD("%s\n",pObjecPath); - - devices_list_lock(); - - device = devices_list_find_device_by_path(pObjecPath); - - if (0 == g_strcmp0(pInterface, DEVICE_INTERFACE)) { - - device_update_from_Device1(device, properties); - - } else if (0 == g_strcmp0(pInterface, MEDIA_CONTROL1_INTERFACE)) { - - device_update_from_MediaControl1(device, properties); - - } else if (0 == g_strcmp0(pInterface, MEDIA_PLAYER1_INTERFACE)) { - - device_update_from_MediaPlayer1(device, properties); - - } else if (0 == g_strcmp0(pInterface, MEDIA_TRANSPORT1_INTERFACE)) { - - device_update_from_MediaTransport1(device, properties); - - } - - if (g_RegisterCallback.binding_device_properties_changed) - g_RegisterCallback.binding_device_properties_changed(device); - - devices_list_unlock(); - -} - -gboolean agent_requset_confirm( const gchar *device_path, - guint passkey, - const gchar **error) -{ - gboolean ret = FALSE; - - const gchar *myerror = ERROR_BLUEZ_REJECT; - - LOGD("-%s,%d\n",device_path,passkey); - - if (NULL != g_RegisterCallback.binding_request_confirmation) - { - - devices_list_lock(); - struct btd_device *device = devices_list_find_device_by_path(device_path); - gchar *device_bdaddr = NULL; - - if (device) - { - device_bdaddr = g_strdup(device->bdaddr); - } - devices_list_unlock(); - - if (device_bdaddr) - ret = g_RegisterCallback.binding_request_confirmation(device_bdaddr, passkey); - } - - if (TRUE == ret) - { - LOGD("return TRUE\n"); - return TRUE; - }else{ - *error = myerror; - LOGD("return FALSE\n"); - return FALSE; - } -} - - -/* - * register callback function - * Returns: 0 - success or other errors - */ -static int bt_manager_app_init(void) -{ - GError *error = NULL; - int ret; - - cli.system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (error) { - LOGE("Create System GDBusconnection fail\n"); - LOGE("Error:%s\n", error->message); - g_error_free(error); - return -1; - } - - cli.session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); - if (error) { - LOGE("Create Session GDBusconnection fail\n"); - LOGE("Error:%s\n", error->message); - g_error_free(error); - g_object_unref(cli.system_conn); - return -1; - } - - Bluez_RegisterCallback_t Bluez_API_Callback; - Bluez_API_Callback.device_added = bluez_device_added_cb; - Bluez_API_Callback.device_removed = bluez_device_removed_cb; - Bluez_API_Callback.device_properties_changed = bluez_device_properties_changed_cb; - BluezDeviceAPIRegister(&Bluez_API_Callback); - - Agent_RegisterCallback_t AgentRegCallback; - AgentRegCallback.agent_RequestConfirmation = agent_requset_confirm; - agent_API_register(&AgentRegCallback); - - BluetoothManage.priorities = bt_priority_list(); - - ret = BluezManagerInit(); - if (0 != ret ) - { - LOGE("BluezManagerInit fail\n"); - return -1; - } - - ret = agent_register(""); - if (0 != ret ) - { - LOGE("agent_register fail\n"); - - BluezManagerQuit(); - return -1; - } - - return 0; -} - -int hci_interface_enable(int hdev) -{ - int ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); - int ret; - - if (ctl < 0) - return ctl; - - ret = ioctl(ctl, HCIDEVUP, hdev); - - close(ctl); - - return ret; -} - -gboolean bluetooth_rfkill_event(GIOChannel *chan, GIOCondition cond, gpointer data) -{ - LOGD("\n"); - struct rfkill_event event; - gchar *name, buf[8]; - int fd, len; - - fd = g_io_channel_unix_get_fd(chan); - len = read(fd, &event, sizeof(struct rfkill_event)); - - if (len != sizeof(struct rfkill_event)) - return TRUE; - - if (event.type != RFKILL_TYPE_BLUETOOTH) - return TRUE; - - if (event.op == RFKILL_OP_DEL) - return TRUE; - - name = g_strdup_printf("/sys/class/rfkill/rfkill%u/soft", event.idx); - - fd = g_open(name, O_WRONLY); - write(fd, "0", 1); - g_close(fd, NULL); - - g_free(name); - - memset(&buf, 0, sizeof(buf)); - - name = g_strdup_printf("/sys/class/rfkill/rfkill%u/name", event.idx); - fd = g_open(name, O_RDONLY); - len = read(fd, &buf, sizeof(buf) - 1); - - if (len > 0) - { - int idx = 0; - sscanf(buf, "hci%d", &idx); - - /* - * 50 millisecond delay to allow time for rfkill to unblock before - * attempting to bring up HCI interface - */ - g_usleep(50000); - - LOGD ("Enabling hci%d interface\n", idx); - hci_interface_enable(idx); - } - - g_free(name); - - return TRUE; -} - - -/* Create RFKILL monitor to soft unblock bluetooth devices - * - * Returns: 0 - success or other errors - */ -int BluetoothMonitorInit() -{ - int fd = g_open("/dev/rfkill", O_RDWR); - GIOChannel *chan = NULL; - - if (fd < 0) - { - LOGE("Cannot open /dev/rfkill"); - return -1; - } - - chan = g_io_channel_unix_new(fd); - g_io_channel_set_close_on_unref(chan, TRUE); - - BluetoothManage.watch = g_io_add_watch(chan, G_IO_IN, bluetooth_rfkill_event, NULL); - - g_io_channel_unref(chan); - - return 0; -} - -gboolean bt_autoconnect(gpointer ptr) -{ - LOGD("\n"); - gboolean ret = TRUE; - GSList *list, *tmp; - - devices_list_lock(); - - list = GetBluezDevicesList(); - tmp = list; - - while (tmp) - { - struct bt_device *BDdevice = tmp->data; - tmp = tmp->next; - - if (BDdevice->connected) - { - g_slist_free_full(list, g_free); - devices_list_unlock(); - return FALSE; - } - } - - g_slist_free_full(list, g_free); - devices_list_unlock(); - - tmp = BluetoothManage.priorities; - - if (tmp == NULL) - { - return TRUE; - } - - while (tmp) - { - LOGD("Autoconnect to %s\n", tmp->data); - ret = device_connect(tmp->data, NULL) ? TRUE : FALSE; - tmp = tmp->next; - - if (ret == FALSE) - break; - } - - return ret; -} - -/* - * Bluetooth Manager Thread - * register callback function and create a new GMainLoop structure - */ -static void *bt_event_loop_thread() -{ - int ret = 0; - - cli.clientloop = g_main_loop_new(NULL, FALSE); - - ret = bt_manager_app_init(); - - if (0 == ret){ - - devices_list_update(); - - BluetoothManage_InitFlag_Set(TRUE); - BluetoothMonitorInit(); - - BluetoothManage.autoconnect = g_timeout_add_seconds(5, bt_autoconnect, NULL); - - LOGD("g_main_loop_run\n"); - g_main_loop_run(cli.clientloop); - - } - - g_main_loop_unref(cli.clientloop); - - LOGD("Exit\n"); -} - -/* - * print log message - */ -void DebugTraceSendMsg(int level, gchar* message) -{ - - if (logfp) - { - struct timeval tv; - struct tm tm; - char s[32] = {0}; - - gettimeofday(&tv, NULL); - localtime_r(&tv.tv_sec, &tm); - strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", &tm); - fprintf(logfp, "[%s.%6.6d] ", s, (int)(tv.tv_usec)); - - switch (level) - { - case DT_LEVEL_ERROR: - fprintf(logfp,"[E]"); - break; - - case DT_LEVEL_WARNING: - fprintf(logfp,"[W]"); - break; - - case DT_LEVEL_NOTICE: - fprintf(logfp,"[N]"); - break; - - case DT_LEVEL_INFO: - fprintf(logfp,"[I]"); - break; - - case DT_LEVEL_DEBUG: - fprintf(logfp,"[D]"); - break; - - default: - fprintf(logfp,"[-]"); - break; - } - - fprintf(logfp,"%s\n",message); - fflush(logfp); - } -#ifdef LOCAL_PRINT_DEBUG - switch (level) - { - case DT_LEVEL_ERROR: - g_print("[E]"); - break; - - case DT_LEVEL_WARNING: - g_print("[W]"); - break; - - case DT_LEVEL_NOTICE: - g_print("[N]"); - break; - - case DT_LEVEL_INFO: - g_print("[I]"); - break; - - case DT_LEVEL_DEBUG: - g_print("[D]"); - break; - - default: - g_print("[-]"); - break; - } - - g_print("%s",message); -#endif - - if (message) { - g_free(message); - } - -} - - - -/* ------ PUBLIC PLUGIN FUNCTIONS --------- */ - -/* - * Set the Bluez Adapter Property "Powered" value - * If success return 0, else return -1; - */ -int adapter_set_powered(gboolean powervalue) -{ - LOGD("value:%d\n",powervalue); - - GError *error = NULL; - GVariant *value; - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGD("BluetoothManage Not Init\n"); - return -1; - } - - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - ADAPTER_PATH, FREEDESKTOP_PROPERTIES, - "Set", g_variant_new("(ssv)", ADAPTER_INTERFACE, - "Powered", g_variant_new("b", powervalue)), - NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, - NULL, &error); - - if (NULL == value) { - LOGW ("Error getting object manager client: %s", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(value); - return 0; -} - -/* - * Get the Bluez Adapter Property "Powered" value - * If success return 0, else return -1; - */ -int adapter_get_powered(gboolean *powervalue) { - LOGD("\n"); - - GError *error = NULL; - GVariant *value = NULL; - GVariant *subValue = NULL; - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGD("BluetoothManage Not Init\n"); - return -1; - } - - if (NULL == powervalue) { - LOGD("powervalue is NULL\n"); - return -1; - } - - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - ADAPTER_PATH, FREEDESKTOP_PROPERTIES, "Get", - g_variant_new("(ss)", ADAPTER_INTERFACE, "Powered"), - NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, - NULL, &error); - - if (NULL == value) { - LOGW ("Error getting object manager client: %s\n", error->message); - g_error_free(error); - return -1; - } - - g_variant_get(value, "(v)", &subValue); - g_variant_get(subValue, "b", powervalue); - g_variant_unref(subValue); - - g_variant_unref(value); - - LOGD("get ret :%d\n",*powervalue); - return 0; -} - -/* - * Set the Bluez Adapter Property value - * Only support boolean property now.(Discoverable, Pairable, Powered) - * If success return 0, else return -1; - */ -int adapter_set_property(const gchar* property, gboolean setvalue) -{ - LOGD("property:%s,value:%d\n",property, setvalue); - - GError *error = NULL; - GVariant *value; - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGW("BluetoothManage Not Init\n"); - return -1; - } - - if ((0!=g_strcmp0 (property, "Discoverable"))&& - (0!=g_strcmp0 (property, "Pairable"))&& - (0!=g_strcmp0 (property, "Powered"))) - { - LOGD("Invalid value\n"); - return -1; - } - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - ADAPTER_PATH, FREEDESKTOP_PROPERTIES, - "Set", g_variant_new("(ssv)", ADAPTER_INTERFACE, - property, g_variant_new("b", setvalue)), - NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, - NULL, &error); - - if (NULL == value) { - LOGW ("Error : %s", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(value); - - return 0; -} - - -/* - * Call the Bluez Adapter Method "StartDiscovery" - * If success return 0, else return -1; - */ -int adapter_start_discovery() -{ - LOGD("\n"); - - GError *error = NULL; - GVariant *value = NULL; - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGW("BluetoothManage Not Init\n"); - return -1; - } - - if (BluetoothManage.autoconnect > 0) { - LOGW("Canceling autoconnection for discovery mode\n"); - g_source_remove(BluetoothManage.autoconnect); - } - - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - ADAPTER_PATH, ADAPTER_INTERFACE, "StartDiscovery", - NULL, NULL, G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, NULL, &error); - - if (NULL == value) { - LOGW ("Error getting object manager client: %s\n", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(value); - return 0; -} - -/* - * Call the Bluez Adapter Method "StopDiscovery" - * If success return 0, else return -1; - */ -int adapter_stop_discovery() -{ - LOGD("\n"); - - GError *error = NULL; - GVariant *value = NULL; - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGW("BluetoothManage Not Init\n"); - return -1; - } - - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - ADAPTER_PATH, ADAPTER_INTERFACE, "StopDiscovery", - NULL, NULL, G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, NULL, &error); - - if (NULL == value) { - LOGW ("Error getting object manager client: %s\n", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(value); - - return 0; -} - -/* - * Call the Bluez Adapter Method "RemoveDevice" - * If success return 0, else return -1; - */ -int adapter_remove_device(const gchar* bdaddr) -{ - LOGD("\n%s\n",bdaddr); - - struct btd_device * device; - gchar *path; - GError *error = NULL; - GVariant *value; - - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGW("BluetoothManage Not Init\n"); - return -1; - } - - devices_list_lock(); - device = devices_list_find_device_by_bdaddr(bdaddr); - - if (NULL == device) { - devices_list_unlock(); - LOGD("not find device\n"); - return -1; - } - path = g_strdup(device->path); - devices_list_unlock(); - - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - ADAPTER_PATH, ADAPTER_INTERFACE, "RemoveDevice", - g_variant_new("(o)", path), NULL, - G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &error); - - bt_remove_priority(bdaddr); - - g_free(path); - - if (NULL == value) { - LOGW ("Error getting object manager client: %s", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(value); - return 0; - -} - - -/* - * Get the copy of device list. - */ -GSList* adapter_get_devices_list() -{ - GSList* tmp; - devices_list_lock(); - tmp = g_slist_copy_deep (BluetoothManage.device, - (GCopyFunc)device_copy, NULL); - devices_list_unlock(); - return tmp; -} - -/* - * free device list. - */ -void adapter_devices_list_free(GSList* list) -{ - if (NULL != list) - g_slist_free_full(list,(GDestroyNotify)device_free); - -} - -/* - * device_pair callback - */ -void device_pair_done_cb(GDBusConnection *source_object, - GAsyncResult *res, - gpointer user_data) -{ - LOGD("\n"); - gchar *bdaddr = user_data; - - if (g_task_had_error(G_TASK(res)) == FALSE) - { - bt_save_priority(bdaddr); - } - g_free(bdaddr); - - g_dbus_connection_call_finish (source_object, res, NULL); - -} - -/* - * send pairing command - * If success return 0, else return -1; - */ -int device_pair(const gchar * bdaddr) -{ - LOGD("\n%s\n",bdaddr); - - struct btd_device * device; - gchar *path; - GError *error = NULL; - GVariant *value; - - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGD("BluetoothManage Not Init\n"); - return -1; - } - - devices_list_lock(); - device = devices_list_find_device_by_bdaddr(bdaddr); - - if (NULL == device) { - devices_list_unlock(); - LOGD("not find device\n"); - return -1; - } - path = g_strdup(device->path); - devices_list_unlock(); - -#if 0 - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - path, DEVICE_INTERFACE, "Pair", - NULL, NULL, G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, NULL, &error); - - g_free(path); - - if (NULL == value) { - LOGW ("Error getting object manager client: %s", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(value); -#else - - g_dbus_connection_call(cli.system_conn, BLUEZ_SERVICE, - path, DEVICE_INTERFACE, "Pair", - NULL, NULL, G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, NULL, - (GAsyncReadyCallback)device_pair_done_cb, g_strdup(bdaddr)); - - g_free(path); -#endif - return 0; - -} - -/* - * send cancel pairing command - * If success return 0, else return -1; - */ -int device_cancelPairing(const gchar * bdaddr) -{ - LOGD("\n%s\n",bdaddr); - - struct btd_device * device; - gchar *path; - GError *error = NULL; - GVariant *value; - - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGD("BluetoothManage Not Init\n"); - return -1; - } - - devices_list_lock(); - device = devices_list_find_device_by_bdaddr(bdaddr); - - if (NULL == device) { - devices_list_unlock(); - LOGD("not find device\n"); - return -1; - } - path = g_strdup(device->path); - devices_list_unlock(); - - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - path, DEVICE_INTERFACE, "CancelPairing", - NULL, NULL, G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, NULL, &error); - - g_free(path); - - if (NULL == value) { - LOGW ("Error getting object manager client: %s", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(value); - return 0; - -} -/* - * send connect command - * If success return 0, else return -1; - */ -int device_connect(const gchar * bdaddr, const gchar * uuid) -{ - LOGD("\n%s\n",bdaddr); - - struct btd_device * device; - gchar *path; - GError *error = NULL; - GVariant *value; - - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGD("BluetoothManage Not Init\n"); - return -1; - } - - devices_list_lock(); - device = devices_list_find_device_by_bdaddr(bdaddr); - - if (NULL == device) { - devices_list_unlock(); - LOGD("not find device\n"); - return -1; - } - path = g_strdup(device->path); - devices_list_unlock(); - - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - path, DEVICE_INTERFACE, uuid ? "ConnectProfile" : "Connect", - uuid ? g_variant_new("(s)", uuid) : NULL, - NULL, G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, NULL, &error); - - g_free(path); - - if (NULL == value) { - LOGW ("Error getting object manager client: %s", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(value); - return 0; - -} - -/* - * send disconnect command - * If success return 0, else return -1; - */ -int device_disconnect(const gchar* bdaddr, const gchar *uuid) -{ - LOGD("\n%s\n",bdaddr); - - struct btd_device * device; - gchar *path; - GError *error = NULL; - GVariant *value; - - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGD("BluetoothManage Not Init\n"); - return -1; - } - - devices_list_lock(); - device = devices_list_find_device_by_bdaddr(bdaddr); - - if (NULL == device) { - devices_list_unlock(); - LOGD("not find device\n"); - return -1; - } - path = g_strdup(device->path); - devices_list_unlock(); - - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - path, DEVICE_INTERFACE, uuid ? "DisconnectProfile" : "Disconnect", - uuid ? g_variant_new("(s)", uuid) : NULL, - NULL, G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, NULL, &error); - - g_free(path); - - if (NULL == value) { - LOGW ("Error getting object manager client: %s", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(value); - return 0; -} - -/* - * set remote device property - * If success return 0, else return -1; - */ -int device_set_property(const char * bdaddr, const char *property_name, - const char *property_value) -{ - LOGD("\n%s-%s-%s\n",bdaddr,property_name,property_value); - - GError *error = NULL; - GVariant *ret; - struct btd_device * device; - gchar *path; - gboolean value; - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGD("BluetoothManage Not Init\n"); - return -1; - } - - //Only support set "Trusted" - if (strcmp(property_name, "Trusted")) { - LOGD("Not support property name\n"); - return -1; - } - - if (atoi(property_value) == 1 || !strcasecmp(property_value, "true")) { - value = TRUE; - } else if (atoi(property_value) == 0 - || !strcasecmp(property_value, "false")) { - value = FALSE; - } else { - LOGD("Not support property value\n"); - return -1; - } - - devices_list_lock(); - device = devices_list_find_device_by_bdaddr(bdaddr); - - if (NULL == device) { - devices_list_unlock(); - LOGD("not find device\n"); - return -1; - } - path = g_strdup(device->path); - devices_list_unlock(); - - ret = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - path, FREEDESKTOP_PROPERTIES, "Set", - g_variant_new("(ssv)", DEVICE_INTERFACE, property_name, - g_variant_new("b", value)), NULL, G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, NULL, &error); - - g_free(path); - - if (NULL == ret) { - LOGW ("Error getting object manager client: %s", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(ret); - return 0; -} - -/* - * call remote device avrcp method - * Only support controls (Play, Pause, Stop, Previous, Next) - * If success return 0, else return -1; - */ -int device_call_avrcp_method(const gchar* bdaddr, const gchar* method) -{ - LOGD("device:%s,value:%d\n", bdaddr, method); - - struct btd_device * device; - GError *error = NULL; - GVariant *value; - gchar *path; - - if (FALSE == BluetoothManage_InitFlag_Get()) { - LOGW("BluetoothManage Not Init\n"); - return -1; - } - - if ((0!=g_strcmp0 (method, "Play"))&& - (0!=g_strcmp0 (method, "Pause"))&& - (0!=g_strcmp0 (method, "Stop"))&& - (0!=g_strcmp0 (method, "Previous"))&& - (0!=g_strcmp0 (method, "Next"))) - { - LOGD("Invalid method\n"); - return -1; - } - - devices_list_lock(); - device = devices_list_find_device_by_bdaddr(bdaddr); - - if (NULL == device) { - devices_list_unlock(); - LOGD("not find device\n"); - return -1; - } - path = g_strdup(device->path); - devices_list_unlock(); - - value = g_dbus_connection_call_sync(cli.system_conn, BLUEZ_SERVICE, - path, MEDIA_CONTROL1_INTERFACE, - method, NULL, NULL, - G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, - NULL, &error); - - g_free(path); - - if (NULL == value) { - LOGW ("Error : %s", error->message); - g_error_free(error); - return -1; - } - - g_variant_unref(value); - - return 0; -} - - -/* - * Stops the GMainLoop - */ -int BluetoothManagerQuit() -{ - LOGD("\n"); - - if (FALSE == BluetoothManage.inited ) - { - LOGD("BluetoothManage Not init\n"); - return -1; - } - - if(cli.clientloop){ - g_main_loop_quit(cli.clientloop); - } - - BluezManagerQuit(); - stop_agent(); - - devices_list_lock(); - devices_list_cleanup(); - devices_list_unlock(); - - - g_mutex_clear (&(BluetoothManage.m)); - - g_object_unref(cli.system_conn); - g_object_unref(cli.session_conn); - - if (logfp) - fclose(logfp); - logfp = NULL; - - BluetoothManage.inited = FALSE; - - return 0; -} - -/* - * Create Bluetooth Manager Thread - * Note: bluetooth-api shall do BluetoothManageInit() first before call other APIs. - * bluetooth-api shall register callback function - * Returns: 0 - success or other errors - */ -int BluetoothManagerInit() { - pthread_t thread_id; - - LOGD("\n"); - - if (TRUE == BluetoothManage.inited ) - { - LOGW("BluetoothManage already init\n"); - return -1; - } - - logfp = fopen("/var/log/BluetoothManager.log", "a+"); - - if (NULL == logfp) - { - openlog("BluetoothManager", LOG_CONS | LOG_PID, LOG_USER); - syslog(LOG_WARNING, "BluetoothManager create log file fail\n"); - closelog(); - } - - g_mutex_init(&(BluetoothManage.m)); - - pthread_create(&thread_id, NULL, bt_event_loop_thread, NULL); - //pthread_setname_np(thread_id, "BT_Manager"); - - return 0; -} - -/* - * Register Bluetooth Manager Callback function - */ -void BindingAPIRegister(const Binding_RegisterCallback_t* pstRegisterCallback) -{ - if (NULL != pstRegisterCallback) - { - if (NULL != pstRegisterCallback->binding_device_added) - { - g_RegisterCallback.binding_device_added = - pstRegisterCallback->binding_device_added; - } - - if (NULL != pstRegisterCallback->binding_device_removed) - { - g_RegisterCallback.binding_device_removed = - pstRegisterCallback->binding_device_removed; - } - - if (NULL != pstRegisterCallback->binding_device_properties_changed) - { - g_RegisterCallback.binding_device_properties_changed = - pstRegisterCallback->binding_device_properties_changed; - } - - if (NULL != pstRegisterCallback->binding_request_confirmation) - { - g_RegisterCallback.binding_request_confirmation = - pstRegisterCallback->binding_request_confirmation; - } - } -} diff --git a/binding-bluetooth/bluetooth-manager.h b/binding-bluetooth/bluetooth-manager.h deleted file mode 100644 index 3e22cb8..0000000 --- a/binding-bluetooth/bluetooth-manager.h +++ /dev/null @@ -1,196 +0,0 @@ -/* Copyright 2016 ALPS ELECTRIC CO., LTD. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#ifndef BLUEZ_MANAGER_H -#define BLUEZ_MANAGER_H - -#include <glib.h> -#include <gio/gio.h> -#include <glib-object.h> -#include <sys/ioctl.h> - - /* Debug Trace Level */ -#define DT_LEVEL_ERROR (1 << 1) -#define DT_LEVEL_WARNING (1 << 2) -#define DT_LEVEL_NOTICE (1 << 3) -#define DT_LEVEL_INFO (1 << 4) -#define DT_LEVEL_DEBUG (1 << 5) -//#define _DEBUG - -#define LOGE(fmt, args...) \ - DebugTraceSendMsg(DT_LEVEL_ERROR, g_strdup_printf("[%d:%s]" fmt, __LINE__, __FUNCTION__, ## args)) -#define LOGW(fmt, args...) \ - DebugTraceSendMsg(DT_LEVEL_WARNING, g_strdup_printf("[%d:%s]" fmt, __LINE__, __FUNCTION__, ## args)) -#define LOGN(fmt, args...) \ - DebugTraceSendMsg(DT_LEVEL_NOTICE, g_strdup_printf("[%d:%s]" fmt, __LINE__, __FUNCTION__, ## args)) -#define LOGI(fmt, args...) \ - DebugTraceSendMsg(DT_LEVEL_INFO, g_strdup_printf("[%d:%s]" fmt, __LINE__, __FUNCTION__, ## args)) -#define LOGD(fmt, args...) \ - DebugTraceSendMsg(DT_LEVEL_DEBUG, g_strdup_printf("[%d:%s]" fmt, __LINE__, __FUNCTION__, ## args)) - -#ifdef _DEBUG - #define _DEBUG_PRINT_DBUS - #define LOCAL_PRINT_DEBUG -#endif - -#ifdef LOCAL_PRINT_DEBUG -#define D_PRINTF(fmt, args...) \ - g_print("[DEBUG][%d:%s]"fmt, __LINE__, __FUNCTION__, ## args) -#define D_PRINTF_RAW(fmt, args...) \ - g_print(""fmt, ## args) -#else -#define D_PRINTF(fmt, args...) -#define D_PRINTF_RAW(fmt, args...) -#endif /* ifdef _DEBUG */ - -//service -#define AGENT_SERVICE "org.agent" - -//remote service -#define BLUEZ_SERVICE "org.bluez" -#define CLIENT_SERVICE "org.bluez.obex" - -//object path -#define BLUEZ_MANAGER_PATH "/" -#define AGENT_PATH "/org/bluez" -#define ADAPTER_PATH "/org/bluez/hci0" -#define OBEX_CLIENT_PATH "/org/bluez/obex" - - -//interface -#define ADAPTER_INTERFACE "org.bluez.Adapter1" -#define DEVICE_INTERFACE "org.bluez.Device1" -#define AGENT_MANAGER_INTERFACE "org.bluez.AgentManager1" -//#define SERVICE_INTERFACE "org.bluez.Service" -#define AGENT_INTERFACE "org.bluez.Agent" - -#define CLIENT_INTERFACE "org.bluez.obex.Client1" -#define TRANSFER_INTERFACE "org.bluez.obex.Transfer" -#define SESSION_INTERFACE "org.bluez.obex.Session" -#define OBEX_ERROR_INTERFACE "org.bluez.obex.Error" -#define BLUEZ_ERROR_INTERFACE "org.bluez.Error" -#define PBAP_INTERFACE "org.bluez.obex.PhonebookAccess" -#define MAP_INTERFACE "org.bluez.obex.MessageAccess" -#define MAP_MSG_INTERFACE "org.bluez.obex.Message" - -#define MEDIA_PLAYER_INTERFACE "org.bluez.MediaPlayer" -#define MEDIA_PLAYER1_INTERFACE "org.bluez.MediaPlayer1" -#define MEDIA_FOLDER_INTERFACE "org.bluez.MediaFolder" -#define MEDIA_ITEM_INTERFACE "org.bluez.MediaItem" -#define MEDIA_TRANSPORT_INTERFACE "org.bluez.MediaTransport" -#define MEDIA_TRANSPORT1_INTERFACE "org.bluez.MediaTransport1" -#define MEDIA_CONTROL1_INTERFACE "org.bluez.MediaControl1" - -#define FREEDESKTOP_INTROSPECT "org.freedesktop.DBus.Introspectable" -#define FREEDESKTOP_PROPERTIES "org.freedesktop.DBus.Properties" -#define FREEDESKTOP_OBJECTMANAGER "org.freedesktop.DBus.ObjectManager" - -#define HOMESCREEN_SERVICE "org.agl.homescreen" -#define HOMESCREEN_ICON_INTERFACE "org.agl.statusbar" -#define HOMESCREEN_ICON_PATH "/StatusBar" -#define HOMESCREEN_BT_ICON_POSITION 1 - -#define DBUS_REPLY_TIMEOUT (120 * 1000) -#define DBUS_REPLY_TIMEOUT_SHORT (10 * 1000) - -#define ERROR_BLUEZ_REJECT "org.bluez.Error.Rejected" -#define ERROR_BLUEZ_CANCELED "org.bluez.Error.Canceled" - -#define HCIDEVUP _IOW('H', 201, int) - -#define AF_BLUETOOTH 31 -#define BTPROTO_HCI 1 - -#if 0 -void DebugTraceSendMsg(int level, gchar* message); -#else - -typedef struct _client -{ - GDBusConnection *system_conn; - GDBusConnection *session_conn; - GMainLoop *clientloop; -} Client; - -//Bluetooth Device Properties -struct btd_device { - gchar *path; - gchar *bdaddr; - gchar *name; - gchar *avrcp_title; - gchar *avrcp_artist; - gchar *avrcp_status; - gchar *transport_state; - guint32 avrcp_duration; - guint32 avrcp_position; - guint16 transport_volume; - gboolean paired; - gboolean trusted; - gboolean connected; - gboolean avconnected; - gboolean hfpconnected; - GList *uuids; -}; - -typedef struct { - gboolean inited; - GMutex m; - gint watch; - guint autoconnect; - GSList * device; - GSList * priorities; -} stBluetoothManage; - -typedef struct tagBinding_RegisterCallback -{ - void (*binding_device_added)(struct btd_device *BDdevice); - void (*binding_device_removed)(struct btd_device *BDdevice); - void (*binding_device_properties_changed)(struct btd_device *BDdevice); - gboolean (*binding_request_confirmation)(const gchar *device, guint passkey); -}Binding_RegisterCallback_t; - -void DebugTraceSendMsg(int level, gchar* message); - -/* ------ PUBLIC PLUGIN FUNCTIONS --------- */ -void BindingAPIRegister(const Binding_RegisterCallback_t* pstRegisterCallback); -int BluetoothManagerInit(void); -int BluetoothManagerQuit(void); - -GSList* adapter_get_devices_list() ; -void adapter_devices_list_free(GSList* list) ; - -int adapter_set_powered(gboolean value); -int adapter_get_powered(gboolean *value); -//int adapter_set_discoverable(gboolean value); -int adapter_start_discovery(); -int adapter_stop_discovery(); -int adapter_remove_device(const gchar *addr); -int device_pair(const gchar * addr); -int device_cancelPairing(const gchar * bdaddr); -int device_connect(const gchar *addr, const gchar *uuid); -int device_disconnect(const gchar *addr, const gchar *uuid); -int device_set_property(const gchar * bdaddr, const gchar *property, const gchar *value); -int device_call_avrcp_method(const gchar* device, const gchar* method); -int device_priority_list(void *(object_cb)(void *, gchar *), void *ptr); - -int adapter_set_property(const gchar* property, gboolean value) ; - -#endif -#endif /* BLUETOOTH_MANAGER_H */ - - -/****************************** The End Of File ******************************/ - diff --git a/binding-bluetooth/bluez-client.c b/binding-bluetooth/bluez-client.c deleted file mode 100644 index d078d06..0000000 --- a/binding-bluetooth/bluez-client.c +++ /dev/null @@ -1,966 +0,0 @@ -/* Copyright 2016 ALPS ELECTRIC CO., LTD. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <pthread.h> -#include <glib.h> -#include <gio/gio.h> -#include <glib-object.h> - -#include "lib_bluez.h" -#include "bluez-client.h" - -#ifdef BLUEZ_THREAD -static GMainLoop *BluezLoop; -#endif -static Bluez_RegisterCallback_t bluez_RegisterCallback = { 0 }; -static stBluezManage BluezManage = { 0 }; - - -/* ------ LOCAL FUNCTIONS --------- */ - -/* - * make a copy of each element - * And, to entirely free the new btd_device, you could do: device_free - */ -static struct bt_device *bluez_device_copy(struct bt_device* device) -{ - struct bt_device * temp; - - if (NULL == device) { - return NULL; - } - - temp = g_malloc0(sizeof(struct bt_device)); - temp->path = g_strdup(device->path); - temp->bdaddr = g_strdup(device->bdaddr); - temp->name = g_strdup(device->name); - temp->alias = g_strdup(device->alias); - temp->paired = device->paired; - temp->trusted = device->trusted; - temp->blocked = device->blocked; - temp->connected = device->connected; - temp->avconnected = device->avconnected; - temp->legacypairing = device->legacypairing; - temp->rssi = device->rssi; - temp->uuids = g_list_copy(device->uuids); - - return temp; -} - -/* - * Frees all of the memory - */ -static void bluez_device_free(struct bt_device* device) -{ - - if (NULL == device) { - return ; - } - D_PRINTF("device %p\n",device); - if (device->path) { - D_PRINTF("path:%s\n",device->path); - g_free(device->path); - device->path = NULL; - } - if (device->bdaddr) { - D_PRINTF("bdaddr:%s\n",device->bdaddr); - g_free(device->bdaddr); - device->bdaddr = NULL; - } - if (device->name) { - D_PRINTF("name:%s\n",device->name); - g_free(device->name); - device->name = NULL; - } - if (device->alias) { - D_PRINTF("alias:%s\n",device->alias); - g_free(device->alias); - device->alias = NULL; - } - - if (device->uuids){ - D_PRINTF("uuids xxx\n"); - g_list_free_full(device->uuids, g_free); - device->uuids = NULL; - } - - g_free(device); - -} - -#ifdef BLUEZ_BD_LIST - -static void bluez_devices_list_lock(void) -{ - g_mutex_lock(&(BluezManage.m)); -} - -static void bluez_devices_list_unlock(void) -{ - g_mutex_unlock(&(BluezManage.m)); -} - -static int bluez_device_path_cmp(struct bt_device * device, const gchar* pPath ) -{ - return g_strcmp0 (device->path, pPath); -} - -/* - * search device by path - * Returns the first found btd_device or NULL if it is not found - */ -static struct bt_device *bluez_devices_list_find_device_by_path(const gchar* pPath) -{ - GSList * temp; - - temp = g_slist_find_custom (BluezManage.device, pPath, - (GCompareFunc)bluez_device_path_cmp); - - if (temp) { - return temp->data; - } - - return NULL; - -} - - -static int bluez_device_bdaddr_cmp(struct bt_device * device, const gchar* pBDaddr ) -{ - return g_strcmp0 (device->bdaddr, pBDaddr); -} - -/* - * search device by path - * Returns the first found btd_device or NULL if it is not found - */ -static struct -bt_device *bluez_devices_list_find_device_by_bdaddr(const gchar* pBDaddr) -{ - GSList * temp; - - temp = g_slist_find_custom (BluezManage.device, pBDaddr, - (GCompareFunc)bluez_device_bdaddr_cmp); - - if (temp) { - return temp->data; - } - - return NULL; - -} - -/* - * remove all the devices - */ -static void bluez_devices_list_cleanup() -{ - LOGD("\n"); - GSList * temp = BluezManage.device; - while (temp) { - struct bt_device *BDdevice = temp->data; - temp = temp->next; - - BluezManage.device = g_slist_remove_all(BluezManage.device, - BDdevice); - - bluez_device_free(BDdevice); - } -} - -/* - * Get the copy of device list. - */ -GSList* bluez_devices_list_copy() -{ - GSList* tmp; - bluez_devices_list_lock(); - tmp = g_slist_copy_deep (BluezManage.device, - (GCopyFunc)bluez_device_copy, NULL); - bluez_devices_list_unlock(); - return tmp; -} - -#endif - -/* - * free device list. - */ -void bluez_devices_list_free(GSList* list) -{ - if (NULL != list) - g_slist_free_full(list,(GDestroyNotify)bluez_device_free); - -} - -/* - * update device from Interfcace org.bluez.Device1 properties - */ -static int -bluez_device1_properties_update(struct bt_device *device, GVariant *value) -{ - if ((NULL==device) || (NULL==value)) - { - return -1; - } - - GVariantIter iter; - const gchar *key; - GVariant *subValue; - - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "{&sv}", &key, &subValue)) - { - //gchar *s = g_variant_print (subValue, TRUE); - //g_print (" %s -> %s\n", key, s); - //g_free (s); - - gboolean value_b = FALSE;//b gboolean - //gchar value_c = 0; - //guchar value_y = 0;//y guchar - gint16 value_n = 0;//n gint16 - //guint16 value_q = 0;//q guint16 - //gint32 value_i = 0;//i gint32 - //guint32 value_u = 0;//u guint32 - //gint64 value_x = 0;//x gint64 - //guint64 value_t = 0;//t guint64 - //gint32 value_h = 0;//h gint32 - //gdouble value_d = 0.0;//d gdouble - gchar *str; - - if (0==g_strcmp0(key,"Address")) { - g_variant_get(subValue, "s", &str ); - D_PRINTF("Address %s\n",str); - - if (device->bdaddr) - g_free (device->bdaddr); - - device->bdaddr = g_strdup(str); - - g_free (str); - str = NULL; - - }else if (0==g_strcmp0(key,"Name")) { - g_variant_get(subValue, "s", &str ); - D_PRINTF("Name %s\n",str); - - if (device->name) - g_free (device->name); - - device->name = g_strdup(str); - - g_free (str); - str = NULL; - - }else if (0==g_strcmp0(key,"Alias")) { - g_variant_get(subValue, "s", &str ); - D_PRINTF("Alias %s\n",str); - - if (device->alias) - g_free (device->alias); - - device->alias = g_strdup(str); - - g_free (str); - str = NULL; - }else if (0==g_strcmp0(key,"LegacyPairing")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("LegacyPairing %d\n",value_b); - device->legacypairing = value_b; - - }else if (0==g_strcmp0(key,"Paired")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("Paired %d\n",value_b); - device->paired = value_b; - - }else if (0==g_strcmp0(key,"Trusted")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("Trusted %d\n",value_b); - device->trusted = value_b; - - }else if (0==g_strcmp0(key,"Blocked")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("Blocked %d\n",value_b); - device->blocked = value_b; - - }else if (0==g_strcmp0(key,"Connected")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("Connected %d\n",value_b); - device->connected = value_b; - - }else if (0==g_strcmp0(key,"RSSI")) { - g_variant_get(subValue, "n", &value_n ); - D_PRINTF("RSSI %d\n",value_n); - device->rssi = value_n; - - }else if (0==g_strcmp0(key,"UUIDs")) { - GVariantIter iter; - gchar *val; - - //g_print ("type '%s'\n", g_variant_get_type_string (subValue)); - if (device->uuids) { - g_list_free_full(device->uuids, g_free); - } - - g_variant_iter_init (&iter, subValue); - while (g_variant_iter_next (&iter, "s", &val)) - { - device->uuids = g_list_append(device->uuids, g_strdup(val)); - } - } - } - - return 0; - -} - -/* - * update device from Interfcace org.bluez.MediaControl1 properties - */ -static int -bluez_mediacontrol1_properties_update(struct bt_device *device, GVariant *value) -{ - GVariantIter iter; - const gchar *key; - GVariant *subValue; - - if ((NULL==device) || (NULL==value)) - { - return -1; - } - - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "{&sv}", &key, &subValue)) - { - //gchar *s = g_variant_print (subValue, TRUE); - //g_print (" %s -> %s\n", key, s); - //g_free (s); - - gboolean value_b = FALSE;//b gboolean - gchar *str; - - if (0==g_strcmp0(key,"Connected")) { - g_variant_get(subValue, "b", &value_b ); - D_PRINTF("Connected %d\n",value_b); - device->avconnected = value_b; - - }else if (0==g_strcmp0(key,"Player")) { - g_variant_get(subValue, "o", &str ); - D_PRINTF("Player Object %s\n",str); - - } - } - - return 0; - -} - -/* - * Get the device list - * Call <method>GetManagedObjects - * Returns: 0 - success or other errors - */ -static GSList * bluez_get_devices_list() { - LOGD("\n"); - - GError *error = NULL; - GVariant *result = NULL; - GSList *newDeviceList = NULL; - - result = g_dbus_connection_call_sync(BluezManage.system_conn, - BLUEZ_SERVICE, BLUEZ_MANAGER_PATH, FREEDESKTOP_OBJECTMANAGER, - "GetManagedObjects", NULL, NULL, - G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &error); - - if (error) { - LOGW ("Error : %s\n", error->message); - g_error_free(error); - return NULL; - } - - GVariant *ArrayValue = NULL; - GVariantIter *ArrayValueIter; - GVariant *Value = NULL; - - g_variant_get(result, "(*)", &ArrayValue); - - g_variant_get(ArrayValue, "a*", &ArrayValueIter); - while (g_variant_iter_loop(ArrayValueIter, "*", &Value)) { - - GVariantIter dbus_object_iter; - GVariant *dbusObjecPath; - GVariant *dbusObjecInterfaces; - - gchar *pObjecPath = NULL; - struct bt_device *device = NULL; - - g_variant_iter_init(&dbus_object_iter, Value); - - //1st : DBus Object Path - dbusObjecPath = g_variant_iter_next_value(&dbus_object_iter); - - g_variant_get(dbusObjecPath, "o", &pObjecPath); - - LOGD("object path %s\n",pObjecPath); - //ObjectPath is /org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx - if ((37 != strlen(pObjecPath)) - || (NULL == g_strrstr_len(pObjecPath, 19, - ADAPTER_PATH"/dev"))) { - g_free(pObjecPath); - pObjecPath = NULL; - g_variant_unref(dbusObjecPath); - continue; - } - device = g_malloc0(sizeof(struct bt_device)); - device->path = g_strdup(pObjecPath); - g_free(pObjecPath); - pObjecPath = NULL; - g_variant_unref(dbusObjecPath); - - LOGD("Found new device%s\n",device->path ); - - //2nd : DBus Interfaces under Object Path - dbusObjecInterfaces = g_variant_iter_next_value(&dbus_object_iter); - - GVariant *interfaces_value = NULL; - g_variant_lookup(dbusObjecInterfaces, DEVICE_INTERFACE, - "*", &interfaces_value); - - if (interfaces_value) - { - bluez_device1_properties_update(device, interfaces_value); - - g_variant_unref (interfaces_value); - interfaces_value = NULL; - } - - g_variant_lookup(dbusObjecInterfaces, MEDIA_CONTROL1_INTERFACE, - "*", &interfaces_value); - - if (interfaces_value) - { - bluez_mediacontrol1_properties_update(device, interfaces_value); - - g_variant_unref (interfaces_value); - interfaces_value = NULL; - } - - g_variant_unref(dbusObjecInterfaces); - - //newDeviceList = g_slist_prepend(newDeviceList, device); - newDeviceList = g_slist_append(newDeviceList, device); - - - } - - g_variant_iter_free(ArrayValueIter); - g_variant_unref(ArrayValue); - - g_variant_unref(result); - - return newDeviceList; -} - - - -/* - * notify::name-owner callback function - */ -static void on_notify_name_owner (GObject *object, - GParamSpec *pspec, - gpointer user_data) -{ -#ifdef _DEBUG_PRINT_DBUS - GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (object); - gchar *name_owner; - - name_owner = g_dbus_object_manager_client_get_name_owner (manager); - g_print ("name-owner: %s\n", name_owner); - g_free (name_owner); -#endif -} - -/* - * object_added callback function - */ -static void on_object_added (GDBusObjectManager *manager, - GDBusObject *object, - gpointer user_data) -{ -#ifdef _DEBUG_PRINT_DBUS - gchar *owner; - owner = g_dbus_object_manager_client_get_name_owner ( - G_DBUS_OBJECT_MANAGER_CLIENT (manager)); - g_print ("Added object at %s (owner %s)\n", - g_dbus_object_get_object_path (object), owner); - g_free (owner); -#endif - - - const gchar *dbusObjecPath; - GError *error = NULL; - GVariant *value = NULL; - struct bt_device *device; - - dbusObjecPath = g_dbus_object_get_object_path (object); - - LOGD("%s\n", dbusObjecPath); - - //ObjectPath is /org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx - if ((37 != strlen(dbusObjecPath)) - || (NULL == g_strrstr_len(dbusObjecPath, 19,ADAPTER_PATH"/dev"))) { - return; - } - - device = g_malloc0(sizeof(struct bt_device)); - device->path = g_strdup(dbusObjecPath); - - value = g_dbus_connection_call_sync(BluezManage.system_conn, BLUEZ_SERVICE, - dbusObjecPath, FREEDESKTOP_PROPERTIES, - "GetAll", g_variant_new("(s)", DEVICE_INTERFACE), - NULL, G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, NULL, &error); - - if (error) { - LOGW ("Error : %s\n", error->message); - g_error_free(error); - g_free(device->path); - g_free(device); - return; - } - - if (value) { - GVariant *subValue; - g_variant_get(value, "(*)", &subValue); - - bluez_device1_properties_update(device, subValue); - - g_variant_unref (subValue); - g_variant_unref(value); - } - -#ifdef BLUEZ_BD_LIST - - bluez_devices_list_lock(); - - //BluezManage.device = g_slist_prepend(BluezManage.device, device); - BluezManage.device = g_slist_append(BluezManage.device, device); - - if (NULL != bluez_RegisterCallback.device_added) - { - bluez_RegisterCallback.device_added(device); - } - - bluez_devices_list_unlock(); -#else - - if (NULL != bluez_RegisterCallback.device_added) - { - bluez_RegisterCallback.device_added(device); - } - bluez_device_free(device); - -#endif -} - -/* - * object-removed callback function - */ -static void on_object_removed (GDBusObjectManager *manager, - GDBusObject *object, - gpointer user_data) -{ -#ifdef _DEBUG_PRINT_DBUS - gchar *owner; - - owner = g_dbus_object_manager_client_get_name_owner ( - G_DBUS_OBJECT_MANAGER_CLIENT (manager)); - g_print ("Removed object at %s (owner %s)\n", - g_dbus_object_get_object_path (object), owner); - g_free (owner); -#endif - - const gchar *dbusObjecPath; - //int ret; - - - dbusObjecPath = g_dbus_object_get_object_path (object); - - if ((37 != strlen(dbusObjecPath)) - || (NULL == g_strrstr_len(dbusObjecPath, 19,ADAPTER_PATH"/dev"))) { - return; - } - - if (NULL != bluez_RegisterCallback.device_removed) - { - bluez_RegisterCallback.device_removed(dbusObjecPath); - } - LOGD("%s\n", dbusObjecPath); -#ifdef BLUEZ_BD_LIST - struct bt_device *device; - - bluez_devices_list_lock(); - - device = bluez_devices_list_find_device_by_path(dbusObjecPath); - - if (device) { - LOGD("Path :%s.\n", dbusObjecPath); - BluezManage.device = g_slist_remove_all(BluezManage.device, - device); - - bluez_device_free(device); - } - - bluez_devices_list_unlock(); -#endif - -} - -/* - * BLUEZ interface-proxy-properties-changed callback function - */ -static void -on_interface_proxy_properties_changed (GDBusObjectManagerClient *manager, - GDBusObjectProxy *object_proxy, - GDBusProxy *interface_proxy, - GVariant *changed_properties, - const gchar *const *invalidated_properties, - gpointer user_data) -{ - const gchar *pObjecPath; - const gchar *pInterface; - - pObjecPath = g_dbus_object_get_object_path (G_DBUS_OBJECT (object_proxy)); - pInterface = g_dbus_proxy_get_interface_name (interface_proxy); - -#ifdef _DEBUG_PRINT_DBUS - gchar *s; - g_print ("Path:%s, Interface:%s\n",pObjecPath, pInterface); - g_print ("type '%s'\n", g_variant_get_type_string (changed_properties)); - s = g_variant_print (changed_properties, TRUE); - g_print (" %s\n", s); - g_free (s); -#endif - - //ObjectPath is /org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx - - LOGD("%s\n",pObjecPath); - - if( (0 == g_strcmp0(pInterface, DEVICE_INTERFACE)) || - (0 == g_strcmp0(pInterface, MEDIA_CONTROL1_INTERFACE)) || - (0 == g_strcmp0(pInterface, MEDIA_PLAYER1_INTERFACE)) || - (0 == g_strcmp0(pInterface, MEDIA_TRANSPORT1_INTERFACE))) { - - if (bluez_RegisterCallback.device_properties_changed) - bluez_RegisterCallback.device_properties_changed(pObjecPath, - pInterface, changed_properties); - - } - -#ifdef BLUEZ_BD_LIST - struct bt_device *device; - - if (0 == g_strcmp0(pInterface, DEVICE_INTERFACE)) { - - bluez_devices_list_lock(); - - device = bluez_devices_list_find_device_by_path(pObjecPath); - - bluez_device1_properties_update(device, changed_properties); - - bluez_devices_list_unlock(); - - } else if (0 == g_strcmp0(pInterface, MEDIA_CONTROL1_INTERFACE)) { - - bluez_devices_list_lock(); - - device = bluez_devices_list_find_device_by_path(pObjecPath); - - bluez_mediacontrol1_properties_update(device, changed_properties); - - bluez_devices_list_unlock(); - } -#endif -} - -/* - * init cli dbus connection - * Returns: 0 - success or other errors - */ -static int bluez_manager_connect_to_dbus(void) -{ - GError *error = NULL; - - BluezManage.system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - - if (error) { - LOGE("Create System GDBusconnection fail\n"); - LOGE("Error:%s\n", error->message); - g_error_free(error); - - return -1; - } - - BluezManage.session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); - - if (error) { - LOGE("Create Session GDBusconnection fail\n"); - LOGE("Error:%s\n", error->message); - g_error_free(error); - - g_object_unref(BluezManage.system_conn); - - return -1; - } - - BluezManage.proxy = bluez_object_manager_client_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, BLUEZ_SERVICE, - BLUEZ_MANAGER_PATH, NULL, &error); - - if (error) { - LOGE("Create Bluez manager client fail\n"); - LOGE("Error:%s\n", error->message); - g_error_free(error); - - g_object_unref(BluezManage.system_conn); - g_object_unref(BluezManage.session_conn); - return -1; - } - - return 0; -} - - -/* - * register dbus callback function - * Returns: 0 - success or other errors - */ -static int bluez_manager_register_callback(void) -{ - - g_signal_connect (BluezManage.proxy, - "notify::name-owner", - G_CALLBACK (on_notify_name_owner), - NULL); - - g_signal_connect (BluezManage.proxy, - "object-added", - G_CALLBACK (on_object_added), - NULL); - - g_signal_connect (BluezManage.proxy, - "object-removed", - G_CALLBACK (on_object_removed), - NULL); - - g_signal_connect (BluezManage.proxy, - "interface-proxy-properties-changed", - G_CALLBACK (on_interface_proxy_properties_changed), - NULL); - - return 0; -} - -/* - * init bluez client - * Returns: 0 - success or other errors - */ -static int bluez_manager_int() -{ - int ret = 0; - - LOGD("\n"); - - ret = bluez_manager_connect_to_dbus(); - - if (ret){ - LOGE("Init Fail\n"); - return -1; - } - - bluez_manager_register_callback(); - -#ifdef BLUEZ_BD_LIST - - g_mutex_init(&(BluezManage.m)); - - BluezManage.device = bluez_get_devices_list(); - -#endif - - BluezManage.inited = TRUE; - - return 0; - -} - -#ifdef BLUEZ_THREAD -/* - * Bluetooth Manager Thread - * register callback function and create a new GMainLoop structure - */ -static void *bluez_event_loop_thread() -{ - int ret = 0; - - BluezLoop = g_main_loop_new(NULL, FALSE);; - - ret = bluez_manager_int(); - - if (0 == ret){ - LOGD("g_main_loop_run\n"); - g_main_loop_run(BluezLoop); - } - - g_main_loop_unref(BluezLoop); - LOGD("exit...\n"); -} -#endif - - -/* ------ PUBLIC FUNCTIONS --------- */ - - -/* - * Get the device list - * The list should free by FreeBluezDevicesList() - */ -GSList * GetBluezDevicesList(void) -{ - LOGD("\n"); - - GSList* newDeviceList = NULL; - - if (TRUE != BluezManage.inited) - { - LOGD("Bluez Manager is not inited\n"); - return NULL; - } - -#ifdef BLUEZ_BD_LIST - newDeviceList = bluez_devices_list_copy(); -#else - newDeviceList = bluez_get_devices_list(); -#endif - return newDeviceList; -} - -/* - * free device list. - */ -void FreeBluezDevicesList(GSList* list) -{ - bluez_devices_list_free(list); -} - -/* - * Stops the GMainLoop - */ -int BluezManagerQuit(void) -{ - LOGD("\n"); - - if (FALSE == BluezManage.inited) - { - LOGD("Bluez Manager is not inited\n"); - return -1; - } - -#ifdef BLUEZ_THREAD - g_main_loop_quit(BluezLoop); -#endif - - memset(&bluez_RegisterCallback, 0, sizeof(Bluez_RegisterCallback_t)); - - g_object_unref(BluezManage.proxy); - -#ifdef BLUEZ_BD_LIST - bluez_devices_list_lock(); - bluez_devices_list_cleanup(); - bluez_devices_list_unlock(); - - g_mutex_clear (&(BluezManage.m)); -#endif - - g_object_unref(BluezManage.system_conn); - g_object_unref(BluezManage.session_conn); - - BluezManage.inited = FALSE; - - return 0; -} - -/* - * Init Bluez Manager - */ -int BluezManagerInit() -{ - LOGD("\n"); - int ret = 0; - - - if (TRUE == BluezManage.inited) - { - LOGD("Bluez Manager is already inited\n"); - return -1; - } - -#ifdef BLUEZ_THREAD - - pthread_t thread_id; - pthread_create(&thread_id, NULL, bluez_event_loop_thread, NULL); - pthread_setname_np(thread_id, "Bluez_Manage"); - -#else - - ret = bluez_manager_int(); -#endif - - return ret; -} - -/* - * Register Bluez Manager Callback function - */ -void BluezDeviceAPIRegister(const Bluez_RegisterCallback_t* pstRegisterCallback) -{ - if (NULL != pstRegisterCallback) - { - if (NULL != pstRegisterCallback->device_added) - { - bluez_RegisterCallback.device_added = - pstRegisterCallback->device_added; - } - - if (NULL != pstRegisterCallback->device_removed) - { - bluez_RegisterCallback.device_removed = - pstRegisterCallback->device_removed; - } - - if (NULL != pstRegisterCallback->device_properties_changed) - { - bluez_RegisterCallback.device_properties_changed = - pstRegisterCallback->device_properties_changed; - } - } -} - - - diff --git a/binding-bluetooth/bluez-client.h b/binding-bluetooth/bluez-client.h deleted file mode 100644 index 17f82f0..0000000 --- a/binding-bluetooth/bluez-client.h +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright 2016 ALPS ELECTRIC CO., LTD. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef BLUEZ_CLIENT_H -#define BLUEZ_CLIENT_H - -#include <glib.h> -#include <gio/gio.h> -#include <glib-object.h> - -#include "lib_bluez.h" -#include "bluetooth-manager.h" - -//#define BLUEZ_THREAD -//#define BLUEZ_BD_LIST - -//Bluetooth Device Properties -struct bt_device { - gchar *path; - gchar *bdaddr; - gchar *name; - gchar *alias; - gboolean paired; - gboolean trusted; - gboolean blocked; - gboolean connected; - gboolean avconnected; - gboolean legacypairing; - gint16 rssi; - GList *uuids; -}; - -typedef struct { - gboolean inited; - #ifdef BLUEZ_BD_LIST - GMutex m; - GSList * device; - #endif - GDBusObjectManager *proxy; - GDBusConnection *system_conn; - GDBusConnection *session_conn; -} stBluezManage; - -typedef struct tagBluez_RegisterCallback -{ - void (*device_added)(struct bt_device *device); - void (*device_removed)(const gchar *path); - void (*device_properties_changed)(const gchar *pObjecPath, const gchar *pInterface, GVariant *value); -}Bluez_RegisterCallback_t; - -/* --- PUBLIC FUNCTIONS --- */ -void BluezDeviceAPIRegister(const Bluez_RegisterCallback_t* pstRegisterCallback); - -int BluezManagerInit(void) ; -int BluezManagerQuit(void) ; - -GSList * GetBluezDevicesList(void); -void FreeBluezDevicesList(GSList* list) ; - -#endif /* BLUEZ_CLIENT_H */ - - -/****************************** The End Of File ******************************/ - diff --git a/binding-bluetooth/lib_agent.c b/binding-bluetooth/lib_agent.c deleted file mode 100644 index 6324dfb..0000000 --- a/binding-bluetooth/lib_agent.c +++ /dev/null @@ -1,2504 +0,0 @@ -/* - * Generated by gdbus-codegen 2.48.1. DO NOT EDIT. - * - * The license of this code is the same as for the source it was derived from. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "lib_agent.h" - -#include <string.h> -#ifdef G_OS_UNIX -# include <gio/gunixfdlist.h> -#endif - -typedef struct -{ - GDBusArgInfo parent_struct; - gboolean use_gvariant; -} _ExtendedGDBusArgInfo; - -typedef struct -{ - GDBusMethodInfo parent_struct; - const gchar *signal_name; - gboolean pass_fdlist; -} _ExtendedGDBusMethodInfo; - -typedef struct -{ - GDBusSignalInfo parent_struct; - const gchar *signal_name; -} _ExtendedGDBusSignalInfo; - -typedef struct -{ - GDBusPropertyInfo parent_struct; - const gchar *hyphen_name; - gboolean use_gvariant; -} _ExtendedGDBusPropertyInfo; - -typedef struct -{ - GDBusInterfaceInfo parent_struct; - const gchar *hyphen_name; -} _ExtendedGDBusInterfaceInfo; - -typedef struct -{ - const _ExtendedGDBusPropertyInfo *info; - guint prop_id; - GValue orig_value; /* the value before the change */ -} ChangedProperty; - -static void -_changed_property_free (ChangedProperty *data) -{ - g_value_unset (&data->orig_value); - g_free (data); -} - -static gboolean -_g_strv_equal0 (gchar **a, gchar **b) -{ - gboolean ret = FALSE; - guint n; - if (a == NULL && b == NULL) - { - ret = TRUE; - goto out; - } - if (a == NULL || b == NULL) - goto out; - if (g_strv_length (a) != g_strv_length (b)) - goto out; - for (n = 0; a[n] != NULL; n++) - if (g_strcmp0 (a[n], b[n]) != 0) - goto out; - ret = TRUE; -out: - return ret; -} - -static gboolean -_g_variant_equal0 (GVariant *a, GVariant *b) -{ - gboolean ret = FALSE; - if (a == NULL && b == NULL) - { - ret = TRUE; - goto out; - } - if (a == NULL || b == NULL) - goto out; - ret = g_variant_equal (a, b); -out: - return ret; -} - -G_GNUC_UNUSED static gboolean -_g_value_equal (const GValue *a, const GValue *b) -{ - gboolean ret = FALSE; - g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b)); - switch (G_VALUE_TYPE (a)) - { - case G_TYPE_BOOLEAN: - ret = (g_value_get_boolean (a) == g_value_get_boolean (b)); - break; - case G_TYPE_UCHAR: - ret = (g_value_get_uchar (a) == g_value_get_uchar (b)); - break; - case G_TYPE_INT: - ret = (g_value_get_int (a) == g_value_get_int (b)); - break; - case G_TYPE_UINT: - ret = (g_value_get_uint (a) == g_value_get_uint (b)); - break; - case G_TYPE_INT64: - ret = (g_value_get_int64 (a) == g_value_get_int64 (b)); - break; - case G_TYPE_UINT64: - ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b)); - break; - case G_TYPE_DOUBLE: - { - /* Avoid -Wfloat-equal warnings by doing a direct bit compare */ - gdouble da = g_value_get_double (a); - gdouble db = g_value_get_double (b); - ret = memcmp (&da, &db, sizeof (gdouble)) == 0; - } - break; - case G_TYPE_STRING: - ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0); - break; - case G_TYPE_VARIANT: - ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b)); - break; - default: - if (G_VALUE_TYPE (a) == G_TYPE_STRV) - ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b)); - else - g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a))); - break; - } - return ret; -} - -/* ------------------------------------------------------------------------ - * Code for interface org.bluez.Agent1 - * ------------------------------------------------------------------------ - */ - -/** - * SECTION:AGENTOrgBluezAgent1 - * @title: AGENTOrgBluezAgent1 - * @short_description: Generated C code for the org.bluez.Agent1 D-Bus interface - * - * This section contains code for working with the <link linkend="gdbus-interface-org-bluez-Agent1.top_of_page">org.bluez.Agent1</link> D-Bus interface in C. - */ - -/* ---- Introspection data for org.bluez.Agent1 ---- */ - -static const _ExtendedGDBusMethodInfo _agent_org_bluez_agent1_method_info_release = -{ - { - -1, - (gchar *) "Release", - NULL, - NULL, - NULL - }, - "handle-release", - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_request_pin_code_IN_ARG_device = -{ - { - -1, - (gchar *) "device", - (gchar *) "o", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo * const _agent_org_bluez_agent1_method_info_request_pin_code_IN_ARG_pointers[] = -{ - &_agent_org_bluez_agent1_method_info_request_pin_code_IN_ARG_device, - NULL -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_request_pin_code_OUT_ARG_pincode = -{ - { - -1, - (gchar *) "pincode", - (gchar *) "s", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo * const _agent_org_bluez_agent1_method_info_request_pin_code_OUT_ARG_pointers[] = -{ - &_agent_org_bluez_agent1_method_info_request_pin_code_OUT_ARG_pincode, - NULL -}; - -static const _ExtendedGDBusMethodInfo _agent_org_bluez_agent1_method_info_request_pin_code = -{ - { - -1, - (gchar *) "RequestPinCode", - (GDBusArgInfo **) &_agent_org_bluez_agent1_method_info_request_pin_code_IN_ARG_pointers, - (GDBusArgInfo **) &_agent_org_bluez_agent1_method_info_request_pin_code_OUT_ARG_pointers, - NULL - }, - "handle-request-pin-code", - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_display_pin_code_IN_ARG_device = -{ - { - -1, - (gchar *) "device", - (gchar *) "o", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_display_pin_code_IN_ARG_pincode = -{ - { - -1, - (gchar *) "pincode", - (gchar *) "s", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo * const _agent_org_bluez_agent1_method_info_display_pin_code_IN_ARG_pointers[] = -{ - &_agent_org_bluez_agent1_method_info_display_pin_code_IN_ARG_device, - &_agent_org_bluez_agent1_method_info_display_pin_code_IN_ARG_pincode, - NULL -}; - -static const _ExtendedGDBusMethodInfo _agent_org_bluez_agent1_method_info_display_pin_code = -{ - { - -1, - (gchar *) "DisplayPinCode", - (GDBusArgInfo **) &_agent_org_bluez_agent1_method_info_display_pin_code_IN_ARG_pointers, - NULL, - NULL - }, - "handle-display-pin-code", - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_request_passkey_IN_ARG_device = -{ - { - -1, - (gchar *) "device", - (gchar *) "o", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo * const _agent_org_bluez_agent1_method_info_request_passkey_IN_ARG_pointers[] = -{ - &_agent_org_bluez_agent1_method_info_request_passkey_IN_ARG_device, - NULL -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_request_passkey_OUT_ARG_passkey = -{ - { - -1, - (gchar *) "passkey", - (gchar *) "u", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo * const _agent_org_bluez_agent1_method_info_request_passkey_OUT_ARG_pointers[] = -{ - &_agent_org_bluez_agent1_method_info_request_passkey_OUT_ARG_passkey, - NULL -}; - -static const _ExtendedGDBusMethodInfo _agent_org_bluez_agent1_method_info_request_passkey = -{ - { - -1, - (gchar *) "RequestPasskey", - (GDBusArgInfo **) &_agent_org_bluez_agent1_method_info_request_passkey_IN_ARG_pointers, - (GDBusArgInfo **) &_agent_org_bluez_agent1_method_info_request_passkey_OUT_ARG_pointers, - NULL - }, - "handle-request-passkey", - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_display_passkey_IN_ARG_device = -{ - { - -1, - (gchar *) "device", - (gchar *) "o", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_display_passkey_IN_ARG_passkey = -{ - { - -1, - (gchar *) "passkey", - (gchar *) "u", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_display_passkey_IN_ARG_entered = -{ - { - -1, - (gchar *) "entered", - (gchar *) "q", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo * const _agent_org_bluez_agent1_method_info_display_passkey_IN_ARG_pointers[] = -{ - &_agent_org_bluez_agent1_method_info_display_passkey_IN_ARG_device, - &_agent_org_bluez_agent1_method_info_display_passkey_IN_ARG_passkey, - &_agent_org_bluez_agent1_method_info_display_passkey_IN_ARG_entered, - NULL -}; - -static const _ExtendedGDBusMethodInfo _agent_org_bluez_agent1_method_info_display_passkey = -{ - { - -1, - (gchar *) "DisplayPasskey", - (GDBusArgInfo **) &_agent_org_bluez_agent1_method_info_display_passkey_IN_ARG_pointers, - NULL, - NULL - }, - "handle-display-passkey", - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_request_confirmation_IN_ARG_device = -{ - { - -1, - (gchar *) "device", - (gchar *) "o", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_request_confirmation_IN_ARG_passkey = -{ - { - -1, - (gchar *) "passkey", - (gchar *) "u", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo * const _agent_org_bluez_agent1_method_info_request_confirmation_IN_ARG_pointers[] = -{ - &_agent_org_bluez_agent1_method_info_request_confirmation_IN_ARG_device, - &_agent_org_bluez_agent1_method_info_request_confirmation_IN_ARG_passkey, - NULL -}; - -static const _ExtendedGDBusMethodInfo _agent_org_bluez_agent1_method_info_request_confirmation = -{ - { - -1, - (gchar *) "RequestConfirmation", - (GDBusArgInfo **) &_agent_org_bluez_agent1_method_info_request_confirmation_IN_ARG_pointers, - NULL, - NULL - }, - "handle-request-confirmation", - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_request_authorization_IN_ARG_device = -{ - { - -1, - (gchar *) "device", - (gchar *) "o", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo * const _agent_org_bluez_agent1_method_info_request_authorization_IN_ARG_pointers[] = -{ - &_agent_org_bluez_agent1_method_info_request_authorization_IN_ARG_device, - NULL -}; - -static const _ExtendedGDBusMethodInfo _agent_org_bluez_agent1_method_info_request_authorization = -{ - { - -1, - (gchar *) "RequestAuthorization", - (GDBusArgInfo **) &_agent_org_bluez_agent1_method_info_request_authorization_IN_ARG_pointers, - NULL, - NULL - }, - "handle-request-authorization", - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_authorize_service_IN_ARG_device = -{ - { - -1, - (gchar *) "device", - (gchar *) "o", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo _agent_org_bluez_agent1_method_info_authorize_service_IN_ARG_uuid = -{ - { - -1, - (gchar *) "uuid", - (gchar *) "s", - NULL - }, - FALSE -}; - -static const _ExtendedGDBusArgInfo * const _agent_org_bluez_agent1_method_info_authorize_service_IN_ARG_pointers[] = -{ - &_agent_org_bluez_agent1_method_info_authorize_service_IN_ARG_device, - &_agent_org_bluez_agent1_method_info_authorize_service_IN_ARG_uuid, - NULL -}; - -static const _ExtendedGDBusMethodInfo _agent_org_bluez_agent1_method_info_authorize_service = -{ - { - -1, - (gchar *) "AuthorizeService", - (GDBusArgInfo **) &_agent_org_bluez_agent1_method_info_authorize_service_IN_ARG_pointers, - NULL, - NULL - }, - "handle-authorize-service", - FALSE -}; - -static const _ExtendedGDBusMethodInfo _agent_org_bluez_agent1_method_info_cancel = -{ - { - -1, - (gchar *) "Cancel", - NULL, - NULL, - NULL - }, - "handle-cancel", - FALSE -}; - -static const _ExtendedGDBusMethodInfo * const _agent_org_bluez_agent1_method_info_pointers[] = -{ - &_agent_org_bluez_agent1_method_info_release, - &_agent_org_bluez_agent1_method_info_request_pin_code, - &_agent_org_bluez_agent1_method_info_display_pin_code, - &_agent_org_bluez_agent1_method_info_request_passkey, - &_agent_org_bluez_agent1_method_info_display_passkey, - &_agent_org_bluez_agent1_method_info_request_confirmation, - &_agent_org_bluez_agent1_method_info_request_authorization, - &_agent_org_bluez_agent1_method_info_authorize_service, - &_agent_org_bluez_agent1_method_info_cancel, - NULL -}; - -static const _ExtendedGDBusInterfaceInfo _agent_org_bluez_agent1_interface_info = -{ - { - -1, - (gchar *) "org.bluez.Agent1", - (GDBusMethodInfo **) &_agent_org_bluez_agent1_method_info_pointers, - NULL, - NULL, - NULL - }, - "org-bluez-agent1", -}; - - -/** - * agent_org_bluez_agent1_interface_info: - * - * Gets a machine-readable description of the <link linkend="gdbus-interface-org-bluez-Agent1.top_of_page">org.bluez.Agent1</link> D-Bus interface. - * - * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free. - */ -GDBusInterfaceInfo * -agent_org_bluez_agent1_interface_info (void) -{ - return (GDBusInterfaceInfo *) &_agent_org_bluez_agent1_interface_info.parent_struct; -} - -/** - * agent_org_bluez_agent1_override_properties: - * @klass: The class structure for a #GObject<!-- -->-derived class. - * @property_id_begin: The property id to assign to the first overridden property. - * - * Overrides all #GObject properties in the #AGENTOrgBluezAgent1 interface for a concrete class. - * The properties are overridden in the order they are defined. - * - * Returns: The last property id. - */ -guint -agent_org_bluez_agent1_override_properties (GObjectClass *klass, guint property_id_begin) -{ - return property_id_begin - 1; -} - - - -/** - * AGENTOrgBluezAgent1: - * - * Abstract interface type for the D-Bus interface <link linkend="gdbus-interface-org-bluez-Agent1.top_of_page">org.bluez.Agent1</link>. - */ - -/** - * AGENTOrgBluezAgent1Iface: - * @parent_iface: The parent interface. - * @handle_authorize_service: Handler for the #AGENTOrgBluezAgent1::handle-authorize-service signal. - * @handle_cancel: Handler for the #AGENTOrgBluezAgent1::handle-cancel signal. - * @handle_display_passkey: Handler for the #AGENTOrgBluezAgent1::handle-display-passkey signal. - * @handle_display_pin_code: Handler for the #AGENTOrgBluezAgent1::handle-display-pin-code signal. - * @handle_release: Handler for the #AGENTOrgBluezAgent1::handle-release signal. - * @handle_request_authorization: Handler for the #AGENTOrgBluezAgent1::handle-request-authorization signal. - * @handle_request_confirmation: Handler for the #AGENTOrgBluezAgent1::handle-request-confirmation signal. - * @handle_request_passkey: Handler for the #AGENTOrgBluezAgent1::handle-request-passkey signal. - * @handle_request_pin_code: Handler for the #AGENTOrgBluezAgent1::handle-request-pin-code signal. - * - * Virtual table for the D-Bus interface <link linkend="gdbus-interface-org-bluez-Agent1.top_of_page">org.bluez.Agent1</link>. - */ - -typedef AGENTOrgBluezAgent1Iface AGENTOrgBluezAgent1Interface; -G_DEFINE_INTERFACE (AGENTOrgBluezAgent1, agent_org_bluez_agent1, G_TYPE_OBJECT); - -static void -agent_org_bluez_agent1_default_init (AGENTOrgBluezAgent1Iface *iface) -{ - /* GObject signals for incoming D-Bus method calls: */ - /** - * AGENTOrgBluezAgent1::handle-release: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: A #GDBusMethodInvocation. - * - * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-bluez-Agent1.Release">Release()</link> D-Bus method. - * - * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call agent_org_bluez_agent1_complete_release() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. - * - * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. - */ - g_signal_new ("handle-release", - G_TYPE_FROM_INTERFACE (iface), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AGENTOrgBluezAgent1Iface, handle_release), - g_signal_accumulator_true_handled, - NULL, - g_cclosure_marshal_generic, - G_TYPE_BOOLEAN, - 1, - G_TYPE_DBUS_METHOD_INVOCATION); - - /** - * AGENTOrgBluezAgent1::handle-request-pin-code: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: A #GDBusMethodInvocation. - * @arg_device: Argument passed by remote caller. - * - * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-bluez-Agent1.RequestPinCode">RequestPinCode()</link> D-Bus method. - * - * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call agent_org_bluez_agent1_complete_request_pin_code() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. - * - * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. - */ - g_signal_new ("handle-request-pin-code", - G_TYPE_FROM_INTERFACE (iface), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AGENTOrgBluezAgent1Iface, handle_request_pin_code), - g_signal_accumulator_true_handled, - NULL, - g_cclosure_marshal_generic, - G_TYPE_BOOLEAN, - 2, - G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_STRING); - - /** - * AGENTOrgBluezAgent1::handle-display-pin-code: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: A #GDBusMethodInvocation. - * @arg_device: Argument passed by remote caller. - * @arg_pincode: Argument passed by remote caller. - * - * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-bluez-Agent1.DisplayPinCode">DisplayPinCode()</link> D-Bus method. - * - * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call agent_org_bluez_agent1_complete_display_pin_code() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. - * - * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. - */ - g_signal_new ("handle-display-pin-code", - G_TYPE_FROM_INTERFACE (iface), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AGENTOrgBluezAgent1Iface, handle_display_pin_code), - g_signal_accumulator_true_handled, - NULL, - g_cclosure_marshal_generic, - G_TYPE_BOOLEAN, - 3, - G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_STRING, G_TYPE_STRING); - - /** - * AGENTOrgBluezAgent1::handle-request-passkey: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: A #GDBusMethodInvocation. - * @arg_device: Argument passed by remote caller. - * - * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-bluez-Agent1.RequestPasskey">RequestPasskey()</link> D-Bus method. - * - * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call agent_org_bluez_agent1_complete_request_passkey() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. - * - * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. - */ - g_signal_new ("handle-request-passkey", - G_TYPE_FROM_INTERFACE (iface), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AGENTOrgBluezAgent1Iface, handle_request_passkey), - g_signal_accumulator_true_handled, - NULL, - g_cclosure_marshal_generic, - G_TYPE_BOOLEAN, - 2, - G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_STRING); - - /** - * AGENTOrgBluezAgent1::handle-display-passkey: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: A #GDBusMethodInvocation. - * @arg_device: Argument passed by remote caller. - * @arg_passkey: Argument passed by remote caller. - * @arg_entered: Argument passed by remote caller. - * - * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-bluez-Agent1.DisplayPasskey">DisplayPasskey()</link> D-Bus method. - * - * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call agent_org_bluez_agent1_complete_display_passkey() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. - * - * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. - */ - g_signal_new ("handle-display-passkey", - G_TYPE_FROM_INTERFACE (iface), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AGENTOrgBluezAgent1Iface, handle_display_passkey), - g_signal_accumulator_true_handled, - NULL, - g_cclosure_marshal_generic, - G_TYPE_BOOLEAN, - 4, - G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT); - - /** - * AGENTOrgBluezAgent1::handle-request-confirmation: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: A #GDBusMethodInvocation. - * @arg_device: Argument passed by remote caller. - * @arg_passkey: Argument passed by remote caller. - * - * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-bluez-Agent1.RequestConfirmation">RequestConfirmation()</link> D-Bus method. - * - * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call agent_org_bluez_agent1_complete_request_confirmation() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. - * - * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. - */ - g_signal_new ("handle-request-confirmation", - G_TYPE_FROM_INTERFACE (iface), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AGENTOrgBluezAgent1Iface, handle_request_confirmation), - g_signal_accumulator_true_handled, - NULL, - g_cclosure_marshal_generic, - G_TYPE_BOOLEAN, - 3, - G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_STRING, G_TYPE_UINT); - - /** - * AGENTOrgBluezAgent1::handle-request-authorization: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: A #GDBusMethodInvocation. - * @arg_device: Argument passed by remote caller. - * - * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-bluez-Agent1.RequestAuthorization">RequestAuthorization()</link> D-Bus method. - * - * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call agent_org_bluez_agent1_complete_request_authorization() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. - * - * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. - */ - g_signal_new ("handle-request-authorization", - G_TYPE_FROM_INTERFACE (iface), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AGENTOrgBluezAgent1Iface, handle_request_authorization), - g_signal_accumulator_true_handled, - NULL, - g_cclosure_marshal_generic, - G_TYPE_BOOLEAN, - 2, - G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_STRING); - - /** - * AGENTOrgBluezAgent1::handle-authorize-service: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: A #GDBusMethodInvocation. - * @arg_device: Argument passed by remote caller. - * @arg_uuid: Argument passed by remote caller. - * - * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-bluez-Agent1.AuthorizeService">AuthorizeService()</link> D-Bus method. - * - * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call agent_org_bluez_agent1_complete_authorize_service() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. - * - * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. - */ - g_signal_new ("handle-authorize-service", - G_TYPE_FROM_INTERFACE (iface), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AGENTOrgBluezAgent1Iface, handle_authorize_service), - g_signal_accumulator_true_handled, - NULL, - g_cclosure_marshal_generic, - G_TYPE_BOOLEAN, - 3, - G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_STRING, G_TYPE_STRING); - - /** - * AGENTOrgBluezAgent1::handle-cancel: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: A #GDBusMethodInvocation. - * - * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-bluez-Agent1.Cancel">Cancel()</link> D-Bus method. - * - * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call agent_org_bluez_agent1_complete_cancel() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. - * - * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. - */ - g_signal_new ("handle-cancel", - G_TYPE_FROM_INTERFACE (iface), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AGENTOrgBluezAgent1Iface, handle_cancel), - g_signal_accumulator_true_handled, - NULL, - g_cclosure_marshal_generic, - G_TYPE_BOOLEAN, - 1, - G_TYPE_DBUS_METHOD_INVOCATION); - -} - -/** - * agent_org_bluez_agent1_call_release: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. - * @user_data: User data to pass to @callback. - * - * Asynchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.Release">Release()</link> D-Bus method on @proxy. - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_call_release_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_call_release_sync() for the synchronous, blocking version of this method. - */ -void -agent_org_bluez_agent1_call_release ( - AGENTOrgBluezAgent1 *proxy, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_dbus_proxy_call (G_DBUS_PROXY (proxy), - "Release", - g_variant_new ("()"), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - callback, - user_data); -} - -/** - * agent_org_bluez_agent1_call_release_finish: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_call_release(). - * @error: Return location for error or %NULL. - * - * Finishes an operation started with agent_org_bluez_agent1_call_release(). - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_release_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_release_sync: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL. - * - * Synchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.Release">Release()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_call_release() for the asynchronous version of this method. - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_release_sync ( - AGENTOrgBluezAgent1 *proxy, - GCancellable *cancellable, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), - "Release", - g_variant_new ("()"), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_request_pin_code: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. - * @user_data: User data to pass to @callback. - * - * Asynchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.RequestPinCode">RequestPinCode()</link> D-Bus method on @proxy. - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_call_request_pin_code_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_call_request_pin_code_sync() for the synchronous, blocking version of this method. - */ -void -agent_org_bluez_agent1_call_request_pin_code ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_dbus_proxy_call (G_DBUS_PROXY (proxy), - "RequestPinCode", - g_variant_new ("(o)", - arg_device), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - callback, - user_data); -} - -/** - * agent_org_bluez_agent1_call_request_pin_code_finish: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @out_pincode: (out): Return location for return parameter or %NULL to ignore. - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_call_request_pin_code(). - * @error: Return location for error or %NULL. - * - * Finishes an operation started with agent_org_bluez_agent1_call_request_pin_code(). - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_request_pin_code_finish ( - AGENTOrgBluezAgent1 *proxy, - gchar **out_pincode, - GAsyncResult *res, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "(s)", - out_pincode); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_request_pin_code_sync: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @out_pincode: (out): Return location for return parameter or %NULL to ignore. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL. - * - * Synchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.RequestPinCode">RequestPinCode()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_call_request_pin_code() for the asynchronous version of this method. - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_request_pin_code_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - gchar **out_pincode, - GCancellable *cancellable, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), - "RequestPinCode", - g_variant_new ("(o)", - arg_device), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "(s)", - out_pincode); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_display_pin_code: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @arg_pincode: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. - * @user_data: User data to pass to @callback. - * - * Asynchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.DisplayPinCode">DisplayPinCode()</link> D-Bus method on @proxy. - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_call_display_pin_code_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_call_display_pin_code_sync() for the synchronous, blocking version of this method. - */ -void -agent_org_bluez_agent1_call_display_pin_code ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - const gchar *arg_pincode, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_dbus_proxy_call (G_DBUS_PROXY (proxy), - "DisplayPinCode", - g_variant_new ("(os)", - arg_device, - arg_pincode), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - callback, - user_data); -} - -/** - * agent_org_bluez_agent1_call_display_pin_code_finish: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_call_display_pin_code(). - * @error: Return location for error or %NULL. - * - * Finishes an operation started with agent_org_bluez_agent1_call_display_pin_code(). - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_display_pin_code_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_display_pin_code_sync: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @arg_pincode: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL. - * - * Synchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.DisplayPinCode">DisplayPinCode()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_call_display_pin_code() for the asynchronous version of this method. - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_display_pin_code_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - const gchar *arg_pincode, - GCancellable *cancellable, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), - "DisplayPinCode", - g_variant_new ("(os)", - arg_device, - arg_pincode), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_request_passkey: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. - * @user_data: User data to pass to @callback. - * - * Asynchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.RequestPasskey">RequestPasskey()</link> D-Bus method on @proxy. - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_call_request_passkey_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_call_request_passkey_sync() for the synchronous, blocking version of this method. - */ -void -agent_org_bluez_agent1_call_request_passkey ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_dbus_proxy_call (G_DBUS_PROXY (proxy), - "RequestPasskey", - g_variant_new ("(o)", - arg_device), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - callback, - user_data); -} - -/** - * agent_org_bluez_agent1_call_request_passkey_finish: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @out_passkey: (out): Return location for return parameter or %NULL to ignore. - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_call_request_passkey(). - * @error: Return location for error or %NULL. - * - * Finishes an operation started with agent_org_bluez_agent1_call_request_passkey(). - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_request_passkey_finish ( - AGENTOrgBluezAgent1 *proxy, - guint *out_passkey, - GAsyncResult *res, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "(u)", - out_passkey); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_request_passkey_sync: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @out_passkey: (out): Return location for return parameter or %NULL to ignore. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL. - * - * Synchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.RequestPasskey">RequestPasskey()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_call_request_passkey() for the asynchronous version of this method. - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_request_passkey_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - guint *out_passkey, - GCancellable *cancellable, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), - "RequestPasskey", - g_variant_new ("(o)", - arg_device), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "(u)", - out_passkey); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_display_passkey: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @arg_passkey: Argument to pass with the method invocation. - * @arg_entered: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. - * @user_data: User data to pass to @callback. - * - * Asynchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.DisplayPasskey">DisplayPasskey()</link> D-Bus method on @proxy. - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_call_display_passkey_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_call_display_passkey_sync() for the synchronous, blocking version of this method. - */ -void -agent_org_bluez_agent1_call_display_passkey ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - guint arg_passkey, - guint16 arg_entered, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_dbus_proxy_call (G_DBUS_PROXY (proxy), - "DisplayPasskey", - g_variant_new ("(ouq)", - arg_device, - arg_passkey, - arg_entered), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - callback, - user_data); -} - -/** - * agent_org_bluez_agent1_call_display_passkey_finish: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_call_display_passkey(). - * @error: Return location for error or %NULL. - * - * Finishes an operation started with agent_org_bluez_agent1_call_display_passkey(). - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_display_passkey_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_display_passkey_sync: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @arg_passkey: Argument to pass with the method invocation. - * @arg_entered: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL. - * - * Synchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.DisplayPasskey">DisplayPasskey()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_call_display_passkey() for the asynchronous version of this method. - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_display_passkey_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - guint arg_passkey, - guint16 arg_entered, - GCancellable *cancellable, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), - "DisplayPasskey", - g_variant_new ("(ouq)", - arg_device, - arg_passkey, - arg_entered), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_request_confirmation: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @arg_passkey: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. - * @user_data: User data to pass to @callback. - * - * Asynchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.RequestConfirmation">RequestConfirmation()</link> D-Bus method on @proxy. - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_call_request_confirmation_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_call_request_confirmation_sync() for the synchronous, blocking version of this method. - */ -void -agent_org_bluez_agent1_call_request_confirmation ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - guint arg_passkey, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_dbus_proxy_call (G_DBUS_PROXY (proxy), - "RequestConfirmation", - g_variant_new ("(ou)", - arg_device, - arg_passkey), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - callback, - user_data); -} - -/** - * agent_org_bluez_agent1_call_request_confirmation_finish: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_call_request_confirmation(). - * @error: Return location for error or %NULL. - * - * Finishes an operation started with agent_org_bluez_agent1_call_request_confirmation(). - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_request_confirmation_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_request_confirmation_sync: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @arg_passkey: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL. - * - * Synchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.RequestConfirmation">RequestConfirmation()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_call_request_confirmation() for the asynchronous version of this method. - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_request_confirmation_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - guint arg_passkey, - GCancellable *cancellable, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), - "RequestConfirmation", - g_variant_new ("(ou)", - arg_device, - arg_passkey), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_request_authorization: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. - * @user_data: User data to pass to @callback. - * - * Asynchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.RequestAuthorization">RequestAuthorization()</link> D-Bus method on @proxy. - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_call_request_authorization_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_call_request_authorization_sync() for the synchronous, blocking version of this method. - */ -void -agent_org_bluez_agent1_call_request_authorization ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_dbus_proxy_call (G_DBUS_PROXY (proxy), - "RequestAuthorization", - g_variant_new ("(o)", - arg_device), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - callback, - user_data); -} - -/** - * agent_org_bluez_agent1_call_request_authorization_finish: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_call_request_authorization(). - * @error: Return location for error or %NULL. - * - * Finishes an operation started with agent_org_bluez_agent1_call_request_authorization(). - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_request_authorization_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_request_authorization_sync: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL. - * - * Synchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.RequestAuthorization">RequestAuthorization()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_call_request_authorization() for the asynchronous version of this method. - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_request_authorization_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - GCancellable *cancellable, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), - "RequestAuthorization", - g_variant_new ("(o)", - arg_device), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_authorize_service: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @arg_uuid: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. - * @user_data: User data to pass to @callback. - * - * Asynchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.AuthorizeService">AuthorizeService()</link> D-Bus method on @proxy. - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_call_authorize_service_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_call_authorize_service_sync() for the synchronous, blocking version of this method. - */ -void -agent_org_bluez_agent1_call_authorize_service ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - const gchar *arg_uuid, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_dbus_proxy_call (G_DBUS_PROXY (proxy), - "AuthorizeService", - g_variant_new ("(os)", - arg_device, - arg_uuid), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - callback, - user_data); -} - -/** - * agent_org_bluez_agent1_call_authorize_service_finish: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_call_authorize_service(). - * @error: Return location for error or %NULL. - * - * Finishes an operation started with agent_org_bluez_agent1_call_authorize_service(). - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_authorize_service_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_authorize_service_sync: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @arg_device: Argument to pass with the method invocation. - * @arg_uuid: Argument to pass with the method invocation. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL. - * - * Synchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.AuthorizeService">AuthorizeService()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_call_authorize_service() for the asynchronous version of this method. - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_authorize_service_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - const gchar *arg_uuid, - GCancellable *cancellable, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), - "AuthorizeService", - g_variant_new ("(os)", - arg_device, - arg_uuid), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_cancel: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. - * @user_data: User data to pass to @callback. - * - * Asynchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.Cancel">Cancel()</link> D-Bus method on @proxy. - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_call_cancel_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_call_cancel_sync() for the synchronous, blocking version of this method. - */ -void -agent_org_bluez_agent1_call_cancel ( - AGENTOrgBluezAgent1 *proxy, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_dbus_proxy_call (G_DBUS_PROXY (proxy), - "Cancel", - g_variant_new ("()"), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - callback, - user_data); -} - -/** - * agent_org_bluez_agent1_call_cancel_finish: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_call_cancel(). - * @error: Return location for error or %NULL. - * - * Finishes an operation started with agent_org_bluez_agent1_call_cancel(). - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_cancel_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_call_cancel_sync: - * @proxy: A #AGENTOrgBluezAgent1Proxy. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL. - * - * Synchronously invokes the <link linkend="gdbus-method-org-bluez-Agent1.Cancel">Cancel()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_call_cancel() for the asynchronous version of this method. - * - * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. - */ -gboolean -agent_org_bluez_agent1_call_cancel_sync ( - AGENTOrgBluezAgent1 *proxy, - GCancellable *cancellable, - GError **error) -{ - GVariant *_ret; - _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), - "Cancel", - g_variant_new ("()"), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - error); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); -_out: - return _ret != NULL; -} - -/** - * agent_org_bluez_agent1_complete_release: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: (transfer full): A #GDBusMethodInvocation. - * - * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-bluez-Agent1.Release">Release()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. - * - * This method will free @invocation, you cannot use it afterwards. - */ -void -agent_org_bluez_agent1_complete_release ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation) -{ - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("()")); -} - -/** - * agent_org_bluez_agent1_complete_request_pin_code: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: (transfer full): A #GDBusMethodInvocation. - * @pincode: Parameter to return. - * - * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-bluez-Agent1.RequestPinCode">RequestPinCode()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. - * - * This method will free @invocation, you cannot use it afterwards. - */ -void -agent_org_bluez_agent1_complete_request_pin_code ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *pincode) -{ - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("(s)", - pincode)); -} - -/** - * agent_org_bluez_agent1_complete_display_pin_code: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: (transfer full): A #GDBusMethodInvocation. - * - * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-bluez-Agent1.DisplayPinCode">DisplayPinCode()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. - * - * This method will free @invocation, you cannot use it afterwards. - */ -void -agent_org_bluez_agent1_complete_display_pin_code ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation) -{ - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("()")); -} - -/** - * agent_org_bluez_agent1_complete_request_passkey: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: (transfer full): A #GDBusMethodInvocation. - * @passkey: Parameter to return. - * - * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-bluez-Agent1.RequestPasskey">RequestPasskey()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. - * - * This method will free @invocation, you cannot use it afterwards. - */ -void -agent_org_bluez_agent1_complete_request_passkey ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - guint passkey) -{ - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("(u)", - passkey)); -} - -/** - * agent_org_bluez_agent1_complete_display_passkey: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: (transfer full): A #GDBusMethodInvocation. - * - * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-bluez-Agent1.DisplayPasskey">DisplayPasskey()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. - * - * This method will free @invocation, you cannot use it afterwards. - */ -void -agent_org_bluez_agent1_complete_display_passkey ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation) -{ - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("()")); -} - -/** - * agent_org_bluez_agent1_complete_request_confirmation: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: (transfer full): A #GDBusMethodInvocation. - * - * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-bluez-Agent1.RequestConfirmation">RequestConfirmation()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. - * - * This method will free @invocation, you cannot use it afterwards. - */ -void -agent_org_bluez_agent1_complete_request_confirmation ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation) -{ - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("()")); -} - -/** - * agent_org_bluez_agent1_complete_request_authorization: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: (transfer full): A #GDBusMethodInvocation. - * - * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-bluez-Agent1.RequestAuthorization">RequestAuthorization()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. - * - * This method will free @invocation, you cannot use it afterwards. - */ -void -agent_org_bluez_agent1_complete_request_authorization ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation) -{ - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("()")); -} - -/** - * agent_org_bluez_agent1_complete_authorize_service: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: (transfer full): A #GDBusMethodInvocation. - * - * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-bluez-Agent1.AuthorizeService">AuthorizeService()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. - * - * This method will free @invocation, you cannot use it afterwards. - */ -void -agent_org_bluez_agent1_complete_authorize_service ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation) -{ - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("()")); -} - -/** - * agent_org_bluez_agent1_complete_cancel: - * @object: A #AGENTOrgBluezAgent1. - * @invocation: (transfer full): A #GDBusMethodInvocation. - * - * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-bluez-Agent1.Cancel">Cancel()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. - * - * This method will free @invocation, you cannot use it afterwards. - */ -void -agent_org_bluez_agent1_complete_cancel ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation) -{ - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("()")); -} - -/* ------------------------------------------------------------------------ */ - -/** - * AGENTOrgBluezAgent1Proxy: - * - * The #AGENTOrgBluezAgent1Proxy structure contains only private data and should only be accessed using the provided API. - */ - -/** - * AGENTOrgBluezAgent1ProxyClass: - * @parent_class: The parent class. - * - * Class structure for #AGENTOrgBluezAgent1Proxy. - */ - -struct _AGENTOrgBluezAgent1ProxyPrivate -{ - GData *qdata; -}; - -static void agent_org_bluez_agent1_proxy_iface_init (AGENTOrgBluezAgent1Iface *iface); - -#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 -G_DEFINE_TYPE_WITH_CODE (AGENTOrgBluezAgent1Proxy, agent_org_bluez_agent1_proxy, G_TYPE_DBUS_PROXY, - G_ADD_PRIVATE (AGENTOrgBluezAgent1Proxy) - G_IMPLEMENT_INTERFACE (AGENT_TYPE_ORG_BLUEZ_AGENT1, agent_org_bluez_agent1_proxy_iface_init)); - -#else -G_DEFINE_TYPE_WITH_CODE (AGENTOrgBluezAgent1Proxy, agent_org_bluez_agent1_proxy, G_TYPE_DBUS_PROXY, - G_IMPLEMENT_INTERFACE (AGENT_TYPE_ORG_BLUEZ_AGENT1, agent_org_bluez_agent1_proxy_iface_init)); - -#endif -static void -agent_org_bluez_agent1_proxy_finalize (GObject *object) -{ - AGENTOrgBluezAgent1Proxy *proxy = AGENT_ORG_BLUEZ_AGENT1_PROXY (object); - g_datalist_clear (&proxy->priv->qdata); - G_OBJECT_CLASS (agent_org_bluez_agent1_proxy_parent_class)->finalize (object); -} - -static void -agent_org_bluez_agent1_proxy_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec G_GNUC_UNUSED) -{ -} - -static void -agent_org_bluez_agent1_proxy_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec G_GNUC_UNUSED) -{ -} - -static void -agent_org_bluez_agent1_proxy_g_signal (GDBusProxy *proxy, - const gchar *sender_name G_GNUC_UNUSED, - const gchar *signal_name, - GVariant *parameters) -{ - _ExtendedGDBusSignalInfo *info; - GVariantIter iter; - GVariant *child; - GValue *paramv; - guint num_params; - guint n; - guint signal_id; - info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_agent_org_bluez_agent1_interface_info.parent_struct, signal_name); - if (info == NULL) - return; - num_params = g_variant_n_children (parameters); - paramv = g_new0 (GValue, num_params + 1); - g_value_init (¶mv[0], AGENT_TYPE_ORG_BLUEZ_AGENT1); - g_value_set_object (¶mv[0], proxy); - g_variant_iter_init (&iter, parameters); - n = 1; - while ((child = g_variant_iter_next_value (&iter)) != NULL) - { - _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1]; - if (arg_info->use_gvariant) - { - g_value_init (¶mv[n], G_TYPE_VARIANT); - g_value_set_variant (¶mv[n], child); - n++; - } - else - g_dbus_gvariant_to_gvalue (child, ¶mv[n++]); - g_variant_unref (child); - } - signal_id = g_signal_lookup (info->signal_name, AGENT_TYPE_ORG_BLUEZ_AGENT1); - g_signal_emitv (paramv, signal_id, 0, NULL); - for (n = 0; n < num_params + 1; n++) - g_value_unset (¶mv[n]); - g_free (paramv); -} - -static void -agent_org_bluez_agent1_proxy_g_properties_changed (GDBusProxy *_proxy, - GVariant *changed_properties, - const gchar *const *invalidated_properties) -{ - AGENTOrgBluezAgent1Proxy *proxy = AGENT_ORG_BLUEZ_AGENT1_PROXY (_proxy); - guint n; - const gchar *key; - GVariantIter *iter; - _ExtendedGDBusPropertyInfo *info; - g_variant_get (changed_properties, "a{sv}", &iter); - while (g_variant_iter_next (iter, "{&sv}", &key, NULL)) - { - info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_agent_org_bluez_agent1_interface_info.parent_struct, key); - g_datalist_remove_data (&proxy->priv->qdata, key); - if (info != NULL) - g_object_notify (G_OBJECT (proxy), info->hyphen_name); - } - g_variant_iter_free (iter); - for (n = 0; invalidated_properties[n] != NULL; n++) - { - info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_agent_org_bluez_agent1_interface_info.parent_struct, invalidated_properties[n]); - g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]); - if (info != NULL) - g_object_notify (G_OBJECT (proxy), info->hyphen_name); - } -} - -static void -agent_org_bluez_agent1_proxy_init (AGENTOrgBluezAgent1Proxy *proxy) -{ -#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 - proxy->priv = agent_org_bluez_agent1_proxy_get_instance_private (proxy); -#else - proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY, AGENTOrgBluezAgent1ProxyPrivate); -#endif - - g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), agent_org_bluez_agent1_interface_info ()); -} - -static void -agent_org_bluez_agent1_proxy_class_init (AGENTOrgBluezAgent1ProxyClass *klass) -{ - GObjectClass *gobject_class; - GDBusProxyClass *proxy_class; - - gobject_class = G_OBJECT_CLASS (klass); - gobject_class->finalize = agent_org_bluez_agent1_proxy_finalize; - gobject_class->get_property = agent_org_bluez_agent1_proxy_get_property; - gobject_class->set_property = agent_org_bluez_agent1_proxy_set_property; - - proxy_class = G_DBUS_PROXY_CLASS (klass); - proxy_class->g_signal = agent_org_bluez_agent1_proxy_g_signal; - proxy_class->g_properties_changed = agent_org_bluez_agent1_proxy_g_properties_changed; - -#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38 - g_type_class_add_private (klass, sizeof (AGENTOrgBluezAgent1ProxyPrivate)); -#endif -} - -static void -agent_org_bluez_agent1_proxy_iface_init (AGENTOrgBluezAgent1Iface *iface) -{ -} - -/** - * agent_org_bluez_agent1_proxy_new: - * @connection: A #GDBusConnection. - * @flags: Flags from the #GDBusProxyFlags enumeration. - * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. - * @object_path: An object path. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied. - * @user_data: User data to pass to @callback. - * - * Asynchronously creates a proxy for the D-Bus interface <link linkend="gdbus-interface-org-bluez-Agent1.top_of_page">org.bluez.Agent1</link>. See g_dbus_proxy_new() for more details. - * - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_proxy_new_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_proxy_new_sync() for the synchronous, blocking version of this constructor. - */ -void -agent_org_bluez_agent1_proxy_new ( - GDBusConnection *connection, - GDBusProxyFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_async_initable_new_async (AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "org.bluez.Agent1", NULL); -} - -/** - * agent_org_bluez_agent1_proxy_new_finish: - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_proxy_new(). - * @error: Return location for error or %NULL - * - * Finishes an operation started with agent_org_bluez_agent1_proxy_new(). - * - * Returns: (transfer full) (type AGENTOrgBluezAgent1Proxy): The constructed proxy object or %NULL if @error is set. - */ -AGENTOrgBluezAgent1 * -agent_org_bluez_agent1_proxy_new_finish ( - GAsyncResult *res, - GError **error) -{ - GObject *ret; - GObject *source_object; - source_object = g_async_result_get_source_object (res); - ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); - g_object_unref (source_object); - if (ret != NULL) - return AGENT_ORG_BLUEZ_AGENT1 (ret); - else - return NULL; -} - -/** - * agent_org_bluez_agent1_proxy_new_sync: - * @connection: A #GDBusConnection. - * @flags: Flags from the #GDBusProxyFlags enumeration. - * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. - * @object_path: An object path. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL - * - * Synchronously creates a proxy for the D-Bus interface <link linkend="gdbus-interface-org-bluez-Agent1.top_of_page">org.bluez.Agent1</link>. See g_dbus_proxy_new_sync() for more details. - * - * The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_proxy_new() for the asynchronous version of this constructor. - * - * Returns: (transfer full) (type AGENTOrgBluezAgent1Proxy): The constructed proxy object or %NULL if @error is set. - */ -AGENTOrgBluezAgent1 * -agent_org_bluez_agent1_proxy_new_sync ( - GDBusConnection *connection, - GDBusProxyFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GError **error) -{ - GInitable *ret; - ret = g_initable_new (AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "org.bluez.Agent1", NULL); - if (ret != NULL) - return AGENT_ORG_BLUEZ_AGENT1 (ret); - else - return NULL; -} - - -/** - * agent_org_bluez_agent1_proxy_new_for_bus: - * @bus_type: A #GBusType. - * @flags: Flags from the #GDBusProxyFlags enumeration. - * @name: A bus name (well-known or unique). - * @object_path: An object path. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied. - * @user_data: User data to pass to @callback. - * - * Like agent_org_bluez_agent1_proxy_new() but takes a #GBusType instead of a #GDBusConnection. - * - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call agent_org_bluez_agent1_proxy_new_for_bus_finish() to get the result of the operation. - * - * See agent_org_bluez_agent1_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor. - */ -void -agent_org_bluez_agent1_proxy_new_for_bus ( - GBusType bus_type, - GDBusProxyFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_async_initable_new_async (AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "org.bluez.Agent1", NULL); -} - -/** - * agent_org_bluez_agent1_proxy_new_for_bus_finish: - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to agent_org_bluez_agent1_proxy_new_for_bus(). - * @error: Return location for error or %NULL - * - * Finishes an operation started with agent_org_bluez_agent1_proxy_new_for_bus(). - * - * Returns: (transfer full) (type AGENTOrgBluezAgent1Proxy): The constructed proxy object or %NULL if @error is set. - */ -AGENTOrgBluezAgent1 * -agent_org_bluez_agent1_proxy_new_for_bus_finish ( - GAsyncResult *res, - GError **error) -{ - GObject *ret; - GObject *source_object; - source_object = g_async_result_get_source_object (res); - ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); - g_object_unref (source_object); - if (ret != NULL) - return AGENT_ORG_BLUEZ_AGENT1 (ret); - else - return NULL; -} - -/** - * agent_org_bluez_agent1_proxy_new_for_bus_sync: - * @bus_type: A #GBusType. - * @flags: Flags from the #GDBusProxyFlags enumeration. - * @name: A bus name (well-known or unique). - * @object_path: An object path. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL - * - * Like agent_org_bluez_agent1_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection. - * - * The calling thread is blocked until a reply is received. - * - * See agent_org_bluez_agent1_proxy_new_for_bus() for the asynchronous version of this constructor. - * - * Returns: (transfer full) (type AGENTOrgBluezAgent1Proxy): The constructed proxy object or %NULL if @error is set. - */ -AGENTOrgBluezAgent1 * -agent_org_bluez_agent1_proxy_new_for_bus_sync ( - GBusType bus_type, - GDBusProxyFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GError **error) -{ - GInitable *ret; - ret = g_initable_new (AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "org.bluez.Agent1", NULL); - if (ret != NULL) - return AGENT_ORG_BLUEZ_AGENT1 (ret); - else - return NULL; -} - - -/* ------------------------------------------------------------------------ */ - -/** - * AGENTOrgBluezAgent1Skeleton: - * - * The #AGENTOrgBluezAgent1Skeleton structure contains only private data and should only be accessed using the provided API. - */ - -/** - * AGENTOrgBluezAgent1SkeletonClass: - * @parent_class: The parent class. - * - * Class structure for #AGENTOrgBluezAgent1Skeleton. - */ - -struct _AGENTOrgBluezAgent1SkeletonPrivate -{ - GValue *properties; - GList *changed_properties; - GSource *changed_properties_idle_source; - GMainContext *context; - GMutex lock; -}; - -static void -_agent_org_bluez_agent1_skeleton_handle_method_call ( - GDBusConnection *connection G_GNUC_UNUSED, - const gchar *sender G_GNUC_UNUSED, - const gchar *object_path G_GNUC_UNUSED, - const gchar *interface_name, - const gchar *method_name, - GVariant *parameters, - GDBusMethodInvocation *invocation, - gpointer user_data) -{ - AGENTOrgBluezAgent1Skeleton *skeleton = AGENT_ORG_BLUEZ_AGENT1_SKELETON (user_data); - _ExtendedGDBusMethodInfo *info; - GVariantIter iter; - GVariant *child; - GValue *paramv; - guint num_params; - guint num_extra; - guint n; - guint signal_id; - GValue return_value = G_VALUE_INIT; - info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation); - g_assert (info != NULL); - num_params = g_variant_n_children (parameters); - num_extra = info->pass_fdlist ? 3 : 2; paramv = g_new0 (GValue, num_params + num_extra); - n = 0; - g_value_init (¶mv[n], AGENT_TYPE_ORG_BLUEZ_AGENT1); - g_value_set_object (¶mv[n++], skeleton); - g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION); - g_value_set_object (¶mv[n++], invocation); - if (info->pass_fdlist) - { -#ifdef G_OS_UNIX - g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST); - g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation))); -#else - g_assert_not_reached (); -#endif - } - g_variant_iter_init (&iter, parameters); - while ((child = g_variant_iter_next_value (&iter)) != NULL) - { - _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra]; - if (arg_info->use_gvariant) - { - g_value_init (¶mv[n], G_TYPE_VARIANT); - g_value_set_variant (¶mv[n], child); - n++; - } - else - g_dbus_gvariant_to_gvalue (child, ¶mv[n++]); - g_variant_unref (child); - } - signal_id = g_signal_lookup (info->signal_name, AGENT_TYPE_ORG_BLUEZ_AGENT1); - g_value_init (&return_value, G_TYPE_BOOLEAN); - g_signal_emitv (paramv, signal_id, 0, &return_value); - if (!g_value_get_boolean (&return_value)) - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Method %s is not implemented on interface %s", method_name, interface_name); - g_value_unset (&return_value); - for (n = 0; n < num_params + num_extra; n++) - g_value_unset (¶mv[n]); - g_free (paramv); -} - -static GVariant * -_agent_org_bluez_agent1_skeleton_handle_get_property ( - GDBusConnection *connection G_GNUC_UNUSED, - const gchar *sender G_GNUC_UNUSED, - const gchar *object_path G_GNUC_UNUSED, - const gchar *interface_name G_GNUC_UNUSED, - const gchar *property_name, - GError **error, - gpointer user_data) -{ - AGENTOrgBluezAgent1Skeleton *skeleton = AGENT_ORG_BLUEZ_AGENT1_SKELETON (user_data); - GValue value = G_VALUE_INIT; - GParamSpec *pspec; - _ExtendedGDBusPropertyInfo *info; - GVariant *ret; - ret = NULL; - info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_agent_org_bluez_agent1_interface_info.parent_struct, property_name); - g_assert (info != NULL); - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name); - if (pspec == NULL) - { - g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %s", property_name); - } - else - { - g_value_init (&value, pspec->value_type); - g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value); - ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature)); - g_value_unset (&value); - } - return ret; -} - -static gboolean -_agent_org_bluez_agent1_skeleton_handle_set_property ( - GDBusConnection *connection G_GNUC_UNUSED, - const gchar *sender G_GNUC_UNUSED, - const gchar *object_path G_GNUC_UNUSED, - const gchar *interface_name G_GNUC_UNUSED, - const gchar *property_name, - GVariant *variant, - GError **error, - gpointer user_data) -{ - AGENTOrgBluezAgent1Skeleton *skeleton = AGENT_ORG_BLUEZ_AGENT1_SKELETON (user_data); - GValue value = G_VALUE_INIT; - GParamSpec *pspec; - _ExtendedGDBusPropertyInfo *info; - gboolean ret; - ret = FALSE; - info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_agent_org_bluez_agent1_interface_info.parent_struct, property_name); - g_assert (info != NULL); - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name); - if (pspec == NULL) - { - g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %s", property_name); - } - else - { - if (info->use_gvariant) - g_value_set_variant (&value, variant); - else - g_dbus_gvariant_to_gvalue (variant, &value); - g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value); - g_value_unset (&value); - ret = TRUE; - } - return ret; -} - -static const GDBusInterfaceVTable _agent_org_bluez_agent1_skeleton_vtable = -{ - _agent_org_bluez_agent1_skeleton_handle_method_call, - _agent_org_bluez_agent1_skeleton_handle_get_property, - _agent_org_bluez_agent1_skeleton_handle_set_property, - {NULL} -}; - -static GDBusInterfaceInfo * -agent_org_bluez_agent1_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED) -{ - return agent_org_bluez_agent1_interface_info (); -} - -static GDBusInterfaceVTable * -agent_org_bluez_agent1_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED) -{ - return (GDBusInterfaceVTable *) &_agent_org_bluez_agent1_skeleton_vtable; -} - -static GVariant * -agent_org_bluez_agent1_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton) -{ - AGENTOrgBluezAgent1Skeleton *skeleton = AGENT_ORG_BLUEZ_AGENT1_SKELETON (_skeleton); - - GVariantBuilder builder; - guint n; - g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); - if (_agent_org_bluez_agent1_interface_info.parent_struct.properties == NULL) - goto out; - for (n = 0; _agent_org_bluez_agent1_interface_info.parent_struct.properties[n] != NULL; n++) - { - GDBusPropertyInfo *info = _agent_org_bluez_agent1_interface_info.parent_struct.properties[n]; - if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE) - { - GVariant *value; - value = _agent_org_bluez_agent1_skeleton_handle_get_property (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)), NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "org.bluez.Agent1", info->name, NULL, skeleton); - if (value != NULL) - { - g_variant_take_ref (value); - g_variant_builder_add (&builder, "{sv}", info->name, value); - g_variant_unref (value); - } - } - } -out: - return g_variant_builder_end (&builder); -} - -static void -agent_org_bluez_agent1_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton) -{ -} - -static void agent_org_bluez_agent1_skeleton_iface_init (AGENTOrgBluezAgent1Iface *iface); -#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 -G_DEFINE_TYPE_WITH_CODE (AGENTOrgBluezAgent1Skeleton, agent_org_bluez_agent1_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON, - G_ADD_PRIVATE (AGENTOrgBluezAgent1Skeleton) - G_IMPLEMENT_INTERFACE (AGENT_TYPE_ORG_BLUEZ_AGENT1, agent_org_bluez_agent1_skeleton_iface_init)); - -#else -G_DEFINE_TYPE_WITH_CODE (AGENTOrgBluezAgent1Skeleton, agent_org_bluez_agent1_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON, - G_IMPLEMENT_INTERFACE (AGENT_TYPE_ORG_BLUEZ_AGENT1, agent_org_bluez_agent1_skeleton_iface_init)); - -#endif -static void -agent_org_bluez_agent1_skeleton_finalize (GObject *object) -{ - AGENTOrgBluezAgent1Skeleton *skeleton = AGENT_ORG_BLUEZ_AGENT1_SKELETON (object); - g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free); - if (skeleton->priv->changed_properties_idle_source != NULL) - g_source_destroy (skeleton->priv->changed_properties_idle_source); - g_main_context_unref (skeleton->priv->context); - g_mutex_clear (&skeleton->priv->lock); - G_OBJECT_CLASS (agent_org_bluez_agent1_skeleton_parent_class)->finalize (object); -} - -static void -agent_org_bluez_agent1_skeleton_init (AGENTOrgBluezAgent1Skeleton *skeleton) -{ -#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 - skeleton->priv = agent_org_bluez_agent1_skeleton_get_instance_private (skeleton); -#else - skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, AGENT_TYPE_ORG_BLUEZ_AGENT1_SKELETON, AGENTOrgBluezAgent1SkeletonPrivate); -#endif - - g_mutex_init (&skeleton->priv->lock); - skeleton->priv->context = g_main_context_ref_thread_default (); -} - -static void -agent_org_bluez_agent1_skeleton_class_init (AGENTOrgBluezAgent1SkeletonClass *klass) -{ - GObjectClass *gobject_class; - GDBusInterfaceSkeletonClass *skeleton_class; - - gobject_class = G_OBJECT_CLASS (klass); - gobject_class->finalize = agent_org_bluez_agent1_skeleton_finalize; - - skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass); - skeleton_class->get_info = agent_org_bluez_agent1_skeleton_dbus_interface_get_info; - skeleton_class->get_properties = agent_org_bluez_agent1_skeleton_dbus_interface_get_properties; - skeleton_class->flush = agent_org_bluez_agent1_skeleton_dbus_interface_flush; - skeleton_class->get_vtable = agent_org_bluez_agent1_skeleton_dbus_interface_get_vtable; - -#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38 - g_type_class_add_private (klass, sizeof (AGENTOrgBluezAgent1SkeletonPrivate)); -#endif -} - -static void -agent_org_bluez_agent1_skeleton_iface_init (AGENTOrgBluezAgent1Iface *iface) -{ -} - -/** - * agent_org_bluez_agent1_skeleton_new: - * - * Creates a skeleton object for the D-Bus interface <link linkend="gdbus-interface-org-bluez-Agent1.top_of_page">org.bluez.Agent1</link>. - * - * Returns: (transfer full) (type AGENTOrgBluezAgent1Skeleton): The skeleton object. - */ -AGENTOrgBluezAgent1 * -agent_org_bluez_agent1_skeleton_new (void) -{ - return AGENT_ORG_BLUEZ_AGENT1 (g_object_new (AGENT_TYPE_ORG_BLUEZ_AGENT1_SKELETON, NULL)); -} - diff --git a/binding-bluetooth/lib_agent.h b/binding-bluetooth/lib_agent.h deleted file mode 100644 index 0a355ee..0000000 --- a/binding-bluetooth/lib_agent.h +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Generated by gdbus-codegen 2.48.1. DO NOT EDIT. - * - * The license of this code is the same as for the source it was derived from. - */ - -#ifndef __LIB_AGENT_H__ -#define __LIB_AGENT_H__ - -#include <gio/gio.h> - -G_BEGIN_DECLS - - -/* ------------------------------------------------------------------------ */ -/* Declarations for org.bluez.Agent1 */ - -#define AGENT_TYPE_ORG_BLUEZ_AGENT1 (agent_org_bluez_agent1_get_type ()) -#define AGENT_ORG_BLUEZ_AGENT1(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), AGENT_TYPE_ORG_BLUEZ_AGENT1, AGENTOrgBluezAgent1)) -#define AGENT_IS_ORG_BLUEZ_AGENT1(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), AGENT_TYPE_ORG_BLUEZ_AGENT1)) -#define AGENT_ORG_BLUEZ_AGENT1_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), AGENT_TYPE_ORG_BLUEZ_AGENT1, AGENTOrgBluezAgent1Iface)) - -struct _AGENTOrgBluezAgent1; -typedef struct _AGENTOrgBluezAgent1 AGENTOrgBluezAgent1; -typedef struct _AGENTOrgBluezAgent1Iface AGENTOrgBluezAgent1Iface; - -struct _AGENTOrgBluezAgent1Iface -{ - GTypeInterface parent_iface; - - gboolean (*handle_authorize_service) ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *arg_device, - const gchar *arg_uuid); - - gboolean (*handle_cancel) ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation); - - gboolean (*handle_display_passkey) ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *arg_device, - guint arg_passkey, - guint16 arg_entered); - - gboolean (*handle_display_pin_code) ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *arg_device, - const gchar *arg_pincode); - - gboolean (*handle_release) ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation); - - gboolean (*handle_request_authorization) ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *arg_device); - - gboolean (*handle_request_confirmation) ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *arg_device, - guint arg_passkey); - - gboolean (*handle_request_passkey) ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *arg_device); - - gboolean (*handle_request_pin_code) ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *arg_device); - -}; - -GType agent_org_bluez_agent1_get_type (void) G_GNUC_CONST; - -GDBusInterfaceInfo *agent_org_bluez_agent1_interface_info (void); -guint agent_org_bluez_agent1_override_properties (GObjectClass *klass, guint property_id_begin); - - -/* D-Bus method call completion functions: */ -void agent_org_bluez_agent1_complete_release ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation); - -void agent_org_bluez_agent1_complete_request_pin_code ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - const gchar *pincode); - -void agent_org_bluez_agent1_complete_display_pin_code ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation); - -void agent_org_bluez_agent1_complete_request_passkey ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation, - guint passkey); - -void agent_org_bluez_agent1_complete_display_passkey ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation); - -void agent_org_bluez_agent1_complete_request_confirmation ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation); - -void agent_org_bluez_agent1_complete_request_authorization ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation); - -void agent_org_bluez_agent1_complete_authorize_service ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation); - -void agent_org_bluez_agent1_complete_cancel ( - AGENTOrgBluezAgent1 *object, - GDBusMethodInvocation *invocation); - - - -/* D-Bus method calls: */ -void agent_org_bluez_agent1_call_release ( - AGENTOrgBluezAgent1 *proxy, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean agent_org_bluez_agent1_call_release_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error); - -gboolean agent_org_bluez_agent1_call_release_sync ( - AGENTOrgBluezAgent1 *proxy, - GCancellable *cancellable, - GError **error); - -void agent_org_bluez_agent1_call_request_pin_code ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean agent_org_bluez_agent1_call_request_pin_code_finish ( - AGENTOrgBluezAgent1 *proxy, - gchar **out_pincode, - GAsyncResult *res, - GError **error); - -gboolean agent_org_bluez_agent1_call_request_pin_code_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - gchar **out_pincode, - GCancellable *cancellable, - GError **error); - -void agent_org_bluez_agent1_call_display_pin_code ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - const gchar *arg_pincode, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean agent_org_bluez_agent1_call_display_pin_code_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error); - -gboolean agent_org_bluez_agent1_call_display_pin_code_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - const gchar *arg_pincode, - GCancellable *cancellable, - GError **error); - -void agent_org_bluez_agent1_call_request_passkey ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean agent_org_bluez_agent1_call_request_passkey_finish ( - AGENTOrgBluezAgent1 *proxy, - guint *out_passkey, - GAsyncResult *res, - GError **error); - -gboolean agent_org_bluez_agent1_call_request_passkey_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - guint *out_passkey, - GCancellable *cancellable, - GError **error); - -void agent_org_bluez_agent1_call_display_passkey ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - guint arg_passkey, - guint16 arg_entered, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean agent_org_bluez_agent1_call_display_passkey_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error); - -gboolean agent_org_bluez_agent1_call_display_passkey_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - guint arg_passkey, - guint16 arg_entered, - GCancellable *cancellable, - GError **error); - -void agent_org_bluez_agent1_call_request_confirmation ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - guint arg_passkey, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean agent_org_bluez_agent1_call_request_confirmation_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error); - -gboolean agent_org_bluez_agent1_call_request_confirmation_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - guint arg_passkey, - GCancellable *cancellable, - GError **error); - -void agent_org_bluez_agent1_call_request_authorization ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean agent_org_bluez_agent1_call_request_authorization_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error); - -gboolean agent_org_bluez_agent1_call_request_authorization_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - GCancellable *cancellable, - GError **error); - -void agent_org_bluez_agent1_call_authorize_service ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - const gchar *arg_uuid, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean agent_org_bluez_agent1_call_authorize_service_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error); - -gboolean agent_org_bluez_agent1_call_authorize_service_sync ( - AGENTOrgBluezAgent1 *proxy, - const gchar *arg_device, - const gchar *arg_uuid, - GCancellable *cancellable, - GError **error); - -void agent_org_bluez_agent1_call_cancel ( - AGENTOrgBluezAgent1 *proxy, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean agent_org_bluez_agent1_call_cancel_finish ( - AGENTOrgBluezAgent1 *proxy, - GAsyncResult *res, - GError **error); - -gboolean agent_org_bluez_agent1_call_cancel_sync ( - AGENTOrgBluezAgent1 *proxy, - GCancellable *cancellable, - GError **error); - - - -/* ---- */ - -#define AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY (agent_org_bluez_agent1_proxy_get_type ()) -#define AGENT_ORG_BLUEZ_AGENT1_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY, AGENTOrgBluezAgent1Proxy)) -#define AGENT_ORG_BLUEZ_AGENT1_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY, AGENTOrgBluezAgent1ProxyClass)) -#define AGENT_ORG_BLUEZ_AGENT1_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY, AGENTOrgBluezAgent1ProxyClass)) -#define AGENT_IS_ORG_BLUEZ_AGENT1_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY)) -#define AGENT_IS_ORG_BLUEZ_AGENT1_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), AGENT_TYPE_ORG_BLUEZ_AGENT1_PROXY)) - -typedef struct _AGENTOrgBluezAgent1Proxy AGENTOrgBluezAgent1Proxy; -typedef struct _AGENTOrgBluezAgent1ProxyClass AGENTOrgBluezAgent1ProxyClass; -typedef struct _AGENTOrgBluezAgent1ProxyPrivate AGENTOrgBluezAgent1ProxyPrivate; - -struct _AGENTOrgBluezAgent1Proxy -{ - /*< private >*/ - GDBusProxy parent_instance; - AGENTOrgBluezAgent1ProxyPrivate *priv; -}; - -struct _AGENTOrgBluezAgent1ProxyClass -{ - GDBusProxyClass parent_class; -}; - -GType agent_org_bluez_agent1_proxy_get_type (void) G_GNUC_CONST; - -#if GLIB_CHECK_VERSION(2, 44, 0) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (AGENTOrgBluezAgent1Proxy, g_object_unref) -#endif - -void agent_org_bluez_agent1_proxy_new ( - GDBusConnection *connection, - GDBusProxyFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -AGENTOrgBluezAgent1 *agent_org_bluez_agent1_proxy_new_finish ( - GAsyncResult *res, - GError **error); -AGENTOrgBluezAgent1 *agent_org_bluez_agent1_proxy_new_sync ( - GDBusConnection *connection, - GDBusProxyFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GError **error); - -void agent_org_bluez_agent1_proxy_new_for_bus ( - GBusType bus_type, - GDBusProxyFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -AGENTOrgBluezAgent1 *agent_org_bluez_agent1_proxy_new_for_bus_finish ( - GAsyncResult *res, - GError **error); -AGENTOrgBluezAgent1 *agent_org_bluez_agent1_proxy_new_for_bus_sync ( - GBusType bus_type, - GDBusProxyFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GError **error); - - -/* ---- */ - -#define AGENT_TYPE_ORG_BLUEZ_AGENT1_SKELETON (agent_org_bluez_agent1_skeleton_get_type ()) -#define AGENT_ORG_BLUEZ_AGENT1_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), AGENT_TYPE_ORG_BLUEZ_AGENT1_SKELETON, AGENTOrgBluezAgent1Skeleton)) -#define AGENT_ORG_BLUEZ_AGENT1_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), AGENT_TYPE_ORG_BLUEZ_AGENT1_SKELETON, AGENTOrgBluezAgent1SkeletonClass)) -#define AGENT_ORG_BLUEZ_AGENT1_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), AGENT_TYPE_ORG_BLUEZ_AGENT1_SKELETON, AGENTOrgBluezAgent1SkeletonClass)) -#define AGENT_IS_ORG_BLUEZ_AGENT1_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), AGENT_TYPE_ORG_BLUEZ_AGENT1_SKELETON)) -#define AGENT_IS_ORG_BLUEZ_AGENT1_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), AGENT_TYPE_ORG_BLUEZ_AGENT1_SKELETON)) - -typedef struct _AGENTOrgBluezAgent1Skeleton AGENTOrgBluezAgent1Skeleton; -typedef struct _AGENTOrgBluezAgent1SkeletonClass AGENTOrgBluezAgent1SkeletonClass; -typedef struct _AGENTOrgBluezAgent1SkeletonPrivate AGENTOrgBluezAgent1SkeletonPrivate; - -struct _AGENTOrgBluezAgent1Skeleton -{ - /*< private >*/ - GDBusInterfaceSkeleton parent_instance; - AGENTOrgBluezAgent1SkeletonPrivate *priv; -}; - -struct _AGENTOrgBluezAgent1SkeletonClass -{ - GDBusInterfaceSkeletonClass parent_class; -}; - -GType agent_org_bluez_agent1_skeleton_get_type (void) G_GNUC_CONST; - -#if GLIB_CHECK_VERSION(2, 44, 0) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (AGENTOrgBluezAgent1Skeleton, g_object_unref) -#endif - -AGENTOrgBluezAgent1 *agent_org_bluez_agent1_skeleton_new (void); - - -G_END_DECLS - -#endif /* __LIB_AGENT_H__ */ diff --git a/binding-bluetooth/lib_bluez.c b/binding-bluetooth/lib_bluez.c deleted file mode 100644 index 58d844d..0000000 --- a/binding-bluetooth/lib_bluez.c +++ /dev/null @@ -1,630 +0,0 @@ -/* - * Generated by gdbus-codegen 2.48.1. DO NOT EDIT. - * - * The license of this code is the same as for the source it was derived from. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "lib_bluez.h" - -#include <string.h> -#ifdef G_OS_UNIX -# include <gio/gunixfdlist.h> -#endif - -typedef struct -{ - GDBusArgInfo parent_struct; - gboolean use_gvariant; -} _ExtendedGDBusArgInfo; - -typedef struct -{ - GDBusMethodInfo parent_struct; - const gchar *signal_name; - gboolean pass_fdlist; -} _ExtendedGDBusMethodInfo; - -typedef struct -{ - GDBusSignalInfo parent_struct; - const gchar *signal_name; -} _ExtendedGDBusSignalInfo; - -typedef struct -{ - GDBusPropertyInfo parent_struct; - const gchar *hyphen_name; - gboolean use_gvariant; -} _ExtendedGDBusPropertyInfo; - -typedef struct -{ - GDBusInterfaceInfo parent_struct; - const gchar *hyphen_name; -} _ExtendedGDBusInterfaceInfo; - -typedef struct -{ - const _ExtendedGDBusPropertyInfo *info; - guint prop_id; - GValue orig_value; /* the value before the change */ -} ChangedProperty; - -static void -_changed_property_free (ChangedProperty *data) -{ - g_value_unset (&data->orig_value); - g_free (data); -} - -static gboolean -_g_strv_equal0 (gchar **a, gchar **b) -{ - gboolean ret = FALSE; - guint n; - if (a == NULL && b == NULL) - { - ret = TRUE; - goto out; - } - if (a == NULL || b == NULL) - goto out; - if (g_strv_length (a) != g_strv_length (b)) - goto out; - for (n = 0; a[n] != NULL; n++) - if (g_strcmp0 (a[n], b[n]) != 0) - goto out; - ret = TRUE; -out: - return ret; -} - -static gboolean -_g_variant_equal0 (GVariant *a, GVariant *b) -{ - gboolean ret = FALSE; - if (a == NULL && b == NULL) - { - ret = TRUE; - goto out; - } - if (a == NULL || b == NULL) - goto out; - ret = g_variant_equal (a, b); -out: - return ret; -} - -G_GNUC_UNUSED static gboolean -_g_value_equal (const GValue *a, const GValue *b) -{ - gboolean ret = FALSE; - g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b)); - switch (G_VALUE_TYPE (a)) - { - case G_TYPE_BOOLEAN: - ret = (g_value_get_boolean (a) == g_value_get_boolean (b)); - break; - case G_TYPE_UCHAR: - ret = (g_value_get_uchar (a) == g_value_get_uchar (b)); - break; - case G_TYPE_INT: - ret = (g_value_get_int (a) == g_value_get_int (b)); - break; - case G_TYPE_UINT: - ret = (g_value_get_uint (a) == g_value_get_uint (b)); - break; - case G_TYPE_INT64: - ret = (g_value_get_int64 (a) == g_value_get_int64 (b)); - break; - case G_TYPE_UINT64: - ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b)); - break; - case G_TYPE_DOUBLE: - { - /* Avoid -Wfloat-equal warnings by doing a direct bit compare */ - gdouble da = g_value_get_double (a); - gdouble db = g_value_get_double (b); - ret = memcmp (&da, &db, sizeof (gdouble)) == 0; - } - break; - case G_TYPE_STRING: - ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0); - break; - case G_TYPE_VARIANT: - ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b)); - break; - default: - if (G_VALUE_TYPE (a) == G_TYPE_STRV) - ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b)); - else - g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a))); - break; - } - return ret; -} - -/* ------------------------------------------------------------------------ - * Code for Object, ObjectProxy and ObjectSkeleton - * ------------------------------------------------------------------------ - */ - -/** - * SECTION:BLUEZObject - * @title: BLUEZObject - * @short_description: Specialized GDBusObject types - * - * This section contains the #BLUEZObject, #BLUEZObjectProxy, and #BLUEZObjectSkeleton types which make it easier to work with objects implementing generated types for D-Bus interfaces. - */ - -/** - * BLUEZObject: - * - * The #BLUEZObject type is a specialized container of interfaces. - */ - -/** - * BLUEZObjectIface: - * @parent_iface: The parent interface. - * - * Virtual table for the #BLUEZObject interface. - */ - -typedef BLUEZObjectIface BLUEZObjectInterface; -G_DEFINE_INTERFACE_WITH_CODE (BLUEZObject, bluez_object, G_TYPE_OBJECT, g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_DBUS_OBJECT)); - -static void -bluez_object_default_init (BLUEZObjectIface *iface) -{ -} - - - -static void -bluez_object_notify (GDBusObject *object, GDBusInterface *interface) -{ - _ExtendedGDBusInterfaceInfo *info = (_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface); - /* info can be NULL if the other end is using a D-Bus interface we don't know - * anything about, for example old generated code in this process talking to - * newer generated code in the other process. */ - if (info != NULL) - g_object_notify (G_OBJECT (object), info->hyphen_name); -} - -/** - * BLUEZObjectProxy: - * - * The #BLUEZObjectProxy structure contains only private data and should only be accessed using the provided API. - */ - -/** - * BLUEZObjectProxyClass: - * @parent_class: The parent class. - * - * Class structure for #BLUEZObjectProxy. - */ - -static void -bluez_object_proxy__bluez_object_iface_init (BLUEZObjectIface *iface G_GNUC_UNUSED) -{ -} - -static void -bluez_object_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface) -{ - iface->interface_added = bluez_object_notify; - iface->interface_removed = bluez_object_notify; -} - - -G_DEFINE_TYPE_WITH_CODE (BLUEZObjectProxy, bluez_object_proxy, G_TYPE_DBUS_OBJECT_PROXY, - G_IMPLEMENT_INTERFACE (BLUEZ_TYPE_OBJECT, bluez_object_proxy__bluez_object_iface_init) - G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, bluez_object_proxy__g_dbus_object_iface_init)); - -static void -bluez_object_proxy_init (BLUEZObjectProxy *object G_GNUC_UNUSED) -{ -} - -static void -bluez_object_proxy_set_property (GObject *gobject, - guint prop_id, - const GValue *value G_GNUC_UNUSED, - GParamSpec *pspec) -{ - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); -} - -static void -bluez_object_proxy_get_property (GObject *gobject, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - BLUEZObjectProxy *object = BLUEZ_OBJECT_PROXY (gobject); - GDBusInterface *interface; - - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -bluez_object_proxy_class_init (BLUEZObjectProxyClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->set_property = bluez_object_proxy_set_property; - gobject_class->get_property = bluez_object_proxy_get_property; - -} - -/** - * bluez_object_proxy_new: - * @connection: A #GDBusConnection. - * @object_path: An object path. - * - * Creates a new proxy object. - * - * Returns: (transfer full): The proxy object. - */ -BLUEZObjectProxy * -bluez_object_proxy_new (GDBusConnection *connection, - const gchar *object_path) -{ - g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); - g_return_val_if_fail (g_variant_is_object_path (object_path), NULL); - return BLUEZ_OBJECT_PROXY (g_object_new (BLUEZ_TYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL)); -} - -/** - * BLUEZObjectSkeleton: - * - * The #BLUEZObjectSkeleton structure contains only private data and should only be accessed using the provided API. - */ - -/** - * BLUEZObjectSkeletonClass: - * @parent_class: The parent class. - * - * Class structure for #BLUEZObjectSkeleton. - */ - -static void -bluez_object_skeleton__bluez_object_iface_init (BLUEZObjectIface *iface G_GNUC_UNUSED) -{ -} - - -static void -bluez_object_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface) -{ - iface->interface_added = bluez_object_notify; - iface->interface_removed = bluez_object_notify; -} - -G_DEFINE_TYPE_WITH_CODE (BLUEZObjectSkeleton, bluez_object_skeleton, G_TYPE_DBUS_OBJECT_SKELETON, - G_IMPLEMENT_INTERFACE (BLUEZ_TYPE_OBJECT, bluez_object_skeleton__bluez_object_iface_init) - G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, bluez_object_skeleton__g_dbus_object_iface_init)); - -static void -bluez_object_skeleton_init (BLUEZObjectSkeleton *object G_GNUC_UNUSED) -{ -} - -static void -bluez_object_skeleton_set_property (GObject *gobject, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - BLUEZObjectSkeleton *object = BLUEZ_OBJECT_SKELETON (gobject); - GDBusInterfaceSkeleton *interface; - - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -bluez_object_skeleton_get_property (GObject *gobject, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - BLUEZObjectSkeleton *object = BLUEZ_OBJECT_SKELETON (gobject); - GDBusInterface *interface; - - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -bluez_object_skeleton_class_init (BLUEZObjectSkeletonClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->set_property = bluez_object_skeleton_set_property; - gobject_class->get_property = bluez_object_skeleton_get_property; - -} - -/** - * bluez_object_skeleton_new: - * @object_path: An object path. - * - * Creates a new skeleton object. - * - * Returns: (transfer full): The skeleton object. - */ -BLUEZObjectSkeleton * -bluez_object_skeleton_new (const gchar *object_path) -{ - g_return_val_if_fail (g_variant_is_object_path (object_path), NULL); - return BLUEZ_OBJECT_SKELETON (g_object_new (BLUEZ_TYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL)); -} - - -/* ------------------------------------------------------------------------ - * Code for ObjectManager client - * ------------------------------------------------------------------------ - */ - -/** - * SECTION:BLUEZObjectManagerClient - * @title: BLUEZObjectManagerClient - * @short_description: Generated GDBusObjectManagerClient type - * - * This section contains a #GDBusObjectManagerClient that uses bluez_object_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. - */ - -/** - * BLUEZObjectManagerClient: - * - * The #BLUEZObjectManagerClient structure contains only private data and should only be accessed using the provided API. - */ - -/** - * BLUEZObjectManagerClientClass: - * @parent_class: The parent class. - * - * Class structure for #BLUEZObjectManagerClient. - */ - -G_DEFINE_TYPE (BLUEZObjectManagerClient, bluez_object_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT); - -static void -bluez_object_manager_client_init (BLUEZObjectManagerClient *manager G_GNUC_UNUSED) -{ -} - -static void -bluez_object_manager_client_class_init (BLUEZObjectManagerClientClass *klass G_GNUC_UNUSED) -{ -} - -/** - * bluez_object_manager_client_get_proxy_type: - * @manager: A #GDBusObjectManagerClient. - * @object_path: The object path of the remote object (unused). - * @interface_name: (allow-none): Interface name of the remote object or %NULL to get the object proxy #GType. - * @user_data: User data (unused). - * - * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types. - * - * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %NULL, otherwise the #GType for #BLUEZObjectProxy. - */ -GType -bluez_object_manager_client_get_proxy_type (GDBusObjectManagerClient *manager G_GNUC_UNUSED, const gchar *object_path G_GNUC_UNUSED, const gchar *interface_name, gpointer user_data G_GNUC_UNUSED) -{ - static gsize once_init_value = 0; - static GHashTable *lookup_hash; - GType ret; - - if (interface_name == NULL) - return BLUEZ_TYPE_OBJECT_PROXY; - if (g_once_init_enter (&once_init_value)) - { - lookup_hash = g_hash_table_new (g_str_hash, g_str_equal); - g_once_init_leave (&once_init_value, 1); - } - ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name)); - if (ret == (GType) 0) - ret = G_TYPE_DBUS_PROXY; - return ret; -} - -/** - * bluez_object_manager_client_new: - * @connection: A #GDBusConnection. - * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. - * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. - * @object_path: An object path. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied. - * @user_data: User data to pass to @callback. - * - * Asynchronously creates #GDBusObjectManagerClient using bluez_object_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details. - * - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call bluez_object_manager_client_new_finish() to get the result of the operation. - * - * See bluez_object_manager_client_new_sync() for the synchronous, blocking version of this constructor. - */ -void -bluez_object_manager_client_new ( - GDBusConnection *connection, - GDBusObjectManagerClientFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_async_initable_new_async (BLUEZ_TYPE_OBJECT_MANAGER_CLIENT, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "flags", flags, "name", name, "connection", connection, "object-path", object_path, "get-proxy-type-func", bluez_object_manager_client_get_proxy_type, NULL); -} - -/** - * bluez_object_manager_client_new_finish: - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to bluez_object_manager_client_new(). - * @error: Return location for error or %NULL - * - * Finishes an operation started with bluez_object_manager_client_new(). - * - * Returns: (transfer full) (type BLUEZObjectManagerClient): The constructed object manager client or %NULL if @error is set. - */ -GDBusObjectManager * -bluez_object_manager_client_new_finish ( - GAsyncResult *res, - GError **error) -{ - GObject *ret; - GObject *source_object; - source_object = g_async_result_get_source_object (res); - ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); - g_object_unref (source_object); - if (ret != NULL) - return G_DBUS_OBJECT_MANAGER (ret); - else - return NULL; -} - -/** - * bluez_object_manager_client_new_sync: - * @connection: A #GDBusConnection. - * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. - * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. - * @object_path: An object path. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL - * - * Synchronously creates #GDBusObjectManagerClient using bluez_object_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new_sync() for more details. - * - * The calling thread is blocked until a reply is received. - * - * See bluez_object_manager_client_new() for the asynchronous version of this constructor. - * - * Returns: (transfer full) (type BLUEZObjectManagerClient): The constructed object manager client or %NULL if @error is set. - */ -GDBusObjectManager * -bluez_object_manager_client_new_sync ( - GDBusConnection *connection, - GDBusObjectManagerClientFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GError **error) -{ - GInitable *ret; - ret = g_initable_new (BLUEZ_TYPE_OBJECT_MANAGER_CLIENT, cancellable, error, "flags", flags, "name", name, "connection", connection, "object-path", object_path, "get-proxy-type-func", bluez_object_manager_client_get_proxy_type, NULL); - if (ret != NULL) - return G_DBUS_OBJECT_MANAGER (ret); - else - return NULL; -} - - -/** - * bluez_object_manager_client_new_for_bus: - * @bus_type: A #GBusType. - * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. - * @name: A bus name (well-known or unique). - * @object_path: An object path. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @callback: A #GAsyncReadyCallback to call when the request is satisfied. - * @user_data: User data to pass to @callback. - * - * Like bluez_object_manager_client_new() but takes a #GBusType instead of a #GDBusConnection. - * - * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. - * You can then call bluez_object_manager_client_new_for_bus_finish() to get the result of the operation. - * - * See bluez_object_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor. - */ -void -bluez_object_manager_client_new_for_bus ( - GBusType bus_type, - GDBusObjectManagerClientFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_async_initable_new_async (BLUEZ_TYPE_OBJECT_MANAGER_CLIENT, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "flags", flags, "name", name, "bus-type", bus_type, "object-path", object_path, "get-proxy-type-func", bluez_object_manager_client_get_proxy_type, NULL); -} - -/** - * bluez_object_manager_client_new_for_bus_finish: - * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to bluez_object_manager_client_new_for_bus(). - * @error: Return location for error or %NULL - * - * Finishes an operation started with bluez_object_manager_client_new_for_bus(). - * - * Returns: (transfer full) (type BLUEZObjectManagerClient): The constructed object manager client or %NULL if @error is set. - */ -GDBusObjectManager * -bluez_object_manager_client_new_for_bus_finish ( - GAsyncResult *res, - GError **error) -{ - GObject *ret; - GObject *source_object; - source_object = g_async_result_get_source_object (res); - ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); - g_object_unref (source_object); - if (ret != NULL) - return G_DBUS_OBJECT_MANAGER (ret); - else - return NULL; -} - -/** - * bluez_object_manager_client_new_for_bus_sync: - * @bus_type: A #GBusType. - * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. - * @name: A bus name (well-known or unique). - * @object_path: An object path. - * @cancellable: (allow-none): A #GCancellable or %NULL. - * @error: Return location for error or %NULL - * - * Like bluez_object_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection. - * - * The calling thread is blocked until a reply is received. - * - * See bluez_object_manager_client_new_for_bus() for the asynchronous version of this constructor. - * - * Returns: (transfer full) (type BLUEZObjectManagerClient): The constructed object manager client or %NULL if @error is set. - */ -GDBusObjectManager * -bluez_object_manager_client_new_for_bus_sync ( - GBusType bus_type, - GDBusObjectManagerClientFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GError **error) -{ - GInitable *ret; - ret = g_initable_new (BLUEZ_TYPE_OBJECT_MANAGER_CLIENT, cancellable, error, "flags", flags, "name", name, "bus-type", bus_type, "object-path", object_path, "get-proxy-type-func", bluez_object_manager_client_get_proxy_type, NULL); - if (ret != NULL) - return G_DBUS_OBJECT_MANAGER (ret); - else - return NULL; -} - - diff --git a/binding-bluetooth/lib_bluez.h b/binding-bluetooth/lib_bluez.h deleted file mode 100644 index 1408bb2..0000000 --- a/binding-bluetooth/lib_bluez.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Generated by gdbus-codegen 2.48.1. DO NOT EDIT. - * - * The license of this code is the same as for the source it was derived from. - */ - -#ifndef __LIB_BLUEZ_H__ -#define __LIB_BLUEZ_H__ - -#include <gio/gio.h> - -G_BEGIN_DECLS - - -/* ---- */ - -#define BLUEZ_TYPE_OBJECT (bluez_object_get_type ()) -#define BLUEZ_OBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), BLUEZ_TYPE_OBJECT, BLUEZObject)) -#define BLUEZ_IS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), BLUEZ_TYPE_OBJECT)) -#define BLUEZ_OBJECT_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), BLUEZ_TYPE_OBJECT, BLUEZObject)) - -struct _BLUEZObject; -typedef struct _BLUEZObject BLUEZObject; -typedef struct _BLUEZObjectIface BLUEZObjectIface; - -struct _BLUEZObjectIface -{ - GTypeInterface parent_iface; -}; - -GType bluez_object_get_type (void) G_GNUC_CONST; - - -#define BLUEZ_TYPE_OBJECT_PROXY (bluez_object_proxy_get_type ()) -#define BLUEZ_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), BLUEZ_TYPE_OBJECT_PROXY, BLUEZObjectProxy)) -#define BLUEZ_OBJECT_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), BLUEZ_TYPE_OBJECT_PROXY, BLUEZObjectProxyClass)) -#define BLUEZ_OBJECT_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), BLUEZ_TYPE_OBJECT_PROXY, BLUEZObjectProxyClass)) -#define BLUEZ_IS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), BLUEZ_TYPE_OBJECT_PROXY)) -#define BLUEZ_IS_OBJECT_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), BLUEZ_TYPE_OBJECT_PROXY)) - -typedef struct _BLUEZObjectProxy BLUEZObjectProxy; -typedef struct _BLUEZObjectProxyClass BLUEZObjectProxyClass; -typedef struct _BLUEZObjectProxyPrivate BLUEZObjectProxyPrivate; - -struct _BLUEZObjectProxy -{ - /*< private >*/ - GDBusObjectProxy parent_instance; - BLUEZObjectProxyPrivate *priv; -}; - -struct _BLUEZObjectProxyClass -{ - GDBusObjectProxyClass parent_class; -}; - -GType bluez_object_proxy_get_type (void) G_GNUC_CONST; - -#if GLIB_CHECK_VERSION(2, 44, 0) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (BLUEZObjectProxy, g_object_unref) -#endif - -BLUEZObjectProxy *bluez_object_proxy_new (GDBusConnection *connection, const gchar *object_path); - -#define BLUEZ_TYPE_OBJECT_SKELETON (bluez_object_skeleton_get_type ()) -#define BLUEZ_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), BLUEZ_TYPE_OBJECT_SKELETON, BLUEZObjectSkeleton)) -#define BLUEZ_OBJECT_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), BLUEZ_TYPE_OBJECT_SKELETON, BLUEZObjectSkeletonClass)) -#define BLUEZ_OBJECT_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), BLUEZ_TYPE_OBJECT_SKELETON, BLUEZObjectSkeletonClass)) -#define BLUEZ_IS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), BLUEZ_TYPE_OBJECT_SKELETON)) -#define BLUEZ_IS_OBJECT_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), BLUEZ_TYPE_OBJECT_SKELETON)) - -typedef struct _BLUEZObjectSkeleton BLUEZObjectSkeleton; -typedef struct _BLUEZObjectSkeletonClass BLUEZObjectSkeletonClass; -typedef struct _BLUEZObjectSkeletonPrivate BLUEZObjectSkeletonPrivate; - -struct _BLUEZObjectSkeleton -{ - /*< private >*/ - GDBusObjectSkeleton parent_instance; - BLUEZObjectSkeletonPrivate *priv; -}; - -struct _BLUEZObjectSkeletonClass -{ - GDBusObjectSkeletonClass parent_class; -}; - -GType bluez_object_skeleton_get_type (void) G_GNUC_CONST; - -#if GLIB_CHECK_VERSION(2, 44, 0) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (BLUEZObjectSkeleton, g_object_unref) -#endif - -BLUEZObjectSkeleton *bluez_object_skeleton_new (const gchar *object_path); - -/* ---- */ - -#define BLUEZ_TYPE_OBJECT_MANAGER_CLIENT (bluez_object_manager_client_get_type ()) -#define BLUEZ_OBJECT_MANAGER_CLIENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), BLUEZ_TYPE_OBJECT_MANAGER_CLIENT, BLUEZObjectManagerClient)) -#define BLUEZ_OBJECT_MANAGER_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), BLUEZ_TYPE_OBJECT_MANAGER_CLIENT, BLUEZObjectManagerClientClass)) -#define BLUEZ_OBJECT_MANAGER_CLIENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), BLUEZ_TYPE_OBJECT_MANAGER_CLIENT, BLUEZObjectManagerClientClass)) -#define BLUEZ_IS_OBJECT_MANAGER_CLIENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), BLUEZ_TYPE_OBJECT_MANAGER_CLIENT)) -#define BLUEZ_IS_OBJECT_MANAGER_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), BLUEZ_TYPE_OBJECT_MANAGER_CLIENT)) - -typedef struct _BLUEZObjectManagerClient BLUEZObjectManagerClient; -typedef struct _BLUEZObjectManagerClientClass BLUEZObjectManagerClientClass; -typedef struct _BLUEZObjectManagerClientPrivate BLUEZObjectManagerClientPrivate; - -struct _BLUEZObjectManagerClient -{ - /*< private >*/ - GDBusObjectManagerClient parent_instance; - BLUEZObjectManagerClientPrivate *priv; -}; - -struct _BLUEZObjectManagerClientClass -{ - GDBusObjectManagerClientClass parent_class; -}; - -#if GLIB_CHECK_VERSION(2, 44, 0) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (BLUEZObjectManagerClient, g_object_unref) -#endif - -GType bluez_object_manager_client_get_type (void) G_GNUC_CONST; - -GType bluez_object_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data); - -void bluez_object_manager_client_new ( - GDBusConnection *connection, - GDBusObjectManagerClientFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -GDBusObjectManager *bluez_object_manager_client_new_finish ( - GAsyncResult *res, - GError **error); -GDBusObjectManager *bluez_object_manager_client_new_sync ( - GDBusConnection *connection, - GDBusObjectManagerClientFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GError **error); - -void bluez_object_manager_client_new_for_bus ( - GBusType bus_type, - GDBusObjectManagerClientFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -GDBusObjectManager *bluez_object_manager_client_new_for_bus_finish ( - GAsyncResult *res, - GError **error); -GDBusObjectManager *bluez_object_manager_client_new_for_bus_sync ( - GBusType bus_type, - GDBusObjectManagerClientFlags flags, - const gchar *name, - const gchar *object_path, - GCancellable *cancellable, - GError **error); - - -G_END_DECLS - -#endif /* __LIB_BLUEZ_H__ */ diff --git a/binding-bluetooth/CMakeLists.txt b/binding/CMakeLists.txt index 7461824..a4a8072 100644 --- a/binding-bluetooth/CMakeLists.txt +++ b/binding/CMakeLists.txt @@ -18,24 +18,18 @@ ########################################################################### # Add target to project dependency list -PROJECT_TARGET_ADD(bluetooth-binding) +PROJECT_TARGET_ADD(afm-bluetooth-binding) # Define project Targets - add_library(${TARGET_NAME} MODULE - bluetooth-api.c - bluetooth-manager.c - bluetooth-agent.c - lib_agent.c - bluez-client.c - lib_bluez.c) + add_library(afm-bluetooth-binding MODULE bluetooth-api.c bluetooth-agent.c bluetooth-rfkill.c bluetooth-util.c bluetooth-bluez.c) # Binder exposes a unique public entry point SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES - PREFIX "libafm-" + PREFIX "lib" LABELS "BINDING" + LINK_FLAGS ${BINDINGS_LINK_FLAG} OUTPUT_NAME ${TARGET_NAME} ) # Library dependencies (include updates automatically) TARGET_LINK_LIBRARIES(${TARGET_NAME} ${link_libraries}) - diff --git a/binding/bluetooth-agent.c b/binding/bluetooth-agent.c new file mode 100644 index 0000000..b6ae5fe --- /dev/null +++ b/binding/bluetooth-agent.c @@ -0,0 +1,272 @@ +/* + * Copyright 2018 Konsulko Group + * Author: Pantelis Antoniou <pantelis.antoniou@konsulko.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <pthread.h> +#include <semaphore.h> + +#include <glib.h> +#include <stdlib.h> +#include <gio/gio.h> +#include <glib-object.h> + +#include <json-c/json.h> + +#define AFB_BINDING_VERSION 3 +#include <afb/afb-binding.h> + +#include "bluetooth-api.h" +#include "bluetooth-common.h" + +/* Introspection data for the agent service */ +static const gchar introspection_xml[] = +"<node>" +" <interface name='org.bluez.Agent1'>" +" <method name='RequestConfirmation'>" +" <arg name='device' direction='in' type='o'/>" +" <arg name='passkey' direction='in' type='u'/>" +" </method>" +" <method name='AuthorizeService'>" +" <arg name='device' direction='in' type='o'/>" +" <arg name='uuid' direction='in' type='s'/>" +" </method>" +" <method name='Cancel'>" +" </method>" +" </interface>" +"</node>"; + +static void handle_method_call( + GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + struct bluetooth_state *ns = user_data; + struct call_work *cw; + GError *error = NULL; + json_object *jev = NULL; + const gchar *path = NULL; + + /* AFB_INFO("sender=%s", sender_name); + AFB_INFO("object_path=%s", object_path); + AFB_INFO("interface=%s", interface_name); + AFB_INFO("method=%s", method_name); */ + + if (!g_strcmp0(method_name, "RequestConfirmation")) { + int pin; + + g_variant_get(parameters, "(ou)", &path, &pin); + + call_work_lock(ns); + + /* can only occur while a pair is issued */ + cw = call_work_lookup_unlocked(ns, "device", NULL, "RequestConfirmation"); + + /* if nothing is pending return an error */ + /* TODO: allow client side pairing */ + if (!cw) + cw = call_work_create_unlocked(ns, "device", NULL, + "RequestConfirmation", NULL, &error); + + if (!cw) { + call_work_unlock(ns); + g_dbus_method_invocation_return_dbus_error(invocation, + "org.bluez.Error.Rejected", + "No connection pending"); + return; + } + + jev = json_object_new_object(); + json_object_object_add(jev, "action", json_object_new_string("request_confirmation")); + json_object_object_add(jev, "device", json_object_new_string(path)); + json_object_object_add(jev, "pincode", json_object_new_int(pin)); + + cw->agent_data.pin_code = pin; + cw->agent_data.device_path = g_strdup(path); + cw->invocation = invocation; + + call_work_unlock(ns); + + afb_event_push(ns->agent_event, jev); + + return; + } else if (!g_strcmp0(method_name, "AuthorizeService")) { + + /* g_variant_get(parameters, "(os)", &path, &service); + + jev = json_object_new_object(); + json_object_object_add(jev, "action", json_object_new_string("authorize_service")); + json_object_object_add(jev, "path", json_object_new_string(path)); + json_object_object_add(jev, "uuid", json_object_new_string(service)); + + afb_event_push(ns->agent_event, jev); */ + + return g_dbus_method_invocation_return_value(invocation, NULL); + } else if (!g_strcmp0(method_name, "Cancel")) { + + call_work_lock(ns); + + /* can only occur while a pair is issued */ + cw = call_work_lookup_unlocked(ns, "device", NULL, "RequestConfirmation"); + + if (!cw) { + call_work_unlock(ns); + g_dbus_method_invocation_return_dbus_error(invocation, + "org.bluez.Error.Rejected", + "No connection pending"); + return; + } + + jev = json_object_new_object(); + json_object_object_add(jev, "action", json_object_new_string("canceled_pairing")); + + afb_event_push(ns->agent_event, jev); + + call_work_destroy_unlocked(cw); + call_work_unlock(ns); + + return g_dbus_method_invocation_return_value(invocation, NULL); + } + + g_dbus_method_invocation_return_dbus_error(invocation, + "org.freedesktop.DBus.Error.UnknownMethod", + "Uknown method"); +} + +static const GDBusInterfaceVTable interface_vtable = { + .method_call = handle_method_call, + .get_property = NULL, + .set_property = NULL, +}; + +static void on_bus_acquired(GDBusConnection *connection, + const gchar *name, gpointer user_data) +{ + struct init_data *id = user_data; + struct bluetooth_state *ns = id->ns; + GVariant *result; + GError *error = NULL; + + AFB_INFO("agent bus acquired - registering %s", ns->agent_path); + + ns->registration_id = g_dbus_connection_register_object(connection, + ns->agent_path, + ns->introspection_data->interfaces[0], + &interface_vtable, + ns, /* user data */ + NULL, /* user_data_free_func */ + NULL); + + if (!ns->registration_id) { + AFB_ERROR("failed to register agent to dbus"); + goto err_unable_to_register_bus; + + } + + result = agentmanager_call(ns, "RegisterAgent", + g_variant_new("(os)", ns->agent_path, "KeyboardDisplay"), + &error); + if (!result) { + AFB_ERROR("failed to register agent to bluez"); + goto err_unable_to_register_bluez; + } + g_variant_unref(result); + + result = agentmanager_call(ns, "RequestDefaultAgent", + g_variant_new("(o)", ns->agent_path), + &error); + if (!result) { + AFB_ERROR("failed to request default agent to bluez"); + goto err_unable_to_request_default_agent_bluez; + } + g_variant_unref(result); + + ns->agent_registered = TRUE; + + AFB_INFO("agent registered at %s", ns->agent_path); + signal_init_done(id, 0); + + return; + +err_unable_to_request_default_agent_bluez: + agentmanager_call(ns, "UnregisterAgent", + g_variant_new("(o)", ns->agent_path), + &error); + +err_unable_to_register_bluez: + g_dbus_connection_unregister_object(ns->conn, ns->registration_id); + ns->registration_id = 0; + +err_unable_to_register_bus: + signal_init_done(id, -1); +} + +int bluetooth_register_agent(struct init_data *id) +{ + struct bluetooth_state *ns = id->ns; + + ns->agent_path = g_strdup_printf("%s/agent%d", + BLUEZ_PATH, getpid()); + if (!ns->agent_path) { + AFB_ERROR("can't create agent path"); + goto out_no_agent_path; + } + + ns->introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); + if (!ns->introspection_data) { + AFB_ERROR("can't create introspection data"); + goto out_no_introspection_data; + } + + ns->agent_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, BLUEZ_AGENT_INTERFACE, + G_BUS_NAME_OWNER_FLAGS_REPLACE | + G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT, + on_bus_acquired, + NULL, + NULL, + id, + NULL); + if (!ns->agent_id) { + AFB_ERROR("can't create agent bus instance"); + goto out_no_bus_name; + } + + return 0; + +out_no_bus_name: + g_dbus_node_info_unref(ns->introspection_data); +out_no_introspection_data: + g_free(ns->agent_path); +out_no_agent_path: + return -1; +} + +void bluetooth_unregister_agent(struct bluetooth_state *ns) +{ + g_bus_unown_name(ns->agent_id); + g_dbus_node_info_unref(ns->introspection_data); + g_free(ns->agent_path); +} diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c new file mode 100644 index 0000000..633bbd6 --- /dev/null +++ b/binding/bluetooth-api.c @@ -0,0 +1,1034 @@ +/* + * Copyright 2018 Konsulko Group + * Author: Matt Ranostay <matt.ranostay@konsulko.com> + * Author: Pantelis Antoniou <pantelis.antoniou@konsulko.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <pthread.h> +#include <semaphore.h> + +#include <glib.h> +#include <stdlib.h> +#include <gio/gio.h> +#include <glib-object.h> + +#include <json-c/json.h> + +#define AFB_BINDING_VERSION 3 +#include <afb/afb-binding.h> + +#include "bluetooth-api.h" +#include "bluetooth-common.h" + +/** + * The global thread + */ +static GThread *global_thread; + +static struct bluetooth_state *bluetooth_get_userdata(afb_req_t request) { + afb_api_t api = afb_req_get_api(request); + return afb_api_get_userdata(api); +} + +void call_work_lock(struct bluetooth_state *ns) +{ + g_mutex_lock(&ns->cw_mutex); +} + +void call_work_unlock(struct bluetooth_state *ns) +{ + g_mutex_unlock(&ns->cw_mutex); +} + +struct call_work *call_work_lookup_unlocked( + struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method) +{ + struct call_work *cw; + GSList *list; + + /* we can only allow a single pending call */ + for (list = ns->cw_pending; list; list = g_slist_next(list)) { + cw = list->data; + if (!g_strcmp0(access_type, cw->access_type) && + !g_strcmp0(type_arg, cw->type_arg) && + !g_strcmp0(method, cw->method)) + return cw; + } + return NULL; +} + +struct call_work *call_work_lookup( + struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method) +{ + struct call_work *cw; + + g_mutex_lock(&ns->cw_mutex); + cw = call_work_lookup_unlocked(ns, access_type, type_arg, method); + g_mutex_unlock(&ns->cw_mutex); + + return cw; +} + +int call_work_pending_id( + struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method) +{ + struct call_work *cw; + int id = -1; + + g_mutex_lock(&ns->cw_mutex); + cw = call_work_lookup_unlocked(ns, access_type, type_arg, method); + if (cw) + id = cw->id; + g_mutex_unlock(&ns->cw_mutex); + + return id; +} + +struct call_work *call_work_lookup_by_id_unlocked( + struct bluetooth_state *ns, int id) +{ + struct call_work *cw; + GSList *list; + + /* we can only allow a single pending call */ + for (list = ns->cw_pending; list; list = g_slist_next(list)) { + cw = list->data; + if (cw->id == id) + return cw; + } + return NULL; +} + +struct call_work *call_work_lookup_by_id( + struct bluetooth_state *ns, int id) +{ + struct call_work *cw; + + g_mutex_lock(&ns->cw_mutex); + cw = call_work_lookup_by_id_unlocked(ns, id); + g_mutex_unlock(&ns->cw_mutex); + + return cw; +} + +struct call_work *call_work_create_unlocked(struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method, const char *bluez_method, + GError **error) +{ + + struct call_work *cw = NULL; + + cw = call_work_lookup_unlocked(ns, access_type, type_arg, method); + if (cw) { + g_set_error(error, NB_ERROR, NB_ERROR_CALL_IN_PROGRESS, + "another call in progress (%s/%s/%s)", + access_type, type_arg, method); + return NULL; + } + + /* no other pending; allocate */ + cw = g_malloc0(sizeof(*cw)); + cw->ns = ns; + do { + cw->id = ns->next_cw_id; + if (++ns->next_cw_id < 0) + ns->next_cw_id = 1; + } while (call_work_lookup_by_id_unlocked(ns, cw->id)); + + cw->access_type = g_strdup(access_type); + cw->type_arg = g_strdup(type_arg); + cw->method = g_strdup(method); + cw->bluez_method = g_strdup(bluez_method); + + ns->cw_pending = g_slist_prepend(ns->cw_pending, cw); + + return cw; +} + +struct call_work *call_work_create(struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method, const char *bluez_method, + GError **error) +{ + + struct call_work *cw; + + g_mutex_lock(&ns->cw_mutex); + cw = call_work_create_unlocked(ns, + access_type, type_arg, method, bluez_method, + error); + g_mutex_unlock(&ns->cw_mutex); + + return cw; +} + +void call_work_destroy_unlocked(struct call_work *cw) +{ + struct bluetooth_state *ns = cw->ns; + struct call_work *cw2; + + /* verify that it's something we know about */ + cw2 = call_work_lookup_by_id_unlocked(ns, cw->id); + if (cw2 != cw) { + AFB_ERROR("Bad call work to destroy"); + return; + } + + /* remove it */ + ns->cw_pending = g_slist_remove(ns->cw_pending, cw); + + /* agent struct data */ + g_free(cw->agent_data.device_path); + + g_free(cw->access_type); + g_free(cw->type_arg); + g_free(cw->method); + g_free(cw->bluez_method); +} + +void call_work_destroy(struct call_work *cw) +{ + struct bluetooth_state *ns = cw->ns; + + g_mutex_lock(&ns->cw_mutex); + call_work_destroy_unlocked(cw); + g_mutex_unlock(&ns->cw_mutex); +} + +static afb_event_t get_event_from_value(struct bluetooth_state *ns, + const char *value) +{ + if (!g_strcmp0(value, "device_changes")) + return ns->device_changes_event; + + if (!g_strcmp0(value, "agent")) + return ns->agent_event; + + return NULL; +} + +static void bluez_devices_signal_callback( + GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + struct bluetooth_state *ns = user_data; + GVariantIter *array1 = NULL; + GError *error = NULL; + GVariant *var = NULL; + const gchar *path = NULL; + const gchar *key = NULL; + json_object *jresp = NULL, *jobj; + GVariantIter *array; + gboolean is_config, ret; + + /* AFB_INFO("sender=%s", sender_name); + AFB_INFO("object_path=%s", object_path); + AFB_INFO("interface=%s", interface_name); + AFB_INFO("signal=%s", signal_name); */ + + if (!g_strcmp0(signal_name, "InterfacesAdded")) { + + g_variant_get(parameters, "(&oa{sa{sv}})", &path, &array); + + jresp = json_object_new_object(); + + json_object_object_add(jresp, "device", + json_object_new_string(path)); + json_object_object_add(jresp, "action", + json_object_new_string("added")); + + jobj = json_object_new_object(); + + while (g_variant_iter_next(array, "{&s@a{sv}}", &key, &var)) { + const char *name = NULL; + GVariant *val = NULL; + + if (g_strcmp0(key, BLUEZ_DEVICE_INTERFACE) != 0) + continue; + + array1 = g_variant_iter_new(var); + + while (g_variant_iter_next(array1, "{&sv}", &name, &val)) { + ret = device_property_dbus2json(jobj, + name, val, &is_config, &error); + g_variant_unref(val); + if (!ret) { + AFB_WARNING("%s property %s - %s", + "devices", + key, error->message); + g_clear_error(&error); + } + } + g_variant_iter_free(array1); + } + g_variant_iter_free(array); + + if (array1) { + json_object_object_add(jresp, "properties", jobj); + } else { + json_object_put(jresp); + jresp = NULL; + } + + } else if (!g_strcmp0(signal_name, "InterfacesRemoved")) { + + g_variant_get(parameters, "(&oas)", &path, &array); + g_variant_iter_free(array); + + jresp = json_object_new_object(); + + json_object_object_add(jresp, "path", + json_object_new_string(path)); + json_object_object_add(jresp, "action", + json_object_new_string("removed")); + + } else if (!g_strcmp0(signal_name, "PropertiesChanged")) { + + g_variant_get(parameters, "(&sa{sv}as)", &path, &array, &array1); + + if (!g_strcmp0(path, BLUEZ_DEVICE_INTERFACE)) { + + jresp = json_object_new_object(); + + json_object_object_add(jresp, "path", + json_object_new_string(object_path)); + json_object_object_add(jresp, "action", + json_object_new_string("changed")); + + jobj = json_object_new_object(); + + while (g_variant_iter_next(array, "{&sv}", &key, &var)) { + ret = device_property_dbus2json(jobj, + key, var, &is_config, &error); + g_variant_unref(var); + if (!ret) { + AFB_WARNING("%s property %s - %s", + "devices", + key, error->message); + g_clear_error(&error); + } + } + + json_object_object_add(jresp, "properties", jobj); + } + + g_variant_iter_free(array); + g_variant_iter_free(array1); + } + + if (jresp) { + afb_event_push(ns->device_changes_event, jresp); + jresp = NULL; + } + + json_object_put(jresp); +} + +static struct bluetooth_state *bluetooth_init(GMainLoop *loop) +{ + struct bluetooth_state *ns; + GError *error = NULL; + + ns = g_try_malloc0(sizeof(*ns)); + if (!ns) { + AFB_ERROR("out of memory allocating bluetooth state"); + goto err_no_ns; + } + + AFB_INFO("connecting to dbus"); + + ns->loop = loop; + ns->conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!ns->conn) { + if (error) + g_dbus_error_strip_remote_error(error); + AFB_ERROR("Cannot connect to D-Bus, %s", + error ? error->message : "unspecified"); + g_error_free(error); + goto err_no_conn; + + } + + AFB_INFO("connected to dbus"); + + ns->device_changes_event = + afb_daemon_make_event("device_changes"); + ns->agent_event = + afb_daemon_make_event("agent"); + + if (!afb_event_is_valid(ns->device_changes_event) || + !afb_event_is_valid(ns->agent_event)) { + AFB_ERROR("Cannot create events"); + goto err_no_events; + } + + ns->device_sub = g_dbus_connection_signal_subscribe( + ns->conn, + BLUEZ_SERVICE, + NULL, /* interface */ + NULL, /* member */ + NULL, /* object path */ + NULL, /* arg0 */ + G_DBUS_SIGNAL_FLAGS_NONE, + bluez_devices_signal_callback, + ns, + NULL); + if (!ns->device_sub) { + AFB_ERROR("Unable to subscribe to interface signals"); + goto err_no_device_sub; + } + + g_mutex_init(&ns->cw_mutex); + ns->next_cw_id = 1; + + bluetooth_monitor_init(); + + return ns; + +err_no_device_sub: + /* no way to clear the events */ +err_no_events: + g_dbus_connection_close(ns->conn, NULL, NULL, NULL); +err_no_conn: + g_free(ns); +err_no_ns: + return NULL; +} + +static void bluetooth_cleanup(struct bluetooth_state *ns) +{ + g_dbus_connection_signal_unsubscribe(ns->conn, ns->device_sub); + g_dbus_connection_close(ns->conn, NULL, NULL, NULL); + g_free(ns); +} + +static gpointer bluetooth_func(gpointer ptr) +{ + struct init_data *id = ptr; + struct bluetooth_state *ns; + GMainLoop *loop; + int rc = 0; + + loop = g_main_loop_new(NULL, FALSE); + if (!loop) { + AFB_ERROR("Unable to create main loop"); + goto err_no_loop; + } + + /* real bluetooth init */ + ns = bluetooth_init(loop); + if (!ns) { + AFB_ERROR("bluetooth_init() failed"); + goto err_no_ns; + } + + id->ns = ns; + rc = bluetooth_register_agent(id); + if (rc) { + AFB_ERROR("bluetooth_register_agent() failed"); + goto err_no_agent; + } + + /* note that we wait for agent registration to signal done */ + + afb_api_set_userdata(id->api, ns); + g_main_loop_run(loop); + + g_main_loop_unref(ns->loop); + + bluetooth_unregister_agent(ns); + + bluetooth_cleanup(ns); + afb_api_set_userdata(id->api, NULL); + + return NULL; + +err_no_agent: + bluetooth_cleanup(ns); + +err_no_ns: + g_main_loop_unref(loop); + +err_no_loop: + signal_init_done(id, -1); + + return NULL; +} + +static int init(afb_api_t api) +{ + struct init_data init_data, *id = &init_data; + gint64 end_time; + + memset(id, 0, sizeof(*id)); + id->init_done = FALSE; + id->rc = 0; + id->api = api; + g_cond_init(&id->cond); + g_mutex_init(&id->mutex); + + global_thread = g_thread_new("agl-service-bluetooth", + bluetooth_func, + id); + + AFB_INFO("bluetooth-binding waiting for init done"); + + /* wait maximum 10 seconds for init done */ + end_time = g_get_monotonic_time () + 10 * G_TIME_SPAN_SECOND; + g_mutex_lock(&id->mutex); + while (!id->init_done) { + if (!g_cond_wait_until(&id->cond, &id->mutex, end_time)) + break; + } + g_mutex_unlock(&id->mutex); + + if (!id->init_done) { + AFB_ERROR("bluetooth-binding init timeout"); + return -1; + } + + if (id->rc) + AFB_ERROR("bluetooth-binding init thread returned %d", + id->rc); + else + AFB_INFO("bluetooth-binding operational"); + + return id->rc; +} + +static void bluetooth_subscribe_unsubscribe(afb_req_t request, + gboolean unsub) +{ + struct bluetooth_state *ns = bluetooth_get_userdata(request); + json_object *jresp = json_object_new_object(); + const char *value; + afb_event_t event; + int rc; + + /* if value exists means to set offline mode */ + value = afb_req_value(request, "value"); + if (!value) { + afb_req_fail_f(request, "failed", "Missing \"value\" event"); + return; + } + + event = get_event_from_value(ns, value); + if (!event) { + afb_req_fail_f(request, "failed", "Bad \"value\" event \"%s\"", + value); + return; + } + + if (!unsub) + rc = afb_req_subscribe(request, event); + else + rc = afb_req_unsubscribe(request, event); + if (rc != 0) { + afb_req_fail_f(request, "failed", + "%s error on \"value\" event \"%s\"", + !unsub ? "subscribe" : "unsubscribe", + value); + return; + } + + afb_req_success_f(request, jresp, "Bluetooth %s to event \"%s\"", + !unsub ? "subscribed" : "unsubscribed", + value); +} + +static void bluetooth_subscribe(afb_req_t request) +{ + bluetooth_subscribe_unsubscribe(request, FALSE); +} + +static void bluetooth_unsubscribe(afb_req_t request) +{ + bluetooth_subscribe_unsubscribe(request, TRUE); +} + +static void bluetooth_list(afb_req_t request) +{ + struct bluetooth_state *ns = bluetooth_get_userdata(request); + GError *error = NULL; + json_object *jresp; + + jresp = object_properties(ns, &error); + + afb_req_success(request, jresp, "Bluetooth - managed objects"); +} + +static void bluetooth_state(afb_req_t request) +{ + struct bluetooth_state *ns = bluetooth_get_userdata(request); + GError *error = NULL; + json_object *jresp; + const char *adapter; + + adapter = afb_req_value(request, "adapter"); + if (!adapter) { + afb_req_fail(request, "failed", "No adapter give to return state"); + return; + } + + jresp = adapter_properties(ns, &error, adapter); + if (!jresp) { + afb_req_fail_f(request, "failed", "property %s error %s", + "State", error->message); + return; + } + + afb_req_success(request, jresp, "Bluetooth - adapter state"); +} + +static void bluetooth_adapter(afb_req_t request) +{ + struct bluetooth_state *ns = bluetooth_get_userdata(request); + GError *error = NULL; + const char *adapter, *scan, *discoverable, *powered; + + adapter = afb_req_value(request, "adapter"); + if (!adapter) { + afb_req_fail(request, "failed", "No adapter given to configure"); + return; + } + + scan = afb_req_value(request, "discovery"); + if (scan) { + GVariant *reply = adapter_call(ns, adapter, str2boolean(scan) ? + "StartDiscovery" : "StopDiscovery", NULL, &error); + + if (!reply) { + afb_req_fail_f(request, "failed", + "adapter %s method %s error %s", + scan, "Scan", error->message); + g_error_free(error); + return; + } + g_variant_unref(reply); + } + + discoverable = afb_req_value(request, "discoverable"); + if (discoverable) { + int ret = adapter_set_property(ns, adapter, FALSE, "Discoverable", + json_object_new_boolean(str2boolean(discoverable)), + &error); + if (!ret) { + afb_req_fail_f(request, "failed", + "adapter %s set_property %s error %s", + adapter, "Discoverable", error->message); + g_error_free(error); + return; + } + } + + powered = afb_req_value(request, "powered"); + if (powered) { + int ret = adapter_set_property(ns, adapter, FALSE, "Powered", + json_object_new_boolean(str2boolean(powered)), + &error); + if (!ret) { + afb_req_fail_f(request, "failed", + "adapter %s set_property %s error %s", + adapter, "Powered", error->message); + g_error_free(error); + return; + } + } + + bluetooth_state(request); +} + +static void connect_service_callback(void *user_data, + GVariant *result, GError **error) +{ + struct call_work *cw = user_data; + struct bluetooth_state *ns = cw->ns; + + bluez_decode_call_error(ns, + cw->access_type, cw->type_arg, cw->bluez_method, + error); + + if (error && *error) { + afb_req_fail_f(cw->request, "failed", "Connect error: %s", + (*error)->message); + goto out_free; + } + + if (result) + g_variant_unref(result); + + afb_req_success_f(cw->request, NULL, "Bluetooth - device %s connected", + cw->type_arg); +out_free: + afb_req_unref(cw->request); + call_work_destroy(cw); +} + +static void bluetooth_connect_device(afb_req_t request) +{ + struct bluetooth_state *ns = bluetooth_get_userdata(request); + GError *error = NULL; + const char *device, *uuid; + struct call_work *cw; + + /* first device */ + device = afb_req_value(request, "device"); + if (!device) { + afb_req_fail(request, "failed", "No path given"); + return; + } + + /* optional, connect single profile */ + uuid = afb_req_value(request, "uuid"); + + cw = call_work_create(ns, "device", device, + "connect_service", "Connect", &error); + if (!cw) { + afb_req_fail_f(request, "failed", "can't queue work %s", + error->message); + g_error_free(error); + return; + } + + cw->request = request; + afb_req_addref(request); + + if (uuid) + cw->cpw = bluez_call_async(ns, "device", device, + "ConnectProfile", g_variant_new("(&s)", uuid), &error, + connect_service_callback, cw); + else + cw->cpw = bluez_call_async(ns, "device", device, + "Connect", NULL, &error, + connect_service_callback, cw); + + if (!cw->cpw) { + afb_req_fail_f(request, "failed", "connection error %s", + error->message); + call_work_destroy(cw); + g_error_free(error); + return; + } +} + +static void bluetooth_disconnect_device(afb_req_t request) +{ + struct bluetooth_state *ns = bluetooth_get_userdata(request); + json_object *jresp; + GVariant *reply = NULL; + GError *error = NULL; + const char *device, *uuid; + + /* first device */ + device = afb_req_value(request, "device"); + if (!device) { + afb_req_fail(request, "failed", "No device given to disconnect"); + return; + } + + /* optional, disconnect single profile */ + uuid = afb_req_value(request, "uuid"); + + if (uuid) + reply = device_call(ns, device, "DisconnectProfile", + g_variant_new("(&s)", uuid), &error); + else + reply = device_call(ns, device, "Disconnect", NULL, &error); + + if (!reply) { + afb_req_fail_f(request, "failed", "Disconnect error %s", + error ? error->message : "unspecified"); + g_error_free(error); + return; + } + + g_variant_unref(reply); + + jresp = json_object_new_object(); + afb_req_success_f(request, jresp, "Device - Bluetooth %s disconnected", + device); +} + +static void pair_service_callback(void *user_data, + GVariant *result, GError **error) +{ + struct call_work *cw = user_data; + struct bluetooth_state *ns = cw->ns; + + bluez_decode_call_error(ns, + cw->access_type, cw->type_arg, cw->bluez_method, + error); + + if (error && *error) { + afb_req_fail_f(cw->request, "failed", "Connect error: %s", + (*error)->message); + goto out_free; + } + + if (result) + g_variant_unref(result); + + afb_req_success_f(cw->request, NULL, "Bluetooth - device %s paired", + cw->type_arg); +out_free: + afb_req_unref(cw->request); + call_work_destroy(cw); +} + +static void bluetooth_pair_device(afb_req_t request) +{ + struct bluetooth_state *ns = bluetooth_get_userdata(request); + GError *error = NULL; + const char *device; + struct call_work *cw; + + /* first device */ + device = afb_req_value(request, "device"); + if (!device) { + afb_req_fail(request, "failed", "No path given"); + return; + } + + cw = call_work_create(ns, "device", device, + "pair_device", "Pair", &error); + if (!cw) { + afb_req_fail_f(request, "failed", "can't queue work %s", + error->message); + g_error_free(error); + return; + } + + cw->request = request; + afb_req_addref(request); + + cw->cpw = bluez_call_async(ns, "device", device, "Pair", NULL, &error, + pair_service_callback, cw); + + if (!cw->cpw) { + afb_req_fail_f(request, "failed", "connection error %s", + error->message); + call_work_destroy(cw); + g_error_free(error); + return; + } +} + +static void bluetooth_cancel_pairing(afb_req_t request) +{ + struct bluetooth_state *ns = bluetooth_get_userdata(request); + struct call_work *cw; + GVariant *reply = NULL; + GError *error = NULL; + gchar *device; + + call_work_lock(ns); + + cw = call_work_lookup_unlocked(ns, "device", NULL, "RequestConfirmation"); + + if (!cw) { + call_work_unlock(ns); + afb_req_fail(request, "failed", "No pairing in progress"); + return; + } + + device = cw->agent_data.device_path; + reply = device_call(ns, device, "CancelPairing", NULL, &error); + + if (!reply) { + call_work_unlock(ns); + afb_req_fail_f(request, "failed", + "device %s method %s error %s", + device, "CancelPairing", error->message); + return; + } + + call_work_unlock(ns); + + afb_req_success(request, json_object_new_object(), + "Bluetooth - pairing canceled"); +} + +static void bluetooth_confirm_pairing(afb_req_t request) +{ + struct bluetooth_state *ns = bluetooth_get_userdata(request); + struct call_work *cw; + int pin = -1; + + const char *value = afb_req_value(request, "pincode"); + + if (value) + pin = (int)strtol(value, NULL, 10); + + if (!value || !pin) { + afb_req_fail_f(request, "failed", "No pincode parameter"); + return; + } + + call_work_lock(ns); + + cw = call_work_lookup_unlocked(ns, "device", NULL, "RequestConfirmation"); + + if (!cw) { + call_work_unlock(ns); + afb_req_fail(request, "failed", "No pairing in progress"); + return; + } + + if (pin == cw->agent_data.pin_code) { + g_dbus_method_invocation_return_value(cw->invocation, NULL); + + afb_req_success(request, json_object_new_object(), + "Bluetooth - pairing confimed"); + } else { + g_dbus_method_invocation_return_dbus_error(cw->invocation, + "org.bluez.Error.Rejected", + "No connection pending"); + + afb_req_fail(request, "failed", "Bluetooth - pairing failed"); + } + + call_work_destroy_unlocked(cw); + call_work_unlock(ns); +} + +static void bluetooth_remove_device(afb_req_t request) +{ + struct bluetooth_state *ns = bluetooth_get_userdata(request); + GError *error = NULL; + GVariant *reply; + json_object *jval = NULL; + const char *device, *adapter; + + /* first device */ + device = afb_req_value(request, "device"); + if (!device) { + afb_req_fail(request, "failed", "No path given"); + return; + } + + jval = bluez_get_property(ns, "device", device, FALSE, "Adapter", &error); + + if (!jval) { + afb_req_fail_f(request, "failed", + " adapter not found for device %s error %s", + device, error->message); + + g_error_free(error); + return; + } + + adapter = json_object_get_string(jval); + + reply = adapter_call(ns, adapter, "RemoveDevice", + g_variant_new("(o)", device), &error); + + if (!reply) { + afb_req_fail_f(request, "failed", + " device %s method %s error %s", + device, "RemoveDevice", error->message); + g_error_free(error); + json_object_put(jval); + return; + } + g_variant_unref(reply); + + afb_req_success_f(request, json_object_new_object(), + "Bluetooth - device %s removed", adapter); + + json_object_put(jval); +} + +static const struct afb_verb_v3 bluetooth_verbs[] = { + { + .verb = "subscribe", + .session = AFB_SESSION_NONE, + .callback = bluetooth_subscribe, + .info = "Subscribe to the event of 'value'", + }, { + .verb = "unsubscribe", + .session = AFB_SESSION_NONE, + .callback = bluetooth_unsubscribe, + .info = "Unsubscribe to the event of 'value'", + }, { + .verb = "managed_objects", + .session = AFB_SESSION_NONE, + .callback = bluetooth_list, + .info = "Retrieve managed bluetooth devices" + }, { + .verb = "adapter_state", + .session = AFB_SESSION_NONE, + .callback = bluetooth_adapter, + .info = "Set adapter mode and retrieve properties" + }, { + .verb = "connect", + .session = AFB_SESSION_NONE, + .callback = bluetooth_connect_device, + .info = "Connect device and/or profile" + }, { + .verb = "disconnect", + .session = AFB_SESSION_NONE, + .callback = bluetooth_disconnect_device, + .info = "Disconnect device and/or profile" + }, { + .verb = "pair", + .session = AFB_SESSION_NONE, + .callback = bluetooth_pair_device, + .info = "Pair device" + }, { + .verb = "cancel_pairing", + .session = AFB_SESSION_NONE, + .callback = bluetooth_cancel_pairing, + .info = "Cancel pairing" + }, { + .verb = "confirm_pairing", + .session = AFB_SESSION_NONE, + .callback = bluetooth_confirm_pairing, + .info = "Confirm pairing", + }, { + .verb = "remove_device", + .session = AFB_SESSION_NONE, + .callback = bluetooth_remove_device, + .info = "Removed paired device", + }, + { } /* marker for end of the array */ +}; + +/* + * description of the binding for afb-daemon + */ +const struct afb_binding_v3 afbBindingV3 = { + .api = "bluetooth-manager", + .specification = "bluetooth manager API", + .verbs = bluetooth_verbs, + .init = init, +}; diff --git a/binding/bluetooth-api.h b/binding/bluetooth-api.h new file mode 100644 index 0000000..50bf501 --- /dev/null +++ b/binding/bluetooth-api.h @@ -0,0 +1,200 @@ +/* + * Copyright 2018 Konsulko Group + * Author: Matt Ranostay <matt.ranostay@konsulko.com> + * Author: Pantelis Antoniou <pantelis.antoniou@konsulko.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BLUETOOTH_API_H +#define BLUETOOTH_API_H + +#include <alloca.h> +#include <stdio.h> +#include <stddef.h> +#include <string.h> + +#include <glib.h> + +#include <json-c/json.h> + +#define BLUEZ_SERVICE "org.bluez" +#define BLUEZ_ADAPTER_INTERFACE BLUEZ_SERVICE ".Adapter1" +#define BLUEZ_AGENT_INTERFACE BLUEZ_SERVICE ".Agent1" +#define BLUEZ_AGENTMANAGER_INTERFACE BLUEZ_SERVICE ".AgentManager1" +#define BLUEZ_DEVICE_INTERFACE BLUEZ_SERVICE ".Device1" + +#define BLUEZ_OBJECT_PATH "/" +#define BLUEZ_PATH "/org/bluez" + +#define FREEDESKTOP_INTROSPECT "org.freedesktop.DBus.Introspectable" +#define FREEDESKTOP_PROPERTIES "org.freedesktop.DBus.Properties" +#define FREEDESKTOP_OBJECTMANAGER "org.freedesktop.DBus.ObjectManager" + +#define DBUS_REPLY_TIMEOUT (120 * 1000) +#define DBUS_REPLY_TIMEOUT_SHORT (10 * 1000) + +#define BLUEZ_AT_OBJECT "object" +#define BLUEZ_AT_ADAPTER "adapter" +#define BLUEZ_AT_DEVICE "device" +#define BLUEZ_AT_AGENT "agent" +#define BLUEZ_AT_AGENTMANAGER "agent-manager" + +struct bluetooth_state; + +static inline const char *bluez_strip_path(const char *path) +{ + const char *basename; + + basename = strrchr(path, '/'); + if (!basename) + return NULL; + basename++; + /* at least one character */ + return *basename ? basename : NULL; +} + + +struct call_work *call_work_create_unlocked(struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method, const char *bluez_method, + GError **error); + +void call_work_destroy_unlocked(struct call_work *cw); + +void call_work_lock(struct bluetooth_state *ns); + +void call_work_unlock(struct bluetooth_state *ns); + +struct call_work *call_work_lookup_unlocked( + struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method); + +const struct property_info *bluez_get_property_info( + const char *access_type, GError **error); + +gboolean bluez_property_dbus2json(const char *access_type, + json_object *jprop, const gchar *key, GVariant *var, + gboolean *is_config, + GError **error); + +GVariant *bluez_call(struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method, GVariant *params, GError **error); + +json_object *bluez_get_properties(struct bluetooth_state *ns, + const char *access_type, const char *path, + GError **error); + +json_object *bluez_get_property(struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + gboolean is_json_name, const char *name, GError **error); + +gboolean bluez_set_property(struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + gboolean is_json_name, const char *name, json_object *jval, + GError **error); + +/* convenience access methods */ +static inline gboolean device_property_dbus2json(json_object *jprop, + const gchar *key, GVariant *var, gboolean *is_config, + GError **error) +{ + return bluez_property_dbus2json(BLUEZ_AT_DEVICE, + jprop, key, var, is_config, error); +} + +static inline gboolean agent_property_dbus2json(json_object *jprop, + const gchar *key, GVariant *var, gboolean *is_config, + GError **error) +{ + return bluez_property_dbus2json(BLUEZ_AT_AGENT, + jprop, key, var, is_config, error); +} + +static inline GVariant *device_call(struct bluetooth_state *ns, + const char *device, const char *method, + GVariant *params, GError **error) +{ + return bluez_call(ns, BLUEZ_AT_DEVICE, device, + method, params, error); +} + +static inline GVariant *adapter_call(struct bluetooth_state *ns, + const char *adapter, const char *method, + GVariant *params, GError **error) +{ + return bluez_call(ns, BLUEZ_AT_ADAPTER, adapter, + method, params, error); +} + +static inline GVariant *agentmanager_call(struct bluetooth_state *ns, + const char *method, GVariant *params, GError **error) +{ + return bluez_call(ns, BLUEZ_AT_AGENTMANAGER, NULL, + method, params, error); +} + +static inline gboolean adapter_set_property(struct bluetooth_state *ns, + const char *adapter, gboolean is_json_name, const char *name, + json_object *jval, GError **error) +{ + return bluez_set_property(ns, BLUEZ_AT_ADAPTER, adapter, + is_json_name, name, jval, error); +} + +static inline json_object *adapter_get_property(struct bluetooth_state *ns, + gboolean is_json_name, const char *name, GError **error) +{ + return bluez_get_property(ns, BLUEZ_AT_ADAPTER, NULL, + is_json_name, name, error); +} + +static inline json_object *adapter_properties(struct bluetooth_state *ns, + GError **error, const gchar *adapter) +{ + return bluez_get_properties(ns, + BLUEZ_AT_ADAPTER, adapter, error); +} + +static inline json_object *object_properties(struct bluetooth_state *ns, + GError **error) +{ + return bluez_get_properties(ns, + BLUEZ_AT_OBJECT, BLUEZ_OBJECT_PATH, error); +} + +struct bluez_pending_work { + struct bluetooth_state *ns; + void *user_data; + GCancellable *cancel; + void (*callback)(void *user_data, GVariant *result, GError **error); +}; + +void bluez_cancel_call(struct bluetooth_state *ns, + struct bluez_pending_work *cpw); + +struct bluez_pending_work * +bluez_call_async(struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method, GVariant *params, GError **error, + void (*callback)(void *user_data, GVariant *result, GError **error), + void *user_data); + +void bluez_decode_call_error(struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method, + GError **error); + +#endif /* BLUETOOTH_API_H */ diff --git a/binding/bluetooth-bluez.c b/binding/bluetooth-bluez.c new file mode 100644 index 0000000..990a244 --- /dev/null +++ b/binding/bluetooth-bluez.c @@ -0,0 +1,513 @@ +/* + * Copyright 2018 Konsulko Group + * Author: Pantelis Antoniou <pantelis.antoniou@konsulko.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <pthread.h> +#include <semaphore.h> + +#include <glib.h> +#include <stdlib.h> +#include <gio/gio.h> +#include <glib-object.h> + +#include <json-c/json.h> + +#define AFB_BINDING_VERSION 3 +#include <afb/afb-binding.h> + +#include "bluetooth-api.h" +#include "bluetooth-common.h" + +static const struct property_info adapter_props[] = { + { .name = "UUIDs", .fmt = "as", }, + { .name = "Discoverable", .fmt = "b", }, + { .name = "Discovering", .fmt = "b", }, + { .name = "Pairable", .fmt = "b", }, + { .name = "Powered", .fmt = "b", }, + { .name = "Address", .fmt = "s", }, + { .name = "AddressType", .fmt = "s", }, + { .name = "DiscoverableTimeout",.fmt = "u", }, + { .name = "PairableTimeout", .fmt = "u", }, + { }, +}; + +static const struct property_info device_props[] = { + { .name = "Address", .fmt = "s", }, + { .name = "AddressType", .fmt = "s", }, + { .name = "Name", .fmt = "s", }, + { .name = "Adapter", .fmt = "s", }, + { .name = "Alias", .fmt = "s", }, + { .name = "Class", .fmt = "u", }, + { .name = "Icon", .fmt = "s", }, + { .name = "Modalias", .fmt = "s", }, + { .name = "Paired", .fmt = "b", }, + { .name = "Trusted", .fmt = "b", }, + { .name = "Blocked", .fmt = "b", }, + { .name = "LegacyPairing", .fmt = "b", }, + { .name = "TxPower", .fmt = "n", }, + { .name = "RSSI", .fmt = "n", }, + { .name = "Connected", .fmt = "b", }, + { .name = "UUIDs", .fmt = "as", }, + { .name = "Adapter", .fmt = "s", }, + { .name = "ServicesResolved", .fmt = "b", }, + { }, +}; + +const struct property_info *bluez_get_property_info( + const char *access_type, GError **error) +{ + const struct property_info *pi = NULL; + + if (!strcmp(access_type, BLUEZ_AT_ADAPTER)) + pi = adapter_props; + else if (!strcmp(access_type, BLUEZ_AT_DEVICE)) + pi = device_props; + else + g_set_error(error, NB_ERROR, NB_ERROR_ILLEGAL_ARGUMENT, + "illegal %s argument", access_type); + return pi; +} + +gboolean bluez_property_dbus2json(const char *access_type, + json_object *jprop, const gchar *key, GVariant *var, + gboolean *is_config, + GError **error) +{ + const struct property_info *pi; + gboolean ret; + + *is_config = FALSE; + pi = bluez_get_property_info(access_type, error); + if (!pi) + return FALSE; + + ret = root_property_dbus2json(jprop, pi, key, var, is_config); + if (!ret) + g_set_error(error, NB_ERROR, NB_ERROR_UNKNOWN_PROPERTY, + "unknown %s property %s", + access_type, key); + + return ret; +} + + +void bluez_decode_call_error(struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method, + GError **error) +{ + if (!error || !*error) + return; + + if (strstr((*error)->message, + "org.freedesktop.DBus.Error.UnknownObject")) { + + if (!strcmp(method, "Set") || + !strcmp(method, "Get") || + !strcmp(method, "GetAll")) { + + g_clear_error(error); + g_set_error(error, NB_ERROR, + NB_ERROR_UNKNOWN_PROPERTY, + "unknown %s property on %s", + access_type, type_arg); + + } else if (!strcmp(method, "Connect") || + !strcmp(method, "ConnectProfile") || + !strcmp(method, "Disconnect") || + !strcmp(method, "DisconnectProfile") || + !strcmp(method, "Pair") || + !strcmp(method, "Unpair") || + !strcmp(method, "RemoveDevice")) { + + g_clear_error(error); + g_set_error(error, NB_ERROR, + NB_ERROR_UNKNOWN_SERVICE, + "unknown service %s", + type_arg); + + } else if (!strcmp(method, "StartDiscovery") || + !strcmp(method, "StopDiscovery") || + !strcmp(method, "RegisterAgent")) { + + g_clear_error(error); + g_set_error(error, NB_ERROR, + NB_ERROR_UNKNOWN_SERVICE, + "unknown service %s", + type_arg); + } + } +} + +GVariant *bluez_call(struct bluetooth_state *ns, + const char *access_type, const char *path, + const char *method, GVariant *params, GError **error) +{ + const char *interface; + GVariant *reply; + + if (!path && (!strcmp(access_type, BLUEZ_AT_DEVICE) || + !strcmp(access_type, BLUEZ_AT_ADAPTER))) { + g_set_error(error, NB_ERROR, NB_ERROR_MISSING_ARGUMENT, + "missing %s argument", + access_type); + return NULL; + } + + if (!strcmp(access_type, BLUEZ_AT_DEVICE)) { + interface = BLUEZ_DEVICE_INTERFACE; + } else if (!strcmp(access_type, BLUEZ_AT_ADAPTER)) { + interface = BLUEZ_ADAPTER_INTERFACE; + } else if (!strcmp(access_type, BLUEZ_AT_AGENTMANAGER)) { + path = BLUEZ_PATH; + interface = BLUEZ_AGENTMANAGER_INTERFACE; + } else { + g_set_error(error, NB_ERROR, NB_ERROR_ILLEGAL_ARGUMENT, + "illegal %s argument", + access_type); + return NULL; + } + + reply = g_dbus_connection_call_sync(ns->conn, + BLUEZ_SERVICE, path, interface, method, params, + NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, + NULL, error); + bluez_decode_call_error(ns, access_type, path, method, + error); + if (!reply) { + if (error && *error) + g_dbus_error_strip_remote_error(*error); + AFB_ERROR("Error calling %s%s%s %s method %s", + access_type, + path ? "/" : "", + path ? path : "", + method, + error && *error ? (*error)->message : + "unspecified"); + } + + return reply; +} + +static void bluez_call_async_ready(GObject *source_object, + GAsyncResult *res, gpointer user_data) +{ + struct bluez_pending_work *cpw = user_data; + struct bluetooth_state *ns = cpw->ns; + GVariant *result; + GError *error = NULL; + + result = g_dbus_connection_call_finish(ns->conn, res, &error); + + cpw->callback(cpw->user_data, result, &error); + + g_clear_error(&error); + g_cancellable_reset(cpw->cancel); + g_free(cpw); +} + +void bluez_cancel_call(struct bluetooth_state *ns, + struct bluez_pending_work *cpw) +{ + g_cancellable_cancel(cpw->cancel); +} + +struct bluez_pending_work * +bluez_call_async(struct bluetooth_state *ns, + const char *access_type, const char *type_arg, + const char *method, GVariant *params, GError **error, + void (*callback)(void *user_data, GVariant *result, GError **error), + void *user_data) +{ + const char *path; + const char *interface; + struct bluez_pending_work *cpw; + + if (!type_arg && (!strcmp(access_type, BLUEZ_AT_DEVICE) || + !strcmp(access_type, BLUEZ_AT_ADAPTER))) { + g_set_error(error, NB_ERROR, NB_ERROR_MISSING_ARGUMENT, + "missing %s argument", + access_type); + return NULL; + } + + if (!strcmp(access_type, BLUEZ_AT_DEVICE)) { + path = type_arg; + interface = BLUEZ_DEVICE_INTERFACE; + } else if (!strcmp(access_type, BLUEZ_AT_ADAPTER)) { + path = type_arg; + interface = BLUEZ_ADAPTER_INTERFACE; + } else { + g_set_error(error, NB_ERROR, NB_ERROR_ILLEGAL_ARGUMENT, + "illegal %s argument", + access_type); + return NULL; + } + + cpw = g_malloc(sizeof(*cpw)); + if (!cpw) { + g_set_error(error, NB_ERROR, NB_ERROR_OUT_OF_MEMORY, + "out of memory"); + return NULL; + } + cpw->ns = ns; + cpw->user_data = user_data; + cpw->cancel = g_cancellable_new(); + if (!cpw->cancel) { + g_free(cpw); + g_set_error(error, NB_ERROR, NB_ERROR_OUT_OF_MEMORY, + "out of memory"); + return NULL; + } + cpw->callback = callback; + + g_dbus_connection_call(ns->conn, + BLUEZ_SERVICE, path, interface, method, params, + NULL, /* reply type */ + G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, + cpw->cancel, /* cancellable? */ + bluez_call_async_ready, + cpw); + + return cpw; +} + +json_object *bluez_get_properties(struct bluetooth_state *ns, + const char *access_type, const char *path, + GError **error) +{ + const struct property_info *pi = NULL; + const char *method = NULL; + GVariant *reply = NULL; + GVariantIter *array, *array2, *array3; + GVariant *var = NULL; + const char *interface, *interface2, *path2 = NULL; + const gchar *key = NULL; + json_object *jarray = NULL, *jarray2 = NULL; + json_object *jprop = NULL, *jresp = NULL, *jtype = NULL; + gboolean is_config; + + if (!strcmp(access_type, BLUEZ_AT_DEVICE) || + !strcmp(access_type, BLUEZ_AT_ADAPTER)) { + + pi = bluez_get_property_info(access_type, error); + if (!pi) + return NULL; + + interface = FREEDESKTOP_PROPERTIES; + method = "GetAll"; + } else if (!strcmp(access_type, BLUEZ_AT_OBJECT)) { + interface = FREEDESKTOP_OBJECTMANAGER; + method = "GetManagedObjects"; + } else { + return FALSE; + } + + if (!strcmp(access_type, BLUEZ_AT_DEVICE)) + interface2 = BLUEZ_DEVICE_INTERFACE; + else if (!strcmp(access_type, BLUEZ_AT_ADAPTER)) + interface2 = BLUEZ_ADAPTER_INTERFACE; + else if (!strcmp(access_type, BLUEZ_AT_OBJECT)) + interface2 = NULL; + else + return FALSE; + + if (!method) { + g_set_error(error, NB_ERROR, NB_ERROR_ILLEGAL_ARGUMENT, + "illegal %s argument", + access_type); + return NULL; + } + + reply = g_dbus_connection_call_sync(ns->conn, + BLUEZ_SERVICE, path, interface, method, + interface2 ? g_variant_new("(s)", interface2) : NULL, + NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, + NULL, error); + + if (!reply) + return NULL; + + if (!strcmp(access_type, BLUEZ_AT_DEVICE) || + !strcmp(access_type, BLUEZ_AT_ADAPTER)) { + jprop = json_object_new_object(); + g_variant_get(reply, "(a{sv})", &array); + while (g_variant_iter_loop(array, "{sv}", &key, &var)) { + root_property_dbus2json(jprop, pi, + key, var, &is_config); + } + g_variant_iter_free(array); + g_variant_unref(reply); + jresp = jprop; + } else if (!strcmp(access_type, BLUEZ_AT_OBJECT)) { + + jarray = json_object_new_array(); + jarray2 = json_object_new_array(); + + jresp = json_object_new_object(); + json_object_object_add(jresp, "adapters", jarray); + json_object_object_add(jresp, "devices", jarray2); + + g_variant_get(reply, "(a{oa{sa{sv}}})", &array); + while (g_variant_iter_loop(array, "{oa{sa{sv}}}", &path2, &array2)) { + + while (g_variant_iter_loop(array2, "{&sa{sv}}", &interface, &array3)) { + json_object *array = NULL; + + if (!strcmp(interface, BLUEZ_ADAPTER_INTERFACE)) { + access_type = BLUEZ_AT_ADAPTER; + array = jarray; + } else if (!strcmp(interface, BLUEZ_DEVICE_INTERFACE)) { + access_type = BLUEZ_AT_DEVICE; + array = jarray2; + } else { + continue; /* TODO: Maybe display other interfaces */ + } + + pi = bluez_get_property_info(access_type, error); + jtype = json_object_new_object(); + + json_object_object_add(jtype, "path", + json_object_new_string(path2)); + + while (g_variant_iter_loop(array3, "{sv}", &key, &var)) { + if (!jprop) + jprop = json_object_new_object(); + + root_property_dbus2json(jprop, pi, + key, var, &is_config); + } + + json_object_object_add(jtype, "properties", jprop); + json_object_array_add(array, jtype); + jprop = NULL; + } + + } + + g_variant_iter_free(array); + g_variant_unref(reply); + } + + if (!jresp) { + g_set_error(error, NB_ERROR, NB_ERROR_ILLEGAL_ARGUMENT, + "No %s", access_type); + } + + return jresp; +} + +json_object *bluez_get_property(struct bluetooth_state *ns, + const char *access_type, const char *path, + gboolean is_json_name, const char *name, GError **error) +{ + const struct property_info *pi; + json_object *jprop, *jval; + + pi = bluez_get_property_info(access_type, error); + if (!pi) + return NULL; + + jprop = bluez_get_properties(ns, access_type, path, error); + if (!jprop) + return NULL; + + jval = get_named_property(pi, is_json_name, name, jprop); + json_object_put(jprop); + + if (!jval) + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property %s on %s%s%s", name, + access_type, + path ? "/" : "", + path ? path : ""); + return jval; +} + +/* NOTE: jval is consumed */ +gboolean bluez_set_property(struct bluetooth_state *ns, + const char *access_type, const char *path, + gboolean is_json_name, const char *name, json_object *jval, + GError **error) +{ + const struct property_info *pi; + GVariant *reply, *arg; + const char *interface; + gboolean is_config; + gchar *propname; + + g_assert(path); + + /* get start of properties */ + pi = bluez_get_property_info(access_type, error); + if (!pi) + return FALSE; + + /* get actual property */ + pi = property_by_name(pi, is_json_name, name, &is_config); + if (!pi) { + g_set_error(error, NB_ERROR, NB_ERROR_UNKNOWN_PROPERTY, + "unknown property with name %s", name); + json_object_put(jval); + return FALSE; + } + + /* convert to gvariant */ + arg = property_json_to_gvariant(pi, NULL, NULL, jval, error); + + /* we don't need this anymore */ + json_object_put(jval); + jval = NULL; + + /* no variant? error */ + if (!arg) + return FALSE; + + if (!is_config) + propname = g_strdup(pi->name); + else + propname = configuration_dbus_name(pi->name); + + if (!strcmp(access_type, BLUEZ_AT_DEVICE)) + interface = BLUEZ_DEVICE_INTERFACE; + else if (!strcmp(access_type, BLUEZ_AT_ADAPTER)) + interface = BLUEZ_ADAPTER_INTERFACE; + else if (!strcmp(access_type, BLUEZ_AT_AGENT)) + interface = BLUEZ_AGENT_INTERFACE; + else + return FALSE; + + reply = g_dbus_connection_call_sync(ns->conn, + BLUEZ_SERVICE, path, FREEDESKTOP_PROPERTIES, "Set", + g_variant_new("(ssv)", interface, propname, arg), + NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, + NULL, error); + + g_free(propname); + + if (!reply) + return FALSE; + + g_variant_unref(reply); + + return TRUE; +} diff --git a/binding/bluetooth-common.h b/binding/bluetooth-common.h new file mode 100644 index 0000000..159c5f4 --- /dev/null +++ b/binding/bluetooth-common.h @@ -0,0 +1,196 @@ +/* + * Copyright 2018 Konsulko Group + * Author: Matt Ranostay <matt.ranostay@konsulko.com> + * Author: Pantelis Antoniou <pantelis.antoniou@konsulko.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BLUETOOTH_COMMON_H +#define BLUETOOTH_COMMON_H + +#include <stddef.h> + +#define _GNU_SOURCE +#include <glib.h> +#include <stdlib.h> +#include <gio/gio.h> +#include <glib-object.h> + +#include <json-c/json.h> + +#define AFB_BINDING_VERSION 3 +#include <afb/afb-binding.h> + +struct call_work; + +struct bluetooth_state { + GMainLoop *loop; + GDBusConnection *conn; + guint device_sub; + guint autoconnect_sub; + + afb_event_t device_changes_event; + afb_event_t agent_event; + + /* NOTE: single connection allowed for now */ + /* NOTE: needs locking and a list */ + GMutex cw_mutex; + int next_cw_id; + GSList *cw_pending; + struct call_work *cw; + + /* agent */ + GDBusNodeInfo *introspection_data; + guint agent_id; + guint registration_id; + gchar *agent_path; + gboolean agent_registered; +}; + +struct init_data { + GCond cond; + GMutex mutex; + gboolean init_done; + afb_api_t api; + struct bluetooth_state *ns; /* before setting afb_api_set_userdata() */ + int rc; +}; + +struct agent_data { + int pin_code; + gchar *device_path; +}; + +struct call_work { + struct bluetooth_state *ns; + int id; + gchar *access_type; + gchar *type_arg; + gchar *method; + gchar *bluez_method; + struct bluez_pending_work *cpw; + afb_req_t request; + struct agent_data agent_data; + GDBusMethodInvocation *invocation; +}; + +/* init methods in bluetooth-rfkill.c */ + +int bluetooth_monitor_init(void); + +/* agent methods in bluetooth-agent.c */ + +int bluetooth_register_agent(struct init_data *id); + +void bluetooth_unregister_agent(struct bluetooth_state *ns); + +/* utility methods in bluetooth-util.c */ + +extern gboolean auto_lowercase_keys; + +void signal_init_done(struct init_data *id, int rc); + +int str2boolean(const char *value); + +json_object *json_object_copy(json_object *jval); + +gchar *key_dbus_to_json(const gchar *key, gboolean auto_lower); + +json_object *simple_gvariant_to_json(GVariant *var, json_object *parent, + gboolean recurse); + +/** + * Structure for converting from dbus properties to json + * and vice-versa. + * Note this is _not_ a generic dbus json bridge since + * some constructs are not easily mapped. + */ +struct property_info { + const char *name; /* the connman property name */ + const char *json_name; /* the json name (if NULL autoconvert) */ + const char *fmt; + unsigned int flags; + const struct property_info *sub; +}; + +#define PI_CONFIG (1U << 0) + +const struct property_info *property_by_dbus_name( + const struct property_info *pi, + const gchar *dbus_name, + gboolean *is_config); +const struct property_info *property_by_json_name( + const struct property_info *pi, + const gchar *json_name, + gboolean *is_config); +const struct property_info *property_by_name( + const struct property_info *pi, + gboolean is_json_name, const gchar *name, + gboolean *is_config); + +gchar *property_get_json_name(const struct property_info *pi, + const gchar *name); +gchar *property_get_name(const struct property_info *pi, + const gchar *json_name); + +gchar *configuration_dbus_name(const gchar *dbus_name); +gchar *configuration_json_name(const gchar *json_name); + +gchar *property_name_dbus2json(const struct property_info *pi, + gboolean is_config); + +json_object *property_dbus2json( + const struct property_info **pip, + const gchar *key, GVariant *var, + gboolean *is_config); + +gboolean root_property_dbus2json( + json_object *jparent, + const struct property_info *pi, + const gchar *key, GVariant *var, + gboolean *is_config); + +GVariant *property_json_to_gvariant( + const struct property_info *pi, + const char *fmt, /* if NULL use pi->fmt */ + const struct property_info *pi_parent, + json_object *jval, + GError **error); + +typedef enum { + NB_ERROR_BAD_TECHNOLOGY, + NB_ERROR_BAD_SERVICE, + NB_ERROR_OUT_OF_MEMORY, + NB_ERROR_NO_TECHNOLOGIES, + NB_ERROR_NO_SERVICES, + NB_ERROR_BAD_PROPERTY, + NB_ERROR_UNIMPLEMENTED, + NB_ERROR_UNKNOWN_PROPERTY, + NB_ERROR_UNKNOWN_TECHNOLOGY, + NB_ERROR_UNKNOWN_SERVICE, + NB_ERROR_MISSING_ARGUMENT, + NB_ERROR_ILLEGAL_ARGUMENT, + NB_ERROR_CALL_IN_PROGRESS, +} NBError; + +#define NB_ERROR (nb_error_quark()) + +extern GQuark nb_error_quark(void); + +json_object *get_property_collect(json_object *jreqprop, json_object *jprop, + GError **error); +json_object *get_named_property(const struct property_info *pi, + gboolean is_json_name, const char *name, json_object *jprop); + +#endif diff --git a/binding/bluetooth-rfkill.c b/binding/bluetooth-rfkill.c new file mode 100644 index 0000000..5419e8f --- /dev/null +++ b/binding/bluetooth-rfkill.c @@ -0,0 +1,129 @@ +/* + * Copyright 2018 Konsulko Group + * Author: Matt Ranostay <matt.ranostay@konsulko.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <ctype.h> +#include <string.h> +#include <errno.h> +#include <fcntl.h> + +#include <linux/rfkill.h> + +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/stat.h> + +#include <glib.h> +#include <glib/gstdio.h> +#include <gio/gio.h> + +#define AFB_BINDING_VERSION 3 +#include <afb/afb-binding.h> + +#define HCIDEVUP _IOW('H', 201, int) +#define BTPROTO_HCI 1 + + + +static int hci_interface_enable(int hdev) +{ + int ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + int ret; + + if (ctl < 0) + return ctl; + + ret = ioctl(ctl, HCIDEVUP, hdev); + + close(ctl); + + return ret; +} + +static gboolean bluetooth_rfkill_event(GIOChannel *chan, GIOCondition cond, gpointer ptr) +{ + struct rfkill_event event; + gchar *name, buf[8]; + ssize_t len; + int fd; + + fd = g_io_channel_unix_get_fd(chan); + len = read(fd, &event, sizeof(struct rfkill_event)); + + if (len != sizeof(struct rfkill_event)) + return TRUE; + + if (event.type != RFKILL_TYPE_BLUETOOTH) + return TRUE; + + if (event.op == RFKILL_OP_DEL) + return TRUE; + + name = g_strdup_printf("/sys/class/rfkill/rfkill%u/soft", event.idx); + + fd = g_open(name, O_WRONLY); + len = write(fd, "0", 1); + g_close(fd, NULL); + + g_free(name); + + memset(&buf, 0, sizeof(buf)); + + name = g_strdup_printf("/sys/class/rfkill/rfkill%u/name", event.idx); + fd = g_open(name, O_RDONLY); + len = read(fd, &buf, sizeof(buf) - 1); + + if (len > 0) + { + int idx = 0; + sscanf(buf, "hci%d", &idx); + + /* + * 50 millisecond delay to allow time for rfkill to unblock before + * attempting to bring up HCI interface + */ + g_usleep(50000); + + hci_interface_enable(idx); + } + + g_free(name); + + return TRUE; +} + +int bluetooth_monitor_init(void) +{ + int fd = g_open("/dev/rfkill", O_RDWR); + GIOChannel *chan = NULL; + int ret = -EINVAL; + + if (fd < 0) + { + AFB_ERROR("Cannot open /dev/rfkill"); + return ret; + } + + chan = g_io_channel_unix_new(fd); + g_io_channel_set_close_on_unref(chan, TRUE); + + ret = g_io_add_watch(chan, G_IO_IN, bluetooth_rfkill_event, NULL); + + g_io_channel_unref(chan); + + return 0; +} diff --git a/binding/bluetooth-util.c b/binding/bluetooth-util.c new file mode 100644 index 0000000..0af4898 --- /dev/null +++ b/binding/bluetooth-util.c @@ -0,0 +1,1026 @@ +/* + * Copyright 2018 Konsulko Group + * Author: Pantelis Antoniou <pantelis.antoniou@konsulko.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <ctype.h> +#include <errno.h> +#include <pthread.h> +#include <semaphore.h> + +#include <glib.h> +#include <stdlib.h> +#include <gio/gio.h> +#include <glib-object.h> + +#include <json-c/json.h> + +#define AFB_BINDING_VERSION 3 +#include <afb/afb-binding.h> + +#include "bluetooth-api.h" +#include "bluetooth-common.h" + +G_DEFINE_QUARK(bluetooth-binding-error-quark, nb_error) + +/* convert dbus key to lower case */ +gboolean auto_lowercase_keys = TRUE; + +void signal_init_done(struct init_data *id, int rc) +{ + g_mutex_lock(&id->mutex); + id->init_done = TRUE; + id->rc = rc; + g_cond_signal(&id->cond); + g_mutex_unlock(&id->mutex); +} + +int str2boolean(const char *value) +{ + if (!strcmp(value, "1") || !g_ascii_strcasecmp(value, "true") || + !g_ascii_strcasecmp(value, "on") || !g_ascii_strcasecmp(value, "enabled") || + !g_ascii_strcasecmp(value, "yes")) + return TRUE; + if (!strcmp(value, "0") || !g_ascii_strcasecmp(value, "false") || + !g_ascii_strcasecmp(value, "off") || !g_ascii_strcasecmp(value, "disabled") || + !g_ascii_strcasecmp(value, "no")) + return FALSE; + return -1; +} + +json_object *json_object_copy(json_object *jval) +{ + json_object *jobj; + int i, len; + + /* handle NULL */ + if (!jval) + return NULL; + + switch (json_object_get_type(jval)) { + case json_type_object: + jobj = json_object_new_object(); + json_object_object_foreach(jval, key, jval2) + json_object_object_add(jobj, key, + json_object_copy(jval2)); + + return jobj; + + case json_type_array: + jobj = json_object_new_array(); + len = json_object_array_length(jval); + for (i = 0; i < len; i++) + json_object_array_add(jobj, + json_object_copy( + json_object_array_get_idx(jval, i))); + return jobj; + + case json_type_null: + return NULL; + + case json_type_boolean: + return json_object_new_boolean( + json_object_get_boolean(jval)); + + case json_type_double: + return json_object_new_double( + json_object_get_double(jval)); + + case json_type_int: + return json_object_new_int64( + json_object_get_int64(jval)); + + case json_type_string: + return json_object_new_string( + json_object_get_string(jval)); + } + + g_assert(0); + /* should never happen */ + return NULL; +} + +gchar *key_dbus_to_json(const gchar *key, gboolean auto_lower) +{ + gchar *lower, *s; + + lower = g_strdup(key); + g_assert(lower); + + if (!auto_lower) + return lower; + + /* convert to lower case */ + for (s = lower; *s; s++) + *s = g_ascii_tolower(*s); + + return lower; +} + +json_object *simple_gvariant_to_json(GVariant *var, json_object *parent, + gboolean recurse) +{ + json_object *obj = NULL, *item; + gint32 i32; + gint64 i64; + guint32 ui32; + guint64 ui64; + GVariantIter iter; + GVariant *key, *value; + gchar *json_key; + gsize nitems; + gboolean is_dict; + + obj = NULL; + + /* AFB_DEBUG("g_variant_classify(var)=%c", g_variant_classify(var)); */ + + /* we only handle simple types */ + switch (g_variant_classify(var)) { + case G_VARIANT_CLASS_BOOLEAN: + obj = json_object_new_boolean(g_variant_get_boolean(var)); + break; + case G_VARIANT_CLASS_INT16: + obj = json_object_new_int(g_variant_get_int16(var)); + break; + case G_VARIANT_CLASS_INT32: + i32 = g_variant_get_int32(var); + obj = json_object_new_int(i32); + break; + case G_VARIANT_CLASS_INT64: + i64 = g_variant_get_int64(var); + if (i64 >= -(1L << 31) && i64 < (1L << 31)) + obj = json_object_new_int((int)i64); + else + obj = json_object_new_int64(i64); + break; + case G_VARIANT_CLASS_BYTE: + obj = json_object_new_int((int)g_variant_get_byte(var)); + break; + case G_VARIANT_CLASS_UINT16: + obj = json_object_new_int((int)g_variant_get_uint16(var)); + break; + case G_VARIANT_CLASS_UINT32: + ui32 = g_variant_get_uint32(var); + if (ui32 < (1U << 31)) + obj = json_object_new_int(ui32); + else + obj = json_object_new_int64(ui32); + break; + case G_VARIANT_CLASS_UINT64: + ui64 = g_variant_get_uint64(var); + if (ui64 < (1U << 31)) + obj = json_object_new_int((int)ui64); + else if (ui64 < (1LLU << 63)) + obj = json_object_new_int64(ui64); + else { + AFB_WARNING("U64 value %llu clamped to %llu", + (unsigned long long)ui64, + (unsigned long long)((1LLU << 63) - 1)); + obj = json_object_new_int64((1LLU << 63) - 1); + } + break; + case G_VARIANT_CLASS_DOUBLE: + obj = json_object_new_double(g_variant_get_double(var)); + break; + case G_VARIANT_CLASS_OBJECT_PATH: + case G_VARIANT_CLASS_STRING: + obj = json_object_new_string(g_variant_get_string(var, NULL)); + break; + + case G_VARIANT_CLASS_ARRAY: + + if (!recurse) + break; + + /* detect dictionaries which are arrays of dict entries */ + g_variant_iter_init(&iter, var); + + nitems = g_variant_iter_n_children(&iter); + /* remove completely empty arrays */ + if (nitems == 0) + break; + + is_dict = nitems > 0; + while (is_dict && (value = g_variant_iter_next_value(&iter))) { + is_dict = g_variant_classify(value) == G_VARIANT_CLASS_DICT_ENTRY; + g_variant_unref(value); + } + + if (is_dict) + obj = json_object_new_object(); + else + obj = json_object_new_array(); + + g_variant_iter_init(&iter, var); + while ((value = g_variant_iter_next_value(&iter))) { + + item = simple_gvariant_to_json(value, obj, TRUE); + if (!is_dict && item) + json_object_array_add(obj, item); + + g_variant_unref(value); + } + break; + + case G_VARIANT_CLASS_DICT_ENTRY: + + if (!recurse) + break; + + if (!parent) { + AFB_WARNING("#### dict new object without a parent"); + break; + } + + g_variant_iter_init(&iter, var); + while ((key = g_variant_iter_next_value(&iter))) { + + value = g_variant_iter_next_value(&iter); + if (!value) { + AFB_WARNING("Out of values with a key"); + g_variant_unref(key); + break; + } + + json_key = key_dbus_to_json( + g_variant_get_string(key, NULL), + auto_lowercase_keys); + + /* only handle dict values with string keys */ + if (g_variant_classify(key) == G_VARIANT_CLASS_STRING) { + item = simple_gvariant_to_json(value, obj, TRUE); + if (item) + json_object_object_add(parent, json_key, item); + + } else + AFB_WARNING("Can't handle non-string key"); + + g_free(json_key); + + g_variant_unref(value); + g_variant_unref(key); + } + break; + + case G_VARIANT_CLASS_VARIANT: + + /* NOTE: recurse allowed because we only allow a single encapsulated variant */ + + g_variant_iter_init(&iter, var); + nitems = g_variant_iter_n_children(&iter); + if (nitems != 1) { + AFB_WARNING("Can't handle variants with more than one children (%lu)", nitems); + break; + } + + while ((value = g_variant_iter_next_value(&iter))) { + obj = simple_gvariant_to_json(value, parent, TRUE); + g_variant_unref(value); + break; + } + break; + + default: + AFB_WARNING("############ class is %c", g_variant_classify(var)); + obj = NULL; + break; + } + + return obj; +} + +gchar *property_name_dbus2json(const struct property_info *pi, + gboolean is_config) +{ + gchar *json_name; + gchar *cfgname; + + if (pi->json_name) + json_name = g_strdup(pi->json_name); + else + json_name = key_dbus_to_json(pi->name, auto_lowercase_keys); + + if (!json_name) + return NULL; + + if (!is_config) + return json_name; + + cfgname = g_strdup_printf("%s.%configuration", + json_name, + auto_lowercase_keys ? 'c' : 'C'); + g_free(json_name); + return cfgname; +} + +json_object *property_dbus2json( + const struct property_info **pip, + const gchar *key, GVariant *var, + gboolean *is_config) +{ + const struct property_info *pi = *pip, *pi2, *pi_sub; + GVariantIter iter, iter2; + json_object *obj = NULL, *obji; + const char *fmt; + GVariant *value, *dict_value, *dict_key; + const gchar *sub_key; + gchar *json_key; + gboolean is_subconfig; + + if (key) { + pi = property_by_dbus_name(pi, key, is_config); + if (!pi) + return NULL; + *pip = pi; + } + + fmt = pi->fmt; + + obj = simple_gvariant_to_json(var, NULL, FALSE); + if (obj) { + /* TODO check fmt for matching type */ + return obj; + } + + switch (*fmt) { + case 'a': /* array */ + obj = json_object_new_array(); + + g_variant_iter_init(&iter, var); + while ((value = g_variant_iter_next_value(&iter))) { + pi2 = pi; + obji = property_dbus2json(&pi2, NULL, value, + &is_subconfig); + if (obji) + json_object_array_add(obj, obji); + + g_variant_unref(value); + } + break; + case '{': + /* we only support {sX} */ + + /* there must be a sub property entry */ + g_assert(pi->sub); + + obj = json_object_new_object(); + + g_variant_iter_init(&iter, var); + while ((value = g_variant_iter_next_value(&iter))) { + + if (g_variant_classify(value) != G_VARIANT_CLASS_DICT_ENTRY) { + AFB_WARNING("Expecting dict got '%c'", g_variant_classify(value)); + g_variant_unref(value); + break; + } + + g_variant_iter_init(&iter2, value); + while ((dict_key = g_variant_iter_next_value(&iter2))) { + if (g_variant_classify(dict_key) != G_VARIANT_CLASS_STRING) { + AFB_WARNING("Can't handle non-string dict keys '%c'", + g_variant_classify(dict_key)); + g_variant_unref(dict_key); + g_variant_unref(value); + continue; + } + + dict_value = g_variant_iter_next_value(&iter2); + if (!dict_value) { + AFB_WARNING("Out of values with a dict_key"); + g_variant_unref(dict_key); + g_variant_unref(value); + break; + } + + sub_key = g_variant_get_string(dict_key, NULL); + + pi_sub = pi->sub; + while (pi_sub->name) { + if (!g_strcmp0(sub_key, pi_sub->name)) + break; + pi_sub++; + } + + if (pi_sub->name) { + pi2 = pi_sub; + obji = property_dbus2json(&pi2, + sub_key, dict_value, + &is_subconfig); + if (obji) { + json_key = property_name_dbus2json(pi2, FALSE); + json_object_object_add(obj, json_key, obji); + g_free(json_key); + } + } else + AFB_INFO("Unhandled %s/%s property", key, sub_key); + + g_variant_unref(dict_value); + g_variant_unref(dict_key); + } + + g_variant_unref(value); + } + + break; + } + + if (!obj) + AFB_INFO("# %s not a type we can handle", key ? key : "<NULL>"); + + return obj; +} + +const struct property_info *property_by_dbus_name( + const struct property_info *pi, + const gchar *dbus_name, + gboolean *is_config) +{ + const struct property_info *pit; + const gchar *suffix; + gchar *tmpname; + size_t len; + + /* direct match first */ + pit = pi; + while (pit->name) { + if (!g_strcmp0(dbus_name, pit->name)) { + if (is_config) + *is_config = FALSE; + return pit; + } + pit++; + } + + /* try to see if a matching config property exists */ + suffix = strrchr(dbus_name, '.'); + if (!suffix || g_ascii_strcasecmp(suffix, ".Configuration")) + return NULL; + + /* it's a (possible) .config property */ + len = suffix - dbus_name; + tmpname = alloca(len + 1); + memcpy(tmpname, dbus_name, len); + tmpname[len] = '\0'; + + /* match with config */ + pit = pi; + while (pit->name) { + if (!(pit->flags & PI_CONFIG)) { + pit++; + continue; + } + if (!g_strcmp0(tmpname, pit->name)) { + if (is_config) + *is_config = TRUE; + return pit; + } + pit++; + } + + return NULL; +} + +const struct property_info *property_by_json_name( + const struct property_info *pi, + const gchar *json_name, + gboolean *is_config) +{ + const struct property_info *pit; + gchar *this_json_name; + const gchar *suffix; + gchar *tmpname; + size_t len; + + /* direct match */ + pit = pi; + while (pit->name) { + this_json_name = property_name_dbus2json(pit, FALSE); + if (!g_strcmp0(this_json_name, json_name)) { + g_free(this_json_name); + if (is_config) + *is_config = FALSE; + return pit; + } + g_free(this_json_name); + pit++; + } + + /* try to see if a matching config property exists */ + suffix = strrchr(json_name, '.'); + if (!suffix || g_ascii_strcasecmp(suffix, ".configuration")) + return NULL; + + /* it's a (possible) .config property */ + len = suffix - json_name; + tmpname = alloca(len + 1); + memcpy(tmpname, json_name, len); + tmpname[len] = '\0'; + + /* match with config */ + pit = pi; + while (pit->name) { + if (!(pit->flags & PI_CONFIG)) { + pit++; + continue; + } + this_json_name = property_name_dbus2json(pit, FALSE); + if (!g_strcmp0(this_json_name, tmpname)) { + g_free(this_json_name); + if (is_config) + *is_config = TRUE; + return pit; + } + g_free(this_json_name); + pit++; + } + + return NULL; +} + +const struct property_info *property_by_name( + const struct property_info *pi, + gboolean is_json_name, const gchar *name, + gboolean *is_config) +{ + return is_json_name ? + property_by_json_name(pi, name, is_config) : + property_by_dbus_name(pi, name, is_config); +} + +gchar *property_get_json_name(const struct property_info *pi, + const gchar *name) +{ + gboolean is_config; + + pi = property_by_dbus_name(pi, name, &is_config); + if (!pi) + return NULL; + return property_name_dbus2json(pi, is_config); +} + +gchar *configuration_dbus_name(const gchar *dbus_name) +{ + return g_strdup_printf("%s.Configuration", dbus_name); +} + +gchar *configuration_json_name(const gchar *json_name) +{ + return g_strdup_printf("%s.configuration", json_name); +} + +gchar *property_get_name(const struct property_info *pi, + const gchar *json_name) +{ + gboolean is_config; + + pi = property_by_json_name(pi, json_name, &is_config); + if (!pi) + return NULL; + + return !is_config ? g_strdup(pi->name) : + configuration_dbus_name(pi->name); +} + +gboolean root_property_dbus2json( + json_object *jparent, + const struct property_info *pi, + const gchar *key, GVariant *var, + gboolean *is_config) +{ + json_object *obj; + gchar *json_key; + + obj = property_dbus2json(&pi, key, var, is_config); + if (!obj) + return FALSE; + + switch (json_object_get_type(jparent)) { + case json_type_object: + json_key = property_name_dbus2json(pi, *is_config); + json_object_object_add(jparent, json_key, obj); + g_free(json_key); + break; + case json_type_array: + json_object_array_add(jparent, obj); + break; + default: + json_object_put(obj); + return FALSE; + } + + return TRUE; +} + +static const GVariantType *type_from_fmt(const char *fmt) +{ + switch (*fmt) { + case 'b': /* gboolean */ + return G_VARIANT_TYPE_BOOLEAN; + case 'y': /* guchar */ + return G_VARIANT_TYPE_BYTE; + case 'n': /* gint16 */ + return G_VARIANT_TYPE_INT16; + case 'q': /* guint16 */ + return G_VARIANT_TYPE_UINT16; + case 'h': + return G_VARIANT_TYPE_HANDLE; + case 'i': /* gint32 */ + return G_VARIANT_TYPE_INT32; + case 'u': /* guint32 */ + return G_VARIANT_TYPE_UINT32; + case 'x': /* gint64 */ + return G_VARIANT_TYPE_INT64; + case 't': /* gint64 */ + return G_VARIANT_TYPE_UINT64; + case 'd': /* double */ + return G_VARIANT_TYPE_DOUBLE; + case 's': /* string */ + return G_VARIANT_TYPE_STRING; + case 'o': /* object */ + return G_VARIANT_TYPE_OBJECT_PATH; + case 'g': /* signature */ + return G_VARIANT_TYPE_SIGNATURE; + case 'v': /* variant */ + return G_VARIANT_TYPE_VARIANT; + } + /* nothing complex */ + return NULL; +} + +GVariant *property_json_to_gvariant( + const struct property_info *pi, + const char *fmt, + const struct property_info *pi_parent, + json_object *jval, + GError **error) +{ + const struct property_info *pi_sub; + GVariant *arg, *item; + GVariantBuilder builder; + json_object *jitem; + json_bool b; + gchar *dbus_name; + int64_t i64; + double d; + const char *jvalstr, *str; + char c; + int i, len; + gboolean is_config; + + if (!fmt) + fmt = pi->fmt; + + if (!jval) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "can't encode json NULL type"); + return NULL; + } + + jvalstr = json_object_to_json_string(jval); + + arg = NULL; + + b = FALSE; + i64 = 0; + d = 0.0; + str = NULL; + + /* conversion and type check */ + c = *fmt++; + if (c == 'a') { + if (!json_object_is_type(jval, json_type_array)) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property \"%s\" (not an array)", + jvalstr); + return NULL; + } + + len = json_object_array_length(jval); + /* special case for empty array */ + if (!len) { + arg = g_variant_new_array(type_from_fmt(fmt), NULL, 0); + if (!arg) + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Can't create empty array on \"%s\"", + jvalstr); + return arg; + } + + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); + for (i = 0; i < len; i++) { + jitem = json_object_array_get_idx(jval, i); + item = property_json_to_gvariant(pi, fmt, NULL, jitem, error); + if (!item) { + g_variant_builder_clear(&builder); + return NULL; + } + g_variant_builder_add_value(&builder, item); + } + + arg = g_variant_builder_end(&builder); + + if (!arg) + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Can't handle array on \"%s\"", + jvalstr); + + return arg; + } + if (c == '{') { + g_assert(pi->sub); + + c = *fmt++; + /* we only handle string keys */ + if (c != 's') { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Can't handle non-string keys on \"%s\"", + jvalstr); + return NULL; + } + c = *fmt++; + + /* this is arguably wrong */ + g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); + pi_sub = pi->sub; + json_object_object_foreach(jval, key_o, jval_o) { + pi_sub = property_by_json_name(pi->sub, key_o, &is_config); + if (!pi_sub) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Unknown sub-property %s in \"%s\"", + key_o, json_object_to_json_string(jval_o)); + return NULL; + } + item = property_json_to_gvariant(pi_sub, NULL, pi, jval_o, error); + if (!item) + return NULL; + + dbus_name = property_get_name(pi->sub, key_o); + g_assert(dbus_name); /* can't fail; but check */ + + g_variant_builder_add(&builder, pi->fmt, dbus_name, item); + + g_free(dbus_name); + } + + arg = g_variant_builder_end(&builder); + + if (!arg) + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Can't handle object on \"%s\"", + jvalstr); + return arg; + } + + switch (c) { + case 'b': /* gboolean */ + if (!json_object_is_type(jval, json_type_boolean)) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property \"%s\" (not a boolean)", + jvalstr); + return NULL; + } + b = json_object_get_boolean(jval); + break; + case 'y': /* guchar */ + case 'n': /* gint16 */ + case 'q': /* guint16 */ + case 'h': + case 'i': /* gint32 */ + case 'u': /* guint32 */ + case 'x': /* gint64 */ + case 't': /* gint64 */ + if (!json_object_is_type(jval, json_type_int)) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property \"%s\" (not an integer)", + jvalstr); + return NULL; + } + /* note unsigned 64 bit values shall be truncated */ + i64 = json_object_get_int64(jval); + break; + + case 'd': /* double */ + if (!json_object_is_type(jval, json_type_double)) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property \"%s\" (not a double)", + jvalstr); + return NULL; + } + d = json_object_get_double(jval); + break; + case 's': /* string */ + case 'o': /* object */ + case 'g': /* signature */ + if (!json_object_is_type(jval, json_type_string)) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property \"%s\" (not a string)", + jvalstr); + return NULL; + } + str = json_object_get_string(jval); + break; + case 'v': /* variant */ + AFB_WARNING("Can't handle variant yet"); + break; + } + + /* build gvariant */ + switch (c) { + case 'b': /* gboolean */ + arg = g_variant_new_boolean(b); + break; + case 'y': /* guchar */ + if (i64 < 0 || i64 > 255) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property %s (out of byte range)", + jvalstr); + return FALSE; + } + arg = g_variant_new_byte((guchar)i64); + break; + case 'n': /* gint16 */ + if (i64 < -(1LL << 15) || i64 >= (1LL << 15)) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property %s (out of int16 range)", + jvalstr); + return FALSE; + } + arg = g_variant_new_int16((gint16)i64); + break; + case 'q': /* guint16 */ + if (i64 < 0 || i64 >= (1LL << 16)) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property %s (out of uint16 range)", + jvalstr); + return FALSE; + } + arg = g_variant_new_uint16((guint16)i64); + break; + case 'h': + case 'i': /* gint32 */ + if (i64 < -(1LL << 31) || i64 >= (1LL << 31)) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property %s (out of int32 range)", + jvalstr); + return FALSE; + } + arg = g_variant_new_int32((gint32)i64); + break; + case 'u': /* guint32 */ + if (i64 < 0 || i64 >= (1LL << 32)) { + g_set_error(error, NB_ERROR, NB_ERROR_BAD_PROPERTY, + "Bad property %s (out of uint32 range)", + jvalstr); + return FALSE; + } + arg = g_variant_new_uint32((guint32)i64); + break; + case 'x': /* gint64 */ + arg = g_variant_new_int64(i64); + break; + case 't': /* gint64 */ + arg = g_variant_new_uint64(i64); + break; + case 'd': /* double */ + arg = g_variant_new_double(d); + break; + case 's': /* string */ + arg = g_variant_new_string(str); + break; + case 'o': /* object */ + arg = g_variant_new_object_path(str); + break; + case 'g': /* signature */ + arg = g_variant_new_signature(str); + break; + case 'v': /* variant */ + AFB_WARNING("Can't handle variant yet"); + break; + } + + return arg; +} + +json_object *get_property_collect(json_object *jreqprop, json_object *jprop, + GError **error) +{ + int i, len; + json_object *jkey, *jval, *jobj = NULL, *jobjval; + const char *key; + + + /* printf("jreqprop=%s\n", json_object_to_json_string_ext(jreqprop, + JSON_C_TO_STRING_SPACED)); + printf("jprop=%s\n", json_object_to_json_string_ext(jprop, + JSON_C_TO_STRING_SPACED)); */ + + /* get is an array of strings (or an object for subtype */ + g_assert(json_object_get_type(jreqprop) == json_type_array); + + len = json_object_array_length(jreqprop); + if (len == 0) + return NULL; + + for (i = 0; i < len; i++) { + jkey = json_object_array_get_idx(jreqprop, i); + + /* string key */ + if (json_object_is_type(jkey, json_type_string)) { + key = json_object_get_string(jkey); + if (!json_object_object_get_ex(jprop, key, &jval)) { + g_set_error(error, + NB_ERROR, NB_ERROR_BAD_PROPERTY, + "can't find key %s", key); + json_object_put(jobj); + return NULL; + } + + if (!jobj) + jobj = json_object_new_object(); + + json_object_object_add(jobj, key, + json_object_copy(jval)); + + } else if (json_object_is_type(jkey, json_type_object)) { + /* recursing into an object */ + + json_object_object_foreach(jkey, key_o, jval_o) { + if (!json_object_object_get_ex(jprop, key_o, + &jval)) { + g_set_error(error, NB_ERROR, + NB_ERROR_BAD_PROPERTY, + "can't find key %s", key_o); + json_object_put(jobj); + return NULL; + } + + /* jval_o is on jreqprop */ + /* jval is on jprop */ + + jobjval = get_property_collect(jval_o, jval, + error); + + if (!jobjval && error && *error) { + json_object_put(jobj); + return NULL; + } + + if (jobjval) { + if (!jobj) + jobj = json_object_new_object(); + + json_object_object_add(jobj, key_o, jobjval); + } + } + } + } + + /* if (jobj) + printf("jobj=%s\n", json_object_to_json_string_ext(jobj, + JSON_C_TO_STRING_SPACED)); */ + + return jobj; +} + +json_object *get_named_property(const struct property_info *pi, + gboolean is_json_name, const char *name, json_object *jprop) +{ + json_object *jret = NULL; + gchar *json_name = NULL; + + if (!is_json_name) { + json_name = property_get_json_name(pi, name); + if (!json_name) + return NULL; + name = json_name; + } + + json_object_object_foreach(jprop, key, jval) { + if (!g_strcmp0(key, name)) { + jret = json_object_copy(jval); + break; + } + } + + g_free(json_name); + + return jret; +} diff --git a/conf.d/autobuild/agl/autobuild b/conf.d/autobuild/agl/autobuild deleted file mode 100755 index 759f6be..0000000 --- a/conf.d/autobuild/agl/autobuild +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/make -f -# Copyright (C) 2015, 2016 "IoT.bzh" -# Author "Romain Forlot" <romain.forlot@iot.bzh> -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -THISFILE := $(lastword $(MAKEFILE_LIST)) -BUILD_DIR := $(abspath $(dir $(THISFILE)/../../../../..)/build) -DEST := ${BUILD_DIR}/target - -.PHONY: all clean distclean configure build package help - -all: help - -help: - @echo "List of targets available:" - @echo "" - @echo "- all" - @echo "- clean" - @echo "- distclean" - @echo "- configure" - @echo "- build" - @echo "- package" - @echo "" - @echo "Usage: ./conf.d/autobuild/agl/autobuild package DEST=${HOME}/opt" - @echo "Don't use your build dir as DEST as wgt file is generated at this location" - -clean: - @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} clean) || echo Nothing to clean - -distclean: - @rm -rf ${BUILD_DIR} - -configure: ${BUILD_DIR}/Makefile - -build: configure - @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all - -package: build - @mkdir -p ${BUILD_DIR}/$@/bin - @mkdir -p ${BUILD_DIR}/$@/etc - @mkdir -p ${BUILD_DIR}/$@/lib - @mkdir -p ${BUILD_DIR}/$@/htdocs - @mkdir -p ${BUILD_DIR}/$@/data - @cmake --build ${BUILD_DIR} --target widget - @mkdir -p ${DEST} && cp ${BUILD_DIR}/*wgt ${DEST} - -${BUILD_DIR}/Makefile: - @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR} - @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..) diff --git a/conf.d/autobuild/linux/autobuild b/conf.d/autobuild/linux/autobuild deleted file mode 100755 index 759f6be..0000000 --- a/conf.d/autobuild/linux/autobuild +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/make -f -# Copyright (C) 2015, 2016 "IoT.bzh" -# Author "Romain Forlot" <romain.forlot@iot.bzh> -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -THISFILE := $(lastword $(MAKEFILE_LIST)) -BUILD_DIR := $(abspath $(dir $(THISFILE)/../../../../..)/build) -DEST := ${BUILD_DIR}/target - -.PHONY: all clean distclean configure build package help - -all: help - -help: - @echo "List of targets available:" - @echo "" - @echo "- all" - @echo "- clean" - @echo "- distclean" - @echo "- configure" - @echo "- build" - @echo "- package" - @echo "" - @echo "Usage: ./conf.d/autobuild/agl/autobuild package DEST=${HOME}/opt" - @echo "Don't use your build dir as DEST as wgt file is generated at this location" - -clean: - @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} clean) || echo Nothing to clean - -distclean: - @rm -rf ${BUILD_DIR} - -configure: ${BUILD_DIR}/Makefile - -build: configure - @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all - -package: build - @mkdir -p ${BUILD_DIR}/$@/bin - @mkdir -p ${BUILD_DIR}/$@/etc - @mkdir -p ${BUILD_DIR}/$@/lib - @mkdir -p ${BUILD_DIR}/$@/htdocs - @mkdir -p ${BUILD_DIR}/$@/data - @cmake --build ${BUILD_DIR} --target widget - @mkdir -p ${DEST} && cp ${BUILD_DIR}/*wgt ${DEST} - -${BUILD_DIR}/Makefile: - @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR} - @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..) diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake index 6d7ace7..0b9515b 100644 --- a/conf.d/cmake/config.cmake +++ b/conf.d/cmake/config.cmake @@ -19,17 +19,17 @@ # Project Info # ------------------ set(PROJECT_NAME agl-service-bluetooth) -set(PROJECT_VERSION "1.0") -set(PROJECT_PRETTY_NAME "Bluetooth binding service") -set(PROJECT_DESCRIPTION "Expose Bluetooth Low Level APIs through AGL Framework") +set(PROJECT_VERSION "2.0") +set(PROJECT_PRETTY_NAME "Bluetooth-Manager service") +set(PROJECT_DESCRIPTION "Interface BlueZ through AGL Framework service") set(PROJECT_ICON "icon.png") -set(PROJECT_AUTHOR "Tasuku Suzuki") -set(PROJECT_AUTHOR_MAIL "tasuku.suzuki@qt.io") +set(PROJECT_AUTHOR "Matt Ranostay") +set(PROJECT_AUTHOR_MAIL "matt.ranostay@konsulko.com") set(PROJECT_LICENSE "APL2.0") set(PROJECT_LANGUAGES,"C") +set(API_NAME "Bluetooth-Manager") -# Where are stored the project configuration files -# relative to the root project directory +# Where the project configuration files are stored set(PROJECT_CMAKE_CONF_DIR "conf.d") # Where are stored your external libraries for your project. This is 3rd party library that you don't maintain diff --git a/conf.d/wgt/config.xml.in b/conf.d/wgt/config.xml.in index 393bd68..feab37b 100644 --- a/conf.d/wgt/config.xml.in +++ b/conf.d/wgt/config.xml.in @@ -8,17 +8,18 @@ <license>@PROJECT_LICENSE@</license> <feature name="urn:AGL:widget:required-permission"> - <param name="urn:AGL:permission::public:hidden" value="required" /> - <param name="urn:AGL:permission::system:run-by-default" value="required" /> - <param name="http://tizen.org/privilege/internal/dbus" value="required" /> + <param name="urn:AGL:permission::public:hidden" value="required" /> + <param name="urn:AGL:permission::public:no-htdocs" value="required" /> + <param name="urn:AGL:permission::system:run-by-default" value="required" /> + <param name="http://tizen.org/privilege/internal/dbus" value="required" /> </feature> - <feature name="urn:AGL:widget:provided-api"> - <param name="Bluetooth-Manager" value="ws" /> - </feature> - - <feature name="urn:AGL:widget:required-binding"> - <param name="@WIDGET_ENTRY_POINT@" value="local" /> - </feature> + <feature name="urn:AGL:widget:provided-api"> + <param name="Bluetooth-Manager" value="ws" /> + </feature> + <feature name="urn:AGL:widget:required-api"> + <param name="persistence" value="ws" /> + <param name="@WIDGET_ENTRY_POINT@" value="local" /> + </feature> </widget> |