Back to index

im-sdk  12.3.91
Classes | Defines | Typedefs | Functions | Variables
xaux_ext_hdlrmng.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <X11/Xlib.h>
#include "xaux_ext_common.h"

Go to the source code of this file.

Classes

struct  xaux_ext_hdlrmng_ent_struct
struct  xaux_ext_hdlrmng_db_struct

Defines

#define MAXMASK   32

Typedefs

typedef struct
xaux_ext_hdlrmng_ent_struct 
xaux_ext_hdlrmng_ent_t
typedef struct
xaux_ext_hdlrmng_db_struct 
xaux_ext_hdlrmng_db_t

Functions

static int mask2index (long mask)
static long index2mask (int idx)
static long type2mask (int type, Bool *nonmaskable_return)
static Bool add_to_list (xaux_ext_hdlrmng_ent_t *list, xaux_ext_cb_evhandler_t handler, void *sodata)
static Bool rm_from_list (xaux_ext_hdlrmng_ent_t *list, xaux_ext_cb_evhandler_t handler, void *sodata)
static void free_list (xaux_ext_hdlrmng_ent_t *list)
static xaux_ext_hdlrmng_handle_t xaux_ext_hdlrmng_open (void)
static Bool xaux_ext_hdlrmng_add (xaux_ext_hdlrmng_handle_t handle, xaux_ext_cb_evhandler_t handler, void *sodata, long mask, Bool nonmaskable, long *mask_add_return, Bool *nonmaskable_add_return, long *mask_new_return, Bool *nonmaskable_new_return)
static Bool xaux_ext_hdlrmng_remove (xaux_ext_hdlrmng_handle_t handle, xaux_ext_cb_evhandler_t handler, void *sodata, long mask, Bool nonmaskable, long *mask_rm_return, Bool *nonmaskable_rm_return, long *mask_new_return, Bool *nonmaskable_new_return)
static Bool xaux_ext_hdlrmng_filter (xaux_ext_hdlrmng_handle_t handle, xaux_ext_handle_t ext_handle, XEvent *ev)
static void xaux_ext_hdlrmng_close (xaux_ext_hdlrmng_handle_t handle)

Variables

xaux_ext_hdlrmng_methods_t xaux_ext_hdlrmng_methods

Class Documentation

struct xaux_ext_hdlrmng_ent_struct

Definition at line 51 of file xaux_ext_hdlrmng.c.

Collaboration diagram for xaux_ext_hdlrmng_ent_struct:
Class Members
xaux_ext_cb_evhandler_t handler
struct
xaux_ext_hdlrmng_ent_struct *
next
struct
xaux_ext_hdlrmng_ent_struct *
prev
void * sodata
struct xaux_ext_hdlrmng_db_struct

Definition at line 60 of file xaux_ext_hdlrmng.c.

Collaboration diagram for xaux_ext_hdlrmng_db_struct:
Class Members
long comb_mask
Bool comb_nonmaskable
xaux_ext_hdlrmng_ent_t maskable
xaux_ext_hdlrmng_ent_t nonmaskable

Define Documentation

#define MAXMASK   32

Definition at line 58 of file xaux_ext_hdlrmng.c.


Typedef Documentation


Function Documentation

static Bool add_to_list ( xaux_ext_hdlrmng_ent_t list,
xaux_ext_cb_evhandler_t  handler,
void *  sodata 
) [static]

Definition at line 136 of file xaux_ext_hdlrmng.c.

{
       xaux_ext_hdlrmng_ent_t      *le = list, *le_prev = NULL;

       while (le != NULL) {
              if ((le->handler == handler) && (le->sodata == sodata)) {
                     /* already registered */
                     return (True);
              } 
              le_prev = le;
              le = le->next;
       }

       if ((le = le_prev->next = (xaux_ext_hdlrmng_ent_t *)malloc(
                     sizeof (xaux_ext_hdlrmng_ent_t))) == NULL) {
              return (False);
       }

       le->prev = le_prev;
       le->next = NULL;
       le->handler = handler;
       le->sodata = sodata;

       return (True);
}

Here is the caller graph for this function:

static void free_list ( xaux_ext_hdlrmng_ent_t list) [static]

Definition at line 192 of file xaux_ext_hdlrmng.c.

{
       xaux_ext_hdlrmng_ent_t      *le = list, *le_next;

       while (le) {
              le_next = le->next;
              free(le);
              le = le->next;
       }
       return;
}

Here is the caller graph for this function:

static long index2mask ( int  idx) [static]

Definition at line 94 of file xaux_ext_hdlrmng.c.

{
       return (1L << idx);
}
static int mask2index ( long  mask) [static]

