design_pattern_for_c  V 1.00
publisher.c File Reference

Implement of Flyweight design petten library API, related to Publisher class. More...

#include <stdlib.h>
#include <string.h>
#include "publish_content.h"
#include "dp_util.h"
Include dependency graph for publisher.c:

Go to the source code of this file.

Data Structures

struct  publisher_mng_t
 publisher class instance More...
 

Macros

#define PC_INDEX_FROM_ID(content_id)   ((content_id)-1)
 

Functions

static PublishContent publisher_get_content (int content_id)
 get content from id More...
 
int publisher_new (size_t contents_num)
 new Publisher content, user can get notify to subscribe. More...
 
void publisher_free (void)
 free All publisher content More...
 
SubscriberAccount publisher_subscribe (int content_id, int publish_type, void(*notify)(int publish_type, void *detail, void *ctx), void *ctx)
 subscribe More...
 
void publisher_subscribe_oneshot (int content_id, int publish_type, void(*notify)(int publish_type, void *detail, void *ctx), void *ctx)
 subscribe only oneshot More...
 
void publisher_unsubscribe (int content_id, SubscriberAccount account)
 unsubscribe, if you want to stop subscribe, please call it More...
 
void publisher_publish (int content_id, int publish_type, void *detail)
 publish, Publisher call subscriber's notify if type is same More...
 

Variables

struct publisher_mng_t publisher_g
 

Detailed Description

Implement of Flyweight design petten library API, related to Publisher class.

Definition in file publisher.c.

Macro Definition Documentation

◆ PC_INDEX_FROM_ID

#define PC_INDEX_FROM_ID (   content_id)    ((content_id)-1)

Definition at line 19 of file publisher.c.

Function Documentation

◆ publisher_free()

void publisher_free ( void  )

free All publisher content

Returns
none

Definition at line 75 of file publisher.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publisher_get_content()

static PublishContent publisher_get_content ( int  content_id)
static

get content from id

Parameters
[in]content_id
Returns
PublishContent instance

Definition at line 29 of file publisher.c.

Here is the caller graph for this function:

◆ publisher_new()

int publisher_new ( size_t  contents_num)

new Publisher content, user can get notify to subscribe.

Parameters
[in]contents_nummax size of publish content
Return values
PUBLISHER_SUCCESSsuccess to create PublisherContents, you can select content by 1, 2, 3, ... ,contents_num
PUBLISHER_FAILEDFailed to create instance/already created

Definition at line 40 of file publisher.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publisher_publish()

void publisher_publish ( int  content_id,
int  publish_type,
void *  detail 
)

publish, Publisher call subscriber's notify if type is same

Parameters
[in]content_idid
[in]publish_typepublish type
[in]detaildetail data of publish
Returns
none

Definition at line 132 of file publisher.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publisher_subscribe()

SubscriberAccount publisher_subscribe ( int  content_id,
int  publish_type,
void(*)(int publish_type, void *detail, void *ctx)  notify,
void *  ctx 
)

subscribe

Parameters
[in]content_idid of publish content you want to receive
[in]publish_typetype of pushlish related to publish. this ID use bitwise operation "OR". So if you want to receive notification from some publish type, please use "OR". So, if you set 0, send notify to all
[in]notifynotification interface. If subscriber set this IF and type, publisher notify when publish.
[in]ctxuser definition ctx information
Return values
!=NULLSubscriberAccount account of this subscribe, if you want to manage unscribe/subscribe many time, please keep this accout information
NULLfailed to subscribe

Definition at line 91 of file publisher.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publisher_subscribe_oneshot()

void publisher_subscribe_oneshot ( int  content_id,
int  publish_type,
void(*)(int publish_type, void *detail, void *ctx)  notify,
void *  ctx 
)

subscribe only oneshot

Parameters
[in]content_idid of publish content you want to receive
[in]publish_typetype of pushlish related to publish. this ID use bitwise operation "OR". So if you want to receive notification from some publish type, please use "OR". So, if you set 0, send notify to all
[in]notifynotification interface. If subscriber set this IF and type, publisher notify when publish.
[in]ctxuser definition ctx information
Returns
none
Note
ctx is not free in this library

Definition at line 107 of file publisher.c.

Here is the call graph for this function:

◆ publisher_unsubscribe()

void publisher_unsubscribe ( int  content_id,
SubscriberAccount  account 
)

unsubscribe, if you want to stop subscribe, please call it

Parameters
[in]content_idid of publish content
[in]accountaccount returned at publisher_subscribe
Returns
none

Definition at line 122 of file publisher.c.

Here is the call graph for this function:

Variable Documentation

◆ publisher_g

struct publisher_mng_t publisher_g