auto-start PVA server w/ initHook
split of this code into a new library pvAccessIOC which depends on all core libraries.
This commit is contained in:
3
Makefile
3
Makefile
@ -8,6 +8,9 @@ DIRS := configure
|
||||
DIRS += src
|
||||
src_DEPEND_DIRS = configure
|
||||
|
||||
DIRS += src/ioc
|
||||
src/ioc_DEPEND_DIRS = src
|
||||
|
||||
DIRS += pvtoolsSrc
|
||||
pvtoolsSrc_DEPEND_DIRS = src
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
Release 5.x.x
|
||||
==========
|
||||
|
||||
*
|
||||
* Add new library pvAccessIOC for use with PVAClientRegister.dbd and PVAServerRegister.dbd.
|
||||
Necessary to avoid having pvAccess library depend on all IOC core libraries.
|
||||
|
||||
Release 5.0.0
|
||||
==========
|
||||
|
@ -23,6 +23,13 @@ CHECK_RELEASE = YES
|
||||
-include $(TOP)/../CONFIG_SITE.local
|
||||
-include $(TOP)/configure/CONFIG_SITE.local
|
||||
|
||||
EPICS_PVA_MAJOR_VERSION = 5
|
||||
EPICS_PVA_MINOR_VERSION = 0
|
||||
EPICS_PVA_MAINTENANCE_VERSION = 1
|
||||
EPICS_PVA_DEVELOPMENT_FLAG = 1
|
||||
|
||||
SHRLIB_VERSION ?= $(EPICS_PVA_MAJOR_VERSION).$(EPICS_PVA_MINOR_VERSION).$(EPICS_PVA_MAINTENANCE_VERSION)
|
||||
|
||||
ifdef WITH_COVERAGE
|
||||
USR_CPPFLAGS += --coverage
|
||||
USR_LDFLAGS += --coverage
|
||||
|
@ -3,11 +3,6 @@
|
||||
TOP = ..
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
EPICS_PVA_MAJOR_VERSION = 5
|
||||
EPICS_PVA_MINOR_VERSION = 0
|
||||
EPICS_PVA_MAINTENANCE_VERSION = 1
|
||||
EPICS_PVA_DEVELOPMENT_FLAG = 1
|
||||
|
||||
EXPANDVARS += EPICS_PVA_MAJOR_VERSION
|
||||
EXPANDVARS += EPICS_PVA_MINOR_VERSION
|
||||
EXPANDVARS += EPICS_PVA_MAINTENANCE_VERSION
|
||||
@ -29,12 +24,9 @@ include $(PVACCESS_SRC)/rpcClient/Makefile
|
||||
include $(PVACCESS_SRC)/pipelineService/Makefile
|
||||
include $(PVACCESS_SRC)/ca/Makefile
|
||||
include $(PVACCESS_SRC)/mb/Makefile
|
||||
include $(PVACCESS_SRC)/ioc/Makefile
|
||||
|
||||
LIBRARY = pvAccess
|
||||
|
||||
SHRLIB_VERSION = $(EPICS_PVA_MAJOR_VERSION).$(EPICS_PVA_MINOR_VERSION).$(EPICS_PVA_MAINTENANCE_VERSION)
|
||||
|
||||
pvAccess_LIBS += pvData
|
||||
ifdef WITH_MICROBENCH
|
||||
pvAccess_LIBS += pvMB
|
||||
|
@ -1,6 +1,7 @@
|
||||
# This is a Makefile fragment, see ../Makefile
|
||||
TOP = ../..
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
SRC_DIRS += $(PVACCESS_SRC)/ioc
|
||||
LIBRARY += pvAccessIOC
|
||||
|
||||
INC += pv/syncChannelFind.h
|
||||
|
||||
@ -9,3 +10,7 @@ DBD += PVAClientRegister.dbd
|
||||
|
||||
LIBSRCS += PVAServerRegister.cpp
|
||||
LIBSRCS += PVAClientRegister.cpp
|
||||
|
||||
pvAccessIOC_LIBS += $(EPICS_BASE_IOC_LIBS)
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <epicsEvent.h>
|
||||
#include <epicsThread.h>
|
||||
#include <iocsh.h>
|
||||
#include <initHooks.h>
|
||||
#include <epicsExit.h>
|
||||
|
||||
#include <epicsExport.h>
|
||||
@ -37,8 +38,21 @@ using std::endl;
|
||||
namespace pvd = epics::pvData;
|
||||
namespace pva = epics::pvAccess;
|
||||
|
||||
static pvd::Mutex the_server_lock;
|
||||
static pva::ServerContext::shared_pointer the_server;
|
||||
|
||||
static void startitup() {
|
||||
the_server = pva::ServerContext::create(pva::ServerContext::Config()
|
||||
.config(pva::ConfigurationBuilder()
|
||||
// default to all providers instead of just "local"
|
||||
.add("EPICS_PVA_PROVIDER_NAMES", pva::PVACCESS_ALL_PROVIDERS)
|
||||
.push_map()
|
||||
// prefer to use EPICS_PVA_PROVIDER_NAMES or EPICS_PVAS_PROVIDER_NAMES
|
||||
// from environment
|
||||
.push_env()
|
||||
.build()));
|
||||
}
|
||||
|
||||
static const iocshArg startPVAServerArg0 = { "providerNames", iocshArgString };
|
||||
static const iocshArg *startPVAServerArgs[] = {
|
||||
&startPVAServerArg0};
|
||||
@ -49,17 +63,19 @@ static const iocshFuncDef startPVAServerFuncDef = {
|
||||
static void startPVAServer(const iocshArgBuf *args)
|
||||
{
|
||||
try {
|
||||
char *names = args[0].sval;
|
||||
if(names && names[0]!='\0') {
|
||||
printf("Warning: startPVAServer() no longer accepts provider list as argument.\n"
|
||||
" Instead place the following before calling startPVAServer() and iocInit()\n"
|
||||
" epicsEnvSet(\"EPICS_PVAS_PROVIDER_NAMES\", \"%s\")\n",
|
||||
names);
|
||||
}
|
||||
pvd::Lock G(the_server_lock);
|
||||
if(the_server) {
|
||||
std::cout<<"PVA server already running\n";
|
||||
return;
|
||||
}
|
||||
char *names = args[0].sval;
|
||||
if(!names) {
|
||||
the_server = pva::startPVAServer(pva::PVACCESS_ALL_PROVIDERS,0,true,true);
|
||||
} else {
|
||||
std::string providerNames(names);
|
||||
the_server = pva::startPVAServer(providerNames,0,true,true);
|
||||
}
|
||||
startitup();
|
||||
}catch(std::exception& e){
|
||||
std::cout<<"Error: "<<e.what()<<"\n";
|
||||
}
|
||||
@ -72,6 +88,7 @@ static const iocshFuncDef stopPVAServerFuncDef = {
|
||||
static void stopPVAServer(const iocshArgBuf *args)
|
||||
{
|
||||
try {
|
||||
pvd::Lock G(the_server_lock);
|
||||
if(!the_server) {
|
||||
std::cout<<"PVA server not running\n";
|
||||
return;
|
||||
@ -82,10 +99,43 @@ static void stopPVAServer(const iocshArgBuf *args)
|
||||
}
|
||||
}
|
||||
|
||||
static const iocshArg *statusPVAServerArgs[] = {};
|
||||
static const iocshFuncDef statusPVAServerFuncDef = {
|
||||
"statusPVAServer", 0, statusPVAServerArgs
|
||||
};
|
||||
static void statusPVAServer(const iocshArgBuf *args)
|
||||
{
|
||||
try {
|
||||
pvd::Lock G(the_server_lock);
|
||||
if(!the_server) {
|
||||
std::cout<<"PVA server not running\n";
|
||||
return;
|
||||
} else {
|
||||
the_server->printInfo();
|
||||
}
|
||||
}catch(std::exception& e){
|
||||
std::cout<<"Error: "<<e.what()<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
static void initStartPVAServer(initHookState state)
|
||||
{
|
||||
pvd::Lock G(the_server_lock);
|
||||
if(state==initHookAfterIocRunning && !the_server) {
|
||||
startitup();
|
||||
|
||||
} else if(state==initHookAtIocPause) {
|
||||
the_server.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void registerStartPVAServer(void)
|
||||
{
|
||||
iocshRegister(&startPVAServerFuncDef, startPVAServer);
|
||||
iocshRegister(&stopPVAServerFuncDef, stopPVAServer);
|
||||
iocshRegister(&statusPVAServerFuncDef, statusPVAServer);
|
||||
initHookRegister(&initStartPVAServer);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
Reference in New Issue
Block a user