09dc1148f05abff1dc4de5f83920519285fac138
[platform/core/api/usb-accessory.git] / include / usb_accessory_private.h
1 /*
2  * usb-accessory
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__
19 #define __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__
20
21 #define _GNU_SOURCE
22 #include <stdio.h>
23 #include <libintl.h>
24 #include <stdbool.h>
25 #include <errno.h>
26 #include <string.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <sys/socket.h>
31 #include <sys/un.h>
32 #include <dlog.h>
33 #include <unistd.h>
34 #include <aul.h>
35 #include <vconf.h>
36 #include <stdlib.h>
37 #include <sys/utsname.h>
38 #include <glib.h>
39
40 #define ACC_ELEMENT_LEN 256
41 #define SOCK_PATH "/tmp/usb_server_sock"
42 #define ACC_SOCK_PATH "/tmp/usb_acc_sock"
43 #define USB_ACCESSORY_NODE "/dev/usb_accessory"
44 #define APP_ID_LEN 64
45 #define SOCK_STR_LEN 1542
46
47 #define USB_TAG "USB_ACCESSORY"
48
49 #define USB_LOG(format, args...) \
50         LOG(LOG_VERBOSE, USB_TAG, "[%s][Ln: %d] " format, \
51                                         (char*)(strrchr(__FILE__, '/')+1), __LINE__, ##args)
52
53 #define USB_LOG_ERROR(format, args...) \
54         LOG(LOG_ERROR, USB_TAG, "[%s][Ln: %d] " format, \
55                                         (char*)(strrchr(__FILE__, '/')+1), __LINE__, ##args)
56
57 #define __USB_FUNC_ENTER__ \
58                         USB_LOG("Entering: %s()\n", __func__)
59
60 #define __USB_FUNC_EXIT__ \
61                         USB_LOG("Exit: %s()\n", __func__)
62
63 #define FREE(arg) \
64         do { \
65                 if(arg) { \
66                         free((void *)arg); \
67                         arg = NULL; \
68                 } \
69         } while (0);
70
71 #define um_retvm_if(expr, val, fmt, arg...) \
72         do { \
73                 if(expr) { \
74                         USB_LOG_ERROR(fmt, ##arg); \
75                         return (val); \
76                 } \
77         } while (0);
78
79 #define um_retm_if(expr, fmt, arg...) \
80         do { \
81                 if(expr) { \
82                         USB_LOG_ERROR(fmt, ##arg); \
83                         return; \
84                 } \
85         } while (0);
86
87 typedef enum {
88         IPC_ERROR = 0,
89         IPC_FAIL,
90         IPC_SUCCESS
91 } IPC_SIMPLE_RESULT;
92
93 typedef enum {
94         /* General */
95         ERROR_POPUP_OK_BTN = 0,
96         IS_EMUL_BIN,
97
98         /* for Accessory */
99         LAUNCH_APP_FOR_ACC = 20,
100         REQ_ACC_PERMISSION,
101         HAS_ACC_PERMISSION,
102         REQ_ACC_PERM_NOTI_YES_BTN,
103         REQ_ACC_PERM_NOTI_NO_BTN,
104         GET_ACC_INFO,
105
106         /* for Host */
107         LAUNCH_APP_FOR_HOST = 40,
108         REQ_HOST_PERMISSION,
109         HAS_HOST_PERMISSION,
110         REQ_HOST_PERM_NOTI_YES_BTN,
111         REQ_HOST_PERM_NOTI_NO_BTN,
112         REQ_HOST_CONNECTION
113 } REQUEST_TO_USB_MANGER;
114
115
116 typedef enum {
117         ACC_MANUFACTURER = 0,
118         ACC_MODEL,
119         ACC_DESCRIPTION,
120         ACC_VERSION,
121         ACC_URI,
122         ACC_SERIAL
123 } ACCESSORY_INFO;
124
125 struct usb_accessory_s {
126         bool            accPermission;
127
128         char            manufacturer[ACC_ELEMENT_LEN];
129         char            model[ACC_ELEMENT_LEN];
130         char            description[ACC_ELEMENT_LEN];
131         char            version[ACC_ELEMENT_LEN];
132         char            uri[ACC_ELEMENT_LEN];
133         char            serial[ACC_ELEMENT_LEN];
134 };
135
136 struct usb_accessory_list {
137         struct usb_accessory_s *accessory;
138         struct usb_accessory_list *next;
139 };
140
141 struct AccCbData {
142         void *user_data;
143         void (*connection_cb_func)(struct usb_accessory_s *accessory, bool is_connected, void *data);
144         void (*request_perm_cb_func)(struct usb_accessory_s *accessory, bool is_granted);
145         struct usb_accessory_s *accessory;
146 };
147
148 int ipc_request_client_init(int *sock_remote);
149 int ipc_request_client_close(int *sock_remote);
150 int request_to_usb_server(int sock_remote, int request, char *answer, char *pkgName);
151 char *get_app_id();
152 void accessory_status_changed_cb(keynode_t *in_key, void* data);
153 bool getAccList(struct usb_accessory_list **accList);
154 bool freeAccList(struct usb_accessory_list *accList);
155 int ipc_noti_client_init(void);
156 int ipc_noti_client_close(int *sock_remote);
157 gboolean ipc_noti_client_cb(GIOChannel *g_io_ch, GIOCondition condition, gpointer data);
158 bool is_emul_bin();
159 #endif /* __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__ */
160