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

Macros

#define MODULE   _ANSI_LIGHTGREEN "subscribe" _ANSI_NONE
 File: subscribe.c Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru More...
 
#define add_data_to_list(sscr_list, peer_name, e, c)
 
#define kev   ((ksnetEvMgrClass*) ((ksnCoreClass *) kco->kc)->ke)
 

Typedefs

typedef struct teoSScrMapData teoSScrMapData
 

Functions

teoSScrClassteoSScrInit (void *ke)
 Initialize teoSScr module. More...
 
void teoSScrSend (teoSScrClass *sscr, uint16_t ev, void *data, size_t data_length, uint8_t cmd)
 Send event and it data to all subscribers. More...
 
int teoSScrNumberOfSubscribers (teoSScrClass *sscr)
 Calculate number of subscriptions. More...
 
int teoSScrNumberOfEventSubscribers (teoSScrClass *sscr, uint16_t event)
 Calculate number of subscribers to particular event. More...
 
void teoSScrSubscription (teoSScrClass *sscr, char *peer_name, uint16_t ev, ksnet_arp_data *arp_data)
 Remote peer subscribed to event at this host. More...
 
int teoSScrUnSubscription (teoSScrClass *sscr, char *peer_name, uint16_t ev)
 Remote peer unsubscribed from event at this host. More...
 
const char * teoSScrSubscriptionList (teoSScrClass *sscr)
 Show peers subscribed to this host. More...
 
int teoSScrUnSubscriptionAll (teoSScrClass *sscr, char *peer_name)
 Unsubscribe peer_name from all events. More...
 
void teoSScrSubscribe (teoSScrClass *sscr, char *peer_name, uint16_t ev)
 Send command to subscribe this host to event at remote peer. More...
 
void teoSScrUnSubscribe (teoSScrClass *sscr, char *peer_name, uint16_t ev)
 Send command to unsubscribe this host from event at remote peer. More...
 
void teoSScrDestroy (teoSScrClass *sscr)
 Destroy teoSScr module. More...
 
int cmd_subscribe_cb (ksnCommandClass *kco, ksnCorePacketData *rd)
 Process CMD_SUBSCRIBE, CMD_UNSUBSCRIBE and CMD_SUBSCRIBE_ANSWER commands. More...
 

Macro Definition Documentation

#define add_data_to_list (   sscr_list,
  peer_name,
  e,
 
)
Value:
teoSScrListData *sscr_list_data = malloc(sizeof(teoSScrListData) + \
strlen(peer_name) + 1); \
strcpy(sscr_list_data->data, peer_name); \
sscr_list_data->cmd = c; \
sscr_list_data->ev = e; \
if(arp_data == NULL) { \
sscr_list_data->l0_f = 0; \
sscr_list_data->addr[0] = 0; \
sscr_list_data->port = 0; \
} \
else { \
sscr_list_data->l0_f = 1; \
strncpy(sscr_list_data->addr, arp_data->addr, sizeof(sscr_list_data->addr)); \
sscr_list_data->port = arp_data->port; \
} \
pblListAdd(sscr_list, (void*)sscr_list_data)
if(!(yy_init))
Definition: lexer-filter.c:653
teoSScr class list or CMD_SUBSCRIBE_ANSWER data
Definition: subscribe.h:29
void * malloc(YYSIZE_T)
char data[]
Remote peer name in list or data in CMD_SUBSCRIBE_ANSWER.
Definition: subscribe.h:36
char addr[ARP_TABLE_IP_SIZE]
L0 peer IP address.
Definition: subscribe.h:35

Referenced by teoSScrSubscription().

#define kev   ((ksnetEvMgrClass*) ((ksnCoreClass *) kco->kc)->ke)

Referenced by cmd_subscribe_cb().

#define MODULE   _ANSI_LIGHTGREEN "subscribe" _ANSI_NONE

File: subscribe.c Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru

Created on December 28, 2015, 1:31 PM Subscribe module

Subscribe remote peers to host events events

Referenced by teoSScrSend(), teoSScrSubscription(), and teoSScrUnSubscription().

Typedef Documentation

typedef struct teoSScrMapData teoSScrMapData

Function Documentation

int cmd_subscribe_cb ( ksnCommandClass kco,
ksnCorePacketData rd 
)
void teoSScrDestroy ( teoSScrClass sscr)

Destroy teoSScr module.

Parameters
sscrPointer to ksnCQueClass

References free(), and teoSScrClass::map.

Referenced by ksnCommandDestroy(), test_6_1(), and test_6_2().

