2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
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
10 * @brief header file of library for communicate
22 /*============================================================================*/
24 /*============================================================================*/
25 struct ico_uws_context;
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
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
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,
68 typedef void (*ico_uws_evt_cb)
69 (const struct ico_uws_context *context,
70 const ico_uws_evt_e event,
72 const ico_uws_detail *detail,
75 /*============================================================================*/
77 /*============================================================================*/
78 /*--------------------------------------------------------------------------*/
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://".)
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
91 * @retval ico_uws context success
94 /*--------------------------------------------------------------------------*/
95 struct ico_uws_context *ico_uws_create_context(const char *uri,
96 const char *protocol);
98 /*--------------------------------------------------------------------------*/
100 * @brief ico_uws_close
101 * Close the connection and destroy the ico_uws context.
103 * @param[in] context ico_uws context
106 /*--------------------------------------------------------------------------*/
107 void ico_uws_close(struct ico_uws_context *context);
109 /*--------------------------------------------------------------------------*/
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.
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
121 * @see ico_uws_service
123 /*--------------------------------------------------------------------------*/
124 void ico_uws_send(struct ico_uws_context *context, void *id,
125 unsigned char *data, size_t len);
127 /*--------------------------------------------------------------------------*/
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.
134 * @param[in] context ico_uws context
137 /*--------------------------------------------------------------------------*/
138 void ico_uws_service(struct ico_uws_context *context);
140 /*--------------------------------------------------------------------------*/
142 * @brief ico_uws_get_uri
143 * Get the uri that is connecting to now.
145 * @param[in] context ico_uws context
147 * @retval data of string success
150 /*--------------------------------------------------------------------------*/
151 char *ico_uws_get_uri(struct ico_uws_context *context);
153 /*--------------------------------------------------------------------------*/
155 * @brief ico_uws_get_ready_state
156 * Get the state of connection.
158 * @param[in] context ico_uws context
160 * @retval >= 0 success
161 * @retval ICO_UWS_STATE_UNKNOWN error
163 /*--------------------------------------------------------------------------*/
164 ico_uws_state_e ico_uws_get_ready_state(struct ico_uws_context *context);
166 /*--------------------------------------------------------------------------*/
168 * @brief ico_uws_set_event_cb
169 * Set the event callback function.
171 * @param[in] context ico_uws context
172 * @param[in] callback callback function
173 * @param[in] user_data user data
175 * @retval ICO_UWS_ERR_NONE success
176 * @retval others error
178 /*--------------------------------------------------------------------------*/
179 int ico_uws_set_event_cb(struct ico_uws_context *context, ico_uws_evt_cb callback,
182 /*--------------------------------------------------------------------------*/
184 * @brief ico_uws_unset_event_cb
185 * Unset the event callback function.
187 * @param[in] context ico_uws context
190 /*--------------------------------------------------------------------------*/
191 void ico_uws_unset_event_cb(struct ico_uws_context *context);
198 #endif /* __ICO_UWS_H__ */