Main Page Class Hierarchy Compound List File List Compound Members File Members

# transport.h

Go to the documentation of this file.

    00001
    00002 /*
    00003  *   THIS FILE IS UNDER RCS - DO NOT MODIFY UNLESS YOU HAVE
    00004  *   CHECKED IT OUT USING THE COMMAND CHECKOUT.
    00005  *
    00006  *    $Id: transport_8h-source.html,v 1.1 2006/05/19 16:55:02 paulf Exp $
    00007  *
    00008  *    Revision history:
    00009  *     $Log: transport_8h-source.html,v $
    00009  *     Revision 1.1  2006/05/19 16:55:02  paulf
    00009  *     first inclusion
    00009  *
    00010  *     Revision 1.4  2001/05/04 23:39:11  dietz
    00011  *     changed SHM_HEAD.flag from short to int so it can hold processids.
    00012  *     changed prototype for tport_putflag accordingly.
    00013  *
    00014  *     Revision 1.3  2000/09/07 21:56:33  lucky
    00015  *     Changed NTRACK_PUT and NTRACK_GET to 200 and 500 respectively
    00016  *
    00017  *     Revision 1.2  2000/06/02 17:14:58  dietz
    00018  *     added TPORT_FATAL definition
    00019  *
    00020  *     Revision 1.1  2000/02/14 20:05:54  lucky
    00021  *     Initial revision
    00022  *
    00023  *
    00024  */
    00025
    00026
    00027     /********************************************************************/
    00028     /*                                                                  */
    00029     /*                          transport.h                             */
    00030     /*                                                                  */
    00031     /*             Include file for transport functions                 */
    00032     /*                to access shared memory regions.                  */
    00033     /*                                                                  */
    00034     /* This include file requires that _SOLARIS, _WIN32, or _OS2 be     */
    00035     /* defined in the makefile.                                         */
    00036     /*                                                                  */
    00037     /********************************************************************/
    00038
    00039 #ifndef TRANSPORT_H
    00040 #define TRANSPORT_H
    00041
    00042 #include <platform.h>
    00043
    00044 /* Structure types used in transport.c */
    00045
    00046 typedef struct {                   /********** shared memory header *********/
    00047         long             nbytes;   /* total size of shared memory region    */
    00048         unsigned long    keymax;   /* # usable bytes (nbytes - SHM_HEAD)    */
    00049         unsigned long    keyin;    /* index of next available byte          */
    00050         unsigned long    keyold;   /* index of oldest complete message      */
    00051         int              flag;     /* flag watched by attached programs     */
    00052 } SHM_HEAD;                        /*****************************************/
    00053
    00054
    00055 typedef struct {                   /******* shared memory information *******/
    00056         SHM_HEAD *       addr;     /* pointer to beginning of shred mem reg */
    00057         long             key;      /* key to shared memory region           */
    00058                                    /*                                       */
    00059 #ifdef _SOLARIS                    /* SOLARIS ONLY:                         */
    00060         long             mid;      /* shared memory region identifier       */
    00061         long             sid;      /* associated semaphore identifier       */
    00062 #endif                             /*                                       */
    00063 #ifdef _OS2                        /* OS2 ONLY:                             */
    00064         PVOID            objAlloc; /* pointer to memory object              */
    00065         HMTX             hmtx;     /* mutex semaphore handle                */
    00066 #endif                             /*                                       */
    00067 #ifdef  _WINNT                     /* WIN NT or 95 ONLY                     */
    00068         HANDLE           hShare;   /* shared memory region handle           */
    00069         HANDLE           hMutex;   /* mutex handle                          */
    00070 #endif                             /*                                       */
    00071 } SHM_INFO;                        /*****************************************/
    00072
    00073
    00074 typedef struct {                   /******** description of message *********/
    00075         unsigned char    type;     /* message is of this type               */
    00076         unsigned char    mod;      /* was created by this module id         */
    00077         unsigned char    instid;   /* at this installation                  */
    00078 } MSG_LOGO;                        /*****************************************/
    00079
    00080
    00081 typedef struct {                     /******** transport layer header *********/
    00082         char             start;      /* byte to flag beginning of this msg    */
    00083         long             size;       /* size of msg (not including TPORT_HEAD)*/
    00084         MSG_LOGO         logo;       /* description of message source         */
    00085         unsigned char    seq;        /* sequence number of message            */
    00086 } TPORT_HEAD;                        /*****************************************/
    00087
    00088
    00089 typedef struct {                     /***** sequence #, outpointer tracker ****/
    00090         long             memkey;     /* key to memory region being accessed   */
    00091         MSG_LOGO         logo;       /* description of message source         */
    00092         unsigned char    seq;        /* sequence number of message            */
    00093         unsigned long    keyout;     /* points to msg after last one "got"    */
    00094         unsigned char    active;     /* 0 until msg of logo is found in memkey*/
    00095 } MSG_TRACK;                         /*****************************************/
    00096
    00097
    00098 /* Definitions for tracking message logos (type,module,class) */
    00099 #define WILD          0   /* wildcard for message descriptor       */
    00100 #define NTRACK_PUT  200   /* max # message trackers for a "putter" */
    00101 #define NTRACK_GET  500   /* max # message trackers for a "getter" */
    00102 #define FIRST_BYTE  111   /* byte-value to flag beginning of msg   */
    00103                           /* Note: To work on both Solaris & OS2,  */
    00104                           /*       FIRST_BYTE must be from 0-127   */
    00105
    00106 /* Definition for internal use in transport functions */
    00107 #define TPORT_FATAL -99   /* a fatal error has occurred, function should exit */
    00108
    00109 /* Definitions of return values for tport_putmsg() and/or tport_copyto() */
    00110 #define PUT_OK        1   /* put the message in memory, no problems           */
    00111 #define PUT_NOTRACK  -1   /* NTRACK_PUT exceeded; msg not sent [tport_putmsg] */
    00112 #define PUT_TOOBIG   -2   /* message is too big for shared memory             */
    00113
    00114 /* Definitions of return values for tport_getmsg() and/or tport_copyfrom() */
    00115 #define GET_OK           1  /* got a requested message (modid,type,class)     */
    00116 #define GET_NONE         0  /* no messages of requested logo(s) in memory     */
    00117 #define GET_MISS        -1  /* got a message, but missed some [tport_getmsg]  */
    00118 #define GET_NOTRACK     -2  /* got a message, but NTRACK_GET was exceeded     */
    00119 #define GET_TOOBIG      -3  /* next message of requested logo(s) is too       */
    00120                             /* long for caller's buffer; no msg retrieved     */
    00121 #define GET_MISS_LAPPED -4  /* got a message, but some were overwritten       */
    00122                             /* before we saw to them [tport_copyfrom]         */
    00123 #define GET_MISS_SEQGAP -5  /* got a message, but there was a gap in seq #'s; */
    00124                             /* missed msgs were either never in the ring, or  */
    00125                             /* were previously found "toobig" [tport_copyfrom]*/
    00126
    00127 /* Definitions for semaphore operations */
    00128 #define SHM_INUSE    -1   /* add to semval to flag that memory is in use */
    00129 #define SHM_FREE      1   /* add to semval to flag that memory is free   */
    00130
    00131 /* Definitions for shared memory header flag */
    00132 #define TERMINATE  -999   /* tells attached programs to detach & terminate */
    00133
    00134
    00135 /* These functions are in transport.c */
    00136
    00137 void  tport_create( SHM_INFO *, long, long );
    00138 void  tport_destroy( SHM_INFO * );
    00139 void  tport_attach( SHM_INFO *, long );
    00140 void  tport_detach( SHM_INFO * );
    00141 int   tport_putmsg( SHM_INFO *, MSG_LOGO *, long, char * );
    00142 int   tport_getmsg( SHM_INFO *, MSG_LOGO *, short, MSG_LOGO *,
    00143                     long *, char *, long );
    00144 void  tport_putflag( SHM_INFO *, int );
    00145 int   tport_getflag( SHM_INFO * );
    00146 int   tport_buffer  ( SHM_INFO *, SHM_INFO *, MSG_LOGO *, short, unsigned,
    00147                       unsigned char, unsigned char );
    00148 int   tport_copyto  ( SHM_INFO *, MSG_LOGO *, long, char *, unsigned char );
    00149 int   tport_copyfrom( SHM_INFO *, MSG_LOGO *, short, MSG_LOGO *,
    00150                       long *, char *, long, unsigned char * );
    00151
    00152 /* SOLARIS ONLY: */
    00153 /* This union definition is in sys/sem.h in SunOS, but not in Solaris */
    00154 /* It's an argument template for semctl system calls on semaphores    */
    00155 #ifdef _SOLARIS
    00156 union semun
    00157 {
    00158         int              val;   /* value for SETVAL */
    00159         struct semid_ds *buf;   /* buffer for IPC_STAT & IPC_SET */
    00160         unsigned short  *array; /* array for GETALL & SETALL */
    00161 };
    00162 #endif
    00163
    00164 #endif