Diff for /Amaya/amaya/AHTBridge.c between versions 1.67 and 1.68

version 1.67, 1999/06/27 16:26:39 version 1.68, 1999/11/08 10:41:32
Line 15 Line 15
  *         J. K./R. Guetari. Windows NT/95 routines   *         J. K./R. Guetari. Windows NT/95 routines
  *   *
  */   */
   #ifdef _GTK
   #include <glib.h>
   #endif /* _GTK */
   
 #ifndef AMAYA_JAVA  #ifndef AMAYA_JAVA
   
 #define THOT_EXPORT extern  #define THOT_EXPORT extern
Line 32 Line 36
   
 #ifndef _WINDOWS  #ifndef _WINDOWS
 /* Amaya's X appcontext */  /* Amaya's X appcontext */
   
 extern ThotAppContext app_cont;  extern ThotAppContext app_cont;
   #ifndef _GTK
   
 /* Private functions */  /* Private functions */
 #ifdef __STDC__  #ifdef __STDC__
Line 52  static void         RequestRegisterExcep Line 56  static void         RequestRegisterExcep
 static void         RequestKillExceptXtevent ();  static void         RequestKillExceptXtevent ();
 #endif /* __STDC__ */  #endif /* __STDC__ */
   
   #endif /* _GTK */
 #endif /* !_WINDOWS */  #endif /* !_WINDOWS */
   
   #ifdef _GTK
   #define WWW_HIGH_PRIORITY (G_PRIORITY_HIGH_IDLE + 50)
   #define WWW_LOW_PRIORITY G_PRIORITY_LOW
   #define WWW_SCALE_PRIORITY(p) ((WWW_HIGH_PRIORITY - WWW_LOW_PRIORITY) * p \
                             / HT_PRIORITY_MAX + WWW_LOW_PRIORITY)
        
   #define READ_CONDITION (G_IO_IN | G_IO_HUP | G_IO_ERR)
   #define WRITE_CONDITION (G_IO_OUT | G_IO_ERR)
   #define EXCEPTION_CONDITION (G_IO_PRI)
        
    typedef struct _SockEventInfo SockEventInfo;
    struct _SockEventInfo {
      SOCKET s;
      HTEventType type;
      HTEvent *event;
      guint io_tag;
      guint timer_tag;
    };
    
    typedef struct _SockInfo SockInfo;
    struct _SockInfo {
      SOCKET s;
      GIOChannel *io;
      SockEventInfo ev[HTEvent_TYPES];
    };
    
    static GHashTable *sockhash = NULL;
    
    
    static SockInfo *
    get_sock_info(SOCKET s, gboolean create)
    {
      SockInfo *info;
    
      if (!sockhash)
        sockhash = g_hash_table_new(g_direct_hash, g_direct_equal);
    
      info = g_hash_table_lookup(sockhash, GINT_TO_POINTER(s));
      if (!info && create) {
        info = g_new0(SockInfo, 1);
        info->s = s;
        info->io = g_io_channel_unix_new(s);
        info->ev[0].s = info->ev[1].s = info->ev[2].s = s;
        info->ev[0].type = HTEvent_READ;
        info->ev[1].type = HTEvent_WRITE;
        info->ev[2].type = HTEvent_OOB;
        g_hash_table_insert(sockhash, GINT_TO_POINTER(s), info);
      }
      return info;
    }
    
    static gboolean glibwww_timeout_func (gpointer data);
    static gboolean glibwww_io_func(GIOChannel *source, GIOCondition condition,
                                    gpointer data);
   #endif /* _GTK */
   
 /* Private variables */  /* Private variables */
   
 /*  /*
Line 65  static void         RequestKillExceptXte Line 126  static void         RequestKillExceptXte
  * BSD Unix semantics    * BSD Unix semantics 
  */   */
   
   #ifndef _GTK
 static const HTEventType ReadBits = HTEvent_READ | HTEvent_ACCEPT | HTEvent_CLOSE;  static const HTEventType ReadBits = HTEvent_READ | HTEvent_ACCEPT | HTEvent_CLOSE;
 static const HTEventType WriteBits = HTEvent_WRITE | HTEvent_CONNECT;  static const HTEventType WriteBits = HTEvent_WRITE | HTEvent_CONNECT;
 static const HTEventType ExceptBits = HTEvent_OOB;  static const HTEventType ExceptBits = HTEvent_OOB;
