design_pattern_for_c  V 1.00
publisher.h File Reference

This is API as Observer(Publish-Subscribe) design petten. More...

#include <stddef.h>
Include dependency graph for publisher.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PUBLISHER_SUCCESS   (0)
 
#define PUBLISHER_FAILED   (-1)
 

Typedefs

typedef struct subscriber_account_t subscriber_account_t
 SubscriberAccount class definition. More...
 
typedef struct subscriber_account_tSubscriberAccount
 

Functions

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

Detailed Description

This is API as Observer(Publish-Subscribe) design petten.

Definition in file publisher.h.

Macro Definition Documentation

◆ PUBLISHER_FAILED

#define PUBLISHER_FAILED   (-1)

Definition at line 11 of file publisher.h.

◆ PUBLISHER_SUCCESS

#define PUBLISHER_SUCCESS   (0)

Definition at line 10 of file publisher.h.

Typedef Documentation

◆ subscriber_account_t

SubscriberAccount class definition.

Definition at line 19 of file publisher.h.

◆ SubscriberAccount

Definition at line 19 of file publisher.h.

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_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: