Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

filemem.hh

Go to the documentation of this file.
00001 /************************************************************************
00002 File: filemem.hh
00003 Purpose: Defines FILEMEM which is a derived class of CMS that provides
00004 a means of logging messages to a file or of reading messages from
00005 a pseudo-script.
00006 **********************************************************************/
00007 
00008 #ifndef FILEMEM_HH
00009 #define FILEMEM_HH
00010 
00011 
00012 #if defined(VXWORKS) || defined(DOS_WINDOWS) || defined(lynxosPC)
00013 #ifdef USE_FCNTL_FILE_LOCKING
00014 #undef USE_FCNTL_FILE_LOCKING
00015 #endif
00016 #endif
00017 
00018 #if !defined(USE_FCNTL_FILE_LOCKING) && !defined(MSDOS)
00019 #define FILEMEM_USE_SEMAPHORES
00020 #endif
00021 
00022 #include "rcs_defs.hh"          // DOS_WINDOWS
00023 #include "cms.hh"               // class CMS
00024 #include <stdio.h>              // FILE *, fpos_t
00025 
00026 #ifdef FILEMEM_USE_SEMAPHORES
00027 #include "sem.hh"               // class RCS_SEMAPHORE
00028 
00029 #if  !defined(DOS_WINDOWS) && !defined(VXWORKS)
00030 #include <sys/types.h>          /* key_t */
00031 #include <sys/ipc.h>
00032 #include <sys/sem.h>
00033 #endif
00034 
00035 #include <stddef.h>             /* size_t */
00036 
00037 #ifndef KEY_T_DEFINED
00038 
00039 #ifdef VXWORKS
00040 typedef int key_t;              /* key_t is not defined in VxWorks or  Windows -- do
00041                                    it here, and it should be visible
00042                                    throughout all the shared mem code */
00043 #endif
00044 
00045 #ifdef WIN32
00046 typedef long key_t;
00047 #endif
00048 #endif
00049 
00050 #endif
00051 
00052 
00053 #define FILEMEM_INPUT_BUFFER_SIZE (2048)
00054 
00055 
00056 #ifdef USE_FCNTL_FILE_LOCKING
00057 #include <sys/fcntl.h>
00058 #endif
00059 
00060 #ifdef sunos4
00061 // The sunos4 header files say that fgetpos and fsetpos take a pointer to a
00062 // a long even though ANSI says they should take an fpos_t.
00063 typedef long fpos_t;
00064 #endif
00065 
00066 class FILEMEM:public CMS
00067 {
00068 public:
00069   FILEMEM (char *bufline, char *procline, int set_to_server =
00070            0, int set_to_master = 0);
00071     virtual ~ FILEMEM ();
00072 
00073   /* Overloaded CMS functions. */
00074   CMS_STATUS clear ();
00075   int check_if_read ();
00076   CMS_STATUS read ();
00077   CMS_STATUS peek ();
00078   CMS_STATUS write (void *data);
00079   CMS_STATUS write_if_read (void *data);
00080 
00081 protected:
00082   char infile_name[80];
00083   char outfile_name[80];
00084   long input_file_pos;
00085   long max_output_messages;
00086   void close_input ();
00087   void reopen_input ();
00088   FILE *in;
00089   FILE *out;
00090   char input_buffer[FILEMEM_INPUT_BUFFER_SIZE];
00091   int input_is_stdin;
00092   int output_is_stdout;
00093   double last_read_time;
00094   double read_time;
00095   double last_write_time;
00096   double write_time;
00097   double wait_period;
00098   double wait_start;
00099   int write_cycle;
00100   int write_count;
00101   int read_cycle;
00102   int add_waits;
00103   fpos_t last_read_pos;
00104   fpos_t last_write_pos;
00105 #ifdef FILEMEM_USE_SEMAPHORES
00106   key_t key;                    /* key for sem */
00107   RCS_SEMAPHORE *sem;           /* semaphore */
00108 #endif
00109   long write_file_length;
00110 #ifdef USE_FCNTL_FILE_LOCKING
00111   struct flock read_lock;
00112   struct flock write_lock;
00113   int input_fd;
00114   int output_fd;
00115 #endif
00116   int lock_input ();
00117   int lock_output ();
00118   int unlock_input ();
00119   int unlock_output ();
00120 
00121 
00122 };
00123 
00124 
00125 
00126 #endif

Generated on Sun Dec 2 15:56:49 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001