00001
00002
00003
00004
00005
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"
00023 #include "cms.hh"
00024 #include <stdio.h>
00025
00026 #ifdef FILEMEM_USE_SEMAPHORES
00027 #include "sem.hh"
00028
00029 #if !defined(DOS_WINDOWS) && !defined(VXWORKS)
00030 #include <sys/types.h>
00031 #include <sys/ipc.h>
00032 #include <sys/sem.h>
00033 #endif
00034
00035 #include <stddef.h>
00036
00037 #ifndef KEY_T_DEFINED
00038
00039 #ifdef VXWORKS
00040 typedef int key_t;
00041
00042
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
00062
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
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;
00107 RCS_SEMAPHORE *sem;
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