00001
00002 #ifndef NML_MODULE_H
00003 #define NML_MODULE_H
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "nml.hh"
00042 #include "stat_msg.hh"
00043 #include "cmd_msg.hh"
00044 #include "timer.hh"
00045 #include "inifile.h"
00046
00047
00048
00049
00050 #define STATE_MATCH (set_file_and_line(__FILE__,__LINE__)),stateMatch
00051
00052
00053
00054 enum RCS_STATE
00055 {
00056 UNINITIALIZED_STATE = -1,
00057 NEW_COMMAND = -2,
00058 NOP_STATE = -3,
00059 SE0 = -10,
00060 SE1 = -11,
00061 SE2 = -12,
00062 SE3 = -13,
00063 SE4 = -14,
00064 SE5 = -15,
00065 SE6 = -16,
00066 SE7 = -17,
00067 SE8 = -18,
00068 SE9 = -19,
00069 S0 = 0,
00070 S1 = 1,
00071 S2 = 2,
00072 S3 = 3,
00073 S4 = 4,
00074 S5 = 5,
00075 S6 = 6,
00076 S7 = 7,
00077 S8 = 8,
00078 S9 = 9,
00079 S10 = 10,
00080 S11 = 11,
00081 S12 = 12,
00082 S13 = 13,
00083 S14 = 14,
00084 S15 = 15,
00085 S16 = 16,
00086 S17 = 17,
00087 S18 = 18,
00088 S19 = 19,
00089 S20 = 20,
00090 S21 = 21,
00091 S22 = 22,
00092 S23 = 23,
00093 S24 = 24,
00094 S25 = 25,
00095 S26 = 26,
00096 S27 = 27,
00097 S28 = 28,
00098 S29 = 29,
00099 S30 = 30,
00100 S31 = 31,
00101 S32 = 32,
00102 S33 = 33,
00103 S34 = 34,
00104 S35 = 35,
00105 S36 = 36,
00106 S37 = 37,
00107 S38 = 38,
00108 S39 = 39
00109 };
00110
00111
00112 enum RCS_STATUS
00113 {
00114 UNINITIALIZED_STATUS = -1,
00115 RCS_DONE = 1,
00116 RCS_EXEC = 2,
00117 RCS_ERROR = 3
00118 };
00119
00120 struct NML_SUBORDINATE_STRUCT
00121 {
00122 public:
00123 RCS_CMD_CHANNEL * commandOut;
00124 RCS_STAT_CHANNEL *statusIn;
00125 RCS_CMD_MSG *commandOutData;
00126 RCS_STAT_MSG *statusInData;
00127 int modification_number;
00128 char *name;
00129 };
00130
00131
00132 #if 0
00133 class RCS_EXPORT NML_MODULE_INI_INFO
00134 {
00135 public:
00136 NML_MODULE_INI_INFO (const char *inifile, const char *section);
00137 virtual ~ NML_MODULE_INI_INFO ();
00138 INIFILE *inif;
00139 char nml_file[256];
00140 char ini_file[256];
00141 char ini_section[80];
00142 char module_name[80];
00143 char cmd_buf_name[80];
00144 char stat_buf_name[80];
00145 char err_buf_name[80];
00146 INIFILE_ENTRY entries[32];
00147 int num_entries;
00148
00149 long getLongInt (const char *, long def = -1);
00150 const char *getString (const char *, const char *def = NULL);
00151 double getDouble (const char *, double def = -1.0);
00152 };
00153 #endif
00154
00155 class RCS_EXPORT NML_MODULE
00156 {
00157 public:
00158
00159 void controller (void);
00160
00161 virtual void DECISION_PROCESS (void);
00162
00163 virtual void READ_COMM_BUFFERS (void);
00164 virtual void PRE_PROCESS ();
00165
00166
00167 virtual void WRITE_COMM_BUFFERS (void);
00168 virtual void POST_PROCESS ();
00169
00170
00171 int stateMatch (char *_src_file, int source_line, int state, int conds = 1);
00172 int stateMatch (int state, int conds = 1);
00173 void stateNext (int state);
00174 void stateNext (RCS_STATE state);
00175
00176 void read_command_in ();
00177 void read_subordinates_status ();
00178 void write_status_out ();
00179 void write_commands_to_subordinates ();
00180 void setCmdChannel (RCS_CMD_CHANNEL *);
00181
00182 void setStatChannel (RCS_STAT_CHANNEL *, RCS_STAT_MSG *);
00183
00184 void setErrorLogChannel (NML *);
00185 int addSubordinate (RCS_CMD_CHANNEL *, RCS_STAT_CHANNEL *);
00186 int sendCommand (RCS_CMD_MSG *, int sub_num);
00187 int modifyCommand (RCS_CMD_MSG *, int sub_num);
00188 void setSelfCommand (RCS_CMD_MSG *);
00189 int force_command;
00190
00191 void check_if_new_command (void);
00192
00193 #if 0
00194 RCS_EXEC_HISTORY_STRUCT exec_history;
00195 RCS_EXEC_STATUS_STRUCT exec_status;
00196
00197 RCS_RUN_COMMAND_STRUCT run_command;
00198 RCS_RUN_STATUS_STRUCT run_status;
00199 #endif
00200
00201 long cycle_start;
00202 long cycle_stop;
00203
00204 int command_time_averaged;
00205 int new_command_sequence;
00206 int new_line_num_sequence;
00207 int new_sup_request;
00208
00209 long delta_clock;
00210 long command_current_time;
00211
00212 int pause_status;
00213 int command;
00214 int last_line;
00215
00216 int execute;
00217 int command_time;
00218 RCS_STATE state;
00219 int status;
00220
00221 int sup_req_num;
00222 int sup_req_num_echo;
00223 int command_num;
00224 int command_num_echo;
00225
00226 private:
00227 int matched;
00228
00229 int stateBegin;
00230
00231 char *source_file;
00232 int source_line;
00233
00234 public:
00235
00236 NML_MODULE (const char *inifile, const char *section);
00237 NML_MODULE ();
00238 virtual ~ NML_MODULE ();
00239
00240 void zero_common_vars ();
00241
00242 #if 0
00243 NML_MODULE_INI_INFO *ini;
00244 #endif
00245
00246 RCS_CMD_CHANNEL *commandIn;
00247 RCS_STAT_CHANNEL *statusOut;
00248 NML *errorLog;
00249
00250 RCS_CMD_MSG *commandInData;
00251 RCS_STAT_MSG *statusOutData;
00252
00253 int *commandLastNum;
00254 int *commandOutstanding;
00255
00256
00257 NML_SUBORDINATE_STRUCT **subs;
00258 RCS_STAT_MSG **statusInData;
00259 RCS_CMD_MSG **commandOutData;
00260
00261 RCS_TIMER *timer;
00262
00263 int done;
00264
00265 int setSubordinates (int number);
00266 int setLogInfo (const char *src, int l);
00267 int logError (const char *fmt, ...);
00268 int logText (const char *fmt, ...);
00269 int requestDisplay (const char *display);
00270 void stop_timing (void);
00271 void set_file_and_line (char *file, int line);
00272
00273 int commands_received;
00274 int commands_executed;
00275 int cycles;
00276 int cycles_executing;
00277 int cycles_executing_completed_commands;
00278 int cycles_executing_this_command;
00279 int last_command_completed_serial_number;
00280 double expected_cycle_time;
00281 double start_run_time;
00282 double last_start_run_time;
00283 double stop_run_time;
00284 double total_run_time;
00285 double min_run_time;
00286 double max_run_time;
00287 double start_cycle_time;
00288 double min_cycle_time;
00289 double max_cycle_time;
00290 double last_cycle_time;
00291
00292 void check_cycle_time_start ();
00293 void check_cycle_time_end ();
00294 void print_statistics ();
00295
00296 void loadDclock (double expiration);
00297 int checkDclock ();
00298
00299 protected:
00300
00301 char *proc_name;
00302 char *temp_file;
00303 int temp_line;
00304 int numSubordinates;
00305 double Dclock_expiration;
00306 double Dclock_start_time;
00307 int log_line;
00308 const char *log_src;
00309
00310 public:
00311
00312
00313 int subs_allocated;
00314 static int use_realloc;
00315
00316
00317 };
00318
00319 #define NML_MOD_LOG_ERROR setLogInfo(__FILE__,__LINE__); logError
00320 extern int logTextToNML (NML *, const char *fmt, ...);
00321
00322 #endif