Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev_mgr.h File Reference
#include <unistd.h>
#include <pthread.h>
#include <ev.h>
#include "config/opt.h"
#include "config/conf.h"
#include "utils/utils.h"
#include "hotkeys.h"
#include "modules/vpn.h"
#include "modules/cque.h"
#include "modules/teodb.h"
#include "modules/stream.h"
#include "modules/metric.h"
#include "modules/net_tcp.h"
#include "modules/net_tun.h"
#include "modules/net_term.h"
#include "modules/tcp_proxy.h"
#include "modules/l0-server.h"
#include "modules/log_reader.h"
#include "modules/async_calls.h"
#include "modules/logging_server.h"
#include "modules/logging_client.h"

Go to the source code of this file.

Data Structures

struct  ksnetEvMgrAppParam
 Application parameters user data. More...
 
struct  ksnetEvMgrClass
 KSNet event manager functions data. More...
 
struct  stdin_idle_data
 STDIN idle watcher data. More...
 

Macros

#define NULL_STR   (void*) null_str
 
#define CHECK_EVENTS_AFTER   11.5
 
#define EVENT_MANAGER_OBJECT(X)
 
#define ARP_TABLE_OBJECT(X)
 

Typedefs

typedef enum ksnetEvMgrEvents ksnetEvMgrEvents
 KSNet event manager events. More...
 
typedef struct ksnetEvMgrAppParam ksnetEvMgrAppParam
 Application parameters user data. More...
 
typedef struct ksnetEvMgrClass ksnetEvMgrClass
 KSNet event manager functions data. More...
 
typedef void(* event_cb_t )(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data)
 Event callback type. More...
 
typedef struct stdin_idle_data stdin_idle_data
 STDIN idle watcher data. More...
 
typedef void(* ksn_event_cb_type )(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data)
 

Enumerations

enum  EventManagerStatus { kEventMgrStopped = 0, kEventMgrRunning = 1 }
 
enum  ksnetEvMgrEvents {
  EV_K_STARTED, EV_K_STOPPED_BEFORE, EV_K_STOPPED, EV_K_CONNECTED,
  EV_K_DISCONNECTED, EV_K_RECEIVED, EV_K_RECEIVED_WRONG, EV_K_RECEIVED_ACK,
  EV_K_IDLE, EV_K_TIMER, EV_K_HOTKEY, EV_K_USER,
  EV_K_ASYNC, EV_K_TERM_STARTED, EV_K_CQUE_CALLBACK, EV_K_STREAM_CONNECTED,
  EV_K_STREAM_CONNECT_TIMEOUT, EV_K_STREAM_DISCONNECTED, EV_K_STREAM_DATA, EV_K_SUBSCRIBE,
  EV_K_SUBSCRIBED, EV_K_L0_CONNECTED, EV_K_L0_DISCONNECTED, EV_K_L0_NEW_VISIT,
  EV_H_HWS_EVENT, EV_U_RECEIVED, EV_D_SET, EV_A_INTERVAL,
  EV_K_LOGGING, EV_K_LOG_READER, EV_K_APP_USER = 0x8000
}
 KSNet event manager events. More...
 

Functions

ksnetEvMgrClass__ke_from_command_class (ksnCommandClass *X)
 
ksnetEvMgrClass__ke_from_L0_class (ksnLNullClass *X)
 
ksnetArpClass__arp_from_command_class (ksnCommandClass *X)
 
ksnetEvMgrClassksnetEvMgrInit (int argc, char **argv, ksn_event_cb_type event_cb, int options)
 Initialize KSNet Event Manager and network. More...
 
