Webcom C SDK
webcom-base.h
Go to the documentation of this file.
1 /*
2  * webcom-sdk-c
3  *
4  * Copyright 2018 Orange
5  * <camille.oudot@orange.com>
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or (at your
10  * option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22 
23 #ifndef INCLUDE_WEBCOM_C_WEBCOM_BASE_H_
24 #define INCLUDE_WEBCOM_C_WEBCOM_BASE_H_
25 
26 
27 typedef struct wc_context wc_context_t;
28 typedef struct wc_datasync_context wc_datasync_context_t;
29 typedef struct wc_auth_context wc_auth_context_t;
30 
31 #include <poll.h>
32 #include <stddef.h>
33 #include <stdint.h>
34 
81 #define WC_POLLHUP (POLLHUP|POLLERR)
82 #define WC_POLLIN (POLLIN)
83 #define WC_POLLOUT (POLLOUT)
84 
88 enum wc_pollsrc {
91 
92  _WC_POLL_MAX /* keep last */
93 };
94 
102 
103  _WC_TIMER_MAX /* keep last */
104 };
105 
109 struct wc_pollargs {
110  int fd;
111  short events;
113 };
114 
118 struct wc_timerargs {
119  long ms;
120  enum wc_timersrc timer;
121  int repeat;
122 };
123 
124 #define WC_BASE_EVENT_OFFSET 0x00000001
125 #define WC_DATASYNC_EVENT_OFFSET 0x00000100
126 #define WC_AUTH_EVENT_OFFSET 0x00010000
127 
128 typedef enum {
129  /* Base */
130 
137 
143 
150 
157 
162 
163  /* Datasync */
164 
171 
179 
185 
192 
193  /* Authentication */
194 
201 } wc_event_t;
202 
214 typedef int (*wc_on_event_cb_t) (wc_event_t event, wc_context_t *ctx, void *data, size_t len);
215 
217  char *app_name;
218  char *host;
219  uint16_t port;
221  int no_tls;
222  void *user_data;
223 };
224 
236 void wc_dispatch_fd_event(wc_context_t *ctx, struct wc_pollargs *pa);
237 
246 void wc_dispatch_timer_event(wc_context_t *ctx, enum wc_timersrc timer);
247 
256 
257 
268 
277 void wc_context_destroy(wc_context_t * ctx);
278 
283 #endif /* INCLUDE_WEBCOM_C_WEBCOM_BASE_H_ */
void wc_dispatch_fd_event(wc_context_t *ctx, struct wc_pollargs *pa)
struct wc_context wc_context_t
Definition: webcom-base.h:27
short events
a mask of events (WC_POLL* macros)
Definition: webcom-base.h:111
WC_EVENT_ADD_FD.
Definition: webcom-base.h:136
wc_event_t
Definition: webcom-base.h:128
wc_pollsrc
Definition: webcom-base.h:88
wc_on_event_cb_t callback
Definition: webcom-base.h:220
special value, holds the actual number of possible socket event sources
Definition: webcom-base.h:92
WC_EVENT_ON_CNX_CLOSED.
Definition: webcom-base.h:170
wc_timersrc
Definition: webcom-base.h:98
int no_tls
Definition: webcom-base.h:221
WC_EVENT_SET_TIMER.
Definition: webcom-base.h:156
#define WC_DATASYNC_EVENT_OFFSET
Definition: webcom-base.h:125
uint16_t port
Definition: webcom-base.h:219
the event relates to the authentication HTTP request handling
Definition: webcom-base.h:101
char * app_name
Definition: webcom-base.h:217
WC_EVENT_DEL_FD.
Definition: webcom-base.h:142
WC_EVENT_MODIFY_FD.
Definition: webcom-base.h:149
special value, holds the actual number of possible timers
Definition: webcom-base.h:103
wc_context_t * wc_context_create(struct wc_context_options *options)
WC_EVENT_ON_CNX_ERROR.
Definition: webcom-base.h:191
struct wc_datasync_context wc_datasync_context_t
Definition: webcom-base.h:28
void wc_dispatch_timer_event(wc_context_t *ctx, enum wc_timersrc timer)
void * wc_context_get_user_data(wc_context_t *ctx)
#define WC_BASE_EVENT_OFFSET
Definition: webcom-base.h:124
WC_EVENT_ON_MSG_RECEIVED.
Definition: webcom-base.h:184
WC_EVENT_ON_SERVER_HANDSHAKE.
Definition: webcom-base.h:178
void * user_data
Definition: webcom-base.h:222
#define WC_AUTH_EVENT_OFFSET
Definition: webcom-base.h:126
char * host
Definition: webcom-base.h:218
Definition: webcom-base.h:109
long ms
timer delay in milliseconds
Definition: webcom-base.h:119
WC_EVENT_DEL_TIMER.
Definition: webcom-base.h:161
the event relates to the datasync socket
Definition: webcom-base.h:89
int repeat
1 if this timer should be recurring, 0 otherwise (only relevant for the WC_EVENT_SET_TIMER event) ...
Definition: webcom-base.h:121
int fd
file descriptor
Definition: webcom-base.h:110
Definition: webcom-base.h:216
the event relates to the datasync reconnection timer
Definition: webcom-base.h:100
struct wc_auth_context wc_auth_context_t
Definition: webcom-base.h:29
the event relates to the datasync socket keepalive
Definition: webcom-base.h:99
the event relates to the authentication socket
Definition: webcom-base.h:90
WC_AUTH_ON_AUTH_REPLY.
Definition: webcom-base.h:200
enum wc_pollsrc src
the origin of this event
Definition: webcom-base.h:112
int(* wc_on_event_cb_t)(wc_event_t event, wc_context_t *ctx, void *data, size_t len)
Definition: webcom-base.h:214
Definition: webcom-base.h:118
void wc_context_destroy(wc_context_t *ctx)