Addition of the log output function that application is available.
[profile/ivi/ico-uxf-utilities.git] / include / ico_uws_private.h
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   private header file of library for communicate
11  *
12  * @date    June-7-2013
13  */
14
15 #ifndef __ICO_UWS_PRIVATE_H__
16 #define __ICO_UWS_PRIVATE_H__
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /*===========================================================================*/
23 /* variable & table                                                          */
24 /*===========================================================================*/
25 #define ICO_UWS_MAX_NUM     200     /**< max num of list's data         */
26 #define ICO_UWS_MAX_FDS     4       /**< max num of file descriptors    */
27
28 /* libwebsockets's protocol number */
29 enum ico_apf_protocols
30 {
31     PROTOCOL_HTTP = 0,  /* always first */
32     PROTOCOL_ICO_UWS,   /* for ico_uws communication */
33     PROTOCOL_END        /* final */
34 };
35
36 /* structure for managing the ico_uws_context */
37 struct ico_uws_mng_context {
38     struct ico_uws_mng_context   *next;
39     struct ico_uws_context       *context;
40 };
41
42 /* structure for managing the ico_uws_context's list */
43 struct ico_uws_mng_context_list {
44     struct ico_uws_mng_context  *first;
45     struct ico_uws_mng_context  *last;
46     struct ico_uws_mng_context  *free;
47 };
48
49 /* structure of connection info */
50 struct ico_uws_connect {
51     struct ico_uws_connect *next;
52     struct libwebsocket *wsi;
53 };
54
55 /* ico uws context */
56 struct ico_uws_context {
57     struct libwebsocket_context *ws_context;
58
59     /* connection information list */
60     struct ico_uws_connect  *con_list_first;
61     struct ico_uws_connect  *con_list_last;
62     struct ico_uws_connect  *con_list_free;
63
64     char uri[128];
65     int port;
66     ico_uws_state_e state;
67     struct  {
68         int     fd;
69         void    *wsi;
70     }   callback_fd_list[ICO_UWS_MAX_FDS];
71
72     struct libwebsocket_protocols protocols[PROTOCOL_END + 1];
73
74     ico_uws_evt_cb callback;
75     void *user_data;
76 };
77
78 /*============================================================================*/
79 /* global API                                                                 */
80 /*============================================================================*/
81 #if defined(__GNUC__) && __GNUC__ >= 4
82 #define ICO_API __attribute__ ((visibility("default")))
83 #else
84 #define ICO_API
85 #endif
86
87 /*============================================================================*/
88 /* log macro                                                                  */
89 /*============================================================================*/
90 #ifndef  _NO_USE_DLOG
91
92 #ifdef LOG_TAG
93 #undef LOG_TAG
94 #endif
95
96 #define LOG_TAG "ICO_UWS"
97 #include <dlog.h>
98
99 static int  _ico_uws_debug = 0;
100
101 #define _ERR(fmt, arg...)                                       \
102     do {                                                        \
103         fprintf(stderr, "ico_uws E: %s:%d [ "fmt" ]\n",         \
104                 __FUNCTION__,                                   \
105                 __LINE__,                                       \
106                 ##arg);                                         \
107         LOGE("%s:%d " fmt, __FUNCTION__, __LINE__, ##arg);      \
108     } while (0)
109
110 #define _WARN(fmt, arg...)                                      \
111     do {                                                        \
112         LOGW("%s:%d " fmt, __FUNCTION__, __LINE__, ##arg);      \
113     } while (0)
114
115 #define _INFO(fmt, arg...)                                      \
116     do {                                                        \
117         LOGI("%s:%d " fmt, __FUNCTION__, __LINE__, ##arg);      \
118     } while (0)
119
120 #define _DBG(fmt, arg...)                                       \
121     do {                                                        \
122         if (_ico_uws_debug == 0)    {                           \
123             if (getenv("ICO_UWS_DEBUG"))                        \
124                 _ico_uws_debug = 1;                             \
125             else                                                \
126                 _ico_uws_debug = -1;                            \
127         }                                                       \
128         if (_ico_uws_debug > 0) {                               \
129             LOGD("%s:%d " fmt, __FUNCTION__, __LINE__, ##arg);  \
130         }                                                       \
131     } while (0)
132
133 #else
134
135 #define _ERR(fmt, arg...)                                       \
136     do {                                                        \
137         fprintf(stderr,                                         \
138                 "ico_uws E: %s:%d [ "fmt" ]\n",                 \
139                 __FUNCTION__,                                   \
140                 __LINE__,                                       \
141                 ##arg);                                         \
142     } while (0)
143
144 #define _WARN(fmt, arg...)                                      \
145     do {                                                        \
146         fprintf(stderr,                                         \
147                 "ico_uws W: %s:%d [ "fmt" ]\n",                 \
148                 __FUNCTION__,                                   \
149                 __LINE__,                                       \
150                 ##arg);                                         \
151     } while (0)
152
153
154 #define _INFO(fmt, arg...)                                      \
155     do {                                                        \
156         fprintf(stderr,                                         \
157                 "ico_uws I: %s:%d [ "fmt" ]\n",                 \
158                 __FUNCTION__,                                   \
159                 __LINE__,                                       \
160                 ##arg);                                         \
161     } while (0)
162
163 #define _DBG(fmt, arg...)                                       \
164     do {                                                        \
165         if (getenv("ICO_UWS_DEBUG")) {                          \
166             fprintf(stderr,                                     \
167                     "ico_uws D: %s:%d [ "fmt" ]\n",             \
168                     __FUNCTION__,                               \
169                     __LINE__,                                   \
170                     ##arg);                                     \
171         }                                                       \
172     } while (0)
173
174 #endif
175
176 #ifdef __cplusplus
177 }
178 #endif
179
180 #endif /* __ICO_UWS_PRIVATE_H__ */