redo addRecord, removeRecord, processRecord, and traceRecord
This commit is contained in:
@ -23,11 +23,6 @@ INC += pv/pvDatabase.h
|
||||
|
||||
INC += pv/channelProviderLocal.h
|
||||
|
||||
#INC += pv/traceRecord.h
|
||||
#INC += pv/removeRecord.h
|
||||
#INC += pv/addRecord.h
|
||||
#INC += pv/processRecord.h
|
||||
|
||||
INC += pv/pvSupport.h
|
||||
INC += pv/controlSupport.h
|
||||
INC += pv/scalarAlarmSupport.h
|
||||
|
@ -1,63 +0,0 @@
|
||||
/* addRecord.h */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
#ifndef ADDRECORD_H
|
||||
#define ADDRECORD_H
|
||||
|
||||
#include <pv/channelProviderLocal.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
|
||||
class AddRecord;
|
||||
typedef std::tr1::shared_ptr<AddRecord> AddRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief Add another record in the same database.
|
||||
*
|
||||
* A record to add another record
|
||||
* It is meant to be used via a channelPutGet request.
|
||||
* The argument has one field: recordName.
|
||||
* The result has a field named status.
|
||||
*/
|
||||
class epicsShareClass AddRecord :
|
||||
public PVRecord
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(AddRecord);
|
||||
/**
|
||||
* Factory methods to create AddRecord.
|
||||
* @param recordName The name for the AddRecord.
|
||||
* @return A shared pointer to AddRecord..
|
||||
*/
|
||||
static AddRecordPtr create(
|
||||
std::string const & recordName);
|
||||
/**
|
||||
* standard init method required by PVRecord
|
||||
* @return true unless record name already exists.
|
||||
*/
|
||||
virtual bool init();
|
||||
/**
|
||||
* @brief Add the record specified by recordName.
|
||||
*/
|
||||
virtual void process();
|
||||
private:
|
||||
AddRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* ADDRECORD_H */
|
@ -1,89 +0,0 @@
|
||||
/* processRecord.h */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2019.06.07
|
||||
*/
|
||||
#ifndef PROCESSRECORD_H
|
||||
#define PROCESSRECORD_H
|
||||
|
||||
#include <map>
|
||||
#include <epicsThread.h>
|
||||
#include <pv/event.h>
|
||||
#include <pv/channelProviderLocal.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
typedef std::tr1::shared_ptr<epicsThread> EpicsThreadPtr;
|
||||
|
||||
class ProcessRecord;
|
||||
typedef std::tr1::shared_ptr<ProcessRecord> ProcessRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief Process another record in the same database.
|
||||
*
|
||||
* A record to process another record
|
||||
* It is meant to be used via a channelPutGet request.
|
||||
* The argument has one field: recordName.
|
||||
* The result has a field named status.
|
||||
*/
|
||||
class epicsShareClass ProcessRecord :
|
||||
public PVRecord,
|
||||
public epicsThreadRunable
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(ProcessRecord);
|
||||
/**
|
||||
* Factory methods to create ProcessRecord.
|
||||
* @param recordName The name for the ProcessRecord.
|
||||
* @param delay Delay time to wait between process requests.
|
||||
* @return A shared pointer to ProcessRecord.
|
||||
*/
|
||||
static ProcessRecordPtr create(
|
||||
std::string const & recordName,double delay);
|
||||
/**
|
||||
* standard init method required by PVRecord
|
||||
* @return true unless record name already exists.
|
||||
*/
|
||||
virtual bool init();
|
||||
/**
|
||||
* @brief Process the record specified by recordName.
|
||||
*/
|
||||
virtual void process();
|
||||
/**
|
||||
* @brief The run method for the thread.
|
||||
*/
|
||||
virtual void run();
|
||||
/**
|
||||
* @brief Start the thread
|
||||
*/
|
||||
void startThread();
|
||||
/**
|
||||
* @brief Stop the thread
|
||||
*/
|
||||
void stop();
|
||||
private:
|
||||
ProcessRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure,double delay);
|
||||
double delay;
|
||||
EpicsThreadPtr thread;
|
||||
epics::pvData::Event runStop;
|
||||
epics::pvData::Event runReturn;
|
||||
PVDatabasePtr pvDatabase;
|
||||
PVRecordMap pvRecordMap;
|
||||
epics::pvData::PVStringPtr pvCommand;
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
epics::pvData::Mutex mutex;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PROCESSRECORD_H */
|
@ -1,63 +0,0 @@
|
||||
/* removeRecord.h */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
#ifndef REMOVERECORD_H
|
||||
#define REMOVERECORD_H
|
||||
|
||||
#include <pv/channelProviderLocal.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
|
||||
class RemoveRecord;
|
||||
typedef std::tr1::shared_ptr<RemoveRecord> RemoveRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief Remove another record in the same database.
|
||||
*
|
||||
* A record to remove another record
|
||||
* It is meant to be used via a channelPutGet request.
|
||||
* The argument has one field: recordName.
|
||||
* The result has a field named status.
|
||||
*/
|
||||
class epicsShareClass RemoveRecord :
|
||||
public PVRecord
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(RemoveRecord);
|
||||
/**
|
||||
* Factory methods to create RemoveRecord.
|
||||
* @param recordName The name for the RemoveRecord.
|
||||
* @return A shared pointer to RemoveRecord..
|
||||
*/
|
||||
static RemoveRecordPtr create(
|
||||
std::string const & recordName);
|
||||
/**
|
||||
* standard init method required by PVRecord
|
||||
* @return true unless record name already exists.
|
||||
*/
|
||||
virtual bool init();
|
||||
/**
|
||||
* @brief Remove the record specified by recordName.
|
||||
*/
|
||||
virtual void process();
|
||||
private:
|
||||
RemoveRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* REMOVERECORD_H */
|
@ -1,66 +0,0 @@
|
||||
/* traceRecord.h */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
#ifndef TRACERECORD_H
|
||||
#define TRACERECORD_H
|
||||
|
||||
#include <pv/channelProviderLocal.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
|
||||
class TraceRecord;
|
||||
typedef std::tr1::shared_ptr<TraceRecord> TraceRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief Trace activity of PVRecord.
|
||||
*
|
||||
* A record to set the trace value for another record
|
||||
* It is meant to be used via a channelPutGet request.
|
||||
* The argument has two fields: recordName and level.
|
||||
* The result has a field named status.
|
||||
*/
|
||||
class epicsShareClass TraceRecord :
|
||||
public PVRecord
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(TraceRecord);
|
||||
/**
|
||||
* @brief Factory method to create TraceRecord.
|
||||
*
|
||||
* @param recordName The name for the TraceRecord.
|
||||
* @return A shared pointer to TraceRecord..
|
||||
*/
|
||||
static TraceRecordPtr create(
|
||||
std::string const & recordName);
|
||||
/**
|
||||
* standard init method required by PVRecord
|
||||
* @return true unless record name already exists.
|
||||
*/
|
||||
virtual bool init();
|
||||
/**
|
||||
* @brief Set the trace level for record specified by recordName.
|
||||
*/
|
||||
virtual void process();
|
||||
private:
|
||||
TraceRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVIntPtr pvLevel;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* TRACERECORD_H */
|
@ -2,20 +2,15 @@
|
||||
|
||||
SRC_DIRS += $(PVDATABASE_SRC)/special
|
||||
|
||||
#LIBSRCS += traceRecord.cpp
|
||||
#LIBSRCS += removeRecord.cpp
|
||||
#LIBSRCS += addRecord.cpp
|
||||
#LIBSRCS += processRecord.cpp
|
||||
DBD += traceRecordRegister.dbd
|
||||
DBD += removeRecordRegister.dbd
|
||||
DBD += addRecordRegister.dbd
|
||||
DBD += processRecordRegister.dbd
|
||||
|
||||
#DBD += traceRecordRegister.dbd
|
||||
#DBD += removeRecordRegister.dbd
|
||||
#DBD += addRecordRegister.dbd
|
||||
#DBD += processRecordRegister.dbd
|
||||
|
||||
#LIBSRCS += traceRecordRegister.cpp
|
||||
#LIBSRCS += removeRecordRegister.cpp
|
||||
#LIBSRCS += addRecordRegister.cpp
|
||||
#LIBSRCS += processRecordRegister.cpp
|
||||
LIBSRCS += traceRecordRegister.cpp
|
||||
LIBSRCS += removeRecordRegister.cpp
|
||||
LIBSRCS += addRecordRegister.cpp
|
||||
LIBSRCS += processRecordRegister.cpp
|
||||
|
||||
DBD += pvdbcrTraceRecordRegister.dbd
|
||||
DBD += pvdbcrRemoveRecordRegister.dbd
|
||||
|
@ -1,116 +0,0 @@
|
||||
/* addRecord.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvType.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/status.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/addRecord.h"
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
AddRecordPtr AddRecord::create(
|
||||
std::string const & recordName)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
addNestedStructure("argument")->
|
||||
add("recordName",pvString)->
|
||||
addNestedUnion("union") ->
|
||||
endNested()->
|
||||
endNested()->
|
||||
addNestedStructure("result") ->
|
||||
add("status",pvString) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
AddRecordPtr pvRecord(
|
||||
new AddRecord(recordName,pvStructure));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
AddRecord::AddRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure)
|
||||
: PVRecord(recordName,pvStructure)
|
||||
{
|
||||
}
|
||||
|
||||
bool AddRecord::init()
|
||||
{
|
||||
initPVRecord();
|
||||
PVStructurePtr pvStructure = getPVStructure();
|
||||
pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
|
||||
if(!pvRecordName) return false;
|
||||
pvResult = pvStructure->getSubField<PVString>("result.status");
|
||||
if(!pvResult) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AddRecord::process()
|
||||
{
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
string name = pvRecordName->get();
|
||||
PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
|
||||
if(pvRecord) {
|
||||
pvResult->put(name + " already exists");
|
||||
return;
|
||||
}
|
||||
PVUnionPtr pvUnion = getPVStructure()->getSubField<PVUnion>("argument.union");
|
||||
if(!pvUnion) {
|
||||
pvResult->put(name + " argument.union is NULL");
|
||||
return;
|
||||
}
|
||||
PVFieldPtr pvField(pvUnion->get());
|
||||
if(!pvField) {
|
||||
pvResult->put(name + " union has no value");
|
||||
return;
|
||||
}
|
||||
if(pvField->getField()->getType()!=epics::pvData::structure) {
|
||||
pvResult->put(name + " union most be a structure");
|
||||
return;
|
||||
}
|
||||
StructureConstPtr st = static_pointer_cast<const Structure>(pvField->getField());
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(st);
|
||||
PVRecordPtr pvRec = PVRecord::create(name,pvStructure);
|
||||
bool result = PVDatabase::getMaster()->addRecord(pvRec);
|
||||
if(result) {
|
||||
pvResult->put("success");
|
||||
} else {
|
||||
pvResult->put("failure");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}}
|
@ -5,11 +5,8 @@
|
||||
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.07.24
|
||||
* @date 2021.03.12
|
||||
*/
|
||||
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
#include <iocsh.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
@ -17,37 +14,137 @@
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
// The following must be the last include for code pvDatabase uses
|
||||
// The following must be the last include for code exampleLink uses
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/channelProviderLocal.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/addRecord.h"
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvDatabase;
|
||||
using namespace std;
|
||||
|
||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg *testArgs[] = {
|
||||
&testArg0};
|
||||
class AddRecord;
|
||||
typedef std::tr1::shared_ptr<AddRecord> AddRecordPtr;
|
||||
|
||||
static const iocshFuncDef addRecordFuncDef = {"addRecordCreate", 1,testArgs};
|
||||
|
||||
class epicsShareClass AddRecord :
|
||||
public PVRecord
|
||||
{
|
||||
private:
|
||||
AddRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
PVStringPtr pvRecordName;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
public:
|
||||
POINTER_DEFINITIONS(AddRecord);
|
||||
|
||||
static AddRecordPtr create(
|
||||
std::string const & recordName);
|
||||
virtual bool init();
|
||||
virtual void process();
|
||||
};
|
||||
|
||||
AddRecordPtr AddRecord::create(
|
||||
std::string const & recordName)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
addNestedStructure("argument")->
|
||||
add("recordName",pvString)->
|
||||
addNestedUnion("union") ->
|
||||
endNested()->
|
||||
endNested()->
|
||||
addNestedStructure("result") ->
|
||||
add("status",pvString) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
AddRecordPtr pvRecord(
|
||||
new AddRecord(recordName,pvStructure));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
AddRecord::AddRecord(
|
||||
std::string const & recordName,
|
||||
PVStructurePtr const & pvStructure)
|
||||
: PVRecord(recordName,pvStructure)
|
||||
{
|
||||
}
|
||||
|
||||
bool AddRecord::init()
|
||||
{
|
||||
initPVRecord();
|
||||
PVStructurePtr pvStructure = getPVStructure();
|
||||
pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
|
||||
if(!pvRecordName) return false;
|
||||
pvResult = pvStructure->getSubField<PVString>("result.status");
|
||||
if(!pvResult) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AddRecord::process()
|
||||
{
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
string name = pvRecordName->get();
|
||||
PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
|
||||
if(pvRecord) {
|
||||
pvResult->put(name + " already exists");
|
||||
return;
|
||||
}
|
||||
PVUnionPtr pvUnion = getPVStructure()->getSubField<PVUnion>("argument.union");
|
||||
if(!pvUnion) {
|
||||
pvResult->put(name + " argument.union is NULL");
|
||||
return;
|
||||
}
|
||||
PVFieldPtr pvField(pvUnion->get());
|
||||
if(!pvField) {
|
||||
pvResult->put(name + " union has no value");
|
||||
return;
|
||||
}
|
||||
if(pvField->getField()->getType()!=epics::pvData::structure) {
|
||||
pvResult->put(name + " union most be a structure");
|
||||
return;
|
||||
}
|
||||
StructureConstPtr st = static_pointer_cast<const Structure>(pvField->getField());
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(st);
|
||||
PVRecordPtr pvRec = PVRecord::create(name,pvStructure);
|
||||
bool result = PVDatabase::getMaster()->addRecord(pvRec);
|
||||
if(result) {
|
||||
pvResult->put("success");
|
||||
} else {
|
||||
pvResult->put("failure");
|
||||
}
|
||||
}
|
||||
|
||||
static const iocshArg arg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg *args[] = {&arg0};
|
||||
|
||||
static const iocshFuncDef addRecordFuncDef = {"addRecordCreate", 1,args};
|
||||
|
||||
static void addRecordCallFunc(const iocshArgBuf *args)
|
||||
{
|
||||
cerr << "DEPRECATED use pvdbcrAddRecord instead\n";
|
||||
char *recordName = args[0].sval;
|
||||
if(!recordName) {
|
||||
throw std::runtime_error("addRecordCreate invalid number of arguments");
|
||||
char *sval = args[0].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("addRecordCreate recordName not specified");
|
||||
}
|
||||
string recordName = string(sval);
|
||||
AddRecordPtr record = AddRecord::create(recordName);
|
||||
bool result = PVDatabase::getMaster()->addRecord(record);
|
||||
if(!result) cout << "recordname" << " not added" << endl;
|
||||
PVDatabasePtr master = PVDatabase::getMaster();
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||
}
|
||||
|
||||
static void addRecordRegister(void)
|
||||
static void addRecordCreateRegister(void)
|
||||
{
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
@ -57,5 +154,5 @@ static void addRecordRegister(void)
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
epicsExportRegistrar(addRecordRegister);
|
||||
epicsExportRegistrar(addRecordCreateRegister);
|
||||
}
|
||||
|
@ -1,166 +0,0 @@
|
||||
/* processRecord.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
#include <map>
|
||||
#include <epicsThread.h>
|
||||
#include <pv/event.h>
|
||||
#include <shareLib.h>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvType.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/status.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/processRecord.h"
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
ProcessRecordPtr ProcessRecord::create(
|
||||
std::string const & recordName,double delay)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
addNestedStructure("argument")->
|
||||
add("command",pvString)->
|
||||
add("recordName",pvString)->
|
||||
endNested()->
|
||||
addNestedStructure("result") ->
|
||||
add("status",pvString) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
ProcessRecordPtr pvRecord(
|
||||
new ProcessRecord(recordName,pvStructure,delay));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
void ProcessRecord::startThread()
|
||||
{
|
||||
thread = EpicsThreadPtr(new epicsThread(
|
||||
*this,
|
||||
"processRecord",
|
||||
epicsThreadGetStackSize(epicsThreadStackSmall),
|
||||
epicsThreadPriorityLow));
|
||||
thread->start();
|
||||
}
|
||||
|
||||
void ProcessRecord::stop()
|
||||
{
|
||||
runStop.signal();
|
||||
runReturn.wait();
|
||||
}
|
||||
|
||||
|
||||
ProcessRecord::ProcessRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure,double delay)
|
||||
: PVRecord(recordName,pvStructure),
|
||||
delay(delay),
|
||||
pvDatabase(PVDatabase::getMaster())
|
||||
{
|
||||
}
|
||||
|
||||
bool ProcessRecord::init()
|
||||
{
|
||||
initPVRecord();
|
||||
PVStructurePtr pvStructure = getPVStructure();
|
||||
pvCommand = pvStructure->getSubField<PVString>("argument.command");
|
||||
pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
|
||||
if(!pvRecordName) return false;
|
||||
pvResult = pvStructure->getSubField<PVString>("result.status");
|
||||
if(!pvResult) return false;
|
||||
startThread();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProcessRecord::process()
|
||||
{
|
||||
string recordName = pvRecordName->get();
|
||||
string command = pvCommand->get();
|
||||
if(command.compare("add")==0) {
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
std::map<std::string,PVRecordPtr>::iterator iter = pvRecordMap.find(recordName);
|
||||
if(iter!=pvRecordMap.end()) {
|
||||
pvResult->put(recordName + " already present");
|
||||
return;
|
||||
}
|
||||
PVRecordPtr pvRecord = pvDatabase->findRecord(recordName);
|
||||
if(!pvRecord) {
|
||||
pvResult->put(recordName + " not in pvDatabase");
|
||||
return;
|
||||
}
|
||||
pvRecordMap.insert(PVRecordMap::value_type(recordName,pvRecord));
|
||||
pvResult->put("success");
|
||||
return;
|
||||
} else if(command.compare("remove")==0) {
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
std::map<std::string,PVRecordPtr>::iterator iter = pvRecordMap.find(recordName);
|
||||
if(iter==pvRecordMap.end()) {
|
||||
pvResult->put(recordName + " not found");
|
||||
return;
|
||||
}
|
||||
pvRecordMap.erase(iter);
|
||||
pvResult->put("success");
|
||||
return;
|
||||
} else {
|
||||
pvResult->put(command + " not a valid command: only add and remove are valid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessRecord::run()
|
||||
{
|
||||
while(true) {
|
||||
if(runStop.tryWait()) {
|
||||
runReturn.signal();
|
||||
return;
|
||||
}
|
||||
if(delay>0.0) epicsThreadSleep(delay);
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
PVRecordMap::iterator iter;
|
||||
for(iter = pvRecordMap.begin(); iter!=pvRecordMap.end(); ++iter) {
|
||||
PVRecordPtr pvRecord = (*iter).second;
|
||||
pvRecord->lock();
|
||||
pvRecord->beginGroupPut();
|
||||
try {
|
||||
pvRecord->process();
|
||||
} catch (std::exception& ex) {
|
||||
std::cout << "record " << pvRecord->getRecordName() << "exception " << ex.what() << "\n";
|
||||
} catch (...) {
|
||||
std::cout<< "record " << pvRecord->getRecordName() << " process exception\n";
|
||||
}
|
||||
pvRecord->endGroupPut();
|
||||
pvRecord->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}}
|
@ -5,11 +5,12 @@
|
||||
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.07.24
|
||||
* @date 2021.03.12
|
||||
*/
|
||||
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
#include <epicsThread.h>
|
||||
#include <epicsGuard.h>
|
||||
#include <pv/event.h>
|
||||
#include <pv/lock.h>
|
||||
#include <iocsh.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
@ -17,38 +18,194 @@
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
// The following must be the last include for code pvDatabase uses
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/channelProviderLocal.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/processRecord.h"
|
||||
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvDatabase;
|
||||
using namespace std;
|
||||
|
||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg testArg1 = { "delay", iocshArgDouble };
|
||||
static const iocshArg *testArgs[] = {
|
||||
&testArg0,&testArg1};
|
||||
typedef std::tr1::shared_ptr<epicsThread> EpicsThreadPtr;
|
||||
class ProcessRecord;
|
||||
typedef std::tr1::shared_ptr<ProcessRecord> ProcessRecordPtr;
|
||||
|
||||
static const iocshFuncDef processRecordFuncDef = {"processRecordCreate", 2,testArgs};
|
||||
class epicsShareClass ProcessRecord :
|
||||
public PVRecord,
|
||||
public epicsThreadRunable
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(ProcessRecord);
|
||||
static ProcessRecordPtr create(
|
||||
std::string const & recordName,double delay);
|
||||
virtual bool init();
|
||||
virtual void process();
|
||||
virtual void run();
|
||||
void startThread();
|
||||
void stop();
|
||||
private:
|
||||
ProcessRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure,double delay);
|
||||
double delay;
|
||||
EpicsThreadPtr thread;
|
||||
epics::pvData::Event runStop;
|
||||
epics::pvData::Event runReturn;
|
||||
PVDatabasePtr pvDatabase;
|
||||
PVRecordMap pvRecordMap;
|
||||
epics::pvData::PVStringPtr pvCommand;
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
epics::pvData::Mutex mutex;
|
||||
};
|
||||
|
||||
ProcessRecordPtr ProcessRecord::create(
|
||||
std::string const & recordName,double delay)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
addNestedStructure("argument")->
|
||||
add("command",pvString)->
|
||||
add("recordName",pvString)->
|
||||
endNested()->
|
||||
addNestedStructure("result") ->
|
||||
add("status",pvString) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
ProcessRecordPtr pvRecord(
|
||||
new ProcessRecord(recordName,pvStructure,delay));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
void ProcessRecord::startThread()
|
||||
{
|
||||
thread = EpicsThreadPtr(new epicsThread(
|
||||
*this,
|
||||
"processRecord",
|
||||
epicsThreadGetStackSize(epicsThreadStackSmall),
|
||||
epicsThreadPriorityLow));
|
||||
thread->start();
|
||||
}
|
||||
|
||||
void ProcessRecord::stop()
|
||||
{
|
||||
runStop.signal();
|
||||
runReturn.wait();
|
||||
}
|
||||
|
||||
|
||||
ProcessRecord::ProcessRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure,double delay)
|
||||
: PVRecord(recordName,pvStructure),
|
||||
delay(delay),
|
||||
pvDatabase(PVDatabase::getMaster())
|
||||
{
|
||||
}
|
||||
|
||||
bool ProcessRecord::init()
|
||||
{
|
||||
initPVRecord();
|
||||
PVStructurePtr pvStructure = getPVStructure();
|
||||
pvCommand = pvStructure->getSubField<PVString>("argument.command");
|
||||
pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
|
||||
if(!pvRecordName) return false;
|
||||
pvResult = pvStructure->getSubField<PVString>("result.status");
|
||||
if(!pvResult) return false;
|
||||
startThread();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProcessRecord::process()
|
||||
{
|
||||
string recordName = pvRecordName->get();
|
||||
string command = pvCommand->get();
|
||||
if(command.compare("add")==0) {
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
std::map<std::string,PVRecordPtr>::iterator iter = pvRecordMap.find(recordName);
|
||||
if(iter!=pvRecordMap.end()) {
|
||||
pvResult->put(recordName + " already present");
|
||||
return;
|
||||
}
|
||||
PVRecordPtr pvRecord = pvDatabase->findRecord(recordName);
|
||||
if(!pvRecord) {
|
||||
pvResult->put(recordName + " not in pvDatabase");
|
||||
return;
|
||||
}
|
||||
pvRecordMap.insert(PVRecordMap::value_type(recordName,pvRecord));
|
||||
pvResult->put("success");
|
||||
return;
|
||||
} else if(command.compare("remove")==0) {
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
std::map<std::string,PVRecordPtr>::iterator iter = pvRecordMap.find(recordName);
|
||||
if(iter==pvRecordMap.end()) {
|
||||
pvResult->put(recordName + " not found");
|
||||
return;
|
||||
}
|
||||
pvRecordMap.erase(iter);
|
||||
pvResult->put("success");
|
||||
return;
|
||||
} else {
|
||||
pvResult->put(command + " not a valid command: only add and remove are valid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessRecord::run()
|
||||
{
|
||||
while(true) {
|
||||
if(runStop.tryWait()) {
|
||||
runReturn.signal();
|
||||
return;
|
||||
}
|
||||
if(delay>0.0) epicsThreadSleep(delay);
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
PVRecordMap::iterator iter;
|
||||
for(iter = pvRecordMap.begin(); iter!=pvRecordMap.end(); ++iter) {
|
||||
PVRecordPtr pvRecord = (*iter).second;
|
||||
pvRecord->lock();
|
||||
pvRecord->beginGroupPut();
|
||||
try {
|
||||
pvRecord->process();
|
||||
} catch (std::exception& ex) {
|
||||
std::cout << "record " << pvRecord->getRecordName() << "exception " << ex.what() << "\n";
|
||||
} catch (...) {
|
||||
std::cout<< "record " << pvRecord->getRecordName() << " process exception\n";
|
||||
}
|
||||
pvRecord->endGroupPut();
|
||||
pvRecord->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const iocshArg arg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg arg1 = { "delay", iocshArgDouble };
|
||||
static const iocshArg *args[] = {&arg0,&arg1};
|
||||
|
||||
static const iocshFuncDef processRecordFuncDef = {"processRecordCreate", 2,args};
|
||||
|
||||
static void processRecordCallFunc(const iocshArgBuf *args)
|
||||
{
|
||||
cerr << "DEPRECATED use pvdbcrProcessRecord instead\n";
|
||||
char *recordName = args[0].sval;
|
||||
if(!recordName) {
|
||||
throw std::runtime_error("processRecordCreate invalid number of arguments");
|
||||
char *sval = args[0].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("processRecord recordName not specified");
|
||||
}
|
||||
string recordName = string(sval);
|
||||
double delay = args[1].dval;
|
||||
if(delay<0.0) delay = 1.0;
|
||||
ProcessRecordPtr record = ProcessRecord::create(recordName,delay);
|
||||
bool result = PVDatabase::getMaster()->addRecord(record);
|
||||
if(!result) cout << "recordname" << " not added" << endl;
|
||||
PVDatabasePtr master = PVDatabase::getMaster();
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||
}
|
||||
|
||||
static void processRecordRegister(void)
|
||||
|
@ -1,91 +0,0 @@
|
||||
/* removeRecord.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvType.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/status.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/removeRecord.h"
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
RemoveRecordPtr RemoveRecord::create(
|
||||
std::string const & recordName)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
addNestedStructure("argument")->
|
||||
add("recordName",pvString)->
|
||||
endNested()->
|
||||
addNestedStructure("result") ->
|
||||
add("status",pvString) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
RemoveRecordPtr pvRecord(
|
||||
new RemoveRecord(recordName,pvStructure));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
RemoveRecord::RemoveRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure)
|
||||
: PVRecord(recordName,pvStructure)
|
||||
{
|
||||
}
|
||||
|
||||
bool RemoveRecord::init()
|
||||
{
|
||||
initPVRecord();
|
||||
PVStructurePtr pvStructure = getPVStructure();
|
||||
pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
|
||||
if(!pvRecordName) return false;
|
||||
pvResult = pvStructure->getSubField<PVString>("result.status");
|
||||
if(!pvResult) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RemoveRecord::process()
|
||||
{
|
||||
string name = pvRecordName->get();
|
||||
PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
|
||||
if(!pvRecord) {
|
||||
pvResult->put(name + " not found");
|
||||
return;
|
||||
}
|
||||
pvRecord->remove();
|
||||
pvResult->put("success");
|
||||
}
|
||||
|
||||
|
||||
}}
|
@ -5,12 +5,8 @@
|
||||
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.07.24
|
||||
* @date 2021.03.12
|
||||
*/
|
||||
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
#include <epicsThread.h>
|
||||
#include <iocsh.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
@ -18,34 +14,107 @@
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
// The following must be the last include for code pvDatabase uses
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/channelProviderLocal.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/removeRecord.h"
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvDatabase;
|
||||
using namespace std;
|
||||
|
||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg *testArgs[] = {
|
||||
&testArg0};
|
||||
class RemoveRecord;
|
||||
typedef std::tr1::shared_ptr<RemoveRecord> RemoveRecordPtr;
|
||||
|
||||
static const iocshFuncDef removeRecordFuncDef = {"removeRecordCreate", 1,testArgs};
|
||||
|
||||
class epicsShareClass RemoveRecord :
|
||||
public PVRecord
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(RemoveRecord);
|
||||
static RemoveRecordPtr create(
|
||||
std::string const & recordName);
|
||||
virtual bool init();
|
||||
virtual void process();
|
||||
private:
|
||||
RemoveRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
};
|
||||
|
||||
RemoveRecordPtr RemoveRecord::create(
|
||||
std::string const & recordName)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
addNestedStructure("argument")->
|
||||
add("recordName",pvString)->
|
||||
endNested()->
|
||||
addNestedStructure("result") ->
|
||||
add("status",pvString) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
RemoveRecordPtr pvRecord(
|
||||
new RemoveRecord(recordName,pvStructure));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
RemoveRecord::RemoveRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure)
|
||||
: PVRecord(recordName,pvStructure)
|
||||
{
|
||||
}
|
||||
|
||||
bool RemoveRecord::init()
|
||||
{
|
||||
initPVRecord();
|
||||
PVStructurePtr pvStructure = getPVStructure();
|
||||
pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
|
||||
if(!pvRecordName) return false;
|
||||
pvResult = pvStructure->getSubField<PVString>("result.status");
|
||||
if(!pvResult) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RemoveRecord::process()
|
||||
{
|
||||
string name = pvRecordName->get();
|
||||
PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
|
||||
if(!pvRecord) {
|
||||
pvResult->put(name + " not found");
|
||||
return;
|
||||
}
|
||||
pvRecord->remove();
|
||||
pvResult->put("success");
|
||||
}
|
||||
|
||||
static const iocshArg arg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg *args[] = {&arg0};
|
||||
|
||||
static const iocshFuncDef removeRecordFuncDef = {"removeRecordCreate", 1,args};
|
||||
|
||||
static void removeRecordCallFunc(const iocshArgBuf *args)
|
||||
{
|
||||
cerr << "DEPRECATED use pvdbcrRemoveRecord instead\n";
|
||||
char *recordName = args[0].sval;
|
||||
if(!recordName) {
|
||||
throw std::runtime_error("removeRecordCreate invalid number of arguments");
|
||||
char *sval = args[0].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("removeRecord recordName not specified");
|
||||
}
|
||||
string recordName = string(sval);
|
||||
RemoveRecordPtr record = RemoveRecord::create(recordName);
|
||||
bool result = PVDatabase::getMaster()->addRecord(record);
|
||||
if(!result) cout << "recordname" << " not added" << endl;
|
||||
PVDatabasePtr master = PVDatabase::getMaster();
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||
}
|
||||
|
||||
static void removeRecordRegister(void)
|
||||
|
@ -1,95 +0,0 @@
|
||||
/* traceRecord.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvType.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/status.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/channelProviderLocal.h"
|
||||
#include "pv/traceRecord.h"
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
TraceRecordPtr TraceRecord::create(
|
||||
std::string const & recordName)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
addNestedStructure("argument")->
|
||||
add("recordName",pvString)->
|
||||
add("level",pvInt)->
|
||||
endNested()->
|
||||
addNestedStructure("result") ->
|
||||
add("status",pvString) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
TraceRecordPtr pvRecord(
|
||||
new TraceRecord(recordName,pvStructure));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
TraceRecord::TraceRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure)
|
||||
: PVRecord(recordName,pvStructure)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TraceRecord::init()
|
||||
{
|
||||
initPVRecord();
|
||||
PVStructurePtr pvStructure = getPVStructure();
|
||||
pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
|
||||
if(!pvRecordName) return false;
|
||||
pvLevel = pvStructure->getSubField<PVInt>("argument.level");
|
||||
if(!pvLevel) return false;
|
||||
pvResult = pvStructure->getSubField<PVString>("result.status");
|
||||
if(!pvResult) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TraceRecord::process()
|
||||
{
|
||||
string name = pvRecordName->get();
|
||||
PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
|
||||
if(!pvRecord) {
|
||||
pvResult->put(name + " not found");
|
||||
return;
|
||||
}
|
||||
pvRecord->setTraceLevel(pvLevel->get());
|
||||
pvResult->put("success");
|
||||
}
|
||||
|
||||
|
||||
}}
|
@ -5,11 +5,8 @@
|
||||
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.07.24
|
||||
* @date 2021.03.12
|
||||
*/
|
||||
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
#include <iocsh.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
@ -17,34 +14,113 @@
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
// The following must be the last include for code pvDatabase uses
|
||||
// The following must be the last include
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/traceRecord.h"
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/channelProviderLocal.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvDatabase;
|
||||
using namespace std;
|
||||
|
||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg *testArgs[] = {
|
||||
&testArg0};
|
||||
class TraceRecord;
|
||||
typedef std::tr1::shared_ptr<TraceRecord> TraceRecordPtr;
|
||||
|
||||
static const iocshFuncDef traceRecordFuncDef = {"traceRecordCreate", 1,testArgs};
|
||||
class epicsShareClass TraceRecord :
|
||||
public PVRecord
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(TraceRecord);
|
||||
static TraceRecordPtr create(
|
||||
std::string const & recordName);
|
||||
virtual bool init();
|
||||
virtual void process();
|
||||
private:
|
||||
TraceRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVIntPtr pvLevel;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
};
|
||||
|
||||
TraceRecordPtr TraceRecord::create(
|
||||
std::string const & recordName)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
addNestedStructure("argument")->
|
||||
add("recordName",pvString)->
|
||||
add("level",pvInt)->
|
||||
endNested()->
|
||||
addNestedStructure("result") ->
|
||||
add("status",pvString) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
TraceRecordPtr pvRecord(
|
||||
new TraceRecord(recordName,pvStructure));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
TraceRecord::TraceRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure)
|
||||
: PVRecord(recordName,pvStructure)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TraceRecord::init()
|
||||
{
|
||||
initPVRecord();
|
||||
PVStructurePtr pvStructure = getPVStructure();
|
||||
pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
|
||||
if(!pvRecordName) return false;
|
||||
pvLevel = pvStructure->getSubField<PVInt>("argument.level");
|
||||
if(!pvLevel) return false;
|
||||
pvResult = pvStructure->getSubField<PVString>("result.status");
|
||||
if(!pvResult) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TraceRecord::process()
|
||||
{
|
||||
string name = pvRecordName->get();
|
||||
PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
|
||||
if(!pvRecord) {
|
||||
pvResult->put(name + " not found");
|
||||
return;
|
||||
}
|
||||
pvRecord->setTraceLevel(pvLevel->get());
|
||||
pvResult->put("success");
|
||||
}
|
||||
|
||||
static const iocshArg arg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg *args[] = {&arg0};
|
||||
|
||||
static const iocshFuncDef traceRecordFuncDef = {"traceRecordCreate", 1,args};
|
||||
|
||||
static void traceRecordCallFunc(const iocshArgBuf *args)
|
||||
{
|
||||
cerr << "DEPRECATED use pvdbcrTraceRecord instead\n";
|
||||
char *recordName = args[0].sval;
|
||||
if(!recordName) {
|
||||
throw std::runtime_error("traceRecordCreate invalid number of arguments");
|
||||
char *sval = args[0].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("traceRecord recordName not specified");
|
||||
}
|
||||
string recordName = string(sval);
|
||||
TraceRecordPtr record = TraceRecord::create(recordName);
|
||||
bool result = PVDatabase::getMaster()->addRecord(record);
|
||||
if(!result) cout << "recordname" << " not added" << endl;
|
||||
PVDatabasePtr master = PVDatabase::getMaster();
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||
}
|
||||
|
||||
static void traceRecordRegister(void)
|
||||
|
Reference in New Issue
Block a user