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

Macros

#define kev   ((ksnetEvMgrClass*)(kq->ke))
 
#define cq   ((ksnCQueData*)(w->data))
 
#define kev2   ((ksnetEvMgrClass*)(cq->kq->ke))
 

Functions

ksnCQueClassksnCQueInit (void *ke, uint8_t send_event)
 Initialize ksnCQue module class. More...
 
void ksnCQueDestroy (ksnCQueClass *kq)
 Destroy ksnCQue module class. More...
 
int ksnCQueExec (ksnCQueClass *kq, uint32_t id)
 Execute callback queue record. More...
 
int ksnCQueRemove (ksnCQueClass *kq, uint32_t id)
 Remove callback from queue. More...
 
int ksnCQueSetData (ksnCQueClass *kq, uint32_t id, void *data)
 Set callback queue data, update data set in ksnCQueAdd. More...
 
void * ksnCQueGetData (ksnCQueClass *kq, uint32_t id)
 Get callback queue data. More...
 
void cq_timer_cb (EV_P_ ev_timer *w, int revents)
 Callback Queue timeout timer callback. More...
 
ksnCQueDataksnCQueAdd (ksnCQueClass *kq, ksnCQueCallback cb, double timeout, void *data)
 Add callback to queue. More...
 
void * ksnCQueFindData (ksnCQueClass *kq, void *find, ksnCQueCompare compare, size_t *key_length)
 Find data in CQue. More...
 
void * pblMapRemoveFree (PblMap *map, void *key, size_t keyLength, size_t *valueLengthPtr)
 Removes the mapping for this key from this map if it is present. More...
 

Detailed Description

Author
Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru

Manage Callback QUEUE class ksnCQueClass module

Callback QUEUE used to organize async calls to any functions.

Main module functions:

See example: teocque.c

See test: test_cque.c

Created on August 21, 2015, 12:10 PM

Macro Definition Documentation

#define kev   ((ksnetEvMgrClass*)(kq->ke))
#define kev2   ((ksnetEvMgrClass*)(cq->kq->ke))

Referenced by cq_timer_cb().

Function Documentation

void cq_timer_cb ( EV_P_ ev_timer *  w,
int  revents 
)

Callback Queue timeout timer callback.

Parameters
wEvent manager loop and watcher
reventsReserved (not used)

References cq, EV_K_CQUE_CALLBACK, kev2, and pblMapRemoveFree().

Referenced by ksnCQueAdd().

ksnCQueData* ksnCQueAdd ( ksnCQueClass kq,
ksnCQueCallback  cb,
double  timeout,
void *  data 
)

Add callback to queue.

Parameters
kqPointer to ksnCQueClass
cbCallback function or NULL. The teonet event EV_K_CQUE_CALLBACK should be send at the same time.
timeoutCallback timeout. If equal to 0 than timeout sets automatically
dataThe user data which should be send to the Callback function
Returns
Pointer to added ksnCQueData or NULL if error occurred
Examples:
teocque.c, and teodb_ex.c.

References ksnCQueData::cb, cq, cq_timer_cb(), ksnCQueClass::cque_map, data, ksnCQueData::data, ksnCQueClass::id, ksnCQueData::id, kev, ksnCQueData::kq, ksnCQueData::timeout, and ksnCQueData::w.

Referenced by _check_connected(), teo::Teonet::CQue::add(), event_cb(), get_cb(), ksnCoreCheckNewPeer(), ksnStreamCreate(), peer_type_cb(), test_4_2(), and test_4_3().

void ksnCQueDestroy ( ksnCQueClass kq)

Destroy ksnCQue module class.

Parameters
kqPointer to ksnCQueClass

References ksnCQueClass::cque_map, and free().

Referenced by modules_destroy(), test_4_1(), test_4_2(), test_4_3(), and teo::Teonet::CQue::~CQue().

int ksnCQueExec ( ksnCQueClass kq,
uint32_t  id 
)

Execute callback queue record.

Get callback queue record and remove it from queue

Parameters
kqPointer to ksnCQueClass
idRequired ID
Returns
return 0: if callback executed OK; !=0 some error occurred
Examples:
teocque.c, and teodb_ex.c.

References ksnCQueData::cb, cq, ksnCQueClass::cque_map, ksnCQueData::data, EV_K_CQUE_CALLBACK, ksnCQueClass::event_f, kev, ksnCQueData::kq, pblMapRemoveFree(), ksnCQueData::timeout, and ksnCQueData::w.

Referenced by event_cb(), teo::Teonet::CQue::exec(), ksnStreamCreate(), and test_4_3().

void* ksnCQueFindData ( ksnCQueClass kq,
void *  find,
ksnCQueCompare  compare,
size_t *  key_length 
)

Find data in CQue.

Parameters
kqPointer to ksnCQueClass
findPointer to data to find
compareCallback compare function int compare(void* find, void* data) which return pointer to key if data find or NULL in other way
key_length[out] Pointer to key_length variable or NULL if not need it
Returns

References ksnCQueClass::cque_map, data, and ksnCQueData::data.

Referenced by teo::Teonet::CQue::find().

void* ksnCQueGetData ( ksnCQueClass kq,
uint32_t  id 
)

Get callback queue data.

Parameters
kqPointer to ksnCQueClass
idExisting callback queue ID
Returns
return Pointer to callback queue records data

References cq, ksnCQueClass::cque_map, and ksnCQueData::data.

Referenced by teo::Teonet::CQue::getCQueData(), and teo::Teonet::CQue::setUserData().

ksnCQueClass* ksnCQueInit ( void *  ke,
uint8_t  send_event 
)

Initialize ksnCQue module class.

Parameters
kePointer to ksnetEvMgrClass
send_eventSend cque event if true
Returns
Pointer to created ksnCQueClass or NULL if error occurred

References ksnCQueClass::cque_map, ksnCQueClass::event_f, ksnCQueClass::id, ksnCQueClass::ke, ke, and malloc().

Referenced by modules_init(), test_4_1(), test_4_2(), and test_4_3().

int ksnCQueRemove ( ksnCQueClass kq,
uint32_t  id 
)

Remove callback from queue.

Parameters
kqPointer to ksnCQueClass
idRequired ID
Returns
return 0: if callback removed OK; !=0 some error occurred

References cq, ksnCQueClass::cque_map, kev, pblMapRemoveFree(), ksnCQueData::timeout, and ksnCQueData::w.

Referenced by teo::Teonet::CQue::remove().

int ksnCQueSetData ( ksnCQueClass kq,
uint32_t  id,
void *  data 
)

Set callback queue data, update data set in ksnCQueAdd.

Parameters
kqPointer to ksnCQueClass
idExisting callback queue ID
dataPointer to callback queue records data
Returns
return 0: if callback executed OK; !=0 some error occurred

References cq, ksnCQueClass::cque_map, data, and ksnCQueData::data.

void* pblMapRemoveFree ( PblMap *  map,
void *  key,
size_t  keyLength,
size_t *  valueLengthPtr 
)

Removes the mapping for this key from this map if it is present.

Parameters
map
key
keyLength
valueLengthPtr
Returns
Return values
!=NULL && != (void*)-1: successfully removed
==NULL: there was no mapping for key
==(void*)-1: An error, see pbl_errno:
PBL_ERROR_OUT_OF_MEMORY - Out of memory.

References free().

Referenced by cq_timer_cb(), ksnCQueExec(), ksnCQueRemove(), ksnLNullClientDisconnect(), ksnSplitCombine(), ksnStreamClose(), and ksnTCPProxyServerClientDisconnect().