Easy Publish and Consume Reference Manual | ||||
---|---|---|---|---|
#include <libepc/publish.h> EpcContents* (*EpcContentsHandler) (EpcPublisher *publisher, const gchar *key, gpointer user_data); EpcContents; EpcContents* epc_contents_new (const gchar *type, gpointer data, gsize length); EpcContents* epc_contents_ref (EpcContents *contents); void epc_contents_unref (EpcContents *contents);
EpcContents is a reference counted structure for storing custom contents. To publish custom content call epc_publisher_add_handler to register a EpcContentsHandler like this:
Example 6. A custom contents handler
static EpcContents* timestamp_handler (EpcPublisher *publisher G_GNUC_UNUSED, const gchar *key G_GNUC_UNUSED, gpointer data) { time_t now = time (NULL); struct tm *tm = localtime (&now); const gchar *format = data; gsize length = 60; gchar *buffer; buffer = g_malloc (length); length = strftime (buffer, length, format, tm); return epc_content_new ("text/plain", buffer, length); }
EpcContents* (*EpcContentsHandler) (EpcPublisher *publisher, const gchar *key, gpointer user_data);
This callback is used to generate custom contents published with the
epc_publisher_add_handler function. The arguments passed are the same as
passed to epc_publisher_add_handler. The EpcPublisher will decrease the
reference count of the returned buffer after deliving it. It's valid to
return NULL
in situations were no contents can be generated.
publisher : |
the EpcPublisher |
key : |
the unique key |
user_data : |
user data set when the signal handler was installed |
Returns : | The EpcContents buffer for this publication, or NULL .
|
typedef struct _EpcContents EpcContents;
A reference counted buffer for storing contents to deliver by the EpcPublisher. Use epc_contents_new to create instances of this buffer.
EpcContents* epc_contents_new (const gchar *type, gpointer data, gsize length);
Creates a new EpcContents buffer.
Passing NULL
for type
is equivalent to passing "application/octet-stream".
type : |
the MIME type of this contents, or NULL
|
data : |
the contents for this buffer |
length : |
the contents length in bytes |
Returns : | The newly created EpcContents buffer. |
EpcContents* epc_contents_ref (EpcContents *contents);
Increases the reference count of contents
.
contents : |
a EpcContents buffer |
Returns : | the same contents buffer.
|
void epc_contents_unref (EpcContents *contents);
Decreases the reference count of contents
.
When its reference count drops to 0, the buffer is released
(i.e. its memory is freed).
contents : |
a EpcContents buffer |