Line 78  typedef struct sStatus { Line 140  typedef struct sStatus {
 #define SOCK_TABLE_SIZE 67  #define SOCK_TABLE_SIZE 67
 #define HASH(s) ((s) % SOCK_TABLE_SIZE)  #define HASH(s) ((s) % SOCK_TABLE_SIZE)
 static SocketStatus persSockets[SOCK_TABLE_SIZE];  static SocketStatus persSockets[SOCK_TABLE_SIZE];
   #endif /* _GTK */
   
 /*--------------------------------------------------------------------  /*--------------------------------------------------------------------
   AHTCallback_bridge    AHTCallback_bridge
Line 96  static SocketStatus persSockets[SOCK_TAB Line 159  static SocketStatus persSockets[SOCK_TAB
   the memory allocated to it.    the memory allocated to it.
   -------------------------------------------------------------------*/    -------------------------------------------------------------------*/
 #ifndef _WINDOWS  #ifndef _WINDOWS
   #ifndef _GTK
 #ifdef __STDC__  #ifdef __STDC__
 void *AHTCallback_bridge (caddr_t cd, int *s, XtInputId * id)  void *AHTCallback_bridge (caddr_t cd, int *s, XtInputId * id)
 #else  /* __STDC__ */  #else  /* __STDC__ */
Line 147  XtInputId          *id; Line 211  XtInputId          *id;
   
    return (0);     return (0);
 }  }
   #endif /* _GTK */
 #endif /* !_WINDOWS */  #endif /* !_WINDOWS */
   
 /*--------------------------------------------------------------------  /*--------------------------------------------------------------------
Line 296  HTAlertPar         *reply; Line 361  HTAlertPar         *reply;
 /* #else  */ /* _WINDOWS */  /* #else  */ /* _WINDOWS */
   
 #ifndef _WINDOWS  #ifndef _WINDOWS
   #ifndef _GTK
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHTEvent_register    AHTEvent_register
Line 345  HTEvent *event; Line 411  HTEvent *event;
       
   return (status);    return (status);
 }  }
   #endif /* _GTK */
 #endif /* _WINDOWS */  #endif /* _WINDOWS */
   
   #ifdef _GTK
   /*----------------------------------------------------------------------
     AHTEvent_register FOR GTK
     callback called by libwww whenever a socket is open and associated
     to a request. It sets the pertinent Xt events so that the Xt Event
     loops gets an interruption whenever there's action of the socket. 
     In addition, it registers the request with libwww.
     ----------------------------------------------------------------------*/
   int AHTEvent_register (SOCKET s, HTEventType type, HTEvent *event)
    {
      SockInfo *info;
      gint priority = G_PRIORITY_DEFAULT;
      GIOCondition condition;
    
      if (s == INVSOC || HTEvent_INDEX(type) >= HTEvent_TYPES)
        return 0;
    
      info = get_sock_info(s, TRUE);
      info->ev[HTEvent_INDEX(type)].event = event;
    
      switch (HTEvent_INDEX(type)) {
      case HTEvent_INDEX(HTEvent_READ):
        condition = READ_CONDITION;      break;
      case HTEvent_INDEX(HTEvent_WRITE):
        condition = WRITE_CONDITION;     break;
      case HTEvent_INDEX(HTEvent_OOB):
        condition = EXCEPTION_CONDITION; break;
      }
      if (event->priority != HT_PRIORITY_OFF)
        priority = WWW_SCALE_PRIORITY(event->priority);
    
      info->ev[HTEvent_INDEX(type)].io_tag =
        g_io_add_watch_full(info->io, priority, condition, glibwww_io_func,
                             &info->ev[HTEvent_INDEX(type)], NULL);
    
      if (event->millis >= 0)
        info->ev[HTEvent_INDEX(type)].timer_tag =
          g_timeout_add_full(priority, event->millis, glibwww_timeout_func,
                             &info->ev[HTEvent_INDEX(type)], NULL);
    
      return HT_OK;
    }
   #endif /* _GTK */
   
   #ifndef _GTK
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHTEvent_unregister    AHTEvent_unregister
   callback called by libwww each time a request is unregistered. This    callback called by libwww each time a request is unregistered. This