ksnetEvMgrClassksnetEvMgrInitPort (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. More...
 
int ksnetEvMgrRun (ksnetEvMgrClass *ke)
 Start KSNet Event Manager and network communication. More...
 
int ksnetEvMgrFree (ksnetEvMgrClass *ke, int free_async)
 Free ksnetEvMgrClass after run. More...
 
void ksnetEvMgrStop (ksnetEvMgrClass *ke)
 Stop event manager. More...
 
int ksnetEvMgrStatus (ksnetEvMgrClass *ke)
 
int ksnetEvMgrRestart (int argc, char **argv)
 Restart application. More...
 
void ksnetEvMgrAsync (ksnetEvMgrClass *ke, void *data, size_t data_len, void *user_data)
 Async call to Event manager. More...
 
double ksnetEvMgrGetTime (ksnetEvMgrClass *ke)
 Get KSNet event manager time. More...
 
char * ksnetEvMgrGetHostName (ksnetEvMgrClass *ke)
 Return host name. More...
 
host_info_data * teoGetHostInfo (ksnetEvMgrClass *ke, size_t *hd_len)
 Get host info data. More...
 
void ksnetEvMgrSetCustomTimer (ksnetEvMgrClass *ke, double time_interval)
 Set custom timer interval. More...
 
const char * teoGetLibteonetVersion ()
 Get teonet library version. More...
 
void teoSetAppType (ksnetEvMgrClass *ke, char *type)
 Set Teonet application type. More...
 
void teoSetAppVersion (ksnetEvMgrClass *ke, char *version)
 Set Teonet application version. More...
 
const char * teoGetAppType (ksnetEvMgrClass *ke)
 Get current application type. More...
 
char * teoGetFullAppTypeFromHostInfo (host_info_data *hid)
 
const char * teoGetAppVersion (ksnetEvMgrClass *ke)
 Get current application version. More...
 
int remove_peer_addr (ksnetEvMgrClass *ke, __CONST_SOCKADDR_ARG addr)
 Remove peer by address. More...
 
int ksnetAllowAckEvent (ksnetEvMgrClass *ke, int allow)
 Allow or disallow send ACK event (EV_K_RECEIVED_ACK) to teonet event loop. More...
 

Variables

const char * null_str
 File: ev_mgr.h Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru More...
 

Macro Definition Documentation

#define ARP_TABLE_OBJECT (   X)
Value:
_Generic((X), \
ksnetArpClass * __arp_from_command_class(ksnCommandClass *X)
Definition: ev_mgr.c:48
KSNet command class data.
Definition: net_com.h:95

Referenced by cmd_disconnected_cb().

#define CHECK_EVENTS_AFTER   11.5

Referenced by check_connected_cb(), and timer_cb().

#define EVENT_MANAGER_OBJECT (   X)
Value:
_Generic((X), \
ksnetEvMgrClass * __ke_from_L0_class(ksnLNullClass *X)
Definition: ev_mgr.c:46
KSNet command class data.
Definition: net_com.h:95
ksnetEvMgrClass * __ke_from_command_class(ksnCommandClass *X)
Definition: ev_mgr.c:45
ksnLNull Class structure definition
Definition: l0-server.h:41

Referenced by _check_connected(), cmd_disconnected_cb(), cmd_l0_check_cb(), cmd_l0_kick_client(), cmd_reconnect_cb(), ksnCommandCheck(), ksnCommandEchoBuffer(), ksnCommandSendCmdConnect(), ksnCommandSendCmdConnectA(), ksnCommandSendCmdEcho(), ksnLNullClientDisconnect(), ksnLNullClientsList(), ksnLNullPacketSend(), ksnLNulltrudpCheckPaket(), and teoLNullPacketCheckMiscrypted().

#define NULL_STR   (void*) null_str

Referenced by open_local_port().

Typedef Documentation

typedef void(* event_cb_t)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data)

Event callback type.

typedef void(* ksn_event_cb_type)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data)

Application parameters user data.

KSNet event manager functions data.

KSNet event manager events.

STDIN idle watcher data.

Enumeration Type Documentation

Enumerator
kEventMgrStopped 
kEventMgrRunning 

KSNet event manager events.

Enumerator
EV_K_STARTED 

#0 Calls immediately after event manager starts

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataNULL
data_len0
user_dataNULL
EV_K_STOPPED_BEFORE 

#1 Calls before event manager stopped

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataNULL
data_len0
user_dataNULL
EV_K_STOPPED 

#2 Calls after event manager stopped

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataNULL
data_len0
user_dataNULL
EV_K_CONNECTED 

#3 New peer connected to host event

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataPointer to ksnCorePacketData
data_lenSize of ksnCorePacketData
user_dataNULL
EV_K_DISCONNECTED 

#4 A peer was disconnected from host

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataPointer to ksnCorePacketData
data_lenSize of ksnCorePacketData
user_dataNULL
EV_K_RECEIVED 

#5 This host Received a data

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataPointer to ksnCorePacketData
data_lenSize of ksnCorePacketData
user_dataNULL
EV_K_RECEIVED_WRONG 

#6 Wrong packet received

EV_K_RECEIVED_ACK 

#7 This host Received ACK to sent data

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataPointer to ksnCorePacketData
data_lenSize of ksnCorePacketData
user_dataPointer to packet ID#7 This host Received ACK to sent data
EV_K_IDLE 

#8 Idle check host events (after 11.5 after last host send or receive data)

EV_K_TIMER 

#9 Timer event

EV_K_HOTKEY 

#10 Hotkey event

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataPointer to integer hotkey
data_lenSize of integer
user_dataPointer to raw keyboard input buffer#10 Hotkey event
EV_K_USER 

#11 User press A hotkey

EV_K_ASYNC 

#12 Async event

EV_K_TERM_STARTED 

#13 After terminal started (in place to define commands

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataNULL
data_len0
user_dataNULL
EV_K_CQUE_CALLBACK 

#14 Teonet Callback QUEUE event

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataPointer to ksnCQueData
data_lenSize of ksnCQueData structure
user_dataPointer to integer with type of this event: 1 - success; 0 - timeout
EV_K_STREAM_CONNECTED 

#15 After stream connected

EV_K_STREAM_CONNECT_TIMEOUT 

#16 Connection timeout

EV_K_STREAM_DISCONNECTED 

#17 After stream disconnected

EV_K_STREAM_DATA 

#18 Input stream has a data

EV_K_SUBSCRIBE 

#19 Subscribe answer command received

EV_K_SUBSCRIBED 

#20 A peer subscribed to event at this host

EV_K_L0_CONNECTED 

#21 New L0 client connected to L0 server

EV_K_L0_DISCONNECTED 

#22 A L0 client was disconnected from L0 server

EV_K_L0_NEW_VISIT 

#23 New clients visit event to all subscribers (equal to L0_CONNECTED but send number of visits)

EV_H_HWS_EVENT 

#24 HTTP WebSocket server event, data - depends of event, user data - poiter to hws_event

EV_U_RECEIVED 

#25 UNIX socket received data event, data - data received from unix socket, user_data - pointer to the usock_class

EV_D_SET 

#26 Database updated

EV_A_INTERVAL 

#27 Angular interval event happened

This event sends by Angular Teonet Service running in Teonet Node Application when Angular interval tick happened

Parameters of Teonet Events callback function:

Parameters
kePointer to ksnetEvMgrClass
eventThis event
dataNULL
data_len0
user_dataNULL
EV_K_LOGGING 

#28 Logging server event, like EV_K_RECEIVED: data Pointer to ksnCorePacketData, data_len Size of ksnCorePacketData, , user_data NULL

EV_K_LOG_READER 

#29 LogReader read data.

EV_K_APP_USER 

#0x8000 Teonet based Applications events

Function Documentation

ksnetArpClass* __arp_from_command_class ( ksnCommandClass X)

References ksnCommandClass::kc.

ksnetEvMgrClass* __ke_from_command_class ( ksnCommandClass X)

References ksnCommandClass::kc.

ksnetEvMgrClass* __ke_from_L0_class ( ksnLNullClass X)

References ksnLNullClass::ke.

int ksnetAllowAckEvent ( ksnetEvMgrClass ke,
int  allow 
)
inline

Allow or disallow send ACK event (EV_K_RECEIVED_ACK) to teonet event loop.

Parameters
kePointer to ksnetEvMgrClass
allowAllow if true or disallow (set by default)
Returns
Previous state
Examples:
teoack.c, and teoackm.c.

References teonet_cfg::send_ack_event_f, and ksnetEvMgrClass::teo_cfg.

Referenced by main().

void ksnetEvMgrAsync ( ksnetEvMgrClass ke,
void *  data,
size_t  data_len,
void *  user_data 
)

Async call to Event manager.

Parameters
kePointer to ksnetEvMgrClass
dataPointer to data
data_lenData length
user_dataPointer to user data

References ksnetEvMgrClass::async_mutex, ksnetEvMgrClass::async_queue, ksnetEvMgrClass::ev_loop, malloc(), and ksnetEvMgrClass::sig_async_w.

Referenced by teoLoggingClientSend().

char* ksnetEvMgrGetHostName ( ksnetEvMgrClass ke)
inline

Return host name.

Parameters
kePointer to ksnetEvMgrClass
Returns

References teonet_cfg::host_name, and ksnetEvMgrClass::teo_cfg.

Referenced by _check_connected(), event_cb(), teo::Teonet::getHostName(), ksnetEvMgrRun(), and teoGetHostInfo().

ksnetEvMgrClass* ksnetEvMgrInit ( int  argc,
char **  argv,
ksn_event_cb_type  event_cb,
int  options 
)

Initialize KSNet Event Manager and network.

Parameters
argcNumber of applications arguments (from main)
argvApplications arguments array (from main)
event_cbEvents callback function called when an event happens
optionsOptions set:
READ_OPTIONS - read options from command line parameters;
READ_CONFIGURATION - read options from configuration file
Returns
Pointer to created ksnetEvMgrClass

References ksnetEvMgrInitPort().

Referenced by main(), and test2().

ksnetEvMgrClass* ksnetEvMgrInitPort ( int  argc,
char **  argv,
void(*)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data)  event_cb,
int  options,
int  port,
void *  user_data 
)

