4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <sys/types.h>
26 #include <dbus/dbus-glib.h>
27 #include <dbus/dbus.h>
30 #include "bluetooth-api.h"
34 #endif /* __cplusplus */
37 #define LOG_TAG "BLUETOOTH_FRWK"
40 #define BT_EXPORT_API __attribute__((visibility("default")))
43 #define BT_DBG(fmt, args...) \
45 #define BT_ERR(fmt, args...) \
48 #define ret_if(expr) \
51 BT_ERR("(%s) return", #expr); \
56 #define retv_if(expr, val) \
59 BT_ERR("(%s) return", #expr); \
64 #define BT_INIT_PARAMS() \
65 GArray *in_param1 = NULL; \
66 GArray *in_param2 = NULL; \
67 GArray *in_param3 = NULL; \
68 GArray *in_param4 = NULL; \
69 GArray *out_param = NULL;
71 #define BT_FREE_PARAMS(IP1,IP2,IP3,IP4,OP) \
74 g_array_free(IP1, TRUE); \
76 g_array_free(IP2, TRUE); \
78 g_array_free(IP3, TRUE); \
80 g_array_free(IP4, TRUE); \
82 g_array_free(OP, TRUE); \
85 #define BT_ALLOC_PARAMS(IP1,IP2,IP3,IP4,OP ) \
87 IP1 = g_array_new(FALSE, FALSE, sizeof(gchar)); \
88 IP2 = g_array_new(FALSE, FALSE, sizeof(gchar)); \
89 IP3 = g_array_new(FALSE, FALSE, sizeof(gchar)); \
90 IP4 = g_array_new(FALSE, FALSE, sizeof(gchar)); \
93 #define BT_INIT_AGENT_PARAMS() \
94 GArray *in_param = NULL; \
95 GArray *out_param = NULL;
97 #define BT_FREE_AGENT_PARAMS(IP,OP) \
100 g_array_free(IP, TRUE); \
102 g_array_free(OP, TRUE); \
105 #define BT_ALLOC_AGENT_PARAMS(IP,OP) \
107 IP = g_array_new(FALSE, FALSE, sizeof(gchar)); \
110 #define BT_CHECK_PARAMETER(arg, func) \
114 BT_ERR("INVALID PARAMETER"); \
115 func BLUETOOTH_ERROR_INVALID_PARAM; \
119 #define BT_CHECK_ENABLED(func) \
121 if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED) \
123 BT_ERR("BT is not enabled"); \
124 func BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; \
128 #define BT_ADDRESS_LENGTH_MAX 6
129 #define BT_ADDRESS_STRING_SIZE 18
130 #define BT_ADAPTER_OBJECT_PATH_MAX 50
132 #define BT_EVENT_FREEDESKTOP "org.freedesktop.DBus"
133 #define BT_FREEDESKTOP_PATH "/org/freedesktop/DBus"
135 #define BT_EVENT_MANAGER "org.bluez.Manager"
136 #define BT_MANAGER_PATH "/"
137 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
138 #define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
139 #define BT_DEVICE_INTERFACE "org.bluez.Device1"
141 #define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
143 #define BT_BLUEZ_NAME "org.bluez"
144 #define BT_DBUS_NAME "org.projectx.bt"
145 #define BT_SERVICE_PATH "/org/projectx/bt_service"
147 #define BT_AGENT_NAME "org.bluez.frwk_agent"
148 #define BT_AGENT_PATH "/org/bluez/agent/frwk_agent"
149 #define BT_AGENT_INTERFACE "org.bluez.Agent1"
151 #define BT_MAX_USER_INFO 5
152 #define RFKILL_EVENT_SIZE 8
153 #define RFKILL_NODE "/dev/rfkill"
158 RFKILL_TYPE_BLUETOOTH,
180 } bt_user_info_type_t;
187 void _bt_set_user_data(int type, void *callback, void *user_data);
189 void _bt_print_device_address_t(const bluetooth_device_address_t *addr);
191 bt_user_info_t* _bt_get_user_data(int type);
193 void _bt_common_event_cb(int event, int result, void *param,
194 void *callback, void *user_data);
196 void _bt_input_event_cb(int event, int result, void *param,
197 void *callback, void *user_data);
199 void _bt_headset_event_cb(int event, int result, void *param,
200 void *callback, void *user_data);
202 void _bt_avrcp_event_cb(int event, int result, void *param,
203 void *callback, void *user_data);
205 void _bt_opp_client_event_cb(int event, int result, void *param,
206 void *callback, void *user_data);
208 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
211 void _bt_convert_addr_string_to_type(unsigned char *addr,
212 const char *address);
214 void _bt_convert_addr_type_to_string(char *address,
215 unsigned char *addr);
217 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length);
219 int _bt_get_adapter_path(DBusGConnection *g_conn, char *path);
221 gboolean _bt_get_adapter_power(DBusGConnection *conn);
223 DBusGProxy *_bt_get_adapter_proxy(DBusGConnection *conn);
225 void _bt_device_path_to_address(const char *device_path, char *device_address);
227 DBusGConnection *__bt_init_system_gconn(void);
229 DBusGConnection *_bt_get_system_gconn(void);
231 DBusConnection *_bt_get_system_conn(void);
235 #endif /* __cplusplus */
236 #endif /*_BT_COMMON_H_*/