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

moved group read/write and []/() oprerators from the VariableGroup class into...

moved group read/write and []/() oprerators from the VariableGroup class into the Module class, to make the functionality also available in ApplicationModules
parent 9bd4c963
No related branches found
No related tags found
No related merge requests found
...@@ -41,12 +41,30 @@ namespace ChimeraTK { ...@@ -41,12 +41,30 @@ namespace ChimeraTK {
/** Terminate the module. Must be called before destruction, if run() was called previously. */ /** Terminate the module. Must be called before destruction, if run() was called previously. */
virtual void terminate() {}; virtual void terminate() {};
/** Wait for receiving an update for any of the push-type variables in the group. Any poll-type variables are
* read after receiving the update. If no push-type variables are in the group, this function will just read
* all variables. The returned TransferElement will be the push-type variable which has been updated. */
boost::shared_ptr<mtca4u::TransferElement> readAny();
/** Just call read() on all variables in the group. If there are push-type variables in the group, this call
* will block until all of the variables have received an update. */
void readAll();
/** Just call readNonBlocking() on all variables in the group. */
void readAllNonBlocking();
/** Just call readLatest() on all variables in the group. */
void readAllLatest();
/** Just call write() on all variables in the group. */
void writeAll();
/** Function call operator: Return VariableNetworkNode of the given variable name */ /** Function call operator: Return VariableNetworkNode of the given variable name */
virtual VariableNetworkNode operator()(const std::string& variableName) const = 0; virtual VariableNetworkNode operator()(const std::string& variableName) const;
/** Subscript operator: Return sub-module of the given name */ /** Subscript operator: Return sub-module of the given name */
virtual Module& operator[](const std::string& moduleName) const = 0; virtual Module& operator[](const std::string& moduleName) const;
/** Connect the entire module into another module. All variables inside this module and all /** Connect the entire module into another module. All variables inside this module and all
* submodules are connected to the target module. All variables and submodules must have an equally * submodules are connected to the target module. All variables and submodules must have an equally
......
...@@ -23,29 +23,7 @@ namespace ChimeraTK { ...@@ -23,29 +23,7 @@ namespace ChimeraTK {
using Module::Module; using Module::Module;
/** Destructor */ /** Destructor */
virtual ~VariableGroup(); virtual ~VariableGroup() {};
/** Wait for receiving an update for any of the push-type variables in the group. Any poll-type variables are
* read after receiving the update. If no push-type variables are in the group, this function will just read
* all variables. The returned TransferElement will be the push-type variable which has been updated. */
boost::shared_ptr<mtca4u::TransferElement> readAny();
/** Just call read() on all variables in the group. If there are push-type variables in the group, this call
* will block until all of the variables have received an update. */
void readAll();
/** Just call readNonBlocking() on all variables in the group. */
void readAllNonBlocking();
/** Just call readLatest() on all variables in the group. */
void readAllLatest();
/** Just call write() on all variables in the group. */
void writeAll();
VariableNetworkNode operator()(const std::string& variableName) const override;
Module& operator[](const std::string& moduleName) const override;
/** Move operation with the assignment operator /** Move operation with the assignment operator
@todo should be in the base class!? */ @todo should be in the base class!? */
......
...@@ -48,4 +48,83 @@ namespace ChimeraTK { ...@@ -48,4 +48,83 @@ namespace ChimeraTK {
} }
/*********************************************************************************************************************/
boost::shared_ptr<mtca4u::TransferElement> Module::readAny() {
auto accessorList = getAccessorListRecursive();
// put push-type transfer elements into a list suitable for TransferElement::readAny()
std::list<std::reference_wrapper<mtca4u::TransferElement>> transferElementList;
for(auto &accessor : accessorList) {
if(accessor.getMode() == UpdateMode::push) {
transferElementList.emplace_back(accessor.getAppAccessorNoType());
}
}
// wait until one of the push-type accessors receives an update
auto ret = Application::getInstance().readAny(transferElementList);
// trigger read on the poll-type accessors
for(auto accessor : accessorList) {
if(accessor.getMode() == UpdateMode::poll) {
accessor.getAppAccessorNoType().readNonBlocking();
}
}
return ret;
}
/*********************************************************************************************************************/
void Module::readAll() {
auto accessorList = getAccessorListRecursive();
for(auto accessor : accessorList) {
accessor.getAppAccessorNoType().read();
}
}
/*********************************************************************************************************************/
void Module::readAllNonBlocking() {
auto accessorList = getAccessorListRecursive();
for(auto accessor : accessorList) {
accessor.getAppAccessorNoType().readNonBlocking();
}
}
/*********************************************************************************************************************/
void Module::readAllLatest() {
auto accessorList = getAccessorListRecursive();
for(auto accessor : accessorList) {
accessor.getAppAccessorNoType().readLatest();
}
}
/*********************************************************************************************************************/
void Module::writeAll() {
auto accessorList = getAccessorListRecursive();
for(auto accessor : accessorList) {
accessor.getAppAccessorNoType().write();
}
}
/*********************************************************************************************************************/
VariableNetworkNode Module::operator()(const std::string& variableName) const {
for(auto variable : getAccessorList()) {
if(variable.getName() == variableName) return VariableNetworkNode(variable);
}
throw std::logic_error("Variable '"+variableName+"' is not part of the variable group '"+_name+"'.");
}
/*********************************************************************************************************************/
Module& Module::operator[](const std::string& moduleName) const {
for(auto submodule : getSubmoduleList()) {
if(submodule->getName() == moduleName) return *submodule;
}
throw std::logic_error("Sub-module '"+moduleName+"' is not part of the variable group '"+_name+"'.");
}
} /* namespace ChimeraTK */ } /* namespace ChimeraTK */
...@@ -12,87 +12,5 @@ ...@@ -12,87 +12,5 @@
namespace ChimeraTK { namespace ChimeraTK {
VariableGroup::~VariableGroup() {
}
/*********************************************************************************************************************/
boost::shared_ptr<mtca4u::TransferElement> VariableGroup::readAny() {
auto accessorList = getAccessorListRecursive();
// put push-type transfer elements into a list suitable for TransferElement::readAny()
std::list<std::reference_wrapper<mtca4u::TransferElement>> transferElementList;
for(auto &accessor : accessorList) {
if(accessor.getMode() == UpdateMode::push) {
transferElementList.emplace_back(accessor.getAppAccessorNoType());
}
}
// wait until one of the push-type accessors receives an update
auto ret = Application::getInstance().readAny(transferElementList);
// trigger read on the poll-type accessors
for(auto accessor : accessorList) {
if(accessor.getMode() == UpdateMode::poll) {
accessor.getAppAccessorNoType().readNonBlocking();
}
}
return ret;
}
/*********************************************************************************************************************/
void VariableGroup::readAll() {
auto accessorList = getAccessorListRecursive();
for(auto accessor : accessorList) {
accessor.getAppAccessorNoType().read();
}
}
/*********************************************************************************************************************/
void VariableGroup::readAllNonBlocking() {
auto accessorList = getAccessorListRecursive();
for(auto accessor : accessorList) {
accessor.getAppAccessorNoType().readNonBlocking();
}
}
/*********************************************************************************************************************/
void VariableGroup::readAllLatest() {
auto accessorList = getAccessorListRecursive();
for(auto accessor : accessorList) {
accessor.getAppAccessorNoType().readLatest();
}
}
/*********************************************************************************************************************/
void VariableGroup::writeAll() {
auto accessorList = getAccessorListRecursive();
for(auto accessor : accessorList) {
accessor.getAppAccessorNoType().write();
}
}
/*********************************************************************************************************************/
VariableNetworkNode VariableGroup::operator()(const std::string& variableName) const {
for(auto variable : getAccessorList()) {
if(variable.getName() == variableName) return VariableNetworkNode(variable);
}
throw std::logic_error("Variable '"+variableName+"' is not part of the variable group '"+_name+"'.");
}
/*********************************************************************************************************************/
Module& VariableGroup::operator[](const std::string& moduleName) const {
for(auto submodule : getSubmoduleList()) {
if(submodule->getName() == moduleName) return *submodule;
}
throw std::logic_error("Sub-module '"+moduleName+"' is not part of the variable group '"+_name+"'.");
}
} /* namespace ChimeraTK */ } /* namespace ChimeraTK */
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