Initialize KSNet Event Manager and network and set new default port.

Parameters
argcNumber of applications arguments (from main)
argvApplications arguments array (from main)
event_cbEvents callback function called when an event happens
optionsOptions set:
READ_OPTIONS - read options from command line parameters;
READ_CONFIGURATION - read options from configuration file
portSet default port number if non 0
user_dataPointer to user data or NULL if absent
Returns
Pointer to created ksnetEvMgrClass

References teonet_cfg::app_argc, teonet_cfg::app_argv, APP_PARAM, ksnetEvMgrClass::argc, ksnetEvMgrClass::argv, ksnetEvMgrClass::async_mutex, BLOCK_CLI_INPUT, teonet_cfg::block_cli_input_f, ksnetEvMgrClass::custom_timer_interval, ksnetEvMgrClass::ev_loop, ksnetEvMgrClass::event_cb, event_cb(), ke, ksnetEvMgrClass::kf, ksnetEvMgrClass::kl, ksnetEvMgrClass::km, ksnetEvMgrClass::ks, ksnet_configInit(), ksnet_optRead(), ksnet_optSetApp(), ksnetEvMgrClass::kt, ksnetEvMgrClass::last_custom_timer, malloc(), ksnetEvMgrClass::n_next, ksnetEvMgrClass::n_prev, ksnetEvMgrClass::net_count, ksnetEvMgrClass::net_idx, null_str, teonet_cfg::port, ksnetEvMgrClass::printf_mutex, read_config(), READ_CONFIGURATION, READ_OPTIONS, ksnetEvMgrClass::runEventMgr, teo_argc, teo_argv, ksnetEvMgrClass::teo_cfg, ksnetEvMgrClass::teo_class, ksnetEvMgrClass::tp, and ksnetEvMgrClass::user_data.

Referenced by ksnetEvMgrInit(), ksnMultiInit(), main(), teoMultiAddNet(), teo::Teonet::Teonet(), and teonet_t().

int ksnetEvMgrRestart ( int  argc,
char **  argv 
)

Restart application.

Parameters
argc
argv
Returns

References free(), ksnet_formatMessage(), ksnet_stringArrSplit(), and usleep().

Referenced by ksnetEvMgrFree(), ksnMultiDestroy(), and sigusr2_cb().

void ksnetEvMgrSetCustomTimer ( ksnetEvMgrClass ke,
double  time_interval 
)

Set custom timer interval.

Parameters
kePointer to ksnetEvMgrClass
time_interval

References ksnetEvMgrClass::custom_timer_interval, ksnetEvMgrGetTime(), and ksnetEvMgrClass::last_custom_timer.

Referenced by event_cb(), main(), and teo::Teonet::setCustomTimer().

int ksnetEvMgrStatus ( ksnetEvMgrClass ke)
void ksnetEvMgrStop ( ksnetEvMgrClass ke)
inline
int remove_peer_addr ( ksnetEvMgrClass ke,
__CONST_SOCKADDR_ARG  addr 
)

Remove peer by address.

Parameters
kePointer to ksnetEvMgrClass
addr
Returns
Return values
0peer not found
1peer removed
-1peer not removed, this is this host

