Commit a9ed2f86 authored by Piotr Nikiel's avatar Piotr Nikiel
Browse files

Merge branch 'OPCUA-1978_sigint_handlers_for_graceful_stop' into 'master'

Ctrl-C handler

Closes OPCUA-1978

See merge request atlas-dcs-common-software/ScaSoftware!97
parents e7b93979 4be72fc7
......@@ -6,6 +6,7 @@
* Note: the original idea for this program is of Paris Moschovakos
*/
#include <signal.h>
#include <iostream>
#include <sstream>
#include <boost/program_options.hpp>
......@@ -32,6 +33,7 @@ struct Config
unsigned int fromHostPort;
unsigned int toHostPort;
};
Config parseProgramOptions(int argc, char* argv[])
{
using namespace boost::program_options;
......@@ -68,8 +70,17 @@ Config parseProgramOptions(int argc, char* argv[])
return config;
}
bool exitRequired (false);
void handleSigInt (int)
{
LOG(Log::INF) << "Caught Ctrl-C, clean shutdown will happen soon...";
exitRequired = true;
}
int main (int argc, char* argv[])
{
signal(SIGINT, handleSigInt );
Config config = parseProgramOptions(argc,argv);
const unsigned int numElinks = config.to - config.from + 1;
......@@ -83,7 +94,7 @@ int main (int argc, char* argv[])
std::vector<ScaInfo> foundSca (numElinks, ScaInfo());
std::cout << "-- scanning begun; it will take ~5 minutes. Summary results will be printed then." << std::endl;
for (unsigned int elink=config.from; elink<=config.to; ++elink)
for (unsigned int elink=config.from; elink <= config.to && !exitRequired; ++elink)
{
const std::string address =
"simple-netio://direct/" +
......
......@@ -5,6 +5,7 @@
* Author: pnikiel
*/
#include <signal.h>
#include <Hdlc/BackendFactory.h>
#include <Sca/Defs.h>
#include <Sca/SynchronousService.h>
......@@ -58,8 +59,18 @@ Config parseProgramOptions(int argc, char* argv[])
return config;
}
bool exitRequired (false);
void handleSigInt (int)
{
LOG(Log::INF) << "Caught Ctrl-C, clean shutdown will happen soon...";
exitRequired = true;
}
int main (int argc, char* argv[])
{
signal(SIGINT, handleSigInt );
Config config = parseProgramOptions( argc, argv);
srand(time(0));
......@@ -71,7 +82,7 @@ int main (int argc, char* argv[])
LOG(Log::INF) << "The chip id is: " << std::hex << sca.getChipId();
unsigned int i=0;
while (i < config.iterations)
while (i < config.iterations && !exitRequired)
{
try
{
......
......@@ -5,6 +5,8 @@
* Author: aikoulou, based on pnikiel
*/
#include <signal.h>
#include <Hdlc/BackendFactory.h>
#include <Sca/Defs.h>
#include <Sca/SynchronousService.h>
......@@ -19,14 +21,23 @@
using namespace ScaSwDemonstrators;
bool exitRequired (false);
void handleSigInt (int)
{
LOG(Log::INF) << "Caught Ctrl-C, clean shutdown will happen soon...";
exitRequired = true;
}
int main ()
{
signal(SIGINT, handleSigInt );
srand(time(0));
initializeLogging("INF");
Sca::Sca sca ("sca-simulator://1") ;
while (1)
while (!exitRequired)
{
try
{
......
......@@ -5,6 +5,8 @@
* Author: aikoulou, based on pnikiel
*/
#include <signal.h>
#include <Hdlc/BackendFactory.h>
#include <Sca/Defs.h>
#include <Sca/SynchronousService.h>
......@@ -50,10 +52,17 @@ Config parseProgramOptions(int argc, char* argv[])
return config;
}
bool exitRequired (false);
void handleSigInt (int)
{
LOG(Log::INF) << "Caught Ctrl-C, clean shutdown will happen soon...";
exitRequired = true;
}
int main (int argc, char* argv[])
{
signal(SIGINT, handleSigInt );
Config config = parseProgramOptions( argc, argv);
srand(time(0));
......@@ -61,7 +70,7 @@ int main (int argc, char* argv[])
sca.gpio().setRegister(::Sca::Constants::GpioRegisters::Direction,0xffffffff);
while (1)
while (!exitRequired)
{
try
{
......
......@@ -5,6 +5,8 @@
* Author: Paris Moschovakos
*/
#include <signal.h>
#include <Hdlc/BackendFactory.h>
#include <Sca/Defs.h>
#include <Sca/SynchronousService.h>
......@@ -51,14 +53,23 @@ Config parseProgramOptions(int argc, char* argv[])
return config;
}
bool exitRequired (false);
void handleSigInt (int)
{
LOG(Log::INF) << "Caught Ctrl-C, clean shutdown will happen soon...";
exitRequired = true;
}
int main (int argc, char* argv[])
{
signal(SIGINT, handleSigInt );
Config config = parseProgramOptions(argc, argv);
srand(time(0));
Sca::Sca sca ( config.address ) ;
while (1)
while (!exitRequired)
{
try
{
......
......@@ -5,6 +5,8 @@
* Author: pnikiel
*/
#include <signal.h>
#include <Hdlc/BackendFactory.h>
#include <Sca/Defs.h>
#include <Sca/SynchronousService.h>
......@@ -121,6 +123,13 @@ void runner (CommonInfo* info)
}
bool exitRequired (false);
void handleSigInt (int)
{
LOG(Log::INF) << "Caught Ctrl-C, clean shutdown will happen soon...";
exitRequired = true;
}
int main (int argc, char* argv[])
{
Config config = parseProgramOptions( argc, argv);
......@@ -144,7 +153,7 @@ int main (int argc, char* argv[])
}
while (1)
while (!exitRequired)
{
usleep (4000000);
size_t howManyAlive = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment