File: rpcWildServiceExample.cpp

package info (click to toggle)
epics-base 7.0.8.1%2Bdfsg1-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,532 kB
  • sloc: cpp: 130,870; ansic: 115,274; perl: 10,647; makefile: 3,477; yacc: 1,307; python: 594; lex: 236; sh: 108; csh: 36
file content (47 lines) | stat: -rw-r--r-- 1,448 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
 * Copyright - See the COPYRIGHT that is included with this distribution.
 * pvAccessCPP is distributed subject to a Software License Agreement found
 * in file LICENSE that is included with this distribution.
 */

#include <pv/pvData.h>
#include <pv/rpcServer.h>

using namespace epics::pvData;
using namespace epics::pvAccess;

static Structure::const_shared_pointer resultStructure =
    getFieldCreate()->createFieldBuilder()->
    add("channelName", pvString)->
    createStructure();

class WildServiceImpl :
    public RPCService
{
    PVStructure::shared_pointer request(PVStructure::shared_pointer const & pvArguments)
    {
        // requires NTURI as argument
        if (pvArguments->getStructure()->getID() != "epics:nt/NTURI:1.0")
            throw RPCRequestException(Status::STATUSTYPE_ERROR, "RPC argument must be a NTURI normative type");

        std::string channelName = pvArguments->getSubField<PVString>("path")->get();

        // create return structure and set data
        PVStructure::shared_pointer result = getPVDataCreate()->createPVStructure(resultStructure);
        result->getSubField<PVString>("channelName")->put(channelName);
        return result;
    }
};

int main()
{
    RPCServer server;

    server.registerService("wild*", RPCService::shared_pointer(new WildServiceImpl()));
    // you can register as many services as you want here ...

    server.printInfo();
    server.run();

    return 0;
}