Next:, Previous:Denial of Service, Up:Top


11 Library

The Pedro C-library provides support for writing Pedro clients. It is built on top of the glib library.

Client is an opaque datatype used to store information about a Pedro client. The intention is to use g_main_loop_run with the callback declared in the creation of the client called each time data is sent to the client from the Pedro server. The program consumer.c in the examples directory is a simple example using this approach.

The following functions define the client interface.

Client* client_new(void (*cb) (char*, gpointer, gpointer), gpointer user_data);
This function returns a pointer to a new client object connected to the Pedro server on this machine using the default port (4550). The callback cb (user defined) takes the data from the server, the rock specified in the matching subscription and a pointer to user data and is called each time data arrives from the server. The last argument, user_data, is a pointer to the user data used as the third agument to the callback.
Client* client_new_full(int port, char* hostname, void (*cb) (char*, gpointer, gpointer), gpointer user_data);
This function is the same as the previous one except the port and machine name of the Pedro server are also supplied.
void client_destroy(Client* client);
Shut down the connection with the Pedro server and free the client object data.
int subscribe(Client* client, char* term, char* goal, gpointer rock);
Make a subscription for the given client and return the ID of the subscription (0 if the subscription is unsuccessful).
gboolean unsubscribe(Client* client, guint id);
Remove the subscription with the supplied ID. It returns true iff the operation was successful.
gboolean notify(Client* client, char* term);
Send a notification to the server. It returns true iff the operation was successful.
gboolean register_name(Client* client, char* name);
Register the supplied name with the server. It returns true iff the operation was successful.
gboolean deregister_name(Client* client);
Deregister the current name with the server. It returns true iff the operation was successful.
gboolean p2p(Client* client, char* toaddr, char* msg);
Send a peer-to-peer message to the supplied address. It returns true iff the operation was successful.