add qsrv
This commit is contained in:
@ -405,4 +405,35 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template<class CP>
|
||||
struct BaseChannelProviderFactory : epics::pvAccess::ChannelProviderFactory
|
||||
{
|
||||
typedef CP provider_type;
|
||||
std::string name;
|
||||
epicsMutex lock;
|
||||
std::tr1::weak_ptr<CP> last_shared;
|
||||
|
||||
BaseChannelProviderFactory(const char *name) :name(name) {}
|
||||
virtual ~BaseChannelProviderFactory() {}
|
||||
|
||||
virtual std::string getFactoryName() { return name; }
|
||||
|
||||
virtual epics::pvAccess::ChannelProvider::shared_pointer sharedInstance()
|
||||
{
|
||||
epicsGuard<epicsMutex> G(lock);
|
||||
std::tr1::shared_ptr<CP> ret(last_shared.lock());
|
||||
if(!ret) {
|
||||
ret.reset(new CP());
|
||||
last_shared = ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
virtual epics::pvAccess::ChannelProvider::shared_pointer newInstance(const std::tr1::shared_ptr<epics::pvAccess::Configuration>&)
|
||||
{
|
||||
std::tr1::shared_ptr<CP> ret(new CP());
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PVAHELPER_H
|
||||
|
@ -10,6 +10,7 @@ LIBRARY_HOST += pdbcore
|
||||
USR_CPPFLAGS += -I$(TOP)/common -I$(TOP)/p2pApp
|
||||
|
||||
pdbcore_SRCS += pvif.cpp
|
||||
pdbcore_SRCS += qsrv.cpp
|
||||
pdbcore_SRCS += pdb.cpp
|
||||
pdbcore_SRCS += pdbsingle.cpp
|
||||
pdbcore_SRCS += pdbgroup.cpp
|
||||
|
75
pdbApp/qsrv.cpp
Normal file
75
pdbApp/qsrv.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
#include <epicsExport.h>
|
||||
#include <initHooks.h>
|
||||
#include <epicsExit.h>
|
||||
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
#include "pvahelper.h"
|
||||
#include "iocshelper.h"
|
||||
#include "pdb.h"
|
||||
|
||||
namespace pva = epics::pvAccess;
|
||||
|
||||
static
|
||||
epicsMutex qsrv_lock;
|
||||
|
||||
static
|
||||
pva::ServerContext::shared_pointer qsrv;
|
||||
|
||||
void qsrvStart()
|
||||
{
|
||||
try{
|
||||
epicsGuard<epicsMutex> G(qsrv_lock);
|
||||
if(qsrv) {
|
||||
std::cout<<"QSRV already started\n";
|
||||
} else {
|
||||
qsrv = pva::startPVAServer("QSRV", 0, true, false);
|
||||
}
|
||||
}catch(std::exception& e){
|
||||
printf("Error: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void qsrvStop()
|
||||
{
|
||||
try{
|
||||
epicsGuard<epicsMutex> G(qsrv_lock);
|
||||
if(!qsrv) {
|
||||
std::cout<<"QSRV not running\n";
|
||||
} else {
|
||||
qsrv->destroy();
|
||||
qsrv.reset();
|
||||
}
|
||||
}catch(std::exception& e){
|
||||
printf("Error: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void QSRVExit(void *)
|
||||
{
|
||||
qsrvStop();
|
||||
}
|
||||
|
||||
static
|
||||
void QSRVHooks(initHookState state)
|
||||
{
|
||||
if(state!=initHookAfterCaServerInit)
|
||||
return;
|
||||
epicsAtExit(QSRVExit, NULL);
|
||||
qsrvStart();
|
||||
}
|
||||
|
||||
static
|
||||
void QSRVRegistrar()
|
||||
{
|
||||
pva::ChannelProviderFactory::shared_pointer fact(new BaseChannelProviderFactory<PDBProvider>("QSRV"));
|
||||
initHookRegister(QSRVHooks);
|
||||
pva::registerChannelProviderFactory(fact);
|
||||
iocshRegister<&qsrvStart>("qsrvStart");
|
||||
iocshRegister<&qsrvStop>("qsrvStop");
|
||||
}
|
||||
|
||||
epicsExportRegistrar(QSRVRegistrar);
|
1
pdbApp/qsrv.dbd
Normal file
1
pdbApp/qsrv.dbd
Normal file
@ -0,0 +1 @@
|
||||
registrar(QSRVRegistrar)
|
Reference in New Issue
Block a user