NDS3  1.0.0
API reference manual
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rpcSquare/rpcSquare.cpp

This example shows an PVAction node used for RPC-like functionality.

#include <nds3/nds.h>
class RPCSquare
{
public:
RPCSquare(nds::Factory& factory, const std::string& device,
const nds::namedParameters_t& parameters);
void square(const timespec& timestamp, const std::int32_t& value);
void init(timespec* timestamp, std::int32_t* value);
private:
nds::PVAction squarePV;
};
RPCSquare::RPCSquare(nds::Factory& factory, const std::string& device,
const nds::namedParameters_t& parameters)
{
nds::Port rootNode(device);
squarePV = nds::PVAction(
"Square", std::bind(&RPCSquare::square, this,
std::placeholders::_1, std::placeholders::_2),
std::bind(&RPCSquare::init, this, std::placeholders::_1,
std::placeholders::_2));
squarePV.setDescription("Square any integer");
rootNode.addChild(squarePV);
rootNode.initialize(this, factory);
}
void
RPCSquare::square(const timespec& timestamp, const std::int32_t& value)
{
squarePV.setValueBack(timestamp, value*value);
}
void
RPCSquare::init(timespec* timestamp, std::int32_t* value)
{
*value = 0;
}
NDS_DEFINE_DRIVER(RPCSquare, RPCSquare)