10#include <ChimeraTK/DeviceBackend.h>
11#include <ChimeraTK/Utilities.h>
18 std::function<
void(
ChimeraTK::Device&)> initialisationHandler,
const std::string& pathInDevice)
26 if(initialisationHandler) {
31 if(!triggerPath.empty() && triggerPath[0] !=
'/') {
32 throw ChimeraTK::logic_error(
"DeviceModule triggerPath must be absolute!");
41 assert(neighbourDirectory.isValid());
44 auto nodeList = dm->getNodesList();
47 for(
auto& node : nodeList) {
49 if(!boost::starts_with(node.getRegisterName(),
_pathInDevice)) {
54 assert(boost::starts_with(node.getRegisterName(),
_pathInDevice));
55 auto cut = pathInDevice.size();
56 if(!boost::ends_with(pathInDevice,
"/")) {
59 auto relativePath = node.getRegisterName().substr(cut);
66 node.setOwningModule(
this);
77 if(other._model.isValid()) {
80 neighbourDirectory = other._model.
visit(
82 assert(neighbourDirectory.
isValid());
86 for(
const auto& reg : dm->getDevice().getRegisterCatalogue()) {
87 if(reg.getNumberOfDimensions() > 1) {
90 std::string registerName = reg.getRegisterName();
91 if(!boost::starts_with(registerName, _pathInDevice)) {
98 neighbourDirectory.
visitByPath(registerName, [&](
auto proxy) {
99 if constexpr(isVariable(proxy)) {
100 assert(proxy.isValid());
103 for(
auto& proxyNode : proxy.getNodes()) {
104 if(proxyNode->getType() ==
NodeType::Device && proxyNode->getDeviceAlias() == getDeviceAliasOrURI()) {
106 theNode = *proxyNode;
119 catch(ChimeraTK::logic_error& e) {
120 std::cerr << e.what() << std::endl;
125 _model = std::move(other._model);
127 if(_model.isValid()) {
128 _model.informMove(*
this);
155 return _dm.lock()->getDeviceAliasOrURI();
161 _dm.lock()->addInitialisationHandler(std::move(initialisationHandler));
167 _dm.lock()->reportException(std::move(errMsg));
173 ChimeraTK::setDMapFilePath(dmapFilePath);
boost::shared_ptr< DeviceManager > getDeviceManager(const std::string &aliasOrCDD)
Return the DeviceManager for the given alias name or CDD.
static Application & getInstance()
Obtain instance of the application.
Implements access to a ChimeraTK::Device.
DeviceModule & operator=(DeviceModule &&other) noexcept
Move assignment.
boost::weak_ptr< DeviceManager > _dm
The corresponding DeviceManager.
void addInitialisationHandler(std::function< void(ChimeraTK::Device &)> initialisationHandler)
void reportException(std::string errMsg)
Use this function to report an exception.
std::string _pathInDevice
DeviceManager & getDeviceManager()
Return the corresponding DeviceManager.
const std::string & getDeviceAliasOrURI() const
Model::DeviceModuleProxy getModel()
Model::DeviceModuleProxy _model
void addVariable(ProcessVariableProxy &variable, VariableNetworkNode &node)
bool visitByPath(std::string_view path, VISITOR visitor) const
Resolve the given path and call the visitor for the found object.
ModuleGroupProxy add(ModuleGroup &module)
void removeNode(const VariableNetworkNode &node)
Remove VariableNetworkNode from the list of nodes. Note: Will invalidate return value of getNodes()!
bool isValid() const
Check if the model is valid.
auto visit(VISITOR visitor, Args... args) const
Traverse the model using the specified filter and call the visitor functor for each ModuleGroup,...
ModuleGroup & operator=(ModuleGroup &&other) noexcept
Move assignment.
friend class DeviceModule
ChimeraTK::Model::ModuleGroupProxy getModel()
Return the application model proxy representing this module.
SetDMapFilePath(const std::string &dmapFilePath)
Class describing a node of a variable network.
constexpr ReturnFirstHitWithValue< void > returnFirstHit()
Stop the search after the first hit and return.
std::string getPathName(const std::string &qualifiedName)
Return all but the last components of the given qualified name.
std::string getUnqualifiedName(const std::string &qualifiedName)
Return the last component of the given qualified path name.
InvalidityTracer application module.