design_pattern_for_c  V 1.00
chain_of_responsibility.h File Reference

This is API for Chain of Responsibility design pettern class. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct chain_element_partChainElementPart
 ChainElementPart class definition. More...
 
typedef cor_result_e(* chain_func) (void *arg, void *ctx)
 chain func More...
 

Enumerations

enum  cor_result_e { CoR_GONEXT, CoR_RETURN }
 chain_api result type More...
 

Functions

void cor_set_threadsafe (int is_threadsafe)
 set thredsafe More...
 
ChainElementPart cor_add_function (const int id, chain_func func, void *ctx)
 add to chain api More...
 
void cor_call (const int id, void *arg)
 call chain api More...
 
void cor_remove_function (const int id, chain_func func)
 remove to chain api More...
 
void cor_remove_chain_element_part (const int id, ChainElementPart element)
 remove to chain api More...
 
void cor_clear (void)
 clear all list More...
 

Detailed Description

This is API for Chain of Responsibility design pettern class.

Definition in file chain_of_responsibility.h.

Typedef Documentation

◆ chain_func

typedef cor_result_e(* chain_func) (void *arg, void *ctx)

chain func

Parameters
[in]arginput parameter pointer, related to function
[in]ctxcontext information registered at cor_add_function
Return values
CoR_GONEXT-> call next chain_api
CoR_RETURN-> exit to call chain_api

Definition at line 31 of file chain_of_responsibility.h.

◆ ChainElementPart

ChainElementPart class definition.

Definition at line 21 of file chain_of_responsibility.h.

Enumeration Type Documentation

◆ cor_result_e

chain_api result type

Enumerator
CoR_GONEXT 

go to next

CoR_RETURN 

exit to call chain_api

Definition at line 11 of file chain_of_responsibility.h.

Function Documentation

◆ cor_add_function()

ChainElementPart cor_add_function ( const int  id,
chain_func  func,
void *  ctx 
)

add to chain api

Parameters
[in]idkey id related to chain api
[in]funcchain func
[in]ctxuser defined context information
Return values
!=NULL-> Success to add, if you want to remove element, please keep it.
NULL-> Faled to add

Definition at line 90 of file chain_of_responsibility.c.

Here is the call graph for this function:

◆ cor_call()

void cor_call ( const int  id,
void *  arg 
)

call chain api

Parameters
[in]idkey id related to chain api
[in]arginput parameter pointer, related to function
Returns
none. If you want to get result, please define input parameter to know result

Definition at line 112 of file chain_of_responsibility.c.

Here is the call graph for this function:

◆ cor_clear()

void cor_clear ( void  )

clear all list

Returns
none

Definition at line 144 of file chain_of_responsibility.c.

Here is the call graph for this function:

◆ cor_remove_chain_element_part()

void cor_remove_chain_element_part ( const int  id,
ChainElementPart  element 
)

remove to chain api

Parameters
[in]idkey id related to chain api
[in]elementchain element returned at cor_add_function
Returns
none
Note
This function only remove element. So if you want to register same functions, and remove only one element, please use it.
This function "NOT" free ctx

Definition at line 133 of file chain_of_responsibility.c.

Here is the call graph for this function:

◆ cor_remove_function()

void cor_remove_function ( const int  id,
chain_func  func 
)

remove to chain api

Parameters
[in]idkey id related to chain api
[in]funcchain api func
Returns
none
Note
This function remove all functions which is same address. So if you set same function by cor_add_function, all of them will remove.
This function "NOT" free ctx

Definition at line 122 of file chain_of_responsibility.c.

Here is the call graph for this function:

◆ cor_set_threadsafe()

void cor_set_threadsafe ( int  is_threadsafe)

set thredsafe

Parameters
[in]is_threadsafe1 if you want to use threadsafe.
Returns
none

Definition at line 86 of file chain_of_responsibility.c.