DDS plugin: Automatically set session and device id if not provided

Resolves #187
This commit is contained in:
Dennis Klein
2019-07-28 19:20:11 +02:00
committed by Dennis Klein
parent 07fe02a0a0
commit 1bb77bf47b
6 changed files with 42 additions and 30 deletions

View File

@@ -55,18 +55,18 @@ DDS::DDS(const string& name,
{
try {
TakeDeviceControl();
fControllerThread = thread(&DDS::HandleControl, this);
fHeartbeatThread = thread(&DDS::HeartbeatSender, this);
} catch (PluginServices::DeviceControlError& e) {
LOG(debug) << e.what();
} catch (exception& e) {
LOG(error) << "Error in plugin initialization: " << e.what();
}
}
auto DDS::HandleControl() -> void
{
try {
fHeartbeatThread = thread(&DDS::HeartbeatSender, this);
std::string deviceId(GetProperty<std::string>("id"));
if (deviceId.empty()) {
SetProperty<std::string>("id", dds::env_prop<dds::task_path>());
}
std::string sessionId(GetProperty<std::string>("session"));
if (sessionId == "default") {
SetProperty<std::string>("session", dds::env_prop<dds::dds_session_id>());
}
auto control = GetProperty<string>("control");
bool staticMode(false);
if (control == "static") {
@@ -121,15 +121,26 @@ auto DDS::HandleControl() -> void
});
if (staticMode) {
TransitionDeviceStateTo(DeviceState::Running);
// wait until stop signal
unique_lock<mutex> lock(fStopMutex);
while (!fDeviceTerminationRequested) {
fStopCondition.wait_for(lock, chrono::seconds(1));
}
LOG(debug) << "Stopping DDS control plugin";
fControllerThread = thread(&DDS::StaticControl, this);
}
} catch (PluginServices::DeviceControlError& e) {
LOG(debug) << e.what();
} catch (exception& e) {
LOG(error) << "Error in plugin initialization: " << e.what();
}
}
auto DDS::StaticControl() -> void
{
try {
TransitionDeviceStateTo(DeviceState::Running);
// wait until stop signal
unique_lock<mutex> lock(fStopMutex);
while (!fDeviceTerminationRequested) {
fStopCondition.wait_for(lock, chrono::seconds(1));
}
LOG(debug) << "Stopping DDS plugin static controller";
} catch (DeviceErrorState&) {
ReleaseDeviceControl();
} catch (exception& e) {

View File

@@ -128,7 +128,7 @@ class DDS : public Plugin
~DDS();
private:
auto HandleControl() -> void;
auto StaticControl() -> void;
auto FillChannelContainers() -> void;
auto SubscribeForConnectingChannels() -> void;