Definition at line 74 of file xaux_ext_hdlrmng.c.

{
       int    i;

       for (i = 0; i < MAXMASK; i++) {
              if ((mask & 1L) != 0) {
                     return (i);
              } else {
                     mask >>= 1;
              }
       }
       return (-1);
}

Here is the caller graph for this function:

static Bool rm_from_list ( xaux_ext_hdlrmng_ent_t list,
xaux_ext_cb_evhandler_t  handler,
void *  sodata 
) [static]

Definition at line 166 of file xaux_ext_hdlrmng.c.

{
       xaux_ext_hdlrmng_ent_t      *le = list, *le_prev;
       Bool                 rv = False;

       while (le != NULL) {
              if ((le->handler == handler) && (le->sodata == sodata)) {
                     /* found */
                     le->prev->next = le->next;
                     if (le->next != NULL) {
                            le->next->prev = le->prev;
                     }
                     free(le);
                     return (True);
              } 
              le = le->next;
       }

       /* not found */
       return (False);
}

Here is the caller graph for this function:

static long type2mask ( int  type,
Bool nonmaskable_return 
) [static]

Definition at line 103 of file xaux_ext_hdlrmng.c.

{
       long   mask;

       switch (type) {
       case DestroyNotify:
              mask = StructureNotifyMask;
              *nonmaskable_return = False;
              break;
       case PropertyNotify:
              mask = PropertyChangeMask;
              *nonmaskable_return = False;
              break;
       case SelectionClear:
       case SelectionNotify:
       case SelectionRequest:
       case ClientMessage:
              mask = NoEventMask;
              *nonmaskable_return = True;
              break;
       default:
              /* event type not interested by xaux_ext */
              mask = NoEventMask;
              *nonmaskable_return = False;
              break;
       }

       return (mask);
}

Here is the caller graph for this function:

static Bool xaux_ext_hdlrmng_add ( xaux_ext_hdlrmng_handle_t  handle,
xaux_ext_cb_evhandler_t  handler,
void *  sodata,
long  mask,
Bool  nonmaskable,
long *  mask_add_return,
Bool nonmaskable_add_return,
long *  mask_new_return,
Bool nonmaskable_new_return 
) [static]

Definition at line 237 of file xaux_ext_hdlrmng.c.

{
       xaux_ext_hdlrmng_db_t       *db = (xaux_ext_hdlrmng_db_t *)handle;
       int                  m;
       Bool                 rv = False;
       long                 mask_new;
       Bool                 nonmaskable_new;

#if defined(DEBUG_XAUX)
       fprintf(stderr, "(--) hdlrmng_add: handle=%p handler=%p sodata=%p "
              "mask=0x%x nonmaskable=%d %p %p %p %p\n",
              handle, handler, sodata, mask, nonmaskable,
              mask_add_return, nonmaskable_add_return,
              mask_new_return, nonmaskable_new_return);
#endif /* defined(DEBUG_XAUX) */

       if (handler == NULL) {
              return (False);
       }

       *mask_add_return = NoEventMask;
       *nonmaskable_add_return = False;
       mask_new = db->comb_mask;
       nonmaskable_new = db->comb_nonmaskable;

       for (m = 0; m < MAXMASK; m++) {
              if ((mask & (1L << m)) == 0L) {
                     continue;
              }
              if (add_to_list(&(db->maskable[m]), handler, sodata) == True) {
                     *mask_add_return |= (1L << m);
                     mask_new |= (1L << m);
              }
       }

       if (nonmaskable == True) {
              if (add_to_list(&(db->nonmaskable), handler, sodata) == True) {
                     *nonmaskable_add_return = True;
                     nonmaskable_new = True;
              }
       }

       if ((*mask_add_return != NoEventMask) ||
              (*nonmaskable_add_return == True)) {
              /* mask and/or nonmaskable has been changed */
              rv = True;
       }

       db->comb_mask = mask_new;
       db->comb_nonmaskable = nonmaskable_new;

       if (mask_new_return != NULL) {
              *mask_new_return = mask_new;
       }
       if (nonmaskable_new_return != NULL) {
              *nonmaskable_new_return = nonmaskable_new;
       }

       return (rv);
}

Here is the call graph for this function:

static void xaux_ext_hdlrmng_close ( xaux_ext_hdlrmng_handle_t  handle) [static]

Definition at line 417 of file xaux_ext_hdlrmng.c.

{
       xaux_ext_hdlrmng_db_t       *db = (xaux_ext_hdlrmng_db_t *)handle;
       int    i;

       if (db == NULL) {
              return;
       }

       for (i = 0; i < MAXMASK; i++) {
              free_list(db->maskable[i].next);
       }
       free_list(db->nonmaskable.next);
       free(db);
       return;
}

