[Xcb] design to handle requests and reply in ecore_xcb

Vincent Torri Vincent.Torri at iecn.u-nancy.fr
Sat Dec 10 17:45:14 PST 2005


hey,

I would like, in ecore, to add in a queue the requests and store the
cookie and reply function. I have paste some (untested) code below. I
would like to have your opinion about its design: is it good ? Is there a
better solution ? etc...

thank you

Vincent

Code:

typedef XCBVoidCookie Ecore_Xcb_Generic_Cookie;

typedef void *(*Ecore_Xcb_Reply) (Ecore_Xcb_Connection      *c,
                                  Ecore_Xcb_Generic_Cookie   cookie,
                                  Ecore_Xcb_Generic_Error  **e);

typedef struct
{
  Ecore_Xcb_Generic_Cookie cookie;
  Ecore_Xcb_Reply          reply;
}Ecore_Xcb_Request;

static int                ecore_xcb_request_ref = 0;
static int                ecore_xcb_request_size = 256; /* Number of
request during init: 140*/
static Ecore_Xcb_Request *ecore_xcb_request_requests = NULL;

static void ecore_xcb_request_resize (void);

int
ecore_xcb_request_init ()
{
  ecore_xcb_request_requests = (Ecore_Xcb_Request *)malloc
(ecore_xcb_request_size * sizeof (Ecore_Xcb_Request));
  if (!ecore_xcb_request_requests)
    return 0;

  return 1;
}

void
ecore_xcb_request_add (Ecore_Xcb_Generic_Cookie cookie,
                       Ecore_Xcb_Reply          reply)
{
  if (!reply)
    return;

  if (ecore_xcb_request_ref + 1 == ecore_xcb_request_size)
    ecore_xcb_request_resize ();

  ecore_xcb_request_requests[ecore_xcb_request_ref].cookie = cookie;
  ecore_xcb_request_requests[ecore_xcb_request_ref].reply = reply;

  ecore_xcb_request_ref++;
}

void
ecore_xcb_request_flush ()
{
  while (ecore_xcb_request_ref--)
    ecore_xcb_request_requests[ecore_xcb_request_ref].reply
(ecore_xcb_conn,

ecore_xcb_request_requests[ecore_xcb_request_ref].cookie,
                                                             NULL);
}

void
ecore_xcb_request_shutdown ()
{
   if (ecore_xcb_request_requests)
      free (ecore_xcb_request_requests);
}

/* FIXME: should we test if realloc fails ? */
static void
ecore_xcb_request_resize (void)
{
  ecore_xcb_request_size <<= 1;

  realloc (ecore_xcb_request_requests, ecore_xcb_request_size * sizeof
(Ecore_Xcb_Request));
}


More information about the Xcb mailing list