home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / lib / PEX / include / cp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-29  |  5.5 KB  |  195 lines

  1. /* $XConsortium: cp.h,v 5.6 91/06/29 19:21:06 rws Exp $ */
  2.  
  3. /***********************************************************
  4. Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Sun Microsystems,
  13. the X Consortium, and MIT not be used in advertising or publicity 
  14. pertaining to distribution of the software without specific, written 
  15. prior permission.  
  16.  
  17. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
  18. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
  19. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  20. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24. ******************************************************************/
  25.  
  26. #ifndef PHG_CP_H_INCLUDED
  27. #define PHG_CP_H_INCLUDED
  28.  
  29. typedef void    (*Cp_func)();
  30.  
  31. #include "cpx.h"
  32. #include "X11/Xos.h"
  33.  
  34. /* The maximum number of indirect data blocks ("pointed to" data) that
  35.  * the CP will send across the communication channel for any single CP
  36.  * command.
  37.  */
  38. #define CP_MAX_COM_PTRS        50
  39.  
  40. #ifndef PEX_API_SOCKET_IPC
  41. #define CP_SHM_DATA_BUF_SIZE    20000    /* Pfloats, for correct alignment */
  42. #define CP_SHM_ARGS_BUF_SIZE    1000    /* args elements */
  43. #define CP_SHM_RET_BUF_SIZE    8000    /* Pfloats, for correct alignment */
  44. #else
  45. /* These buffers aren't used. */
  46. #define CP_SHM_DATA_BUF_SIZE    1
  47. #define CP_SHM_ARGS_BUF_SIZE    1
  48. #define CP_SHM_RET_BUF_SIZE    1
  49. #endif /* !PEX_API_SOCKET_IPC */
  50.  
  51. typedef enum {
  52.     CP_LOCAL,
  53.     CP_REMOTE
  54. } Cp_configuration;
  55.  
  56.  
  57. #define CP_FUNC( cph, _op, args, ret) \
  58.     ((args)->op = (unsigned)(_op), (*(cph)->funcs[(int)(_op)])((cph), (args), (ret)))
  59.  
  60. /* Struct to use for internal file buffering, similar to type FILE. */
  61. typedef struct {
  62.     int        cnt;        /* current number of bytes in buffer */
  63.     int        bufsize;    /* max size of buffer */
  64.     int        fd;
  65.     char    *ptr;        /* ptr to next byte to read */
  66.     char    *base;        /* ptr to buffer */
  67. } Cp_file;
  68.  
  69. typedef struct _Cp_display_connection {
  70.     Display    *display;
  71.     int        instance_count;
  72.     struct {
  73.     unsigned opened_by_api: 1;
  74.     }        flags;
  75.     struct _Cp_display_connection    *next;
  76. } Cp_display_connection;
  77.  
  78. /* Data specific to the configuration (local, monitor or client) */
  79.  
  80. typedef struct {
  81.     void    (*set_input_notify)();
  82. } Cp_data_local;
  83.  
  84. typedef struct {
  85.     int        child_pid;
  86.     int        sfd;        /* socket fd for communication with monitor */
  87. } Cp_data_client;
  88.  
  89. typedef enum {
  90.     CP_READING_ARGS,
  91.     CP_EXECUTING_CMD,
  92.     CP_CMD_DONE
  93. } Cp_cmd_state;
  94.  
  95. typedef struct {
  96.     int            parent_pid;
  97.     Cp_cmd_state    cmd_state;
  98.     int            cur_cnt;    /* number of bytes read so far */
  99.     Cp_file        *infile;
  100.     int            sfd;        /* communication with client fd */
  101.     Phg_args        *arg_buf;    /* not used when shared memory used */
  102.     Phg_ret        *ret_buf;    /* not used when shared memory used */
  103.     struct itimerval    cmd_timeout;
  104.     XtAppContext    app_con;
  105.     char        *name;        /* of application */
  106.     char        *classname;    /* of application */
  107.     int            argc;
  108.     char        **argv;
  109. } Cp_data_monitor;
  110.  
  111. typedef union {
  112.     Cp_data_local    local;
  113.     Cp_data_monitor    monitor;
  114.     Cp_data_client    client;
  115. } Cp_data;
  116.  
  117. typedef struct _Cp_wst_list_entry {
  118.     Wst_handle            wst;
  119.     struct _Cp_wst_list_entry    *next;
  120. } Cp_wst_list_entry;
  121.  
  122. typedef enum {
  123.     CP_RET_DATA_UNLOCKED,
  124.     CP_RET_DATA_LOCKED,
  125.     CP_RET_DATA_READY
  126. } Cp_ret_data_state;
  127.  
  128. /* Shared memory buffer. */
  129. typedef struct {
  130.     int        shmid;        /* id from shmget(2) call */
  131.     struct {
  132.     int        buf_size;
  133.     int        lock;
  134.     int        head;
  135.     int        tail;
  136.     Phg_args    buf[CP_SHM_ARGS_BUF_SIZE];
  137.     }        args;            /* args queue */
  138.     struct {
  139.     int        buf_size;
  140.     int        lock;
  141.     int        head;
  142.     int        tail;
  143.     Pfloat        buf[CP_SHM_DATA_BUF_SIZE];
  144.     }        data;            /* pre-data queue */
  145.     struct {
  146.     int            buf_size;
  147.     Cp_ret_data_state    state;
  148.     Phg_ret            data;
  149.     Pfloat            buf[CP_SHM_RET_BUF_SIZE];
  150.     }        ret;            /* returned data buffers */
  151. } Cp_shm_buf;
  152.  
  153. typedef struct _Cp_struct {
  154.     Cp_func        funcs[NUM_CP_FUNCS];
  155.     Psl_handle        psl;    /* NULL in monitor */
  156.     Err_handle        erh;
  157.     Cp_configuration    configuration;
  158.     Cp_data        data;
  159.     Ar_handle        arhl[MAX_NO_OPEN_ARFILES];
  160.     Input_q_handle    input_q;   /* only in monitor */
  161.     Cp_wst_list_entry    *wst_list; /* head of ws type linked list, not used
  162.                       in monitor */
  163.     Cpx_css_srvr    *css_srvr_list;
  164.     Ws_handle        ws_list;
  165.     Ar_handle        ar_list;
  166.     struct {
  167.     unsigned monitor_active: 1;
  168.     unsigned force_client_SS: 1;
  169.     unsigned in_monitor: 1;
  170.     unsigned err_sync: 1;
  171.     unsigned ignore_DC_errors: 1;
  172.     }            flags;
  173.     Phg_scratch        scratch;
  174.     Cp_shm_buf        *shm_buf;
  175.     int            max_fd;
  176.     /* Use a generous size for fd_masks, to avoid including <sys/param.h> */
  177.     unsigned long    fd_masks[64];
  178.     Phg_desc_tbl    pdt;
  179.     Cp_display_connection    *displays;
  180. } Cp_struct;
  181.  
  182. extern Cp_handle    phg_cp_open();
  183. extern int        phg_cp_add_wst();
  184. extern void        phg_cp_rmv_wst();
  185. extern void        phg_cp_send_request();
  186. extern int        phg_cp_any_inp_device_active();
  187.  
  188. /* Notify utilities */
  189. extern void        phg_ntfy_unregister_event();
  190. extern void        phg_ntfy_unregister_window();
  191. extern void        phg_ntfy_unregister_display();
  192.  
  193. #endif
  194.  
  195.