11 #include <pv/standardField.h> 12 #include <pv/standardPVField.h> 13 #include <pv/timeStamp.h> 14 #include <pv/pvTimeStamp.h> 16 #include <pv/pvAlarm.h> 17 #include <pv/pvAccess.h> 18 #include <pv/serverContext.h> 19 #include <pv/rpcService.h> 22 #include <epicsExport.h> 23 #define epicsExportSharedSymbols 29 namespace epics {
namespace pvDatabase {
32 std::string
const & recordName,
33 int asLevel,std::string
const & asGroup)
35 FieldCreatePtr fieldCreate = getFieldCreate();
36 PVDataCreatePtr pvDataCreate = getPVDataCreate();
37 StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
38 addNestedStructure(
"argument")->
39 add(
"recordName",pvString)->
40 addNestedUnion(
"union") ->
43 addNestedStructure(
"result") ->
44 add(
"status",pvString) ->
47 PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
50 if(!pvRecord->init()) pvRecord.reset();
54 PvdbcrAddRecord::PvdbcrAddRecord(
55 std::string
const & recordName,
56 PVStructurePtr
const & pvStructure,
57 int asLevel,std::string
const & asGroup)
58 :
PVRecord(recordName,pvStructure,asLevel,asGroup)
62 bool PvdbcrAddRecord::init()
65 PVStructurePtr pvStructure = getPVStructure();
66 pvRecordName = pvStructure->getSubField<PVString>(
"argument.recordName");
67 if(!pvRecordName)
return false;
68 pvResult = pvStructure->getSubField<PVString>(
"result.status");
69 if(!pvResult)
return false;
73 void PvdbcrAddRecord::process()
75 PVDataCreatePtr pvDataCreate = getPVDataCreate();
76 string name = pvRecordName->get();
77 PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
79 pvResult->put(name +
" already exists");
82 PVUnionPtr pvUnion = getPVStructure()->getSubField<PVUnion>(
"argument.union");
84 pvResult->put(name +
" argument.union is NULL");
87 PVFieldPtr pvField(pvUnion->get());
89 pvResult->put(name +
" union has no value");
92 if(pvField->getField()->getType()!=epics::pvData::structure) {
93 pvResult->put(name +
" union most be a structure");
96 StructureConstPtr st = std::tr1::static_pointer_cast<
const Structure>(pvField->getField());
97 PVStructurePtr pvStructure = pvDataCreate->createPVStructure(st);
98 PVRecordPtr pvRec = PVRecord::create(name,pvStructure);
99 bool result = PVDatabase::getMaster()->addRecord(pvRec);
101 pvResult->put(
"success");
103 pvResult->put(
"failure");
108 static const iocshArg arg0 = {
"recordName", iocshArgString };
109 static const iocshArg arg1 = {
"asLevel", iocshArgInt };
110 static const iocshArg arg2 = {
"asGroup", iocshArgString };
111 static const iocshArg *args[] = {&arg0,&arg1,&arg2};
113 static const iocshFuncDef pvdbcrAddRecordFuncDef = {
"pvdbcrAddRecord", 3,args};
115 static void pvdbcrAddRecordCallFunc(
const iocshArgBuf *args)
117 char *sval = args[0].sval;
119 throw std::runtime_error(
"pvdbcrAddRecord recordName not specified");
121 string recordName = string(sval);
122 int asLevel = args[1].ival;
123 string asGroup(
"DEFAULT");
126 asGroup = string(sval);
129 record->setAsLevel(asLevel);
130 record->setAsGroup(asGroup);
132 bool result = master->addRecord(record);
133 if(!result) cout <<
"recordname " << recordName <<
" not added" << endl;
136 static void pvdbcrAddRecord(
void)
138 static int firstTime = 1;
141 iocshRegister(&pvdbcrAddRecordFuncDef, pvdbcrAddRecordCallFunc);
Base interface for a PVRecord.
std::tr1::shared_ptr< PVDatabase > PVDatabasePtr
std::tr1::shared_ptr< PvdbcrAddRecord > PvdbcrAddRecordPtr
PvdbcrAddRecord A record that adds a record to the master database.
static PVDatabasePtr getMaster()
Get the master database.
std::tr1::shared_ptr< PVRecord > PVRecordPtr
epicsExportRegistrar(pvdbcrAddRecord)
static PvdbcrAddRecordPtr create(std::string const &recordName, int asLevel=0, std::string const &asGroup=std::string("DEFAULT"))
Create a record.