aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bluetooth-api.c49
-rw-r--r--bluetooth-manager.c59
-rw-r--r--bluetooth-manager.h1
3 files changed, 109 insertions, 0 deletions
diff --git a/bluetooth-api.c b/bluetooth-api.c
index 31d179a..34caac5 100644
--- a/bluetooth-api.c
+++ b/bluetooth-api.c
@@ -603,6 +603,54 @@ static void bt_set_property (struct afb_req request)
}
+/**/
+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 eventadd (struct afb_req request)
{
const char *tag = afb_req_value(request, "tag");
@@ -792,6 +840,7 @@ static const struct afb_verb_desc_v1 binding_verbs[]= {
{ .name = "disconnect", .session = AFB_SESSION_NONE, .callback = bt_disconnect, .info = "Disconnect special device" },
{ .name = "set_device_property", .session = AFB_SESSION_NONE, .callback = bt_set_device_property, .info = "Set special device property" },
{ .name = "set_property", .session = AFB_SESSION_NONE, .callback = bt_set_property, .info = "Set Bluetooth property" },
+{ .name = "set_avrcp_controls", .session = AFB_SESSION_NONE, .callback = bt_set_avrcp_controls, .info = "Set Bluetooth AVRCP controls" },
{ .name = "send_confirmation", .session = AFB_SESSION_NONE, .callback = bt_send_confirmation, .info = "Send Confirmation" },
{ .name = "eventadd", .session = AFB_SESSION_NONE, .callback = eventadd, .info = "adds the event of 'name' for the 'tag'"},
{ .name = "eventdel", .session = AFB_SESSION_NONE, .callback = eventdel, .info = "deletes the event of 'tag'"},
diff --git a/bluetooth-manager.c b/bluetooth-manager.c
index a6c4472..35c770f 100644
--- a/bluetooth-manager.c
+++ b/bluetooth-manager.c
@@ -1519,6 +1519,65 @@ int device_set_property(const char * bdaddr, const char *property_name,
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
diff --git a/bluetooth-manager.h b/bluetooth-manager.h
index 4a86533..9b7eee0 100644
--- a/bluetooth-manager.h
+++ b/bluetooth-manager.h
@@ -185,6 +185,7 @@ int device_connect(const gchar *addr);
int device_disconnect(const gchar *addr);
//int device_disconnectProfile();
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 adapter_set_property(const gchar* property, gboolean value) ;