Here is the call graph for this function:

static Bool xaux_ext_hdlrmng_filter ( xaux_ext_hdlrmng_handle_t  handle,
xaux_ext_handle_t  ext_handle,
XEvent *  ev 
) [static]

Definition at line 375 of file xaux_ext_hdlrmng.c.

{
       xaux_ext_hdlrmng_db_t       *db = (xaux_ext_hdlrmng_db_t *)handle;
       xaux_ext_hdlrmng_ent_t      *le, *list;
       Bool   nonmaskable = False;
       long   mask;

#if defined(DEBUG_XAUX_DETAIL)
       fprintf(stderr, "(--) filter called ev->type = %d\n", ev->type);
#endif /* defined(DEBUG_XAUX_DETAIL) */

       mask = type2mask(ev->type, &nonmaskable);

       if (mask != NoEventMask) {
              le = db->maskable[mask2index(mask)].next;
              while (le != NULL) {
                     if ((*le->handler)(ext_handle,
                                   (Window)None, ev, le->sodata) == True) {
                            return (True);
                     }
                     le = le->next;
              }
       }

       if (nonmaskable == True) {
              le = db->nonmaskable.next;
              while (le != NULL) {
                     if ((*le->handler)(ext_handle,
                                   (Window)None, ev, le->sodata) == True) {
                            return (True);
                     }
                     le = le->next;
              }
       }

       return (False);
}

Here is the call graph for this function:

Definition at line 206 of file xaux_ext_hdlrmng.c.

{
       xaux_ext_hdlrmng_db_t       *db;
       int    i;

       if ((db = (xaux_ext_hdlrmng_db_t *)malloc(
                     sizeof (xaux_ext_hdlrmng_db_t))) == NULL) {
              return (NULL);
       }

       bzero(db, sizeof (xaux_ext_hdlrmng_db_t));

       for (i = 0; i < MAXMASK; i++) {
              db->maskable[i].prev = NULL;
              db->maskable[i].next = NULL;
              db->maskable[i].handler = NULL;
              db->maskable[i].sodata = NULL;
       }

       db->nonmaskable.prev = NULL;
       db->nonmaskable.next = NULL;
       db->nonmaskable.handler = NULL;
       db->nonmaskable.sodata = NULL;

       db->comb_mask = 0L;
       db->comb_nonmaskable = False;

       return ((xaux_ext_hdlrmng_handle_t)db);
}
static Bool xaux_ext_hdlrmng_remove ( xaux_ext_hdlrmng_handle_t  handle,
xaux_ext_cb_evhandler_t  handler,
void *  sodata,
long  mask,
Bool  nonmaskable,
long *  mask_rm_return,
Bool nonmaskable_rm_return,
long *  mask_new_return,
Bool nonmaskable_new_return 
) [static]

Definition at line 308 of file xaux_ext_hdlrmng.c.

{
       xaux_ext_hdlrmng_db_t       *db = (xaux_ext_hdlrmng_db_t *)handle;
       int                  m;
       Bool                 rv = False;
       long                 mask_new;
       Bool                 nonmaskable_new;

       if (handler == NULL) {
              return (False);
       }

       *mask_rm_return = NoEventMask;
       *nonmaskable_rm_return = False;
       mask_new = db->comb_mask;
       nonmaskable_new = db->comb_nonmaskable;

       for (m = 0; m < MAXMASK; m++) {
              if ((mask & (1L << m)) == 0L) {
                     continue;
              }
              if (rm_from_list(&(db->maskable[m]), handler, sodata) == True) {
                     if (db->maskable[m].next == NULL) {
                            *mask_rm_return |= (1L << m);
                            mask_new &= ~(1L << m);
                     }
              }
       }

       if (nonmaskable == True) {
              if (rm_from_list(&(db->nonmaskable), handler, sodata) == True) {
                     if (db->nonmaskable.next == NULL) {
                            *nonmaskable_rm_return = True;
                            nonmaskable_new = False;
                     }
              }
       }

       if ((*mask_rm_return != NoEventMask) ||
              (*nonmaskable_rm_return == True)) {
              /* mask and/or nonmaskable has been changed */
              rv = True;
       }

       db->comb_mask = *mask_new_return;
       db->comb_nonmaskable = *nonmaskable_new_return;

       if (mask_new_return != NULL) {
              *mask_new_return = mask_new;
       }
       if (nonmaskable_new_return != NULL) {
              *nonmaskable_new_return = nonmaskable_new;
       }

       return (rv);
}

Here is the call graph for this function:


Variable Documentation