Newer
Older
Martin Christoph Hierholzer
committed
/*
* DeviceModule.h
*
* Created on: Jun 27, 2016
* Author: Martin Hierholzer
*/
#ifndef CHIMERATK_DEVICE_MODULE_H
#define CHIMERATK_DEVICE_MODULE_H
Martin Christoph Hierholzer
committed
#include <mtca4u/ForwardDeclarations.h>
#include <mtca4u/RegisterPath.h>
Martin Christoph Hierholzer
committed
#include "VariableNetworkNode.h"
#include "Module.h"
namespace ChimeraTK {
class DeviceModule : public Module {
public:
/** Constructor: The device represented by this DeviceModule is identified by either the device alias found
Martin Christoph Hierholzer
committed
* in the DMAP file or directly an URI. The given optional prefix will be prepended to all register names
* (separated by a slash). */
Martin Christoph Hierholzer
committed
DeviceModule(const std::string& deviceAliasOrURI, const std::string& registerNamePrefix="");
/** The subscript operator returns a VariableNetworkNode which can be used in the Application::initialise()
* function to connect the register with another variable. */
Martin Christoph Hierholzer
committed
VariableNetworkNode operator()(const std::string& registerName, UpdateMode mode,
Martin Christoph Hierholzer
committed
const std::type_info &valueType=typeid(AnyType), size_t nElements=0) const;
Martin Christoph Hierholzer
committed
VariableNetworkNode operator()(const std::string& registerName, const std::type_info &valueType,
Martin Christoph Hierholzer
committed
size_t nElements=0, UpdateMode mode=UpdateMode::poll) const {
Martin Christoph Hierholzer
committed
return operator()(registerName, mode, valueType, nElements);
Martin Christoph Hierholzer
committed
}
Martin Christoph Hierholzer
committed
VariableNetworkNode operator()(const std::string& variableName) const override {
Martin Christoph Hierholzer
committed
return operator()(variableName, UpdateMode::poll);
}
Martin Christoph Hierholzer
committed
Module& operator[](const std::string& moduleName) const override {
Martin Christoph Hierholzer
committed
subModules.emplace_back(deviceAliasOrURI, registerNamePrefix/moduleName);
return subModules.back();
}
Martin Christoph Hierholzer
committed
/** Prepare the device for usage (i.e. open it) */
Martin Christoph Hierholzer
committed
void prepare() override;
Martin Christoph Hierholzer
committed
protected:
std::string deviceAliasOrURI;
mtca4u::RegisterPath registerNamePrefix;
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
// 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;
Martin Christoph Hierholzer
committed
};
} /* namespace ChimeraTK */
#endif /* CHIMERATK_DEVICE_MODULE_H */