Skip to content

Commit

Permalink
Minor cleanup and small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantaraya36 committed Dec 21, 2020
1 parent eb9a77d commit 3ec521c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 31 deletions.
34 changes: 17 additions & 17 deletions include/tinc/ComputationChain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,13 @@ class ComputationChain : public Processor {
* This function will block if computation is currently executing and will
* return after computation is done.
*/
std::map<std::string, bool> getResults() {
std::unique_lock<std::mutex> lk2(mChainLock);
return mResults;
}
std::map<std::string, bool> getResults();

ComputationChain &operator<<(Processor &processor) {
addProcessor(processor);
return *this;
}
ComputationChain &operator<<(Processor &processor);

template <class ParameterType>
ComputationChain &
registerParameter(al::ParameterWrapper<ParameterType> &param) {
mParameters.push_back(&param);
configuration[param.getName()] = param.get();
param.registerChangeCallback([&](ParameterType value) {
configuration[param.getName()] = value;
process();
});
return *this;
}
registerParameter(al::ParameterWrapper<ParameterType> &param);

template <class ParameterType>
ComputationChain &operator<<(al::ParameterWrapper<ParameterType> &newParam) {
Expand All @@ -99,6 +85,20 @@ class ComputationChain : public Processor {
ChainType mType;
};

// Implementation

template <class ParameterType>
ComputationChain &ComputationChain::registerParameter(
al::ParameterWrapper<ParameterType> &param) {
mParameters.push_back(&param);
configuration[param.getName()] = param.get();
param.registerChangeCallback([&](ParameterType value) {
configuration[param.getName()] = value;
process();
});
return *this;
}

} // namespace tinc

#endif // COMPUTATIONCHAIN_HPP
10 changes: 10 additions & 0 deletions src/ComputationChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ bool ComputationChain::process(bool forceRecompute) {
callDoneCallbacks(ret);
return ret;
}

std::map<std::string, bool> ComputationChain::getResults() {
std::unique_lock<std::mutex> lk2(mChainLock);
return mResults;
}

ComputationChain &tinc::ComputationChain::operator<<(Processor &processor) {
addProcessor(processor);
return *this;
}
10 changes: 6 additions & 4 deletions src/TincClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,18 @@ bool TincClient::processIncomingMessage(al::Message &message, al::Socket *src) {
}
break;
case MessageType::REGISTER:
// FIXME remove after debugging
std::cout << "client register" << std::endl;
if (verbose()) {
std::cout << "client register received" << std::endl;
}
if (!readRegisterMessage(objectType, (void *)&details, src)) {
std::cerr << __FUNCTION__ << ": Error processing Register message"
<< std::endl;
}
break;
case MessageType::CONFIGURE:
// FIXME remove after debugging
std::cout << "client configure" << std::endl;
if (verbose()) {
std::cout << "client configure received" << std::endl;
}
if (!readConfigureMessage(objectType, (void *)&details, src)) {
std::cerr << __FUNCTION__ << ": Error processing Configure message"
<< std::endl;
Expand Down
5 changes: 3 additions & 2 deletions tests/tincprotocol_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,11 @@ TEST(TincProtocol, ParameterTrigger) {
EXPECT_EQ(paramTrigger->get(), true);

// change value on the clientside
paramTrigger->set(false);
paramTrigger->set(true);
al::al_sleep(0.1); // wait for new value

EXPECT_EQ(p.get(), false);
// It makes no sense to get() values for Trigger.
// EXPECT_EQ(p.get(), false);

tclient.stop();
tserver.stop();
Expand Down
20 changes: 12 additions & 8 deletions tests/tincprotocol_remote_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,17 +413,21 @@ TEST(TincProtocol, RemoteParameterTrigger) {
EXPECT_EQ(paramTrigger->getDefault(), false);
EXPECT_EQ(paramTrigger->get(), false);

// change value on the serverside
p.trigger();
al::al_sleep(0.1); // wait for new value
bool triggeredInServer = false;
bool triggeredInClient = false;

EXPECT_EQ(paramTrigger->get(), true);
static_cast<al::Trigger *>(param)
->registerChangeCallback([&](bool val) { triggeredInServer = true; });

// change value on the clientside
paramTrigger->set(false);
al::al_sleep(0.1); // wait for new value
// change value on the client side
p.trigger();
al::al_sleep(0.2); // wait for new value
EXPECT_EQ(triggeredInServer, true);

EXPECT_EQ(p.get(), false);
p.registerChangeCallback([&](bool val) { triggeredInClient = true; });
static_cast<al::Trigger *>(param)->trigger();
al::al_sleep(0.2); // wait for new value
EXPECT_EQ(triggeredInClient, true);

tclient.stop();
tserver.stop();
Expand Down

0 comments on commit 3ec521c

Please sign in to comment.