Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
net_multi.c File Reference
#include <stdlib.h>
#include <string.h>
#include "net_multi.h"
#include "utils/rlutil.h"
#include "utils/teo_memory.h"

Macros

#define add_line()
 

Functions

ksnMultiClassksnMultiInit (ksnMultiData *md, void *user_data)
 Initialize ksnMultiClass object. More...
 
void teoMultiRun (ksnMultiClass *km)
 Start teonet event loop (for all functions added with ksnMultiInit) More...
 
void teoMultiAddNet (ksnMultiClass *km, ksn_event_cb_type e_cb, const char *host, int port, const char *network, void *user_data)
 Add new network. More...
 
void teoMultiRemoveNet (ksnMultiClass *km, const char *network)
 Remove network. More...
 
void ksnMultiDestroy (ksnMultiClass *km)
 Destroy ksnMultiClass object and running networks. More...
 
ksnetEvMgrClassteoMultiGetByNumber (ksnMultiClass *km, int number)
 Get network by number. More...
 
ksnetEvMgrClassteoMultiGetByNetwork (ksnMultiClass *km, char *network_name)
 Get network by network name. More...
 
bool teoMultiIsNetworkExist (ksnMultiClass *km, int number)
 Check if network with input number is exist. More...
 
void ksnMultiSetNumNets (ksnMultiClass *km, int num)
 Set number of networks to all modules list networks. More...
 
char * ksnMultiShowListStr (ksnMultiClass *km)
 Show list of networks. More...
 
ksnet_arp_data * teoMultiSendCmdToNet (ksnMultiClass *km, char *peer, char *network, uint8_t cmd, void *data, size_t data_len)
 Send command by name (or type) and by network. More...
 
ksnet_arp_data * ksnMultiSendCmdTo (ksnMultiClass *km, char *to, uint8_t cmd, void *data, size_t data_len)
 : It will be new function for broadcast sending Send command by name to peer More...
 

Macro Definition Documentation

#define add_line ( )
Value:
str = ksnet_sformatMessage(str, "%s" \
"------------------------------------------------------------------\n",\
str)
char * ksnet_sformatMessage(char *str_to_free, const char *fmt,...)
Create formated message in new null terminated string, and free str_to_free.
Definition: utils.c:249

Referenced by ksnMultiShowListStr().

Function Documentation

void ksnMultiDestroy ( ksnMultiClass km)

Destroy ksnMultiClass object and running networks.

Parameters
kmPointer to ksnMultiClass
Examples:
teomulti.c.

References free(), ksnetEvMgrFree(), ksnetEvMgrRestart(), ksnetEvMgrStop(), ksnMultiClass::last_net_idx, ksnMultiClass::list, and teoMultiGetByNumber().

Referenced by main(), and sigusr2_cb().

ksnet_arp_data* ksnMultiSendCmdTo ( ksnMultiClass km,
char *  to,
uint8_t  cmd,
void *  data,
size_t  data_len 
)

: It will be new function for broadcast sending Send command by name to peer

Parameters
kmPointer to ksnMultiClass
toRecipient peer name
cmdCommand
dataCommand data
data_lenData length
Returns
Pointer to ksnet_arp_data or NULL if not found

Referenced by ksnCoreSendCmdto().

void ksnMultiSetNumNets ( ksnMultiClass km,
int  num 
)

Set number of networks to all modules list networks.

Parameters
kmPointer to ksnMultiClass
numNumber of networks

References ke, ksnMultiClass::list, and ksnMultiClass::net_count.

char* ksnMultiShowListStr ( ksnMultiClass km)

Show list of networks.

Parameters
kmPointer to ksnMultiClass
Returns
Pointer to string, should be free after use

References add_line, ke, ksnet_formatMessage(), ksnet_sformatMessage(), LIGHTCYAN, LIGHTGREEN, ksnMultiClass::list, and NONE.

Referenced by hotkeys_cb().

void teoMultiAddNet ( ksnMultiClass km,
ksn_event_cb_type  e_cb,
const char *  host,
int  port,
const char *  network,
void *  user_data 
)
ksnetEvMgrClass* teoMultiGetByNetwork ( ksnMultiClass km,
char *  network_name 
)

Get network by network name.

Parameters
kmPointer to ksnMultiClass
network_nameNetwork name
Returns
Pointer to ksnetEvMgrClass or NULL if not found

References ke, and ksnMultiClass::list.

ksnetEvMgrClass* teoMultiGetByNumber ( ksnMultiClass km,
int  number 
)

Get network by number.

Parameters
kmPointer to ksnMultiClass
numNumber of network
Returns
Pointer to ksnetEvMgrClass

References ke, and ksnMultiClass::list.

Referenced by ksnMultiDestroy(), teoMultiAddNet(), and teoMultiRun().

bool teoMultiIsNetworkExist ( ksnMultiClass km,
int  number 
)

Check if network with input number is exist.

Parameters
kmPointer to ksnMultiClass
numNumber of network
Returns
true if network with input number is exist

References ke, and ksnMultiClass::list.

Referenced by hotkeys_cb().

void teoMultiRemoveNet ( ksnMultiClass km,
const char *  network 
)

Remove network.

Parameters
kmPointer to ksnMultiClass
networkNetwork name

References free(), ke, ksnetEvMgrFree(), ksnetEvMgrStop(), ksnMultiClass::list, and ksnMultiClass::net_count.

void teoMultiRun ( ksnMultiClass km)

Start teonet event loop (for all functions added with ksnMultiInit)

Parameters
kmPointer to ksnMultiClass
Examples:
teomulti.c.

References ksnetEvMgrClass::ev_loop, ksnMultiClass::last_net_idx, and teoMultiGetByNumber().

Referenced by main().

ksnet_arp_data* teoMultiSendCmdToNet ( ksnMultiClass km,
char *  peer,
char *  network,
uint8_t  cmd,
void *  data,
size_t  data_len 
)

Send command by name (or type) and by network.

Parameters
kmPointer to ksnMultiClass
peerPeer name
networkNetwork name
cmdCommand ID
dataPointer to data
data_lenData length
Returns
Pointer to ksnet_arp_data or NULL if network not found or peer not found in arp table of selected network

References ke, ksnCoreSendCmdto(), and ksnMultiClass::list.