715d6ef83211b563355b08325e732c32017c69f1
[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 #include <stdio.h>
21 #include <libintl.h>
22 #include <stdbool.h>
23 #include <errno.h>
24 #include <string.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <fcntl.h>
28 #include <sys/socket.h>
29 #include <sys/un.h>
30 #include <dlog.h>
31 #include <unistd.h>
32 #include <aul.h>
33 #include <vconf.h>
34 #include <stdlib.h>
35 //#include <Ecore.h>
36 #include <glib.h>
37
38 #define ACC_ELEMENT_LEN 256
39 #define SOCK_PATH "/tmp/usb_server_sock"
40 #define ACC_SOCK_PATH "/tmp/usb_acc_sock"
41 #define USB_ACCESSORY_NODE "/dev/usb_accessory"
42 #define APP_ID_LEN 64
43 #define SOCK_STR_LEN 1542
44
45 #define USB_TAG "USB_ACCESSORY"
46
47 #define USB_LOG(format, args...) \
48         LOG(LOG_VERBOSE, USB_TAG, "[%s][Ln: %d] " format, \
49                                         (char*)(strrchr(__FILE__, '/')+1), __LINE__, ##args)
50
51 #define USB_LOG_ERROR(format, args...) \
52         LOG(LOG_ERROR, USB_TAG, "[%s][Ln: %d] " format, \
53                                         (char*)(strrchr(__FILE__, '/')+1), __LINE__, ##args)
54
55 #define __USB_FUNC_ENTER__ \
56                         USB_LOG("Entering: %s()\n", __func__)
57
58 #define __USB_FUNC_EXIT__ \
59                         USB_LOG("Exit: %s()\n", __func__)
60
61 #define FREE(arg) \
62         do { \
63                 if(arg) { \
64                         free((void *)arg); \
65                         arg = NULL; \
66                 } \
67         } while (0);
68
69 #define um_retvm_if(expr, val, fmt, arg...) \
70         do { \
71                 if(expr) { \
72                         USB_LOG_ERROR(fmt, ##arg); \
73                         return (val); \
74                 } \
75         } while (0);
76
77 #define um_retm_if(expr, fmt, arg...) \
78         do { \
79                 if(expr) { \
80                         USB_LOG_ERROR(fmt, ##arg); \
81                         return; \
82                 } \
83         } while (0);
84
85 typedef enum {
86         IPC_ERROR = 0,
87         IPC_FAIL,
88         IPC_SUCCESS
89 } IPC_SIMPLE_RESULT;
90
91 typedef enum {
92         LAUNCH_APP = 0,
93         REQUEST_PERMISSION,
94         HAS_PERMISSION,
95         REQ_PERM_NOTI_YES_BTN,
96         REQ_PERM_NOTI_NO_BTN,
97         GET_ACC_INFO,
98         ERROR_POPUP_OK_BTN,
99         KIESWIFI_POPUP_YES_BTN,
100         KIESWIFI_POPUP_NO_BTN
101 } REQUEST_TO_USB_MANGER;
102
103 typedef enum {
104         ACC_MANUFACTURER = 0,
105         ACC_MODEL,
106         ACC_DESCRIPTION,
107         ACC_VERSION,
108         ACC_URI,
109         ACC_SERIAL
110 } ACCESSORY_INFO;
111
112 struct usb_accessory_s {
113         bool            accPermission;
114
115         char            manufacturer[ACC_ELEMENT_LEN];
116         char            model[ACC_ELEMENT_LEN];
117         char            description[ACC_ELEMENT_LEN];
118         char            version[ACC_ELEMENT_LEN];
119         char            uri[ACC_ELEMENT_LEN];
120         char            serial[ACC_ELEMENT_LEN];
121 };
122
123 struct usb_accessory_list {
124         struct usb_accessory_s *accessory;
125         struct usb_accessory_list *next;
126 };
127
128 struct AccCbData {
129         void *user_data;
130         void (*connection_cb_func)(struct usb_accessory_s *accessory, bool is_connected, void *data);
131         void (*request_perm_cb_func)(struct usb_accessory_s *accessory, bool is_granted);
132         struct usb_accessory_s *accessory;
133 };
134
135 int ipc_request_client_init(int *sock_remote);
136 int ipc_request_client_close(int *sock_remote);
137 int request_to_usb_server(int sock_remote, int request, char *answer, char *pkgName);
138 char *get_app_id();
139 void accessory_status_changed_cb(keynode_t *in_key, void* data);
140 bool getAccList(struct usb_accessory_list **accList);
141 bool freeAccList(struct usb_accessory_list *accList);
142 int ipc_noti_client_init(void);
143 int ipc_noti_client_close(int *sock_remote);
144 gboolean ipc_noti_client_cb(GIOChannel *g_io_ch, GIOCondition condition, gpointer data);
145 #endif /* __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__ */
146