Skip to content

Commit 57d33a5

Browse files
author
hpcdgrie
committed
Only master knows about devices, so only call addDevice callback on master
1 parent c794128 commit 57d33a5

2 files changed

Lines changed: 32 additions & 30 deletions

File tree

src/OpenCOVER/cover/input/deviceDiscovery.cpp

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,37 +79,38 @@ namespace opencover
7979
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex);
8080
int numToAdd = toAdd.size();
8181
coVRMSController::instance()->syncData(&numToAdd, sizeof(numToAdd));
82-
if (coVRMSController::instance()->isMaster())
83-
{
84-
for(const auto &i:toAdd)
85-
{
86-
devices.push_back(i);
87-
int len = i->pluginName.length();
88-
coVRMSController::instance()->sendSlaves(&len, sizeof(len));
89-
coVRMSController::instance()->sendSlaves(i->pluginName.c_str(), len + 1);
90-
cover->addPlugin(i->pluginName.c_str());
91-
}
92-
}
93-
else
94-
{
95-
for(int i=0;i<numToAdd;i++)
96-
{
97-
std::string pluginName;
98-
int len = 0;
99-
char buf[1000];
100-
coVRMSController::instance()->readMaster(&len, sizeof(len));
101-
coVRMSController::instance()->readMaster(buf, len+1);
102-
cover->addPlugin(buf);
103-
}
104-
}
105-
toAdd.clear();
106-
auto firstNew = devices.end() - numToAdd;
107-
for (int i = 0; i < numToAdd; i++)
108-
{
109-
deviceAdded(*firstNew);
110-
++firstNew;
111-
}
82+
if (coVRMSController::instance()->isMaster())
83+
{
84+
for(const auto &i:toAdd)
85+
{
86+
devices.push_back(i);
87+
int len = i->pluginName.length();
88+
coVRMSController::instance()->sendSlaves(&len, sizeof(len));
89+
coVRMSController::instance()->sendSlaves(i->pluginName.c_str(), len + 1);
90+
cover->addPlugin(i->pluginName.c_str());
91+
}
92+
auto firstNew = devices.end() - numToAdd;
93+
for (int i = 0; i < numToAdd; i++)
94+
{
95+
deviceAdded(*firstNew);
96+
++firstNew;
97+
}
98+
}
99+
else
100+
{
101+
for(int i=0;i<numToAdd;i++)
102+
{
103+
std::string pluginName;
104+
int len = 0;
105+
char buf[1000];
106+
coVRMSController::instance()->readMaster(&len, sizeof(len));
107+
coVRMSController::instance()->readMaster(buf, len+1);
108+
cover->addPlugin(buf);
109+
}
110+
}
111+
toAdd.clear();
112112
}
113+
113114
void deviceDiscovery::run()
114115
{
115116
covise::setThreadName("deviceDiscoveryThread");

src/OpenCOVER/cover/input/deviceDiscovery.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace opencover
5858

5959
// only to be used from main thread
6060
const std::vector<const deviceInfo *> &getDevices() const;
61+
// only called on master, slaves don't know about devices
6162
sigslot::signal<const deviceInfo *> deviceAdded;
6263

6364
private:

0 commit comments

Comments
 (0)