design_pattern_for_c
V 1.00
|
This is API as Observer(Publish-Subscribe) design petten. More...
#include <stddef.h>
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_t * | SubscriberAccount |
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... | |
This is API as Observer(Publish-Subscribe) design petten.
Definition in file publisher.h.
#define PUBLISHER_FAILED (-1) |
Definition at line 11 of file publisher.h.
#define PUBLISHER_SUCCESS (0) |
Definition at line 10 of file publisher.h.
typedef struct subscriber_account_t subscriber_account_t |
SubscriberAccount class definition.
Definition at line 19 of file publisher.h.
typedef struct subscriber_account_t * SubscriberAccount |
Definition at line 19 of file publisher.h.
void publisher_free | ( | void | ) |
free All publisher content
Definition at line 75 of file publisher.c.
int publisher_new | ( | size_t | contents_num | ) |
new Publisher content, user can get notify to subscribe.
[in] | contents_num | max size of publish content |
PUBLISHER_SUCCESS | success to create PublisherContents, you can select content by 1, 2, 3, ... ,contents_num |
PUBLISHER_FAILED | Failed to create instance/already created |
Definition at line 40 of file publisher.c.
void publisher_publish | ( | int | content_id, |
int | publish_type, | ||
void * | detail | ||
) |
publish, Publisher call subscriber's notify if type is same
[in] | content_id | id |
[in] | publish_type | publish type |
[in] | detail | detail data of publish |
Definition at line 132 of file publisher.c.
SubscriberAccount publisher_subscribe | ( | int | content_id, |
int | publish_type, | ||
void(*)(int publish_type, void *detail, void *ctx) | notify, | ||
void * | ctx | ||
) |
subscribe
[in] | content_id | id of publish content you want to receive |
[in] | publish_type | type 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] | notify | notification interface. If subscriber set this IF and type, publisher notify when publish. |
[in] | ctx | user definition ctx information |
!=NULL | SubscriberAccount account of this subscribe, if you want to manage unscribe/subscribe many time, please keep this accout information |
NULL | failed to subscribe |
Definition at line 91 of file publisher.c.
void publisher_subscribe_oneshot | ( | int | content_id, |
int | publish_type, | ||
void(*)(int publish_type, void *detail, void *ctx) | notify, | ||
void * | ctx | ||
) |
subscribe only oneshot
[in] | content_id | id of publish content you want to receive |
[in] | publish_type | type 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] | notify | notification interface. If subscriber set this IF and type, publisher notify when publish. |
[in] | ctx | user definition ctx information |
Definition at line 107 of file publisher.c.
void publisher_unsubscribe | ( | int | content_id, |
SubscriberAccount | account | ||
) |
unsubscribe, if you want to stop subscribe, please call it
[in] | content_id | id of publish content |
[in] | account | account returned at publisher_subscribe |
Definition at line 122 of file publisher.c.