forked from epics-rip/exampleCPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exampleLinkMain.cpp
96 lines (88 loc) · 3.04 KB
/
exampleLinkMain.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
/**
* @author mrk
*/
/* Author: Marty Kraimer */
#include <cstddef>
#include <cstdlib>
#include <cstddef>
#include <string>
#include <cstdio>
#include <memory>
#include <vector>
#include <iostream>
#include <pv/channelProviderLocal.h>
#include <pv/serverContext.h>
#include <pv/ntscalarArray.h>
#include <pv/exampleMonitorLinkRecord.h>
#include <pv/exampleGetLinkRecord.h>
#include <pv/examplePutLinkRecord.h>
using namespace std;
using std::tr1::static_pointer_cast;
using namespace epics::pvData;
using namespace epics::nt;
using namespace epics::pvaClient;
using namespace epics::pvAccess;
using namespace epics::pvDatabase;
using namespace epics::exampleCPP::exampleLink;
int main(int argc,char *argv[])
{
string provider("pva");
string linkedRecordName("doubleArray");
bool generateLinkedRecord(true);
if(argc==2 && string(argv[1])==string("-help")) {
cout << "provider linkedRecordName generateLinkedRecord" << endl;
cout << "default" << endl;
cout << provider << " " << " " << linkedRecordName << " true" << endl;
return 0;
}
if(argc>1) provider = argv[1];
if(argc>2) linkedRecordName = argv[2];
if(argc>3) {
string val = argv[3];
if(val=="false") generateLinkedRecord = false;
}
try {
PVDatabasePtr master = PVDatabase::getMaster();
ChannelProviderLocalPtr channelProvider = getChannelProviderLocal();
PvaClientPtr pva= PvaClient::get(provider);
ServerContext::shared_pointer ctx =
startPVAServer("local",0,true,true);
if(generateLinkedRecord) {
NTScalarArrayBuilderPtr ntScalarArrayBuilder = NTScalarArray::createBuilder();
PVStructurePtr pvStructure = ntScalarArrayBuilder->
value(pvDouble)->
addAlarm()->
addTimeStamp()->
createPVStructure();
PVRecordPtr pvRecord(PVRecord::create(linkedRecordName,pvStructure));
master->addRecord(pvRecord);
}
ExampleMonitorLinkRecordPtr pvMonitorRecord(
ExampleMonitorLinkRecord::create(
pva, "exampleMonitorLink",provider,linkedRecordName));
master->addRecord(pvMonitorRecord);
ExampleGetLinkRecordPtr pvGetRecord(
ExampleGetLinkRecord::create(
pva,"exampleGetLink",provider,linkedRecordName));
master->addRecord(pvGetRecord);
ExamplePutLinkRecordPtr pvPutRecord(
ExamplePutLinkRecord::create(
pva,"examplePutLink",provider,linkedRecordName));
master->addRecord(pvPutRecord);
cout << "exampleMonitorLink\n";
string str;
while(true) {
cout << "Type exit to stop: \n";
getline(cin,str);
if(str.compare("exit")==0) break;
}
} catch (std::runtime_error e) {
cerr << "exception " << e.what() << endl;
return 1;
}
return 0;
}