Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cque.h File Reference
#include <ev.h>
#include <pbl.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ksnCQueClass
 ksnCQue Class structure definition More...
 
struct  ksnCQueData
 ksnCQue data structure More...
 

Typedefs

typedef struct ksnCQueClass ksnCQueClass
 ksnCQue Class structure definition More...
 
typedef void(* ksnCQueCallback )(uint32_t id, int type, void *data)
 ksnCQue callback function definition More...
 
typedef struct ksnCQueData ksnCQueData
 ksnCQue data structure More...
 
typedef int(* ksnCQueCompare )(void *find, void *data)
 Find data in CQueue callback function. More...
 

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...
 
void * ksnCQueGetData (ksnCQueClass *kq, uint32_t id)
 Get callback queue data. More...
 
int ksnCQueSetData (ksnCQueClass *kq, uint32_t id, void *data)
 Set callback queue data, update data set in ksnCQueAdd. More...
 
ksnCQueDataksnCQueAdd (ksnCQueClass *kq, ksnCQueCallback cb, double timeout, void *data)
 Add callback to queue. More...
 
int ksnCQueRemove (ksnCQueClass *kq, uint32_t id)
 Remove callback from 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...
 

Typedef Documentation

typedef void(* ksnCQueCallback)(uint32_t id, int type, void *data)

ksnCQue callback function definition

Parameters
idCalls ID
typeType: 0 - timeout callback; 1 - successful callback
dataUser data selected in ksnCQueAdd() function
typedef struct ksnCQueClass ksnCQueClass

ksnCQue Class structure definition

typedef int(* ksnCQueCompare)(void *find, void *data)

Find data in CQueue callback function.

typedef struct ksnCQueData ksnCQueData

ksnCQue data structure

Function Documentation

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

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

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().