mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 00:31:14 +00:00
feat: Add interactive controller button to print connected peers
This commit is contained in:
parent
fda8126a43
commit
ebcbe2dde6
|
@ -327,6 +327,14 @@ class Device
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Get numbers of connected peers for the given channel
|
||||||
|
/// @param name channel name
|
||||||
|
/// @param index sub-channel
|
||||||
|
unsigned long GetNumberOfConnectedPeers(const std::string& channelName, int index = 0)
|
||||||
|
{
|
||||||
|
return fChannels.at(channelName).at(index).GetNumberOfConnectedPeers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void RegisterChannelEndpoints() {}
|
virtual void RegisterChannelEndpoints() {}
|
||||||
|
|
||||||
bool RegisterChannelEndpoint(const std::string& channelName,
|
bool RegisterChannelEndpoint(const std::string& channelName,
|
||||||
|
|
|
@ -91,6 +91,8 @@ class Plugin
|
||||||
auto SubscribeToDeviceStateChange(std::function<void(DeviceState)> callback) -> void { fPluginServices->SubscribeToDeviceStateChange(fkName, callback); }
|
auto SubscribeToDeviceStateChange(std::function<void(DeviceState)> callback) -> void { fPluginServices->SubscribeToDeviceStateChange(fkName, callback); }
|
||||||
auto UnsubscribeFromDeviceStateChange() -> void { fPluginServices->UnsubscribeFromDeviceStateChange(fkName); }
|
auto UnsubscribeFromDeviceStateChange() -> void { fPluginServices->UnsubscribeFromDeviceStateChange(fkName); }
|
||||||
|
|
||||||
|
auto GetNumberOfConnectedPeers(const std::string& channelName, int index = 0) -> unsigned long { return fPluginServices->GetNumberOfConnectedPeers(channelName, index); }
|
||||||
|
|
||||||
// device config API
|
// device config API
|
||||||
// see <fairmq/PluginServices.h> for docs
|
// see <fairmq/PluginServices.h> for docs
|
||||||
auto PropertyExists(const std::string& key) -> int { return fPluginServices->PropertyExists(key); }
|
auto PropertyExists(const std::string& key) -> int { return fPluginServices->PropertyExists(key); }
|
||||||
|
|
|
@ -138,6 +138,9 @@ class PluginServices
|
||||||
/// @param subscriber id
|
/// @param subscriber id
|
||||||
auto UnsubscribeFromDeviceStateChange(const std::string& subscriber) -> void { fDevice.UnsubscribeFromStateChange(subscriber); }
|
auto UnsubscribeFromDeviceStateChange(const std::string& subscriber) -> void { fDevice.UnsubscribeFromStateChange(subscriber); }
|
||||||
|
|
||||||
|
/// DO NOT USE, ONLY FOR TESTING, WILL BE REMOVED (and info made available via property api)
|
||||||
|
auto GetNumberOfConnectedPeers(const std::string& channelName, int index = 0) -> unsigned long { return fDevice.GetNumberOfConnectedPeers(channelName, index); }
|
||||||
|
|
||||||
// Config API
|
// Config API
|
||||||
|
|
||||||
/// @brief Checks a property with the given key exist in the configuration
|
/// @brief Checks a property with the given key exist in the configuration
|
||||||
|
|
|
@ -206,6 +206,10 @@ try {
|
||||||
cout << "\n --> [m] decrease log verbosity\n\n" << flush;
|
cout << "\n --> [m] decrease log verbosity\n\n" << flush;
|
||||||
CycleLogVerbosityDown();
|
CycleLogVerbosityDown();
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
cout << "\n --> [p] print number of connected peers for all channels\n\n" << flush;
|
||||||
|
PrintNumberOfConnectedPeers();
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
cout << "\n --> [h] help\n\n" << flush;
|
cout << "\n --> [h] help\n\n" << flush;
|
||||||
if (color) {
|
if (color) {
|
||||||
|
@ -248,7 +252,7 @@ auto Control::PrintInteractiveHelpColor() -> void
|
||||||
{
|
{
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss << "Following control commands are available:\n\n"
|
ss << "Following control commands are available:\n\n"
|
||||||
<< " [\033[01;32mh\033[0m] help, [\033[01;32mc\033[0m] check current device state,\n"
|
<< " [\033[01;32mh\033[0m] help, [\033[01;32mc\033[0m] check current device state, [\033[01;32mp\033[0m] print number of connected peers for channels,\n"
|
||||||
<< " [\033[01;32mi\033[0m] init device, [\033[01;32mb\033[0m] bind, [\033[01;32mx\033[0m] connect, [\033[01;32mj\033[0m] init task,"
|
<< " [\033[01;32mi\033[0m] init device, [\033[01;32mb\033[0m] bind, [\033[01;32mx\033[0m] connect, [\033[01;32mj\033[0m] init task,"
|
||||||
<< " [\033[01;32mr\033[0m] run, [\033[01;32ms\033[0m] stop,\n"
|
<< " [\033[01;32mr\033[0m] run, [\033[01;32ms\033[0m] stop,\n"
|
||||||
<< " [\033[01;32mt\033[0m] reset task, [\033[01;32md\033[0m] reset device, [\033[01;32mq\033[0m] end,\n"
|
<< " [\033[01;32mt\033[0m] reset task, [\033[01;32md\033[0m] reset device, [\033[01;32mq\033[0m] end,\n"
|
||||||
|
@ -260,7 +264,7 @@ auto Control::PrintInteractiveHelp() -> void
|
||||||
{
|
{
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss << "Following control commands are available:\n\n"
|
ss << "Following control commands are available:\n\n"
|
||||||
<< " [h] help, [c] check current device state,\n"
|
<< " [h] help, [c] check current device state, [p] print number of connected peers for channels\n"
|
||||||
<< " [i] init device, [b] bind, [x] connect, [j] init task,\n"
|
<< " [i] init device, [b] bind, [x] connect, [j] init task,\n"
|
||||||
<< " [r] run, [s] stop,\n"
|
<< " [r] run, [s] stop,\n"
|
||||||
<< " [t] reset task, [d] reset device, [q] end,\n"
|
<< " [t] reset task, [d] reset device, [q] end,\n"
|
||||||
|
@ -344,6 +348,17 @@ void Control::PrintStateMachine()
|
||||||
cout << ss.str() << flush;
|
cout << ss.str() << flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Control::PrintNumberOfConnectedPeers() -> void
|
||||||
|
{
|
||||||
|
unordered_map<string, int> channelInfo(GetChannelInfo());
|
||||||
|
|
||||||
|
for (const auto& c : channelInfo) {
|
||||||
|
for (int i = 0; i < c.second; ++i) {
|
||||||
|
LOG(info) << c.first << "[" << i << "]: " << GetNumberOfConnectedPeers(c.first, i) << " peers connected";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto Control::StaticMode() -> void
|
auto Control::StaticMode() -> void
|
||||||
try {
|
try {
|
||||||
RunStartupSequence();
|
RunStartupSequence();
|
||||||
|
|
|
@ -41,6 +41,7 @@ class Control : public Plugin
|
||||||
static auto PrintInteractiveHelp() -> void;
|
static auto PrintInteractiveHelp() -> void;
|
||||||
static auto PrintStateMachineColor() -> void;
|
static auto PrintStateMachineColor() -> void;
|
||||||
static auto PrintStateMachine() -> void;
|
static auto PrintStateMachine() -> void;
|
||||||
|
auto PrintNumberOfConnectedPeers() -> void;
|
||||||
auto StaticMode() -> void;
|
auto StaticMode() -> void;
|
||||||
auto SignalHandler() -> void;
|
auto SignalHandler() -> void;
|
||||||
auto RunShutdownSequence() -> void;
|
auto RunShutdownSequence() -> void;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user