Main Page | Data Structures | File List | Data Fields | Globals

isisserver.h

Go to the documentation of this file.
00001 #ifndef ISISSERVER_H
00002 #define ISISSERVER_H
00003 
00004 //
00005 // Main ISIS header file
00006 //
00007 // R. Pogge, OSU Astronomy Dept.
00008 // pogge@astronomy.ohio-state.edu
00009 // 2003 January 20
00010 //
00011 // Last modification: 2009 May 8 [v2.x]
00012 //
00013 
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <unistd.h>
00022 #include <string.h>
00023 #include <errno.h>
00024 #include <sys/stat.h>
00025 #include <sys/time.h>
00026 #include <sys/times.h>
00027 #include <sys/types.h>
00028 #include <sys/socket.h>
00029 #include <sys/file.h>
00030 #include <netdb.h>
00031 #include <netinet/in.h>
00032 #include <arpa/inet.h>
00033 #include <time.h>
00034 #include <termios.h>
00035 #include <fcntl.h>
00036 #include <ctype.h>
00037 
00038 // In case the version and compilation data are not defined at
00039 // compilation, put in some placeholders to prevent code barfing
00040 
00041 #ifndef ISIS_VERSION
00042 #define ISIS_VERSION "0.0"          
00043 #endif
00044 
00045 #ifndef ISIS_COMPDATE
00046 #define ISIS_COMPDATE "0000-00-00"  
00047 #endif
00048 
00049 #ifndef ISIS_COMPTIME
00050 #define ISIS_COMPTIME "00:00:00"    
00051 #endif
00052 
00053 #ifndef ISIS_CONFIG
00054 #define ISIS_CONFIG  "/lhome/dts/Config/isis.ini"   
00055 #endif
00056 
00057 #ifndef ISIS_DCONFIG
00058 #define ISIS_DCONFIG  "/lhome/dts/Config/isisd.ini"   
00059 #endif
00060 
00061 #ifndef ISIS_LOGS
00062 #define ISIS_LOGS  "/lhome/Logs/ISIS/isis.log"   
00063 #endif
00064 
00065 // Various site-dependent but system-independent default values 
00066 
00067 // These are for ISIS running at MDM
00068 
00069 #define DEFAULT_LOCALHOST "IS"  
00070 #define DEFAULT_ISISPORT  0  
00071 
00072 //
00073 // END of Site-Dependent Setup
00074 //
00075 // Touch the stuff below this at your own risk..
00076 //
00077 //--------------------------------------------------------------------------
00078 
00079 // String sizes 
00080 
00081 #define POSIX
00082 
00083 #define ISIS_MSGSIZE      4096  
00084 #define IMPv2_HOST_SIZE   9     
00085 #define LONG_STR_SIZE     4096  
00086 #define MED_STR_SIZE      256   
00087 #define BIG_STR_SIZE      2048  
00088 #define SHORT_STR_SIZE    32    
00089 
00090 // Some useful flags 
00091 
00092 #define isis_TRUE       1       
00093 #define isis_FALSE      0       
00094 #define NUL             '\0'    
00095 
00096 // Pseudo Client Indices for the server and broadcast 
00097 
00098 #define ISIS_SERVER   777       
00099 #define BROADCAST     666       
00100 
00101 // Message action flags 
00102 
00103 #define MSG_NOOP    0  
00104 #define MSG_REPLY   1  
00105 #define MSG_FORWARD 2  
00106 #define MSG_ECHO    3  
00107 
00108 // Message erorr codes 
00109 
00110 #define ERR_UNKNOWN_HOST  -1  
00111 #define ERR_UNKNOWN_FD    -2  
00112 #define ERR_HOSTS_FULL    -3  
00113 
00114 //--------------------------------------------------------------------------
00115 //
00116 // ISIS server global system table structure 
00117 //
00118 // Parameters are loaded from the isis.ini file
00119 //
00120 
00127 extern struct server {
00128   char serverID[IMPv2_HOST_SIZE];     
00129   int  sockFD;                        
00130   int  sockPort;                      
00131   char sockAddr[INET6_ADDRSTRLEN];    
00132   char hostName[64];                  
00133   char localHost[64];                 
00134   char startTime[24];                 
00135   char userID[SHORT_STR_SIZE];        
00136   int  keepGoing;                     
00137   int  isVerbose;                     
00138   int  useCLI;                        
00139   int  doLogging;                     
00140   int  doStartup;                     
00141   int  doHandShaking;                 
00142   char utcDate[SHORT_STR_SIZE];       
00143   char utcTime[SHORT_STR_SIZE];       
00144   char dateTag[SHORT_STR_SIZE];       
00145   char lastDate[SHORT_STR_SIZE];      
00146   char exeFile[MED_STR_SIZE];         
00147   char iniFile[MED_STR_SIZE];         
00148   char logRoot[MED_STR_SIZE];         
00149   char logFile[MED_STR_SIZE];         
00150   int  logFD;                         
00151   int  logDate;                       
00152   int  numClients;                    
00153   int  numSerial;                     
00154   int  numPreset;                     
00155   char instID[MED_STR_SIZE];          
00156 } isis;
00157 
00158 // ISIS Start/Restart Flags 
00159 
00160 #define NO_STARTUP   0  
00161 #define COLD_START   1  
00162 #define WARM_START   2  
00163 
00164 // ISIS logging date conventions
00165 
00166 #define UTCDATE      0  
00167 #define OBSDAY       1  
00168 
00169 //--------------------------------------------------------------------------
00170 //
00171 // ISIS Client Table
00172 //
00173  
00174 #define MAXCLIENTS 32  
00175 
00176 
00187 extern struct clients {
00188   char ID[IMPv2_HOST_SIZE];     
00189   int  method;                  
00190   int  fd;                      
00191   long addr;                    
00192   int  port;                    
00193   double tstamp;                
00194 } clientTab[MAXCLIENTS];
00195 
00196 // Client transport method codes 
00197 
00198 #define UNASSIGNED 0   
00199 #define SERIAL     1   
00200 #define SOCKET     2   
00201 
00202 //--------------------------------------------------------------------------
00203 //
00204 // ISIS serial port table
00205 //
00206 
00207 #define MAXSERIAL 8  
00208 
00209 
00216 extern struct serial {
00217   char devName[MED_STR_SIZE];  
00218   int  fd;                     
00219 } ttyTab[MAXSERIAL];
00220 
00221 //--------------------------------------------------------------------------
00222 //
00223 // ISIS preset UDP socket port table
00224 //
00225 // May define up to MAXPRESET UDP socket port targets to ping
00226 // on startup or restart.  These are not put into the host table
00227 // unless we get a response from one of the ports.
00228 //
00229 
00230 #define MAXPRESET   8  
00231 
00232 
00240 extern struct udpPreset {
00241   char host[MED_STR_SIZE];  
00242   int  port;                
00243 } udpTab[MAXPRESET];
00244 
00245 //--------------------------------------------------------------------------
00246 //
00247 // Function prototypes 
00248 //
00249  
00250 // Server startup and shutdown 
00251 
00252 int  openSocket(int );
00253 void closeSocket(int );
00254 int  loadConfig(char *);
00255 void handShake(void);
00256 
00257 // Client Host Table Functions 
00258 
00259 void initHostTable();
00260 int  updateHosts(char *, int, int, long, int);
00261 int  removeHost(char *);
00262 int  isKnownHost(char *);
00263 void printHosts(char *);
00264 void hostInfo(char *, char *);
00265 
00266 // Serial I/O Utilties 
00267 
00268 int  initSerialPorts(void);
00269 int  getSerialInfo(int );
00270 void portInfo(char *);
00271 
00272 // I/O handlers 
00273 
00274 void ttyHandler(char *line);
00275 void socketHandler(int );
00276 void serialHandler(int );
00277 void sendMessage(int, char *);
00278 void handleMessage(int, int, char *);
00279 void broadcastMessage(int, char *);
00280 
00281 // Command Utilities 
00282 
00283 int  isisCommand(char *, char *);
00284 int  serverInfo(char *);
00285 void printInfo(void);
00286 void printHelp(void);
00287 
00288 // Runtime Logging Utilities 
00289 
00290 void initLog(void);
00291 int  logMessage(char *);
00292 
00293 // Utilities 
00294 
00295 void   getUTCTime(void);
00296 char   *getFineTime(void);
00297 char   *getDateTime(void);
00298 double sysTimeStamp(void);
00299 char   *noonDateTag(void);
00300 void   getArg(char *, int, char *);
00301 void   upperCase(char *);
00302 
00303 #endif  // ISISSERVER_H

Generated on Tue Apr 16 17:04:08 2013 for ISIS Server by  doxygen 1.3.9.1