rendered paste body--- emcsvr.cc.old 2007-03-26 16:28:02.000000000 -0400
+++ emcsvr.cc 2007-03-26 16:27:05.000000000 -0400
@@ -17,7 +17,6 @@
********************************************************************/
#include <stdio.h> // sscanf()
-#include <math.h> // fabs()
#include <stdlib.h> // exit()
#include <string.h> // strncpy()
#include <unistd.h> // _exit()
@@ -33,6 +32,9 @@
#include "timer.hh"
#include "nml_srv.hh" // run_nml_servers()
+#define MAX_TIME 10.0
+#define RETRY_TIMEOUT .2
+
static int
iniLoad (const char *filename)
{
@@ -111,102 +113,76 @@
rcs_print ("after iniLoad()\n");
- start_time = etime ();
+ start_time = etime () + MAX_TIME;
+
+ emcCommandChannel =
+ new RCS_CMD_CHANNEL (emcFormat, "emcCommand", "emcsvr", EMC_NMLFILE);
+ emcStatusChannel =
+ new RCS_STAT_CHANNEL (emcFormat, "emcStatus", "emcsvr", EMC_NMLFILE);
+ emcErrorChannel =
+ new NML (nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE);
+ toolCommandChannel =
+ new RCS_CMD_CHANNEL (emcFormat, "toolCmd", "emcsvr", EMC_NMLFILE);
+ toolStatusChannel =
+ new RCS_STAT_CHANNEL (emcFormat, "toolSts", "emcsvr", EMC_NMLFILE);
+
- while (fabs (etime () - start_time) < 10.0 &&
- (emcCommandChannel == NULL || emcStatusChannel == NULL
- || toolCommandChannel == NULL || toolStatusChannel == NULL
- || emcErrorChannel == NULL))
+ //reinstantiation loop
+ while (etime () < start_time && !s)
{
- if (NULL == emcCommandChannel)
+ s = 1;
+ if (!emcCommandChannel->valid ())
{
- rcs_print ("emcCommandChannel==NULL, attempt to create\n");
+ delete emcCommandChannel;
emcCommandChannel =
new RCS_CMD_CHANNEL (emcFormat, "emcCommand", "emcsvr",
EMC_NMLFILE);
+ s = 0;
}
- if (NULL == emcStatusChannel)
+ if (!emcStatusChannel->valid ())
{
- rcs_print ("emcStatusChannel==NULL, attempt to create\n");
+ rcs_print
+ ("emcStatusChannel bungalo-ed, attempt to reinstantiate\n");
+ delete emcStatusChannel;
emcStatusChannel =
new RCS_STAT_CHANNEL (emcFormat, "emcStatus", "emcsvr",
EMC_NMLFILE);
+ s = 0;
}
- if (NULL == emcErrorChannel)
+ if (!emcErrorChannel->valid ())
{
+ rcs_print
+ ("emcErrorChannel bungalo-ed, attempt to reinstantiate\n");
+ delete emcErrorChannel;
emcErrorChannel =
new NML (nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE);
- }
- if (NULL == toolCommandChannel)
- {
- toolCommandChannel =
- new RCS_CMD_CHANNEL (emcFormat, "toolCmd", "emcsvr", EMC_NMLFILE);
- }
- if (NULL == toolStatusChannel)
- {
- toolStatusChannel =
- new RCS_STAT_CHANNEL (emcFormat, "toolSts", "emcsvr",
- EMC_NMLFILE);
+ s = 0;
}
-
- if (!emcCommandChannel->valid ())
- {
- delete emcCommandChannel;
- emcCommandChannel = NULL;
- }
- if (!emcStatusChannel->valid ())
- {
- delete emcStatusChannel;
- emcStatusChannel = NULL;
- }
- if (!emcErrorChannel->valid ())
- {
- delete emcErrorChannel;
- emcErrorChannel = NULL;
- }
if (!toolCommandChannel->valid ())
{
+ rcs_print
+ ("toolCommandChannel bungalo-ed, attempt to reinstantiate\n");
delete toolCommandChannel;
- toolCommandChannel = NULL;
+ toolCommandChannel =
+ new RCS_CMD_CHANNEL (emcFormat, "toolCmd", "emcsvr", EMC_NMLFILE);
+ s = 0;
}
if (!toolStatusChannel->valid ())
{
+ rcs_print
+ ("toolStatusChannel bungalo-ed, attempt to reinstantiate\n");
delete toolStatusChannel;
- toolStatusChannel = NULL;
+ toolStatusChannel =
+ new RCS_STAT_CHANNEL (emcFormat, "toolSts", "emcsvr",
+ EMC_NMLFILE);
+ s = 0;
}
-
- esleep (0.200);
+ esleep (RETRY_TIMEOUT);
}
set_rcs_print_destination (RCS_PRINT_TO_STDERR);
- if (NULL == emcCommandChannel)
- {
- emcCommandChannel =
- new RCS_CMD_CHANNEL (emcFormat, "emcCommand", "emcsvr", EMC_NMLFILE);
- }
- if (NULL == emcStatusChannel)
- {
- emcStatusChannel =
- new RCS_STAT_CHANNEL (emcFormat, "emcStatus", "emcsvr", EMC_NMLFILE);
- }
- if (NULL == emcErrorChannel)
- {
- emcErrorChannel =
- new NML (nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE);
- }
- if (NULL == toolCommandChannel)
- {
- toolCommandChannel =
- new RCS_CMD_CHANNEL (emcFormat, "toolCmd", "emcsvr", EMC_NMLFILE);
- }
- if (NULL == toolStatusChannel)
- {
- toolStatusChannel =
- new RCS_STAT_CHANNEL (emcFormat, "toolSts", "emcsvr", EMC_NMLFILE);
- }
-
signal (SIGTERM, nice_exit);
run_nml_servers ();