FairMQ: Add dump-config functionality to DDS plugin

This commit is contained in:
Dennis Klein 2017-10-31 15:24:29 +01:00 committed by Mohammad Al-Turany
parent 511141c851
commit 7429f7a326
3 changed files with 20 additions and 5 deletions

View File

@ -10,6 +10,8 @@
#include <termios.h> // for the interactive mode
#include <poll.h> // for the interactive mode
#include <sstream>
#include <iostream>
using namespace std;
@ -89,7 +91,7 @@ auto DDS::HandleControl() -> void
}
// subscribe for state changes from DDS (subscriptions start firing after fService.start() is called)
SubscribeForStateChanges();
SubscribeForCustomCommands();
// start DDS service - subscriptions will only start firing after this step
fService.start();
@ -201,7 +203,7 @@ auto DDS::PublishBoundChannels() -> void
}
}
auto DDS::SubscribeForStateChanges() -> void
auto DDS::SubscribeForCustomCommands() -> void
{
string id = GetProperty<string>("id");
string pid(to_string(getpid()));
@ -230,6 +232,15 @@ auto DDS::SubscribeForStateChanges() -> void
fStopCondition.notify_one();
}
}
else if (cmd == "dump-config")
{
stringstream ss;
for (const auto pKey: GetPropertyKeys())
{
ss << id << ": " << pKey << " -> " << GetPropertyAsString(pKey) << endl;
}
fDDSCustomCmd.send(ss.str(), to_string(senderId));
}
else
{
LOG(WARN) << "Unknown command: " << cmd;

View File

@ -56,7 +56,7 @@ class DDS : public Plugin
auto FillChannelContainers() -> void;
auto SubscribeForConnectingChannels() -> void;
auto PublishBoundChannels() -> void;
auto SubscribeForStateChanges() -> void;
auto SubscribeForCustomCommands() -> void;
dds::intercom_api::CIntercomService fService;
dds::intercom_api::CCustomCmd fDDSCustomCmd;

View File

@ -23,7 +23,7 @@ using namespace dds::intercom_api;
void PrintControlsHelp()
{
cout << "Use keys to control the devices:" << endl;
cout << "[c] check states, [h] help, [p] pause, [r] run, [s] stop, [t] reset task, [d] reset device, [q] end, [j] init task, [i] init device" << endl;
cout << "[c] check states, [o] dump config, [h] help, [p] pause, [r] run, [s] stop, [t] reset task, [d] reset device, [q] end, [j] init task, [i] init device" << endl;
cout << "To quit press Ctrl+C" << endl;
}
@ -42,7 +42,7 @@ int main(int argc, char* argv[])
// subscribe to receive messages from DDS
ddsCustomCmd.subscribe([](const string& msg, const string& /*condition*/, uint64_t /*senderId*/)
{
cout << "Received: \"" << msg << "\"" << endl;
cout << "Received: " << msg << endl;
});
service.start();
@ -72,6 +72,10 @@ int main(int argc, char* argv[])
cout << " > checking state of the devices" << endl;
ddsCustomCmd.send("check-state", "");
break;
case 'o':
cout << " > dumping config of the devices" << endl;
ddsCustomCmd.send("dump-config", "");
break;
case 'i':
cout << " > init devices" << endl;
ddsCustomCmd.send("INIT DEVICE", "");