3 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
5 * Contact: Nilesh Trimbake <t.shripati@samsung.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
31 #include "bt-hal-avrcp-transport-dbus-handler.h"
32 #include "bt-hal-dbus-common-utils.h"
33 #include "bt-hal-internal.h"
35 static const char *__bt_transport_type_to_str(int type)
38 case BTRC_TRANSPORT_ATTR_DELAY:
40 case BTRC_TRANSPORT_ATTR_VOLUME:
49 bt_status_t _bt_hal_dbus_handler_avrcp_transport_get_property(bt_bdaddr_t *bd_addr, int type, unsigned int *value)
51 GDBusProxy *proxy = NULL;
53 GVariant *reply = NULL;
54 GVariant *temp = NULL;
56 proxy = _bt_hal_get_avrcp_transport_properties_proxy(bd_addr);
58 ERR("Unable to get proxy \n");
59 return BT_STATUS_FAIL;
62 reply = g_dbus_proxy_call_sync(proxy,
63 "Get", g_variant_new("(ss)", BT_HAL_MEDIATRANSPORT_INTERFACE,
64 __bt_transport_type_to_str(type)),
65 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
67 g_object_unref(proxy);
70 ERR("Can't get managed objects");
72 ERR("%s", err->message);
75 return BT_STATUS_FAIL;
78 g_variant_get(reply, "(v)", &temp);
79 *value = g_variant_get_uint16(temp);
80 g_variant_unref(temp);
82 DBG("Type[%s] and Value[%d]", __bt_transport_type_to_str(type), *value);
84 g_variant_unref(reply);
85 return BT_STATUS_SUCCESS;
89 bt_status_t _bt_hal_dbus_handler_avrcp_transport_set_property(bt_bdaddr_t *bd_addr, int type, unsigned int value)
91 GVariant *reply, *param = NULL;
93 GDBusProxy *proxy = NULL;
94 uint16_t property_level = (uint16_t)value;
97 case BTRC_TRANSPORT_ATTR_DELAY:
98 param = g_variant_new("q", property_level);
99 INFO("delay level %d", property_level);
101 case BTRC_TRANSPORT_ATTR_VOLUME:
102 param = g_variant_new("q", property_level);
103 INFO("volume level %d", property_level);
106 ERR("Invalid property type: %d", type);
107 return BT_STATUS_FAIL;
110 proxy = _bt_hal_get_avrcp_transport_properties_proxy(bd_addr);
112 ERR("Unable to get proxy \n");
113 return BT_STATUS_FAIL;
116 reply = g_dbus_proxy_call_sync(proxy,
117 "Set", g_variant_new("(ssv)",
118 BT_HAL_MEDIATRANSPORT_INTERFACE,
119 __bt_transport_type_to_str(type), param),
120 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
121 g_object_unref(proxy);
123 ERR("Can't get managed objects");
125 ERR("SetProperty Fail: %s", err->message);
127 return BT_STATUS_FAIL;
131 g_variant_unref(reply);
133 return BT_STATUS_SUCCESS;