Newer
Older
Martin Christoph Hierholzer
committed
/*
* VariableNetworkNode.h
*
* Created on: Jun 23, 2016
* Author: Martin Hierholzer
*/
#ifndef CHIMERATK_VARIABLE_NETWORK_NODE_H
#define CHIMERATK_VARIABLE_NETWORK_NODE_H
Martin Christoph Hierholzer
committed
#include <assert.h>
Martin Christoph Hierholzer
committed
#include "Flags.h"
namespace xmlpp {
class Element;
}
namespace ChimeraTK {
class VariableNetwork;
class AccessorBase;
Martin Christoph Hierholzer
committed
/** Pseudo type to identify nodes which can have arbitrary types */
class AnyType {};
Martin Christoph Hierholzer
committed
/** Class describing a node of a variable network */
class VariableNetworkNode {
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
public:
Martin Christoph Hierholzer
committed
/** Constructor for an Application node */
VariableNetworkNode(AccessorBase &accessor);
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
/** Constructor for a Device node */
Martin Christoph Hierholzer
committed
VariableNetworkNode(const std::string &deviceAlias, const std::string ®isterName, UpdateMode mode,
VariableDirection direction, const std::type_info &valTyp=typeid(AnyType));
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
/** Constructor for a ControlSystem node */
Martin Christoph Hierholzer
committed
VariableNetworkNode(std::string publicName, VariableDirection direction,
const std::type_info &valTyp=typeid(AnyType));
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
/** Constructor for a TriggerReceiver node triggering the data transfer of another network */
VariableNetworkNode(VariableNetwork *networkToTrigger);
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
/** Default constructor for an invalid node */
VariableNetworkNode() {}
/** Set the owner network of this node. If an owner network is already set, an assertion will be raised */
void setOwner(VariableNetwork *network);
Martin Christoph Hierholzer
committed
/** Function checking if the node requires a fixed implementation */
bool hasImplementation() const;
/** Compare two nodes */
bool operator==(const VariableNetworkNode& other) const;
bool operator!=(const VariableNetworkNode& other) const;
/** Print node information to std::cout */
void dump() const;
/** Create an XML node describing this network node as seen by the control syste. If the type is not
* NodeType::ControlSystem, this function does nothing. Otherwise the correct directory hierarchy will be
* created (if not yet existing) and a variable tag will be created containing the externally visible
* properties of this variable. */
void createXML(xmlpp::Element *rootElement) const;
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
/** Check if the node already has an owner */
bool hasOwner() const { return network != nullptr; }
Martin Christoph Hierholzer
committed
/** Getter for the properties */
NodeType getType() const { return type; }
UpdateMode getMode() const { return mode; }
Martin Christoph Hierholzer
committed
VariableDirection getDirection() const { return direction; }
const std::type_info& getValueType() const { return *valueType; }
const std::string& getUnit() const { return unit; }
Martin Christoph Hierholzer
committed
VariableNetwork& getOwner() const { assert(network != nullptr); return *network; }
AccessorBase& getAppAccessor() const { assert(appNode != nullptr); return *appNode; }
VariableNetwork& getTriggerReceiver() const { assert(triggerReceiver != nullptr); return *triggerReceiver; }
const std::string& getPublicName() const { assert(type == NodeType::ControlSystem); return publicName; }
const std::string& getDeviceAlias() const { assert(type == NodeType::Device); return deviceAlias; }
const std::string& getRegisterName() const { assert(type == NodeType::Device); return registerName; }
private:
/** Type of the node (Application, Device, ControlSystem, Trigger) */
NodeType type{NodeType::invalid};
/** Update mode: poll or push */
UpdateMode mode{UpdateMode::invalid};
Martin Christoph Hierholzer
committed
/** Node direction: feeding or consuming */
VariableDirection direction{VariableDirection::invalid};
/** Value type of this node. If the type_info is the typeid of AnyType, the actual type can be decided when making
* the connections. */
const std::type_info* valueType{&typeid(AnyType)};
/** Engineering unit. If "arbitrary", no unit has been defined (and any unit is allowed). */
std::string unit{"arbitrary"};
Martin Christoph Hierholzer
committed
/** The network this node belongs to */
VariableNetwork *network{nullptr};
/** Pointer to Accessor if type == Application */
AccessorBase *appNode{nullptr};
/** Pointer to network which should be triggered by this node */
VariableNetwork *triggerReceiver{nullptr};
/** Public name if type == ControlSystem */
std::string publicName;
/** Device information if type == Device */
std::string deviceAlias;
std::string registerName;
Martin Christoph Hierholzer
committed
};
} /* namespace ChimeraTK */
#endif /* CHIMERATK_VARIABLE_NETWORK_NODE_H */