14 #include "PlusConfigure.h" 15 #include "igsioCommon.h" 23 #include "vtkSmartPointer.h" 24 #include "vtkIGSIOTransformRepository.h" 25 #include "vtksys/CommandLineArguments.hxx" 36 void CheckConsoleWindowCloseRequested(HWND consoleHwnd);
40 int main(
int argc,
char** argv)
43 bool printHelp(
false);
44 std::string inputConfigFileName;
45 std::string testingConfigFileName;
46 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
47 double runTimeSec = 0.0;
49 const int numOfTestClientsToConnect = 5;
51 vtksys::CommandLineArguments args;
52 args.Initialize(argc, argv);
54 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
55 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Name of the input configuration file.");
56 args.AddArgument(
"--running-time", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &runTimeSec,
"Server running time period in seconds. If the parameter is not defined or 0 then the server runs infinitely.");
57 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
61 std::cerr <<
"Problem parsing arguments." << std::endl;
62 std::cout <<
"Help: " << args.GetHelp() << std::endl;
68 std::cout << args.GetHelp() << std::endl;
74 if (inputConfigFileName.empty())
76 LOG_ERROR(
"--config-file argument is required!");
77 std::cout <<
"Help: " << args.GetHelp() << std::endl;
84 vtkNew<vtkPlusDataCollector> dataCollector;
85 if (dataCollector->ReadConfiguration(inputConfigFileName) !=
PLUS_SUCCESS)
87 LOG_ERROR(
"Datacollector failed to read configuration");
92 LOG_INFO(
"Server status: Reading configuration.");
96 vtkNew<vtkIGSIOTransformRepository> transformRepository;
97 if (transformRepository->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
99 LOG_ERROR(
"Transform repository failed to read configuration");
103 LOG_INFO(
"Server status: Connecting to devices.");
106 LOG_ERROR(
"Datacollector failed to connect to devices");
112 LOG_ERROR(
"Datacollector failed to start");
116 LOG_INFO(
"Server status: Starting servers.");
117 std::vector<vtkPlusOpenIGTLinkServer*> serverList;
119 for (
int i = 0;
i < configRootElement->GetNumberOfNestedElements(); ++
i)
121 vtkXMLDataElement* serverElement = configRootElement->GetNestedElement(
i);
122 if (STRCASECMP(serverElement->GetName(),
"PlusOpenIGTLinkServer") != 0)
130 vtkSmartPointer<vtkPlusOpenIGTLinkServer>
server = vtkSmartPointer<vtkPlusOpenIGTLinkServer>::New();
131 LOG_DEBUG(
"Initializing Plus OpenIGTLink server... ");
134 LOG_ERROR(
"Failed to start OpenIGTLink server");
137 serverList.push_back(
server);
139 if (serverCount == 0)
141 LOG_ERROR(
"No vtkPlusOpenIGTLinkServer tags were found in the configuration file. Please add at least one.");
145 double startTime = vtkIGSIOAccurateTimer::GetSystemTime();
147 LOG_INFO(
"Server status: Server(s) are running.");
148 LOG_INFO(
"Press Ctrl-C to quit.");
153 HWND consoleHwnd = GetConsoleWindow();
156 bool neverStop = (runTimeSec == 0.0);
159 const double commandQueuePollIntervalSec = 0.010;
160 while ((neverStop || (vtkIGSIOAccurateTimer::GetSystemTime() < startTime + runTimeSec)) && !
stopRequested)
162 for (std::vector<vtkPlusOpenIGTLinkServer*>::iterator it = serverList.begin(); it != serverList.end(); ++it)
164 (*it)->ProcessPendingCommands();
169 CheckConsoleWindowCloseRequested(consoleHwnd);
172 vtkIGSIOAccurateTimer::DelayWithEventProcessing(commandQueuePollIntervalSec);
175 for (std::vector<vtkPlusOpenIGTLinkServer*>::iterator it = serverList.begin(); it != serverList.end(); ++it)
180 LOG_INFO(
"Shutdown successful.");
188 LOG_INFO(
"Stop requested...");
197 void CheckConsoleWindowCloseRequested(HWND consoleHwnd)
200 if (PeekMessage(&msg, 0, WM_CLOSE, WM_CLOSE, PM_NOREMOVE))
205 if (msg.hwnd == NULL || msg.hwnd == consoleHwnd)
std::string GetDeviceSetConfigurationFileName()
void SignalInterruptHandler(int s)
static vtkPlusConfig * GetInstance()
static vtkIGSIOLogger * Instance()
int main(int argc, char **argv)
virtual vtkXMLDataElement * GetDeviceSetConfigurationData()
static bool stopRequested
vtkNew< vtkPlusOpenIGTLinkServer > server