This chapter details the ENS C API; it is divided into three main sections:
This chapter includes a description of the following Publisher functions, listed in Table 2–1:
Table 2–1 ENS Publisher API Functions List
Function |
Description |
Definition for a publisher. |
|
Generic callback function acknowledging an asynchronous call. |
|
Creates a new asynchronous publisher. |
|
Creates a new synchronous publisher. |
|
Sends an asynchronous notification to the notification service. |
|
Sends a synchronous notification to the notification service. |
|
Terminates a publish session. |
|
Creates a subscriber using the publisher’s credentials. |
|
Creates an RENL, which enables the invocation of end2end_ack. |
|
Cancels an RENL. |
This chapter includes a description of following Subscriber functions, listed in Table 2–2:
Table 2–2 ENS Subscriber API Functions List
Function |
Description |
Definition of a subscriber. |
|
Definition of a subscription. |
|
Generic callback function acknowledging an asynchronous call. |
|
Synchronous callback; called upon receipt of a notification. |
|
Creates a new asynchronous subscriber. |
|
Creates a new synchronous subscriber. |
|
Establishes an asynchronous subscription. |
|
Cancels an asynchronous subscription. |
|
Terminates a subscriber. |
|
Creates a publisher using the subscriber’s credentials. |
|
Creates the subscription part of the RENL. |
|
Cancels an RENL. |
This chapter includes a description of the following Publish and Subscribe Dispatcher functions, listed in Table 2–3:
Table 2–3 ENS Publish and Subscribe Dispatcher Functions List
Function |
Description |
Definition of a publish and subscribe dispatcher. |
|
Creates a dispatcher. |
|
Destroys a dispatcher created with pas_dispatcher_new. |
|
Starts the dispatch loop of an event notification environment. |
|
Stops the dispatch loop on an event notification environment started with pas_dispatch. |
The Publisher API consists of one definition and nine functions:
A publisher.
typedef struct enc_struct publisher_t;
None.
Nothing.
Generic callback function invoked by ENS to acknowledge an asynchronous call.
typedef void (*publisher_cb_t) (void *arg, int rc, void *data);
arg |
Context variable passed by the caller. |
rc |
The return code. |
data |
For an open, contains a newly created context. |
Nothing.
Creates a new asynchronous publisher.
void publisher_new_a (pas_dispatcher_t *disp, void *worker, const char *host, unsigned short port, publisher_cb_t cbdone, void *cbarg);
Nothing. It passes the new active publisher as third argument of cbdone callback.
Creates a new synchronous publisher.
publisher_t *publisher_new_s (pas_dispatcher_t *disp, void *worker, const char *host, unsigned short port);
disp |
P&S thread pool context returned by pas_dispatcher_new. |
worker |
Application worker. If not NULL, grouped with existing workers created by ENS to service this publisher session. Used to prevent multiple threads from accessing the publisher data at the same time. |
host |
Notification server host name. |
port |
Notification server port. |
A new active publisher (publisher_t).
Sends an asynchronous notification to the notification service.
void 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);
publisher_t |
The active publisher. |
event_ref |
The event reference. This is a URI identifying the modified resource. |
data |
The event data. The body of the notification message. It is opaque to the notification service, which merely relays it to the events’ subscriber. |
datalen |
The length in bytes of the data. |
cbdone |
The callback invoked when the data has been accepted or deemed unacceptable by the notification service. What makes a notification acceptable depends on the protocol used. The protocol may choose to use the transport acknowledgment (TCP) or use its own acknowledgment response mechanism. |
end2end_ack |
The callback function invoked after acknowledgment from the consumer peer (in an RENL) has been received. Used only in the context of an RENL. |
cbarg |
The first argument of cbdone or end2end_ack when invoked. |
timeout |
The length of time to wait for an RENL to complete. |
Nothing.
Sends a synchronous notification to the notification service.
int publish_s (publisher_t *publisher, const char *event_ref, const char *data, unsigned int datalen);
publisher |
The active publisher. |
event_ref |
The event reference. This is a URI identifying the modified resource. |
data |
The event data. The body of the notification message. It is opaque to the notification service, which relays it to the events’ subscriber. |
datalen |
The length in bytes of the data. |
Zero 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.
Terminates a publish session.
void publisher_delete (publisher_t *publisher);
publisher |
The publisher to delete. |
Nothing.
Creates a subscriber using the credentials of the publisher.
struct subscriber_struct * publisher_get_subscriber(publisher_t *publisher);
publisher |
The publisher whose credentials are used to create the subscriber. |
The subscriber, or NULL if the creation failed. If the creation failed, use the subscriber_new to create the subscriber.
Declares 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.
void renl_create_publisher (publisher_t *publisher, const char *renl_id, const char *subscriber, publisher_cb_t cbdone, void *cbarg);
publisher |
The active publisher. |
renl_id |
The unique RENL identifier. This allows two peers to be able to set up multiple RENLs between them. |
subscriber |
The authenticated identity of the peer. |
cbdone |
The callback invoked when the RENL is established. |
cbarg |
The first argument of cbdone, when invoked. |
Nothing.
This 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.
void renl_cancel_publisher (renl_t *renl);
renl |
The RENL to cancel. |
Nothing.
The Subscriber API includes two definitions and ten functions:
A subscriber.
typedef struct enc_struct subscriber_t;
None.
Nothing.
A subscription.
typedef struct subscription_struct subscription_t;
None.
Nothing.
Generic callback function invoked by ENS to acknowledge an asynchronous call.
typedef void (*subscriber_cb_t) (void *arg, int rc, void *data);
arg |
Context variable passed by the caller. |
rc |
The return code. |
data |
For an open, contains a newly created context. |
Nothing
Subscriber callback; called upon receipt of a notification.
typedef void (*subscriber_notify_cb_t) (void *arg, char *event, char *data, int datalen);
arg |
Context pointer passed to subscribe (notify_arg). |
event |
The event reference (URI). The notification event reference matches the subscription, but may contain additional information called event attributes, such as a uid. |
data |
The body of the notification. A MIME object. |
datalen |
Length of the data. |
Zero if successful, non-zero otherwise.
Creates a new asynchronous subscriber.
void subscriber_new_a (pas_dispatcher_t *disp, void *worker, const char *host, unsigned short port, subscriber_cb_t cbdone, void *cbarg);
Nothing. It passes the new active subscriber as third argument of cbdone callback.
Creates a new synchronous subscriber.
subscriber_t *subscriber_new_s (pas_dispatcher_t *disp, const char *host, unsigned short port);
disp |
Publish and subscribe dispatcher returned by pas_dispatcher_new. |
worker |
Application worker. If not NULL, grouped with existing workers created by ENS to service this publisher session. Used to prevent multiple threads from accessing the publisher data at the same time. Only usable if the caller creates and dispatches the GDisp context. |
host |
Notification server host name or IP address. |
port |
Subscription service port number. |
A new active subscriber (subscriber_t).
Establishes an asynchronous subscription.
void subscribe_a (subscriber_t *subscriber, const char *event_ref, subscriber_notify_cb_t notify_cb, void *notify_arg, subscriber_cb_t cbdone, void *cbarg):
Nothing.
Cancels an asynchronous subscription.
void unsubscribe_a (subscriber_t *subscriber, subscription_t *subscription, subscriber_cb_t cbdone, void *cbarg);
Nothing.
Terminates a subscriber.
void subscriber_delete (subscriber_t *subscriber);
subscriber |
The subscriber to delete. |
Nothing
Creates a publisher, using the credentials of the subscriber.
struct publisher_struct *subscriber_get_publisher (subscriber_t *subscriber);
subscriber |
The subscriber whose credentials are used to create the publisher. |
The publisher, or NULL if creation failed. In case the creation fails, use the publisher_new.
Creates the subscription part of an RENL.
renl_t *renl_create_subscriber (subscription_t *subscription, const char *renl_id, const char *publisher);
subscription |
The subscription. |
renl_id |
The unique RENL identifier. This allows two peers to be able to set up multiple RENLs between them. |
publisher |
The authenticated identity of the peer. |
The opaque RENL object.
This 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.
void renl_cancel_subscriber (renl_t *renl);
renl |
The RENL to cancel. |
Nothing.
The Publish and Subscribe Dispatcher API includes one definition and four functions:
The only thread dispatcher supported is GDisp (libasync).
A publish and subscribe dispatcher.
typedef struct pas_dispatcher_struct pas_dispatcher_t;
None.
Nothing.
Creates or advertises a dispatcher.
pas_dispatcher_t *pas_dispatcher_new (void *disp);
dispcx |
The dispatcher context. If NULL,to start dispatching notifications, the application must call pas_dispatch. If not NULL, the dispatcher is a libasync dispatcher. |
The dispatcher to use when creating publishers or subscribers (pas_dispatcher_t).
Destroys a dispatcher created with pas_dispatcher_new.
void pas_dispatcher_delete (pas_dispatcher_t *disp);
disp |
The event notification client environment. |
Nothing.
Starts the dispatch loop of an event notification environment. It has no effect if the application uses its own thread pool.
void pas_dispatch (pas_dispatcher_t *disp);
disp |
The new dispatcher. |
Nothing.
Stops 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.
void pas_shutdown (pas_dispatcher_t *disp);
disp |
The dispatcher context to shutdown. |
Nothing.