Addition of the log output function that application is available.
[profile/ivi/ico-uxf-utilities.git] / include / ico_uws.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   header file of library for communicate
11  *
12  * @date    June-7-2013
13  */
14
15 #ifndef __ICO_UWS_H__
16 #define __ICO_UWS_H__
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /*============================================================================*/
23 /* definition                                                                 */
24 /*============================================================================*/
25 struct ico_uws_context;
26
27 typedef enum {
28     ICO_UWS_STATE_CONNECTING    = 0,
29     ICO_UWS_STATE_OPEN          = 1,
30     ICO_UWS_STATE_CLOSING       = 2,
31     ICO_UWS_STATE_CLOSED        = 3,
32     ICO_UWS_STATE_UNKNOWN       = -1
33 } ico_uws_state_e;
34
35 typedef enum {
36     ICO_UWS_EVT_OPEN    = 100,
37     ICO_UWS_EVT_ERROR   = 101,
38     ICO_UWS_EVT_CLOSE   = 102,
39     ICO_UWS_EVT_RECEIVE = 103,
40     ICO_UWS_EVT_ADD_FD  = 104,
41     ICO_UWS_EVT_DEL_FD  = 105
42 } ico_uws_evt_e;
43
44 typedef enum {
45     ICO_UWS_ERR_NONE            = 0,    /**< success */
46     ICO_UWS_ERR_CREATE          = -201,
47     ICO_UWS_ERR_CONNECT         = -202,
48     ICO_UWS_ERR_CLOSED          = -203,
49     ICO_UWS_ERR_SEND            = -204,
50     ICO_UWS_ERR_INVALID_PARAM   = -205,
51     ICO_UWS_ERR_OUT_OF_MEMORY   = -206,
52     ICO_UWS_ERR_UNKNOWN         = -300,
53 } ico_uws_error_e;
54
55 typedef union {
56     struct {
57         void            *recv_data;
58         size_t          recv_len;
59     } _ico_uws_message;
60     struct {
61         ico_uws_error_e code;
62     } _ico_uws_error;
63     struct {
64         int             fd;
65     } _ico_uws_fd;
66 } ico_uws_detail;
67
68 typedef void (*ico_uws_evt_cb)
69              (const struct ico_uws_context *context,
70               const ico_uws_evt_e event,
71               const void *id,
72               const ico_uws_detail *detail,
73               void *user_data);
74
75 /*============================================================================*/
76 /* functions                                                                  */
77 /*============================================================================*/
78 /*--------------------------------------------------------------------------*/
79 /**
80  * @brief   ico_uws_create_context
81  *          Create ico_uws context.
82  *          This API does not support secure access ("wss://") and
83  *          the multi protocols.
84  *          (If user sets "wss://", this function processes as "ws://".)
85  *
86  * @param[in]   uri                 the uri to which to connect
87  *                                  server sets the string ":(port)"
88  *                                  client sets the string "ws://(host):(port)"
89  * @param[in]   protocol            the protocol name
90  * @return      context
91  * @retval      ico_uws context     success
92  * @retval      NULL                error
93  */
94 /*--------------------------------------------------------------------------*/
95 struct ico_uws_context *ico_uws_create_context(const char *uri,
96                                                const char *protocol);
97
98 /*--------------------------------------------------------------------------*/
99 /**
100  * @brief   ico_uws_close
101  *          Close the connection and destroy the ico_uws context.
102  *
103  * @param[in]   context             ico_uws context
104  * @return      none
105  */
106 /*--------------------------------------------------------------------------*/
107 void ico_uws_close(struct ico_uws_context *context);
108
109 /*--------------------------------------------------------------------------*/
110 /**
111  * @brief   ico_uws_send
112  *          Send data to which to connect.
113  *          User needs to call the function "ico_uws_service"
114  *          before calling this function.
115  *
116  * @param[in]   context             ico_uws context
117  * @param[in]   id                  the id to connected to (callback notifies)
118  * @param[in]   data                the data to send
119  * @param[in]   len                 count of the data bytes
120  * @return      none
121  * @see         ico_uws_service
122  */
123 /*--------------------------------------------------------------------------*/
124 void ico_uws_send(struct ico_uws_context *context, void *id,
125                   unsigned char *data, size_t len);
126
127 /*--------------------------------------------------------------------------*/
128 /**
129  * @brief   ico_uws_service
130  *          Service any pending websocket activity.
131  *          This function deals with any pending websocket traffic,
132  *          so you need to call this function periodically.
133  *
134  * @param[in]   context             ico_uws context
135  * @return      none
136  */
137 /*--------------------------------------------------------------------------*/
138 void ico_uws_service(struct ico_uws_context *context);
139
140 /*--------------------------------------------------------------------------*/
141 /**
142  * @brief   ico_uws_get_uri
143  *          Get the uri that is connecting to now.
144  *
145  * @param[in]   context             ico_uws context
146  * @return      uri
147  * @retval      data of string      success
148  * @retval      NULL                error
149  */
150 /*--------------------------------------------------------------------------*/
151 char *ico_uws_get_uri(struct ico_uws_context *context);
152
153 /*--------------------------------------------------------------------------*/
154 /**
155  * @brief   ico_uws_get_ready_state
156  *          Get the state of connection.
157  *
158  * @param[in]   context                 ico_uws context
159  * @return      state
160  * @retval      >= 0                    success
161  * @retval      ICO_UWS_STATE_UNKNOWN   error
162  */
163 /*--------------------------------------------------------------------------*/
164 ico_uws_state_e ico_uws_get_ready_state(struct ico_uws_context *context);
165
166 /*--------------------------------------------------------------------------*/
167 /**
168  * @brief   ico_uws_set_event_cb
169  *          Set the event callback function.
170  *
171  * @param[in]   context             ico_uws context
172  * @param[in]   callback            callback function
173  * @param[in]   user_data           user data
174  * @return      result
175  * @retval      ICO_UWS_ERR_NONE    success
176  * @retval      others              error
177  */
178 /*--------------------------------------------------------------------------*/
179 int ico_uws_set_event_cb(struct ico_uws_context *context, ico_uws_evt_cb callback,
180                          void *user_data);
181
182 /*--------------------------------------------------------------------------*/
183 /**
184  * @brief   ico_uws_unset_event_cb
185  *          Unset the event callback function.
186  *
187  * @param[in]   context             ico_uws context
188  * @return      none
189  */
190 /*--------------------------------------------------------------------------*/
191 void ico_uws_unset_event_cb(struct ico_uws_context *context);
192
193
194 #ifdef __cplusplus
195 }
196 #endif
197
198 #endif /* __ICO_UWS_H__ */