⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nml_mod.cc

📁 Source code for an Numeric Cmputer
💻 CC
📖 第 1 页 / 共 2 页
字号:
/*   nml_mod.cc   Definition of NML_MODULE class.   *//*   Modification history:    9-Sep-1997 WPS eliminated LOAL_LOCAL_VARIABLES, UNLOAD_LOCAL_VARIABLES,    READ_CHILD_BUFFERS, WRITE_CHILD_BUFFERS, and DETERMINE_CHILD_STATUS   29-May-1997 WPS replaced include nml_emc.hh with nml_oi.hh    3-Apr-1997 WPS brought over the functions from RCS_MODULE_C   11-Feb-1997 WPS modified  calc_avg_time, update_line_history, and   stop_timing all use exec_history but fail to check to   see if it is initialized.   I override them here minimize changes to rcs_module.cc   3-Dec-1996  FMP changed NML to RCS_CMD/STAT_CHANNEL for commandIn,   statusOut, etc.   112696-hui, changed the base class for commandInData, etc., from NMLmsg   to RCS_CMD_MSG and RCS_STAT_MSG.   16-Oct-1996  FMP inited done to 0 in ctor   29-Jul-1996  FMP moved NML_ERROR, NML_TEXT, NML_DISPLAY, and NML_STATUS   into nml_emc.cc   29-Jul-1996  FMP added NML_TEXT and NML_DISPLAY classes   10-Jun-1996  Fred Proctor added malloc/free of cmdOutstanding array   5-Jun-1996  Fred Proctor added NML error stuff   16-Apr-1996  Fred Proctor added NMLmsg * initing   5-Apr-1996  Fred Proctor created    */#ifdef __cplusplusextern "C"{#endif#include <stdlib.h>		// malloc()#include <string.h>		// strcpy()#include <errno.h>		// errno#include <stdarg.h>#include <math.h>		// fabs()#ifdef __cplusplus}#endif#include "nml_mod.hh"#include "nml_oi.hh"		// NML_ERROR, NML_TEXT, NML_DISPLAY#include "rcs_print.hh"#include "rcs_exit.hh"NML_MODULE::NML_MODULE (const char *inifile, const char *section){  zero_common_vars ();}NML_MODULE::NML_MODULE (){  zero_common_vars ();}voidNML_MODULE::zero_common_vars (){  commandIn = 0;  force_command = 0;  commandInData = 0;  statusOut = 0;  statusOutData = 0;  subs = 0;  commandLastNum = 0;  commandOutstanding = 0;  timer = 0;  numSubordinates = 0;  errorLog = 0;  done = 0;  statusInData = 0;  commandOutData = 0;  cycle_start = 0;  cycle_stop = 0;  command_time_averaged = 0;  new_command_sequence = 0;  new_line_num_sequence = 0;  new_sup_request = 0;  delta_clock = 0;  command_current_time = 0;  pause_status = 0;  command = 0;  last_line = 0;  execute = 0;  command_time = 0;  state = UNINITIALIZED_STATE;  status = UNINITIALIZED_STATUS;  sup_req_num = 0;  sup_req_num_echo = 0;  command_num = 0;  command_num_echo = 0;  // state table vars  matched = 0;  stateBegin = 0;/*! \todo Another #if 0 */#if 0//below 010997-hui  exec_status.command_num = 0;  exec_status.command = 0;  exec_status.status = 0;  exec_status.state = 0;  exec_status.line_num = 0;  exec_status.command_time = 0;  run_command.run_state = 0;  run_command.step_num = 0;  run_status.step_num_echo = 0;  run_status.dummy1 = 0;#endif  source_line = -1;  source_file = NULL;  commands_received = 0;  commands_executed = 0;  last_command_completed_serial_number = -1;  total_run_time = 0;  cycles = 0;  max_cycle_time = 0;  min_cycle_time = 1e6;  last_cycle_time = 0;  start_run_time = 0;  stop_run_time = 0;  last_start_run_time = 0;  subs_allocated = 0;  expected_cycle_time = 0;  min_run_time = 1e6;  max_run_time = 0;  start_cycle_time = 0;  temp_file = 0;  temp_line = 0;  Dclock_expiration = 0;  Dclock_start_time = 0;  log_line = 0;  log_src = 0;}NML_MODULE::~NML_MODULE (){  int t;  if (commandIn != 0)    delete commandIn;  commandIn = 0;  if (statusOut != 0)    delete statusOut;  statusOut = 0;  if (errorLog != 0)    delete (errorLog);  errorLog = 0;  if (subs != 0)    {      for (t = 0; t < numSubordinates; t++)	{	  if (subs[t] == 0)	    {	      continue;	    }	  if (subs[t]->commandOut != 0)	    {	      delete subs[t]->commandOut;	      subs[t]->commandOut = 0;	    }	  if (subs[t]->statusIn != 0)	    {	      delete subs[t]->statusIn;	      subs[t]->statusIn = 0;	    }	  subs[t]->commandOutData = 0;	  subs[t]->statusInData = 0;	  delete subs[t];	  subs[t] = 0;	}      free(subs);/*! \todo Another #if 0 */#if 0      if (NULL != ini)	{	  delete ini;	  ini = NULL;	}#endif      subs = 0;    }  if (commandOutstanding != 0)    {      free(commandOutstanding);      commandOutstanding = 0;    }  if (commandLastNum != 0)    {      free(commandLastNum);      commandLastNum = 0;    }  if (timer != 0)    {      delete timer;      timer = 0;    }  if (proc_name != 0)    {      free(proc_name);      proc_name = 0;    }}voidNML_MODULE::setCmdChannel (RCS_CMD_CHANNEL * cmd_channel){  if (NULL == cmd_channel)    {      rcs_print_error ("Command channel is NULL.\n");      rcs_exit (-1);    }  commandIn = cmd_channel;  if (!commandIn->valid ())    {      rcs_print_error ("Command channel is invalid.\n");      rcs_exit (-1);    }  else    {      commandInData = commandIn->get_address ();    }  if (NULL != commandIn->cms)    {      if (NULL != commandIn->cms->ProcessName)	{	  proc_name =	    (char *) malloc (strlen (commandIn->cms->ProcessName) + 1);	  strcpy (proc_name, commandIn->cms->ProcessName);	}    }}voidNML_MODULE::setStatChannel (RCS_STAT_CHANNEL * stat_channel,			    RCS_STAT_MSG * stat_msg){  if (NULL == stat_channel)    {      rcs_print_error ("Status channel is NULL.\n");      rcs_exit (-1);    }  statusOut = stat_channel;  if (!statusOut->valid ())    {      rcs_print_error ("Status channel is invalid.\n");      rcs_exit (-1);    }  if (NULL == stat_msg)    {      rcs_print_error ("Status out message is NULL.\n");      rcs_exit (-1);    }  if (stat_msg->type <= 0)    {      rcs_print_error	("Status out message must have positive type. (type = %d)\n",	 stat_msg->type);      rcs_exit (-1);    }  if (stat_msg->size < ((long) sizeof (RCS_STAT_MSG)))    {      rcs_print_error	("Status out message must have a size of atleast sizeof(RCS_STAT_MSG) or %d bytes,",	 sizeof (RCS_STAT_MSG));      rcs_print_error ("but the status out message size was only %d.\n",		       stat_msg->size);      rcs_exit (-1);    }  statusOutData = stat_msg;}voidNML_MODULE::setErrorLogChannel (NML * errorLog_channel){  if (NULL == errorLog_channel)    {      rcs_print_error ("Error Log channel is NULL.\n");      rcs_exit (-1);    }  errorLog = errorLog_channel;  if (!errorLog->valid ())    {      rcs_print_error ("Error Log channel is invalid.\n");      rcs_exit (-1);    }}intNML_MODULE::addSubordinate (RCS_CMD_CHANNEL * cmd_channel,			    RCS_STAT_CHANNEL * stat_channel){  int sub_num = numSubordinates;  setSubordinates (numSubordinates + 1);  if (NULL == cmd_channel)    {      logError ("Command Channel for subordinate %d is NULL.\n", sub_num);      rcs_exit (-1);    }  if (NULL == stat_channel)    {      logError ("Status Channel for subordinate %d is NULL.\n", sub_num);      rcs_exit (-1);    }  subs[sub_num]->commandOut = cmd_channel;  if (!subs[sub_num]->commandOut->valid ())    {      logError ("Command Channel for subordinate %d is invalid.\n", sub_num);      rcs_exit (-1);    }  else    {      subs[sub_num]->commandOutData =	subs[sub_num]->commandOut->get_address ();    }  commandOutData[sub_num] = subs[sub_num]->commandOutData;  subs[sub_num]->statusIn = stat_channel;  if (!subs[sub_num]->statusIn->valid ())    {      logError ("Command Channel for subordinate %d is invalid.\n", sub_num);      rcs_exit (-1);    }  else    {      subs[sub_num]->statusInData = subs[sub_num]->statusIn->get_address ();    }  statusInData[sub_num] = subs[sub_num]->statusInData;  return sub_num;}int  NML_MODULE::use_realloc =  1;intNML_MODULE::setSubordinates (int number){  int t;  int previousNumSubordinates = numSubordinates;  if (NULL == subs)    {      subs_allocated = 0;    }  if (subs_allocated > numSubordinates)    {      numSubordinates = number;      subs[number]->commandOut = 0;      subs[number]->commandOutData = 0;      subs[number]->statusIn = 0;      subs[number]->statusInData = 0;      statusInData[number] = 0;      commandOutData[number] = 0;      return 0;    }  if (number < 0)    return -1;  // record number of subordinates  numSubordinates = number;  // get out now if nothing else to do  if (number == 0)    return 0;  // allocate subordinate NML channels  // On NT we sometimes get a lame problem with realloc  if (use_realloc)    {      subs = (NML_SUBORDINATE_STRUCT **) realloc (subs,						  number *						  sizeof						  (NML_SUBORDINATE_STRUCT *));      statusInData = (RCS_STAT_MSG **) realloc (statusInData,						number *						sizeof (RCS_STAT_MSG *));      commandOutData = (RCS_CMD_MSG **) realloc (statusInData,						 number *						 sizeof (RCS_CMD_MSG *));    }  else    {      NML_SUBORDINATE_STRUCT **old_subs = subs;      RCS_STAT_MSG **old_statusInData = statusInData;      RCS_CMD_MSG **old_commandOutData = commandOutData;      subs =	(NML_SUBORDINATE_STRUCT **) malloc (number *						  sizeof						  (NML_SUBORDINATE_STRUCT *));      if (NULL != old_subs && NULL != subs)	{	  memcpy (subs, old_subs,		  previousNumSubordinates *		  sizeof (NML_SUBORDINATE_STRUCT *));	}      statusInData =	(RCS_STAT_MSG **) malloc (number * sizeof (RCS_STAT_MSG *));      if (NULL != old_statusInData && NULL != statusInData)	{	  memcpy (statusInData, old_statusInData,		  previousNumSubordinates * sizeof (RCS_STAT_MSG *));	}      commandOutData =	(RCS_CMD_MSG **) malloc (number * sizeof (RCS_CMD_MSG *));      if (NULL != old_commandOutData && NULL != commandOutData)	{	  memcpy (commandOutData, old_commandOutData,		  previousNumSubordinates * sizeof (RCS_CMD_MSG *));	}    }/*! \todo Another #if 0 */#if 0  // allocate commandOutstanding array  commandLastNum = (int *) realloc (commandLastNum, number * sizeof (int));  commandOutstanding = (int *) realloc (commandOutstanding,					number * sizeof (int));#endif  if (NULL == subs || NULL == statusInData)    {      rcs_print_error ("Out of memory.\n");      rcs_exit (-1);    }  // initialize each NML channel in the new arrays to 0  for (t = previousNumSubordinates; t < number; t++)    {      subs[t] = new NML_SUBORDINATE_STRUCT ();      if (NULL == subs[t])	{	  rcs_print_error ("Out of memory.\n");	  rcs_exit (-1);	}      subs[t]->commandOut = 0;      subs[t]->commandOutData = 0;      subs[t]->statusIn = 0;      subs[t]->statusInData = 0;      statusInData[t] = 0;      commandOutData[t] = 0;      //      commandOutstanding[t] = 0;    }  subs_allocated = numSubordinates;  return 0;}/*   Error, text, and display functions. Note that all these go to   the errorLog channel   */intNML_MODULE::setLogInfo (const char *src, int l){  log_line = l;  log_src = src;  return (0);};intNML_MODULE::logError (const char *fmt, ...){  NML_ERROR error_msg;  va_list ap;  memset (error_msg.error, 0, NML_ERROR_LEN);  if (log_line > 0 && log_src != NULL)    {      sprintf (error_msg.error, "%s:%d ", log_src, log_line);    }  // write args to NML message  va_start (ap, fmt);  vsprintf (error_msg.error, fmt, ap);  va_end (ap);  // force a NULL at the end for safety  error_msg.error[NML_ERROR_LEN - 1] = 0;  set_print_rcs_error_info (NULL, -1);  print_rcs_error_new ("%s\n", error_msg.error);  // check channel for validity  if (errorLog == NULL)    return -1;  if (!errorLog->valid ())    return -1;  // write it  errorLog->write (error_msg);  return 0;}intNML_MODULE::logText (const char *fmt, ...){  NML_TEXT text_msg;  va_list ap;  // check channel for validity  if (errorLog == NULL)    return -1;  if (!errorLog->valid ())    return -1;  // write args to NML message  va_start (ap, fmt);  vsprintf (text_msg.text, fmt, ap);  va_end (ap);  rcs_print ("%s\n", text_msg.text);  // force a NULL at the end for safety  text_msg.text[NML_TEXT_LEN - 1] = 0;  // write it  errorLog->write (text_msg);  return 0;}intlogTextToNML (NML * errorLog, const char *fmt, ...){  NML_TEXT text_msg;  va_list ap;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -