Commit b1026805 authored by Sylvain Fargier's avatar Sylvain Fargier 🐾
Browse files

Merge branch 'wip-warnings-reset2' into 'master'

[NTOFNEWDAQ-789] impl real reset

See merge request !17
parents 748c54d5 ea480555
Pipeline #3449822 passed with stages
in 10 minutes and 58 seconds
ntofutils @ 973fb2de
Subproject commit 5faf77c6f6342f13674a0c8e4de7175450cf7c4e
Subproject commit 973fb2de7789a1361c7c8c5b93f5615e529f2458
......@@ -72,11 +72,11 @@ void ADDHWriter::initServices()
// Other dependencies
m_addh.reset(new ADDH());
connect(&m_addh->errorSignal, &m_addh->warningSignal);
connect("addh", &m_addh->errorSignal, &m_addh->warningSignal);
m_addh->initConfigurations();
m_writer.reset(new WriterFile(m_addh));
connect(&m_writer->errorSignal, &m_writer->warningSignal);
connect("writer", &m_writer->errorSignal, &m_writer->warningSignal);
m_addhCmd.reset(new ADDHCmd());
......@@ -160,14 +160,15 @@ void ADDHWriter::doAction(ADDHCommand *command)
{
actionWrite(command);
}
else if ((*command).command == "clear")
{
clearWarnings();
}
else if ((*command).command == "reset")
{
clearWarnings();
clearErrors();
// Reset ADDH Class
disconnect("addh");
m_addh.reset(new ADDH());
connect("addh", &m_addh->errorSignal, &m_addh->warningSignal);
m_addh->initConfigurations();
}
}
......@@ -178,13 +179,22 @@ void ADDHWriter::actionWrite(ADDHCommand *command)
m_writer->addCommand((*command));
}
void ADDHWriter::connect(ErrorSignal *err, WarningSignal *warn)
void ADDHWriter::connect(const std::string &key,
ErrorSignal *err,
WarningSignal *warn)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (err)
m_conn.emplace_back(err->connect(m_errSlot));
m_conn.emplace(std::make_pair(key + "_err", err->connect(m_errSlot)));
if (warn)
m_conn.emplace_back(warn->connect(m_warnSlot));
m_conn.emplace(std::make_pair(key + "_warn", warn->connect(m_warnSlot)));
}
void ADDHWriter::disconnect(const std::string &key)
{
std::lock_guard<std::mutex> lock(m_mutex);
m_conn.erase(key + "_err");
m_conn.erase(key + "_warn");
}
} /* namespace addh */
......
......@@ -87,7 +87,14 @@ public:
/**
* @brief connect an error signal to this state machine
*/
void connect(ErrorSignal *err, WarningSignal *warn = nullptr);
void connect(const std::string &key,
ErrorSignal *err,
WarningSignal *warn = nullptr);
/**
* @brief disconnect an error signal to this state machine
*/
void disconnect(const std::string &key);
protected:
/**
......@@ -127,7 +134,7 @@ protected:
std::function<WarningSignal::signature_type> m_warnSlot;
// protected with Thread::m_mutex
std::list<ntof::dim::scoped_connection> m_conn;
std::map<std::string, ntof::dim::scoped_connection> m_conn;
};
} /* namespace addh */
......
......@@ -33,11 +33,6 @@ using namespace ntof::dim;
ADDHCli::ADDHCli() : m_cmd("ADDH/Command") {}
bool ADDHCli::cmdClear()
{
return sendSimpleCommand("clear");
}
bool ADDHCli::cmdReset()
{
return sendSimpleCommand("reset");
......
......@@ -47,7 +47,6 @@ public:
ADDHCli();
bool cmdClear();
bool cmdReset();
bool cmdWrite(int32_t runNumber,
int32_t timingEvent,
......
......@@ -46,32 +46,6 @@ using namespace ntof::dim;
typedef std::vector<std::string> VArgs;
int clearCmd(const std::string &name, VArgs &vargs)
{
po::options_description desc("Clear Options");
// clang-format off
desc.add_options()
("help", "produce this help message");
// clang-format on
po::variables_map vm;
po::store(po::command_line_parser(vargs).options(desc).run(), vm);
if (vm.count("help"))
{
std::cout << "Usage: " << name << " clear \n\n" << desc << std::endl;
po::notify(vm);
return 0;
}
po::notify(vm);
ADDHCli cli;
if (!cli.cmdReset())
ADDH_THROW("Failed to clear", 0);
std::cout << "Addh clear executed" << std::endl;
return 0;
}
int resetCmd(const std::string &name, VArgs &vargs)
{
po::options_description desc("Reset Options");
......@@ -193,8 +167,7 @@ int main(int argc, char **argv)
"force the misc configuration file")(
"command", po::value(&command),
"Command to execute:\n"
" clear: clear warnings\n"
" reset: clear warnings and errors\n"
" reset: reset addh clients\n"
" listen: listen for events\n"
)
("verbose", "Turn on maximum verbosity");
......@@ -256,16 +229,14 @@ int main(int argc, char **argv)
l->configure(conf);
}
if (command == "clear")
return clearCmd(argv[0], unparsed);
else if (command == "reset")
if (command == "reset")
return resetCmd(argv[0], unparsed);
else if (command == "listen")
return listen(argv[0], unparsed);
}
std::cout << "Usage:\n"
<< argv[0] << " [clear|reset|listen...] <opts>\n\n"
<< argv[0] << " [reset|listen...] <opts>\n\n"
<< desc << std::endl;
return 0;
}
......
......@@ -48,6 +48,7 @@ class TestADDHWriter : public CppUnit::TestFixture
protected:
CPPUNIT_TEST_SUITE(TestADDHWriter);
CPPUNIT_TEST(startup);
CPPUNIT_TEST(resetCmd);
CPPUNIT_TEST_SUITE_END();
std::unique_ptr<DimTestHelper> m_dim;
......@@ -82,11 +83,8 @@ public:
destination == valueNode.attribute("destination").as_string(""));
}
void startup()
void simple(ADDHWriter &addhWriter)
{
// Initialize ADDHWriter
ADDHWriter addhWriter;
addhWriter.initServices();
const std::shared_ptr<ADDH> &addh = addhWriter.getAddh();
ADDHCli cli;
......@@ -113,6 +111,7 @@ public:
EQ(size_t(0), extraClients.size());
size_t numOfClients = clients.size();
EQ(false, numOfClients == 0);
// Check that all clients are in warning
EQ(numOfClients, cli.getStateClient()->getActiveWarnings().size());
......@@ -187,13 +186,55 @@ public:
pugi::xml_document docExtraFile;
docExtraFile.load_file("/tmp/ntof_extra.xml");
checkExtraXmlDoc(docExtraFile, "EXTRA/Service_I", "ExtraService_I");
}
void startup()
{
// Initialize ADDHWriter
ADDHWriter addhWriter;
addhWriter.initServices();
simple(addhWriter);
}
void resetCmd()
{
// Initialize ADDHWriter
ADDHWriter addhWriter;
addhWriter.initServices();
simple(addhWriter);
ADDHCli cli;
cli.listen();
SignalWaiter stateWaiter;
stateWaiter.listen(cli.addhStateSignal);
SignalWaiter extraWaiter;
extraWaiter.listen(cli.extraSignal);
std::shared_ptr<ADDH> addh(addhWriter.getAddh());
const ClientsMap clients = addh->getClients();
const ClientsMap clientsExtra = addh->getExtraClients();
size_t numOfClients = clients.size() + clientsExtra.size();
// Release addh shared ptr now
addh.reset();
EQ(true, numOfClients > 0);
addhWriter.setWarning(1000, "Fake warning");
// Check that warnings are clients + 1 (fake)
EQ(true, stateWaiter.wait([&cli, &numOfClients]() {
return cli.getStateClient()->getActiveWarnings().size() ==
(numOfClients + 1);
}));
// Clear all the warnings
cli.cmdReset();
// Check that there are no warnings anymore
EQ(true, stateWaiter.wait([&cli]() {
return cli.getStateClient()->getActiveWarnings().size() == 0;
// Check that warnings are back after reset (with no fake one)
EQ(true, stateWaiter.wait([&cli, &numOfClients]() {
return cli.getStateClient()->getActiveWarnings().size() ==
numOfClients;
}));
}
};
......
Supports Markdown
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