design_pattern_for_c  V 1.00
chain_of_responsibility.c File Reference

Implement of Chain of Responsibility design petten library API. More...

#include "chain_of_responsibility.h"
#include "flyweight.h"
#include "chain_element.h"
#include "dp_util.h"
Include dependency graph for chain_of_responsibility.c:

Go to the source code of this file.

Data Structures

struct  chain_of_resp_t
 ChainElementPart class instance definition, which is a part of chain. More...
 
struct  chain_of_resp_mng_t
 management parameter of this class API, to use flyweight 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...
 

Variables

struct chain_of_resp_mng_t cor_mng_g
 

ChainOfResponsibility class

typedef struct chain_of_resp_tChainOfResponsibility
 
static void chain_of_resp_new (void *this, size_t size, void *input_parameter)
 new API More...
 
static int chain_of_resp_equall_operand (void *this, size_t size, void *input_parameter)
 equall operand, check name More...
 
static int chain_of_resp_setter (void *this, size_t size, void *input_parameter)
 setter, add function to ChainElement More...
 
static void chain_of_resp_free (void *this)
 free member resource More...
 

Detailed Description

Implement of Chain of Responsibility design petten library API.

Definition in file chain_of_responsibility.c.

Typedef Documentation

◆ ChainOfResponsibility

Definition at line 15 of file chain_of_responsibility.c.

Function Documentation

◆ chain_of_resp_equall_operand()

static int chain_of_resp_equall_operand ( void *  this,
size_t  size,
void *  input_parameter 
)
static

equall operand, check name

Definition at line 62 of file chain_of_responsibility.c.

◆ chain_of_resp_free()

static void chain_of_resp_free ( void *  this)
static

free member resource

Definition at line 78 of file chain_of_responsibility.c.

Here is the call graph for this function:

◆ chain_of_resp_new()

static void chain_of_resp_new ( void *  this,
size_t  size,
void *  input_parameter 
)
static

new API

Definition at line 54 of file chain_of_responsibility.c.

Here is the call graph for this function:

◆ chain_of_resp_setter()

static int chain_of_resp_setter ( void *  this,
size_t  size,
void *  input_parameter 
)
static

setter, add function to ChainElement

Definition at line 71 of file chain_of_responsibility.c.

Here is the call graph for this function:

◆ 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.

Variable Documentation

◆ cor_mng_g

struct chain_of_resp_mng_t cor_mng_g
Initial value:
= {
.method ={
.constructor=chain_of_resp_new,
.destructor=chain_of_resp_free,
},
.handle = NULL,
.is_threadsafe = 0,
}
static void chain_of_resp_new(void *this, size_t size, void *input_parameter)
new API
static int chain_of_resp_equall_operand(void *this, size_t size, void *input_parameter)
equall operand, check name
static int chain_of_resp_setter(void *this, size_t size, void *input_parameter)
setter, add function to ChainElement
static void chain_of_resp_free(void *this)
free member resource