Add the base code for gtest verification
[platform/core/connectivity/bluetooth-agent.git] / hid-agent / bluetooth-hid-agent.h
1 /*
2  * Bluetooth-hid-agent
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  *              http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #ifndef __DEF_BT_HID_AGENT_H_
21 #define __DEF_BT_HID_AGENT_H_
22 #define FUNCTION_TRACE
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #include <stdio.h>
29 #include <dlog.h>
30 #include <glib.h>
31 #include <sys/socket.h>
32 #include <gio/gio.h>
33 #include <gio/gunixfdlist.h>
34 #include <inttypes.h>
35
36 #undef LOG_TAG
37 #define LOG_TAG "BLUETOOTH_HID_AGENT"
38
39 #define LOG_COLOR_RESET    "\033[0m"
40 #define LOG_COLOR_RED      "\033[31m"
41 #define LOG_COLOR_YELLOW   "\033[33m"
42 #define LOG_COLOR_GREEN         "\033[32m"
43 #define LOG_COLOR_BLUE          "\033[36m"
44 #define LOG_COLOR_PURPLE   "\033[35m"
45
46 #define DBG(fmt, args...) SLOGD(fmt, ##args)
47 #define INFO(fmt, args...) SLOGI(fmt, ##args)
48 #define ERR(fmt, args...) SLOGE(fmt, ##args)
49 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
50 #define INFO_SECURE(fmt, args...) SECURE_SLOGI(fmt, ##args)
51 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
52 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
53 #define INFO_C(fmt, arg...) \
54         SLOGI_IF(TRUE,  LOG_COLOR_BLUE" "fmt" "LOG_COLOR_RESET, ##arg)
55 #define ERR_C(fmt, arg...) \
56         SLOGI_IF(TRUE,  LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg)
57
58 #ifdef FUNCTION_TRACE
59 #define FN_START DBG("[ENTER FUNC]")
60 #define FN_END DBG("[EXIT FUNC]")
61 #else
62 #define FN_START
63 #define FN_END
64 #endif
65
66 #define BT_HID_SERVICE_NAME "org.bluez.hid_agent"
67 #define BT_HID_AGENT_OBJECT_PATH "/org/bluez/hid_agent"
68 #define BT_HID_SERVICE_INTERFACE "org.tizen.HidApp"
69 #define BT_HID_AGENT_ERROR (__bt_hid_agent_error_quark())
70
71 #define BT_HID_BLUEZ_OBJECT_PATH "/org/tizen/hid"
72 #define BT_HID_BLUEZ_INTERFACE  "org.bluez.HidAgent"
73
74 #define BLUEZ_SERVICE_NAME "org.bluez"
75 #define BLUEZ_HID_INTERFACE_NAME "org.bluez.hid_device"
76
77 #define BLUEZ_PROFILE_MGMT_INTERFACE "org.bluez.ProfileManager1"
78 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
79 #define BT_ADAPTER_INTERFACE    "org.bluez.Adapter1"
80
81 #define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
82 #define BT_INTERFACES_ADDED "InterfacesAdded"
83 #define BT_INTERFACES_REMOVED "InterfacesRemoved"
84 #define BT_PROPERTY_CHANGED "PropertiesChanged"
85
86 #define BLUEZ_MEDIA_TRANSPORT_INTERFACE "org.bluez.MediaTransport1"
87 #define BLUEZ_MEDIA_ENDPOINT_INTERFACE "org.bluez.MediaEndpoint1"
88 #define BLUEZ_DEVICE_INTERFACE  "org.bluez.Device1"
89 #define A2DP_SOURCE_ENDPOINT "/MediaEndpoint/A2DPSource"
90
91 #define BT_ADDRESS_STRING_SIZE 18
92 #define BT_ADAPTER_OBJECT_PATH_MAX 50
93 #define BT_HID_DATA_BUF_SIZE 1024
94
95 #define BT_ERROR_INTERNAL "InternalError"
96 #define BT_ERROR_NOT_AVAILABLE "NotAvailable"
97 #define BT_ERROR_NOT_CONNECTED "NotConnected"
98 #define BT_ERROR_NOT_CONNECTION_FAILED "ConnectionFailed"
99 #define BT_ERROR_BUSY "InProgress"
100 #define BT_ERROR_INVALID_PARAM "InvalidArguments"
101 #define BT_ERROR_ALREADY_EXIST "AlreadyExists"
102 #define BT_ERROR_ALREADY_CONNECTED "Already Connected"
103 #define BT_ERROR_NO_MEMORY "No memory"
104 #define BT_ERROR_NO_DATA "No data"
105 #define BT_ERROR_I_O_ERROR "I/O error"
106 #define BT_ERROR_OPERATION_NOT_AVAILABLE "Operation currently not available"
107 #define BT_ERROR_OPERATION_NOT_ALLOWED "Operation not allowed"
108 #define BT_ERROR_OPERATION_NOT_SUPPORTED "Operation not supported"
109 #define BT_ERROR_INVALID_FILE_DESCRIPTOR "Invalid File Descriptor"
110
111 #define ret_if(expr) \
112         do { \
113                 if (expr) { \
114                         ERR("(%s) return", #expr); \
115                         return; \
116                 } \
117         } while (0)
118
119 typedef enum {
120         BT_HID_AGENT_ERROR_NONE,
121         BT_HID_AGENT_ERROR_INTERNAL,
122         BT_HID_AGENT_ERROR_NOT_AVAILABLE,
123         BT_HID_AGENT_ERROR_NOT_CONNECTED,
124         BT_HID_AGENT_ERROR_CONNECTION_FAILED,
125         BT_HID_AGENT_ERROR_BUSY,
126         BT_HID_AGENT_ERROR_INVALID_PARAM,
127         BT_HID_AGENT_ERROR_ALREADY_EXIST,
128         BT_HID_AGENT_ERROR_ALREADY_CONNECTED,
129         BT_HID_AGENT_ERROR_NO_MEMORY,
130         BT_HID_AGENT_ERROR_NO_DATA,
131         BT_HID_AGENT_ERROR_I_O_ERROR,
132         BT_HID_AGENT_ERROR_APPLICATION,
133         BT_HID_AGENT_ERROR_NOT_ALLOWED,
134         BT_HID_AGENT_ERROR_NOT_SUPPORTED,
135         BT_HID_AGENT_ERROR_INVALID_FILE_DESCRIPTOR,
136 } bt_hid_agent_error_t;
137
138 typedef enum {
139         BT_HID_STATE_UNAVAILABLE,
140         BT_HID_STATE_DISCONNECTED,
141         BT_HID_STATE_CONNECTING,
142         BT_HID_STATE_CONNECTED,
143         BT_HID_STATE_DISCONNECTING,
144 } bt_hid_state_t;
145
146 typedef struct {
147         guint32 fd;
148         char remote_addr[BT_ADDRESS_STRING_SIZE];
149         char *object_path;
150         GDBusMethodInvocation *context;
151         char *path;
152 } bt_hid_agent_info_t;
153
154 typedef struct {
155         unsigned char b[6];
156 } __attribute__((packed)) bdaddr_t;
157
158 /* Remote socket address */
159 struct sockaddr_remote {
160         sa_family_t     family;
161         bdaddr_t        remote_bdaddr;
162         uint8_t         channel;
163 };
164
165 bt_hid_agent_error_t _bt_hid_disconnect_profile(void);
166
167 #ifdef __cplusplus
168 }
169 #endif
170 #endif /* __DEF_BT_HID_AGENT_H_ */