16
exampleRPC/Makefile
Normal file
16
exampleRPC/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
#Makefile at top of application tree
|
||||
TOP = .
|
||||
include $(TOP)/configure/CONFIG
|
||||
DIRS += configure
|
||||
|
||||
DIRS += src
|
||||
src_DEPEND_DIRS = configure
|
||||
|
||||
DIRS += ioc
|
||||
ioc_DEPEND_DIRS = src
|
||||
|
||||
DIRS += iocBoot
|
||||
|
||||
include $(TOP)/configure/RULES_TOP
|
||||
|
||||
|
29
exampleRPC/configure/CONFIG
Normal file
29
exampleRPC/configure/CONFIG
Normal file
@ -0,0 +1,29 @@
|
||||
# CONFIG - Load build configuration data
|
||||
#
|
||||
# Do not make changes to this file!
|
||||
|
||||
# Allow user to override where the build rules come from
|
||||
RULES = $(EPICS_BASE)
|
||||
|
||||
# RELEASE files point to other application tops
|
||||
include $(TOP)/configure/RELEASE
|
||||
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH).Common
|
||||
ifdef T_A
|
||||
-include $(TOP)/configure/RELEASE.Common.$(T_A)
|
||||
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH).$(T_A)
|
||||
endif
|
||||
|
||||
CONFIG = $(RULES)/configure
|
||||
include $(CONFIG)/CONFIG
|
||||
|
||||
# Override the Base definition:
|
||||
INSTALL_LOCATION = $(TOP)
|
||||
|
||||
# CONFIG_SITE files contain other build configuration settings
|
||||
include $(TOP)/configure/CONFIG_SITE
|
||||
-include $(TOP)/configure/CONFIG_SITE.$(EPICS_HOST_ARCH).Common
|
||||
ifdef T_A
|
||||
-include $(TOP)/configure/CONFIG_SITE.Common.$(T_A)
|
||||
-include $(TOP)/configure/CONFIG_SITE.$(EPICS_HOST_ARCH).$(T_A)
|
||||
endif
|
||||
|
39
exampleRPC/configure/CONFIG_SITE
Normal file
39
exampleRPC/configure/CONFIG_SITE
Normal file
@ -0,0 +1,39 @@
|
||||
# CONFIG_SITE
|
||||
|
||||
# Make any application-specific changes to the EPICS build
|
||||
# configuration variables in this file.
|
||||
#
|
||||
# Host/target specific settings can be specified in files named
|
||||
# CONFIG_SITE.$(EPICS_HOST_ARCH).Common
|
||||
# CONFIG_SITE.Common.$(T_A)
|
||||
# CONFIG_SITE.$(EPICS_HOST_ARCH).$(T_A)
|
||||
|
||||
# CHECK_RELEASE controls the consistency checking of the support
|
||||
# applications pointed to by the RELEASE* files.
|
||||
# Normally CHECK_RELEASE should be set to YES.
|
||||
# Set CHECK_RELEASE to NO to disable checking completely.
|
||||
# Set CHECK_RELEASE to WARN to perform consistency checking but
|
||||
# continue building anyway if conflicts are found.
|
||||
#CHECK_RELEASE = YES
|
||||
|
||||
# Set this when you only want to compile this application
|
||||
# for a subset of the cross-compiled target architectures
|
||||
# that Base is built for.
|
||||
#CROSS_COMPILER_TARGET_ARCHS = vxWorks-68040
|
||||
|
||||
# To install files into a location other than $(TOP) define
|
||||
# INSTALL_LOCATION here.
|
||||
#INSTALL_LOCATION=</path/name/to/install/top>
|
||||
|
||||
# Set this when your IOC and the host use different paths
|
||||
# to access the application. This will be needed to boot
|
||||
# from a Microsoft FTP server or with some NFS mounts.
|
||||
# You must rebuild in the iocBoot directory for this to
|
||||
# take effect.
|
||||
#IOCS_APPL_TOP = </IOC/path/to/application/top>
|
||||
|
||||
INSTALL_INCLUDE = $(INSTALL_LOCATION)/include/pv
|
||||
USR_INCLUDES += -I $(INSTALL_LOCATION)/include
|
||||
|
||||
-include $(TOP)/../../CONFIG_SITE.local
|
||||
-include $(TOP)/../configure/CONFIG_SITE.local
|
8
exampleRPC/configure/ExampleRELEASE.local
Normal file
8
exampleRPC/configure/ExampleRELEASE.local
Normal file
@ -0,0 +1,8 @@
|
||||
EPICS_BASE=/home/install/epics/base
|
||||
TEMPLATE_TOP=$(EPICS_BASE)/templates/makeBaseApp/top
|
||||
EPICSV4HOME=/home/hg
|
||||
PVCOMMON=${EPICSV4HOME}/pvCommonCPP
|
||||
PVDATA=${EPICSV4HOME}/pvDataCPP
|
||||
PVACCESS=${EPICSV4HOME}/pvAccessCPP
|
||||
PVDATABASE=${EPICSV4HOME}/pvDatabaseCPP
|
||||
PVASRV=${EPICSV4HOME}/pvaSrv
|
8
exampleRPC/configure/Makefile
Normal file
8
exampleRPC/configure/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
TOP=..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
TARGETS = $(CONFIG_TARGETS)
|
||||
CONFIGS += $(subst ../,,$(wildcard $(CONFIG_INSTALLS)))
|
||||
|
||||
include $(TOP)/configure/RULES
|
40
exampleRPC/configure/RELEASE
Normal file
40
exampleRPC/configure/RELEASE
Normal file
@ -0,0 +1,40 @@
|
||||
# pvDatabaseCPP/example RELEASE - Location of external support modules
|
||||
#
|
||||
# IF YOU CHANGE this file or any file it includes you must
|
||||
# subsequently do a "gnumake rebuild" in the application's
|
||||
# top level directory.
|
||||
#
|
||||
# The build process does not check dependencies against files
|
||||
# that are outside this application, thus you should also do a
|
||||
# "gnumake rebuild" in the top level directory after EPICS_BASE
|
||||
# or any other external module pointed to below is rebuilt.
|
||||
#
|
||||
# Host- or target-specific settings can be given in files named
|
||||
# RELEASE.$(EPICS_HOST_ARCH).Common
|
||||
# RELEASE.Common.$(T_A)
|
||||
# RELEASE.$(EPICS_HOST_ARCH).$(T_A)
|
||||
|
||||
# EPICS V4 Developers: Do not edit the locations in this file!
|
||||
#
|
||||
# Create a file RELEASE.local pointing to your places
|
||||
# for the dependencies, e.g.
|
||||
# PVACCESS = /path/to/epics/pvAccessCPP
|
||||
# PVDATA = /path/to/epics/pvDataCPP
|
||||
# PVCOMMON = /path/to/epics/pvCommonCPP
|
||||
# EPICS_BASE = /path/to/epics/base
|
||||
|
||||
# If this example is built in a directory under pvDatabaseCPP,
|
||||
# use the following definitions:
|
||||
|
||||
PVDATABASE = $(TOP)/..
|
||||
-include $(TOP)/../../RELEASE.local
|
||||
-include $(TOP)/../configure/RELEASE.local
|
||||
|
||||
# If you copied this example from pvDatabaseCPP to be built as a
|
||||
# standalone TOP, define
|
||||
# PVDATABASE = /path/to/epics/pvDatabaseCPP
|
||||
# in the appropriate RELEASE[.local],
|
||||
# and use the following definitions instead:
|
||||
|
||||
#-include $(TOP)/../RELEASE.local
|
||||
#-include $(TOP)/configure/RELEASE.local
|
6
exampleRPC/configure/RULES
Normal file
6
exampleRPC/configure/RULES
Normal file
@ -0,0 +1,6 @@
|
||||
# RULES
|
||||
|
||||
include $(CONFIG)/RULES
|
||||
|
||||
# Library should be rebuilt because LIBOBJS may have changed.
|
||||
$(LIBNAME): ../Makefile
|
2
exampleRPC/configure/RULES.ioc
Normal file
2
exampleRPC/configure/RULES.ioc
Normal file
@ -0,0 +1,2 @@
|
||||
#RULES.ioc
|
||||
include $(CONFIG)/RULES.ioc
|
2
exampleRPC/configure/RULES_DIRS
Normal file
2
exampleRPC/configure/RULES_DIRS
Normal file
@ -0,0 +1,2 @@
|
||||
#RULES_DIRS
|
||||
include $(CONFIG)/RULES_DIRS
|
3
exampleRPC/configure/RULES_TOP
Normal file
3
exampleRPC/configure/RULES_TOP
Normal file
@ -0,0 +1,3 @@
|
||||
#RULES_TOP
|
||||
include $(CONFIG)/RULES_TOP
|
||||
|
28
exampleRPC/ioc/Db/Makefile
Normal file
28
exampleRPC/ioc/Db/Makefile
Normal file
@ -0,0 +1,28 @@
|
||||
TOP=../..
|
||||
include $(TOP)/configure/CONFIG
|
||||
#----------------------------------------
|
||||
# ADD MACRO DEFINITIONS AFTER THIS LINE
|
||||
|
||||
#----------------------------------------------------
|
||||
# Optimization of db files using dbst (DEFAULT: NO)
|
||||
#DB_OPT = YES
|
||||
|
||||
#----------------------------------------------------
|
||||
# Create and install (or just install)
|
||||
# databases, templates, substitutions like this
|
||||
DB += dbScalar.db
|
||||
DB += dbInteger.db
|
||||
DB += dbArray.db
|
||||
DB += dbString.db
|
||||
DB += dbStringArray.db
|
||||
DB += dbEnum.db
|
||||
DB += dbCounter.db
|
||||
|
||||
#----------------------------------------------------
|
||||
# If <anyname>.db template is not named <anyname>*.template add
|
||||
# <anyname>_TEMPLATE = <templatename>
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
#----------------------------------------
|
||||
# ADD RULES AFTER THIS LINE
|
||||
|
9
exampleRPC/ioc/Db/dbArray.db
Normal file
9
exampleRPC/ioc/Db/dbArray.db
Normal file
@ -0,0 +1,9 @@
|
||||
record(waveform, "$(name)")
|
||||
{
|
||||
field(NELM,"5")
|
||||
field(NORD,"5")
|
||||
field(FTVL,"$(type)")
|
||||
field(EGU, "Counts")
|
||||
field(HOPR, "10")
|
||||
field(LOPR, "0")
|
||||
}
|
20
exampleRPC/ioc/Db/dbCounter.db
Normal file
20
exampleRPC/ioc/Db/dbCounter.db
Normal file
@ -0,0 +1,20 @@
|
||||
record(calc, "${name}")
|
||||
{
|
||||
field(DESC, "Counter")
|
||||
field(SCAN,"1 second")
|
||||
field(CALC, "(A<B)?(A+C):D")
|
||||
field(INPA, "${name} NPP NMS")
|
||||
field(INPB, "9")
|
||||
field(INPC, "1")
|
||||
field(INPD, "0")
|
||||
field(EGU, "Counts")
|
||||
field(HOPR, "10")
|
||||
field(HIHI, "8")
|
||||
field(HIGH, "6")
|
||||
field(LOW, "4")
|
||||
field(LOLO, "2")
|
||||
field(HHSV, "MAJOR")
|
||||
field(HSV, "MINOR")
|
||||
field(LSV, "MINOR")
|
||||
field(LLSV, "MAJOR")
|
||||
}
|
14
exampleRPC/ioc/Db/dbEnum.db
Normal file
14
exampleRPC/ioc/Db/dbEnum.db
Normal file
@ -0,0 +1,14 @@
|
||||
record(mbbo, "$(name)")
|
||||
{
|
||||
field(NOBT,"2")
|
||||
field(ZRVL,"0")
|
||||
field(ONVL,"1")
|
||||
field(TWVL,"2")
|
||||
field(THVL,"3")
|
||||
field(ZRST,"zero")
|
||||
field(ONST,"one")
|
||||
field(TWST,"two")
|
||||
field(THST,"three")
|
||||
field(TWSV,"MINOR")
|
||||
field(THSV,"MAJOR")
|
||||
}
|
16
exampleRPC/ioc/Db/dbInteger.db
Normal file
16
exampleRPC/ioc/Db/dbInteger.db
Normal file
@ -0,0 +1,16 @@
|
||||
record($(type), "$(name)")
|
||||
{
|
||||
field(EGU, "Counts")
|
||||
field(HOPR, "10")
|
||||
field(LOPR, "0")
|
||||
field(DRVH, "9")
|
||||
field(DRVL, "0")
|
||||
field(HIHI, "8")
|
||||
field(HIGH, "6")
|
||||
field(LOW, "4")
|
||||
field(LOLO, "2")
|
||||
field(HHSV, "MAJOR")
|
||||
field(HSV, "MINOR")
|
||||
field(LSV, "MINOR")
|
||||
field(LLSV, "MAJOR")
|
||||
}
|
17
exampleRPC/ioc/Db/dbScalar.db
Normal file
17
exampleRPC/ioc/Db/dbScalar.db
Normal file
@ -0,0 +1,17 @@
|
||||
record($(type), "$(name)")
|
||||
{
|
||||
field(PREC, "1")
|
||||
field(EGU, "Counts")
|
||||
field(HOPR, "10")
|
||||
field(LOPR, "0")
|
||||
field(DRVH, "9.9")
|
||||
field(DRVL, "-0.1")
|
||||
field(HIHI, "8")
|
||||
field(HIGH, "6")
|
||||
field(LOW, "4")
|
||||
field(LOLO, "2")
|
||||
field(HHSV, "MAJOR")
|
||||
field(HSV, "MINOR")
|
||||
field(LSV, "MINOR")
|
||||
field(LLSV, "MAJOR")
|
||||
}
|
3
exampleRPC/ioc/Db/dbString.db
Normal file
3
exampleRPC/ioc/Db/dbString.db
Normal file
@ -0,0 +1,3 @@
|
||||
record(stringout, "$(name)")
|
||||
{
|
||||
}
|
5
exampleRPC/ioc/Db/dbStringArray.db
Normal file
5
exampleRPC/ioc/Db/dbStringArray.db
Normal file
@ -0,0 +1,5 @@
|
||||
record(waveform, "${name}")
|
||||
{
|
||||
field(NELM,"5")
|
||||
field(FTVL,"STRING")
|
||||
}
|
8
exampleRPC/ioc/Makefile
Normal file
8
exampleRPC/ioc/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
TOP = ..
|
||||
include $(TOP)/configure/CONFIG
|
||||
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard *src*))
|
||||
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard *Src*))
|
||||
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard *db*))
|
||||
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard *Db*))
|
||||
include $(TOP)/configure/RULES_DIRS
|
||||
|
41
exampleRPC/ioc/src/Makefile
Normal file
41
exampleRPC/ioc/src/Makefile
Normal file
@ -0,0 +1,41 @@
|
||||
TOP=../..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
#----------------------------------------
|
||||
# ADD MACRO DEFINITIONS AFTER THIS LINE
|
||||
#=============================
|
||||
|
||||
#==================================================
|
||||
# Build an IOC support library
|
||||
#
|
||||
|
||||
DBD += exampleRPC.dbd
|
||||
|
||||
#=============================
|
||||
# build an ioc application
|
||||
|
||||
PROD_IOC += exampleRPC
|
||||
|
||||
|
||||
# <name>_registerRecordDeviceDriver.cpp will be created from <name>.dbd
|
||||
exampleRPC_SRCS += exampleRPC_registerRecordDeviceDriver.cpp
|
||||
exampleRPC_SRCS_DEFAULT += exampleRPCMain.cpp
|
||||
exampleRPC_SRCS_vxWorks += -nil-
|
||||
|
||||
|
||||
# The following adds support from base/src/vxWorks
|
||||
exampleRPC_OBJS_vxWorks += $(EPICS_BASE_BIN)/vxComLibrary
|
||||
|
||||
exampleRPC_LIBS += exampleRPC
|
||||
exampleRPC_LIBS += pvDatabase
|
||||
exampleRPC_LIBS += pvaSrv
|
||||
exampleRPC_LIBS += pvAccess
|
||||
exampleRPC_LIBS += pvData
|
||||
exampleRPC_LIBS += $(EPICS_BASE_IOC_LIBS)
|
||||
|
||||
#===========================
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
#----------------------------------------
|
||||
# ADD RULES AFTER THIS LINE
|
||||
|
6
exampleRPC/ioc/src/exampleRPCInclude.dbd
Normal file
6
exampleRPC/ioc/src/exampleRPCInclude.dbd
Normal file
@ -0,0 +1,6 @@
|
||||
include "base.dbd"
|
||||
include "PVAClientRegister.dbd"
|
||||
include "PVAServerRegister.dbd"
|
||||
include "registerChannelProviderLocal.dbd"
|
||||
include "dbPv.dbd"
|
||||
include "exampleRPC.dbd"
|
31
exampleRPC/ioc/src/exampleRPCMain.cpp
Normal file
31
exampleRPC/ioc/src/exampleRPCMain.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/* exampleRPCMain.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.07.24
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "epicsExit.h"
|
||||
#include "epicsThread.h"
|
||||
#include "iocsh.h"
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
if(argc>=2) {
|
||||
iocsh(argv[1]);
|
||||
epicsThreadSleep(.2);
|
||||
}
|
||||
iocsh(NULL);
|
||||
epicsExit(0);
|
||||
return(0);
|
||||
}
|
7
exampleRPC/iocBoot/Makefile
Normal file
7
exampleRPC/iocBoot/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TOP = ..
|
||||
include $(TOP)/configure/CONFIG
|
||||
DIRS += $(wildcard *ioc*)
|
||||
DIRS += $(wildcard as*)
|
||||
DIRS += $(wildcard example*)
|
||||
include $(CONFIG)/RULES_DIRS
|
||||
|
5
exampleRPC/iocBoot/exampleRPC/Makefile
Normal file
5
exampleRPC/iocBoot/exampleRPC/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
TOP = ../..
|
||||
include $(TOP)/configure/CONFIG
|
||||
ARCH = $(EPICS_HOST_ARCH)
|
||||
TARGETS = envPaths
|
||||
include $(TOP)/configure/RULES.ioc
|
23
exampleRPC/iocBoot/exampleRPC/st.cmd
Normal file
23
exampleRPC/iocBoot/exampleRPC/st.cmd
Normal file
@ -0,0 +1,23 @@
|
||||
< envPaths
|
||||
|
||||
cd ${TOP}
|
||||
|
||||
## Register all support components
|
||||
dbLoadDatabase("dbd/exampleRPC.dbd")
|
||||
exampleRPC_registerRecordDeviceDriver(pdbbase)
|
||||
|
||||
## Load record instances
|
||||
dbLoadRecords("db/dbScalar.db","name=pvdouble,type=ao")
|
||||
dbLoadRecords("db/dbArray.db","name=pvdoubleArray,type=DOUBLE")
|
||||
dbLoadRecords("db/dbStringArray.db","name=pvstringArray")
|
||||
dbLoadRecords("db/dbEnum.db","name=pvenum")
|
||||
dbLoadRecords("db/dbCounter.db","name=pvcounter");
|
||||
|
||||
cd ${TOP}/iocBoot/${IOC}
|
||||
iocInit()
|
||||
dbl
|
||||
epicsThreadSleep(1.0)
|
||||
exampleRPCCreateRecord mydevice
|
||||
startPVAServer
|
||||
pvdbl
|
||||
|
43
exampleRPC/src/Makefile
Normal file
43
exampleRPC/src/Makefile
Normal file
@ -0,0 +1,43 @@
|
||||
TOP=..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
#----------------------------------------
|
||||
# ADD MACRO DEFINITIONS AFTER THIS LINE
|
||||
#=============================
|
||||
|
||||
#==================================================
|
||||
# Build an IOC support library
|
||||
#
|
||||
|
||||
|
||||
DBD += exampleRPC.dbd
|
||||
|
||||
INC += exampleRPC.h
|
||||
|
||||
LIBRARY_IOC += exampleRPC
|
||||
exampleRPC_SRCS += exampleRPC.cpp
|
||||
exampleRPC_SRCS += exampleRPCRegister.cpp
|
||||
exampleRPC_LIBS += pvDatabase
|
||||
exampleRPC_LIBS += pvAccess
|
||||
exampleRPC_LIBS += pvData
|
||||
exampleRPC_LIBS += Com
|
||||
exampleRPC_LIBS += $(EPICS_BASE_IOC_LIBS)
|
||||
|
||||
PROD_HOST += exampleRPCMain
|
||||
exampleRPCMain_SRCS += exampleRPCMain.cpp
|
||||
exampleRPCMain_LIBS += exampleRPC
|
||||
exampleRPCMain_LIBS += pvDatabase
|
||||
exampleRPCMain_LIBS += pvAccess
|
||||
exampleRPCMain_LIBS += pvData
|
||||
exampleRPCMain_LIBS += Com
|
||||
|
||||
PROD_HOST += move
|
||||
move_SRCS += positionClient.cpp
|
||||
move_LIBS += pvAccess pvData Com
|
||||
|
||||
#===========================
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
#----------------------------------------
|
||||
# ADD RULES AFTER THIS LINE
|
||||
|
213
exampleRPC/src/exampleRPC.cpp
Normal file
213
exampleRPC/src/exampleRPC.cpp
Normal file
@ -0,0 +1,213 @@
|
||||
/* exampleRPC.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 dgh
|
||||
* @date 2015.12.08
|
||||
*/
|
||||
|
||||
#include <pv/standardField.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include <pv/exampleRPC.h>
|
||||
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
|
||||
#include <epicsThread.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvDatabase;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using std::string;
|
||||
|
||||
namespace epics { namespace exampleRPC {
|
||||
|
||||
|
||||
PVStructurePtr ExampleRPCService::request(
|
||||
PVStructure::shared_pointer const & args
|
||||
) throw (epics::pvAccess::RPCRequestException)
|
||||
{
|
||||
bool haveControl = pvRecord->takeControl();
|
||||
if (!haveControl)
|
||||
throw pvAccess::RPCRequestException(Status::STATUSTYPE_ERROR,
|
||||
"I'm busy");
|
||||
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
|
||||
PVStructureArrayPtr valueField = args->getSubField<PVStructureArray>("value");
|
||||
if (valueField.get() == 0)
|
||||
throw pvAccess::RPCRequestException(Status::STATUSTYPE_ERROR,
|
||||
"No structure array value field");
|
||||
|
||||
StructureConstPtr valueFieldStructure = valueField->
|
||||
getStructureArray()->getStructure();
|
||||
|
||||
ScalarConstPtr xField = valueFieldStructure->getField<Scalar>("x");
|
||||
if (xField.get() == 0 || xField->getScalarType() != pvDouble)
|
||||
throw pvAccess::RPCRequestException(Status::STATUSTYPE_ERROR,
|
||||
"value field's structure has no double field x");
|
||||
|
||||
ScalarConstPtr yField = valueFieldStructure->getField<Scalar>("y");
|
||||
if (xField.get() == 0 || xField->getScalarType() != pvDouble)
|
||||
throw pvAccess::RPCRequestException(Status::STATUSTYPE_ERROR,
|
||||
"value field's structure has no double field y");
|
||||
|
||||
PVStructureArray::const_svector vals = valueField->view();
|
||||
|
||||
for (PVStructureArray::const_svector::const_iterator it = vals.begin();
|
||||
it != vals.end(); ++it)
|
||||
{
|
||||
double x = (*it)->getSubFieldT<PVDouble>("x")->get();
|
||||
double y = (*it)->getSubFieldT<PVDouble>("y")->get();
|
||||
pvRecord->put(x,y);
|
||||
epicsThreadSleep(1.0);
|
||||
}
|
||||
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
createStructure();
|
||||
|
||||
PVStructurePtr returned = pvDataCreate->createPVStructure(topStructure);
|
||||
pvRecord->releaseControl();
|
||||
return returned;
|
||||
}
|
||||
|
||||
void ExampleRPCServiceAsync::request(
|
||||
epics::pvData::PVStructurePtr const & args,
|
||||
epics::pvAccess::RPCResponseCallback::shared_pointer const & callback)
|
||||
{
|
||||
bool haveControl = pvRecord->takeControl();
|
||||
if (!haveControl)
|
||||
throw pvAccess::RPCRequestException(Status::STATUSTYPE_ERROR,
|
||||
"I'm busy");
|
||||
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
|
||||
PVStructureArrayPtr valueField = args->getSubField<PVStructureArray>("value");
|
||||
if (valueField.get() == 0)
|
||||
throw pvAccess::RPCRequestException(Status::STATUSTYPE_ERROR,
|
||||
"No structure array value field");
|
||||
|
||||
StructureConstPtr valueFieldStructure = valueField->
|
||||
getStructureArray()->getStructure();
|
||||
|
||||
ScalarConstPtr xField = valueFieldStructure->getField<Scalar>("x");
|
||||
if (xField.get() == 0 || xField->getScalarType() != pvDouble)
|
||||
throw pvAccess::RPCRequestException(Status::STATUSTYPE_ERROR,
|
||||
"value field's structure has no double field x");
|
||||
|
||||
ScalarConstPtr yField = valueFieldStructure->getField<Scalar>("y");
|
||||
if (yField.get() == 0 || yField->getScalarType() != pvDouble)
|
||||
throw pvAccess::RPCRequestException(Status::STATUSTYPE_ERROR,
|
||||
"value field's structure has no double field y");
|
||||
|
||||
PVStructureArray::const_svector vals = valueField->view();
|
||||
|
||||
for (PVStructureArray::const_svector::const_iterator it = vals.begin();
|
||||
it != vals.end(); ++it)
|
||||
{
|
||||
double x = (*it)->getSubFieldT<PVDouble>("x")->get();
|
||||
double y = (*it)->getSubFieldT<PVDouble>("y")->get();
|
||||
pvRecord->put(x,y);
|
||||
epicsThreadSleep(1.0);
|
||||
}
|
||||
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
createStructure();
|
||||
|
||||
PVStructurePtr returned = pvDataCreate->createPVStructure(topStructure);
|
||||
pvRecord->releaseControl();
|
||||
callback->requestDone(Status::Ok, returned);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ExampleRPCPtr ExampleRPC::create(
|
||||
string const & recordName)
|
||||
{
|
||||
StandardFieldPtr standardField = getStandardField();
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
add("x",pvDouble)->
|
||||
add("y",pvDouble)->
|
||||
add("timeStamp",standardField->timeStamp()) ->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
|
||||
ExampleRPCPtr pvRecord(
|
||||
new ExampleRPC(recordName,pvStructure));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
ExampleRPC::ExampleRPC(
|
||||
string const & recordName,
|
||||
PVStructurePtr const & pvStructure)
|
||||
: PVRecord(recordName,pvStructure)
|
||||
{
|
||||
}
|
||||
|
||||
ExampleRPC::~ExampleRPC()
|
||||
{
|
||||
}
|
||||
|
||||
void ExampleRPC::destroy()
|
||||
{
|
||||
PVRecord::destroy();
|
||||
}
|
||||
|
||||
bool ExampleRPC::init()
|
||||
{
|
||||
|
||||
initPVRecord();
|
||||
|
||||
service = ExampleRPCService::create(
|
||||
std::tr1::dynamic_pointer_cast<ExampleRPC>(
|
||||
shared_from_this()));
|
||||
|
||||
PVFieldPtr pvField;
|
||||
pvTimeStamp.attach(getPVStructure()->getSubField("timeStamp"));
|
||||
return true;
|
||||
}
|
||||
|
||||
epics::pvAccess::Service::shared_pointer ExampleRPC::getService(
|
||||
PVStructurePtr const & /*pvRequest*/)
|
||||
{
|
||||
return service;
|
||||
}
|
||||
|
||||
bool ExampleRPC::takeControl()
|
||||
{
|
||||
return taskMutex.tryLock();
|
||||
}
|
||||
|
||||
void ExampleRPC::releaseControl()
|
||||
{
|
||||
taskMutex.unlock();
|
||||
}
|
||||
|
||||
void ExampleRPC::put(double x, double y)
|
||||
{
|
||||
lock();
|
||||
beginGroupPut();
|
||||
getPVStructure()->getSubField<PVDouble>("x")->put(x);
|
||||
getPVStructure()->getSubField<PVDouble>("y")->put(y);
|
||||
endGroupPut();
|
||||
process();
|
||||
unlock();
|
||||
}
|
||||
|
||||
void ExampleRPC::process()
|
||||
{
|
||||
timeStamp.getCurrent();
|
||||
pvTimeStamp.set(timeStamp);
|
||||
}
|
||||
|
||||
|
||||
}}
|
126
exampleRPC/src/exampleRPC.h
Normal file
126
exampleRPC/src/exampleRPC.h
Normal file
@ -0,0 +1,126 @@
|
||||
/* exampleRPC.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 dgh
|
||||
* @date 2015.12.08
|
||||
*/
|
||||
#ifndef EXAMPLERPC_H
|
||||
#define EXAMPLERPC_H
|
||||
|
||||
#ifdef epicsExportSharedSymbols
|
||||
# define exampleRPCEpicsExportSharedSymbols
|
||||
# undef epicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
|
||||
#ifdef exampleRPCEpicsExportSharedSymbols
|
||||
# define epicsExportSharedSymbols
|
||||
# undef exampleRPCEpicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
|
||||
namespace epics { namespace exampleRPC {
|
||||
|
||||
class ExampleRPCService;
|
||||
typedef std::tr1::shared_ptr<ExampleRPCService> ExampleRPCServicePtr;
|
||||
|
||||
class ExampleRPCServiceAsync;
|
||||
typedef std::tr1::shared_ptr<ExampleRPCServiceAsync> ExampleRPCServiceAsyncPtr;
|
||||
|
||||
|
||||
class ExampleRPC;
|
||||
typedef std::tr1::shared_ptr<ExampleRPC> ExampleRPCPtr;
|
||||
|
||||
|
||||
|
||||
class epicsShareClass ExampleRPCService :
|
||||
public virtual epics::pvAccess::RPCService
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(ExampleRPCService);
|
||||
|
||||
static ExampleRPCService::shared_pointer create(ExampleRPCPtr const & pvRecord)
|
||||
{
|
||||
return ExampleRPCServicePtr(new ExampleRPCService(pvRecord));
|
||||
}
|
||||
~ExampleRPCService() {};
|
||||
|
||||
epics::pvData::PVStructurePtr request(
|
||||
epics::pvData::PVStructure::shared_pointer const & args
|
||||
) throw (epics::pvAccess::RPCRequestException);
|
||||
private:
|
||||
ExampleRPCService(ExampleRPCPtr const & pvRecord)
|
||||
: pvRecord(pvRecord)
|
||||
{
|
||||
}
|
||||
|
||||
ExampleRPCPtr pvRecord;
|
||||
};
|
||||
|
||||
|
||||
class ExampleRPCServiceAsync :
|
||||
public epics::pvAccess::RPCServiceAsync
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(ExampleRPCServiceAsync);
|
||||
|
||||
static ExampleRPCServiceAsync::shared_pointer create(ExampleRPCPtr const & pvRecord)
|
||||
{
|
||||
return ExampleRPCServiceAsyncPtr(new ExampleRPCServiceAsync(pvRecord));
|
||||
}
|
||||
|
||||
void request(epics::pvData::PVStructurePtr const & args,
|
||||
epics::pvAccess::RPCResponseCallback::shared_pointer const & callback);
|
||||
private:
|
||||
ExampleRPCServiceAsync(ExampleRPCPtr const & pvRecord)
|
||||
: pvRecord(pvRecord)
|
||||
{
|
||||
}
|
||||
|
||||
ExampleRPCPtr pvRecord;
|
||||
};
|
||||
|
||||
class ExampleRPC;
|
||||
typedef std::tr1::shared_ptr<ExampleRPC> ExampleRPCPtr;
|
||||
|
||||
class epicsShareClass ExampleRPC :
|
||||
public epics::pvDatabase::PVRecord
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(ExampleRPC);
|
||||
static ExampleRPCPtr create(
|
||||
std::string const & recordName);
|
||||
virtual ~ExampleRPC();
|
||||
virtual void destroy();
|
||||
virtual bool init();
|
||||
virtual void process();
|
||||
virtual epics::pvAccess::Service::shared_pointer getService(
|
||||
epics::pvData::PVStructurePtr const & pvRequest);
|
||||
void put(double x, double y);
|
||||
|
||||
bool takeControl();
|
||||
void releaseControl();
|
||||
private:
|
||||
|
||||
ExampleRPC(std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
|
||||
epics::pvData::PVTimeStamp pvTimeStamp;
|
||||
epics::pvData::TimeStamp timeStamp;
|
||||
epics::pvData::Mutex taskMutex;
|
||||
epics::pvAccess::Service::shared_pointer service;
|
||||
};
|
||||
|
||||
|
||||
}}
|
||||
|
||||
#endif /* EXAMPLERPC_H */
|
1
exampleRPC/src/exampleRPCInclude.dbd
Normal file
1
exampleRPC/src/exampleRPCInclude.dbd
Normal file
@ -0,0 +1 @@
|
||||
registrar("exampleRPCRegister")
|
48
exampleRPC/src/exampleRPCMain.cpp
Normal file
48
exampleRPC/src/exampleRPCMain.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*ExampleRPCMain.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
|
||||
*/
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <pv/exampleRPC.h>
|
||||
#include <pv/channelProviderLocal.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvDatabase;
|
||||
using namespace epics::exampleRPC;
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
PVDatabasePtr master = PVDatabase::getMaster();
|
||||
PVRecordPtr pvRecord;
|
||||
bool result = false;
|
||||
string recordName;
|
||||
|
||||
recordName = "mydevice";
|
||||
pvRecord = ExampleRPC::create(recordName);
|
||||
result = master->addRecord(pvRecord);
|
||||
if(!result) cout<< "record " << recordName << " not added" << endl;
|
||||
|
||||
ContextLocal::shared_pointer contextLocal = ContextLocal::create();
|
||||
contextLocal->start();
|
||||
|
||||
PVStringArrayPtr pvNames = master->getRecordNames();
|
||||
shared_vector<const string> names = pvNames->view();
|
||||
for(size_t i=0; i<names.size(); ++i) cout << names[i] << endl;
|
||||
|
||||
contextLocal->waitForExit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
71
exampleRPC/src/exampleRPCRegister.cpp
Normal file
71
exampleRPC/src/exampleRPCRegister.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*exampleRPCRegister.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.07.24
|
||||
*/
|
||||
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
#include <cantProceed.h>
|
||||
#include <epicsStdio.h>
|
||||
#include <epicsMutex.h>
|
||||
#include <epicsEvent.h>
|
||||
#include <epicsThread.h>
|
||||
#include <iocsh.h>
|
||||
|
||||
#include <pv/pvIntrospect.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/pvDatabase.h>
|
||||
|
||||
#include <epicsExport.h>
|
||||
#include <pv/exampleRPC.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvDatabase;
|
||||
using namespace epics::exampleRPC;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
static const iocshArg testArg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg *testArgs[] = {
|
||||
&testArg0};
|
||||
|
||||
static const iocshFuncDef exampleRPCFuncDef = {
|
||||
"exampleRPCCreateRecord", 1, testArgs};
|
||||
static void exampleRPCCallFunc(const iocshArgBuf *args)
|
||||
{
|
||||
PVDatabasePtr master = PVDatabase::getMaster();
|
||||
char *recordName = args[0].sval;
|
||||
ExampleRPCPtr record = ExampleRPC::create(recordName);
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname" << " not added" << endl;
|
||||
}
|
||||
|
||||
static void exampleRPCRegister(void)
|
||||
{
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
iocshRegister(&exampleRPCFuncDef, exampleRPCCallFunc);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
epicsExportRegistrar(exampleRPCRegister);
|
||||
}
|
1
exampleRPC/src/exampleRPCRegister.dbd
Normal file
1
exampleRPC/src/exampleRPCRegister.dbd
Normal file
@ -0,0 +1 @@
|
||||
registrar("exampleRPCRegister")
|
126
exampleRPC/src/positionClient.cpp
Normal file
126
exampleRPC/src/positionClient.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS exampleCPP is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/clientFactory.h>
|
||||
#include <pv/rpcClient.h>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
|
||||
static StructureConstPtr makeDeviceStructure()
|
||||
{
|
||||
static StructureConstPtr deviceStructure;
|
||||
if (deviceStructure.get() == 0)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
|
||||
deviceStructure = fieldCreate->createFieldBuilder()->
|
||||
add("x",pvDouble)->
|
||||
add("y",pvDouble)->
|
||||
createStructure();
|
||||
}
|
||||
return deviceStructure;
|
||||
}
|
||||
|
||||
|
||||
static StructureConstPtr makeArgumentStructure()
|
||||
{
|
||||
static StructureConstPtr requestStructure;
|
||||
if (requestStructure.get() == 0)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
|
||||
requestStructure = fieldCreate->createFieldBuilder()->
|
||||
addArray("value", makeDeviceStructure())->
|
||||
createStructure();
|
||||
}
|
||||
return requestStructure;
|
||||
}
|
||||
|
||||
// Set a pvAccess connection timeout, after which the client gives up trying
|
||||
// to connect to server.
|
||||
const static double REQUEST_TIMEOUT = 3.0;
|
||||
const static std::string DEVICE_NAME = "mydevice";
|
||||
const static std::string APP_NAME = "move";
|
||||
|
||||
void usage()
|
||||
{
|
||||
std::cout << "Usage: " << APP_NAME << " [x_1 y_1] ... [x_n y_n]\n"
|
||||
<< "Sequentially sets the values of the x and y fields of "
|
||||
<< DEVICE_NAME << " to (x_i,y_i).\n"
|
||||
<< "Returns on completion."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
std::string arg(argv[i]);
|
||||
if (arg == "-h" || arg == "--help")
|
||||
{
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((argc % 2) != 1)
|
||||
{
|
||||
std::cerr << APP_NAME << " requires an even number of arguments."
|
||||
<< std::endl;
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
// Start the pvAccess client side.
|
||||
epics::pvAccess::ClientFactory::start();
|
||||
|
||||
try
|
||||
{
|
||||
PVStructurePtr arguments(getPVDataCreate()->createPVStructure(makeArgumentStructure()));
|
||||
|
||||
PVStructureArray::svector values;
|
||||
|
||||
for (int i = 1; i < argc; )
|
||||
{
|
||||
PVStructurePtr point(getPVDataCreate()->createPVStructure(makeDeviceStructure()));
|
||||
point->getSubField<PVDouble>("x")->put(atof(argv[i++]));
|
||||
point->getSubField<PVDouble>("y")->put(atof(argv[i++]));
|
||||
values.push_back(point);
|
||||
}
|
||||
|
||||
arguments->getSubField<PVStructureArray>("value")->replace(freeze(values));
|
||||
|
||||
epics::pvAccess::RPCClient::shared_pointer client
|
||||
= epics::pvAccess::RPCClient::create(DEVICE_NAME);
|
||||
|
||||
PVStructurePtr response = client->request(arguments,
|
||||
REQUEST_TIMEOUT + 1.0 * (argc/2));
|
||||
|
||||
std::cout << "Done" << std::endl;
|
||||
}
|
||||
catch (epics::pvAccess::RPCRequestException & ex)
|
||||
{
|
||||
std::cerr << "Operation failed. RPCException:" << std::endl;
|
||||
std::cerr << ex.what() << std::endl;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Catch any other exceptions so we always call ClientFactory::stop().
|
||||
std::cerr << "Unexpected exception." << std::endl;
|
||||
}
|
||||
|
||||
// Stop pvAccess client, so that this application exits cleanly.
|
||||
epics::pvAccess::ClientFactory::stop();
|
||||
|
||||
return 0;
|
||||
}
|
@ -23,6 +23,7 @@
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvCopy.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
|
||||
#ifdef pvdatabaseEpicsExportSharedSymbols
|
||||
# define epicsExportSharedSymbols
|
||||
@ -189,6 +190,17 @@ public:
|
||||
bool removeListener(
|
||||
PVListenerPtr const & pvListener,
|
||||
epics::pvData::PVCopyPtr const & pvCopy);
|
||||
/**
|
||||
* Return a service corresponding to the specified request PVStructure.
|
||||
* @param pvRequest The request PVStructure
|
||||
* @return The corresponding service
|
||||
*/
|
||||
virtual epics::pvAccess::Service::shared_pointer getService(
|
||||
epics::pvData::PVStructurePtr const & pvRequest)
|
||||
{
|
||||
return epics::pvAccess::Service::shared_pointer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Begins a group of puts.
|
||||
*/
|
||||
|
@ -750,6 +750,233 @@ void ChannelPutGetLocal::getGet()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ChannelRPCLocal :
|
||||
public ChannelRPC,
|
||||
public RPCResponseCallback,
|
||||
public std::tr1::enable_shared_from_this<ChannelRPCLocal>
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(ChannelRPCLocal);
|
||||
static ChannelRPCLocalPtr create(
|
||||
ChannelLocalPtr const & channelLocal,
|
||||
ChannelRPCRequester::shared_pointer const & channelRPCRequester,
|
||||
PVStructurePtr const & pvRequest,
|
||||
PVRecordPtr const & pvRecord);
|
||||
|
||||
ChannelRPCLocal(
|
||||
ChannelLocalPtr const & channelLocal,
|
||||
ChannelRPCRequester::shared_pointer const & channelRPCRequester,
|
||||
Service::shared_pointer const & service,
|
||||
PVRecordPtr const & pvRecord) :
|
||||
isDestroyed(),
|
||||
channelLocal(channelLocal),
|
||||
channelRPCRequester(channelRPCRequester),
|
||||
service(service),
|
||||
pvRecord(pvRecord),
|
||||
isLastRequest()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~ChannelRPCLocal()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "~ChannelRPCLocal()" << endl;
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
|
||||
void processRequest(RPCService::shared_pointer const & service,
|
||||
PVStructurePtr const & pvArgument);
|
||||
|
||||
virtual void requestDone(Status const & status,
|
||||
PVStructurePtr const & result)
|
||||
{
|
||||
channelRPCRequester->requestDone(status, getPtrSelf(), result);
|
||||
|
||||
if (isLastRequest.get())
|
||||
destroy();
|
||||
}
|
||||
|
||||
void processRequest(RPCServiceAsync::shared_pointer const & service,
|
||||
PVStructurePtr const & pvArgument);
|
||||
|
||||
virtual void request(PVStructurePtr const & pvArgument);
|
||||
|
||||
void lastRequest()
|
||||
{
|
||||
isLastRequest.set();
|
||||
}
|
||||
|
||||
virtual Channel::shared_pointer getChannel()
|
||||
{
|
||||
return channelLocal;
|
||||
}
|
||||
|
||||
virtual void cancel() {}
|
||||
|
||||
virtual void destroy();
|
||||
|
||||
virtual void lock() {}
|
||||
|
||||
virtual void unlock() {}
|
||||
|
||||
private:
|
||||
|
||||
shared_pointer getPtrSelf()
|
||||
{
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
AtomicBoolean isDestroyed;
|
||||
ChannelLocalPtr channelLocal;
|
||||
ChannelRPCRequester::shared_pointer channelRPCRequester;
|
||||
Service::shared_pointer service;
|
||||
PVRecordPtr pvRecord;
|
||||
AtomicBoolean isLastRequest;
|
||||
};
|
||||
|
||||
ChannelRPCLocalPtr ChannelRPCLocal::create(
|
||||
ChannelLocalPtr const &channelLocal,
|
||||
ChannelRPCRequester::shared_pointer const & channelRPCRequester,
|
||||
PVStructurePtr const & pvRequest,
|
||||
PVRecordPtr const &pvRecord)
|
||||
{
|
||||
Service::shared_pointer service = pvRecord->getService(pvRequest);
|
||||
if (service.get() == 0)
|
||||
{
|
||||
Status status(Status::STATUSTYPE_ERROR,
|
||||
"ChannelRPC not supported");
|
||||
channelRPCRequester->channelRPCConnect(status,ChannelRPCLocalPtr());
|
||||
return ChannelRPCLocalPtr();
|
||||
}
|
||||
|
||||
if (channelRPCRequester.get() == 0)
|
||||
throw std::invalid_argument("channelRPCRequester == null");
|
||||
|
||||
// TODO use std::make_shared
|
||||
ChannelRPCLocalPtr rpc(
|
||||
new ChannelRPCLocal(channelLocal, channelRPCRequester, service, pvRecord)
|
||||
);
|
||||
channelRPCRequester->channelRPCConnect(Status::Ok, rpc);
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "ChannelRPCLocal::create";
|
||||
cout << " recordName " << pvRecord->getRecordName() << endl;
|
||||
}
|
||||
return rpc;
|
||||
}
|
||||
|
||||
void ChannelRPCLocal::processRequest(
|
||||
RPCService::shared_pointer const & service,
|
||||
PVStructurePtr const & pvArgument)
|
||||
{
|
||||
PVStructurePtr result;
|
||||
Status status = Status::Ok;
|
||||
bool ok = true;
|
||||
try
|
||||
{
|
||||
result = service->request(pvArgument);
|
||||
}
|
||||
catch (RPCRequestException& rre)
|
||||
{
|
||||
status = Status(rre.getStatus(), rre.what());
|
||||
ok = false;
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
status = Status(Status::STATUSTYPE_FATAL, ex.what());
|
||||
ok = false;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// handle user unexpected errors
|
||||
status = Status(Status::STATUSTYPE_FATAL, "Unexpected exception caught while calling RPCService.request(PVStructure).");
|
||||
ok = false;
|
||||
}
|
||||
|
||||
// check null result
|
||||
if (ok && result.get() == 0)
|
||||
{
|
||||
status = Status(Status::STATUSTYPE_FATAL, "RPCService.request(PVStructure) returned null.");
|
||||
}
|
||||
|
||||
channelRPCRequester->requestDone(status, getPtrSelf(), result);
|
||||
|
||||
if (isLastRequest.get())
|
||||
destroy();
|
||||
}
|
||||
|
||||
void ChannelRPCLocal::processRequest(
|
||||
RPCServiceAsync::shared_pointer const & service,
|
||||
PVStructurePtr const & pvArgument)
|
||||
{
|
||||
try
|
||||
{
|
||||
service->request(pvArgument, getPtrSelf());
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
// handle user unexpected errors
|
||||
Status errorStatus(Status::STATUSTYPE_FATAL, ex.what());
|
||||
|
||||
channelRPCRequester->requestDone(errorStatus, getPtrSelf(), PVStructurePtr());
|
||||
|
||||
if (isLastRequest.get())
|
||||
destroy();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// handle user unexpected errors
|
||||
Status errorStatus(Status::STATUSTYPE_FATAL,
|
||||
"Unexpected exception caught while calling RPCServiceAsync.request(PVStructure, RPCResponseCallback).");
|
||||
|
||||
channelRPCRequester->requestDone(errorStatus, shared_from_this(), PVStructurePtr());
|
||||
|
||||
if (isLastRequest.get())
|
||||
destroy();
|
||||
}
|
||||
|
||||
// we wait for callback to be called
|
||||
}
|
||||
|
||||
|
||||
void ChannelRPCLocal::request(PVStructurePtr const & pvArgument)
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "ChannelRPCLocal::request" << endl;
|
||||
}
|
||||
RPCService::shared_pointer rpcService =
|
||||
std::tr1::dynamic_pointer_cast<RPCService>(service);
|
||||
if (rpcService)
|
||||
{
|
||||
processRequest(rpcService, pvArgument);
|
||||
return;
|
||||
}
|
||||
|
||||
RPCServiceAsync::shared_pointer rpcServiceAsync =
|
||||
std::tr1::dynamic_pointer_cast<RPCServiceAsync>(service);
|
||||
if (rpcServiceAsync)
|
||||
{
|
||||
processRequest(rpcServiceAsync, pvArgument);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChannelRPCLocal::destroy()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "ChannelRPCLocal::destroy";
|
||||
cout << " destroyed " << isDestroyed.get() << endl;
|
||||
}
|
||||
isDestroyed.set();
|
||||
}
|
||||
|
||||
|
||||
typedef std::tr1::shared_ptr<PVArray> PVArrayPtr;
|
||||
|
||||
class ChannelArrayLocal :
|
||||
@ -1209,10 +1436,13 @@ ChannelRPC::shared_pointer ChannelLocal::createChannelRPC(
|
||||
ChannelRPCRequester::shared_pointer const & channelRPCRequester,
|
||||
PVStructure::shared_pointer const & pvRequest)
|
||||
{
|
||||
Status status(Status::STATUSTYPE_ERROR,
|
||||
"ChannelRPC not supported");
|
||||
channelRPCRequester->channelRPCConnect(status,ChannelRPC::shared_pointer());
|
||||
return ChannelRPC::shared_pointer();
|
||||
ChannelRPCLocalPtr channelRPC =
|
||||
ChannelRPCLocal::create(
|
||||
getPtrSelf(),
|
||||
channelRPCRequester,
|
||||
pvRequest,
|
||||
pvRecord);
|
||||
return channelRPC;
|
||||
}
|
||||
|
||||
Monitor::shared_pointer ChannelLocal::createMonitor(
|
||||
|
Reference in New Issue
Block a user