Table of Contents
Just a second...

Using the C Classic API

Build the library using the make command and ensure that it is on your LD_LIBRARY_PATH.

Building

To build the library, type make in the source directory. This builds shared and static versions of the Diffusion™ library, libdiffusion.so and libdiffusion.a respectively. Additionally, a number of sample applications are also built.

Installation

Copy the libraries to a location on the user's LD_LIBRARY_PATH (or equivalent). Copy the header files, diffusion.h and llist.h to your C compiler's include path.

For example:
$ mkdir /usr/local/include/diffusion
$ mkdir /usr/local/lib/diffusion
$ cp include/*.h /usr/local/include/diffusion/
$ cp lib/libdiffusion.* /usr/local/lib/diffusion/
$ echo "/usr/local/lib/diffusion" > /etc/ld.so.conf.d/libdiffusion.conf
$ ldconfig

Example usage

The following example shows how to connect to a Diffusion instance (no credentials):
	DIFFUSION_CONNECTION *c = diff_connect("localhost", 8080, NULL);
	if(c == NULL) {
		fprintf(stderr, "Failed to connect to Diffusion\n");
		return(-1);
	}

The following example shows how to connect to a Diffusion instance (with credentials)

	SECURITY_CREDENTIALS creds;
	creds.username = strdup("smith");
	creds.password = strdup("secret");
	DIFFUSION_CONNECTION *c = diff_connect("localhost", 8080, &creds);
	if(c == NULL) {
		fprintf(stderr, "Failed to connect to Diffusion\n");
		return(-1);
	}

The following example shows how to request a subscription to a topic:

	DIFFUSION_CONNECTION *c = diff_connect(...);

	if(diff_subscribe(c, "Assets") == -1) {
		fprintf(stderr, "Failed to subscribe to topic\n");
		return(-1);
	}

The following example shows how to use the event loop and callbacks:

	void on_initial_load(DIFFUSION_MESSAGE *msg) {...}
	void on_delta(DIFFUSION_MESSAGE *msg) {...}

	...

	DIFFUSION_CONNECTION *c = diff_connect(...);
	diff_subscribe(...);

	DIFFUSION_CALLBACKS callbacks;
	DIFF_CB_ZERO(callbacks);		// Reset callback structure
	callbacks.on_initial_load = &on_initial_load;
	callbacks.on_delta = &on_delta;

	diff_loop(c, &callbacks);