Line 386  HTEventType         type; Line 497  HTEventType         type;
         
    return (status);     return (status);
 }  }
   #endif /* _GTK */
   
   #ifdef _GTK
   /*----------------------------------------------------------------------
     AHTEvent_unregister FOR GTK
     callback called by libwww each time a request is unregistered. This
     function takes care of unregistering the pertinent Xt events
     associated with the request's socket. In addition, it unregisters
     the request from libwww.
     ----------------------------------------------------------------------*/
   int AHTEvent_unregister (SOCKET s, HTEventType type)
    {
      SockInfo *info = get_sock_info(s, FALSE);
    
      if (info) {
        if (info->ev[HTEvent_INDEX(type)].io_tag)
          g_source_remove(info->ev[HTEvent_INDEX(type)].io_tag);
        if (info->ev[HTEvent_INDEX(type)].timer_tag)
          g_source_remove(info->ev[HTEvent_INDEX(type)].timer_tag);
    
        info->ev[HTEvent_INDEX(type)].event = NULL;
        info->ev[HTEvent_INDEX(type)].io_tag = 0;
        info->ev[HTEvent_INDEX(type)].timer_tag = 0;
    
        /* clean up sock hash if needed */
        if (info->ev[0].event == NULL &&
            info->ev[1].event == NULL &&
            info->ev[2].event == NULL) {
          g_hash_table_remove(sockhash, GINT_TO_POINTER(s));
          g_io_channel_unref(info->io);
          g_free(info);
        }
        
        return HT_OK;
      }
      return HT_ERROR;
    }
   static gboolean
   glibwww_timeout_func (gpointer data)
    {
      SockEventInfo *info = (SockEventInfo *)data;
      HTEvent *event = info->event;
    
      (* event->cbf) (info->s, event->param, HTEvent_TIMEOUT);
      return TRUE;
    }
    
   static gboolean
   glibwww_io_func(GIOChannel *source, GIOCondition condition, gpointer data)
    {
      SockEventInfo *info = (SockEventInfo *)data;
      HTEvent *event = info->event;
    
      if (info->timer_tag)
          g_source_remove(info->timer_tag);
      if (info->event->millis >= 0) {
        gint priority = G_PRIORITY_DEFAULT;
    
        if (event->priority != HT_PRIORITY_OFF)
          priority = WWW_SCALE_PRIORITY(event->priority);
        info->timer_tag =
          g_timeout_add_full(priority, info->event->millis, glibwww_timeout_func,
                             info, NULL);
      }
    
      (* event->cbf) (info->s, event->param, info->type);
      return TRUE;
    }
   
   #endif /* _GTK */
   
 #ifndef _WINDOWS  #ifndef _WINDOWS
   
Line 403  void                RequestKillAllXteven Line 584  void                RequestKillAllXteven
 AHTReqContext      *me;  AHTReqContext      *me;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   #ifndef _GTK
   int sock = INVSOC;    int sock = INVSOC;
   
   return;    return;
Line 426  AHTReqContext      *me; Line 608  AHTReqContext      *me;
    RequestKillReadXtevent (sock);     RequestKillReadXtevent (sock);
    RequestKillWriteXtevent (sock);     RequestKillWriteXtevent (sock);
    RequestKillExceptXtevent (sock);     RequestKillExceptXtevent (sock);
   #endif /* _GTK */
 }  }
   
   #ifndef _GTK
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   RequestRegisterReadXtevent    RequestRegisterReadXtevent
   Registers with Xt the read events associated with socket sock    Registers with Xt the read events associated with socket sock
Line 769  HTTimer *libwww_timer; Line 953  HTTimer *libwww_timer;
       TtaFreeMemory (me);        TtaFreeMemory (me);
     }      }
 }  }
   #endif /* _GTK */
   
 #endif /* !_WINDOWS */  #endif /* !_WINDOWS */
   

Removed from v.1.67  
changed lines
  Added in v.1.68


Webmaster