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