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

nml_mod.cc

Go to the documentation of this file.
00001 
00002 /*
00003    nml_module.cc
00004 
00005    Definition of NML_MODULE class.
00006    */
00007 
00008 /*
00009    Modification history:
00010 
00011    11-Feb-1997 WPS modified  calc_avg_time, update_line_history, and
00012    stop_timing all use exec_history but fail to check to
00013    see if it is initialized.
00014    I override them here minimize changes to rcs_module.cc
00015    3-Dec-1996  FMP changed NML to RCS_CMD/STAT_CHANNEL for commandIn,
00016    statusOut, etc.
00017    112696-hui, changed the base class for commandInData, etc., from NMLmsg
00018    to RCS_CMD_MSG and RCS_STAT_MSG.
00019    16-Oct-1996  FMP inited done to 0 in ctor
00020    29-Jul-1996  FMP moved NML_ERROR, NML_TEXT, NML_DISPLAY, and NML_STATUS
00021    into nml_emc.cc
00022    29-Jul-1996  FMP added NML_TEXT and NML_DISPLAY classes
00023    10-Jun-1996  Fred Proctor added malloc/free of cmdOutstanding array
00024    5-Jun-1996  Fred Proctor added NML error stuff
00025    16-Apr-1996  Fred Proctor added NMLmsg * initing
00026    5-Apr-1996  Fred Proctor created
00027     */
00028 
00029 extern "C"
00030 {
00031 #include <stdlib.h>             // malloc()
00032 #include <string.h>             // strcpy()
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   // record number of subordinates
00137   numSubordinates = number;
00138 
00139   // get out now if nothing else to do
00140   if (number == 0)
00141     return 0;
00142 
00143   // allocate subordinate NML channels
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   // allocate commandOutstanding array
00152   commandLastNum = (int *) malloc (number * sizeof (int));
00153   commandOutstanding = (int *) malloc (number * sizeof (int));
00154 
00155   // initialize each NML channel in the new arrays to 0
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    Error, text, and display functions. Note that all these go to
00171    the errorLog channel
00172    */
00173 
00174 int
00175 NML_MODULE::logError (const char *fmt, ...)
00176 {
00177   NML_ERROR error_msg;
00178   va_list ap;
00179 
00180   // check channel for validity
00181   if (errorLog == NULL)
00182     return -1;
00183   if (!errorLog->valid ())
00184     return -1;
00185 
00186   // write args to NML message
00187   va_start (ap, fmt);
00188   vsprintf (error_msg.error, fmt, ap);
00189   va_end (ap);
00190 
00191   // force a NULL at the end for safety
00192   error_msg.error[NML_ERROR_LEN - 1] = 0;
00193 
00194   // write it
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   // check channel for validity
00207   if (errorLog == NULL)
00208     return -1;
00209   if (!errorLog->valid ())
00210     return -1;
00211 
00212   // write args to NML message
00213   va_start (ap, fmt);
00214   vsprintf (text_msg.text, fmt, ap);
00215   va_end (ap);
00216 
00217   // force a NULL at the end for safety
00218   text_msg.text[NML_TEXT_LEN - 1] = 0;
00219 
00220   // write it
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   // check channel for validity
00232   if (errorLog == NULL)
00233     return -1;
00234   if (!errorLog->valid ())
00235     return -1;
00236 
00237   // write args to NML message
00238   strcpy (display_msg.display, display);
00239 
00240   // force a NULL at the end for safety
00241   display_msg.display[NML_DISPLAY_LEN - 1] = 0;
00242 
00243   // write it
00244   errorLog->write (display_msg);
00245 
00246   return 0;
00247 }
00248 
00249 
00250   // WPS modified 11-Feb-1997 calc_avg_time, update_line_history, and
00251   // stop_timing all use exec_history but fail to check to
00252   // see if it is initialized.
00253   // I override them here minimize changes to rcs_module.cc
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 }

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