pvDatabaseCPP  4.7.1-dev
pvdbcrScalarRecord.cpp
Go to the documentation of this file.
1 /*
2  * Copyright information and license terms for this software can be
3  * found in the file LICENSE that is included with the distribution
4  */
5 
10 #include <iocsh.h>
11 #include <pv/standardField.h>
12 #include <pv/standardPVField.h>
13 #include <pv/timeStamp.h>
14 #include <pv/pvTimeStamp.h>
15 #include <pv/alarm.h>
16 #include <pv/pvAlarm.h>
17 #include <pv/pvAccess.h>
18 #include <pv/serverContext.h>
19 #include <pv/rpcService.h>
20 
21 // The following must be the last include for code pvDatabase implements
22 #include <epicsExport.h>
23 #define epicsExportSharedSymbols
24 #include "pv/pvDatabase.h"
25 #include "pv/pvdbcrScalarRecord.h"
26 using namespace epics::pvData;
27 using namespace std;
28 
29 namespace epics { namespace pvDatabase {
30 
31 PvdbcrScalarRecord::PvdbcrScalarRecord(
32  std::string const & recordName,epics::pvData::PVStructurePtr const & pvStructure,
33  int asLevel,std::string const & asGroup)
34 : PVRecord(recordName,pvStructure,asLevel,asGroup)
35 {}
36 
37 PvdbcrScalarRecordPtr PvdbcrScalarRecord::create(
38  std::string const & recordName,std::string const & scalarType,
39  int asLevel,std::string const & asGroup)
40 {
41  ScalarType st = epics::pvData::ScalarTypeFunc::getScalarType(scalarType);
42  FieldCreatePtr fieldCreate = getFieldCreate();
43  StandardFieldPtr standardField = getStandardField();
44  PVDataCreatePtr pvDataCreate = getPVDataCreate();
45  StructureConstPtr top = fieldCreate->createFieldBuilder()->
46  add("value",st) ->
47  add("timeStamp",standardField->timeStamp()) ->
48  add("alarm",standardField->alarm()) ->
49  createStructure();
50  PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
51  PvdbcrScalarRecordPtr pvRecord(new PvdbcrScalarRecord(recordName,pvStructure,asLevel,asGroup));
52  pvRecord->initPVRecord();
53  return pvRecord;
54 };
55 }}
56 
57 static const iocshArg arg0 = { "recordName", iocshArgString };
58 static const iocshArg arg1 = { "scalarType", iocshArgString };
59 static const iocshArg arg2 = { "asLevel", iocshArgInt };
60 static const iocshArg arg3 = { "asGroup", iocshArgString };
61 static const iocshArg *args[] = {&arg0,&arg1,&arg2,&arg3};
62 
63 static const iocshFuncDef pvdbcrScalarFuncDef = {"pvdbcrScalarRecord", 4,args};
64 
65 static void pvdbcrScalarCallFunc(const iocshArgBuf *args)
66 {
67  char *sval = args[0].sval;
68  if(!sval) {
69  throw std::runtime_error("pvdbcrScalarRecord recordName not specified");
70  }
71  string recordName = string(sval);
72  sval = args[1].sval;
73  if(!sval) {
74  throw std::runtime_error("pvdbcrScalarRecord scalarType not specified");
75  }
76  string scalarType = string(sval);
77  int asLevel = args[2].ival;
78  string asGroup("DEFAULT");
79  sval = args[3].sval;
80  if(sval) {
81  asGroup = string(sval);
82  }
84  = epics::pvDatabase::PvdbcrScalarRecord::create(recordName,scalarType);
86  record->setAsLevel(asLevel);
87  record->setAsGroup(asGroup);
88  bool result = master->addRecord(record);
89  if(!result) cout << "recordname " << recordName << " not added" << endl;
90 }
91 
92 static void pvdbcrScalarRecord(void)
93 {
94  static int firstTime = 1;
95  if (firstTime) {
96  firstTime = 0;
97  iocshRegister(&pvdbcrScalarFuncDef, pvdbcrScalarCallFunc);
98  }
99 }
100 
101 extern "C" {
102  epicsExportRegistrar(pvdbcrScalarRecord);
103 }
STL namespace.
epicsExportRegistrar(pvdbcrScalarRecord)
static PvdbcrScalarRecordPtr create(std::string const &recordName, std::string const &scalarType, int asLevel=0, std::string const &asGroup=std::string("DEFAULT"))
Create a record.
std::tr1::shared_ptr< PVDatabase > PVDatabasePtr
Definition: pvDatabase.h:43
static PVDatabasePtr getMaster()
Get the master database.
Definition: pvDatabase.cpp:38
PvdbcrScalarRecord creates a record with a scalar value, alarm, and timeStamp.
std::tr1::shared_ptr< PvdbcrScalarRecord > PvdbcrScalarRecordPtr