Skip to content
Snippets Groups Projects
Commit ecffe22e authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

fix: setAndWrite() used wrong VersionNumber

parent 118a6b72
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ namespace ChimeraTK {
bool writeDestructively(ChimeraTK::VersionNumber versionNumber) = delete;
void writeIfDifferent(
const std::vector<UserType>& newValue, VersionNumber versionNumber, DataValidity validity) = delete;
void setAndWrite(const std::vector<UserType>& newValue, VersionNumber versionNumber) = delete;
bool write();
......@@ -46,6 +47,8 @@ namespace ChimeraTK {
void writeIfDifferent(const std::vector<UserType>& newValue);
void setAndWrite(const std::vector<UserType>& newValue);
protected:
friend class InversionOfControlAccessor<ArrayAccessor<UserType>>;
......@@ -175,13 +178,20 @@ namespace ChimeraTK {
if(!std::equal(newValue.begin(), newValue.end(), this->get()->accessChannel(0).begin()) ||
this->getVersionNumber() == VersionNumber(nullptr) ||
targetMetaDataPropagatingDecorator->getTargetValidity() != this->getOwner()->getDataValidity()) {
operator=(newValue);
this->write();
setAndWrite(newValue);
}
}
/********************************************************************************************************************/
template<typename UserType>
void ArrayAccessor<UserType>::setAndWrite(const std::vector<UserType>& newValue) {
operator=(newValue);
this->write();
}
/********************************************************************************************************************/
template<typename UserType>
ArrayAccessor<UserType>::ArrayAccessor(Module* owner, const std::string& name, VariableDirection direction,
std::string unit, size_t nElements, UpdateMode mode, const std::string& description,
......
......@@ -39,6 +39,7 @@ namespace ChimeraTK {
bool write(ChimeraTK::VersionNumber versionNumber) = delete;
bool writeDestructively(ChimeraTK::VersionNumber versionNumber) = delete;
void writeIfDifferent(UserType newValue, VersionNumber versionNumber, DataValidity validity) = delete;
void setAndWrite(UserType newValue, VersionNumber versionNumber) = delete;
bool write();
......@@ -46,6 +47,8 @@ namespace ChimeraTK {
void writeIfDifferent(UserType newValue);
void setAndWrite(UserType newValue);
protected:
friend class InversionOfControlAccessor<ScalarAccessor<UserType>>;
......@@ -172,13 +175,20 @@ namespace ChimeraTK {
// corresponds to the last written data validity for this PV.
if(this->get()->accessData(0, 0) != newValue || this->getVersionNumber() == VersionNumber(nullptr) ||
targetMetaDataPropagatingDecorator->getTargetValidity() != this->getOwner()->getDataValidity()) {
operator=(newValue);
this->write();
setAndWrite(newValue);
}
}
/********************************************************************************************************************/
template<typename UserType>
void ScalarAccessor<UserType>::setAndWrite(UserType newValue) {
operator=(newValue);
this->write();
}
/********************************************************************************************************************/
template<typename UserType>
ScalarAccessor<UserType>::ScalarAccessor(Module* owner, const std::string& name, VariableDirection direction,
std::string unit, UpdateMode mode, const std::string& description, const std::unordered_set<std::string>& tags)
......
......@@ -125,6 +125,79 @@ BOOST_AUTO_TEST_CASE(versionPropagation_testPushTypeReadLatest) {
BOOST_CHECK(application.group1.pushModule.getCurrentVersionNumber() == moduleVersion);
}
BOOST_AUTO_TEST_SUITE_END()
/*********************************************************************************************************************/
/*********************************************************************************************************************/
BOOST_AUTO_TEST_SUITE()
struct ThePushModule : ChimeraTK::ApplicationModule {
using ChimeraTK::ApplicationModule::ApplicationModule;
ChimeraTK::ScalarPushInput<int> pushInput{this, "/theVariable", "", ""};
std::promise<void> p;
void mainLoop() override { p.set_value(); }
};
struct TheOutputModule : ChimeraTK::ApplicationModule {
using ChimeraTK::ApplicationModule::ApplicationModule;
ChimeraTK::ScalarOutput<int> output{this, "/theVariable", "", ""};
void prepare() { output.write(); }
std::promise<void> p;
void mainLoop() override { p.set_value(); }
};
struct TheTestApplication : ChimeraTK::Application {
using ChimeraTK::Application::Application;
~TheTestApplication() override { shutdown(); }
ThePushModule pm{this, "pm", ""};
TheOutputModule om{this, "om", ""};
};
/*********************************************************************************************************************/
BOOST_AUTO_TEST_CASE(versionPropagation_testSetAndWrite) {
std::cout << "versionPropagation_testSetAndWrite" << std::endl;
TheTestApplication app("app");
ChimeraTK::TestFacility test(app, false);
test.runApplication();
app.pm.p.get_future().wait();
app.om.p.get_future().wait();
ChimeraTK::VersionNumber theVersion;
app.om.setCurrentVersionNumber(theVersion);
app.om.output.setAndWrite(42);
app.pm.pushInput.read();
BOOST_CHECK(app.pm.getCurrentVersionNumber() == theVersion);
}
/*********************************************************************************************************************/
BOOST_AUTO_TEST_CASE(versionPropagation_testWriteIfDifferent) {
std::cout << "versionPropagation_testWriteIfDifferent" << std::endl;
TheTestApplication app("app");
ChimeraTK::TestFacility test(app, false);
test.runApplication();
app.pm.p.get_future().wait();
app.om.p.get_future().wait();
ChimeraTK::VersionNumber theVersion;
app.om.setCurrentVersionNumber(theVersion);
app.om.output.writeIfDifferent(42);
app.pm.pushInput.read();
BOOST_CHECK(app.pm.getCurrentVersionNumber() == theVersion);
}
/*********************************************************************************************************************/
BOOST_AUTO_TEST_SUITE_END()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment