Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev_mgr.h
Go to the documentation of this file.
1 
8 #ifndef EV_MGR_H
9 #define EV_MGR_H
10 
11 #include <unistd.h>
12 #include <pthread.h>
13 
14 #include <ev.h>
15 
16 #include "config/opt.h"
17 #include "config/conf.h"
18 #include "utils/utils.h"
19 
20 #include "hotkeys.h"
21 #include "modules/vpn.h"
22 #include "modules/cque.h"
23 #include "modules/teodb.h"
24 #include "modules/stream.h"
25 #include "modules/metric.h"
26 #include "modules/net_tcp.h"
27 #include "modules/net_tun.h"
28 #include "modules/net_term.h"
29 #include "modules/tcp_proxy.h"
30 #include "modules/l0-server.h"
31 #include "modules/log_reader.h"
32 #include "modules/async_calls.h"
33 #include "modules/logging_server.h"
34 #include "modules/logging_client.h"
35 
36 extern const char *null_str;
37 #define NULL_STR (void*) null_str
38 
39 #define CHECK_EVENTS_AFTER 11.5
40 
44 };
45 
49 typedef enum ksnetEvMgrEvents {
50 
62  EV_K_STARTED, // #0 Calls immediately after event manager starts
63 
75  EV_K_STOPPED_BEFORE,// #1 Calls before event manager stopped
76 
88  EV_K_STOPPED, // #2 Calls after event manager stopped
89 
101  EV_K_CONNECTED, // #3 New peer connected to host
102 
114  EV_K_DISCONNECTED, // #4 A peer was disconnected from host
115 
128  EV_K_RECEIVED, // #5 This host Received a data
130 
144 
159 
171  EV_K_TERM_STARTED, // #13 After terminal started (in place to define commands
172 
185  EV_K_CQUE_CALLBACK, // #14 Teonet Callback QUEUE event
186 
191 
194 
198 
200 
202 
204 
219  EV_A_INTERVAL, // #27 Angular interval event happened
220 
222 
224 
225  EV_K_APP_USER = 0x8000
226 
228 
232 typedef struct ksnetEvMgrAppParam {
233 
234  int app_argc;
235  const char **app_argv;
236  const char **app_descr;
237 
239 
240 
241 
245 typedef struct ksnetEvMgrClass {
246 
247  // Pointers to Modules classes
248  void *km;
260 
262 
265 
267 
269 
271 
273  uint32_t timer_val;
274  uint32_t idle_count;
276  void (*event_cb)(struct ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data);
277  struct ev_loop *ev_loop;
278 
279  // Event Manager Watchers
280  ev_idle idle_w;
282  ev_timer timer_w;
283  ev_async sig_async_w;
284  ev_idle idle_async_w;
285 
288 
289  PblList* async_queue;
290  pthread_mutex_t async_mutex;
291  pthread_mutex_t printf_mutex;
292 
293  size_t net_idx;
294  void *n_prev;
295  void *n_next;
296  size_t net_count;
297 
298  // Define signals watchers
299  ev_signal sigint_w;
300  ev_signal sigterm_w;
301  ev_signal sigsegv_w;
302  ev_signal sigabrt_w;
303  #ifndef HAVE_MINGW
304  ev_signal sigquit_w;
305  ev_signal sigkill_w;
306  ev_signal sigstop_w;
307  #endif
308 
309  void *user_data;
310  void *teo_class;
311 
312  struct cli_def *cli;
313 
314  int argc;
315  char** argv;
316 
317  char *app_type;
318  char *app_version;
319 
320  bool is_rhost;
321 
323 
327 
328 #define EVENT_MANAGER_OBJECT(X) _Generic((X), \
329  ksnCommandClass* : __ke_from_command_class, \
330  ksnLNullClass * : __ke_from_L0_class) (X)
331 
332 #define ARP_TABLE_OBJECT(X) _Generic((X), \
333  ksnCommandClass* : __arp_from_command_class) (X)
334 
339  void *data, size_t data_len, void *user_data);
340 
344 typedef struct stdin_idle_data {
345 
347  void *data;
348  ev_io *stdin_w;
349 
351 
352 typedef void (*ksn_event_cb_type)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data);
353 
354 #ifdef __cplusplus
355 extern "C" {
356 #endif
357 
358 
360  int argc, char** argv,
361  //void (*event_cb)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data),
363  int options
364 );
366  int argc, char** argv,
367  //void (*event_cb)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data),
368  ksn_event_cb_type event_cb,
369  int options,
370  int port,
371  void *user_data
372 );
374 int ksnetEvMgrFree(ksnetEvMgrClass *ke, int free_async);
375 #ifdef TEO_THREAD
376 int ksnetEvMgrRunThread(ksnetEvMgrClass *ke);
377 #endif
380 int ksnetEvMgrRestart(int argc, char **argv);
381 void ksnetEvMgrAsync(ksnetEvMgrClass *ke, void *data, size_t data_len, void *user_data);
384 host_info_data *teoGetHostInfo(ksnetEvMgrClass *ke, size_t *hd_len);
385 void ksnetEvMgrSetCustomTimer(ksnetEvMgrClass *ke, double time_interval);
386 
387 const char *teoGetLibteonetVersion();
388 void teoSetAppType(ksnetEvMgrClass *ke, char *type);
389 void teoSetAppVersion(ksnetEvMgrClass *ke, char *version);
390 const char *teoGetAppType(ksnetEvMgrClass *ke);
391 char *teoGetFullAppTypeFromHostInfo(host_info_data *hid);
392 const char *teoGetAppVersion(ksnetEvMgrClass *ke);
393 int remove_peer_addr(ksnetEvMgrClass *ke, __CONST_SOCKADDR_ARG addr);
394 int ksnetAllowAckEvent(ksnetEvMgrClass* ke, int allow);
395 
396 #ifdef __cplusplus
397 }
398 #endif
399 
400 #endif /* EV_MGR_H */
KSNet mesh core data.
Definition: net_core.h:38
#0x8000 Teonet based Applications events
Definition: ev_mgr.h:225
#15 After stream connected
Definition: ev_mgr.h:187
teoAsyncClass * ta
Async calls module.
Definition: ev_mgr.h:268
void * n_next
Next network.
Definition: ev_mgr.h:295
ksnetEvMgrClass * __ke_from_L0_class(ksnLNullClass *X)
Definition: ev_mgr.c:46
size_t net_count
Count of networks.
Definition: ev_mgr.h:296
const char * teoGetLibteonetVersion()
Get teonet library version.
Definition: ev_mgr.c:249
File: net_arp.h Author: Kirill Scherba kirill@scherba.ru
Definition: net_arp.h:24
#4 A peer was disconnected from host
Definition: ev_mgr.h:114
int argc
Applications argc.
Definition: ev_mgr.h:314
#25 UNIX socket received data event, data - data received from unix socket, user_data - pointer to th...
Definition: ev_mgr.h:201
#23 New clients visit event to all subscribers (equal to L0_CONNECTED but send number of visits) ...
Definition: ev_mgr.h:197
ksnVpnClass * kvpn
VPN class.
Definition: ev_mgr.h:251
double last_custom_timer
Last time the custom timer called.
Definition: ev_mgr.h:287
ev_idle idle_w
Idle TIMER watcher.
Definition: ev_mgr.h:280
const char * teoGetAppType(ksnetEvMgrClass *ke)
Get current application type.
Definition: ev_mgr.c:214
char * teoGetFullAppTypeFromHostInfo(host_info_data *hid)
Definition: ev_mgr.c:219
double ksnetEvMgrGetTime(ksnetEvMgrClass *ke)
Get KSNet event manager time.
Definition: ev_mgr.c:701
void ksnetEvMgrStop(ksnetEvMgrClass *ke)
Stop event manager.
Definition: ev_mgr.c:259
ksnCQueClass * kq
Callback QUEUE class.
Definition: ev_mgr.h:257
EventManagerStatus
Definition: ev_mgr.h:41
const char data[]
Make it with: gcc -o post-callback post-callback.c -lcurl.
Definition: post-callback.c:23
struct stdin_idle_data stdin_idle_data
STDIN idle watcher data.
#29 LogReader read data.
Definition: ev_mgr.h:223
ev_idle idle_async_w
Async signal idle watcher.
Definition: ev_mgr.h:284
ksnetEvMgrClass * ksnetEvMgrInitPort(int argc, char **argv, ksn_event_cb_type event_cb, int options, int port, void *user_data)
Initialize KSNet Event Manager and network and set new default port.
Definition: ev_mgr.c:104
#13 After terminal started (in place to define commands
Definition: ev_mgr.h:171
int ksnetEvMgrRestart(int argc, char **argv)
Restart application.
Definition: ev_mgr.c:1093
struct ksnetEvMgrClass ksnetEvMgrClass
KSNet event manager functions data.
int runEventMgr
Run even manages (stop if 0)
Definition: ev_mgr.h:272
int ksnetAllowAckEvent(ksnetEvMgrClass *ke, int allow)
Allow or disallow send ACK event (EV_K_RECEIVED_ACK) to teonet event loop.
Definition: tr-udp.c:38
ev_signal sigkill_w
Signal SIGKILL watcher.
Definition: ev_mgr.h:305
#21 New L0 client connected to L0 server
Definition: ev_mgr.h:195
struct ev_loop * ev_loop
Event loop.
Definition: ev_mgr.h:277
#19 Subscribe answer command received
Definition: ev_mgr.h:192
ksnetEvMgrClass * ke
Definition: ev_mgr.h:346
teoMetricClass * tm
Metric send module.
Definition: ev_mgr.h:270
bool is_rhost
This host is rhost flag.
Definition: ev_mgr.h:320
double custom_timer_interval
Custom timer interval.
Definition: ev_mgr.h:286
Definition: metric.h:6
#12 Async event
Definition: ev_mgr.h:158
void(* event_cb_t)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data)
Event callback type.
Definition: ev_mgr.h:338
#22 A L0 client was disconnected from L0 server
Definition: ev_mgr.h:196
#16 Connection timeout
Definition: ev_mgr.h:188
PblList * async_queue
Async data queue.
Definition: ev_mgr.h:289
ev_signal sigabrt_w
Signal SIGABRT watcher.
Definition: ev_mgr.h:302
#18 Input stream has a data
Definition: ev_mgr.h:190
teonet_cfg teo_cfg
KSNet configuration.
Definition: ev_mgr.h:261
ev_signal sigterm_w
Signal SIGTERM watcher.
Definition: ev_mgr.h:300
ksnCQue Class structure definition
Definition: cque.h:18
File: teodb.h Author: Kirill Scherba kirill@scherba.ru
Definition: teodb.h:18
ksnLNullClass * kl
L0 Server class.
Definition: ev_mgr.h:253
void ksnetEvMgrSetCustomTimer(ksnetEvMgrClass *ke, double time_interval)
Set custom timer interval.
Definition: ev_mgr.c:559
Stream module class structure.
Definition: stream.h:78
ev_signal sigsegv_w
Signal SIGSEGV watcher.
Definition: ev_mgr.h:301
void * n_prev
Previouse network.
Definition: ev_mgr.h:294
int app_argc
Definition: ev_mgr.h:234
Teonet Async class data definition.
Definition: async_calls.h:16
#5 This host Received a data
Definition: ev_mgr.h:128
Application parameters user data.
Definition: ev_mgr.h:232
ksnTermClass * kter
Terminal class.
Definition: ev_mgr.h:256
ev_io * stdin_w
Definition: ev_mgr.h:348
#28 Logging server event, like EV_K_RECEIVED: data Pointer to ksnCorePacketData, data_len Size of ksn...
Definition: ev_mgr.h:221
int ksnetEvMgrFree(ksnetEvMgrClass *ke, int free_async)
Free ksnetEvMgrClass after run.
Definition: ev_mgr.c:474
void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data)
Teonet event handler.
Definition: app/teodb.c:348
teoLoggingClientClass * lc
Logging client class // move it up after testing.
Definition: ev_mgr.h:264
ev_idle idle_activity_w
Idle Check activity watcher.
Definition: ev_mgr.h:281
void * user_data
Pointer to user data or NULL if absent.
Definition: ev_mgr.h:309
void * teo_class
Pointer to Teonet c++ Class (in c++ wrapper)
Definition: ev_mgr.h:310
#3 New peer connected to host event
Definition: ev_mgr.h:101
ev_signal sigstop_w
Signal SIGSTOP watcher.
Definition: ev_mgr.h:306
#2 Calls after event manager stopped
Definition: ev_mgr.h:88
Definition: conf.h:51
char * app_version
Application version.
Definition: ev_mgr.h:318
int ksnetEvMgrRun(ksnetEvMgrClass *ke)
Start KSNet Event Manager and network communication.
Definition: ev_mgr.c:301
#20 A peer subscribed to event at this host
Definition: ev_mgr.h:193
size_t net_idx
Network index.
Definition: ev_mgr.h:293
ksnStreamClass * ks
Stream class.
Definition: ev_mgr.h:259
#24 HTTP WebSocket server event, data - depends of event, user data - poiter to hws_event ...
Definition: ev_mgr.h:199
const char ** app_argv
Definition: ev_mgr.h:235
KSNet terminal module class data definition.
Definition: net_term.h:23
Definition: net_cli.h:43
uint32_t idle_count
Idle callback count.
Definition: ev_mgr.h:274
ksnetEvMgrClass * ksnetEvMgrInit(int argc, char **argv, ksn_event_cb_type event_cb, int options)
Initialize KSNet Event Manager and network.
Definition: ev_mgr.c:79
Teonet Logging client class data definition.
Definition: logging_client.h:16
pthread_mutex_t async_mutex
Async data queue mutex.
Definition: ev_mgr.h:290
ksnetArpClass * __arp_from_command_class(ksnCommandClass *X)
Definition: ev_mgr.c:48
ksnetHotkeysClass * kh
Hotkeys class.
Definition: ev_mgr.h:250
Hot keys class data.
Definition: hotkeys.h:81
int remove_peer_addr(ksnetEvMgrClass *ke, __CONST_SOCKADDR_ARG addr)
Remove peer by address.
Definition: ev_mgr.c:812
void teoSetAppType(ksnetEvMgrClass *ke, char *type)
Set Teonet application type.
Definition: ev_mgr.c:192
#10 Hotkey event
Definition: ev_mgr.h:156
void * data
Definition: ev_mgr.h:347
ksnetEvMgrEvents
KSNet event manager events.
Definition: ev_mgr.h:49
teoLoggingServerClass * ls
Logging server class // move it up after testing.
Definition: ev_mgr.h:263
ksnTDBClass * kf
PBL KeyFile class.
Definition: ev_mgr.h:258
#14 Teonet Callback QUEUE event
Definition: ev_mgr.h:185
void(* event_cb)(struct ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data)
Definition: ev_mgr.h:276
#1 Calls before event manager stopped
Definition: ev_mgr.h:75
#define ke
struct cli_def * cli
Definition: ev_mgr.h:312
pthread_mutex_t printf_mutex
Printf data queue mutex.
Definition: ev_mgr.h:291
#0 Calls immediately after event manager starts
Definition: ev_mgr.h:62
KSNet event manager functions data.
Definition: ev_mgr.h:245
ksnTunClass * ktun
Tunnel class.
Definition: ev_mgr.h:255
uint32_t timer_val
Event loop timer value.
Definition: ev_mgr.h:273
#8 Idle check host events (after 11.5 after last host send or receive data)
Definition: ev_mgr.h:142
void teoSetAppVersion(ksnetEvMgrClass *ke, char *version)
Set Teonet application version.
Definition: ev_mgr.c:203
KSNet command class data.
Definition: net_com.h:95
File: net_tun.h Author: Kirill Scherba.
Definition: net_tun.h:18
teoLogReaderClass * lr
Log reader class.
Definition: ev_mgr.h:266
char * app_type
Application type.
Definition: ev_mgr.h:317
ksnCoreClass * kc
KSNet core class.
Definition: ev_mgr.h:249
ksnTCPProxyClass * tp
TCP Proxy class.
Definition: ev_mgr.h:254
Definition: ev_mgr.h:42
#9 Timer event
Definition: ev_mgr.h:143
Definition: ev_mgr.h:43
ev_async sig_async_w
Async signal watcher.
Definition: ev_mgr.h:283
int ksnetEvMgrStatus(ksnetEvMgrClass *ke)
Definition: ev_mgr.c:263
#7 This host Received ACK to sent data
Definition: ev_mgr.h:141
void(* ksn_event_cb_type)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data)
Definition: ev_mgr.h:352
ksnTcpClass * kt
TCP Client/Server class.
Definition: ev_mgr.h:252
uint32_t idle_activity_count
Idle activity callback count.
Definition: ev_mgr.h:275
#26 Database updated
Definition: ev_mgr.h:203
ksnetEvMgrClass * __ke_from_command_class(ksnCommandClass *X)
Definition: ev_mgr.c:45
void * km
Pointer to multi net class.
Definition: ev_mgr.h:248
struct ksnetEvMgrAppParam ksnetEvMgrAppParam
Application parameters user data.
host_info_data * teoGetHostInfo(ksnetEvMgrClass *ke, size_t *hd_len)
Get host info data.
Definition: ev_mgr.c:584
const char * null_str
File: ev_mgr.h Author: Kirill Scherba kirill@scherba.ru
Definition: ev_mgr.c:39
#27 Angular interval event happened
Definition: ev_mgr.h:219
ksnLNull Class structure definition
Definition: l0-server.h:41
TCP Proxy class data.
Definition: tcp_proxy.h:87
ev_signal sigint_w
Signal SIGINT watcher.
Definition: ev_mgr.h:299
ev_timer timer_w
Timer watcher.
Definition: ev_mgr.h:282
char * ksnetEvMgrGetHostName(ksnetEvMgrClass *ke)
Return host name.
Definition: ev_mgr.c:571
File: vpn.h Author: Kirill Scherba.
Definition: vpn.h:22
Teonet Logging server class data definition.
Definition: logging_server.h:16
const char ** app_descr
Definition: ev_mgr.h:236
const char * teoGetAppVersion(ksnetEvMgrClass *ke)
Get current application version.
Definition: ev_mgr.c:239
#17 After stream disconnected
Definition: ev_mgr.h:189
char ** argv
Applications argv.
Definition: ev_mgr.h:315
ev_signal sigquit_w
Signal SIGQUIT watcher.
Definition: ev_mgr.h:304
#11 User press A hotkey
Definition: ev_mgr.h:157
Definition: log_reader.h:24
File: net_tcp.h Author: Kirill Scherba.
Definition: net_tcp.h:20
#6 Wrong packet received
Definition: ev_mgr.h:129
STDIN idle watcher data.
Definition: ev_mgr.h:344
void ksnetEvMgrAsync(ksnetEvMgrClass *ke, void *data, size_t data_len, void *user_data)
Async call to Event manager.
Definition: ev_mgr.c:672