The following were made to all special pvdbcr modules
1) Much cleaner implementation. 2) pvdbSpecialRegister.dbd is new
This commit is contained in:
@ -28,11 +28,6 @@ INC += pv/removeRecord.h
|
|||||||
INC += pv/addRecord.h
|
INC += pv/addRecord.h
|
||||||
INC += pv/processRecord.h
|
INC += pv/processRecord.h
|
||||||
|
|
||||||
INC += pv/pvdbcrTraceRecord.h
|
|
||||||
INC += pv/pvdbcrRemoveRecord.h
|
|
||||||
INC += pv/pvdbcrAddRecord.h
|
|
||||||
INC += pv/pvdbcrProcessRecord.h
|
|
||||||
|
|
||||||
INC += pv/pvSupport.h
|
INC += pv/pvSupport.h
|
||||||
INC += pv/controlSupport.h
|
INC += pv/controlSupport.h
|
||||||
INC += pv/scalarAlarmSupport.h
|
INC += pv/scalarAlarmSupport.h
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
/* PvdbcrAddRecord.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 2021.03.12
|
|
||||||
*/
|
|
||||||
#ifndef PVDBCRADDRECORD_H
|
|
||||||
#define PVDBCRADDRECORD_H
|
|
||||||
|
|
||||||
#include <pv/channelProviderLocal.h>
|
|
||||||
|
|
||||||
#include <shareLib.h>
|
|
||||||
|
|
||||||
namespace epics { namespace pvDatabase {
|
|
||||||
|
|
||||||
|
|
||||||
class PvdbcrAddRecord;
|
|
||||||
typedef std::tr1::shared_ptr<PvdbcrAddRecord> PvdbcrAddRecordPtr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 PvdbcrAddRecord :
|
|
||||||
public PVRecord
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
POINTER_DEFINITIONS(PvdbcrAddRecord);
|
|
||||||
/**
|
|
||||||
* Factory methods to create PvdbcrAddRecord.
|
|
||||||
* @param recordName The name for the PvdbcrAddRecord.
|
|
||||||
* @return A shared pointer to PvdbcrAddRecord.
|
|
||||||
*/
|
|
||||||
static PvdbcrAddRecordPtr 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:
|
|
||||||
PvdbcrAddRecord(
|
|
||||||
std::string const & recordName,
|
|
||||||
epics::pvData::PVStructurePtr const & pvStructure);
|
|
||||||
epics::pvData::PVStringPtr pvRecordName;
|
|
||||||
epics::pvData::PVStringPtr pvResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
}}
|
|
||||||
|
|
||||||
#endif /* PVDBCRADDRECORD_H */
|
|
@ -1,89 +0,0 @@
|
|||||||
/* PvdbcrProcessRecord.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 2021.03.12
|
|
||||||
*/
|
|
||||||
#ifndef PVDBCRPROCESSRECORD_H
|
|
||||||
#define PVDBCRPROCESSRECORD_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 PvdbcrProcessRecord;
|
|
||||||
typedef std::tr1::shared_ptr<PvdbcrProcessRecord> PvdbcrProcessRecordPtr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 PvdbcrProcessRecord :
|
|
||||||
public PVRecord,
|
|
||||||
public epicsThreadRunable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
POINTER_DEFINITIONS(PvdbcrProcessRecord);
|
|
||||||
/**
|
|
||||||
* 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 PvdbcrProcessRecordPtr 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:
|
|
||||||
PvdbcrProcessRecord(
|
|
||||||
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 /* PVDBCRPROCESSRECORD_H */
|
|
@ -1,63 +0,0 @@
|
|||||||
/* PvdbcrRemoveRecord.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 2021.03.12
|
|
||||||
*/
|
|
||||||
#ifndef PVDBCRREMOVERECORD_H
|
|
||||||
#define PVDBCRREMOVERECORD_H
|
|
||||||
|
|
||||||
#include <pv/channelProviderLocal.h>
|
|
||||||
|
|
||||||
#include <shareLib.h>
|
|
||||||
|
|
||||||
namespace epics { namespace pvDatabase {
|
|
||||||
|
|
||||||
|
|
||||||
class PvdbcrRemoveRecord;
|
|
||||||
typedef std::tr1::shared_ptr<PvdbcrRemoveRecord> PvdbcrRemoveRecordPtr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 PvdbcrRemoveRecord :
|
|
||||||
public PVRecord
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
POINTER_DEFINITIONS(PvdbcrRemoveRecord);
|
|
||||||
/**
|
|
||||||
* Factory methods to create PvdbcrRemoveRecord.
|
|
||||||
* @param recordName The name for the PvdbcrRemoveRecord.
|
|
||||||
* @return A shared pointer to PvdbcrRemoveRecord..
|
|
||||||
*/
|
|
||||||
static PvdbcrRemoveRecordPtr 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:
|
|
||||||
PvdbcrRemoveRecord(
|
|
||||||
std::string const & recordName,
|
|
||||||
epics::pvData::PVStructurePtr const & pvStructure);
|
|
||||||
epics::pvData::PVStringPtr pvRecordName;
|
|
||||||
epics::pvData::PVStringPtr pvResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
}}
|
|
||||||
|
|
||||||
#endif /* PVDBCRREMOVERECORD_H */
|
|
@ -1,66 +0,0 @@
|
|||||||
/* PvdbcrTraceRecord.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 2021.03.12
|
|
||||||
*/
|
|
||||||
#ifndef PVDBCRTRACERECORD_H
|
|
||||||
#define PVDBCRTRACERECORD_H
|
|
||||||
|
|
||||||
#include <pv/channelProviderLocal.h>
|
|
||||||
|
|
||||||
#include <shareLib.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace epics { namespace pvDatabase {
|
|
||||||
|
|
||||||
|
|
||||||
class PvdbcrTraceRecord;
|
|
||||||
typedef std::tr1::shared_ptr<PvdbcrTraceRecord> PvdbcrTraceRecordPtr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 PvdbcrTraceRecord :
|
|
||||||
public PVRecord
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
POINTER_DEFINITIONS(PvdbcrTraceRecord);
|
|
||||||
/**
|
|
||||||
* @brief Factory method to create PvdbcrTraceRecord.
|
|
||||||
*
|
|
||||||
* @param recordName The name for the PvdbcrTraceRecord.
|
|
||||||
* @return A shared pointer to PvdbcrTraceRecord.
|
|
||||||
*/
|
|
||||||
static PvdbcrTraceRecordPtr 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:
|
|
||||||
PvdbcrTraceRecord(
|
|
||||||
std::string const & recordName,
|
|
||||||
epics::pvData::PVStructurePtr const & pvStructure);
|
|
||||||
epics::pvData::PVStringPtr pvRecordName;
|
|
||||||
epics::pvData::PVIntPtr pvLevel;
|
|
||||||
epics::pvData::PVStringPtr pvResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
}}
|
|
||||||
|
|
||||||
#endif /* PVDBCRTRACERECORD_H */
|
|
@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
SRC_DIRS += $(PVDATABASE_SRC)/special
|
SRC_DIRS += $(PVDATABASE_SRC)/special
|
||||||
|
|
||||||
LIBSRCS += pvdbcrTraceRecord.cpp
|
|
||||||
LIBSRCS += pvdbcrRemoveRecord.cpp
|
|
||||||
LIBSRCS += pvdbcrAddRecord.cpp
|
|
||||||
LIBSRCS += pvdbcrProcessRecord.cpp
|
|
||||||
|
|
||||||
DBD += pvdbcrTraceRecordRegister.dbd
|
DBD += pvdbcrTraceRecordRegister.dbd
|
||||||
DBD += pvdbcrRemoveRecordRegister.dbd
|
DBD += pvdbcrRemoveRecordRegister.dbd
|
||||||
@ -13,6 +9,7 @@ DBD += pvdbcrAddRecordRegister.dbd
|
|||||||
DBD += pvdbcrProcessRecordRegister.dbd
|
DBD += pvdbcrProcessRecordRegister.dbd
|
||||||
DBD += pvdbcrScalarRegister.dbd
|
DBD += pvdbcrScalarRegister.dbd
|
||||||
DBD += pvdbcrScalarArrayRegister.dbd
|
DBD += pvdbcrScalarArrayRegister.dbd
|
||||||
|
DBD += pvdbSpecialRegister.dbd
|
||||||
|
|
||||||
LIBSRCS += pvdbcrTraceRecordRegister.cpp
|
LIBSRCS += pvdbcrTraceRecordRegister.cpp
|
||||||
LIBSRCS += pvdbcrRemoveRecordRegister.cpp
|
LIBSRCS += pvdbcrRemoveRecordRegister.cpp
|
||||||
|
6
src/special/pvdbSpecialRegister.dbd
Normal file
6
src/special/pvdbSpecialRegister.dbd
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
include "pvdbcrAddRecordRegister.dbd"
|
||||||
|
include "pvdbcrRemoveRecordRegister.dbd"
|
||||||
|
include "pvdbcrProcessRecordRegister.dbd"
|
||||||
|
include "pvdbcrTraceRecordRegister.dbd"
|
||||||
|
include "pvdbcrScalarRegister.dbd"
|
||||||
|
include "pvdbcrScalarArrayRegister.dbd"
|
@ -1,116 +0,0 @@
|
|||||||
/* pvdbcrAddRecord.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 2021.03.12
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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/pvdbcrAddRecord.h"
|
|
||||||
|
|
||||||
using std::tr1::static_pointer_cast;
|
|
||||||
using namespace epics::pvData;
|
|
||||||
using namespace epics::pvAccess;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace epics { namespace pvDatabase {
|
|
||||||
PvdbcrAddRecordPtr PvdbcrAddRecord::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);
|
|
||||||
PvdbcrAddRecordPtr pvRecord(
|
|
||||||
new PvdbcrAddRecord(recordName,pvStructure));
|
|
||||||
if(!pvRecord->init()) pvRecord.reset();
|
|
||||||
return pvRecord;
|
|
||||||
}
|
|
||||||
|
|
||||||
PvdbcrAddRecord::PvdbcrAddRecord(
|
|
||||||
std::string const & recordName,
|
|
||||||
epics::pvData::PVStructurePtr const & pvStructure)
|
|
||||||
: PVRecord(recordName,pvStructure)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PvdbcrAddRecord::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 PvdbcrAddRecord::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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}}
|
|
@ -7,47 +7,148 @@
|
|||||||
* @author mrk
|
* @author mrk
|
||||||
* @date 2021.03.12
|
* @date 2021.03.12
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Author: Marty Kraimer */
|
|
||||||
#include <epicsThread.h>
|
|
||||||
#include <iocsh.h>
|
#include <iocsh.h>
|
||||||
#include <pv/event.h>
|
#include <pv/standardField.h>
|
||||||
#include <pv/pvAccess.h>
|
#include <pv/standardPVField.h>
|
||||||
#include <pv/serverContext.h>
|
#include <pv/timeStamp.h>
|
||||||
#include <pv/pvData.h>
|
|
||||||
#include <pv/pvTimeStamp.h>
|
#include <pv/pvTimeStamp.h>
|
||||||
#include <pv/rpcService.h>
|
#include <pv/alarm.h>
|
||||||
|
#include <pv/pvAlarm.h>
|
||||||
|
#include <pv/pvDatabase.h>
|
||||||
|
#include <pv/pvaClient.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>
|
#include <epicsExport.h>
|
||||||
#define epicsExportSharedSymbols
|
#define epicsExportSharedSymbols
|
||||||
#include "pv/pvStructureCopy.h"
|
|
||||||
#include "pv/pvDatabase.h"
|
|
||||||
#include "pv/pvdbcrAddRecord.h"
|
|
||||||
|
|
||||||
using namespace epics::pvData;
|
using namespace epics::pvData;
|
||||||
using namespace epics::pvAccess;
|
using namespace epics::pvAccess;
|
||||||
using namespace epics::pvDatabase;
|
using namespace epics::pvDatabase;
|
||||||
|
using namespace epics::pvaClient;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
class PvdbcrAddRecord;
|
||||||
static const iocshArg testArg1 = { "asLevel", iocshArgInt };
|
typedef std::tr1::shared_ptr<PvdbcrAddRecord> PvdbcrAddRecordPtr;
|
||||||
static const iocshArg *testArgs[] = {&testArg0,&testArg1};
|
|
||||||
|
|
||||||
static const iocshFuncDef pvdbcrAddRecordFuncDef = {"pvdbcrAddRecord", 2,testArgs};
|
|
||||||
|
class epicsShareClass PvdbcrAddRecord :
|
||||||
|
public PVRecord
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
PvdbcrAddRecord(
|
||||||
|
std::string const & recordName,
|
||||||
|
epics::pvData::PVStructurePtr const & pvStructure);
|
||||||
|
PVStringPtr pvRecordName;
|
||||||
|
epics::pvData::PVStringPtr pvResult;
|
||||||
|
public:
|
||||||
|
POINTER_DEFINITIONS(PvdbcrAddRecord);
|
||||||
|
|
||||||
|
static PvdbcrAddRecordPtr create(
|
||||||
|
std::string const & recordName);
|
||||||
|
virtual bool init();
|
||||||
|
virtual void process();
|
||||||
|
};
|
||||||
|
|
||||||
|
PvdbcrAddRecordPtr PvdbcrAddRecord::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);
|
||||||
|
PvdbcrAddRecordPtr pvRecord(
|
||||||
|
new PvdbcrAddRecord(recordName,pvStructure));
|
||||||
|
if(!pvRecord->init()) pvRecord.reset();
|
||||||
|
return pvRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
PvdbcrAddRecord::PvdbcrAddRecord(
|
||||||
|
std::string const & recordName,
|
||||||
|
PVStructurePtr const & pvStructure)
|
||||||
|
: PVRecord(recordName,pvStructure)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PvdbcrAddRecord::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 PvdbcrAddRecord::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 arg1 = { "asLevel", iocshArgInt };
|
||||||
|
static const iocshArg arg2 = { "asGroup", iocshArgString };
|
||||||
|
static const iocshArg *args[] = {&arg0,&arg1,&arg2};
|
||||||
|
|
||||||
|
static const iocshFuncDef pvdbcrAddRecordFuncDef = {"pvdbcrAddRecord", 3,args};
|
||||||
|
|
||||||
static void pvdbcrAddRecordCallFunc(const iocshArgBuf *args)
|
static void pvdbcrAddRecordCallFunc(const iocshArgBuf *args)
|
||||||
{
|
{
|
||||||
char *recordName = args[0].sval;
|
char *sval = args[0].sval;
|
||||||
if(!recordName) {
|
if(!sval) {
|
||||||
throw std::runtime_error("pvdbcrAddRecord invalid number of arguments");
|
throw std::runtime_error("pvdbcrAddRecord recordName not specified");
|
||||||
}
|
}
|
||||||
|
string recordName = string(sval);
|
||||||
int asLevel = args[1].ival;
|
int asLevel = args[1].ival;
|
||||||
|
string asGroup("DEFAULT");
|
||||||
|
sval = args[2].sval;
|
||||||
|
if(sval) {
|
||||||
|
asGroup = string(sval);
|
||||||
|
}
|
||||||
PvdbcrAddRecordPtr record = PvdbcrAddRecord::create(recordName);
|
PvdbcrAddRecordPtr record = PvdbcrAddRecord::create(recordName);
|
||||||
record->setAsLevel(asLevel);
|
record->setAsLevel(asLevel);
|
||||||
bool result = PVDatabase::getMaster()->addRecord(record);
|
record->setAsGroup(asGroup);
|
||||||
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 pvdbcrAddRecordRegister(void)
|
static void pvdbcrAddRecordRegister(void)
|
||||||
|
@ -1,166 +0,0 @@
|
|||||||
/* pvdbcrProcessRecord.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 2021.03.12
|
|
||||||
*/
|
|
||||||
#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/pvdbcrProcessRecord.h"
|
|
||||||
|
|
||||||
using std::tr1::static_pointer_cast;
|
|
||||||
using namespace epics::pvData;
|
|
||||||
using namespace epics::pvAccess;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace epics { namespace pvDatabase {
|
|
||||||
|
|
||||||
PvdbcrProcessRecordPtr PvdbcrProcessRecord::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);
|
|
||||||
PvdbcrProcessRecordPtr pvRecord(
|
|
||||||
new PvdbcrProcessRecord(recordName,pvStructure,delay));
|
|
||||||
if(!pvRecord->init()) pvRecord.reset();
|
|
||||||
return pvRecord;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PvdbcrProcessRecord::startThread()
|
|
||||||
{
|
|
||||||
thread = EpicsThreadPtr(new epicsThread(
|
|
||||||
*this,
|
|
||||||
"processRecord",
|
|
||||||
epicsThreadGetStackSize(epicsThreadStackSmall),
|
|
||||||
epicsThreadPriorityLow));
|
|
||||||
thread->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PvdbcrProcessRecord::stop()
|
|
||||||
{
|
|
||||||
runStop.signal();
|
|
||||||
runReturn.wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PvdbcrProcessRecord::PvdbcrProcessRecord(
|
|
||||||
std::string const & recordName,
|
|
||||||
epics::pvData::PVStructurePtr const & pvStructure,double delay)
|
|
||||||
: PVRecord(recordName,pvStructure),
|
|
||||||
delay(delay),
|
|
||||||
pvDatabase(PVDatabase::getMaster())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PvdbcrProcessRecord::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 PvdbcrProcessRecord::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 PvdbcrProcessRecord::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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}}
|
|
@ -7,52 +7,212 @@
|
|||||||
* @author mrk
|
* @author mrk
|
||||||
* @date 2021.03.12
|
* @date 2021.03.12
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Author: Marty Kraimer */
|
|
||||||
|
|
||||||
#include <epicsThread.h>
|
#include <epicsThread.h>
|
||||||
#include <iocsh.h>
|
|
||||||
#include <pv/event.h>
|
#include <pv/event.h>
|
||||||
#include <pv/pvAccess.h>
|
#include <iocsh.h>
|
||||||
#include <pv/serverContext.h>
|
#include <pv/standardField.h>
|
||||||
#include <pv/pvData.h>
|
#include <pv/standardPVField.h>
|
||||||
|
#include <pv/timeStamp.h>
|
||||||
#include <pv/pvTimeStamp.h>
|
#include <pv/pvTimeStamp.h>
|
||||||
#include <pv/rpcService.h>
|
#include <pv/alarm.h>
|
||||||
|
#include <pv/pvAlarm.h>
|
||||||
|
#include <pv/pvDatabase.h>
|
||||||
|
#include <pv/pvaClient.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>
|
#include <epicsExport.h>
|
||||||
#define epicsExportSharedSymbols
|
#define epicsExportSharedSymbols
|
||||||
#include "pv/pvStructureCopy.h"
|
|
||||||
#include "pv/pvDatabase.h"
|
|
||||||
#include "pv/pvdbcrProcessRecord.h"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace epics::pvData;
|
using namespace epics::pvData;
|
||||||
using namespace epics::pvAccess;
|
using namespace epics::pvAccess;
|
||||||
using namespace epics::pvDatabase;
|
using namespace epics::pvDatabase;
|
||||||
|
using namespace epics::pvaClient;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
typedef std::tr1::shared_ptr<epicsThread> EpicsThreadPtr;
|
||||||
static const iocshArg testArg1 = { "delay", iocshArgDouble };
|
class PvdbcrProcessRecord;
|
||||||
static const iocshArg testArg2 = { "asLevel", iocshArgInt };
|
typedef std::tr1::shared_ptr<PvdbcrProcessRecord> PvdbcrProcessRecordPtr;
|
||||||
static const iocshArg *testArgs[] = {&testArg0,&testArg1,&testArg2};
|
|
||||||
|
|
||||||
static const iocshFuncDef pvdbcrProcessRecordFuncDef = {"pvdbcrProcessRecord", 3,testArgs};
|
class epicsShareClass PvdbcrProcessRecord :
|
||||||
|
public PVRecord,
|
||||||
|
public epicsThreadRunable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
POINTER_DEFINITIONS(PvdbcrProcessRecord);
|
||||||
|
static PvdbcrProcessRecordPtr create(
|
||||||
|
std::string const & recordName,double delay);
|
||||||
|
virtual bool init();
|
||||||
|
virtual void process();
|
||||||
|
virtual void run();
|
||||||
|
void startThread();
|
||||||
|
void stop();
|
||||||
|
private:
|
||||||
|
PvdbcrProcessRecord(
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
PvdbcrProcessRecordPtr PvdbcrProcessRecord::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);
|
||||||
|
PvdbcrProcessRecordPtr pvRecord(
|
||||||
|
new PvdbcrProcessRecord(recordName,pvStructure,delay));
|
||||||
|
if(!pvRecord->init()) pvRecord.reset();
|
||||||
|
return pvRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PvdbcrProcessRecord::startThread()
|
||||||
|
{
|
||||||
|
thread = EpicsThreadPtr(new epicsThread(
|
||||||
|
*this,
|
||||||
|
"processRecord",
|
||||||
|
epicsThreadGetStackSize(epicsThreadStackSmall),
|
||||||
|
epicsThreadPriorityLow));
|
||||||
|
thread->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PvdbcrProcessRecord::stop()
|
||||||
|
{
|
||||||
|
runStop.signal();
|
||||||
|
runReturn.wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PvdbcrProcessRecord::PvdbcrProcessRecord(
|
||||||
|
std::string const & recordName,
|
||||||
|
epics::pvData::PVStructurePtr const & pvStructure,double delay)
|
||||||
|
: PVRecord(recordName,pvStructure),
|
||||||
|
delay(delay),
|
||||||
|
pvDatabase(PVDatabase::getMaster())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PvdbcrProcessRecord::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 PvdbcrProcessRecord::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 PvdbcrProcessRecord::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 arg2 = { "asLevel", iocshArgInt };
|
||||||
|
static const iocshArg arg3 = { "asGroup", iocshArgString };
|
||||||
|
static const iocshArg *args[] = {&arg0,&arg1,&arg2,&arg3};
|
||||||
|
|
||||||
|
static const iocshFuncDef pvdbcrProcessRecordFuncDef = {"pvdbcrProcessRecord", 4,args};
|
||||||
|
|
||||||
static void pvdbcrProcessRecordCallFunc(const iocshArgBuf *args)
|
static void pvdbcrProcessRecordCallFunc(const iocshArgBuf *args)
|
||||||
{
|
{
|
||||||
char *recordName = args[0].sval;
|
char *sval = args[0].sval;
|
||||||
if(!recordName) {
|
if(!sval) {
|
||||||
throw std::runtime_error("pvdbcrProcessRecordCreate invalid number of arguments");
|
throw std::runtime_error("pvdbcrProcessRecord recordName not specified");
|
||||||
}
|
}
|
||||||
|
string recordName = string(sval);
|
||||||
double delay = args[1].dval;
|
double delay = args[1].dval;
|
||||||
int asLevel = args[2].ival;
|
|
||||||
if(delay<0.0) delay = 1.0;
|
if(delay<0.0) delay = 1.0;
|
||||||
|
int asLevel = args[2].ival;
|
||||||
|
string asGroup("DEFAULT");
|
||||||
|
sval = args[3].sval;
|
||||||
|
if(sval) {
|
||||||
|
asGroup = string(sval);
|
||||||
|
}
|
||||||
PvdbcrProcessRecordPtr record = PvdbcrProcessRecord::create(recordName,delay);
|
PvdbcrProcessRecordPtr record = PvdbcrProcessRecord::create(recordName,delay);
|
||||||
record->setAsLevel(asLevel);
|
record->setAsLevel(asLevel);
|
||||||
bool result = PVDatabase::getMaster()->addRecord(record);
|
record->setAsGroup(asGroup);
|
||||||
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 pvdbcrProcessRecordRegister(void)
|
static void pvdbcrProcessRecordRegister(void)
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
/* pvdbcrRemoveRecord.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 2021.03.12
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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/pvdbcrRemoveRecord.h"
|
|
||||||
|
|
||||||
using std::tr1::static_pointer_cast;
|
|
||||||
using namespace epics::pvData;
|
|
||||||
using namespace epics::pvAccess;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace epics { namespace pvDatabase {
|
|
||||||
|
|
||||||
PvdbcrRemoveRecordPtr PvdbcrRemoveRecord::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);
|
|
||||||
PvdbcrRemoveRecordPtr pvRecord(
|
|
||||||
new PvdbcrRemoveRecord(recordName,pvStructure));
|
|
||||||
if(!pvRecord->init()) pvRecord.reset();
|
|
||||||
return pvRecord;
|
|
||||||
}
|
|
||||||
|
|
||||||
PvdbcrRemoveRecord::PvdbcrRemoveRecord(
|
|
||||||
std::string const & recordName,
|
|
||||||
epics::pvData::PVStructurePtr const & pvStructure)
|
|
||||||
: PVRecord(recordName,pvStructure)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PvdbcrRemoveRecord::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 PvdbcrRemoveRecord::process()
|
|
||||||
{
|
|
||||||
string name = pvRecordName->get();
|
|
||||||
PVRecordPtr pvRecord = PVDatabase::getMaster()->findRecord(name);
|
|
||||||
if(!pvRecord) {
|
|
||||||
pvResult->put(name + " not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pvRecord->remove();
|
|
||||||
pvResult->put("success");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}}
|
|
@ -7,47 +7,123 @@
|
|||||||
* @author mrk
|
* @author mrk
|
||||||
* @date 2021.03.12
|
* @date 2021.03.12
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Author: Marty Kraimer */
|
|
||||||
#include <epicsThread.h>
|
|
||||||
#include <iocsh.h>
|
#include <iocsh.h>
|
||||||
#include <pv/event.h>
|
#include <pv/standardField.h>
|
||||||
#include <pv/pvAccess.h>
|
#include <pv/standardPVField.h>
|
||||||
#include <pv/serverContext.h>
|
#include <pv/timeStamp.h>
|
||||||
#include <pv/pvData.h>
|
|
||||||
#include <pv/pvTimeStamp.h>
|
#include <pv/pvTimeStamp.h>
|
||||||
#include <pv/rpcService.h>
|
#include <pv/alarm.h>
|
||||||
|
#include <pv/pvAlarm.h>
|
||||||
|
#include <pv/pvDatabase.h>
|
||||||
|
#include <pv/pvaClient.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>
|
#include <epicsExport.h>
|
||||||
#define epicsExportSharedSymbols
|
#define epicsExportSharedSymbols
|
||||||
#include "pv/pvStructureCopy.h"
|
|
||||||
#include "pv/pvDatabase.h"
|
|
||||||
#include "pv/pvdbcrRemoveRecord.h"
|
|
||||||
|
|
||||||
using namespace epics::pvData;
|
using namespace epics::pvData;
|
||||||
using namespace epics::pvAccess;
|
using namespace epics::pvAccess;
|
||||||
using namespace epics::pvDatabase;
|
using namespace epics::pvDatabase;
|
||||||
|
using namespace epics::pvaClient;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
class PvdbcrRemoveRecord;
|
||||||
static const iocshArg testArg1 = { "asLevel", iocshArgInt };
|
typedef std::tr1::shared_ptr<PvdbcrRemoveRecord> PvdbcrRemoveRecordPtr;
|
||||||
static const iocshArg *testArgs[] = {&testArg0,&testArg1};
|
|
||||||
|
|
||||||
static const iocshFuncDef pvdbcrRemoveRecordFuncDef = {"pvdbcrRemoveRecord", 2,testArgs};
|
|
||||||
|
class epicsShareClass PvdbcrRemoveRecord :
|
||||||
|
public PVRecord
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
POINTER_DEFINITIONS(PvdbcrRemoveRecord);
|
||||||
|
static PvdbcrRemoveRecordPtr create(
|
||||||
|
std::string const & recordName);
|
||||||
|
virtual bool init();
|
||||||
|
virtual void process();
|
||||||
|
private:
|
||||||
|
PvdbcrRemoveRecord(
|
||||||
|
std::string const & recordName,
|
||||||
|
epics::pvData::PVStructurePtr const & pvStructure);
|
||||||
|
epics::pvData::PVStringPtr pvRecordName;
|
||||||
|
epics::pvData::PVStringPtr pvResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
PvdbcrRemoveRecordPtr PvdbcrRemoveRecord::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);
|
||||||
|
PvdbcrRemoveRecordPtr pvRecord(
|
||||||
|
new PvdbcrRemoveRecord(recordName,pvStructure));
|
||||||
|
if(!pvRecord->init()) pvRecord.reset();
|
||||||
|
return pvRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
PvdbcrRemoveRecord::PvdbcrRemoveRecord(
|
||||||
|
std::string const & recordName,
|
||||||
|
epics::pvData::PVStructurePtr const & pvStructure)
|
||||||
|
: PVRecord(recordName,pvStructure)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PvdbcrRemoveRecord::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 PvdbcrRemoveRecord::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 arg1 = { "asLevel", iocshArgInt };
|
||||||
|
static const iocshArg arg2 = { "asGroup", iocshArgString };
|
||||||
|
static const iocshArg *args[] = {&arg0,&arg1,&arg2};
|
||||||
|
|
||||||
|
static const iocshFuncDef pvdbcrRemoveRecordFuncDef = {"pvdbcrRemoveRecord", 3,args};
|
||||||
|
|
||||||
static void pvdbcrRemoveRecordCallFunc(const iocshArgBuf *args)
|
static void pvdbcrRemoveRecordCallFunc(const iocshArgBuf *args)
|
||||||
{
|
{
|
||||||
char *recordName = args[0].sval;
|
char *sval = args[0].sval;
|
||||||
if(!recordName) {
|
if(!sval) {
|
||||||
throw std::runtime_error("pvdbcrRemoveRecordCreate invalid number of arguments");
|
throw std::runtime_error("pvdbcrRemoveRecord recordName not specified");
|
||||||
}
|
}
|
||||||
|
string recordName = string(sval);
|
||||||
int asLevel = args[1].ival;
|
int asLevel = args[1].ival;
|
||||||
|
string asGroup("DEFAULT");
|
||||||
|
sval = args[2].sval;
|
||||||
|
if(sval) {
|
||||||
|
asGroup = string(sval);
|
||||||
|
}
|
||||||
PvdbcrRemoveRecordPtr record = PvdbcrRemoveRecord::create(recordName);
|
PvdbcrRemoveRecordPtr record = PvdbcrRemoveRecord::create(recordName);
|
||||||
record->setAsLevel(asLevel);
|
record->setAsLevel(asLevel);
|
||||||
bool result = PVDatabase::getMaster()->addRecord(record);
|
record->setAsGroup(asGroup);
|
||||||
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 pvdbcrRemoveRecordRegister(void)
|
static void pvdbcrRemoveRecordRegister(void)
|
||||||
|
@ -10,35 +10,24 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Author: Marty Kraimer */
|
/* Author: Marty Kraimer */
|
||||||
|
|
||||||
#include <epicsThread.h>
|
|
||||||
#include <iocsh.h>
|
#include <iocsh.h>
|
||||||
#include <pv/event.h>
|
#include <pv/standardField.h>
|
||||||
#include <pv/pvAccess.h>
|
#include <pv/pvDatabase.h>
|
||||||
#include <pv/serverContext.h>
|
// The following must be the last include for code exampleLink uses
|
||||||
#include <pv/pvData.h>
|
|
||||||
#include <pv/pvTimeStamp.h>
|
|
||||||
#include <pv/rpcService.h>
|
|
||||||
#include <pv/ntscalarArray.h>
|
|
||||||
|
|
||||||
// The following must be the last include for code pvDatabase uses
|
|
||||||
#include <epicsExport.h>
|
#include <epicsExport.h>
|
||||||
#define epicsExportSharedSymbols
|
#define epicsExportSharedSymbols
|
||||||
#include "pv/pvStructureCopy.h"
|
|
||||||
#include "pv/pvDatabase.h"
|
|
||||||
|
|
||||||
using namespace epics::pvData;
|
using namespace epics::pvData;
|
||||||
using namespace epics::nt;
|
|
||||||
using namespace epics::pvAccess;
|
|
||||||
using namespace epics::pvDatabase;
|
using namespace epics::pvDatabase;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
static const iocshArg arg0 = { "recordName", iocshArgString };
|
||||||
static const iocshArg testArg1 = { "scalarType", iocshArgString };
|
static const iocshArg arg1 = { "scalarType", iocshArgString };
|
||||||
static const iocshArg testArg2 = { "asLevel", iocshArgInt };
|
static const iocshArg arg2 = { "asLevel", iocshArgInt };
|
||||||
static const iocshArg *testArgs[] = {&testArg0,&testArg1,&testArg2};
|
static const iocshArg arg3 = { "asGroup", iocshArgString };
|
||||||
|
static const iocshArg *args[] = {&arg0,&arg1,&arg2,&arg3};
|
||||||
|
|
||||||
static const iocshFuncDef pvdbcrScalarArrayFuncDef = {"pvdbcrScalarArray", 3,testArgs};
|
static const iocshFuncDef pvdbcrScalarArrayFuncDef = {"pvdbcrScalarArray", 4,args};
|
||||||
|
|
||||||
static void pvdbcrScalarArrayCallFunc(const iocshArgBuf *args)
|
static void pvdbcrScalarArrayCallFunc(const iocshArgBuf *args)
|
||||||
{
|
{
|
||||||
@ -53,22 +42,27 @@ static void pvdbcrScalarArrayCallFunc(const iocshArgBuf *args)
|
|||||||
}
|
}
|
||||||
string scalarType = string(sval);
|
string scalarType = string(sval);
|
||||||
int asLevel = args[2].ival;
|
int asLevel = args[2].ival;
|
||||||
try {
|
string asGroup("DEFAULT");
|
||||||
|
sval = args[3].sval;
|
||||||
|
if(sval) {
|
||||||
|
asGroup = string(sval);
|
||||||
|
}
|
||||||
ScalarType st = epics::pvData::ScalarTypeFunc::getScalarType(scalarType);
|
ScalarType st = epics::pvData::ScalarTypeFunc::getScalarType(scalarType);
|
||||||
NTScalarArrayBuilderPtr ntScalarArrayBuilder = NTScalarArray::createBuilder();
|
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||||
PVStructurePtr pvStructure = ntScalarArrayBuilder->
|
StandardFieldPtr standardField = getStandardField();
|
||||||
value(st)->
|
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||||
addAlarm()->
|
StructureConstPtr top = fieldCreate->createFieldBuilder()->
|
||||||
addTimeStamp()->
|
addArray("value",st) ->
|
||||||
createPVStructure();
|
add("timeStamp",standardField->timeStamp()) ->
|
||||||
|
add("alarm",standardField->alarm()) ->
|
||||||
|
createStructure();
|
||||||
|
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
|
||||||
PVRecordPtr record = PVRecord::create(recordName,pvStructure);
|
PVRecordPtr record = PVRecord::create(recordName,pvStructure);
|
||||||
record->setAsLevel(asLevel);
|
record->setAsLevel(asLevel);
|
||||||
|
record->setAsGroup(asGroup);
|
||||||
PVDatabasePtr master = PVDatabase::getMaster();
|
PVDatabasePtr master = PVDatabase::getMaster();
|
||||||
bool result = master->addRecord(record);
|
bool result = master->addRecord(record);
|
||||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||||
} catch(std::exception& ex) {
|
|
||||||
cerr << "failure " << ex.what() << "/n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pvdbcrScalarArrayRegister(void)
|
static void pvdbcrScalarArrayRegister(void)
|
||||||
|
@ -7,68 +7,59 @@
|
|||||||
* @author mrk
|
* @author mrk
|
||||||
* @date 2021.03.12
|
* @date 2021.03.12
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Author: Marty Kraimer */
|
|
||||||
|
|
||||||
#include <epicsThread.h>
|
|
||||||
#include <iocsh.h>
|
#include <iocsh.h>
|
||||||
#include <pv/event.h>
|
#include <pv/standardField.h>
|
||||||
#include <pv/pvAccess.h>
|
#include <pv/pvDatabase.h>
|
||||||
#include <pv/serverContext.h>
|
// The following must be the last include for code exampleLink uses
|
||||||
#include <pv/pvData.h>
|
|
||||||
#include <pv/pvTimeStamp.h>
|
|
||||||
#include <pv/rpcService.h>
|
|
||||||
#include <pv/ntscalar.h>
|
|
||||||
|
|
||||||
// The following must be the last include for code pvDatabase uses
|
|
||||||
#include <epicsExport.h>
|
#include <epicsExport.h>
|
||||||
#define epicsExportSharedSymbols
|
#define epicsExportSharedSymbols
|
||||||
#include "pv/pvStructureCopy.h"
|
|
||||||
#include "pv/pvDatabase.h"
|
|
||||||
|
|
||||||
using namespace epics::pvData;
|
using namespace epics::pvData;
|
||||||
using namespace epics::nt;
|
|
||||||
using namespace epics::pvAccess;
|
|
||||||
using namespace epics::pvDatabase;
|
using namespace epics::pvDatabase;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
static const iocshArg arg0 = { "recordName", iocshArgString };
|
||||||
static const iocshArg testArg1 = { "scalarType", iocshArgString };
|
static const iocshArg arg1 = { "scalarType", iocshArgString };
|
||||||
static const iocshArg testArg2 = { "asLevel", iocshArgInt };
|
static const iocshArg arg2 = { "asLevel", iocshArgInt };
|
||||||
static const iocshArg *testArgs[] = {&testArg0,&testArg1,&testArg2};
|
static const iocshArg arg3 = { "asGroup", iocshArgString };
|
||||||
|
static const iocshArg *args[] = {&arg0,&arg1,&arg2,&arg3};
|
||||||
|
|
||||||
static const iocshFuncDef pvdbcrScalarFuncDef = {"pvdbcrScalar", 3,testArgs};
|
static const iocshFuncDef pvdbcrScalarFuncDef = {"pvdbcrScalar", 4,args};
|
||||||
|
|
||||||
static void pvdbcrScalarCallFunc(const iocshArgBuf *args)
|
static void pvdbcrScalarCallFunc(const iocshArgBuf *args)
|
||||||
{
|
{
|
||||||
char *sval = args[0].sval;
|
char *sval = args[0].sval;
|
||||||
if(!sval) {
|
if(!sval) {
|
||||||
throw std::runtime_error("pvdbcrScalarCreate recordName not specified");
|
throw std::runtime_error("pvdbcrScalarArrayCreate recordName not specified");
|
||||||
}
|
}
|
||||||
string recordName = string(sval);
|
string recordName = string(sval);
|
||||||
sval = args[1].sval;
|
sval = args[1].sval;
|
||||||
if(!sval) {
|
if(!sval) {
|
||||||
throw std::runtime_error("pvdbcrScalarCreate scalarType not specified");
|
throw std::runtime_error("pvdbcrScalarArrayCreate scalarType not specified");
|
||||||
}
|
}
|
||||||
string scalarType = string(sval);
|
string scalarType = string(sval);
|
||||||
int asLevel = args[2].ival;
|
int asLevel = args[2].ival;
|
||||||
try {
|
string asGroup("DEFAULT");
|
||||||
|
sval = args[3].sval;
|
||||||
|
if(sval) {
|
||||||
|
asGroup = string(sval);
|
||||||
|
}
|
||||||
ScalarType st = epics::pvData::ScalarTypeFunc::getScalarType(scalarType);
|
ScalarType st = epics::pvData::ScalarTypeFunc::getScalarType(scalarType);
|
||||||
NTScalarBuilderPtr ntScalarBuilder = NTScalar::createBuilder();
|
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||||
PVStructurePtr pvStructure = ntScalarBuilder->
|
StandardFieldPtr standardField = getStandardField();
|
||||||
value(st)->
|
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||||
addAlarm()->
|
StructureConstPtr top = fieldCreate->createFieldBuilder()->
|
||||||
addTimeStamp()->
|
add("value",st) ->
|
||||||
createPVStructure();
|
add("timeStamp",standardField->timeStamp()) ->
|
||||||
|
add("alarm",standardField->alarm()) ->
|
||||||
|
createStructure();
|
||||||
|
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
|
||||||
PVRecordPtr record = PVRecord::create(recordName,pvStructure);
|
PVRecordPtr record = PVRecord::create(recordName,pvStructure);
|
||||||
record->setAsLevel(asLevel);
|
record->setAsLevel(asLevel);
|
||||||
|
record->setAsGroup(asGroup);
|
||||||
PVDatabasePtr master = PVDatabase::getMaster();
|
PVDatabasePtr master = PVDatabase::getMaster();
|
||||||
bool result = master->addRecord(record);
|
bool result = master->addRecord(record);
|
||||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||||
} catch(std::exception& ex) {
|
|
||||||
cerr << "failure " << ex.what() << "/n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pvdbcrScalarRegister(void)
|
static void pvdbcrScalarRegister(void)
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
/* pvdbcrTraceRecord.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 2021.03.12
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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/pvdbcrTraceRecord.h"
|
|
||||||
|
|
||||||
using std::tr1::static_pointer_cast;
|
|
||||||
using namespace epics::pvData;
|
|
||||||
using namespace epics::pvAccess;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace epics { namespace pvDatabase {
|
|
||||||
|
|
||||||
PvdbcrTraceRecordPtr PvdbcrTraceRecord::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);
|
|
||||||
PvdbcrTraceRecordPtr pvRecord(
|
|
||||||
new PvdbcrTraceRecord(recordName,pvStructure));
|
|
||||||
if(!pvRecord->init()) pvRecord.reset();
|
|
||||||
return pvRecord;
|
|
||||||
}
|
|
||||||
|
|
||||||
PvdbcrTraceRecord::PvdbcrTraceRecord(
|
|
||||||
std::string const & recordName,
|
|
||||||
epics::pvData::PVStructurePtr const & pvStructure)
|
|
||||||
: PVRecord(recordName,pvStructure)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool PvdbcrTraceRecord::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 PvdbcrTraceRecord::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");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}}
|
|
@ -7,48 +7,127 @@
|
|||||||
* @author mrk
|
* @author mrk
|
||||||
* @date 2021.03.12
|
* @date 2021.03.12
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Author: Marty Kraimer */
|
|
||||||
|
|
||||||
#include <epicsThread.h>
|
|
||||||
#include <iocsh.h>
|
#include <iocsh.h>
|
||||||
#include <pv/event.h>
|
#include <pv/standardField.h>
|
||||||
#include <pv/pvAccess.h>
|
#include <pv/standardPVField.h>
|
||||||
#include <pv/serverContext.h>
|
#include <pv/timeStamp.h>
|
||||||
#include <pv/pvData.h>
|
|
||||||
#include <pv/pvTimeStamp.h>
|
#include <pv/pvTimeStamp.h>
|
||||||
#include <pv/rpcService.h>
|
#include <pv/alarm.h>
|
||||||
|
#include <pv/pvAlarm.h>
|
||||||
|
#include <pv/pvDatabase.h>
|
||||||
|
#include <pv/pvaClient.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>
|
#include <epicsExport.h>
|
||||||
#define epicsExportSharedSymbols
|
#define epicsExportSharedSymbols
|
||||||
#include "pv/pvStructureCopy.h"
|
|
||||||
#include "pv/pvDatabase.h"
|
|
||||||
#include "pv/pvdbcrTraceRecord.h"
|
|
||||||
|
|
||||||
using namespace epics::pvData;
|
using namespace epics::pvData;
|
||||||
using namespace epics::pvAccess;
|
using namespace epics::pvAccess;
|
||||||
using namespace epics::pvDatabase;
|
using namespace epics::pvDatabase;
|
||||||
|
using namespace epics::pvaClient;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
class PvdbcrTraceRecord;
|
||||||
static const iocshArg testArg1 = { "asLevel", iocshArgInt };
|
typedef std::tr1::shared_ptr<PvdbcrTraceRecord> PvdbcrTraceRecordPtr;
|
||||||
static const iocshArg *testArgs[] = {&testArg0,&testArg1};
|
|
||||||
|
|
||||||
static const iocshFuncDef pvdbcrTraceRecordFuncDef = {"pvdbcrTraceRecord", 2,testArgs};
|
class epicsShareClass PvdbcrTraceRecord :
|
||||||
|
public PVRecord
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
POINTER_DEFINITIONS(PvdbcrTraceRecord);
|
||||||
|
static PvdbcrTraceRecordPtr create(
|
||||||
|
std::string const & recordName);
|
||||||
|
virtual bool init();
|
||||||
|
virtual void process();
|
||||||
|
private:
|
||||||
|
PvdbcrTraceRecord(
|
||||||
|
std::string const & recordName,
|
||||||
|
epics::pvData::PVStructurePtr const & pvStructure);
|
||||||
|
epics::pvData::PVStringPtr pvRecordName;
|
||||||
|
epics::pvData::PVIntPtr pvLevel;
|
||||||
|
epics::pvData::PVStringPtr pvResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
PvdbcrTraceRecordPtr PvdbcrTraceRecord::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);
|
||||||
|
PvdbcrTraceRecordPtr pvRecord(
|
||||||
|
new PvdbcrTraceRecord(recordName,pvStructure));
|
||||||
|
if(!pvRecord->init()) pvRecord.reset();
|
||||||
|
return pvRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
PvdbcrTraceRecord::PvdbcrTraceRecord(
|
||||||
|
std::string const & recordName,
|
||||||
|
epics::pvData::PVStructurePtr const & pvStructure)
|
||||||
|
: PVRecord(recordName,pvStructure)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PvdbcrTraceRecord::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 PvdbcrTraceRecord::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 arg1 = { "asLevel", iocshArgInt };
|
||||||
|
static const iocshArg arg2 = { "asGroup", iocshArgString };
|
||||||
|
static const iocshArg *args[] = {&arg0,&arg1,&arg2};
|
||||||
|
|
||||||
|
static const iocshFuncDef pvdbcrTraceRecordFuncDef = {"pvdbcrTraceRecord", 3,args};
|
||||||
|
|
||||||
static void pvdbcrTraceRecordCallFunc(const iocshArgBuf *args)
|
static void pvdbcrTraceRecordCallFunc(const iocshArgBuf *args)
|
||||||
{
|
{
|
||||||
char *recordName = args[0].sval;
|
char *sval = args[0].sval;
|
||||||
if(!recordName) {
|
if(!sval) {
|
||||||
throw std::runtime_error("traceRecordCreate invalid number of arguments");
|
throw std::runtime_error("pvdbcrTraceRecord recordName not specified");
|
||||||
}
|
}
|
||||||
|
string recordName = string(sval);
|
||||||
int asLevel = args[1].ival;
|
int asLevel = args[1].ival;
|
||||||
|
string asGroup("DEFAULT");
|
||||||
|
sval = args[2].sval;
|
||||||
|
if(sval) {
|
||||||
|
asGroup = string(sval);
|
||||||
|
}
|
||||||
PvdbcrTraceRecordPtr record = PvdbcrTraceRecord::create(recordName);
|
PvdbcrTraceRecordPtr record = PvdbcrTraceRecord::create(recordName);
|
||||||
record->setAsLevel(asLevel);
|
record->setAsLevel(asLevel);
|
||||||
bool result = PVDatabase::getMaster()->addRecord(record);
|
record->setAsGroup(asGroup);
|
||||||
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 pvdbcrTraceRecordRegister(void)
|
static void pvdbcrTraceRecordRegister(void)
|
||||||
|
Reference in New Issue
Block a user