teoSScrClass* teoSScrInit ( void *  ke)

Initialize teoSScr module.

Parameters
kePointer to ksnetEvMgrClass
Returns
Pointer to created teoSScrClass or NULL if error occurred

References teoSScrClass::ke, ke, malloc(), and teoSScrClass::map.

Referenced by ksnCommandInit(), test_6_1(), and test_6_2().

int teoSScrNumberOfEventSubscribers ( teoSScrClass sscr,
uint16_t  event 
)

Calculate number of subscribers to particular event.

Parameters
sscr
Returns

References teoSScrClass::map.

int teoSScrNumberOfSubscribers ( teoSScrClass sscr)

Calculate number of subscriptions.

Parameters
sscr
Returns

References teoSScrClass::map.

Referenced by teoSScrSubscription(), teoSScrUnSubscription(), and test_6_2().

void teoSScrSend ( teoSScrClass sscr,
uint16_t  ev,
void *  data,
size_t  data_length,
uint8_t  cmd 
)

Send event and it data to all subscribers.

Parameters
sscrPointer to teoSScrClass
evEvent
dataEvent data
data_lengthEvent data length
cmdCommand, used for EV_K_RECEIVED event to show received command
Examples:
teosscr.c.

References teoSScrListData::addr, CMD_SUBSCRIBE_ANSWER, teoSScrListData::data, DEBUG, free(), teoSScrClass::ke, ksn_printf, ksnCoreSendCmdto(), ksnLNullSendToL0(), teoSScrListData::l0_f, malloc(), teoSScrClass::map, MODULE, and teoSScrListData::port.

Referenced by _send_subscribe_event_connected(), _send_subscribe_event_disconnected(), _send_subscribe_event_newvisit(), cmd_disconnected_cb(), event_cb(), event_cb_server(), teo::Teonet::sendToSscr(), and teoSScrSendA().

void teoSScrSubscribe ( teoSScrClass sscr,
char *  peer_name,
uint16_t  ev 
)

Send command to subscribe this host to event at remote peer.

Parameters
sscrPointer to teoSScrClass
peer_nameRemote host name
evEvent
Examples:
teosscr.c.

References CMD_SUBSCRIBE, teoSScrClass::ke, and ksnCoreSendCmdto().

Referenced by event_cb_client(), teo::Teonet::subscribe(), and teoSScrSubscribeA().

void teoSScrSubscription ( teoSScrClass sscr,
char *  peer_name,
uint16_t  ev,
ksnet_arp_data *  arp_data 
)

Remote peer subscribed to event at this host.

Remote peer 'peer_name' has subscribed to the event 'ev' at this host

Parameters
sscrPointer to teoSScrClass
peer_nameRemote peer name
evEvent
arp_dataPointer to arp data if peer_name is L0 client, or NULL if it's a peer

References add_data_to_list, DEBUG, teoSScrClass::ke, ksn_printf, teoSScrClass::map, MODULE, teoSScrNumberOfSubscribers(), and teoSScrSubscriptionList().

Referenced by cmd_subscribe_cb(), and test_6_2().

const char* teoSScrSubscriptionList ( teoSScrClass sscr)
void teoSScrUnSubscribe ( teoSScrClass sscr,
char *  peer_name,
uint16_t  ev 
)

Send command to unsubscribe this host from event at remote peer.

Parameters
sscrPointer to teoSScrClass
peer_nameRemote host name
evEvent

References CMD_UNSUBSCRIBE, teoSScrClass::ke, and ksnCoreSendCmdto().

int teoSScrUnSubscription ( teoSScrClass sscr,
char *  peer_name,
uint16_t  ev 
)

Remote peer unsubscribed from event at this host.

Parameters
sscrPointer to teoSScrClass
peer_nameRemote peer name
evEvent
Returns
True if this peer_name and event was present and successfully removed
Examples:
teosscr.c.

References teoSScrListData::data, DEBUG, teoSScrListData::ev, teoSScrClass::ke, ksn_printf, teoSScrClass::map, MODULE, and teoSScrNumberOfSubscribers().

Referenced by cmd_subscribe_cb(), event_cb_server(), teoSScrUnSubscriptionAll(), and test_6_2().

int teoSScrUnSubscriptionAll ( teoSScrClass sscr,
char *  peer_name 
)

Unsubscribe peer_name from all events.

Parameters
sscr
peer_name
Returns

References teoSScrClass::map, and teoSScrUnSubscription().

Referenced by test_6_2().