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> 21 #include <epicsExport.h> 22 #define epicsExportSharedSymbols 28 namespace epics {
namespace pvDatabase {
31 std::string
const & recordName,
32 int asLevel,std::string
const & asGroup)
34 FieldCreatePtr fieldCreate = getFieldCreate();
35 PVDataCreatePtr pvDataCreate = getPVDataCreate();
36 StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
37 addNestedStructure(
"argument")->
38 add(
"recordName",pvString)->
40 addNestedStructure(
"result") ->
41 add(
"status",pvString) ->
44 PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
48 if(!pvRecord->init()) pvRecord.reset();
52 PvdbcrRemoveRecord::PvdbcrRemoveRecord(
53 std::string
const & recordName,
54 epics::pvData::PVStructurePtr
const & pvStructure,
55 int asLevel,std::string
const & asGroup)
56 :
PVRecord(recordName,pvStructure,asLevel,asGroup)
60 bool PvdbcrRemoveRecord::init()
63 PVStructurePtr pvStructure = getPVStructure();
64 pvRecordName = pvStructure->getSubField<PVString>(
"argument.recordName");
65 if(!pvRecordName)
return false;
66 pvResult = pvStructure->getSubField<PVString>(
"result.status");
67 if(!pvResult)
return false;
71 void PvdbcrRemoveRecord::process()
73 string name = pvRecordName->get();
74 PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
76 pvResult->put(name +
" not found");
80 pvResult->put(
"success");
84 static const iocshArg arg0 = {
"recordName", iocshArgString };
85 static const iocshArg arg1 = {
"asLevel", iocshArgInt };
86 static const iocshArg arg2 = {
"asGroup", iocshArgString };
87 static const iocshArg *args[] = {&arg0,&arg1,&arg2};
89 static const iocshFuncDef pvdbcrRemoveRecordFuncDef = {
"pvdbcrRemoveRecord", 3,args};
91 static void pvdbcrRemoveRecordCallFunc(
const iocshArgBuf *args)
93 char *sval = args[0].sval;
95 throw std::runtime_error(
"pvdbcrRemoveRecord recordName not specified");
97 string recordName = string(sval);
98 int asLevel = args[1].ival;
99 string asGroup(
"DEFAULT");
102 asGroup = string(sval);
105 record->setAsLevel(asLevel);
106 record->setAsGroup(asGroup);
108 bool result = master->addRecord(record);
109 if(!result) cout <<
"recordname " << recordName <<
" not added" << endl;
112 static void pvdbcrRemoveRecord(
void)
114 static int firstTime = 1;
117 iocshRegister(&pvdbcrRemoveRecordFuncDef, pvdbcrRemoveRecordCallFunc);
std::tr1::shared_ptr< PvdbcrRemoveRecord > PvdbcrRemoveRecordPtr
PvdbcrRemoveRecord A record that removes a record from the master database.
epicsExportRegistrar(pvdbcrRemoveRecord)
Base interface for a PVRecord.
std::tr1::shared_ptr< PVDatabase > PVDatabasePtr
static PvdbcrRemoveRecordPtr create(std::string const &recordName, int asLevel=0, std::string const &asGroup=std::string("DEFAULT"))
Create a record.
static PVDatabasePtr getMaster()
Get the master database.
std::tr1::shared_ptr< PVRecord > PVRecordPtr