DDS Plugin: reset channel containers before filling

This commit is contained in:
Alexey Rybalchenko 2019-09-16 14:57:56 +02:00 committed by Dennis Klein
parent 44bfbe02ed
commit dc72262af1
2 changed files with 27 additions and 9 deletions

View File

@ -100,8 +100,12 @@ DDS::DDS(const string& name,
PublishBoundChannels(); PublishBoundChannels();
break; break;
case DeviceState::ResettingDevice: { case DeviceState::ResettingDevice: {
{
std::lock_guard<std::mutex> lk(fUpdateMutex); std::lock_guard<std::mutex> lk(fUpdateMutex);
fUpdatesAllowed = false; fUpdatesAllowed = false;
}
EmptyChannelContainers();
break; break;
} }
case DeviceState::Exiting: case DeviceState::Exiting:
@ -127,13 +131,7 @@ DDS::DDS(const string& name,
if (staticMode) { if (staticMode) {
fControllerThread = thread(&DDS::StaticControl, this); fControllerThread = thread(&DDS::StaticControl, this);
} else { } else {
fWorkerThread = thread([this]() { StartWorkerThread();
{
std::unique_lock<std::mutex> lk(fUpdateMutex);
fUpdateCondition.wait(lk, [&]{ return fUpdatesAllowed; });
}
fWorkerQueue.run();
});
} }
fDDS.Start(); fDDS.Start();
@ -144,6 +142,19 @@ DDS::DDS(const string& name,
} }
} }
void DDS::EmptyChannelContainers()
{
fBindingChans.clear();
fConnectingChans.clear();
}
auto DDS::StartWorkerThread() -> void
{
fWorkerThread = thread([this]() {
fWorkerQueue.run();
});
}
auto DDS::WaitForExitingAck() -> void auto DDS::WaitForExitingAck() -> void
{ {
unique_lock<mutex> lock(fStateChangeSubscriberMutex); unique_lock<mutex> lock(fStateChangeSubscriberMutex);
@ -257,6 +268,10 @@ auto DDS::SubscribeForConnectingChannels() -> void
boost::asio::post(fWorkerQueue, [=]() { boost::asio::post(fWorkerQueue, [=]() {
try { try {
{
std::unique_lock<std::mutex> lk(fUpdateMutex);
fUpdateCondition.wait(lk, [&]{ return fUpdatesAllowed; });
}
string val = value; string val = value;
// check if it is to handle as one out of multiple values // check if it is to handle as one out of multiple values
auto it = fIofN.find(propertyId); auto it = fIofN.find(propertyId);

View File

@ -133,8 +133,11 @@ class DDS : public Plugin
private: private:
auto StaticControl() -> void; auto StaticControl() -> void;
auto WaitForExitingAck() -> void; auto WaitForExitingAck() -> void;
auto StartWorkerThread() -> void;
auto FillChannelContainers() -> void; auto FillChannelContainers() -> void;
auto EmptyChannelContainers() -> void;
auto SubscribeForConnectingChannels() -> void; auto SubscribeForConnectingChannels() -> void;
auto PublishBoundChannels() -> void; auto PublishBoundChannels() -> void;
auto SubscribeForCustomCommands() -> void; auto SubscribeForCustomCommands() -> void;