Next: , Previous: , Up: Using External Event Loops   [Contents][Index]


7.9.2.5 I/O Callback Example GDK

The I/O callback interface can also be used to integrate GPGME with the GDK event loop. The following code snippets shows how this can be done using the appropriate register and remove I/O callback functions. In this example, the private data of the register I/O callback function is unused. The event notifications is missing because it does not require any GDK specific setup.

It is very similar to the GTK+ example in the previous section.

#include <gdk/gdk.h>

struct my_gpgme_io_cb
{
  gpgme_io_cb_t fnc;
  void *fnc_data;
  gint tag;
};

void
my_gpgme_io_cb (gpointer data, gint source, GdkInputCondition condition)
{
  struct my_gpgme_io_cb *iocb = data;
  (*(iocb->fnc)) (iocb->data, source);
}

void
my_gpgme_remove_io_cb (void *data)
{
  struct my_gpgme_io_cb *iocb = data;
  gdk_input_remove (data->tag);
}

void
my_gpgme_register_io_callback (void *data, int fd, int dir, gpgme_io_cb_t fnc,
                               void *fnc_data, void **tag)
{
  struct my_gpgme_io_cb *iocb = g_malloc (sizeof (struct my_gpgme_io_cb));
  iocb->fnc = fnc;
  iocb->data = fnc_data;
  iocb->tag = gtk_input_add_full (fd, dir ? GDK_INPUT_READ : GDK_INPUT_WRITE,
                                  my_gpgme_io_callback, iocb, NULL);
  *tag = iocb;
  return 0;
}