以 PDF 格式下载本书 (923 KB)
Chapter 2 Event Notification Service C API ReferenceThis chapter details the ENS C API; it is divided into three main sections: Publisher API Functions ListThis chapter includes a description of the following Publisher functions, listed in Table 2–1: Table 2–1 ENS Publisher API Functions List
Unreliable Publisher APIThis chapter includes a description of the following Unreliable Publisher functions, listed in Table 2–2: Table 2–2 ENS Unreliable Publisher API Functions List
Subscriber API Functions ListThis chapter includes a description of following Subscriber functions, listed in Table 2–3: Table 2–3 ENS Subscriber API Functions List
Publish and Subscribe Dispatcher Functions ListThis chapter includes a description of the following Publish and Subscribe Dispatcher functions, listed in Table 2–4: Table 2–4 ENS Publish and Subscribe Dispatcher Functions List
Publisher APIThe Publisher API consists of one definition and nine functions: publisher_tPurpose.A publisher. Syntaxtypedef struct enc_struct publisher_t; ParametersNone. ReturnsNothing. publisher_cb_tPurpose.Generic callback function invoked by ENS to acknowledge an asynchronous call. Syntaxtypedef void (*publisher_cb_t) (void *arg, int rc, void *data); Parameters
ReturnsNothing. publisher_new_aPurposeCreates a new asynchronous publisher. Syntaxvoid publisher_new_a (pas_dispatcher_t *disp,
void *worker,
const char *host,
unsigned short port,
publisher_cb_t cbdone,
void *cbarg);
Parameters
ReturnsNothing. It passes the new active publisher as third argument of cbdone callback. publisher_new_sPurposeCreates a new synchronous publisher. Syntaxpublisher_t *publisher_new_s (pas_dispatcher_t *disp,
void *worker,
const char *host,
unsigned short port);
Parameters
ReturnsA new active publisher (publisher_t). publish_aPurposeSends an asynchronous notification to the notification service. Syntaxvoid publish_a (publisher_t *publisher,
const char *event_ref,
const char *data,
unsigned int datalen,
publisher_cb_t cbdone,
publisher_cb_t end2end_ack,
void *cbarg,
unsigned long timeout);
Parameters
ReturnsNothing. publish_sPurposeSends a synchronous notification to the notification service. Syntaxint publish_s (publisher_t *publisher,
const char *event_ref,
const char *data,
unsigned int datalen);
Parameters
ReturnsZero if successful; a failure code if unsuccessful. If an RENL, the call does not return until the consumer has completely processed the notification and has successfully acknowledged it. publisher_deletePurposeTerminates a publish session. Syntaxvoid publisher_delete (publisher_t *publisher); Parameters
ReturnsNothing. publisher_get_subscriberPurposeCreates a subscriber using the credentials of the publisher. Syntaxstruct subscriber_struct * publisher_get_subscriber(publisher_t *publisher); Parameters
ReturnsThe subscriber, or NULL if the creation failed. If the creation failed, use the subscriber_new to create the subscriber. renl_create_publisherPurposeDeclares an RENL, which enables the end2end_ack invocation. After this call returns, the end2end_ack argument is invoked when an acknowledgment notification matching the specified publisher and subscriber is received. Syntaxvoid renl_create_publisher (publisher_t *publisher,
const char *renl_id,
const char *subscriber,
publisher_cb_t cbdone,
void *cbarg);
Parameters
ReturnsNothing. renl_cancel_publisherPurposeThis cancels an RENL. This does not prevent more notifications being sent, but should a client acknowledgment be received, the end2end_ack argument of publish will no longer be invoked. All RENLs are automatically destroyed when the publisher is deleted. Therefore, this function does not need to be called to free RENL-related memory before deleting a publisher. Syntaxvoid renl_cancel_publisher (renl_t *renl); Parameters
ReturnsNothing. Unreliable Publisher APIThe Unreliable Publisher (upub) API consists of the following functions: upub_tPurposeDefines an unreliable publisher type. Syntaxtypedef struct upub_struct upub_t; ParametersNone. ReturnsNothing. upub_publishPurposeSends a notification. Syntaxvoid upub_publish (upub_t *upub,
const char *event_ref,
void *payload,
unsigned int payload_len,
void (*delete_payload) (void *));
Parameters
ReturnsNothing. upub_initPurposeCreates the publisher. This function allocates the upub object and sets up the thread dispatcher. The thread dispatcher can be provided by the application if the application already has one. This will have the advantage of not creating a thread dedicated to this API. Note: If a connection-based transport is used, the connection to the notification service is not set up here. This is deferred to the first time a notification is actually published. Syntaxupub_t *upub_init(void *gdc,
const char *host, unisgned short port,
int num_workers);
Parameters
ReturnsThe upub ready to be used. upub_shutdownPurposeShuts down and frees the publisher. Syntaxvoid upub_shutdown(upub_t *upub); Parameters
ReturnsNothing. Subscriber APIThe Subscriber API includes two definitions and ten functions: subscriber_tPurposeA subscriber. Syntaxtypedef struct enc_struct subscriber_t; ParametersNone. ReturnsNothing. subscription_tPurposeA subscription. Syntaxtypedef struct subscription_struct subscription_t; ParametersNone. ReturnsNothing. subscriber_cb_tPurposeGeneric callback function invoked by ENS to acknowledge an asynchronous call. Syntaxtypedef void (*subscriber_cb_t) (void *arg,
int rc,
void *data);
Parameters
ReturnsNothing subscriber_notify_cb_tPurposeSubscriber callback; called upon receipt of a notification. Syntaxtypedef void (*subscriber_notify_cb_t) (void *arg,
char *event,
char *data,
int datalen);
Parameters
ReturnsZero if successful, non-zero otherwise. subscriber_new_aPurposeCreates a new asynchronous subscriber. Syntaxvoid subscriber_new_a (pas_dispatcher_t *disp,
void *worker,
const char *host,
unsigned short port,
subscriber_cb_t cbdone,
void *cbarg);
Parameters
ReturnsNothing. It passes the new active subscriber as third argument of cbdone callback. subscriber_new_sPurposeCreates a new synchronous subscriber. Syntaxsubscriber_t *subscriber_new_s (pas_dispatcher_t *disp,
const char *host,
unsigned short port);
Parameters
ReturnsA new active subscriber (subscriber_t). subscribe_aPurposeEstablishes an asynchronous subscription. Syntaxvoid subscribe_a (subscriber_t *subscriber,
const char *event_ref,
subscriber_notify_cb_t notify_cb,
void *notify_arg,
subscriber_cb_t cbdone,
void *cbarg):
Parameters
ReturnsNothing. unsubscribe_aPurposeCancels an asynchronous subscription. Syntaxvoid unsubscribe_a (subscriber_t *subscriber,
subscription_t *subscription,
subscriber_cb_t cbdone,
void *cbarg);
Parameters
ReturnsNothing. subscriber_deletePurposeTerminates a subscriber. Syntaxvoid subscriber_delete (subscriber_t *subscriber); Parameters
Returns.Nothing subscriber_get_publisherPurposeCreates a publisher, using the credentials of the subscriber. Syntaxstruct publisher_struct *subscriber_get_publisher (subscriber_t *subscriber); Parameters
ReturnsThe publisher, or NULL if creation failed. In case the creation fails, use the publisher_new. renl_create_subscriberPurposeCreates the subscription part of an RENL. Syntaxrenl_t *renl_create_subscriber (subscription_t *subscription,
const char *renl_id,
const char *publisher);
Parameters
ReturnsThe opaque RENL object. renl_cancel_subscriberPurposeThis cancels an RENL. It does not cancel a subscription. It tells ENS not to acknowledge any more notifications received for this subscription. It destroys the RENL object, the application may no longer use this RENL. All RENLs are automatically destroyed when the subscription is canceled. Therefore, this function does not need to be called to free RENL-related memory before deleting a subscriber. Syntaxvoid renl_cancel_subscriber (renl_t *renl); Parameters
ReturnsNothing. Publish and Subscribe Dispatcher APIThe Publish and Subscribe Dispatcher API includes one definition and four functions: Note – The only thread dispatcher supported is GDisp (libasync). pas_dispatcher_tPurposeA publish and subscribe dispatcher. Syntaxtypedef struct pas_dispatcher_struct pas_dispatcher_t; ParametersNone. ReturnsNothing. pas_dispatcher_newPurposeCreates or advertises a dispatcher. Syntaxpas_dispatcher_t *pas_dispatcher_new (void *disp); Parameters
ReturnsThe dispatcher to use when creating publishers or subscribers (pas_dispatcher_t). pas_dispatcher_deletePurposeDestroys a dispatcher created with pas_dispatcher_new. Syntaxvoid pas_dispatcher_delete (pas_dispatcher_t *disp); Parameters
ReturnsNothing. pas_dispatchPurposeStarts the dispatch loop of an event notification environment. It has no effect if the application uses its own thread pool. Syntaxvoid pas_dispatch (pas_dispatcher_t *disp); Parameters
ReturnsNothing. pas_shutdownPurposeStops the dispatch loop of an event notification environment started with pas_dispatch. It has no effect if an application-provided dispatcher was passed to pas_dispatcher_new. Syntaxvoid pas_shutdown (pas_dispatcher_t *disp); Parameters
ReturnsNothing. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||