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

Changed Module::connectTo() to accept also temporary module objects, e.g. as...

Changed Module::connectTo() to accept also temporary module objects, e.g. as returned by findTag(). As a consequence, the operators [] and () of the modules had to be changed to const.
parent 6ce0d5f1
No related branches found
No related tags found
No related merge requests found
......@@ -28,13 +28,13 @@ namespace ChimeraTK {
/** To be implemented by the user: function called in a separate thread executing the main loop of the module */
virtual void mainLoop() = 0;
void run();
void run() override;
void terminate();
void terminate() override;
VariableNetworkNode operator()(const std::string& variableName);
VariableNetworkNode operator()(const std::string& variableName) const override;
Module& operator[](const std::string& moduleName);
Module& operator[](const std::string& moduleName) const override;
/** Move operation with the assignment operator */
ApplicationModule& operator=(ApplicationModule &&rhs) {
......
......@@ -28,12 +28,12 @@ namespace ChimeraTK {
/** The function call operator returns a VariableNetworkNode which can be used in the Application::initialise()
* function to connect the control system variable with another variable. */
VariableNetworkNode operator()(const std::string& variableName, const std::type_info &valueType,
size_t nElements=0);
VariableNetworkNode operator()(const std::string& variableName) {
size_t nElements=0) const;
VariableNetworkNode operator()(const std::string& variableName) const override {
return operator()(variableName, typeid(AnyType));
}
Module& operator[](const std::string& moduleName) {
Module& operator[](const std::string& moduleName) const override {
subModules.emplace_back(variableNamePrefix/moduleName);
return subModules.back();
}
......@@ -42,9 +42,13 @@ namespace ChimeraTK {
mtca4u::RegisterPath variableNamePrefix;
std::list<ControlSystemModule> subModules;
// List of sub modules accessed through the operator[]. This is mutable since it is little more than a cache and
// thus does not change the logical state of this module
mutable std::list<ControlSystemModule> subModules;
std::map<std::string, VariableNetworkNode> variables;
// List of variables accessed through the operator(). This is mutable since it is little more than a cache and
// thus does not change the logical state of this module
mutable std::map<std::string, VariableNetworkNode> variables;
};
......
......@@ -28,29 +28,31 @@ namespace ChimeraTK {
/** The subscript operator returns a VariableNetworkNode which can be used in the Application::initialise()
* function to connect the register with another variable. */
VariableNetworkNode operator()(const std::string& registerName, UpdateMode mode,
const std::type_info &valueType=typeid(AnyType), size_t nElements=0);
const std::type_info &valueType=typeid(AnyType), size_t nElements=0) const;
VariableNetworkNode operator()(const std::string& registerName, const std::type_info &valueType,
size_t nElements=0, UpdateMode mode=UpdateMode::poll) {
size_t nElements=0, UpdateMode mode=UpdateMode::poll) const {
return operator()(registerName, mode, valueType, nElements);
}
VariableNetworkNode operator()(const std::string& variableName) {
VariableNetworkNode operator()(const std::string& variableName) const override {
return operator()(variableName, UpdateMode::poll);
}
Module& operator[](const std::string& moduleName) {
Module& operator[](const std::string& moduleName) const override {
subModules.emplace_back(deviceAliasOrURI, registerNamePrefix/moduleName);
return subModules.back();
}
/** Prepare the device for usage (i.e. open it) */
void prepare();
void prepare() override;
protected:
std::string deviceAliasOrURI;
mtca4u::RegisterPath registerNamePrefix;
std::list<DeviceModule> subModules;
// List of sub modules accessed through the operator[]. This is mutable since it is little more than a cache and
// thus does not change the logical state of this module
mutable std::list<DeviceModule> subModules;
};
......
......@@ -43,10 +43,10 @@ namespace ChimeraTK {
virtual void terminate() {};
/** Function call operator: Return VariableNetworkNode of the given variable name */
virtual VariableNetworkNode operator()(const std::string& variableName) = 0;
virtual VariableNetworkNode operator()(const std::string& variableName) const = 0;
/** Subscript operator: Return sub-module of the given name */
virtual Module& operator[](const std::string& moduleName) = 0;
virtual Module& operator[](const std::string& moduleName) const = 0;
/** 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
......@@ -57,7 +57,7 @@ namespace ChimeraTK {
* If an optional trigger node is specified, this trigger node is applied to all poll-type output variables
* of the target module, which are being connected during this operation, if the corresponding variable
* in this module is push-type. */
void connectTo(Module &target, VariableNetworkNode trigger={});
void connectTo(const Module &target, VariableNetworkNode trigger={}) const;
};
......
......@@ -37,9 +37,9 @@ namespace ChimeraTK {
/** Just call write() on all variables in the group. */
void writeAll();
VariableNetworkNode operator()(const std::string& variableName);
VariableNetworkNode operator()(const std::string& variableName) const override;
Module& operator[](const std::string& moduleName);
Module& operator[](const std::string& moduleName) const override;
/** Move operation with the assignment operator
@todo should be in the base class!? */
......
......@@ -30,9 +30,9 @@ namespace ChimeraTK {
/** Destructor */
virtual ~VirtualModule();
VariableNetworkNode operator()(const std::string& variableName);
VariableNetworkNode operator()(const std::string& variableName) const override;
Module& operator[](const std::string& moduleName);
Module& operator[](const std::string& moduleName) const override;
/** Add a virtual sub-module. The module instance will be added to an internal list. */
void addSubModule(VirtualModule module);
......
......@@ -41,7 +41,7 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
VariableNetworkNode ApplicationModule::operator()(const std::string& variableName) {
VariableNetworkNode ApplicationModule::operator()(const std::string& variableName) const {
for(auto variable : getAccessorList()) {
if(variable.getName() == variableName) return VariableNetworkNode(variable);
}
......@@ -50,7 +50,7 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
Module& ApplicationModule::operator[](const std::string& moduleName) {
Module& ApplicationModule::operator[](const std::string& moduleName) const {
for(auto submodule : getSubmoduleList()) {
if(submodule->getName() == moduleName) return *submodule;
}
......
......@@ -18,7 +18,7 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
VariableNetworkNode ControlSystemModule::operator()(const std::string& variableName, const std::type_info &valueType,
size_t nElements) {
size_t nElements) const {
if(variables.count(variableName) == 0) {
variables[variableName] = {variableNamePrefix/variableName, VariableDirection::invalid, valueType, nElements};
}
......
......@@ -21,7 +21,7 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
VariableNetworkNode DeviceModule::operator()(const std::string& registerName, UpdateMode mode,
const std::type_info &valueType, size_t nElements) {
const std::type_info &valueType, size_t nElements) const {
return{deviceAliasOrURI, registerNamePrefix/registerName, mode, VariableDirection::invalid, valueType, nElements};
}
......
......@@ -22,7 +22,7 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
void Module::connectTo(Module &target, VariableNetworkNode trigger) {
void Module::connectTo(const Module &target, VariableNetworkNode trigger) const {
// connect all direct variables of this module to their counter-parts in the right-hand-side module
for(auto variable : getAccessorList()) {
......
......@@ -60,7 +60,7 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
VariableNetworkNode VariableGroup::operator()(const std::string& variableName) {
VariableNetworkNode VariableGroup::operator()(const std::string& variableName) const {
for(auto variable : getAccessorList()) {
if(variable.getName() == variableName) return VariableNetworkNode(variable);
}
......@@ -69,7 +69,7 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
Module& VariableGroup::operator[](const std::string& moduleName) {
Module& VariableGroup::operator[](const std::string& moduleName) const {
for(auto submodule : getSubmoduleList()) {
if(submodule->getName() == moduleName) return *submodule;
}
......
......@@ -28,7 +28,7 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
VariableNetworkNode VirtualModule::operator()(const std::string& variableName) {
VariableNetworkNode VirtualModule::operator()(const std::string& variableName) const {
for(auto variable : getAccessorList()) {
if(variable.getName() == variableName) return VariableNetworkNode(variable);
}
......@@ -37,7 +37,7 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
Module& VirtualModule::operator[](const std::string& moduleName) {
Module& VirtualModule::operator[](const std::string& moduleName) const {
for(auto submodule : getSubmoduleList()) {
if(submodule->getName() == moduleName) return *submodule;
}
......
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