00001
00002
00003
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 extern "C"
00030 {
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <stdarg.h>
00034 }
00035
00036 #include "nml_emc.hh"
00037 #include "nml_mod.h"
00038 #include "rcs_mod.h"
00039 #include "rcs.hh"
00040
00041 NML_MODULE::NML_MODULE ()
00042 {
00043 commandIn = 0;
00044 commandInData = 0;
00045 statusOut = 0;
00046 statusOutData = 0;
00047 commandOut = 0;
00048 commandOutData = 0;
00049 statusIn = 0;
00050 statusInData = 0;
00051 commandLastNum = 0;
00052 commandOutstanding = 0;
00053 timer = 0;
00054 numSubordinates = 0;
00055 errorLog = 0;
00056 done = 0;
00057 }
00058
00059 NML_MODULE::~NML_MODULE ()
00060 {
00061 int t;
00062
00063 if (commandIn != 0)
00064 delete commandIn;
00065 commandIn = 0;
00066
00067 if (statusOut != 0)
00068 delete statusOut;
00069 statusOut = 0;
00070
00071 if (errorLog != 0)
00072 delete (errorLog);
00073 errorLog = 0;
00074
00075 if (commandOut != 0)
00076 {
00077 for (t = 0; t < numSubordinates; t++)
00078 {
00079 if (commandOut[t] != 0)
00080 delete commandOut[t];
00081 }
00082
00083 free (commandOut);
00084 commandOut = 0;
00085 }
00086
00087 if (commandInData != 0)
00088 {
00089 free (commandOutData);
00090 commandOutData = 0;
00091 }
00092
00093 if (statusIn != 0)
00094 {
00095 for (t = 0; t < numSubordinates; t++)
00096 {
00097 if (statusIn[t] != 0)
00098 delete statusIn[t];
00099 }
00100
00101 free (statusIn);
00102 statusIn = 0;
00103 }
00104
00105 if (statusInData != 0)
00106 {
00107 free (statusInData);
00108 statusInData = 0;
00109 }
00110
00111 if (commandOutstanding != 0)
00112 {
00113 free (commandOutstanding);
00114 commandOutstanding = 0;
00115 }
00116
00117 if (commandLastNum != 0)
00118 {
00119 free (commandLastNum);
00120 commandLastNum = 0;
00121 }
00122
00123 if (timer != 0)
00124 delete timer;
00125 timer = 0;
00126 }
00127
00128 int
00129 NML_MODULE::setSubordinates (int number)
00130 {
00131 int t;
00132
00133 if (number < 0)
00134 return -1;
00135
00136
00137 numSubordinates = number;
00138
00139
00140 if (number == 0)
00141 return 0;
00142
00143
00144 commandOut =
00145 (RCS_CMD_CHANNEL **) malloc (number * sizeof (RCS_CMD_CHANNEL *));
00146 commandOutData = (RCS_CMD_MSG **) malloc (number * sizeof (RCS_CMD_MSG *));
00147 statusIn =
00148 (RCS_STAT_CHANNEL **) malloc (number * sizeof (RCS_STAT_CHANNEL *));
00149 statusInData = (RCS_STAT_MSG **) malloc (number * sizeof (RCS_STAT_MSG *));
00150
00151
00152 commandLastNum = (int *) malloc (number * sizeof (int));
00153 commandOutstanding = (int *) malloc (number * sizeof (int));
00154
00155
00156 for (t = 0; t < number; t++)
00157 {
00158 commandOut[t] = 0;
00159 commandOutData[t] = 0;
00160 statusIn[t] = 0;
00161 statusInData[t] = 0;
00162
00163 commandOutstanding[t] = 0;
00164 }
00165
00166 return 0;
00167 }
00168
00169
00170
00171
00172
00173
00174 int
00175 NML_MODULE::logError (const char *fmt, ...)
00176 {
00177 NML_ERROR error_msg;
00178 va_list ap;
00179
00180
00181 if (errorLog == NULL)
00182 return -1;
00183 if (!errorLog->valid ())
00184 return -1;
00185
00186
00187 va_start (ap, fmt);
00188 vsprintf (error_msg.error, fmt, ap);
00189 va_end (ap);
00190
00191
00192 error_msg.error[NML_ERROR_LEN - 1] = 0;
00193
00194
00195 errorLog->write (error_msg);
00196
00197 return 0;
00198 }
00199
00200 int
00201 NML_MODULE::logText (const char *fmt, ...)
00202 {
00203 NML_TEXT text_msg;
00204 va_list ap;
00205
00206
00207 if (errorLog == NULL)
00208 return -1;
00209 if (!errorLog->valid ())
00210 return -1;
00211
00212
00213 va_start (ap, fmt);
00214 vsprintf (text_msg.text, fmt, ap);
00215 va_end (ap);
00216
00217
00218 text_msg.text[NML_TEXT_LEN - 1] = 0;
00219
00220
00221 errorLog->write (text_msg);
00222
00223 return 0;
00224 }
00225
00226 int
00227 NML_MODULE::requestDisplay (const char *display)
00228 {
00229 NML_DISPLAY display_msg;
00230
00231
00232 if (errorLog == NULL)
00233 return -1;
00234 if (!errorLog->valid ())
00235 return -1;
00236
00237
00238 strcpy (display_msg.display, display);
00239
00240
00241 display_msg.display[NML_DISPLAY_LEN - 1] = 0;
00242
00243
00244 errorLog->write (display_msg);
00245
00246 return 0;
00247 }
00248
00249
00250
00251
00252
00253
00254
00255 void
00256 NML_MODULE::calc_avg_time (void)
00257 {
00258 if (NULL == exec_history)
00259 {
00260 return;
00261 }
00262 RCS_MODULE_C::calc_avg_time ();
00263 }
00264
00265
00266 void
00267 NML_MODULE::update_line_num_history (void)
00268 {
00269 if (NULL == exec_history)
00270 {
00271 return;
00272 }
00273 RCS_MODULE_C::update_line_num_history ();
00274 }
00275
00276 void
00277 NML_MODULE::stop_timing (void)
00278 {
00279 if (NULL == exec_history)
00280 {
00281 return;
00282 }
00283 RCS_MODULE_C::update_line_num_history ();
00284 }