References ksnCoreClass::ka, ksnetEvMgrClass::kc, and ksnetArpFindByAddr().

Referenced by trudp_event_cb().

const char* teoGetAppType ( ksnetEvMgrClass ke)
inline

Get current application type.

Parameters
kePointer to ksnetEvMgrClass
Returns
Application type string

References ksnetEvMgrClass::app_type.

Referenced by teoGetHostInfo().

const char* teoGetAppVersion ( ksnetEvMgrClass ke)
inline

Get current application version.

Parameters
kePointer to ksnetEvMgrClass
Returns
Application version string

References ksnetEvMgrClass::app_version.

Referenced by teoGetHostInfo().

char* teoGetFullAppTypeFromHostInfo ( host_info_data *  hid)
host_info_data* teoGetHostInfo ( ksnetEvMgrClass ke,
size_t *  hd_len 
)

Get host info data.

Parameters
kePointer to ksnetEvMgrClass
hd_lenPointer to host_info_data length holder
Returns
Pointer to host_info_data, should be free after use

References ksnetEvMgrGetHostName(), teonet_cfg::l0_allow_f, malloc(), null_str, ksnetEvMgrClass::teo_cfg, teoGetAppType(), teoGetAppVersion(), VERSION, and teonet_cfg::vpn_connect_f.

Referenced by createCmdConnectPacket(), createCmdConnectRPacketUdp(), and ksnetArpAddHost().

const char* teoGetLibteonetVersion ( )
inline

Get teonet library version.

Returns

References VERSION.

Referenced by teo::Teonet::getTeonetVersion(), and main().

void teoSetAppType ( ksnetEvMgrClass ke,
char *  type 
)
inline

Set Teonet application type.

Parameters
kePointer to ksnetEvMgrClass
typeApplication type string

References ksnetEvMgrClass::app_type.

Referenced by event_cb(), main(), and teo::Teonet::setAppType().

void teoSetAppVersion ( ksnetEvMgrClass ke,
char *  version 
)
inline

Set Teonet application version.

Parameters
kePointer to ksnetEvMgrClass
versionApplication version string

References ksnetEvMgrClass::app_version.

Referenced by event_cb(), main(), and teo::Teonet::setAppVersion().

Variable Documentation

const char* null_str

File: ev_mgr.h Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru

Created on April 11, 2015, 2:13 AM