IOServer Class
A base class for IOServers. More...
Header: | #include <IO/IOServer.h> |
Inherits: | CDPComponent |
Inherited By: |
Public Functions
IOServer() | |
virtual | ~IOServer() |
virtual void | ConfigureChannel(XMLElementEx *channelConfig) |
virtual void | ConfigureNode(XMLElementEx *nodeConfig) |
void | DeregisterOnRecieveMessage(const std::string &relativePacketURI) |
void | DeregisterSendOnChange(ServerIO::ISendOnPropertyChange &packet, const char *propertyTracker = nullptr, ICDPNode *contextNode = nullptr) |
void | DeregisterSendOnMessage(const std::string &relativePacketURI) |
virtual double * | GetChannel(const char *fullName) |
double | GetSendOnChangeTimer() |
virtual bool | IsCommProblem() = 0 |
virtual bool | IsOutputDisabled(void) |
virtual unsigned int | NumberOfNodesInXml() const |
virtual unsigned int | NumberOfNodesOnline() |
virtual void | ProcessOffline() |
virtual void | ProcessOnline() |
void | PropertyChangeCallback(CDPPropertyBase *property) |
void | RegisterOnRecieveMessage(const std::string &targetRouting, const std::string &relativePacketURI) |
void | RegisterSendOnChange(ServerIO::ISendOnPropertyChange &packet, const char *propertyRouting = nullptr, ICDPNode *contextNode = nullptr) |
void | RegisterSendOnChangeWakeCall(ServerIO::IWakeFunctor *waker) |
void | RegisterSendOnMessage(ServerIO::ISendTrigger &packet, const std::string &relativePacketURI) |
void | RegisterSendOnMessageWakeCall(ServerIO::IWakeFunctor *waker) |
void | SetSendOnChangeTimer(double interval) |
virtual bool | TransitionNullToOffline() |
virtual bool | TransitionOfflineToOnline() |
virtual bool | TransitionOnlineToOffline() |
Reimplemented Public Functions
virtual void | Activate() override |
virtual void | ActivateIfWaitingForActivate() override |
virtual void | Configure(const char *componentXML) override |
virtual void | Create(const char *fullName) override |
virtual void | CreateModel() override |
virtual void | Destroy() override |
virtual bool | HandleXMLElement(XMLElementEx *pEx) override |
virtual void | ProcessNull() override |
- 90 public functions inherited from CDPComponent
- 37 public functions inherited from CDPObject
- 46 public functions inherited from CDPBaseObject
- 26 public functions inherited from CDP::StudioAPI::CDPNode
- 22 public functions inherited from CDP::StudioAPI::ICDPNode
Protected Functions
int | HandleIOTrigger(const MessagePacketHandle &handle) |
- 12 protected functions inherited from CDPComponent
- 13 protected functions inherited from CDPObject
- 1 protected function inherited from CDP::StudioAPI::CDPNode
Protected Variables
CDPSignal<unsigned int> | m_NumberOfNodes |
CDPSignal<unsigned int> | m_NumberOfNodesOnline |
CDPSignal<double> | m_SendReceiveRoundtrip |
CDPParameterTimer | m_dSignalTimeoutTimer |
CDPAlarm * | m_pTransmissionAlarm |
ServerIO::MessageTriggeringSupport<CDPConnector, IOServer> * | messageTriggeringImplementer |
CDPSignal<bool> | outputDisabled |
ServerIO::TSendOnPropertyChangeSupport<CDPBaseObject, CDPPropertyBase, IOServer> * | sendOnPropertyChangeImplementer |
- 31 protected variables inherited from CDPComponent
- 7 protected variables inherited from CDPObject
- 9 protected variables inherited from CDPBaseObject
Additional Inherited Members
- 2 static public members inherited from CDPComponent
- 6 static public members inherited from CDPObject
- 1 static public member inherited from CDPBaseObject
- 1 static protected member inherited from CDPObject
Detailed Description
A base class for IOServers.
IOServers are special CDPComponents that handle transforming CDP data to and from an external interface. They typically have threads to do lengthy processing, since blocking operations can't be used in Process-functions.
Usage
The IOServer is a base class. Derived IOServers should derive from this class and implement the methods:
A custom IOServer can be added using the Add New... -> Custom IOServer wizard from a library. This will generate the base code and model for an IOServer that has a Transport.
If you do not need the Transport, you can just delete any references to m_transport. Remember to also remove the Transport table; In the Library in Configure mode, click into the CustomIO Elements table and delete the Transport Element.
To make the CustomIO handle dynamic channel configurations, a ChannelManager should be used. See the ChannelManager documentation for how to add ChannelManager functionality to the IOServer.
Another option is to use fixed signals for the I/O. You must then either lock the GetMemberAccessMutex() when accessing the signals, or use CDPComponent::RunInComponentThread() to access the signals.
Note: The example Implementing a Custom Protocol shows how to implement a simple custom IOServer.
Output Disable
The outputs (writes) from the IOServers can be switched off to avoid several components writing different signals to the same physical I/O. The actual output- off- switch must be implemented in the derived IOServer class. The member function IsOutputDisabled() should be used to check if outputs are disabled.
Implementation example:
void CustomIO::ProtocolImplementation() { ... if(!IsOutputDisabled()) SendOutputs(); ReceiveInputs(); ... }
Parameters:
Parameter Name | Description |
---|---|
SignalTimeout | If no data is received within this number of seconds after a send, the Transmission Error is set. |
Signals:
Signal Name | Description |
---|---|
Send-Receive Roundtrip time | The time in seconds from sending until a response is received. |
NumberOfNodes | Number of nodes this IOServer will communicate with |
NumberOfNodesOnline | Number of nodes this IOServer is Online with (communication and node OK) |
outputDisabled | This signal is set to 1 when outputs are disabled, and 0 if not. |
Alarms:
Alarm Name | Description |
---|---|
Transmission Error | This alarm is set when no data has been received for more than 'SignalTimeout' seconds |
See also ServerIO, ServerIO::ChannelManager, ServerIO::IChannel, ServerIO::ICDPChannel, ServerIO::IChangeValidator, ServerIO::IWakeFunctor, ServerIO::ISendTrigger, ServerIO::ISendOnPropertyChange, ServerIO::DeltaValidatorSendTrigger, ServerIO::ACDPBaseChannel, ServerIO::CDPSignalChannel, ServerIO::CDPPropertyChannel, ServerIO::ComponentStateChannel, and ServerIO::ChangeValidatorSupport.
Member Function Documentation
IOServer::IOServer()
Constructs an IOServer.
The member sendOnPropertyChangeImplementer is created from "new ServerIO::TSendOnPropertyChangeSupport<CDPBaseObject,CDPPropertyBase,IOServer>(this)".
The member messageTriggeringImplementer is created from "new ServerIO::MessageTriggeringSupport<CDPConnector, IOServer>(this)".
[virtual]
IOServer::~IOServer()
IOServer destructor, deletes sendOnPropertyChangeImplementer.
[override virtual]
void IOServer::Activate()
Reimplemented from CDPBaseObject::Activate().
Activates the IOServer, starts message processing and periodic process execution.
The CDPSignal NumberOfNodes
is initialized with value from function NumberOfNodesInXml().
[override virtual]
void IOServer::ActivateIfWaitingForActivate()
Reimplemented from CDPObject::ActivateIfWaitingForActivate().
If activate time has been reached, the IOServer is activated.
[override virtual]
void IOServer::Configure(const char *componentXML)
Reimplemented from CDPObject::Configure().
Configure this IOServer from xml.
[virtual]
void IOServer::ConfigureChannel(XMLElementEx *channelConfig)
Creates an i/o signal from channelConfig.
[virtual]
void IOServer::ConfigureNode(XMLElementEx *nodeConfig)
Configures all the modules in one node for this IOServer from nodeConfig.
[override virtual]
void IOServer::Create(const char *fullName)
Reimplemented from CDPComponent::Create().
Creates an IOServer. requestedState is initialized to "Offline".
[override virtual]
void IOServer::CreateModel()
Reimplemented from CDPBaseObject::CreateModel().
Creates model for IOServer. Registers initial states and transitions.
The IOServer base-class REQUIRES these states:
Online
: Switches to Offline state. Offline
: Switches to Online state.
The IOServer base-class REQUIRES these transitions:
Null: initial state, statetransition TransitionNullToOffline
. Offline: checks if we can go Online, statetransition TransitionOnlineToOffline
. Online: checks if we must go to Offline, statetransition TransitionOfflineToOnline
.
void IOServer::DeregisterOnRecieveMessage(const std::string &relativePacketURI)
Deregisters a packet from triggering a message sending.
The function is symmetric opposite to RegisterOnRecieveMessage().
void IOServer::DeregisterSendOnChange(ServerIO::ISendOnPropertyChange &packet, const char *propertyTracker = nullptr, ICDPNode *contextNode = nullptr)
Deregisters a packet from listening for trackedProperty. Must be called before packet is deleted.
When the propertyTracker and contextNode is nullptr, the default property link is removed.
void IOServer::DeregisterSendOnMessage(const std::string &relativePacketURI)
Deregisters a packet from message based triggering.
The function is symmetric opposite to RegisterSendOnMessage().
[override virtual]
void IOServer::Destroy()
Reimplemented from CDPBaseObject::Destroy().
Destroys this IOServer.
[virtual]
double *IOServer::GetChannel(const char *fullName)
Currently not implemented, will just return nullptr.
double IOServer::GetSendOnChangeTimer()
Get timer interval used for default periodic send on change property.
[protected]
int IOServer::HandleIOTrigger(const MessagePacketHandle &handle)
[override virtual]
bool IOServer::HandleXMLElement(XMLElementEx *pEx)
Reimplemented from CDPComponent::HandleXMLElement().
HandleXMLElement() handles XMLElement-names "Channel" and "Node", otherwise calls CDPComponent::HandleXMLElement(pEx).
If XMLElement-name (pEx->GetName()) is "Channel", true
is returned. If XMLElement-name is "Node", ConfigureNode(pEx) is called before true
is returned. Otherwise, value from CDPComponent::HandleXMLElement(pEx) is returned.
[pure virtual]
bool IOServer::IsCommProblem()
Should return true if there is a communication-problem/lost contact with one or several nodes, false if not.
Must be implemented in classes inheriting IOServer.
[virtual]
bool IOServer::IsOutputDisabled(void)
Returns value from CDPSignal outputDisabled.
[virtual]
unsigned int IOServer::NumberOfNodesInXml() const
This function just returns 1.
Overridden version should return number of nodes which the I/O Server configuration specifies. Must be overridden in classes inheriting IOServer, if receiving from more than 1 node.
[virtual]
unsigned int IOServer::NumberOfNodesOnline()
This function returns 1 as long as state is Online, 0 is returned otherwise.
Overridden version should return number of nodes online (receiving from, not timedout, and possibly nodestatus OK (if available)). Must be overridden in classes inheriting IOServer, if receiving from more than 1 node.
[override virtual]
void IOServer::ProcessNull()
Reimplemented from CDPComponent::ProcessNull().
Process method for Null state.
The CDPSignal NumberOfNodesOnline
is updated with value from function NumberOfNodesOnline().
[virtual]
void IOServer::ProcessOffline()
Process-function for Offline state.
Calls sendOnPropertyChangeImplementer->ProcessSendOnChangeRequests(). If IsCommProblem() returns false, "Online" state is requested, SignalTimeoutTimer is restarted and Transmission Error alarm is cleared if it was set. If IsCommProblem() returns true, Transmission Error alarm is set if SignalTimeoutTimer has timed out. The CDPSignal NumberOfNodesOnline
is updated with value from function NumberOfNodesOnline().
[virtual]
void IOServer::ProcessOnline()
Process-function for Online state.
Calls sendOnPropertyChangeImplementer->ProcessSendOnChangeRequests(). If IsCommProblem() returns true, "Offline" state is requested, and Transmission Error alarm is set if SignalTimeoutTimer has timed out. If IsCommProblem() returns false, SignalTimeoutTimer is restarted and Transmission Error alarm is cleared if it was set. The CDPSignal NumberOfNodesOnline
is updated with value from function NumberOfNodesOnline().
void IOServer::PropertyChangeCallback(CDPPropertyBase *property)
Is called by all the properties on target change to handle send flag setting by IOServer on ISendOnPropertyChange implementers.
The input properties are created by the IOServer to listen to external properties.
void IOServer::RegisterOnRecieveMessage(const std::string &targetRouting, const std::string &relativePacketURI)
Registers a packet to trigger the sending of IOTrigger text command message on packet reception.
The function is intended to be used by IOServers that need to implement Message sending on recieve packets.
The function is used with MessageTriggeringSupport::TriggerMessage() that implements ITriggerMessage interface. The MessageTriggeringSupport pointer should be passed into the packet as ITriggerMessage pointer and TriggerMessage() called when the packet is recieved.
targetRouting should contain routing to Object that Handles the IOTrigger messages for the packet. relativePacketURI should contain relative packet routing in the IOServer in question. Incoming event on this packet will trigger corresponding text command message to be sent to targetRouting when packet recieve code calls MessageTriggeringSupport::TriggerMessage() with packets relativePacketURI.
void IOServer::RegisterSendOnChange(ServerIO::ISendOnPropertyChange &packet, const char *propertyRouting = nullptr, ICDPNode *contextNode = nullptr)
Registers a packet to be flagged to be sent on property change.
When propertyRouting is provided, the routed property should be of bool type. The packet's FlagForSend() is called each time the routed property has an edge (change from true to false or from false to true). When propertyRouting is not provided, the packet will be sent at the owning components period.
The propertyRouting must either be a full URI or if relative routing support is required, the optional contextNode argument must be passed in. The contextNode is the node containing the propertyRouting value.
See also ServerIO::ICDPChannel::RegisterValidator().
void IOServer::RegisterSendOnChangeWakeCall(ServerIO::IWakeFunctor *waker)
Setting the IWakeFunctor for the IOServer worker thread.
If IOServer Main thread uses a CDPEvent or OSAPIPeriodicTimer to wait on thread the RegisterSendOnChangeWakeCall may be used to register a Functor that wakes up the specific event or timer from wait. The IOServer implementation should then create a wake functor with the waiting class OSAPIPeriodicTimer for ex. and register it.
struct IOWorkerFunctor : public ServerIO::IWakeFunctor { IOWorkerFunctor(OSAPIPeriodicTimer* t) { wakeable=t; } void operator()() { if (wakable) wakable->SetEvent(); } private: OSAPIPeriodicTimer* wakeable; };
See also ServerIO::ICDPChannel::RegisterValidator().
void IOServer::RegisterSendOnMessage(ServerIO::ISendTrigger &packet, const std::string &relativePacketURI)
Registers a packet to be flagged to be sent on IOTrigger text command message.
The function is intended to be used by IOServers that need to implement Message based triggering for transmit packets.
packet to be registered for send on message behaviour relativePacketURI is packets relative URI in the IOServer
The IOTrigger message must be sent with CDPConnector, that is connected to the IOServer component containing the packet, using additional parameter indicating relative URI of the packet in IOServer component. Optionally the parameter may contain semicolon separated key value pairs to override packet channel values for triggered packet.
The packet triggering with CDPConnector from user component code would look as follows:
connector.SendMessage(ServerIO::IOTrigger, ".MyNode.TPDO1;Speed=20");
void IOServer::RegisterSendOnMessageWakeCall(ServerIO::IWakeFunctor *waker)
Setting the IWakeFunctor for the IOServer worker thread for IOTrigger message wakeup.
If IOServer Main thread uses a CDPEvent or OSAPIPeriodicTimer to wait on thread the RegisterSendOnMessageWakeCall may be used to register a Functor that wakes up the specific event or timer from wait. The IOServer implementation should then create a wake functor with the waiting class OSAPIPeriodicTimer for ex. and register it.
struct IOWorkerFunctor : public ServerIO::IWakeFunctor { IOWorkerFunctor(OSAPIPeriodicTimer* t) { wakeable=t; } void operator()() override { if (wakable) wakable->SetEvent(); } private: OSAPIPeriodicTimer* wakeable; };
void IOServer::SetSendOnChangeTimer(double interval)
Set timer interval used for default periodic send on change property.
[virtual]
bool IOServer::TransitionNullToOffline()
Returns true if requestedState is equal to "Offline".
[virtual]
bool IOServer::TransitionOfflineToOnline()
Returns true if requestedState is equal to "Online".
[virtual]
bool IOServer::TransitionOnlineToOffline()
Returns true if requestedState is equal to "Offline".
Member Variable Documentation
CDPSignal<unsigned int> IOServer::m_NumberOfNodes
This variable holds the CDPSignal "NumberOfNodes", with number of nodes this IOServer will communicate with.
CDPSignal<unsigned int> IOServer::m_NumberOfNodesOnline
This variable holds the CDPSignal "NumberOfNodesOnline", with number of nodes this IOServer is Online with (communication and node OK).
CDPSignal<double> IOServer::m_SendReceiveRoundtrip
This variable holds the CDPSignal "Send-Receive Roundtrip time", giving time in seconds from sending until a response is received.
CDPParameterTimer IOServer::m_dSignalTimeoutTimer
This variable holds the CDPParameterTimer "SignalTimeout"/"SignalTimeoutTimer": If no data is received within this number of seconds after a send, the Transmission Error is set.
CDPAlarm *IOServer::m_pTransmissionAlarm
This variable holds pointer to the CDPAlarm "Transmission Error", which is set when no data has been received for more than 'SignalTimeout' seconds.
ServerIO::MessageTriggeringSupport<CDPConnector, IOServer> *IOServer::messageTriggeringImplementer
This variable holds pointer to MessageTriggeringSupport, which provides support for implementing transmit packet triggering via IOTrigger text command and IOTrigger message sending on packet reception in IOServers.
CDPSignal<bool> IOServer::outputDisabled
This variable holds the CDPSignal "OutputDisable" which is set to when outputs are disabled, and to if not.
ServerIO::TSendOnPropertyChangeSupport<CDPBaseObject, CDPPropertyBase, IOServer> *IOServer::sendOnPropertyChangeImplementer
This variable holds pointer to TSendOnPropertyChangeSupport, which handles property changes.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.