pvDatabaseCPP  4.7.0
pvdbcrTraceRecord.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
22 #include <epicsExport.h>
23 #define epicsExportSharedSymbols
24 #include "pv/pvDatabase.h"
25 #include "pv/pvdbcrTraceRecord.h"
26 using namespace epics::pvData;
27 using namespace std;
28 
29 namespace epics { namespace pvDatabase {
30 
31 PvdbcrTraceRecordPtr PvdbcrTraceRecord::create(
32  std::string const & recordName,
33  int asLevel,std::string const & asGroup)
34 {
35  FieldCreatePtr fieldCreate = getFieldCreate();
36  PVDataCreatePtr pvDataCreate = getPVDataCreate();
37  StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
38  addNestedStructure("argument")->
39  add("recordName",pvString)->
40  add("level",pvInt)->
41  endNested()->
42  addNestedStructure("result") ->
43  add("status",pvString) ->
44  endNested()->
45  createStructure();
46  PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
47  PvdbcrTraceRecordPtr pvRecord(
48  new PvdbcrTraceRecord(recordName,pvStructure,asLevel,asGroup));
49  if(!pvRecord->init()) pvRecord.reset();
50  return pvRecord;
51 }
52 
53 PvdbcrTraceRecord::PvdbcrTraceRecord(
54  std::string const & recordName,
55  epics::pvData::PVStructurePtr const & pvStructure,
56  int asLevel,std::string const & asGroup)
57 : PVRecord(recordName,pvStructure,asLevel,asGroup)
58 {
59 }
60 
61 
62 bool PvdbcrTraceRecord::init()
63 {
64  initPVRecord();
65  PVStructurePtr pvStructure = getPVStructure();
66  pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
67  if(!pvRecordName) return false;
68  pvLevel = pvStructure->getSubField<PVInt>("argument.level");
69  if(!pvLevel) return false;
70  pvResult = pvStructure->getSubField<PVString>("result.status");
71  if(!pvResult) return false;
72  return true;
73 }
74 
75 void PvdbcrTraceRecord::process()
76 {
77  string name = pvRecordName->get();
78  PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
79  if(!pvRecord) {
80  pvResult->put(name + " not found");
81  return;
82  }
83  pvRecord->setTraceLevel(pvLevel->get());
84  pvResult->put("success");
85 }
86 }}
87 
88 static const iocshArg arg0 = { "recordName", iocshArgString };
89 static const iocshArg arg1 = { "asLevel", iocshArgInt };
90 static const iocshArg arg2 = { "asGroup", iocshArgString };
91 static const iocshArg *args[] = {&arg0,&arg1,&arg2};
92 
93 static const iocshFuncDef pvdbcrTraceRecordFuncDef = {"pvdbcrTraceRecord", 3,args};
94 
95 static void pvdbcrTraceRecordCallFunc(const iocshArgBuf *args)
96 {
97  char *sval = args[0].sval;
98  if(!sval) {
99  throw std::runtime_error("pvdbcrTraceRecord recordName not specified");
100  }
101  string recordName = string(sval);
102  int asLevel = args[1].ival;
103  string asGroup("DEFAULT");
104  sval = args[2].sval;
105  if(sval) {
106  asGroup = string(sval);
107  }
110  record->setAsLevel(asLevel);
111  record->setAsGroup(asGroup);
113  bool result = master->addRecord(record);
114  if(!result) cout << "recordname " << recordName << " not added" << endl;
115 }
116 
117 static void pvdbcrTraceRecord(void)
118 {
119  static int firstTime = 1;
120  if (firstTime) {
121  firstTime = 0;
122  iocshRegister(&pvdbcrTraceRecordFuncDef, pvdbcrTraceRecordCallFunc);
123  }
124 }
125 
126 extern "C" {
127  epicsExportRegistrar(pvdbcrTraceRecord);
128 }
STL namespace.
static PvdbcrTraceRecordPtr create(std::string const &recordName, int asLevel=0, std::string const &asGroup=std::string("DEFAULT"))
Create a record.
Base interface for a PVRecord.
Definition: pvDatabase.h:56
std::tr1::shared_ptr< PVDatabase > PVDatabasePtr
Definition: pvDatabase.h:43
std::tr1::shared_ptr< PvdbcrTraceRecord > PvdbcrTraceRecordPtr
static PVDatabasePtr getMaster()
Get the master database.
Definition: pvDatabase.cpp:38
std::tr1::shared_ptr< PVRecord > PVRecordPtr
Definition: pvDatabase.h:21
epicsExportRegistrar(pvdbcrTraceRecord)
PvdbcrTraceRecord A record sets trace level for a record in the master database.