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"
Go to the source code of this file.
|
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...
|
|
Implement of Flyweight design petten library API, related to Publisher class.
Definition in file publisher.c.
◆ PC_INDEX_FROM_ID
#define PC_INDEX_FROM_ID |
( |
|
content_id | ) |
((content_id)-1) |
◆ publisher_free()
void publisher_free |
( |
void |
| ) |
|
free All publisher content
- Returns
- none
Definition at line 75 of file publisher.c.
◆ publisher_get_content()
get content from id
- Parameters
-
- Returns
- PublishContent instance
Definition at line 29 of file publisher.c.
◆ publisher_new()
int publisher_new |
( |
size_t |
contents_num | ) |
|
new Publisher content, user can get notify to subscribe.
- Parameters
-
[in] | contents_num | max size of publish content |
- Return values
-
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.
◆ 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_id | id |
[in] | publish_type | publish type |
[in] | detail | detail data of publish |
- Returns
- none
Definition at line 132 of file publisher.c.
◆ 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_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 |
- Return values
-
!=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.
◆ 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_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 |
- Returns
- none
- Note
- ctx is not free in this library
Definition at line 107 of file publisher.c.
◆ publisher_unsubscribe()
unsubscribe, if you want to stop subscribe, please call it
- Parameters
-
[in] | content_id | id of publish content |
[in] | account | account returned at publisher_subscribe |
- Returns
- none
Definition at line 122 of file publisher.c.
◆ publisher_g