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

qsemu.h

Go to the documentation of this file.
00001 #ifndef QSEMU_ENVTBL_H
00002 #define QSEMU_ENVTBL_H
00003 
00004 /******************************************************************************
00005 * E.S.O. - VLT project
00006 *
00007 * "@(#) $Id: qsemu.h,v 3.49 2003/10/31 13:53:43 vltsccm Exp $" 
00008 *
00009 * qsemuEnvTbl.h - Include file for environment table 
00010 *                 Defines structure for table and
00011 *                 prototypes for functions to manipulate the table
00012 *
00013 * who        when       what
00014 * ---------- ---------- ----------------------------------------------
00015 * tebert     08.05.98   First Version
00016 * bgilli     05/10/99   Added MAXHOSTNAMELEN for LINUX
00017 * bgilli     21/10/99   increased hash table size from 16 to 64Kb
00018 * bgilli     01/03/00   Added Bytes swapping macros from T. Ebert.
00019 * bgilli     26/04/00   HP-UX 11 => common thread handling.
00020 */
00021 #define SELCAST(X)    (X) /* used in `select', but not defined in SUN-headers*/
00022 
00023 #ifndef __EXTENSIONS__
00024 #define __EXTENSIONS__
00025 #endif
00026 #ifndef _REENTRANT
00027 #define _REENTRANT
00028 #endif
00029 
00030 #include <errno.h>
00031 #include <stdlib.h>
00032 #include <sys/types.h>
00033 #include <unistd.h>
00034 #include <signal.h>
00035 #include <pwd.h>
00036 #include <limits.h>
00037 #include <pthread.h>
00038 #include <netdb.h>
00039 
00040 /*
00041  * defines
00042  */
00043 #if defined(i386) || defined(__i386)
00044 /*
00045  * byte swapping macros
00046  */
00047 
00048 /* most significant byte of 2-byte integer */
00049 #define QSEMU_MSB_INT16(x)        (((x) >>  8) & 0xff)
00050 /* least significant byte of 2-byte integer */
00051 #define QSEMU_LSB_INT16(x)         ((x)        & 0xff)
00052 /* most significant word of 2-word integer */
00053 #define QSEMU_MSW_INT32(x) (((x) >> 16) & 0xffff)
00054 /* least signifcant byte of 2-word integer */
00055 #define QSEMU_LSW_INT32(x)  ((x)        & 0xffff)
00056 
00057 /* swap the MSB with the LSB of a 16 bit integer */
00058 #define QSEMU_SWAP_INT16(x) (QSEMU_MSB_INT16(x) | (QSEMU_LSB_INT16(x) << 8))
00059 
00060 /* swap all bytes of a 32 bit integer */
00061 #define QSEMU_SWAP_INT32(x) (QSEMU_SWAP_INT16(QSEMU_LSW_INT32(x)) << 16) | \
00062                              QSEMU_SWAP_INT16(QSEMU_MSW_INT32(x))
00063 /* swap all bytes of two consecutive 32 bit integers */
00064 #define QSEMU_SWAP_2INT32(x_ptr,y_ptr) {int32_t i=*x_ptr;\
00065                                      *x_ptr=*y_ptr;\
00066                                      *y_ptr=i;}\
00067                            *x_ptr = QSEMU_SWAP_INT32(*x_ptr);         \
00068                            *y_ptr = QSEMU_SWAP_INT32(*y_ptr) 
00069 /*
00070 
00071 inline void qsemu_swap_2int32(int32_t* i1, int32_t* i2)
00072                            { int32_t i=*i1; *i1=*i2; *i2=i; };
00073          
00074 swap all bytes of two consecutive 32 bit integers 
00075 #define QSEMU_SWAP_2INT32(x_ptr,y_ptr) qsemu_swap_2int32(x_ptr, y_ptr); \
00076                            *x_ptr = QSEMU_SWAP_INT32(*x_ptr);         \
00077                            *y_ptr = QSEMU_SWAP_INT32(*y_ptr) 
00078 */
00079 #endif
00080 #ifdef LINUX
00081     #ifndef MAXHOSTNAMELEN
00082         #define        MAXHOSTNAMELEN  64
00083     #endif
00084 #endif
00085 #define qsemuCMD_PRINT_TBL              "QPRTBL"
00086 
00087 #define qsemuPROTOCOL_VERSION           3   /* default qsemu protocolVersion */
00088 #define qsemuPROTOCOL_VERSION_RTAP_6_6  3   /* identifies Rtap rev. >= 6.6   */
00089 #define qsemuMAX_ENVS                   100
00090 #define qsemuMAX_CONNECT_FAILURES       4
00091 #define qsemuDISCONNECT_WAIT_TIME       18  /* seconds */
00092 #define qsemuRETRY_TIMEOUT              3   /* seconds */
00093 #define qsemuHASH_SIZE                  65536
00094 #define qsemuTIMEOUT                    9
00095 
00096 /*
00097  * typedefs
00098  */
00099 typedef struct
00100     {
00101     int  mtype;
00102     char mtext[msgMAXLEN];
00103     } msgQUEUE;
00104 
00105 typedef struct
00106     {
00107     vltINT32        netPacketSize;
00108     char            userName[9];
00109     vltUINT8        reserved;
00110     vltUINT16       msgSeqNum;
00111     } qsemuNET_HEADER;
00112  
00113 typedef struct
00114     {
00115     qsemuNET_HEADER         netHeader;
00116     ccsMSG_ACK              msg;
00117     } qsemuNET_PACKET;
00118  
00119 typedef qsemuNET_PACKET *qsemuNET_PACKETP;
00120 
00121 
00122 typedef enum 
00123     {
00124     qsemuDISCONNECTED = 0,
00125     qsemuCONNECTING,
00126     qsemuCONNECTED
00127     } qsemuSTATE;
00128 
00129 typedef struct
00130     {
00131     rtProcessId     procId;
00132     vltUINT8        protocolVersion;
00133     } qsemuHELLO_MSG;
00134  
00135 typedef struct
00136     {
00137     qsemuNET_HEADER netHeader;
00138     qsemuHELLO_MSG  helloMsg;
00139     } qsemuNET_PACKET_ID;
00140 
00141 typedef struct
00142     {
00143     vltBYTES12 name;
00144     int        uid;
00145     } qsemuNAME_STRUCT;
00146 
00147 typedef struct
00148     {
00149     ccsENVNAME      env;
00150     char            host[MAXHOSTNAMELEN];
00151     int             tcpPort;
00152     char            netSuffix[8];
00153     int             fd;
00154     int             protocolVersion;
00155     int             pingCtr;
00156     int             waitPingResponse;
00157     int             connectFailures;
00158     int             monIndex;
00159     time_t          disconnectTime;
00160     pthread_t       threadId;
00161     qsemuSTATE      state;
00162     qsemuNET_PACKET qsMsg;
00163     } qsemuENV_LIST;
00164 
00165 
00166 /*
00167  * externals
00168  */
00169 extern int               qsemuTimeout;
00170 extern char              qsemuEnvTbl[MAX_INPUT];
00171 extern ccsENVNAME        qsemuEnvName;
00172 extern qsemuENV_LIST    *qsemuEnvList;
00173 extern int               qsemuEnvCnt;
00174 extern char              qsemuUser[9];
00175 extern int               qsemuFdReceive;
00176 extern int               qsemuPid;
00177 extern int               qsemuProtocolVersion;
00178 extern int               qsemuMsgSeqNum;
00179 extern pthread_t         qsemuThread;
00180 extern pthread_mutex_t   qsemuMutex;
00181 extern void             *qsemuHash;
00182 extern qsemuNAME_STRUCT *qsemuNames;
00183 extern vltLOGICAL        qsemuLog;
00184 extern int               qsemuCnt;
00185 
00186 /*
00187  * functions
00188  */
00189 ccsCOMPL_STAT  qsemuParseEnvList();
00190 ccsCOMPL_STAT  qsemuCreateSocket(ccsERROR *error);
00191 void           qsemuGetFromLocal(ccsERROR *error);
00192 void           qsemuGetFromRemote();
00193 void           qsemuSendNackToLocal(rtMsgHeader *header, ccsSINGLE_ERROR *singleError);
00194 ccsCOMPL_STAT  qsemuSendToLocal(msgQUEUE *msg, int size, int *errVal, ccsSINGLE_ERROR *singleError);
00195 qsemuENV_LIST *qsemuGetTblEntry(char *env);
00196 ccsCOMPL_STAT  qsemuConnectRemote(qsemuENV_LIST *entry, ccsSINGLE_ERROR *singleError, ccsERROR *error);
00197 ccsCOMPL_STAT  qsemuSendHello(int fd, ccsSINGLE_ERROR *singleError);
00198 ccsCOMPL_STAT  qsemuReadHello(int fd, qsemuENV_LIST *entry, ccsSINGLE_ERROR *singleError);
00199 
00200 int            qsemuReadSocket(int fd, char *buf, int len);
00201 ccsCOMPL_STAT  qsemuSendToRemote(qsemuENV_LIST *entry, qsemuNET_PACKET *qsMsg, 
00202                                  ccsSINGLE_ERROR *singleError);
00203 void           qsemuCloseEnv(qsemuENV_LIST *entry);
00204 ccsCOMPL_STAT  qsemuGetHelloAccept(int fd, qsemuENV_LIST **entry);
00205 ccsCOMPL_STAT  qsemuSendNackToRemote(qsemuENV_LIST *entry, vltUINT16 msgSeqNum, rtMsgHeader *header, 
00206                                      ccsSINGLE_ERROR *singleError, vltUINT8 type);
00207  
00208 ccsCOMPL_STAT  qsemuSendAckToRemote(qsemuENV_LIST *entry, vltUINT16 msgSeqNum, rtMsgHeader *header, 
00209                                     ccsSINGLE_ERROR *singleError);
00210 void           qsemuSendObituary(rtMsgHeader *msg);
00211 void           qsemuEnvThread(qsemuENV_LIST *entry);
00212 ccsCOMPL_STAT  qsemuSendPingResponse(qsemuENV_LIST *entry, vltUINT16 msgSeqNum, rtMsgHeader *header, 
00213                                      ccsSINGLE_ERROR *singleError);
00214 ccsCOMPL_STAT  qsemuSendProcnum(qsemuENV_LIST *entry, vltUINT16 msgSeqNum, rtMsgHeader *header, 
00215                                 ccsPROCNUM procnum, ccsSINGLE_ERROR *singleError);
00216 ccsCOMPL_STAT  qsemuSendProcname(qsemuENV_LIST *entry, vltUINT16 msgSeqNum, rtMsgHeader *header, 
00217                                  ccsPROCNAME name, ccsSINGLE_ERROR *singleError);
00218 ccsCOMPL_STAT  qsemuSendPid(qsemuENV_LIST *entry, vltUINT16 msgSeqNum, rtMsgHeader *header, 
00219                             rtInt pid, ccsSINGLE_ERROR *singleError);
00220 
00221 void           qsemuPrintNetHeader (qsemuNET_HEADER * netHeader);
00222 void           qsemuPrintMsgHeader (rtMsgHeader * msgHeader);
00223 void           qsemuLogDebug (char *fmt, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
00224 void           qsemuPrintNack (ccsACKNOWLEDGE *ack);
00225 msgLENGTH      qsemuSendTblToLocal(msgMSG *header, msgQUEUE *buf, ccsSINGLE_ERROR *singleError, ccsERROR *error);
00226 ccsCOMPL_STAT  qsemuQueryEnvTbl(char *printBuffer, int *printSize);
00227 
00228 ccsCOMPL_STAT  qsemuSendPingRequest(qsemuENV_LIST *entry,  ccsSINGLE_ERROR *singleError);
00229 int            qsemuCompare(const void *name1, const void *name2);
00230 
00231 #if defined(i386) || defined(__i386)
00232     void       qsemuMsgMassage (char *header, vltLOGICAL remote);
00233 #endif
00234 
00235 #ifndef ERROR
00236 #define ERROR -1
00237 #endif
00238 
00239 #ifndef OK
00240 #define OK 0
00241 #endif
00242 
00243 /* #define NULL 0 */
00244 /* typedef unsigned int size_t; */
00245  
00246  
00247 /*  Structure of hashtable in memory:
00248  *
00249  *    size_t         size;          // maximum number of entries
00250  *    size_t         insert_count;  // current number of entries
00251  *    Hashtable_item table[size];   // array of entries
00252  *
00253  *  Remaining memory is ununsed.
00254  */
00255  
00256 #define HASH_STRING_LENGTH 10
00257  
00258 struct Hashtable_item
00259 {
00260    char      key[HASH_STRING_LENGTH];   /* string for identification */
00261    char     *value;                     /* data combined with key    */
00262    int8_t    used;                      /* status of entry in array: */
00263                                         /*    0: not used up to now  */
00264                                         /*    1: used actually       */
00265                                         /*   -1: used before, but    */
00266                                         /*       not actually        */
00267 };
00268  
00269  
00270 /*  prototypes
00271  */
00272  
00273 int symAdd
00274     (
00275     void         *symTblId,    /* symbol table to add symbol to       */
00276     char         *key,         /* pointer to symbol key string        */
00277     char         *value        /* symbol address                      */
00278     );
00279  
00280 int symFindByName
00281     (
00282     void         *symTblId,    /* symbol table to add symbol to       */
00283     char         *key,         /* pointer to symbol key string        */
00284     char         **pValue      /* symbol address                      */
00285         );
00286  
00287 int symRemove /* caution: no merging of empty space */
00288     (
00289     void         *symTblId,    /* symbol tbl to remove symbol from    */
00290     char         *key          /* key of symbol to remove             */
00291         );
00292  
00293 int memPartAddToPool
00294     (
00295     void         *partId,      /* partition to initialize             */
00296     char         *pPool,       /* pointer to memory block             */
00297     unsigned     poolSize      /* block size in bytes                 */
00298         );
00299  
00300 int symHashCreate
00301     (
00302     int          tableSize,    /* max. size of hash table in bytes    */
00303     void         *symPartId    /* start of free memory for hash table */
00304         );
00305  
00306 int fetch_hash_index(
00307     void         *symTblId,    /* symbol table to fetch symbol from   */
00308     char         *search_key,  /* pointer to symbol key string        */
00309     size_t       *hash_index   /* returned index, if search_key found */
00310         );
00311  
00312 size_t hash_function(
00313     void         *symTblId,    /* symbol table to fetch symbol from   */
00314     char         *key          /* pointer to symbol key string        */
00315         );
00316  
00317 int hashtable_print_qsemu(
00318     void         *symTblId     /* symbol table                        */
00319         );
00320  
00321 int hashtable_statistics(
00322     void         *symTblId     /* symbol table                        */
00323         );
00324 
00325 #endif

Generated on Wed Dec 3 14:52:18 2003 for ATCS API by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001