This is Unofficial EPICS BASE Doxygen Site
removeRecord.cpp
Go to the documentation of this file.
1 /* removeRecord.cpp */
12 #include <string>
13 #include <cstring>
14 #include <stdexcept>
15 #include <memory>
16 #include <set>
17 
18 #include <pv/lock.h>
19 #include <pv/pvType.h>
20 #include <pv/pvData.h>
21 #include <pv/pvTimeStamp.h>
22 #include <pv/timeStamp.h>
23 #include <pv/rpcService.h>
24 #include <pv/pvAccess.h>
25 #include <pv/status.h>
26 #include <pv/serverContext.h>
27 
28 
29 #define epicsExportSharedSymbols
30 #include "pv/pvStructureCopy.h"
31 #include "pv/pvDatabase.h"
32 #include "pv/removeRecord.h"
33 
35 using namespace epics::pvData;
36 using namespace epics::pvAccess;
37 using namespace std;
38 
39 namespace epics { namespace pvDatabase {
40 
41 RemoveRecordPtr RemoveRecord::create(
42  std::string const & recordName)
43 {
44  FieldCreatePtr fieldCreate = getFieldCreate();
45  PVDataCreatePtr pvDataCreate = getPVDataCreate();
46  StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
47  addNestedStructure("argument")->
48  add("recordName",pvString)->
49  endNested()->
50  addNestedStructure("result") ->
51  add("status",pvString) ->
52  endNested()->
53  createStructure();
54  PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
55  RemoveRecordPtr pvRecord(
56  new RemoveRecord(recordName,pvStructure));
57  if(!pvRecord->init()) pvRecord.reset();
58  return pvRecord;
59 }
60 
61 RemoveRecord::RemoveRecord(
62  std::string const & recordName,
63  epics::pvData::PVStructurePtr const & pvStructure)
64 : PVRecord(recordName,pvStructure)
65 {
66 }
67 
68 bool RemoveRecord::init()
69 {
70  initPVRecord();
71  PVStructurePtr pvStructure = getPVStructure();
72  pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
73  if(!pvRecordName) return false;
74  pvResult = pvStructure->getSubField<PVString>("result.status");
75  if(!pvResult) return false;
76  return true;
77 }
78 
79 void RemoveRecord::process()
80 {
81  string name = pvRecordName->get();
82  PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
83  if(!pvRecord) {
84  pvResult->put(name + " not found");
85  return;
86  }
87  pvRecord->remove();
88  pvResult->put("success");
89 }
90 
91 
92 }}
std::tr1::shared_ptr< RemoveRecord > RemoveRecordPtr
Definition: removeRecord.h:21
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
Definition: memory.hpp:41
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
std::tr1::shared_ptr< const Structure > StructureConstPtr
Definition: pvIntrospect.h:162
Base interface for a PVRecord.
Definition: pvDatabase.h:56
std::tr1::shared_ptr< PVDataCreate > PVDataCreatePtr
Definition: pvData.h:124
Holds all PVA related.
Definition: pvif.h:34
PVString is special case, since it implements SerializableArray.
Definition: pvData.h:521
pvData
Definition: monitor.h:428
FORCE_INLINE const FieldCreatePtr & getFieldCreate()
std::tr1::shared_ptr< PVRecord > PVRecordPtr
Definition: pvDatabase.h:21
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
Remove another record in the same database.
Definition: removeRecord.h:32
std::tr1::shared_ptr< FieldCreate > FieldCreatePtr
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
Definition: pvData.h:1648