Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a96ec158bc |
@@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e -x
|
||||
|
||||
make -j2 $EXTRA
|
||||
|
||||
if [ "$TEST" != "NO" ]
|
||||
then
|
||||
make -j2 tapfiles
|
||||
make -j2 -s test-results
|
||||
fi
|
||||
@@ -1,109 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e -x
|
||||
|
||||
CURDIR="$PWD"
|
||||
|
||||
cat << EOF > $CURDIR/configure/RELEASE.local
|
||||
EPICS_BASE=$HOME/.source/epics-base
|
||||
EOF
|
||||
|
||||
install -d "$HOME/.source"
|
||||
cd "$HOME/.source"
|
||||
|
||||
add_gh_flat() {
|
||||
MODULE=$1
|
||||
REPOOWNER=$2
|
||||
REPONAME=$3
|
||||
BRANCH=$4
|
||||
MODULE_UC=$(echo $MODULE | tr 'a-z' 'A-Z')
|
||||
( git clone --quiet --depth 5 --branch $BRANCH https://github.com/$REPOOWNER/$REPONAME.git $MODULE && \
|
||||
cd $MODULE && git log -n1 )
|
||||
cat < $CURDIR/configure/RELEASE.local > $MODULE/configure/RELEASE.local
|
||||
cat << EOF >> $CURDIR/configure/RELEASE.local
|
||||
${MODULE_UC}=$HOME/.source/$MODULE
|
||||
EOF
|
||||
}
|
||||
|
||||
# not recursive
|
||||
git clone --quiet --depth 5 --branch "$BRBASE" https://github.com/${REPOBASE:-epics-base}/epics-base.git epics-base
|
||||
(cd epics-base && git log -n1 )
|
||||
add_gh_flat pvData ${REPOPVD:-epics-base} pvDataCPP ${BRPVD:-master}
|
||||
add_gh_flat pvAccess ${REPOPVA:-epics-base} pvAccessCPP ${BRPVA:-master}
|
||||
|
||||
if [ -e $CURDIR/configure/RELEASE.local ]
|
||||
then
|
||||
cat $CURDIR/configure/RELEASE.local
|
||||
fi
|
||||
|
||||
EPICS_HOST_ARCH=`sh epics-base/startup/EpicsHostArch`
|
||||
|
||||
# requires wine and g++-mingw-w64-i686
|
||||
if [ "$WINE" = "32" ]
|
||||
then
|
||||
echo "Cross mingw32"
|
||||
sed -i -e '/CMPLR_PREFIX/d' epics-base/configure/os/CONFIG_SITE.linux-x86.win32-x86-mingw
|
||||
cat << EOF >> epics-base/configure/os/CONFIG_SITE.linux-x86.win32-x86-mingw
|
||||
CMPLR_PREFIX=i686-w64-mingw32-
|
||||
EOF
|
||||
cat << EOF >> epics-base/configure/CONFIG_SITE
|
||||
CROSS_COMPILER_TARGET_ARCHS+=win32-x86-mingw
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [ "$STATIC" = "YES" ]
|
||||
then
|
||||
echo "Build static libraries/executables"
|
||||
cat << EOF >> epics-base/configure/CONFIG_SITE
|
||||
SHARED_LIBRARIES=NO
|
||||
STATIC_BUILD=YES
|
||||
EOF
|
||||
fi
|
||||
|
||||
case "$CMPLR" in
|
||||
clang)
|
||||
echo "Host compiler is clang"
|
||||
cat << EOF >> epics-base/configure/os/CONFIG_SITE.Common.$EPICS_HOST_ARCH
|
||||
GNU = NO
|
||||
CMPLR_CLASS = clang
|
||||
CC = clang
|
||||
CCC = clang++
|
||||
EOF
|
||||
|
||||
# hack
|
||||
sed -i -e 's/CMPLR_CLASS = gcc/CMPLR_CLASS = clang/' epics-base/configure/CONFIG.gnuCommon
|
||||
|
||||
clang --version
|
||||
;;
|
||||
*)
|
||||
echo "Host compiler is default"
|
||||
gcc --version
|
||||
;;
|
||||
esac
|
||||
|
||||
cat <<EOF >> epics-base/configure/CONFIG_SITE
|
||||
USR_CPPFLAGS += $USR_CPPFLAGS
|
||||
USR_CFLAGS += $USR_CFLAGS
|
||||
USR_CXXFLAGS += $USR_CXXFLAGS
|
||||
EOF
|
||||
|
||||
# set RTEMS to eg. "4.9" or "4.10"
|
||||
# requires qemu, bison, flex, texinfo, install-info
|
||||
if [ -n "$RTEMS" ]
|
||||
then
|
||||
echo "Cross RTEMS${RTEMS} for pc386"
|
||||
curl -L "https://github.com/mdavidsaver/rsb/releases/download/20171203-${RTEMS}/i386-rtems${RTEMS}-trusty-20171203-${RTEMS}.tar.bz2" \
|
||||
| tar -C / -xmj
|
||||
|
||||
sed -i -e '/^RTEMS_VERSION/d' -e '/^RTEMS_BASE/d' epics-base/configure/os/CONFIG_SITE.Common.RTEMS
|
||||
cat << EOF >> epics-base/configure/os/CONFIG_SITE.Common.RTEMS
|
||||
RTEMS_VERSION=$RTEMS
|
||||
RTEMS_BASE=$HOME/.rtems
|
||||
EOF
|
||||
cat << EOF >> epics-base/configure/CONFIG_SITE
|
||||
CROSS_COMPILER_TARGET_ARCHS += RTEMS-pc386-qemu
|
||||
EOF
|
||||
fi
|
||||
|
||||
make -j2 -C epics-base $EXTRA
|
||||
make -j2 -C pvData $EXTRA
|
||||
make -j2 -C pvAccess $EXTRA
|
||||
28
.gitignore
vendored
28
.gitignore
vendored
@@ -1,17 +1,13 @@
|
||||
/cfg/
|
||||
/bin/
|
||||
/lib/
|
||||
/db/
|
||||
/dbd/
|
||||
/html/
|
||||
/include/
|
||||
/templates/
|
||||
/configure/*.local
|
||||
/documentation/html
|
||||
/documentation/*.tag
|
||||
O.*/
|
||||
/QtC-*
|
||||
bin/
|
||||
lib/
|
||||
doc/
|
||||
include/
|
||||
db/
|
||||
dbd/
|
||||
documentation/html
|
||||
documentation/*.tag
|
||||
envPaths
|
||||
*.orig
|
||||
*.log
|
||||
.*.swp
|
||||
configure/*.local
|
||||
!configure/ExampleRELEASE.local
|
||||
**/O.*
|
||||
QtC-*
|
||||
@@ -1,17 +0,0 @@
|
||||
# .readthedocs.yml
|
||||
# Read the Docs configuration file
|
||||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||
|
||||
# Required
|
||||
version: 2
|
||||
|
||||
# Build documentation in the documentation/ directory with Sphinx
|
||||
sphinx:
|
||||
configuration: documentation/conf.py
|
||||
|
||||
# Build documentation with MkDocs
|
||||
#mkdocs:
|
||||
# configuration: mkdocs.yml
|
||||
|
||||
# Optionally build your docs in additional formats such as PDF and ePub
|
||||
formats: all
|
||||
31
.travis.yml
31
.travis.yml
@@ -1,31 +0,0 @@
|
||||
sudo: false
|
||||
dist: trusty
|
||||
language: c++
|
||||
compiler:
|
||||
- gcc
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libreadline6-dev
|
||||
- libncurses5-dev
|
||||
- perl
|
||||
- clang
|
||||
- g++-mingw-w64-i686
|
||||
- qemu-system-x86
|
||||
install:
|
||||
- ./.ci/travis-prepare.sh
|
||||
script:
|
||||
- ./.ci/travis-build.sh
|
||||
env:
|
||||
- BRBASE=7.0
|
||||
- BRBASE=7.0 CMPLR=clang
|
||||
- BRBASE=7.0 EXTRA="CMD_CXXFLAGS=-std=c++98"
|
||||
- BRBASE=7.0 EXTRA="CMD_CXXFLAGS=-std=c++11"
|
||||
- BRBASE=7.0 CMPLR=clang EXTRA="CMD_CXXFLAGS=-std=c++11"
|
||||
- BRBASE=7.0 WINE=32 TEST=NO STATIC=YES
|
||||
- BRBASE=7.0 WINE=32 TEST=NO STATIC=NO
|
||||
- BRBASE=7.0 RTEMS=4.10 TEST=NO
|
||||
- BRBASE=7.0 RTEMS=4.9 TEST=NO
|
||||
- BRBASE=3.16
|
||||
- BRBASE=3.15
|
||||
|
||||
6
Doxyfile
6
Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME = pvDatabaseCPP
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = 4.7.1
|
||||
PROJECT_NUMBER =
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
@@ -765,7 +765,7 @@ WARN_LOGFILE =
|
||||
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
|
||||
# Note: If this tag is empty the current directory is searched.
|
||||
|
||||
INPUT = src
|
||||
INPUT = include
|
||||
|
||||
# This tag can be used to specify the character encoding of the source files
|
||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||
@@ -1035,7 +1035,7 @@ GENERATE_HTML = YES
|
||||
# The default directory is: html.
|
||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||
|
||||
HTML_OUTPUT = html/doxygen
|
||||
HTML_OUTPUT = documentation/html
|
||||
|
||||
# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each
|
||||
# generated HTML page (for example: .htm, .php, .asp).
|
||||
|
||||
43
README.md
43
README.md
@@ -1,21 +1,38 @@
|
||||
# pvDatabaseCPP
|
||||
pvaDatabaseCPP
|
||||
============
|
||||
|
||||
The EPICS **pvDatabase** module provides a set of network accessible, smart, memory resident records with a C++ API. Each record has data composed of a top level PVStructure. Each record has a name which is the channelName for pvAccess. A local Channel Provider implements the complete ChannelProvider and Channel interfaces as defined by pvAccess. The local provider gives access to the records in the pvDatabase. This local provider is accessed by the remote pvAccess server. A record is smart because code can be attached to a record, which is accessed via a method named process.
|
||||
|
||||
The pvDatabase module implements a synchronous C++ server interface to pvAccessCPP that was designed to be easier to use than the basic pvAccess server API.
|
||||
A brief description of a pvDatabase is that it is a set of network accessible, smart, memory resident records. Each record has data composed of a top level PVStructure. Each record has a name which is the channelName for pvAccess. A local Channel Provider implements the complete ChannelProvider and Channel interfaces as defined by pvAccess. The local provider provides access to the records in the pvDatabase. This local provider is accessed by the remote pvAccess server. A record is smart because code can be attached to a record, which is accessed via a method named process.
|
||||
pvaDatabase is a synchronous Database interface to pvAccess,
|
||||
which is callback based.
|
||||
pvaDatabase is thus easier to use than pvAccess itself.
|
||||
|
||||
## Links
|
||||
See documentation/pvaDatabaseCPP.html for details.
|
||||
|
||||
- General information about EPICS can be found at the
|
||||
[EPICS Controls website](https://epics-controls.org).
|
||||
- API documentation for this module can be found in its
|
||||
documentation directory, in particular the file
|
||||
pvDatabaseCPP.html
|
||||
Building
|
||||
--------
|
||||
|
||||
## Building
|
||||
If a proper RELEASE.local file exists one directory level above pvaDatabaseCPP
|
||||
then just type:
|
||||
|
||||
This module is included as a submodule of a full EPICS 7 release and will be compiled during builds of that software.
|
||||
make
|
||||
|
||||
It can also be built by:
|
||||
|
||||
cp configure/ExampleRELEASE.local configure/RELEASE.local
|
||||
edit configure/RELEASE.local
|
||||
make
|
||||
|
||||
|
||||
|
||||
Examples
|
||||
------------
|
||||
|
||||
Examples are available in exampleCPP.
|
||||
|
||||
Status
|
||||
------
|
||||
|
||||
* The API is for EPICS Version 4 release 4.6.0
|
||||
|
||||
## Examples
|
||||
|
||||
Some examples are available in the separate exampleCPP module.
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# Version number for the PV Database API and shared library
|
||||
|
||||
EPICS_PVDATABASE_MAJOR_VERSION = 4
|
||||
EPICS_PVDATABASE_MINOR_VERSION = 7
|
||||
EPICS_PVDATABASE_MAINTENANCE_VERSION = 1
|
||||
|
||||
# Development flag, set to zero for release versions
|
||||
|
||||
EPICS_PVDATABASE_DEVELOPMENT_FLAG = 0
|
||||
|
||||
# Immediately after a release the MAINTENANCE_VERSION
|
||||
# will be incremented and the DEVELOPMENT_FLAG set to 1
|
||||
8
configure/ExampleRELEASE.local
Normal file
8
configure/ExampleRELEASE.local
Normal file
@@ -0,0 +1,8 @@
|
||||
EPICS4_DIR=/home/epicsv4/master
|
||||
|
||||
PVACCESS=${EPICS4_DIR}/pvAccessCPP
|
||||
PVDATA=${EPICS4_DIR}/pvDataCPP
|
||||
PVCOMMON=${EPICS4_DIR}/pvCommonCPP
|
||||
|
||||
TEMPLATE_TOP=$(EPICS_BASE)/templates/makeBaseApp/top
|
||||
EPICS_BASE=/home/install/epics/base
|
||||
@@ -2,8 +2,6 @@ TOP=..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
CFG += CONFIG_PVDATABASE_VERSION
|
||||
|
||||
TARGETS = $(CONFIG_TARGETS)
|
||||
CONFIGS += $(subst ../,,$(wildcard $(CONFIG_INSTALLS)))
|
||||
|
||||
|
||||
@@ -1,43 +1,27 @@
|
||||
# RELEASE - Location of external support modules
|
||||
# pvDatabaseCPP RELEASE - Location of external support modules
|
||||
#
|
||||
# IF YOU CHANGE ANY PATHS in this file or make API changes to
|
||||
# any modules it refers to, you should do a "make rebuild" in
|
||||
# this application's top level directory.
|
||||
# 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 EPICS build process does not check dependencies against
|
||||
# any files from outside the application, so it is safest to
|
||||
# rebuild it completely if any modules it depends on change.
|
||||
# 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!
|
||||
#
|
||||
# This file is parsed by both GNUmake and an EPICS Perl script,
|
||||
# so it may ONLY contain definititions of paths to other support
|
||||
# modules, variable definitions that are used in module paths,
|
||||
# and include statements that pull in other RELEASE files.
|
||||
# Variables may be used before their values have been set.
|
||||
# Build variables that are NOT used in paths should be set in
|
||||
# the CONFIG_SITE file.
|
||||
# Create a file RELEASE.local pointing to your PVASRV, PVACCESS,
|
||||
# PVDATA, PVCOMMON and EPICS_BASE build directories, e.g.
|
||||
# PVACCESS = /path/to/epics/pvAccessCPP
|
||||
# PVDATA = /path/to/epics/pvDataCPP
|
||||
# PVCOMMON = /path/to/epics/pvCommonCPP
|
||||
# EPICS_BASE = /path/to/epics/base
|
||||
|
||||
# Variables and paths to dependent modules:
|
||||
#MODULES = /path/to/modules
|
||||
#MYMODULE = $(MODULES)/my-module
|
||||
|
||||
# If building the EPICS modules individually, set these:
|
||||
#EPICS_PVACCESS = $(MODULES)/pvAccess
|
||||
#EPICS_PVDATA = $(MODULES)/pvData
|
||||
#EPICS_DATABASE = $(MODULES)/database
|
||||
#EPICS_CA = $(MODULES)/ca
|
||||
#EPICS_LIBCOM = $(MODULES)/libcom
|
||||
#EPICS_BASE = $(MODULES)/core
|
||||
|
||||
# Set RULES here if you want to use build rules from elsewhere:
|
||||
#RULES = $(MODULES)/build-rules
|
||||
|
||||
# These allow developers to override the RELEASE variable settings
|
||||
# without having to modify the configure/RELEASE file itself.
|
||||
-include $(TOP)/../RELEASE.local
|
||||
-include $(TOP)/../RELEASE.$(EPICS_HOST_ARCH).local
|
||||
-include $(TOP)/configure/RELEASE.local
|
||||
|
||||
@@ -1,117 +1,23 @@
|
||||
# pvDatabaseCPP Module
|
||||
|
||||
This document summarizes the changes to the module between releases.
|
||||
|
||||
## Release 4.7.1 (EPICS 7.0.8, Dec 2023)
|
||||
|
||||
* Added data distributor plugin which can be used for distributing data between
|
||||
a group of clients. The plugin is triggered by the request string of the
|
||||
form:
|
||||
|
||||
`_[distributor=group:<group id>;set:<set_id>;trigger:<field_name>;updates:<n_updates>;mode:<update_mode>]`
|
||||
|
||||
The plugin parameters are optional and are described bellow:
|
||||
|
||||
- group: this parameter indicates a group that client application belongs to (default value: "default"); groups of clients are completely independent of each other
|
||||
|
||||
- set: this parameter designates a client set that application belongs to within its group (default value: "default")
|
||||
|
||||
- trigger: this is the PV structure field that distinguishes different channel updates (default value: "timeStamp"); for example, for area detector images one could use the "uniqueId" field of the NTND structure
|
||||
|
||||
- updates: this parameter configures how many sequential updates a client (or a set of clients) will receive before the data distributor starts updating the next one (default value: "1")
|
||||
|
||||
- mode: this parameter configures how channel updates are to be distributed between clients in a set:
|
||||
- one: update goes to one client per set
|
||||
- all: update goes to all clients in a set
|
||||
- default is "one" if client set id is not specified, and "all" if set id is specified
|
||||
|
||||
For more information and examples of usage see the [plugin documentation](dataDistributorPlugin.md).
|
||||
|
||||
## Release 4.7.0 (EPICS 7.0.7, Sep 2022)
|
||||
|
||||
* Added support for the whole structure (master field) server side plugins.
|
||||
The whole structure is identified as the `_` string, and a pvRequest string
|
||||
that applies a plugin to it takes the form:
|
||||
|
||||
`field(_[XYZ=A:3;B:uniqueId])`
|
||||
|
||||
where `XYZ` is the name of a specific filter plugin that takes parameters
|
||||
`A` and `B` with values `3` and `uniqueId` respectively.
|
||||
|
||||
## Release 4.6.0 (EPICS 7.0.6, Jul 2021)
|
||||
|
||||
* Access Security is now supported.
|
||||
* <b>special</b> has been revised and extended.
|
||||
* addRecord, removeRecord, processRecord, and traceRecord are replaced by pvdbcr versions.
|
||||
* <b>support</b> is DEPRECATED
|
||||
|
||||
## Release 4.5.3 (EPICS 7.0.5, Feb 2021)
|
||||
|
||||
* The previously deprecated destroy methods have been removed.
|
||||
Any application code that was previously calling these can just remove
|
||||
those calls.
|
||||
|
||||
## Release 4.5.2 (EPICS 7.0.3.2, May 2020)
|
||||
|
||||
* plugin support is new
|
||||
* fixed issues #53 and #52
|
||||
|
||||
## Release 4.5.1 (EPICS 7.0.3.1, Nov 2019)
|
||||
|
||||
* addRecord is new.
|
||||
* Doxygen updates and read-the-docs integration.
|
||||
|
||||
|
||||
## Release 4.5.0 (EPICS 7.0.3, Jul 2019)
|
||||
|
||||
* support is a new feature.
|
||||
* processRecord is new.
|
||||
|
||||
|
||||
## Release 4.4.2 (EPICS 7.0.2.2, Apr 2019)
|
||||
|
||||
Formerly if a client makes a request for a subfield of a non structure field
|
||||
it resulted in a crash.
|
||||
|
||||
Now if a request is made for a subfield of a non structure field
|
||||
|
||||
1) if the field is not a union an exception is thrown which is passed to the client.
|
||||
2) if the field is a union
|
||||
a) if more than one subfield is requested an exception is thrown
|
||||
b) if the subfield is the type for the current union the request succeeds
|
||||
c) if type is not the same an exception is thrown
|
||||
|
||||
|
||||
## Release 4.4.1 (EPICS 7.0.2.1, Mar 2019)
|
||||
|
||||
* Cleaned up some build warnings.
|
||||
* RTEMS test harness simplified.
|
||||
|
||||
|
||||
## Release 4.4 (EPICS 7.0.2, Dec 2018)
|
||||
|
||||
* pvCopy is now implemented in pvDatabaseCPP. The version in pvDatacPP can be deprecated.
|
||||
* plugin support is implemented.
|
||||
|
||||
|
||||
## Release 4.3 (EPICS 7.0.1, Dec 2017)
|
||||
|
||||
* Updates for pvAccess API and build system changes.
|
||||
|
||||
|
||||
## Release 4.2 (EPICS V4.6, Aug 2016)
|
||||
EPICS V4 release 4.6
|
||||
====================
|
||||
|
||||
* The examples are moved to exampleCPP
|
||||
* Support for channelRPC is now available.
|
||||
* removeRecord and traceRecord are now available.
|
||||
|
||||
The test is now a regression test which can be run using:
|
||||
The test is now a regression test the can be ran via
|
||||
|
||||
make runtests
|
||||
|
||||
|
||||
## Release 4.1 (EPICS V4.5, Oct 2015)
|
||||
EPICS V4 release 4.5
|
||||
====================
|
||||
|
||||
This release is one component of EPICS V4 release 4.5.
|
||||
|
||||
This is the first release of pvDatabaseCPP.
|
||||
|
||||
It provides functionality equivalent to pvDatabaseJava.
|
||||
|
||||
|
||||
|
||||
19
documentation/TODO.md
Normal file
19
documentation/TODO.md
Normal file
@@ -0,0 +1,19 @@
|
||||
TODO
|
||||
===========
|
||||
|
||||
monitorPlugin
|
||||
-------------
|
||||
|
||||
A debate is on-going about what semantics should be.
|
||||
|
||||
Must test record delete.
|
||||
-------------------
|
||||
|
||||
Must test removing a record from the PVDatabase while a pvAccess client
|
||||
is attached. Also why do both unlisten and detach exists?
|
||||
|
||||
|
||||
create more regression tests
|
||||
----------------
|
||||
|
||||
Currently only some simple tests exist. Most of the testing has been via the examples
|
||||
@@ -1,7 +0,0 @@
|
||||
.wy-side-nav-search {
|
||||
background-color: #18334B;
|
||||
}
|
||||
|
||||
.wy-side-nav-search input[type="text"] {
|
||||
border-color: #18334b;
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# This file only contains a selection of the most common options. For a full
|
||||
# list see the documentation:
|
||||
# http://www.sphinx-doc.org/en/master/config
|
||||
|
||||
# -- Path setup --------------------------------------------------------------
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
# import os
|
||||
# import sys
|
||||
# sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'normativeTypes (C++)'
|
||||
copyright = '2019, EPICS Controls.'
|
||||
author = 'EPICS'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
'sphinx.ext.intersphinx',
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This pattern also affects html_static_path and html_extra_path.
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
# Intersphinx links to subprojects
|
||||
intersphinx_mapping = {
|
||||
}
|
||||
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
html_css_files = [
|
||||
'css/custom.css',
|
||||
]
|
||||
|
||||
master_doc = 'index'
|
||||
|
||||
html_theme_options = {
|
||||
'logo_only': True,
|
||||
}
|
||||
html_logo = "images/EPICS_white_logo_v02.png"
|
||||
|
||||
html_extra_path = [
|
||||
'../html',
|
||||
'pvDatabaseCPP.html',
|
||||
]
|
||||
|
||||
|
||||
# -- Run Doxygen ------------------------------------------------------------
|
||||
|
||||
import subprocess
|
||||
subprocess.call('cd ..; mkdir -p html/doxygen; doxygen', shell=True)
|
||||
@@ -1,233 +0,0 @@
|
||||
# Data Distributor Plugin
|
||||
|
||||
The data distributor plugin enables distribution of channel data between
|
||||
multiple client applications. The plugin considers two basic use cases
|
||||
for a group of clients:
|
||||
|
||||
- For simple parallel processing where client applications do not need
|
||||
to share data all clients in a group receive n sequential updates
|
||||
in a round-robin fashion: client \#1 sees the first n updates, client \#2 the
|
||||
second n updates, and so on.
|
||||
|
||||
- For data analysis where several cooperating client applications must all
|
||||
see the same data in order to process it the applications are grouped
|
||||
into sets, and each set of clients receives the same number of sequential
|
||||
updates. The first n updates are sent to all members of client set #1, the second n updates are sent to all members of client set #2, and so on.
|
||||
|
||||
## Requirements
|
||||
|
||||
This plugin relies on the pvDatabase plugin framework and requires
|
||||
epics base version > 7.0.7
|
||||
|
||||
## Usage
|
||||
|
||||
The PV request object which triggers plugin instantiation is defined below:
|
||||
|
||||
```
|
||||
"_[distributor=group:<group id>;set:<set_id>;trigger:<field_name>;updates:<n_updates>;mode:<update_mode>]"
|
||||
```
|
||||
|
||||
The underscore character at the begining of the PV request object
|
||||
indicates that the data distributor will be targeting entire PV structure.
|
||||
The same PV request object format should work regardless of the language
|
||||
in which a particular client application is written.
|
||||
|
||||
The plugin parameters are the following:
|
||||
|
||||
- `group:<group_id>`: specifying a `group_id` names a group the client application belongs to (default value: `default`); clients with different group names are
|
||||
completely independent of each other
|
||||
|
||||
- `set:<set_id>`: this parameter designates a client set that application belongs to within its group (default value: `default`)
|
||||
|
||||
- `trigger:<field_name>`: this is the PV structure field that distinguishes
|
||||
different channel updates (default value: `timeStamp`); for example,
|
||||
for area detector images one could use the `uniqueId` field of the NTND
|
||||
structure
|
||||
|
||||
- `updates:<n_updates>`: this parameter must be an integer and configures how many sequential updates a client (or a set of clients) will receive before the data distributor starts updating the next one (default value: `1`)
|
||||
|
||||
- `mode:<update_mode>`: this parameter configures how channel updates are to be
|
||||
distributed between clients in a set:
|
||||
- `one`: update goes to one client per set
|
||||
- `all`: update goes to all clients in a set
|
||||
- default is `one` if client set id is not specified, and `all` if set
|
||||
id is specified
|
||||
|
||||
The plugin obeys the following rules:
|
||||
|
||||
- Parameter names are case insensitive, but the string values
|
||||
are not. For example, "group=abc" and "group=ABC" would indicate two
|
||||
different groups of clients. String values allow alphanumeric characters,
|
||||
as well as dashes and underscores.
|
||||
|
||||
- Updates for a set of clients are configured when the first client in
|
||||
the set requests data. Configuration values (i.e., "trigger",
|
||||
"updates", and "mode"), passed in the PV request by the subsequent
|
||||
clients are ignored.
|
||||
|
||||
- A set is removed from the group once the last client in that
|
||||
set disconnects.
|
||||
|
||||
- A group is removed from the distributor plugin once all of its
|
||||
clients have disconnected.
|
||||
|
||||
- Different client groups are completely independent of each other.
|
||||
In other words, channel updates sent to clients belonging to
|
||||
group A do not interfere with updates sent to clients
|
||||
belonging to group B.
|
||||
|
||||
- The order in which clients and groups receive data is on a
|
||||
"first connected, first served basis".
|
||||
|
||||
- The current channel PV object is always distributed to a client on an
|
||||
initial connect.
|
||||
|
||||
- Data distribution is dynamic with respect to the number of clients.
|
||||
As clients connect and disconnect, the data distribution in a group adjusts
|
||||
accordingly. For example, with a group of clients configured to
|
||||
distribute one sequential update to each client, three clients would each be
|
||||
receiving every third update; after client number four connects, all
|
||||
clients would start receiving every fourth update; if one of those then
|
||||
disconnects, remaining three clients would again be receiving every third
|
||||
update.
|
||||
|
||||
## Examples
|
||||
|
||||
For all examples below we assume that PVDatabase server is serving
|
||||
area detector images on the channel 'image'. All clients are started before
|
||||
the server itself, and the initial (empty) object has unique id of 0.
|
||||
|
||||
### Example 1
|
||||
|
||||
This example show behavior of three clients that belong to the same (default)
|
||||
group. Each client receives one sequential update in a round-robin fashion.
|
||||
Note that all clients received current object on initial connection,
|
||||
and every third object afterward:
|
||||
|
||||
Client 1:
|
||||
```
|
||||
$ pvget -m -r _[distributor=trigger:uniqueId] image | grep uniqueId
|
||||
int uniqueId 0
|
||||
int uniqueId 1
|
||||
int uniqueId 4
|
||||
int uniqueId 7
|
||||
int uniqueId 10
|
||||
```
|
||||
|
||||
Client 2:
|
||||
```
|
||||
$ pvget -m -r _[distributor=trigger:uniqueId] image | grep uniqueId
|
||||
int uniqueId 0
|
||||
int uniqueId 2
|
||||
int uniqueId 5
|
||||
int uniqueId 8
|
||||
int uniqueId 11
|
||||
```
|
||||
|
||||
Client 3:
|
||||
```
|
||||
$ pvget -m -r _[distributor=trigger:uniqueId] image | grep uniqueId
|
||||
int uniqueId 0
|
||||
int uniqueId 3
|
||||
int uniqueId 6
|
||||
int uniqueId 9
|
||||
int uniqueId 12
|
||||
```
|
||||
|
||||
### Example 2
|
||||
|
||||
In this example we have two sets of two clients, each client set receiving
|
||||
three sequential updates. Both clients from client set \#1 receive updates
|
||||
(1,2,3), both clients from client set \#2 receive updates (4,5,6),
|
||||
client set \#1 receives updates (7,8,9), and so on.
|
||||
|
||||
Client 1 and Client 2/Set 1:
|
||||
```
|
||||
$ pvget -m -r "_[distributor=set:S1;trigger:uniqueId;updates:3]" image | grep uniqueId
|
||||
int uniqueId 0
|
||||
int uniqueId 1
|
||||
int uniqueId 2
|
||||
int uniqueId 3
|
||||
int uniqueId 7
|
||||
int uniqueId 8
|
||||
int uniqueId 9
|
||||
int uniqueId 13
|
||||
int uniqueId 14
|
||||
int uniqueId 15
|
||||
```
|
||||
|
||||
Client 3 and Client 4/Set 2:
|
||||
```
|
||||
$ pvget -m -r "_[distributor=set:S2;trigger:uniqueId;updates:3]" image | grep uniqueId
|
||||
int uniqueId 0
|
||||
int uniqueId 4
|
||||
int uniqueId 5
|
||||
int uniqueId 6
|
||||
int uniqueId 10
|
||||
int uniqueId 11
|
||||
int uniqueId 12
|
||||
int uniqueId 16
|
||||
int uniqueId 17
|
||||
int uniqueId 18
|
||||
```
|
||||
|
||||
### Example 3
|
||||
|
||||
This example illustrates what happens when multiple independent groups of
|
||||
clients connect to the same channel. Group G1 has two clients belonging
|
||||
to the same default set, and requesting one sequential update per client, while
|
||||
Group G2 has two clients in the default set requesting three
|
||||
sequential updates per client.
|
||||
|
||||
In this case the first client in group G1 receives updates
|
||||
(1,3,5,...), while the second one receives updates (2,4,6,...). On the
|
||||
other hand, the first client in group G2 receives updates
|
||||
(1,2,3,7,8,9,...), while the second one receives updates (4,5,6,10,11,12,...).
|
||||
|
||||
Client 1/Group G1:
|
||||
```
|
||||
$ pvget -m -r "_[distributor=group:G1;trigger:uniqueId]" image | grep uniqueId
|
||||
int uniqueId 0
|
||||
int uniqueId 1
|
||||
int uniqueId 3
|
||||
int uniqueId 5
|
||||
int uniqueId 7
|
||||
int uniqueId 9
|
||||
```
|
||||
|
||||
Client 2/Group G1:
|
||||
```
|
||||
pvget -m -r "_[distributor=group:G1;trigger:uniqueId]" image | grep uniqueId
|
||||
int uniqueId 0
|
||||
int uniqueId 2
|
||||
int uniqueId 4
|
||||
int uniqueId 6
|
||||
int uniqueId 8
|
||||
```
|
||||
|
||||
Client 1/Group G2:
|
||||
```
|
||||
$ pvget -m -r "_[distributor=group:G2;trigger:uniqueId;updates:3]" image | grep uniqueId
|
||||
int uniqueId 0
|
||||
int uniqueId 1
|
||||
int uniqueId 2
|
||||
int uniqueId 3
|
||||
int uniqueId 7
|
||||
int uniqueId 8
|
||||
int uniqueId 9
|
||||
```
|
||||
|
||||
Client 2/Group G2:
|
||||
```
|
||||
$ pvget -m -r "_[distributor=group:G2;trigger:uniqueId;updates:3]" image | grep uniqueId
|
||||
int uniqueId 0
|
||||
int uniqueId 4
|
||||
int uniqueId 5
|
||||
int uniqueId 6
|
||||
int uniqueId 10
|
||||
int uniqueId 11
|
||||
int uniqueId 12
|
||||
```
|
||||
|
||||
The above shows that the two client groups do not interfere with each other.
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.5 KiB |
@@ -1,17 +0,0 @@
|
||||
pvDatabase (C++) Library
|
||||
========================
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
EPICS Website <https://epics-controls.org>
|
||||
EPICS Documentation Home <https://docs.epics-controls.org>
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: pvDatabaseCPP
|
||||
|
||||
Reference Manual <https://docs.epics-controls.org/projects/pvdatabase-cpp/en/latest/pvDatabaseCPP.html>
|
||||
API Documentation <https://docs.epics-controls.org/projects/pvdatabase-cpp/en/latest/doxygen>
|
||||
Source Code Repository on GitHub <https://github.com/epics-base/pvDatabaseCPP>
|
||||
@@ -4,61 +4,70 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
|
||||
<title>EPICS pvDatabaseCPP</title>
|
||||
<title>pvDatabaseCPP</title>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="https://mrkraimer.github.io/website/css/base.css" />
|
||||
href="http://epics-pvdata.sourceforge.net/base.css" />
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="https://mrkraimer.github.io/website/css/epicsv4.css" />
|
||||
href="http://epics-pvdata.sourceforge.net/epicsv4.css" />
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
/*<![CDATA[*/
|
||||
.about { margin-left: 3em; margin-right: 3em; font-size: .83em}
|
||||
table { margin-left: auto; margin-right: auto }
|
||||
.diagram { text-align: center; margin: 2.5em 0 }
|
||||
body { margin-right: 10% }
|
||||
/*]]>*/</style>
|
||||
|
||||
<!-- Script that generates the Table of Contents -->
|
||||
<script type="text/javascript" src="https://mrkraimer.github.io/website/css/tocgen.js"></script>
|
||||
|
||||
span.opt { color: grey }
|
||||
span.nterm { font-style:italic }
|
||||
span.term { font-family:courier }
|
||||
span.user { font-family:courier }
|
||||
span.user:before { content:"<" }
|
||||
span.user:after { content:">" }
|
||||
.nonnorm { font-style:italic }
|
||||
p.ed { color: #AA0000 }
|
||||
span.ed { color: #AA0000 }
|
||||
p.ed.priv { display: inline; }
|
||||
span.ed.priv { display: inline; }
|
||||
/*]]>*/</style>
|
||||
<!-- Script that generates the Table of Contents -->
|
||||
<script type="text/javascript"
|
||||
src="http://epics-pvdata.sourceforge.net/script/tocgen.js">
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="head">
|
||||
<h1>EPICS pvDatabaseCPP</h1>
|
||||
<h2 class="nocount">Release 4.6.0 - March 2021</h2>
|
||||
<h1>pvDatabaseCPP</h1>
|
||||
<h2 class="nocount">Release 4.2-SNAPSHOT - 2016.07.14</h2>
|
||||
|
||||
|
||||
<h2 class="nocount">Abstract</h2>
|
||||
|
||||
<p><b>pvDatabase</b> is a framework for implementing a network accessible database of smart memory resident
|
||||
<p>This document describes pvDatabaseCPP,
|
||||
which is a framework for implementing a network accessible database of smart memory resident
|
||||
records. Network access is via pvAccess. The data in each record is a top level PVStructure as defined by
|
||||
pvData. The framework includes a complete implementation of ChannelProvider as defined by pvAccess.
|
||||
The framework can be extended in order to create record instances that implements services.
|
||||
The minimum that an extension must provide is a top level PVStructure and a process method.
|
||||
</p>
|
||||
|
||||
<!-- last para of Abstract is boilerplate reference to EPICS -->
|
||||
<p>For more information about EPICS generally, please refer to the home page of the <a
|
||||
href="http://www.aps.anl.gov/epics/">Experimental Physics and Industrial
|
||||
Control System</a>.</p>
|
||||
|
||||
|
||||
</div> <!-- head -->
|
||||
</div>
|
||||
|
||||
<div id="contents" class="contents">
|
||||
<div id="toc">
|
||||
<h2 class="nocount">Table of Contents</h2>
|
||||
</div>
|
||||
|
||||
<div id="contents" class="contents">
|
||||
<hr />
|
||||
|
||||
<h2>Overview</h2>
|
||||
<p>
|
||||
Documentation for pvDatabaseCPP is available at:
|
||||
<a
|
||||
href="https://mrkraimer.github.io/website/developerGuide/pvDatabase/pvDatabaseCPP.html">
|
||||
pvDatabase
|
||||
</a>
|
||||
</p>
|
||||
<p>
|
||||
pvDatabaseCPP is one of the components of
|
||||
<a href="https://epics-controls.org/resources-and-support/base/epics-7/">
|
||||
EPICS-7
|
||||
pvDatabaseCPP is one of the components of
|
||||
<a href="http://epics-pvdata.sourceforge.net">
|
||||
EPICS Version 4
|
||||
</a>
|
||||
</p>
|
||||
<p>This document is only a guide to help locate code and documentation related to pvDatabaseCPP
|
||||
@@ -69,32 +78,114 @@ It is intended for developers that want to use pvDatabaseCPP.
|
||||
<h2>Developer Guide</h2>
|
||||
<p>A guide for developers is available at
|
||||
<a
|
||||
href="https://mrkraimer.github.io/website/developerGuide/developerGuide.html">
|
||||
href="http://epics-pvdata.sourceforge.net/informative/developerGuide/developerGuide.html">
|
||||
developerGuide
|
||||
</a>
|
||||
</p>
|
||||
<p>This guide provides an overview of the components that are part of an <b>EPICS V4</b> release.
|
||||
<p>This guide discusses all the components that are part of an <b>EPICS V4</b> release.
|
||||
Some understanding of the components and how they are related is necessary in order to
|
||||
develop code that uses pvDatabaseCPP.
|
||||
In particular read everything related to pvaClient.
|
||||
In particular read everything related to pvDatabase.
|
||||
</p>
|
||||
<p>The developerGuide discusses code in a way that applies to both CPP and C++.
|
||||
For the descriptions of the CPP specific code consult the next section.
|
||||
</p>
|
||||
|
||||
<h2>doxygen</h2>
|
||||
<p>doxygen documentation is available at
|
||||
<a
|
||||
href="./html/index.html">doxygen</a>
|
||||
href="./html/index.html">doxgen</a>
|
||||
</p>
|
||||
|
||||
<h2>pvDatabaseCPP</h2>
|
||||
<p>pvDatabaseCPP itself has the following implementations of a <b>PVRecord</b></p>
|
||||
<dl>
|
||||
<dt>RemoveRecord.cpp</dt>
|
||||
<dd>
|
||||
This is the code that is used to delete another record in the same <b>IOC</b>.
|
||||
</dd>
|
||||
<dt>TraceRecord.cpp</dt>
|
||||
<dd>
|
||||
This is the code that is used to set the trace level
|
||||
in another record in the same <b>IOC</b>.
|
||||
</dd>
|
||||
</dl>
|
||||
<h2>exampleCPP</h2>
|
||||
<p>Example code is available at
|
||||
<p>Example code is available as part of this release.
|
||||
<a
|
||||
href="https://github.com/epics-base/exampleCPP">
|
||||
href="http://epics-pvdata.sourceforge.net/docbuild/exampleCPP/tip/documentation/exampleCPP.html">
|
||||
exampleCPP
|
||||
</a>
|
||||
</p>
|
||||
<p>In particular look at database, exampleLink, and helloPutGet.
|
||||
<p>In particular look at the example code mentioned in the following sub-sections.
|
||||
</p>
|
||||
|
||||
</div> <!-- class="contents" -->
|
||||
<h3>database</h3>
|
||||
<p>This has many examples of how to create both soft records and records that implement
|
||||
other functionality.</p>
|
||||
<dl>
|
||||
<dt>exampleDatabase.cpp</dt>
|
||||
<dd>
|
||||
This shows how to create soft records of each pvData type.<br />
|
||||
In addition shows how to create instances of the following two records.
|
||||
</dd>
|
||||
<dt>exampleHelloRecord.cpp</dt>
|
||||
<dd>
|
||||
This is a simple "hello world" that is intentended to be used via a channelPutGet request.
|
||||
</dd>
|
||||
<dt>exampleHelloRPC.cpp</dt>
|
||||
<dd>
|
||||
This is a simple "hello world" that is intentended to be used via a channelRPC request.
|
||||
</dd>
|
||||
<dt>exampleDatabaseMain.cpp</dt>
|
||||
<dd>
|
||||
This shows how to create a standalone IOC.
|
||||
</dd>
|
||||
<dt>ioc and iocBoot</dt>
|
||||
<dd>
|
||||
This has code and examples to create a V3 IOC which also has a PVDatabase.
|
||||
</dd>
|
||||
</dl>
|
||||
<h3>exampleLink</h3>
|
||||
<p>This shows how to implement a record that has a link to another record</p>
|
||||
<dl>
|
||||
<dt>exampleMonitorLinkRecord</dt>
|
||||
<dd>
|
||||
This creates a monitor link to another record.
|
||||
</dd>
|
||||
<dt>exampleGetLinkRecord</dt>
|
||||
<dd>
|
||||
This creates a get link to another record.
|
||||
</dd>
|
||||
<dt>examplePutLinkRecord</dt>
|
||||
<dd>
|
||||
This creates a put link to another record.
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h2>iocshell commands</h2>
|
||||
<p>Shell commands are made available via the standard DBD include mechanism
|
||||
provided by iocCore.
|
||||
The following provide EPICS V4 shell commands:</p>
|
||||
<pre>
|
||||
pvAccessCPP
|
||||
pvaSrv
|
||||
pvDatabaseCPP
|
||||
</pre>
|
||||
|
||||
<p>pvDatabaseCPP provides the following iocshell command.</p>
|
||||
<dl>
|
||||
<dt>registerChannelProviderLocal</dt>
|
||||
<dd>Including <b>registerChannelProviderLocal.dbd</b> as a dbd file automatically starts provider local
|
||||
and also creates the pvdbl shell command.
|
||||
</dd>
|
||||
<dt>pvdbl</dt>
|
||||
<dd>Provides a list of all the pvRecords in database <b>master</b>
|
||||
</dd>
|
||||
</dl>
|
||||
<p>In addition any code that implements a PVRecord must implement an ioc command.
|
||||
Look at any of the examples in <b>exampleCPP</b> to see how to implement shell commands.</p>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
TOP=../..
|
||||
include $(TOP)/configure/CONFIG
|
||||
#----------------------------------------
|
||||
# ADD MACRO DEFINITIONS AFTER THIS LINE
|
||||
#=============================
|
||||
|
||||
#=============================
|
||||
# Build the application
|
||||
|
||||
TESTPROD_HOST = createdestroy
|
||||
|
||||
createdestroy_SRCS += createdestroy.cpp
|
||||
|
||||
# Add all the support libraries needed by this application
|
||||
#pvatest_LIBS += xxx
|
||||
|
||||
# Finally link to the EPICS Base libraries
|
||||
createdestroy_LIBS += pvDatabase pvAccess pvData
|
||||
createdestroy_LIBS += $(EPICS_BASE_IOC_LIBS)
|
||||
|
||||
#===========================
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
#----------------------------------------
|
||||
# ADD RULES AFTER THIS LINE
|
||||
@@ -1,20 +0,0 @@
|
||||
# pvDatabaseCPP/example/createdestroy
|
||||
|
||||
This is an example that:
|
||||
|
||||
1) Gets the master PVDatabase
|
||||
2) Create ChannelProviderLocal
|
||||
3) Creates a ServerContext
|
||||
|
||||
Then it executes a forever loop that:
|
||||
|
||||
1) creates a pvRecord and adds it to the pvDatabase.
|
||||
2) creates a pvac::ClientProvider
|
||||
3) creates a pvac::ClientChannel
|
||||
4) creates a monitor on the channel
|
||||
5) runs a loop 10 times that: does a put to the channel, and then gets the data for any outstanding monitors
|
||||
6) removes the pvRecord from the pvDatabase
|
||||
|
||||
It also has options to set trace level for the pvRecord and to periodically pause by asking for input.
|
||||
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
/******************************************************************************
|
||||
* This is modeled after a test program created by Bertrand Bauvir from the ITER Organization
|
||||
******************************************************************************/
|
||||
#include <iostream>
|
||||
#include <epicsGetopt.h>
|
||||
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/channelProviderLocal.h>
|
||||
#include <pva/client.h>
|
||||
#include <epicsEvent.h>
|
||||
|
||||
// Local header files
|
||||
|
||||
// Constants
|
||||
|
||||
#define DEFAULT_RECORD_NAME "examplechannel"
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
|
||||
class Record : public ::epics::pvDatabase::PVRecord
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<::epics::pvData::PVStructure> __pv;
|
||||
static std::shared_ptr<Record> create (std::string const & name, std::shared_ptr<::epics::pvData::PVStructure> const & pvstruct);
|
||||
Record (std::string const & name, std::shared_ptr<epics::pvData::PVStructure> const & pvstruct)
|
||||
: epics::pvDatabase::PVRecord(name, pvstruct) { __pv = pvstruct; };
|
||||
virtual void process (void);
|
||||
};
|
||||
|
||||
std::shared_ptr<Record> Record::create (std::string const & name, std::shared_ptr<::epics::pvData::PVStructure> const & pvstruct)
|
||||
{
|
||||
std::shared_ptr<Record> pvrecord (new Record (name, pvstruct));
|
||||
// Need to be explicitly called .. not part of the base constructor
|
||||
if(!pvrecord->init()) pvrecord.reset();
|
||||
return pvrecord;
|
||||
}
|
||||
|
||||
void Record::process (void)
|
||||
{
|
||||
PVRecord::process();
|
||||
std::string name = this->getRecordName();
|
||||
std::cout << this->getRecordName()
|
||||
<< " process\n";
|
||||
}
|
||||
|
||||
class MyMonitor
|
||||
{
|
||||
private:
|
||||
std::tr1::shared_ptr<::pvac::MonitorSync> monitor;
|
||||
MyMonitor(std::tr1::shared_ptr<::pvac::ClientChannel> const &channel)
|
||||
{
|
||||
monitor = std::tr1::shared_ptr<::pvac::MonitorSync>(new ::pvac::MonitorSync(channel->monitor()));
|
||||
}
|
||||
public:
|
||||
static std::tr1::shared_ptr<MyMonitor> create(std::tr1::shared_ptr<::pvac::ClientChannel> const &channel)
|
||||
{
|
||||
return std::tr1::shared_ptr<MyMonitor>(new MyMonitor(channel));
|
||||
}
|
||||
void getData();
|
||||
};
|
||||
|
||||
void MyMonitor::getData()
|
||||
{
|
||||
while (true) {
|
||||
if(!monitor->wait(.001)) break;
|
||||
switch(monitor->event.event) {
|
||||
case pvac::MonitorEvent::Fail:
|
||||
std::cerr<<monitor->name()<<" : Error : "<<monitor->event.message<<"\n";
|
||||
return;
|
||||
case pvac::MonitorEvent::Cancel:
|
||||
std::cout<<monitor->name()<<" <Cancel>\n";
|
||||
return;
|
||||
case pvac::MonitorEvent::Disconnect:
|
||||
std::cout<<monitor->name()<<" <Disconnect>\n";
|
||||
return;
|
||||
case pvac::MonitorEvent::Data:
|
||||
while(monitor->poll()) {
|
||||
std::cout<<monitor->name()<<" : "<<monitor->root;
|
||||
}
|
||||
if(monitor->complete()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
int verbose = 0;
|
||||
unsigned loopctr = 0;
|
||||
unsigned pausectr = 0;
|
||||
bool allowExit = false;
|
||||
bool callRecord = false;
|
||||
bool callDatabase = false;
|
||||
int opt;
|
||||
while((opt = getopt(argc, argv, "v:ardh")) != -1) {
|
||||
switch(opt) {
|
||||
case 'v':
|
||||
verbose = std::stoi(optarg);
|
||||
break;
|
||||
case 'a' :
|
||||
allowExit = true;
|
||||
break;
|
||||
case 'r' :
|
||||
callRecord = true;
|
||||
break;
|
||||
case 'd' :
|
||||
callDatabase = true;
|
||||
break;
|
||||
case 'h':
|
||||
std::cout << " -v level -a -r -d -h \n";
|
||||
std::cout << "-r call pvRecord->remove -d call master->removeRecord\n";
|
||||
std::cout << "default\n";
|
||||
std::cout << "-v " << verbose
|
||||
<< " -a false"
|
||||
<< " -d"
|
||||
<< "\n";
|
||||
return 0;
|
||||
default:
|
||||
std::cerr<<"Unknown argument: "<<opt<<"\n";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(!callRecord && !callDatabase) callDatabase = true;
|
||||
::epics::pvDatabase::PVDatabasePtr master = epics::pvDatabase::PVDatabase::getMaster();
|
||||
::epics::pvDatabase::ChannelProviderLocalPtr channelProvider = epics::pvDatabase::getChannelProviderLocal();
|
||||
epics::pvAccess::ServerContext::shared_pointer context
|
||||
= epics::pvAccess::startPVAServer(epics::pvAccess::PVACCESS_ALL_PROVIDERS, 0, true, true);
|
||||
std::string startset("starting set of puts valuectr = ");
|
||||
|
||||
while (true) {
|
||||
loopctr++;
|
||||
std::string name = DEFAULT_RECORD_NAME + std::to_string(loopctr);
|
||||
|
||||
// Create record
|
||||
// Create record structure
|
||||
::epics::pvData::FieldBuilderPtr builder = epics::pvData::getFieldCreate()->createFieldBuilder();
|
||||
builder->add("value", ::epics::pvData::pvULong);
|
||||
std::shared_ptr<::epics::pvData::PVStructure> pvstruct
|
||||
= ::epics::pvData::getPVDataCreate()->createPVStructure(builder->createStructure());
|
||||
std::shared_ptr<Record> pvrecord = Record::create(std::string(name), pvstruct);
|
||||
master->addRecord(pvrecord);
|
||||
pvrecord->setTraceLevel(verbose);
|
||||
// Start PVA (local) client
|
||||
std::tr1::shared_ptr<::pvac::ClientProvider> provider
|
||||
= std::tr1::shared_ptr<::pvac::ClientProvider>(new ::pvac::ClientProvider ("pva"));
|
||||
std::tr1::shared_ptr<::pvac::ClientChannel> channel
|
||||
= std::tr1::shared_ptr<::pvac::ClientChannel>(new ::pvac::ClientChannel (provider->connect(name)));
|
||||
std::tr1::shared_ptr<MyMonitor> mymonitor = MyMonitor::create(channel);
|
||||
unsigned valuectr = loopctr;
|
||||
std::cout << startset << loopctr << "\n";
|
||||
for (int ind=0; ind<100; ind++) {
|
||||
channel->put().set("value",valuectr++).exec();
|
||||
mymonitor->getData();
|
||||
}
|
||||
pausectr++;
|
||||
if(allowExit && pausectr>10) {
|
||||
pausectr = 0;
|
||||
std::cout << "Type exit to stop: \n";
|
||||
int c = std::cin.peek(); // peek character
|
||||
if ( c == EOF ) continue;
|
||||
std::string str;
|
||||
std::getline(std::cin,str);
|
||||
if(str.compare("exit")==0) break;
|
||||
}
|
||||
if(callRecord) {
|
||||
std::cout << "callRecord\n";
|
||||
pvrecord->remove();
|
||||
}
|
||||
if(callDatabase) {
|
||||
std::cout << "callDatabase\n";
|
||||
master->removeRecord(pvrecord);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -21,21 +21,30 @@ installE4 () {
|
||||
local module=$1
|
||||
local branch=$2
|
||||
|
||||
wget -nv https://openepics.ci.cloudbees.com/job/e4-cpp-${module}-${branch}-build/BASE=${BASE}/lastSuccessfulBuild/artifact/${module}.CB-dist.tar.gz
|
||||
# If microbench version does not exist, try without
|
||||
if [ "${MB}" = "WITH_MICROBENCH" ]; then
|
||||
if ! wget -nv https://openepics.ci.cloudbees.com/job/e4-cpp-${module}-${branch}-build/BASE=${BASE},MB=WITH_MICROBENCH/lastSuccessfulBuild/artifact/${module}.CB-dist.tar.gz; then
|
||||
wget -nv https://openepics.ci.cloudbees.com/job/e4-cpp-${module}-${branch}-build/BASE=${BASE},MB=NO_MICROBENCH/lastSuccessfulBuild/artifact/${module}.CB-dist.tar.gz
|
||||
fi
|
||||
else
|
||||
wget -nv https://openepics.ci.cloudbees.com/job/e4-cpp-${module}-${branch}-build/BASE=${BASE},MB=NO_MICROBENCH/lastSuccessfulBuild/artifact/${module}.CB-dist.tar.gz
|
||||
fi
|
||||
tar -xzf ${module}.CB-dist.tar.gz
|
||||
}
|
||||
|
||||
###########################################
|
||||
# Defaults for EPICS Base
|
||||
# Defaults for EPICS Base and MB
|
||||
|
||||
DEFAULT_BASE=3.15.4
|
||||
BASE=${BASE:-${DEFAULT_BASE}}
|
||||
MB=${MB:-"NO_MICROBENCH"}
|
||||
|
||||
###########################################
|
||||
# Dependent module branches
|
||||
|
||||
PVDATA_BRANCH="master"
|
||||
PVACCESS_BRANCH="master"
|
||||
PVCOMMON_BRANCH="release-4.2"
|
||||
PVDATA_BRANCH="release-6.0"
|
||||
PVACCESS_BRANCH="release-5.0"
|
||||
|
||||
###########################################
|
||||
# Fetch and unpack dependencies
|
||||
@@ -49,6 +58,7 @@ cd ${STUFF}
|
||||
installTool Boost 1.61.0
|
||||
installTool Base ${BASE}
|
||||
|
||||
installE4 pvCommon ${PVCOMMON_BRANCH}
|
||||
installE4 pvData ${PVDATA_BRANCH}
|
||||
installE4 pvAccess ${PVACCESS_BRANCH}
|
||||
|
||||
@@ -74,6 +84,6 @@ make distclean all
|
||||
make runtests
|
||||
|
||||
###########################################
|
||||
# Create cache
|
||||
# Create distribution
|
||||
|
||||
tar -czf pvDatabase.CB-dist.tar.gz lib include dbd LICENSE
|
||||
|
||||
@@ -21,7 +21,14 @@ installE4 () {
|
||||
local module=$1
|
||||
local branch=$2
|
||||
|
||||
wget -nv https://openepics.ci.cloudbees.com/job/e4-cpp-${module}-${branch}-build/BASE=${BASE}/lastSuccessfulBuild/artifact/${module}.CB-dist.tar.gz
|
||||
# If microbench version does not exist, try without
|
||||
if [ "${MB}" = "WITH_MICROBENCH" ]; then
|
||||
if ! wget -nv https://openepics.ci.cloudbees.com/job/e4-cpp-${module}-${branch}-build/BASE=${BASE},MB=WITH_MICROBENCH/lastSuccessfulBuild/artifact/${module}.CB-dist.tar.gz; then
|
||||
wget -nv https://openepics.ci.cloudbees.com/job/e4-cpp-${module}-${branch}-build/BASE=${BASE},MB=NO_MICROBENCH/lastSuccessfulBuild/artifact/${module}.CB-dist.tar.gz
|
||||
fi
|
||||
else
|
||||
wget -nv https://openepics.ci.cloudbees.com/job/e4-cpp-${module}-${branch}-build/BASE=${BASE},MB=NO_MICROBENCH/lastSuccessfulBuild/artifact/${module}.CB-dist.tar.gz
|
||||
fi
|
||||
tar -xzf ${module}.CB-dist.tar.gz
|
||||
}
|
||||
|
||||
@@ -31,6 +38,7 @@ installE4 () {
|
||||
BASE=3.15.4
|
||||
PUBLISH=${PUBLISH:-NO}
|
||||
BRANCH=${BRANCH:-master}
|
||||
MB=NO_MICROBENCH
|
||||
|
||||
###########################################
|
||||
# Fetch and unpack dependencies
|
||||
|
||||
49
src/Makefile
49
src/Makefile
@@ -6,42 +6,25 @@ include $(TOP)/configure/CONFIG
|
||||
PVDATABASE_SRC = $(TOP)/src
|
||||
|
||||
|
||||
INC += pv/pvPlugin.h
|
||||
INC += pv/pvStructureCopy.h
|
||||
INC += pv/pvArrayPlugin.h
|
||||
INC += pv/pvDeadbandPlugin.h
|
||||
INC += pv/pvTimestampPlugin.h
|
||||
|
||||
INC += pv/pvDatabase.h
|
||||
|
||||
INC += pv/channelProviderLocal.h
|
||||
|
||||
INC += pv/pvSupport.h
|
||||
INC += pv/controlSupport.h
|
||||
INC += pv/scalarAlarmSupport.h
|
||||
|
||||
INC += pv/pvdbcrScalarRecord.h
|
||||
INC += pv/pvdbcrScalarArrayRecord.h
|
||||
INC += pv/pvdbcrAddRecord.h
|
||||
INC += pv/pvdbcrRemoveRecord.h
|
||||
INC += pv/pvdbcrProcessRecord.h
|
||||
INC += pv/pvdbcrTraceRecord.h
|
||||
|
||||
include $(PVDATABASE_SRC)/copy/Makefile
|
||||
include $(PVDATABASE_SRC)/database/Makefile
|
||||
include $(PVDATABASE_SRC)/pvAccess/Makefile
|
||||
include $(PVDATABASE_SRC)/support/Makefile
|
||||
include $(PVDATABASE_SRC)/special/Makefile
|
||||
|
||||
LIBRARY += pvDatabase
|
||||
pvDatabase_LIBS += pvData
|
||||
pvDatabase_LIBS += pvAccess
|
||||
LIB_LIBS += Com
|
||||
|
||||
# shared library ABI version.
|
||||
SHRLIB_VERSION ?= $(EPICS_PVDATABASE_MAJOR_VERSION).$(EPICS_PVDATABASE_MINOR_VERSION).$(EPICS_PVDATABASE_MAINTENANCE_VERSION)
|
||||
SHRLIB_VERSION ?= 4.2.0
|
||||
|
||||
INC += pv/channelProviderLocal.h
|
||||
INC += pv/pvDatabase.h
|
||||
INC += pv/traceRecord.h
|
||||
INC += pv/removeRecord.h
|
||||
|
||||
include $(PVDATABASE_SRC)/database/Makefile
|
||||
include $(PVDATABASE_SRC)/pvAccess/Makefile
|
||||
include $(PVDATABASE_SRC)/special/Makefile
|
||||
|
||||
|
||||
pvDatabase_LIBS += pvAccess pvData Com
|
||||
pvDatabase_LIBS += $(EPICS_BASE_IOC_LIBS)
|
||||
|
||||
|
||||
# needed for Windows
|
||||
LIB_SYS_LIBS_WIN32 += netapi32 ws2_32
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
|
||||
# This is a Makefile fragment, see ../Makefile
|
||||
|
||||
SRC_DIRS += $(PVDATABASE_SRC)/copy
|
||||
|
||||
LIBSRCS += pvPlugin.cpp
|
||||
LIBSRCS += pvCopy.cpp
|
||||
LIBSRCS += pvArrayPlugin.cpp
|
||||
LIBSRCS += pvDeadbandPlugin.cpp
|
||||
LIBSRCS += pvTimestampPlugin.cpp
|
||||
LIBSRCS += dataDistributorPlugin.cpp
|
||||
|
||||
|
||||
@@ -1,428 +0,0 @@
|
||||
// Copyright information and license terms for this software can be
|
||||
// found in the file LICENSE that is included with the distribution
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/bitSet.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/dataDistributorPlugin.h"
|
||||
|
||||
using std::string;
|
||||
using std::size_t;
|
||||
using std::endl;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using std::vector;
|
||||
using namespace epics::pvData;
|
||||
namespace epvd = epics::pvData;
|
||||
|
||||
namespace epics { namespace pvCopy {
|
||||
|
||||
// Utilities for manipulating strings
|
||||
static std::string leftTrim(const std::string& s)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int n = (unsigned int)s.length();
|
||||
for (i = 0; i < n; i++) {
|
||||
if (!isspace(s[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return s.substr(i,n-i);
|
||||
}
|
||||
|
||||
static std::string rightTrim(const std::string& s)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int n = (unsigned int)s.length();
|
||||
for (i = n; i > 0; i--) {
|
||||
if (!isspace(s[i-1])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return s.substr(0,i);
|
||||
}
|
||||
|
||||
static std::string trim(const std::string& s)
|
||||
{
|
||||
return rightTrim(leftTrim(s));
|
||||
}
|
||||
|
||||
static std::vector<std::string>& split(const std::string& s, char delimiter, std::vector<std::string>& elements)
|
||||
{
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
while (std::getline(ss, item, delimiter)) {
|
||||
elements.push_back(trim(item));
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
static std::vector<std::string> split(const std::string& s, char delimiter)
|
||||
{
|
||||
std::vector<std::string> elements;
|
||||
split(s, delimiter, elements);
|
||||
return elements;
|
||||
}
|
||||
|
||||
static std::string toLowerCase(const std::string& input)
|
||||
{
|
||||
std::stringstream ss;
|
||||
for (unsigned int i = 0; i < input.size(); i++) {
|
||||
char c = std::tolower(input.at(i));
|
||||
ss << c;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
// Data distributor class
|
||||
|
||||
static std::string name("distributor");
|
||||
bool DataDistributorPlugin::initialized(false);
|
||||
|
||||
std::map<std::string, DataDistributorPtr> DataDistributor::dataDistributorMap;
|
||||
epics::pvData::Mutex DataDistributor::dataDistributorMapMutex;
|
||||
|
||||
DataDistributorPtr DataDistributor::getInstance(const std::string& groupId)
|
||||
{
|
||||
epvd::Lock lock(dataDistributorMapMutex);
|
||||
std::map<std::string,DataDistributorPtr>::iterator ddit = dataDistributorMap.find(groupId);
|
||||
if (ddit != dataDistributorMap.end()) {
|
||||
DataDistributorPtr ddPtr = ddit->second;
|
||||
return ddPtr;
|
||||
}
|
||||
else {
|
||||
DataDistributorPtr ddPtr(new DataDistributor(groupId));
|
||||
dataDistributorMap[groupId] = ddPtr;
|
||||
return ddPtr;
|
||||
}
|
||||
}
|
||||
|
||||
void DataDistributor::removeUnusedInstance(DataDistributorPtr dataDistributorPtr)
|
||||
{
|
||||
epvd::Lock lock(dataDistributorMapMutex);
|
||||
std::string groupId = dataDistributorPtr->getGroupId();
|
||||
std::map<std::string,DataDistributorPtr>::iterator ddit = dataDistributorMap.find(groupId);
|
||||
if (ddit != dataDistributorMap.end()) {
|
||||
DataDistributorPtr ddPtr = ddit->second;
|
||||
size_t nSets = ddPtr->clientSetMap.size();
|
||||
if (nSets == 0) {
|
||||
dataDistributorMap.erase(ddit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DataDistributor::DataDistributor(const std::string& groupId_)
|
||||
: groupId(groupId_)
|
||||
, mutex()
|
||||
, clientSetMap()
|
||||
, clientSetIdList()
|
||||
, currentSetIdIter(clientSetIdList.end())
|
||||
, lastUpdateValue()
|
||||
{
|
||||
}
|
||||
|
||||
DataDistributor::~DataDistributor()
|
||||
{
|
||||
epvd::Lock lock(mutex);
|
||||
clientSetMap.clear();
|
||||
clientSetIdList.clear();
|
||||
}
|
||||
|
||||
std::string DataDistributor::addClient(int clientId, const std::string& setId, const std::string& triggerField, int nUpdatesPerClient, int updateMode)
|
||||
{
|
||||
epvd::Lock lock(mutex);
|
||||
std::map<std::string,ClientSetPtr>::iterator git = clientSetMap.find(setId);
|
||||
if (git != clientSetMap.end()) {
|
||||
ClientSetPtr setPtr = git->second;
|
||||
setPtr->clientIdList.push_back(clientId);
|
||||
return setPtr->triggerField;
|
||||
}
|
||||
else {
|
||||
ClientSetPtr setPtr(new ClientSet(setId, triggerField, nUpdatesPerClient, updateMode));
|
||||
setPtr->clientIdList.push_back(clientId);
|
||||
clientSetMap[setId] = setPtr;
|
||||
clientSetIdList.push_back(setId);
|
||||
return triggerField;
|
||||
}
|
||||
}
|
||||
|
||||
void DataDistributor::removeClient(int clientId, const std::string& setId)
|
||||
{
|
||||
epvd::Lock lock(mutex);
|
||||
std::map<std::string,ClientSetPtr>::iterator git = clientSetMap.find(setId);
|
||||
if (git != clientSetMap.end()) {
|
||||
ClientSetPtr setPtr = git->second;
|
||||
std::list<int>::iterator cit = std::find(setPtr->clientIdList.begin(), setPtr->clientIdList.end(), clientId);
|
||||
if (cit != setPtr->clientIdList.end()) {
|
||||
// If we are removing current client id, advance iterator
|
||||
if (cit == setPtr->currentClientIdIter) {
|
||||
setPtr->currentClientIdIter++;
|
||||
}
|
||||
|
||||
// Find current client id
|
||||
int currentClientId = -1;
|
||||
if (setPtr->currentClientIdIter != setPtr->clientIdList.end()) {
|
||||
currentClientId = *(setPtr->currentClientIdIter);
|
||||
}
|
||||
|
||||
// Remove client id from the list
|
||||
setPtr->clientIdList.erase(cit);
|
||||
|
||||
// Reset current client id iterator
|
||||
setPtr->currentClientIdIter = setPtr->clientIdList.end();
|
||||
if (currentClientId >= 0) {
|
||||
std::list<int>::iterator cit2 = std::find(setPtr->clientIdList.begin(), setPtr->clientIdList.end(), currentClientId);
|
||||
if (cit2 != setPtr->clientIdList.end()) {
|
||||
setPtr->currentClientIdIter = cit2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (setPtr->clientIdList.size() == 0) {
|
||||
clientSetMap.erase(git);
|
||||
std::list<std::string>::iterator git2 = std::find(clientSetIdList.begin(), clientSetIdList.end(), setId);
|
||||
if (git2 == currentSetIdIter) {
|
||||
currentSetIdIter++;
|
||||
}
|
||||
if (git2 != clientSetIdList.end()) {
|
||||
clientSetIdList.erase(git2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DataDistributor::updateClient(int clientId, const std::string& setId, const std::string& triggerFieldValue)
|
||||
{
|
||||
epvd::Lock lock(mutex);
|
||||
bool proceedWithUpdate = false;
|
||||
if (currentSetIdIter == clientSetIdList.end()) {
|
||||
currentSetIdIter = clientSetIdList.begin();
|
||||
}
|
||||
std::string currentSetId = *currentSetIdIter;
|
||||
if (setId != currentSetId) {
|
||||
// We are not distributing data to this set at the moment
|
||||
return proceedWithUpdate;
|
||||
}
|
||||
ClientSetPtr setPtr = clientSetMap[currentSetId];
|
||||
if (setPtr->currentClientIdIter == setPtr->clientIdList.end()) {
|
||||
// Move current client iterator to the beginning of the list
|
||||
setPtr->currentClientIdIter = setPtr->clientIdList.begin();
|
||||
}
|
||||
if (lastUpdateValue == triggerFieldValue) {
|
||||
// This update was already distributed.
|
||||
return proceedWithUpdate;
|
||||
}
|
||||
switch (setPtr->updateMode) {
|
||||
case(DD_UPDATE_ONE_PER_GROUP): {
|
||||
if (clientId != *(setPtr->currentClientIdIter)) {
|
||||
// Not this client's turn.
|
||||
return proceedWithUpdate;
|
||||
}
|
||||
proceedWithUpdate = true;
|
||||
lastUpdateValue = triggerFieldValue;
|
||||
setPtr->lastUpdateValue = triggerFieldValue;
|
||||
setPtr->updateCounter++;
|
||||
if (setPtr->updateCounter >= setPtr->nUpdatesPerClient) {
|
||||
// This client and set are done.
|
||||
setPtr->currentClientIdIter++;
|
||||
setPtr->updateCounter = 0;
|
||||
currentSetIdIter++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(DD_UPDATE_ALL_IN_GROUP): {
|
||||
proceedWithUpdate = true;
|
||||
static unsigned int nClientsUpdated = 0;
|
||||
if (setPtr->lastUpdateValue != triggerFieldValue) {
|
||||
setPtr->lastUpdateValue = triggerFieldValue;
|
||||
setPtr->updateCounter++;
|
||||
nClientsUpdated = 0;
|
||||
}
|
||||
nClientsUpdated++;
|
||||
if (nClientsUpdated == setPtr->clientIdList.size() && setPtr->updateCounter >= setPtr->nUpdatesPerClient) {
|
||||
// This set is done.
|
||||
lastUpdateValue = triggerFieldValue;
|
||||
setPtr->updateCounter = 0;
|
||||
currentSetIdIter++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
proceedWithUpdate = true;
|
||||
}
|
||||
}
|
||||
return proceedWithUpdate;
|
||||
}
|
||||
|
||||
DataDistributorPlugin::DataDistributorPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
DataDistributorPlugin::~DataDistributorPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
void DataDistributorPlugin::create()
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
bool DataDistributorPlugin::initialize()
|
||||
{
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
DataDistributorPluginPtr pvPlugin = DataDistributorPluginPtr(new DataDistributorPlugin());
|
||||
PVPluginRegistry::registerPlugin(name,pvPlugin);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
PVFilterPtr DataDistributorPlugin::create(
|
||||
const std::string& requestValue,
|
||||
const PVCopyPtr& pvCopy,
|
||||
const PVFieldPtr& master)
|
||||
{
|
||||
return DataDistributorFilter::create(requestValue,pvCopy,master);
|
||||
}
|
||||
|
||||
DataDistributorFilter::~DataDistributorFilter()
|
||||
{
|
||||
dataDistributorPtr->removeClient(clientId, setId);
|
||||
DataDistributor::removeUnusedInstance(dataDistributorPtr);
|
||||
}
|
||||
|
||||
DataDistributorFilterPtr DataDistributorFilter::create(
|
||||
const std::string& requestValue,
|
||||
const PVCopyPtr& pvCopy,
|
||||
const PVFieldPtr& master)
|
||||
{
|
||||
static int clientId = 0;
|
||||
clientId++;
|
||||
|
||||
std::vector<std::string> configItems = split(requestValue, ';');
|
||||
// Use lowercase keys if possible.
|
||||
std::string requestValue2 = toLowerCase(requestValue);
|
||||
std::vector<std::string> configItems2 = split(requestValue2, ';');
|
||||
int nUpdatesPerClient = 1;
|
||||
int updateMode = DataDistributor::DD_UPDATE_ONE_PER_GROUP;
|
||||
std::string groupId = "default";
|
||||
std::string setId = "default";
|
||||
std::string triggerField = "timeStamp";
|
||||
bool hasUpdateMode = false;
|
||||
bool hasSetId = false;
|
||||
for(unsigned int i = 0; i < configItems2.size(); i++) {
|
||||
std::string configItem2 = configItems2[i];
|
||||
size_t ind = configItem2.find(':');
|
||||
if (ind == string::npos) {
|
||||
continue;
|
||||
}
|
||||
if(configItem2.find("updates") == 0) {
|
||||
std::string svalue = configItem2.substr(ind+1);
|
||||
nUpdatesPerClient = atoi(svalue.c_str());
|
||||
}
|
||||
else if(configItem2.find("group") == 0) {
|
||||
std::string configItem = configItems[i];
|
||||
groupId = configItem.substr(ind+1);
|
||||
}
|
||||
else if(configItem2.find("set") == 0) {
|
||||
std::string configItem = configItems[i];
|
||||
setId = configItem.substr(ind+1);
|
||||
hasSetId = true;
|
||||
}
|
||||
else if(configItem2.find("mode") == 0) {
|
||||
std::string svalue = toLowerCase(configItem2.substr(ind+1));
|
||||
if (svalue == "one") {
|
||||
updateMode = DataDistributor::DD_UPDATE_ONE_PER_GROUP;
|
||||
hasUpdateMode = true;
|
||||
}
|
||||
else if (svalue == "all") {
|
||||
updateMode = DataDistributor::DD_UPDATE_ALL_IN_GROUP;
|
||||
hasUpdateMode = true;
|
||||
}
|
||||
}
|
||||
else if(configItem2.find("trigger") == 0) {
|
||||
std::string configItem = configItems[i];
|
||||
triggerField = configItem.substr(ind+1);
|
||||
}
|
||||
}
|
||||
// If request does not have update mode specified, but has set id
|
||||
// then use a different update mode
|
||||
if(!hasUpdateMode && hasSetId) {
|
||||
updateMode = DataDistributor::DD_UPDATE_ALL_IN_GROUP;
|
||||
}
|
||||
|
||||
// Make sure request is valid
|
||||
if(nUpdatesPerClient <= 0) {
|
||||
return DataDistributorFilterPtr();
|
||||
}
|
||||
DataDistributorFilterPtr filter =
|
||||
DataDistributorFilterPtr(new DataDistributorFilter(groupId, clientId, setId, triggerField, nUpdatesPerClient, updateMode, pvCopy, master));
|
||||
return filter;
|
||||
}
|
||||
|
||||
DataDistributorFilter::DataDistributorFilter(const std::string& groupId_, int clientId_, const std::string& setId_, const std::string& triggerField_, int nUpdatesPerClient, int updateMode, const PVCopyPtr& copyPtr_, const epvd::PVFieldPtr& masterFieldPtr_)
|
||||
: dataDistributorPtr(DataDistributor::getInstance(groupId_))
|
||||
, clientId(clientId_)
|
||||
, setId(setId_)
|
||||
, triggerField(triggerField_)
|
||||
, masterFieldPtr(masterFieldPtr_)
|
||||
, triggerFieldPtr()
|
||||
, firstUpdate(true)
|
||||
{
|
||||
triggerField = dataDistributorPtr->addClient(clientId, setId, triggerField, nUpdatesPerClient, updateMode);
|
||||
if(masterFieldPtr->getField()->getType() == epvd::structure) {
|
||||
epvd::PVStructurePtr pvStructurePtr = static_pointer_cast<epvd::PVStructure>(masterFieldPtr);
|
||||
if(pvStructurePtr) {
|
||||
triggerFieldPtr = pvStructurePtr->getSubField(triggerField);
|
||||
}
|
||||
}
|
||||
if(!triggerFieldPtr) {
|
||||
triggerFieldPtr = masterFieldPtr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool DataDistributorFilter::filter(const PVFieldPtr& pvCopy, const BitSetPtr& bitSet, bool toCopy)
|
||||
{
|
||||
if(!toCopy) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool proceedWithUpdate = false;
|
||||
if(firstUpdate) {
|
||||
// Always send first update
|
||||
firstUpdate = false;
|
||||
proceedWithUpdate = true;
|
||||
}
|
||||
else {
|
||||
std::stringstream ss;
|
||||
ss << triggerFieldPtr;
|
||||
std::string triggerFieldValue = ss.str();
|
||||
proceedWithUpdate = dataDistributorPtr->updateClient(clientId, setId, triggerFieldValue);
|
||||
}
|
||||
|
||||
if(proceedWithUpdate) {
|
||||
pvCopy->copyUnchecked(*masterFieldPtr);
|
||||
bitSet->set((unsigned int)pvCopy->getFieldOffset());
|
||||
}
|
||||
else {
|
||||
// Clear all bits
|
||||
//bitSet->clear(pvCopy->getFieldOffset());
|
||||
bitSet->clear();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string DataDistributorFilter::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,225 +0,0 @@
|
||||
/* pvArrayPlugin.cpp */
|
||||
/*
|
||||
* The License for this software can be found in the file LICENSE that is included with the distribution.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/bitSet.h>
|
||||
#include <pv/convert.h>
|
||||
#include <pv/pvSubArrayCopy.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvArrayPlugin.h"
|
||||
|
||||
using std::string;
|
||||
using std::size_t;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using std::vector;
|
||||
using namespace epics::pvData;
|
||||
|
||||
namespace epics { namespace pvCopy{
|
||||
|
||||
static ConvertPtr convert = getConvert();
|
||||
static std::string name("array");
|
||||
|
||||
PVArrayPlugin::PVArrayPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
PVArrayPlugin::~PVArrayPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
void PVArrayPlugin::create()
|
||||
{
|
||||
static bool firstTime = true;
|
||||
if(firstTime) {
|
||||
firstTime = false;
|
||||
PVArrayPluginPtr pvPlugin = PVArrayPluginPtr(new PVArrayPlugin());
|
||||
PVPluginRegistry::registerPlugin(name,pvPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
PVFilterPtr PVArrayPlugin::create(
|
||||
const std::string & requestValue,
|
||||
const PVCopyPtr & pvCopy,
|
||||
const PVFieldPtr & master)
|
||||
{
|
||||
return PVArrayFilter::create(requestValue,master);
|
||||
}
|
||||
|
||||
PVArrayFilter::~PVArrayFilter()
|
||||
{
|
||||
}
|
||||
|
||||
static vector<string> split(string const & colonSeparatedList) {
|
||||
string::size_type numValues = 1;
|
||||
string::size_type index=0;
|
||||
while(true) {
|
||||
string::size_type pos = colonSeparatedList.find(':',index);
|
||||
if(pos==string::npos) break;
|
||||
numValues++;
|
||||
index = pos +1;
|
||||
}
|
||||
vector<string> valueList(numValues,"");
|
||||
index=0;
|
||||
for(size_t i=0; i<numValues; i++) {
|
||||
size_t pos = colonSeparatedList.find(':',index);
|
||||
string value = colonSeparatedList.substr(index,pos-index);
|
||||
valueList[i] = value;
|
||||
index = pos +1;
|
||||
}
|
||||
return valueList;
|
||||
}
|
||||
|
||||
PVArrayFilterPtr PVArrayFilter::create(
|
||||
const std::string & requestValue,
|
||||
const PVFieldPtr & masterField)
|
||||
{
|
||||
bool masterIsUnion = false;
|
||||
PVUnionPtr pvUnion;
|
||||
Type type = masterField->getField()->getType();
|
||||
if(type==epics::pvData::union_) {
|
||||
pvUnion = std::tr1::static_pointer_cast<PVUnion>(masterField);
|
||||
PVFieldPtr pvField = pvUnion->get();
|
||||
if(pvField) {
|
||||
masterIsUnion = true;
|
||||
type = pvField->getField()->getType();
|
||||
}
|
||||
}
|
||||
if(type!=scalarArray) {
|
||||
PVArrayFilterPtr filter = PVArrayFilterPtr();
|
||||
return filter;
|
||||
}
|
||||
long start =0;
|
||||
long increment =1;
|
||||
long end = -1;
|
||||
vector<string> values(split(requestValue));
|
||||
long num = values.size();
|
||||
bool ok = true;
|
||||
string value;
|
||||
if(num==1) {
|
||||
value = values[0];
|
||||
start = strtol(value.c_str(),0,10);
|
||||
} else if(num==2) {
|
||||
value = values[0];
|
||||
start = strtol(value.c_str(),0,10);
|
||||
value = values[1];
|
||||
end = strtol(value.c_str(),0,10);
|
||||
} else if(num==3) {
|
||||
value = values[0];
|
||||
start = strtol(value.c_str(),0,10);
|
||||
value = values[1];
|
||||
increment = strtol(value.c_str(),0,10);
|
||||
value = values[2];
|
||||
end = strtol(value.c_str(),0,10);
|
||||
} else {
|
||||
ok = false;
|
||||
}
|
||||
if(!ok) {
|
||||
PVArrayFilterPtr filter = PVArrayFilterPtr();
|
||||
return filter;
|
||||
}
|
||||
PVScalarArrayPtr masterArray;
|
||||
if(masterIsUnion) {
|
||||
masterArray = static_pointer_cast<PVScalarArray>(pvUnion->get());
|
||||
} else {
|
||||
masterArray = static_pointer_cast<PVScalarArray>(masterField);
|
||||
}
|
||||
PVArrayFilterPtr filter =
|
||||
PVArrayFilterPtr(
|
||||
new PVArrayFilter(start,increment,end,masterField,masterArray));
|
||||
return filter;
|
||||
}
|
||||
|
||||
PVArrayFilter::PVArrayFilter(
|
||||
long start,long increment,long end,
|
||||
const PVFieldPtr & masterField,
|
||||
const epics::pvData::PVScalarArrayPtr masterArray)
|
||||
: start(start),
|
||||
increment(increment),
|
||||
end(end),
|
||||
masterField(masterField),
|
||||
masterArray(masterArray)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool PVArrayFilter::filter(const PVFieldPtr & pvField,const BitSetPtr & bitSet,bool toCopy)
|
||||
{
|
||||
PVFieldPtr pvCopy = pvField;
|
||||
PVScalarArrayPtr copyArray;
|
||||
bool isUnion = false;
|
||||
Type type = masterField->getField()->getType();
|
||||
if(type==epics::pvData::union_) {
|
||||
isUnion = true;
|
||||
PVUnionPtr pvMasterUnion = std::tr1::static_pointer_cast<PVUnion>(masterField);
|
||||
PVUnionPtr pvCopyUnion = std::tr1::static_pointer_cast<PVUnion>(pvCopy);
|
||||
if(toCopy) pvCopyUnion->copy(*pvMasterUnion);
|
||||
PVFieldPtr pvField = pvCopyUnion->get();
|
||||
copyArray = static_pointer_cast<PVScalarArray>(pvField);
|
||||
} else {
|
||||
copyArray = static_pointer_cast<PVScalarArray>(pvCopy);
|
||||
}
|
||||
long len = 0;
|
||||
long start = this->start;
|
||||
long end = this->end;
|
||||
long no_elements = masterArray->getLength();
|
||||
if(start<0) {
|
||||
start = no_elements+start;
|
||||
if(start<0) start = 0;
|
||||
}
|
||||
if (end < 0) {
|
||||
end = no_elements + end;
|
||||
if (end < 0) end = 0;
|
||||
|
||||
}
|
||||
if(toCopy) {
|
||||
if (end >= no_elements) end = no_elements - 1;
|
||||
if (end - start >= 0) len = 1 + (end - start) / increment;
|
||||
if(len<=0 || start>=no_elements) {
|
||||
copyArray->setLength(0);
|
||||
return true;
|
||||
}
|
||||
long indfrom = start;
|
||||
long indto = 0;
|
||||
copyArray->setCapacity(len);
|
||||
if(increment==1) {
|
||||
copy(*masterArray,indfrom,1,*copyArray,indto,1,len);
|
||||
} else {
|
||||
for(long i=0; i<len; ++i) {
|
||||
copy(*masterArray,indfrom,1,*copyArray,indto,1,1);
|
||||
indfrom += increment;
|
||||
indto += 1;
|
||||
}
|
||||
}
|
||||
copyArray->setLength(len);
|
||||
bitSet->set(pvField->getFieldOffset());
|
||||
return true;
|
||||
}
|
||||
if (end - start >= 0) len = 1 + (end - start) / increment;
|
||||
if(len<=0) return true;
|
||||
if(no_elements<=end) masterArray->setLength(end+1);
|
||||
long indfrom = 0;
|
||||
long indto = start;
|
||||
if(increment==1) {
|
||||
copy(*copyArray,indfrom,1,*masterArray,indto,1,len);
|
||||
} else {
|
||||
for(long i=0; i<len; ++i) {
|
||||
copy(*copyArray,indfrom,1,*masterArray,indto,1,1);
|
||||
indfrom += 1;
|
||||
indto += increment;
|
||||
}
|
||||
}
|
||||
if(isUnion) masterField->postPut();
|
||||
return true;
|
||||
}
|
||||
|
||||
string PVArrayFilter::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,792 +0,0 @@
|
||||
/* pvCopy.cpp */
|
||||
/*
|
||||
* License terms for this software can be found in the file LICENSE that is included with the distribution
|
||||
*/
|
||||
/**
|
||||
* @author Marty Kraimer
|
||||
* @date 2013.04
|
||||
*/
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
#include <epicsThread.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/bitSet.h>
|
||||
#include <pv/thread.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvPlugin.h"
|
||||
#include "pv/pvStructureCopy.h"
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using std::tr1::dynamic_pointer_cast;
|
||||
using std::string;
|
||||
using std::size_t;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::vector;
|
||||
using namespace epics::pvData;
|
||||
|
||||
namespace epics { namespace pvCopy {
|
||||
|
||||
/**
|
||||
* Convenience method for implementing dump.
|
||||
* It generates a newline and inserts blanks at the beginning of the newline.
|
||||
* @param builder The std::string * being constructed.
|
||||
* @param indentLevel Indent level, Each level is four spaces.
|
||||
*/
|
||||
static void newLine(string *buffer, int indentLevel)
|
||||
{
|
||||
*buffer += "\n";
|
||||
*buffer += string(indentLevel*4, ' ');
|
||||
}
|
||||
|
||||
static PVCopyPtr NULLPVCopy;
|
||||
static StructureConstPtr NULLStructure;
|
||||
static PVStructurePtr NULLPVStructure;
|
||||
|
||||
struct CopyNode {
|
||||
CopyNode()
|
||||
: isStructure(false),
|
||||
structureOffset(0),
|
||||
nfields(0)
|
||||
{}
|
||||
PVFieldPtr masterPVField;
|
||||
bool isStructure;
|
||||
size_t structureOffset; // In the copy
|
||||
size_t nfields;
|
||||
PVStructurePtr options;
|
||||
vector<PVFilterPtr> pvFilters;
|
||||
};
|
||||
|
||||
static CopyNodePtr NULLCopyNode;
|
||||
|
||||
typedef std::vector<CopyNodePtr> CopyNodePtrArray;
|
||||
typedef std::tr1::shared_ptr<CopyNodePtrArray> CopyNodePtrArrayPtr;
|
||||
|
||||
struct CopyStructureNode : public CopyNode {
|
||||
CopyNodePtrArrayPtr nodes;
|
||||
};
|
||||
|
||||
PVCopyPtr PVCopy::create(
|
||||
PVStructurePtr const &pvMaster,
|
||||
PVStructurePtr const &pvRequest,
|
||||
string const & structureName)
|
||||
{
|
||||
PVStructurePtr pvStructure(pvRequest);
|
||||
if(structureName.size()>0) {
|
||||
if(pvStructure->getStructure()->getNumberFields()>0) {
|
||||
pvStructure = pvRequest->getSubField<PVStructure>(structureName);
|
||||
if(!pvStructure) return NULLPVCopy;
|
||||
}
|
||||
} else if(pvRequest->getSubField<PVStructure>("field")) {
|
||||
pvStructure = pvRequest->getSubField<PVStructure>("field");
|
||||
}
|
||||
PVCopyPtr pvCopy = PVCopyPtr(new PVCopy(pvMaster));
|
||||
bool result = pvCopy->init(pvStructure);
|
||||
if(!result) return PVCopyPtr();
|
||||
pvCopy->traverseMasterInitPlugin();
|
||||
return pvCopy;
|
||||
}
|
||||
|
||||
PVStructurePtr PVCopy::getPVMaster()
|
||||
{
|
||||
return pvMaster;
|
||||
}
|
||||
|
||||
void PVCopy::traverseMaster(PVCopyTraverseMasterCallbackPtr const & callback)
|
||||
{
|
||||
traverseMaster(headNode,callback);
|
||||
}
|
||||
|
||||
StructureConstPtr PVCopy::getStructure()
|
||||
{
|
||||
return structure;
|
||||
}
|
||||
|
||||
PVStructurePtr PVCopy::createPVStructure()
|
||||
{
|
||||
if(cacheInitStructure) {
|
||||
PVStructurePtr save = cacheInitStructure;
|
||||
cacheInitStructure.reset();
|
||||
return save;
|
||||
}
|
||||
PVStructurePtr pvStructure =
|
||||
getPVDataCreate()->createPVStructure(structure);
|
||||
return pvStructure;
|
||||
}
|
||||
|
||||
|
||||
size_t PVCopy::getCopyOffset(PVFieldPtr const &masterPVField)
|
||||
{
|
||||
if(!headNode->isStructure) {
|
||||
CopyNodePtr node = static_pointer_cast<CopyNode>(headNode);
|
||||
if((node->masterPVField.get())==masterPVField.get()) {
|
||||
return headNode->structureOffset;
|
||||
}
|
||||
PVStructure * parent = masterPVField->getParent();
|
||||
size_t offsetParent = parent->getFieldOffset();
|
||||
size_t off = masterPVField->getFieldOffset();
|
||||
size_t offdiff = off -offsetParent;
|
||||
if(offdiff<node->nfields) return headNode->structureOffset + offdiff;
|
||||
return string::npos;
|
||||
}
|
||||
CopyStructureNodePtr structNode = static_pointer_cast<CopyStructureNode>(headNode);
|
||||
CopyNodePtr node = getCopyOffset(structNode,masterPVField);
|
||||
if(node) return node->structureOffset;
|
||||
return string::npos;
|
||||
}
|
||||
|
||||
size_t PVCopy::getCopyOffset(
|
||||
PVStructurePtr const &masterPVStructure,
|
||||
PVFieldPtr const &masterPVField)
|
||||
{
|
||||
CopyNodePtr node;
|
||||
if(!headNode->isStructure) {
|
||||
node = static_pointer_cast<CopyNode>(headNode);
|
||||
if(node->masterPVField.get()!=masterPVStructure.get()) return string::npos;
|
||||
} else {
|
||||
CopyStructureNodePtr snode = static_pointer_cast<CopyStructureNode>(headNode);
|
||||
node = getCopyOffset(snode,masterPVField);
|
||||
}
|
||||
if(!node) return string::npos;
|
||||
size_t diff = masterPVField->getFieldOffset()
|
||||
- masterPVStructure->getFieldOffset();
|
||||
return node->structureOffset + diff;
|
||||
}
|
||||
|
||||
PVFieldPtr PVCopy::getMasterPVField(size_t structureOffset)
|
||||
{
|
||||
CopyNodePtr node;
|
||||
if(!headNode->isStructure) {
|
||||
node = headNode;
|
||||
} else {
|
||||
CopyStructureNodePtr snode = static_pointer_cast<CopyStructureNode>(headNode);
|
||||
node = getMasterNode(snode,structureOffset);
|
||||
}
|
||||
if(!node) {
|
||||
throw std::logic_error(
|
||||
"PVCopy::getMasterPVField: structureOffset not valid");
|
||||
}
|
||||
size_t diff = structureOffset - node->structureOffset;
|
||||
PVFieldPtr pvMasterField = node->masterPVField;
|
||||
if(diff==0) return pvMasterField;
|
||||
PVStructurePtr pvStructure
|
||||
= static_pointer_cast<PVStructure>(pvMasterField);
|
||||
return pvStructure->getSubField(
|
||||
pvMasterField->getFieldOffset() + diff);
|
||||
}
|
||||
|
||||
void PVCopy::initCopy(
|
||||
PVStructurePtr const ©PVStructure,
|
||||
BitSetPtr const &bitSet)
|
||||
{
|
||||
for(size_t i=0; i< copyPVStructure->getNumberFields(); ++i) {
|
||||
bitSet->set(i,true);
|
||||
}
|
||||
updateCopyFromBitSet(copyPVStructure,headNode,bitSet);
|
||||
}
|
||||
|
||||
|
||||
bool PVCopy::updateCopySetBitSet(
|
||||
PVStructurePtr const ©PVStructure,
|
||||
BitSetPtr const &bitSet)
|
||||
{
|
||||
updateCopySetBitSet(copyPVStructure,headNode,bitSet);
|
||||
return checkIgnore(copyPVStructure,bitSet);
|
||||
}
|
||||
|
||||
bool PVCopy::updateCopyFromBitSet(
|
||||
PVStructurePtr const ©PVStructure,
|
||||
BitSetPtr const &bitSet)
|
||||
{
|
||||
if(bitSet->get(0)) {
|
||||
for(size_t i=0; i< copyPVStructure->getNumberFields(); ++i) {
|
||||
bitSet->set(i,true);
|
||||
}
|
||||
}
|
||||
updateCopyFromBitSet(copyPVStructure,headNode,bitSet);
|
||||
return checkIgnore(copyPVStructure,bitSet);
|
||||
}
|
||||
|
||||
void PVCopy::updateMasterField(
|
||||
CopyNodePtr const & node,
|
||||
PVFieldPtr const & pvCopy,
|
||||
PVFieldPtr const &pvMaster,
|
||||
BitSetPtr const &bitSet)
|
||||
{
|
||||
bool result = false;
|
||||
for(size_t i=0; i< node->pvFilters.size(); ++i) {
|
||||
PVFilterPtr pvFilter = node->pvFilters[i];
|
||||
if(pvFilter->filter(pvCopy,bitSet,false)) result = true;
|
||||
}
|
||||
if(result) return;
|
||||
pvMaster->copyUnchecked(*pvCopy);
|
||||
}
|
||||
|
||||
void PVCopy::updateMasterCheckBitSet(
|
||||
PVStructurePtr const ©PVStructure,
|
||||
BitSetPtr const &bitSet,
|
||||
size_t nextSet)
|
||||
{
|
||||
if(!bitSet->get(nextSet)) {
|
||||
size_t next = bitSet->nextSetBit(nextSet);
|
||||
if(next==string::npos) return;
|
||||
updateMasterCheckBitSet(copyPVStructure,bitSet,next);
|
||||
return;
|
||||
}
|
||||
PVFieldPtr pvField = copyPVStructure;
|
||||
if(nextSet!=0) pvField = copyPVStructure->getSubField(nextSet);
|
||||
if(pvField->getField()->getType()==epics::pvData::structure) {
|
||||
bitSet->clear(nextSet);
|
||||
PVStructurePtr pv = static_pointer_cast<PVStructure>(pvField);
|
||||
PVFieldPtrArray pvFieldArray = pv->getPVFields();
|
||||
for(size_t i=0; i<pvFieldArray.size(); ++i) {
|
||||
PVFieldPtr pvField = pvFieldArray[i];
|
||||
bitSet->set(pvField->getFieldOffset());
|
||||
}
|
||||
}
|
||||
size_t next = bitSet->nextSetBit(nextSet+1);
|
||||
if(next==string::npos) return;
|
||||
updateMasterCheckBitSet(copyPVStructure,bitSet,next);
|
||||
}
|
||||
|
||||
CopyNodePtr PVCopy::getCopyNode(std::size_t fieldOffset)
|
||||
{
|
||||
if(fieldOffset==0) return headNode;
|
||||
CopyNodePtr node = headNode;
|
||||
while(true) {
|
||||
if(!node->isStructure) return node;
|
||||
CopyStructureNodePtr structNode = static_pointer_cast<CopyStructureNode>(node);
|
||||
CopyNodePtrArrayPtr nodes = structNode->nodes;
|
||||
bool okToContinue = false;
|
||||
for(size_t i=0; i< nodes->size(); i++) {
|
||||
node = (*nodes)[i];
|
||||
size_t soff = node->structureOffset;
|
||||
if(fieldOffset>=soff && fieldOffset<soff+node->nfields) {
|
||||
okToContinue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(okToContinue) continue;
|
||||
}
|
||||
throw std::logic_error("PVCopy::getCopyNode fieldOffset not valid");
|
||||
}
|
||||
|
||||
|
||||
void PVCopy::updateMaster(
|
||||
PVStructurePtr const ©PVStructure,
|
||||
BitSetPtr const &bitSet)
|
||||
{
|
||||
updateMasterCheckBitSet(copyPVStructure,bitSet,0);
|
||||
size_t nextSet =0;
|
||||
while(true) {
|
||||
nextSet = bitSet->nextSetBit(nextSet);
|
||||
if(nextSet==string::npos) return;
|
||||
PVFieldPtr pvCopy = copyPVStructure->getSubField(nextSet);
|
||||
PVFieldPtr pvMaster = headNode->masterPVField;
|
||||
if(pvMaster->getField()->getType()==epics::pvData::structure) {
|
||||
PVStructurePtr pv = static_pointer_cast<PVStructure>(pvMaster);
|
||||
pvMaster = pv->getSubField(pvCopy->getFullName());
|
||||
}
|
||||
updateMasterField(getCopyNode(nextSet),pvCopy,pvMaster,bitSet);
|
||||
bitSet->clear(nextSet);
|
||||
}
|
||||
}
|
||||
|
||||
PVStructurePtr PVCopy::getOptions(std::size_t fieldOffset)
|
||||
{
|
||||
if(fieldOffset==0) return headNode->options;
|
||||
CopyNodePtr node = headNode;
|
||||
while(true) {
|
||||
if(node->structureOffset==fieldOffset) return node->options;
|
||||
if(!node->isStructure) return NULLPVStructure;
|
||||
CopyStructureNodePtr structNode = static_pointer_cast<CopyStructureNode>(node);
|
||||
CopyNodePtrArrayPtr nodes = structNode->nodes;
|
||||
bool okToContinue = false;
|
||||
for(size_t i=0; i< nodes->size(); i++) {
|
||||
node = (*nodes)[i];
|
||||
size_t soff = node->structureOffset;
|
||||
if(fieldOffset>=soff && fieldOffset<soff+node->nfields) {
|
||||
if(fieldOffset==soff) return node->options;
|
||||
if(!node->isStructure) {
|
||||
return NULLPVStructure;
|
||||
}
|
||||
okToContinue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(okToContinue) continue;
|
||||
throw std::logic_error("PVCopy::getOptions logic error: fieldOffset not valid");
|
||||
}
|
||||
}
|
||||
|
||||
string PVCopy::dump()
|
||||
{
|
||||
string builder;
|
||||
dump(&builder,headNode,0);
|
||||
return builder;
|
||||
}
|
||||
|
||||
void PVCopy::traverseMaster(
|
||||
CopyNodePtr const &innode,
|
||||
PVCopyTraverseMasterCallbackPtr const & callback)
|
||||
{
|
||||
CopyNodePtr node = innode;
|
||||
if(!node->isStructure) {
|
||||
callback->nextMasterPVField(node->masterPVField);
|
||||
return;
|
||||
}
|
||||
CopyStructureNodePtr structNode = static_pointer_cast<CopyStructureNode>(node);
|
||||
CopyNodePtrArrayPtr nodes = structNode->nodes;
|
||||
for(size_t i=0; i< nodes->size(); i++) {
|
||||
node = (*nodes)[i];
|
||||
traverseMaster(node,callback);
|
||||
}
|
||||
}
|
||||
|
||||
void PVCopy::updateCopySetBitSet(
|
||||
PVFieldPtr const & pvCopy,
|
||||
PVFieldPtr const & pvMaster,
|
||||
BitSetPtr const & bitSet)
|
||||
{
|
||||
if(pvCopy->getField()->getType()!=epics::pvData::structure) {
|
||||
if(*pvCopy==*pvMaster) return;
|
||||
pvCopy->copy(*pvMaster);
|
||||
bitSet->set(pvCopy->getFieldOffset());
|
||||
return;
|
||||
}
|
||||
PVStructurePtr pvCopyStructure = static_pointer_cast<PVStructure>(pvCopy);
|
||||
PVFieldPtrArray const & pvCopyFields = pvCopyStructure->getPVFields();
|
||||
for(size_t i=0; i<pvCopyFields.size(); ++i) {
|
||||
PVFieldPtr master = getMasterPVField(pvCopyFields[i]->getFieldOffset());
|
||||
updateCopySetBitSet(pvCopyFields[i],master,bitSet);
|
||||
}
|
||||
}
|
||||
|
||||
void PVCopy::updateCopySetBitSet(
|
||||
PVFieldPtr const & pvCopy,
|
||||
CopyNodePtr const & node,
|
||||
BitSetPtr const & bitSet)
|
||||
{
|
||||
bool result = false;
|
||||
for(size_t i=0; i< node->pvFilters.size(); ++i) {
|
||||
PVFilterPtr pvFilter = node->pvFilters[i];
|
||||
if(pvFilter->filter(pvCopy,bitSet,true)) result = true;
|
||||
}
|
||||
if(!node->isStructure) {
|
||||
if(result) return;
|
||||
updateCopySetBitSet(pvCopy,node->masterPVField,bitSet);
|
||||
return;
|
||||
}
|
||||
CopyStructureNodePtr structureNode = static_pointer_cast<CopyStructureNode>(node);
|
||||
PVStructurePtr pvCopyStructure = static_pointer_cast<PVStructure>(pvCopy);
|
||||
PVFieldPtrArray const & pvCopyFields = pvCopyStructure->getPVFields();
|
||||
for(size_t i=0; i<pvCopyFields.size(); ++i) {
|
||||
updateCopySetBitSet(pvCopyFields[i],(*structureNode->nodes)[i],bitSet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PVCopy::updateCopyFromBitSet(
|
||||
PVFieldPtr const & pvCopy,
|
||||
CopyNodePtr const & node,
|
||||
BitSetPtr const & bitSet)
|
||||
{
|
||||
bool result = false;
|
||||
bool update = bitSet->get(pvCopy->getFieldOffset());
|
||||
if(update) {
|
||||
for(size_t i=0; i< node->pvFilters.size(); ++i) {
|
||||
PVFilterPtr pvFilter = node->pvFilters[i];
|
||||
if(pvFilter->filter(pvCopy,bitSet,true)) result = true;
|
||||
}
|
||||
}
|
||||
if(!node->isStructure) {
|
||||
if(result) return;
|
||||
PVFieldPtr pvMaster = node->masterPVField;
|
||||
pvCopy->copy(*pvMaster);
|
||||
return;
|
||||
}
|
||||
CopyStructureNodePtr structureNode = static_pointer_cast<CopyStructureNode>(node);
|
||||
size_t offset = structureNode->structureOffset;
|
||||
size_t nextSet = bitSet->nextSetBit(offset);
|
||||
if(nextSet==string::npos) return;
|
||||
if(offset>=pvCopy->getNextFieldOffset()) return;
|
||||
PVStructurePtr pvCopyStructure = static_pointer_cast<PVStructure>(pvCopy);
|
||||
PVFieldPtrArray const & pvCopyFields = pvCopyStructure->getPVFields();
|
||||
for(size_t i=0; i<pvCopyFields.size(); ++i) {
|
||||
updateCopyFromBitSet(pvCopyFields[i],(*structureNode->nodes)[i],bitSet);
|
||||
}
|
||||
}
|
||||
|
||||
PVCopy::PVCopy(
|
||||
PVStructurePtr const &pvMaster)
|
||||
: pvMaster(pvMaster)
|
||||
{
|
||||
}
|
||||
|
||||
bool PVCopy::init(epics::pvData::PVStructurePtr const &pvRequest)
|
||||
{
|
||||
PVStructurePtr pvMasterStructure = pvMaster;
|
||||
size_t len = pvRequest->getPVFields().size();
|
||||
bool entireMaster = false;
|
||||
PVStructurePtr pvOptions;
|
||||
if(len==0) {
|
||||
entireMaster = true;
|
||||
}
|
||||
else {
|
||||
// If "_" is in the request, but not in the master structure,
|
||||
// then assume the top level PV structure is requested
|
||||
PVStructurePtr masterFieldPtr = pvMaster->getSubField<PVStructure>("_");
|
||||
PVStructurePtr requestFieldPtr = pvRequest->getSubField<PVStructure>("_");
|
||||
if (!masterFieldPtr && requestFieldPtr) {
|
||||
entireMaster = true;
|
||||
pvOptions = requestFieldPtr->getSubField<PVStructure>("_options");
|
||||
}
|
||||
}
|
||||
if(entireMaster) {
|
||||
structure = pvMasterStructure->getStructure();
|
||||
CopyNodePtr node(new CopyNode());
|
||||
headNode = node;
|
||||
node->options = pvOptions;
|
||||
node->isStructure = false;
|
||||
node->structureOffset = 0;
|
||||
node->masterPVField = pvMasterStructure;
|
||||
node->nfields = pvMasterStructure->getNumberFields();
|
||||
return true;
|
||||
}
|
||||
structure = createStructure(pvMasterStructure,pvRequest);
|
||||
if(!structure) return false;
|
||||
cacheInitStructure = createPVStructure();
|
||||
ignorechangeBitSet = BitSetPtr(new BitSet(cacheInitStructure->getNumberFields()));
|
||||
headNode = createStructureNodes(
|
||||
pvMaster,
|
||||
pvRequest,
|
||||
cacheInitStructure);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
StructureConstPtr PVCopy::createStructure(
|
||||
PVStructurePtr const &pvMaster,
|
||||
PVStructurePtr const &pvFromRequest)
|
||||
{
|
||||
if(pvFromRequest->getStructure()->getNumberFields()==0) {
|
||||
return pvMaster->getStructure();
|
||||
}
|
||||
PVFieldPtrArray const &pvFromRequestFields = pvFromRequest->getPVFields();
|
||||
StringArray const &fromRequestFieldNames = pvFromRequest->getStructure()->getFieldNames();
|
||||
size_t length = pvFromRequestFields.size();
|
||||
if(length==0) return NULLStructure;
|
||||
FieldConstPtrArray fields; fields.reserve(length);
|
||||
StringArray fieldNames; fieldNames.reserve(length);
|
||||
for(size_t i=0; i<length; ++i) {
|
||||
string const &fieldName = fromRequestFieldNames[i];
|
||||
PVFieldPtr pvMasterField = pvMaster->getSubField(fieldName);
|
||||
if(!pvMasterField) continue;
|
||||
FieldConstPtr field = pvMasterField->getField();
|
||||
if(field->getType()==epics::pvData::structure) {
|
||||
PVStructurePtr pvRequestStructure = static_pointer_cast<PVStructure>(
|
||||
pvFromRequestFields[i]);
|
||||
if(pvRequestStructure->getNumberFields()>0) {
|
||||
StringArray const &names = pvRequestStructure->getStructure()->
|
||||
getFieldNames();
|
||||
size_t num = names.size();
|
||||
if(num>0 && names[0].compare("_options")==0) --num;
|
||||
if(num>0) {
|
||||
if(pvMasterField->getField()->getType()!=epics::pvData::structure) continue;
|
||||
fieldNames.push_back(fieldName);
|
||||
fields.push_back(createStructure(
|
||||
static_pointer_cast<PVStructure>(pvMasterField),
|
||||
pvRequestStructure));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldNames.push_back(fieldName);
|
||||
fields.push_back(field);
|
||||
}
|
||||
size_t numsubfields = fields.size();
|
||||
if(numsubfields==0) {
|
||||
std::stringstream ss;
|
||||
ss << pvFromRequest << "\n";
|
||||
string val("no fields from the following request were found\n");
|
||||
val += ss.str();
|
||||
throw std::invalid_argument(val);
|
||||
}
|
||||
return getFieldCreate()->createStructure(fieldNames, fields);
|
||||
}
|
||||
|
||||
CopyNodePtr PVCopy::createStructureNodes(
|
||||
PVStructurePtr const &pvMasterStructure,
|
||||
PVStructurePtr const &pvFromRequest,
|
||||
PVStructurePtr const &pvFromCopy)
|
||||
{
|
||||
PVFieldPtrArray const & copyPVFields = pvFromCopy->getPVFields();
|
||||
PVStructurePtr pvOptions = pvFromRequest->getSubField<PVStructure>("_options");
|
||||
size_t number = copyPVFields.size();
|
||||
CopyNodePtrArrayPtr nodes(new CopyNodePtrArray());
|
||||
nodes->reserve(number);
|
||||
for(size_t i=0; i<number; i++) {
|
||||
PVFieldPtr copyPVField = copyPVFields[i];
|
||||
string fieldName = copyPVField->getFieldName();
|
||||
PVStructurePtr requestPVStructure =
|
||||
pvFromRequest->getSubField<PVStructure>(fieldName);
|
||||
PVStructurePtr pvSubFieldOptions =
|
||||
requestPVStructure->getSubField<PVStructure>("_options");
|
||||
PVFieldPtr pvMasterField = pvMasterStructure->getSubField(fieldName);
|
||||
if(!pvMasterField) {
|
||||
throw std::logic_error("PVCopy::createStructureNodes did not find field in master");
|
||||
}
|
||||
size_t numberRequest = requestPVStructure->getPVFields().size();
|
||||
bool haveOptions = false;
|
||||
if(pvSubFieldOptions) {
|
||||
numberRequest--;
|
||||
haveOptions = true;
|
||||
}
|
||||
if(numberRequest>0) {
|
||||
Type copyType = copyPVField->getField()->getType();
|
||||
if(copyType==epics::pvData::structure) {
|
||||
nodes->push_back(createStructureNodes(
|
||||
static_pointer_cast<PVStructure>(pvMasterField),
|
||||
requestPVStructure,
|
||||
static_pointer_cast<PVStructure>(copyPVField)));
|
||||
continue;
|
||||
}
|
||||
if(copyType==epics::pvData::union_) {
|
||||
if(numberRequest!=1) {
|
||||
std::stringstream ss;
|
||||
ss << pvFromRequest << "\n";
|
||||
string val("In the following request a union field has more than one subfield in\n");
|
||||
val += ss.str();
|
||||
throw std::invalid_argument(val);
|
||||
}
|
||||
PVUnionPtr pvUnion = static_pointer_cast<PVUnion>(pvMasterField);
|
||||
std::string selectedName = pvUnion->getSelectedFieldName();
|
||||
PVFieldPtrArray const & pvFields = requestPVStructure->getPVFields();
|
||||
size_t len = pvFields.size();
|
||||
if(len>2 || (haveOptions && len!=2)) {
|
||||
std::stringstream ss;
|
||||
ss << pvFromRequest << "\n";
|
||||
string val("PVCopy logic error: pvRequest is\n");
|
||||
val += ss.str();
|
||||
throw std::logic_error(val);
|
||||
}
|
||||
size_t indRequestValue = 0;
|
||||
if((pvFields[0]->getFieldName().compare("_options"))==0) indRequestValue = 1;
|
||||
PVFieldPtr pvRequestValue = pvFields[indRequestValue];
|
||||
if(pvRequestValue) {
|
||||
string requestName = pvRequestValue->getFieldName();
|
||||
if(requestName.compare(selectedName)!=0) {
|
||||
std::stringstream ss;
|
||||
ss << pvFromCopy << "\n";
|
||||
string requestName = pvRequestValue->getFieldName();
|
||||
string val("field ");
|
||||
val += requestName + " does not match union type in\n";
|
||||
val += ss.str();
|
||||
throw std::invalid_argument(val);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::stringstream ss;
|
||||
ss << pvFromCopy << "\n";
|
||||
string val("requested a subfield of field ");
|
||||
val += fieldName + " which does not have type structure in\n";
|
||||
val += ss.str();
|
||||
throw std::invalid_argument(val);
|
||||
}
|
||||
}
|
||||
CopyNodePtr node(new CopyNode());
|
||||
node->options = pvSubFieldOptions;
|
||||
node->isStructure = false;
|
||||
node->masterPVField = pvMasterField;
|
||||
node->nfields = copyPVField->getNumberFields();
|
||||
node->structureOffset = copyPVField->getFieldOffset();
|
||||
nodes->push_back(node);
|
||||
}
|
||||
CopyStructureNodePtr structureNode(new CopyStructureNode());
|
||||
structureNode->masterPVField = pvMasterStructure;
|
||||
structureNode->isStructure = true;
|
||||
structureNode->nodes = nodes;
|
||||
structureNode->structureOffset = pvFromCopy->getFieldOffset();
|
||||
structureNode->nfields = pvFromCopy->getNumberFields();
|
||||
structureNode->options = pvOptions;
|
||||
return structureNode;
|
||||
}
|
||||
|
||||
void PVCopy::initPlugin(
|
||||
CopyNodePtr const & node,
|
||||
PVStructurePtr const & pvOptions,
|
||||
PVFieldPtr const & pvMasterField)
|
||||
{
|
||||
PVFieldPtrArray const & pvFields = pvOptions->getPVFields();
|
||||
size_t num = pvFields.size();
|
||||
vector<PVFilterPtr> pvFilters(num);
|
||||
size_t numfilter = 0;
|
||||
for(size_t i=0; i<num; ++i) {
|
||||
PVStringPtr pvOption = static_pointer_cast<PVString>(pvFields[i]);
|
||||
string name = pvOption->getFieldName();
|
||||
string value = pvOption->get();
|
||||
PVPluginPtr pvPlugin = PVPluginRegistry::find(name);
|
||||
if(!pvPlugin) {
|
||||
if(name.compare("ignore")==0) setIgnore(node);
|
||||
continue;
|
||||
}
|
||||
pvFilters[numfilter] = pvPlugin->create(value,shared_from_this(),pvMasterField);
|
||||
if(pvFilters[numfilter]) ++numfilter;
|
||||
}
|
||||
if(numfilter==0) return;
|
||||
node->pvFilters.resize(numfilter);
|
||||
for(size_t i=0; i<numfilter; ++i) node->pvFilters[i] = pvFilters[i];
|
||||
}
|
||||
|
||||
void PVCopy::traverseMasterInitPlugin()
|
||||
{
|
||||
traverseMasterInitPlugin(headNode);
|
||||
}
|
||||
|
||||
void PVCopy::traverseMasterInitPlugin(CopyNodePtr const & node)
|
||||
{
|
||||
PVFieldPtr pvField = node->masterPVField;
|
||||
PVStructurePtr pvOptions = node->options;
|
||||
if(pvOptions) initPlugin(node,pvOptions,pvField);
|
||||
if(!node->isStructure) return;
|
||||
CopyStructureNodePtr structureNode = static_pointer_cast<CopyStructureNode>(node);
|
||||
CopyNodePtrArrayPtr nodes = structureNode->nodes;
|
||||
for(size_t i=0; i< nodes->size(); i++) {
|
||||
traverseMasterInitPlugin((*nodes)[i]);
|
||||
}
|
||||
}
|
||||
|
||||
CopyNodePtr PVCopy::getCopyOffset(
|
||||
CopyStructureNodePtr const &structureNode,
|
||||
PVFieldPtr const &masterPVField)
|
||||
{
|
||||
size_t offset = masterPVField->getFieldOffset();
|
||||
CopyNodePtrArrayPtr nodes = structureNode->nodes;
|
||||
for(size_t i=0; i< nodes->size(); i++) {
|
||||
CopyNodePtr node = (*nodes)[i];
|
||||
if(!node->isStructure) {
|
||||
size_t off = node->masterPVField->getFieldOffset();
|
||||
size_t nextOffset = node->masterPVField->getNextFieldOffset();
|
||||
if(offset>= off && offset<nextOffset) return node;
|
||||
} else {
|
||||
CopyStructureNodePtr subNode =
|
||||
static_pointer_cast<CopyStructureNode>(node);
|
||||
CopyNodePtr node =
|
||||
getCopyOffset(subNode,masterPVField);
|
||||
if(node) return node;
|
||||
}
|
||||
}
|
||||
return NULLCopyNode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool PVCopy::checkIgnore(
|
||||
PVStructurePtr const & copyPVStructure,
|
||||
BitSetPtr const & bitSet)
|
||||
{
|
||||
if(!ignorechangeBitSet) {
|
||||
return (bitSet->nextSetBit(0)<0) ? false : true;
|
||||
}
|
||||
int32 numFields = copyPVStructure->getNumberFields();
|
||||
BitSet temp(numFields);
|
||||
temp = *bitSet;
|
||||
int32 ind = 0;
|
||||
while(true) {
|
||||
ind = ignorechangeBitSet->nextSetBit(ind);
|
||||
if(ind<0) break;
|
||||
temp.clear(ind);
|
||||
ind++;
|
||||
if(ind>=numFields) break;
|
||||
}
|
||||
return (temp.nextSetBit(0)<0) ? false : true;
|
||||
}
|
||||
|
||||
void PVCopy::setIgnore(CopyNodePtr const &node) {
|
||||
ignorechangeBitSet->set(node->structureOffset);
|
||||
if(node->isStructure) {
|
||||
CopyStructureNodePtr structureNode = static_pointer_cast<CopyStructureNode>(node);
|
||||
CopyNodePtrArrayPtr nodes = structureNode->nodes;
|
||||
for(size_t i=0; i<nodes->size(); ++i) {
|
||||
CopyNodePtr node = (*nodes)[i];
|
||||
setIgnore(node); }
|
||||
} else {
|
||||
size_t num = node->masterPVField->getNumberFields();
|
||||
if(num>1) {
|
||||
for(size_t i=1; i<num; ++i) {
|
||||
ignorechangeBitSet->set(node->structureOffset+i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CopyNodePtr PVCopy::getMasterNode(
|
||||
CopyStructureNodePtr const &structureNode,
|
||||
std::size_t structureOffset)
|
||||
{
|
||||
CopyNodePtrArrayPtr nodes = structureNode->nodes;
|
||||
for(size_t i=0; i<nodes->size(); ++i) {
|
||||
CopyNodePtr node = (*nodes)[i];
|
||||
if(structureOffset>=(node->structureOffset + node->nfields)) continue;
|
||||
if(!node->isStructure) return node;
|
||||
CopyStructureNodePtr subNode =
|
||||
static_pointer_cast<CopyStructureNode>(node);
|
||||
return getMasterNode(subNode,structureOffset);
|
||||
}
|
||||
return NULLCopyNode;
|
||||
}
|
||||
|
||||
void PVCopy::dump(string *builder,CopyNodePtr const &node,int indentLevel)
|
||||
{
|
||||
newLine(builder,indentLevel);
|
||||
std::stringstream ss;
|
||||
ss << (node->isStructure ? "structureNode" : "node");
|
||||
ss << " structureOffset " << node->structureOffset;
|
||||
ss << " nfields " << node->nfields;
|
||||
*builder += ss.str();
|
||||
PVStructurePtr options = node->options;
|
||||
if(options) {
|
||||
newLine(builder,indentLevel +1);
|
||||
*builder += options->getFieldName();
|
||||
PVFieldPtrArray pvFields = options->getPVFields();
|
||||
for(size_t i=0; i< pvFields.size() ; ++i) {
|
||||
PVStringPtr pvString = static_pointer_cast<PVString>(pvFields[i]);
|
||||
newLine(builder,indentLevel +2);
|
||||
*builder += pvString->getFieldName() + " " + pvString->get();
|
||||
}
|
||||
}
|
||||
string name = node->masterPVField->getFullName();
|
||||
newLine(builder,indentLevel +1);
|
||||
*builder += "masterField " + name;
|
||||
if(node->pvFilters.size()>0) {
|
||||
newLine(builder,indentLevel +2);
|
||||
*builder += "filters:";
|
||||
for(size_t i=0; i< node->pvFilters.size(); ++i) {
|
||||
PVFilterPtr pvFilter = node->pvFilters[i];
|
||||
*builder += " " + pvFilter->getName();
|
||||
}
|
||||
}
|
||||
if(!node->isStructure) return;
|
||||
CopyStructureNodePtr structureNode =
|
||||
static_pointer_cast<CopyStructureNode>(node);
|
||||
CopyNodePtrArrayPtr nodes = structureNode->nodes;
|
||||
for(size_t i=0; i<nodes->size(); ++i) {
|
||||
CopyNodePtr node = (*nodes)[i];
|
||||
if(!node) {
|
||||
newLine(builder,indentLevel +1);
|
||||
ss.str("");
|
||||
ss << "node[" << i << "] is null";
|
||||
*builder += ss.str();
|
||||
continue;
|
||||
}
|
||||
dump(builder,node,indentLevel+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
@@ -1,134 +0,0 @@
|
||||
/* pvDeadbandPlugin.cpp */
|
||||
/*
|
||||
* The License for this software can be found in the file LICENSE that is included with the distribution.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/bitSet.h>
|
||||
#include <pv/convert.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvDeadbandPlugin.h"
|
||||
|
||||
using std::string;
|
||||
using std::size_t;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using std::vector;
|
||||
using namespace epics::pvData;
|
||||
|
||||
namespace epics { namespace pvCopy{
|
||||
|
||||
static ConvertPtr convert = getConvert();
|
||||
static std::string name("deadband");
|
||||
|
||||
PVDeadbandPlugin::PVDeadbandPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
PVDeadbandPlugin::~PVDeadbandPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
void PVDeadbandPlugin::create()
|
||||
{
|
||||
static bool firstTime = true;
|
||||
if(firstTime) {
|
||||
firstTime = false;
|
||||
PVDeadbandPluginPtr pvPlugin = PVDeadbandPluginPtr(new PVDeadbandPlugin());
|
||||
PVPluginRegistry::registerPlugin(name,pvPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
PVFilterPtr PVDeadbandPlugin::create(
|
||||
const std::string & requestValue,
|
||||
const PVCopyPtr & pvCopy,
|
||||
const PVFieldPtr & master)
|
||||
{
|
||||
return PVDeadbandFilter::create(requestValue,master);
|
||||
}
|
||||
|
||||
PVDeadbandFilter::~PVDeadbandFilter()
|
||||
{
|
||||
}
|
||||
|
||||
PVDeadbandFilterPtr PVDeadbandFilter::create(
|
||||
const std::string & requestValue,
|
||||
const PVFieldPtr & master)
|
||||
{
|
||||
FieldConstPtr field =master->getField();
|
||||
Type type = field->getType();
|
||||
if(type!=scalar) return PVDeadbandFilterPtr();
|
||||
ScalarConstPtr scalar = static_pointer_cast<const Scalar>(field);
|
||||
if(!ScalarTypeFunc::isNumeric(scalar->getScalarType())) return PVDeadbandFilterPtr();
|
||||
bool absolute = false;
|
||||
if(requestValue.find("abs")==0) {
|
||||
absolute = true;
|
||||
} else if(requestValue.find("rel")==0) {
|
||||
absolute = false;
|
||||
} else {
|
||||
return PVDeadbandFilterPtr();
|
||||
}
|
||||
size_t ind = requestValue.find(':');
|
||||
if(ind==string::npos) return PVDeadbandFilterPtr();
|
||||
string svalue = requestValue.substr(ind+1);
|
||||
double deadband = atof(svalue.c_str());
|
||||
if(deadband==0.0) return PVDeadbandFilterPtr();
|
||||
PVDeadbandFilterPtr filter =
|
||||
PVDeadbandFilterPtr(
|
||||
new PVDeadbandFilter(
|
||||
absolute,deadband,static_pointer_cast<PVScalar>(master)));
|
||||
return filter;
|
||||
}
|
||||
|
||||
PVDeadbandFilter::PVDeadbandFilter(bool absolute,double deadband,PVScalarPtr const & master)
|
||||
: absolute(absolute),
|
||||
deadband(deadband),
|
||||
master(master),
|
||||
firstTime(true),
|
||||
lastReportedValue(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool PVDeadbandFilter::filter(const PVFieldPtr & pvCopy,const BitSetPtr & bitSet,bool toCopy)
|
||||
{
|
||||
if(!toCopy) return false;
|
||||
double value = convert->toDouble(master);
|
||||
double diff = value - lastReportedValue;
|
||||
if(diff<0.0) diff = - diff;
|
||||
bool report = true;
|
||||
if(firstTime) {
|
||||
firstTime = false;
|
||||
} else if(absolute) {
|
||||
if(diff<deadband) report = false;
|
||||
} else {
|
||||
double last = lastReportedValue;
|
||||
if(last<0.0) last = -last;
|
||||
if(last>1e-20) {
|
||||
double percent = (diff/last)*100.0;
|
||||
if(percent<deadband) report = false;
|
||||
}
|
||||
}
|
||||
PVScalarPtr copy = static_pointer_cast<PVScalar>(pvCopy);
|
||||
convert->fromDouble(copy,value);
|
||||
if(report) {
|
||||
lastReportedValue = value;
|
||||
bitSet->set(pvCopy->getFieldOffset());
|
||||
} else {
|
||||
bitSet->clear(pvCopy->getFieldOffset());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string PVDeadbandFilter::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,40 +0,0 @@
|
||||
/* pvPlugin.cpp */
|
||||
/*
|
||||
* The License for this software can be found in the file LICENSE that is included with the distribution.
|
||||
*/
|
||||
|
||||
#include <pv/pvData.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/bitSet.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvPlugin.h"
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
namespace epics { namespace pvCopy{
|
||||
|
||||
typedef std::map<std::string,PVPluginPtr> PVPluginMap;
|
||||
|
||||
static PVPluginMap pluginMap;
|
||||
static Mutex mutex;
|
||||
|
||||
void PVPluginRegistry::registerPlugin(const std::string & name,const PVPluginPtr & pvPlugin)
|
||||
{
|
||||
Lock xx(mutex);
|
||||
PVPluginMap::iterator iter = pluginMap.find(name);
|
||||
if(iter!=pluginMap.end()) throw std::logic_error("plugin already registered");
|
||||
pluginMap.insert(PVPluginMap::value_type(name,pvPlugin));
|
||||
}
|
||||
|
||||
PVPluginPtr PVPluginRegistry::find(const std::string & name)
|
||||
{
|
||||
Lock xx(mutex);
|
||||
PVPluginMap::iterator iter = pluginMap.find(name);
|
||||
if(iter!=pluginMap.end()) return (*iter).second;
|
||||
return PVPluginPtr();
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,126 +0,0 @@
|
||||
/* pvTimestampPlugin.cpp */
|
||||
/*
|
||||
* The License for this software can be found in the file LICENSE that is included with the distribution.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/bitSet.h>
|
||||
#include <pv/convert.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvPlugin.h"
|
||||
#include "pv/pvTimestampPlugin.h"
|
||||
|
||||
|
||||
using std::string;
|
||||
using std::size_t;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using std::vector;
|
||||
using namespace epics::pvData;
|
||||
|
||||
namespace epics { namespace pvCopy{
|
||||
|
||||
static ConvertPtr convert = getConvert();
|
||||
static std::string name("timestamp");
|
||||
|
||||
PVTimestampPlugin::PVTimestampPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
PVTimestampPlugin::~PVTimestampPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
void PVTimestampPlugin::create()
|
||||
{
|
||||
static bool firstTime = true;
|
||||
if(firstTime) {
|
||||
firstTime = false;
|
||||
PVTimestampPluginPtr pvPlugin = PVTimestampPluginPtr(new PVTimestampPlugin());
|
||||
PVPluginRegistry::registerPlugin(name,pvPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
PVFilterPtr PVTimestampPlugin::create(
|
||||
const std::string & requestValue,
|
||||
const PVCopyPtr & pvCopy,
|
||||
const PVFieldPtr & master)
|
||||
{
|
||||
return PVTimestampFilter::create(requestValue,master);
|
||||
}
|
||||
|
||||
PVTimestampFilter::~PVTimestampFilter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PVTimestampFilterPtr PVTimestampFilter::create(
|
||||
const std::string & requestValue,
|
||||
const PVFieldPtr & master)
|
||||
{
|
||||
PVTimeStamp pvTimeStamp;
|
||||
if(!pvTimeStamp.attach(master)) return PVTimestampFilterPtr();
|
||||
bool current = false;
|
||||
bool copy = false;
|
||||
if(requestValue.compare("current")==0) {
|
||||
current = true;
|
||||
} else if(requestValue.compare("copy")==0){
|
||||
copy = true;
|
||||
} else {
|
||||
return PVTimestampFilterPtr();
|
||||
}
|
||||
PVTimestampFilterPtr filter = PVTimestampFilterPtr(
|
||||
new PVTimestampFilter(current,copy,master));
|
||||
return filter;
|
||||
}
|
||||
|
||||
PVTimestampFilter::PVTimestampFilter(bool current,bool copy,PVFieldPtr const & master)
|
||||
: current(current),
|
||||
copy(copy),
|
||||
master(master)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool PVTimestampFilter::filter(const PVFieldPtr & pvCopy,const BitSetPtr & bitSet,bool toCopy)
|
||||
{
|
||||
if(current) {
|
||||
timeStamp.getCurrent();
|
||||
if(toCopy) {
|
||||
if(!pvTimeStamp.attach(pvCopy)) return false;
|
||||
} else {
|
||||
if(!pvTimeStamp.attach(master)) return false;
|
||||
}
|
||||
pvTimeStamp.set(timeStamp);
|
||||
bitSet->set(pvCopy->getFieldOffset());
|
||||
return true;
|
||||
}
|
||||
if(copy) {
|
||||
if(toCopy) {
|
||||
if(!pvTimeStamp.attach(master)) return false;
|
||||
pvTimeStamp.get(timeStamp);
|
||||
if(!pvTimeStamp.attach(pvCopy)) return false;
|
||||
pvTimeStamp.set(timeStamp);
|
||||
bitSet->set(pvCopy->getFieldOffset());
|
||||
} else {
|
||||
if(!pvTimeStamp.attach(pvCopy)) return false;
|
||||
pvTimeStamp.get(timeStamp);
|
||||
if(!pvTimeStamp.attach(master)) return false;
|
||||
pvTimeStamp.set(timeStamp);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
string PVTimestampFilter::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -10,54 +10,54 @@
|
||||
*/
|
||||
|
||||
#include <epicsGuard.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/pvPlugin.h"
|
||||
#include "pv/pvArrayPlugin.h"
|
||||
#include "pv/pvTimestampPlugin.h"
|
||||
#include "pv/pvDeadbandPlugin.h"
|
||||
#include "pv/dataDistributorPlugin.h"
|
||||
|
||||
#include <pv/pvDatabase.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvCopy;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
|
||||
static PVDatabasePtr pvDatabaseMaster;
|
||||
|
||||
PVDatabasePtr PVDatabase::getMaster()
|
||||
{
|
||||
static bool firstTime = true;
|
||||
if(firstTime) {
|
||||
firstTime = false;
|
||||
pvDatabaseMaster = PVDatabasePtr(new PVDatabase());
|
||||
PVArrayPlugin::create();
|
||||
PVTimestampPlugin::create();
|
||||
PVDeadbandPlugin::create();
|
||||
DataDistributorPlugin::create();
|
||||
static PVDatabasePtr master;
|
||||
static Mutex mutex;
|
||||
Lock xx(mutex);
|
||||
if(master.get()==NULL) {
|
||||
master = PVDatabasePtr(new PVDatabase());
|
||||
}
|
||||
return pvDatabaseMaster;
|
||||
return master;
|
||||
}
|
||||
|
||||
PVDatabase::PVDatabase()
|
||||
: isDestroyed(false)
|
||||
{
|
||||
if(DEBUG_LEVEL>0) cout << "PVDatabase::PVDatabase()\n";
|
||||
}
|
||||
|
||||
PVDatabase::~PVDatabase()
|
||||
{
|
||||
if(DEBUG_LEVEL>0) cout << "PVDatabase::~PVDatabase()\n";
|
||||
destroy();
|
||||
}
|
||||
|
||||
void PVDatabase::destroy()
|
||||
{
|
||||
{
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
if(isDestroyed) {
|
||||
return;
|
||||
}
|
||||
isDestroyed = true;
|
||||
}
|
||||
for(PVRecordMap::iterator iter = recordMap.begin(); iter != recordMap.end(); iter++) {
|
||||
PVRecordPtr pvRecord = (*iter).second;
|
||||
if(pvRecord) {
|
||||
pvRecord->destroy();
|
||||
}
|
||||
}
|
||||
recordMap.clear();
|
||||
}
|
||||
|
||||
void PVDatabase::lock() {
|
||||
@@ -71,19 +71,23 @@ void PVDatabase::unlock() {
|
||||
PVRecordPtr PVDatabase::findRecord(string const& recordName)
|
||||
{
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
PVRecordPtr xxx;
|
||||
if(isDestroyed) {
|
||||
return xxx;
|
||||
}
|
||||
PVRecordMap::iterator iter = recordMap.find(recordName);
|
||||
if(iter!=recordMap.end()) {
|
||||
return (*iter).second;
|
||||
}
|
||||
return PVRecordPtr();
|
||||
return xxx;
|
||||
}
|
||||
|
||||
bool PVDatabase::addRecord(PVRecordPtr const & record)
|
||||
{
|
||||
if(record->getTraceLevel()>0) {
|
||||
cout << "PVDatabase::addRecord " << record->getRecordName() << endl;
|
||||
}
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
if(isDestroyed) {
|
||||
return false;
|
||||
}
|
||||
string recordName = record->getRecordName();
|
||||
PVRecordMap::iterator iter = recordMap.find(recordName);
|
||||
if(iter!=recordMap.end()) {
|
||||
@@ -94,28 +98,18 @@ bool PVDatabase::addRecord(PVRecordPtr const & record)
|
||||
return true;
|
||||
}
|
||||
|
||||
PVRecordWPtr PVDatabase::removeFromMap(PVRecordPtr const & record)
|
||||
bool PVDatabase::removeRecord(PVRecordPtr const & record)
|
||||
{
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
if(isDestroyed) {
|
||||
return false;
|
||||
}
|
||||
string recordName = record->getRecordName();
|
||||
PVRecordMap::iterator iter = recordMap.find(recordName);
|
||||
if(iter!=recordMap.end()) {
|
||||
PVRecordPtr pvRecord = (*iter).second;
|
||||
recordMap.erase(iter);
|
||||
return pvRecord->shared_from_this();
|
||||
}
|
||||
return PVRecordWPtr();
|
||||
}
|
||||
|
||||
bool PVDatabase::removeRecord(PVRecordPtr const & record)
|
||||
{
|
||||
if(record->getTraceLevel()>0) {
|
||||
cout << "PVDatabase::removeRecord " << record->getRecordName() << endl;
|
||||
}
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
PVRecordWPtr pvRecord = removeFromMap(record);
|
||||
if(pvRecord.use_count()!=0) {
|
||||
pvRecord.lock()->unlistenClients();
|
||||
if(pvRecord) pvRecord->destroy();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -125,6 +119,9 @@ PVStringArrayPtr PVDatabase::getRecordNames()
|
||||
{
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
PVStringArrayPtr xxx;
|
||||
if(isDestroyed) {
|
||||
return xxx;
|
||||
}
|
||||
PVStringArrayPtr pvStringArray = static_pointer_cast<PVStringArray>
|
||||
(getPVDataCreate()->createPVScalarArray(pvString));
|
||||
size_t len = recordMap.size();
|
||||
|
||||
@@ -8,40 +8,25 @@
|
||||
* @author mrk
|
||||
* @date 2012.11.21
|
||||
*/
|
||||
#include <list>
|
||||
#include <epicsGuard.h>
|
||||
#include <epicsThread.h>
|
||||
#include <pv/status.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/createRequest.h>
|
||||
#include <pv/pvaVersion.h>
|
||||
#include <pv/pvaVersionNum.h>
|
||||
#include <pv/monitor.h>
|
||||
#include <pv/convert.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
|
||||
#include <pv/pvDatabase.h>
|
||||
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvDatabase;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
PVRecordPtr PVRecord::create(
|
||||
string const &recordName,
|
||||
PVStructurePtr const & pvStructure,
|
||||
int asLevel,
|
||||
const std::string& asGroup)
|
||||
PVStructurePtr const & pvStructure)
|
||||
{
|
||||
PVRecordPtr pvRecord(new PVRecord(recordName,pvStructure,asLevel,asGroup));
|
||||
PVRecordPtr pvRecord(new PVRecord(recordName,pvStructure));
|
||||
if(!pvRecord->init()) {
|
||||
pvRecord.reset();
|
||||
}
|
||||
@@ -51,16 +36,13 @@ PVRecordPtr PVRecord::create(
|
||||
|
||||
PVRecord::PVRecord(
|
||||
string const & recordName,
|
||||
PVStructurePtr const & pvStructure,
|
||||
int asLevel_,
|
||||
const std::string& asGroup_)
|
||||
PVStructurePtr const & pvStructure)
|
||||
: recordName(recordName),
|
||||
pvStructure(pvStructure),
|
||||
depthGroupPut(0),
|
||||
traceLevel(0),
|
||||
isAddListener(false),
|
||||
asLevel(asLevel_),
|
||||
asGroup(asGroup_)
|
||||
isDestroyed(false),
|
||||
isAddListener(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -69,48 +51,7 @@ PVRecord::~PVRecord()
|
||||
if(traceLevel>0) {
|
||||
cout << "~PVRecord() " << recordName << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void PVRecord::unlistenClients()
|
||||
{
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
for(std::list<PVListenerWPtr>::iterator iter = pvListenerList.begin();
|
||||
iter!=pvListenerList.end();
|
||||
iter++ )
|
||||
{
|
||||
PVListenerPtr listener = iter->lock();
|
||||
if(!listener) continue;
|
||||
if(traceLevel>0) {
|
||||
cout << "PVRecord::remove() calling listener->unlisten " << recordName << endl;
|
||||
}
|
||||
listener->unlisten(shared_from_this());
|
||||
}
|
||||
pvListenerList.clear();
|
||||
for (std::list<PVRecordClientWPtr>::iterator iter = clientList.begin();
|
||||
iter!=clientList.end();
|
||||
iter++ )
|
||||
{
|
||||
PVRecordClientPtr client = iter->lock();
|
||||
if(!client) continue;
|
||||
if(traceLevel>0) {
|
||||
cout << "PVRecord::remove() calling client->detach " << recordName << endl;
|
||||
}
|
||||
client->detach(shared_from_this());
|
||||
}
|
||||
clientList.clear();
|
||||
}
|
||||
|
||||
|
||||
void PVRecord::remove()
|
||||
{
|
||||
if(traceLevel>0) {
|
||||
cout << "PVRecord::remove() " << recordName << endl;
|
||||
}
|
||||
unlistenClients();
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
PVDatabasePtr pvDatabase(PVDatabase::getMaster());
|
||||
if(pvDatabase) pvDatabase->removeFromMap(shared_from_this());
|
||||
pvTimeStamp.detach();
|
||||
destroy();
|
||||
}
|
||||
|
||||
void PVRecord::initPVRecord()
|
||||
@@ -123,13 +64,55 @@ void PVRecord::initPVRecord()
|
||||
if(pvField) pvTimeStamp.attach(pvField);
|
||||
}
|
||||
|
||||
void PVRecord::destroy()
|
||||
{
|
||||
{
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
if(traceLevel>0) {
|
||||
cout << "PVRecord::destroy() " << recordName
|
||||
<< " isDestroyed " << (isDestroyed ? "true" : "false")
|
||||
<< endl;
|
||||
}
|
||||
if(isDestroyed) {
|
||||
return;
|
||||
}
|
||||
isDestroyed = true;
|
||||
}
|
||||
PVDatabasePtr pvDatabase(PVDatabase::getMaster());
|
||||
if(pvDatabase) pvDatabase->removeRecord(shared_from_this());
|
||||
pvTimeStamp.detach();
|
||||
for(std::list<PVListenerWPtr>::iterator iter = pvListenerList.begin();
|
||||
iter!=pvListenerList.end();
|
||||
iter++ )
|
||||
{
|
||||
PVListenerPtr listener = iter->lock();
|
||||
if(!listener) continue;
|
||||
if(traceLevel>0) {
|
||||
cout << "PVRecord::destroy() calling listener->unlisten " << recordName << endl;
|
||||
}
|
||||
listener->unlisten(shared_from_this());
|
||||
}
|
||||
pvListenerList.clear();
|
||||
for (std::list<PVRecordClientPtr>::iterator iter = clientList.begin();
|
||||
iter!=clientList.end();
|
||||
iter++ )
|
||||
{
|
||||
PVRecordClientPtr client = *iter;
|
||||
if(!client) continue;
|
||||
if(traceLevel>0) {
|
||||
cout << "PVRecord::destroy() calling client->detach " << recordName << endl;
|
||||
}
|
||||
client->detach(shared_from_this());
|
||||
}
|
||||
clientList.clear();
|
||||
}
|
||||
|
||||
void PVRecord::process()
|
||||
{
|
||||
if(traceLevel>2) {
|
||||
cout << "PVRecord::process() " << recordName << endl;
|
||||
}
|
||||
if(pvTimeStamp.isAttached()) {
|
||||
pvTimeStamp.get(timeStamp);
|
||||
timeStamp.getCurrent();
|
||||
pvTimeStamp.set(timeStamp);
|
||||
}
|
||||
@@ -208,39 +191,70 @@ bool PVRecord::addPVRecordClient(PVRecordClientPtr const & pvRecordClient)
|
||||
cout << "PVRecord::addPVRecordClient() " << recordName << endl;
|
||||
}
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
// clean clientList
|
||||
bool clientListClean = false;
|
||||
while(!clientListClean) {
|
||||
if(clientList.empty()) break;
|
||||
clientListClean = true;
|
||||
std::list<PVRecordClientWPtr>::iterator iter;
|
||||
for (iter = clientList.begin();
|
||||
iter!=clientList.end();
|
||||
iter++ )
|
||||
{
|
||||
PVRecordClientPtr client = iter->lock();
|
||||
if(client) continue;
|
||||
if(traceLevel>1) {
|
||||
cout << "PVRecord::addPVRecordClient() erasing client"
|
||||
<< recordName << endl;
|
||||
}
|
||||
clientList.erase(iter);
|
||||
clientListClean = false;
|
||||
break;
|
||||
if(isDestroyed) {
|
||||
return false;
|
||||
}
|
||||
std::list<PVRecordClientPtr>::iterator iter;
|
||||
for (iter = clientList.begin();
|
||||
iter!=clientList.end();
|
||||
iter++ )
|
||||
{
|
||||
PVRecordClientPtr client = *iter;
|
||||
if(client==pvRecordClient) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(traceLevel>1) {
|
||||
cout << "PVRecord::addPVRecordClient() calling clientList.push_back(pvRecordClient)" << recordName << endl;
|
||||
}
|
||||
clientList.push_back(pvRecordClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PVRecord::removePVRecordClient(PVRecordClientPtr const & pvRecordClient)
|
||||
{
|
||||
if(traceLevel>1) {
|
||||
cout << "PVRecord::removePVRecordClient() " << recordName << endl;
|
||||
}
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
if(isDestroyed) {
|
||||
return false;
|
||||
}
|
||||
std::list<PVRecordClientPtr>::iterator iter;
|
||||
for (iter = clientList.begin();
|
||||
iter!=clientList.end();
|
||||
iter++ )
|
||||
{
|
||||
PVRecordClientPtr client = *iter;
|
||||
if(!client) continue;
|
||||
if(client==pvRecordClient) {
|
||||
clientList.erase(iter);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PVRecord::addListener(
|
||||
PVListenerPtr const & pvListener,
|
||||
epics::pvCopy::PVCopyPtr const & pvCopy)
|
||||
PVCopyPtr const & pvCopy)
|
||||
{
|
||||
if(traceLevel>1) {
|
||||
cout << "PVRecord::addListener() " << recordName << endl;
|
||||
}
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
if(isDestroyed) {
|
||||
return false;
|
||||
}
|
||||
std::list<PVListenerWPtr>::iterator iter;
|
||||
for (iter = pvListenerList.begin(); iter!=pvListenerList.end(); iter++ )
|
||||
{
|
||||
PVListenerPtr listener = iter->lock();
|
||||
if(!listener.get()) continue;
|
||||
if(listener.get()==pvListener.get()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
pvListenerList.push_back(pvListener);
|
||||
this->pvListener = pvListener;
|
||||
isAddListener = true;
|
||||
@@ -254,7 +268,7 @@ void PVRecord::nextMasterPVField(PVFieldPtr const & pvField)
|
||||
PVRecordFieldPtr pvRecordField = findPVRecordField(pvField);
|
||||
PVListenerPtr listener = pvListener.lock();
|
||||
if(!listener.get()) return;
|
||||
if(isAddListener) {
|
||||
if(isAddListener) {
|
||||
pvRecordField->addListener(listener);
|
||||
} else {
|
||||
pvRecordField->removeListener(listener);
|
||||
@@ -263,12 +277,15 @@ void PVRecord::nextMasterPVField(PVFieldPtr const & pvField)
|
||||
|
||||
bool PVRecord::removeListener(
|
||||
PVListenerPtr const & pvListener,
|
||||
epics::pvCopy::PVCopyPtr const & pvCopy)
|
||||
PVCopyPtr const & pvCopy)
|
||||
{
|
||||
if(traceLevel>1) {
|
||||
cout << "PVRecord::removeListener() " << recordName << endl;
|
||||
}
|
||||
epicsGuard<epics::pvData::Mutex> guard(mutex);
|
||||
if(isDestroyed) {
|
||||
return false;
|
||||
}
|
||||
std::list<PVListenerWPtr>::iterator iter;
|
||||
for (iter = pvListenerList.begin(); iter!=pvListenerList.end(); iter++ )
|
||||
{
|
||||
@@ -332,7 +349,6 @@ PVRecordField::PVRecordField(
|
||||
PVRecordPtr const & pvRecord)
|
||||
: pvField(pvField),
|
||||
isStructure(pvField->getField()->getType()==structure ? true : false),
|
||||
master(),
|
||||
parent(parent),
|
||||
pvRecord(pvRecord)
|
||||
{
|
||||
@@ -378,13 +394,21 @@ bool PVRecordField::addListener(PVListenerPtr const & pvListener)
|
||||
if(pvRecord && pvRecord->getTraceLevel()>1) {
|
||||
cout << "PVRecordField::addListener() " << getFullName() << endl;
|
||||
}
|
||||
std::list<PVListenerWPtr>::iterator iter;
|
||||
for (iter = pvListenerList.begin(); iter!=pvListenerList.end(); iter++ ) {
|
||||
PVListenerPtr listener = iter->lock();
|
||||
if(!listener.get()) continue;
|
||||
if(listener.get()==pvListener.get()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
pvListenerList.push_back(pvListener);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PVRecordField::removeListener(PVListenerPtr const & pvListener)
|
||||
{
|
||||
PVRecordPtr pvRecord(this->pvRecord.lock());
|
||||
PVRecordPtr pvRecord(this->pvRecord.lock());
|
||||
if(pvRecord && pvRecord->getTraceLevel()>1) {
|
||||
cout << "PVRecordField::removeListener() " << getFullName() << endl;
|
||||
}
|
||||
@@ -419,22 +443,14 @@ void PVRecordField::postParent(PVRecordFieldPtr const & subField)
|
||||
listener->dataPut(pvrs,subField);
|
||||
}
|
||||
PVRecordStructurePtr parent(this->parent.lock());
|
||||
if(parent) {
|
||||
parent->postParent(subField);
|
||||
}
|
||||
if(parent) parent->postParent(subField);
|
||||
}
|
||||
|
||||
void PVRecordField::postSubField()
|
||||
{
|
||||
// Master field pointer will be set in only one subfield
|
||||
PVRecordStructurePtr master(this->master.lock());
|
||||
if(master) {
|
||||
master->callListener();
|
||||
}
|
||||
callListener();
|
||||
if(isStructure) {
|
||||
PVRecordStructurePtr pvrs =
|
||||
static_pointer_cast<PVRecordStructure>(shared_from_this());
|
||||
PVRecordStructurePtr pvrs = static_pointer_cast<PVRecordStructure>(shared_from_this());
|
||||
PVRecordFieldPtrArrayPtr pvRecordFields = pvrs->getPVRecordFields();
|
||||
PVRecordFieldPtrArray::iterator iter;
|
||||
for(iter = pvRecordFields->begin() ; iter !=pvRecordFields->end(); iter++) {
|
||||
@@ -473,12 +489,7 @@ void PVRecordStructure::init()
|
||||
PVRecordStructurePtr self =
|
||||
static_pointer_cast<PVRecordStructure>(shared_from_this());
|
||||
PVRecordPtr pvRecord = getPVRecord();
|
||||
static bool masterFieldCallbackSet = false;
|
||||
bool isMasterField = (!getFullFieldName().size());
|
||||
if (isMasterField) {
|
||||
masterFieldCallbackSet = false;
|
||||
}
|
||||
for(size_t i=0; i<numFields; i++) {
|
||||
for(size_t i=0; i<numFields; i++) {
|
||||
PVFieldPtr pvField = pvFields[i];
|
||||
if(pvField->getField()->getType()==structure) {
|
||||
PVStructurePtr xxx = static_pointer_cast<PVStructure>(pvField);
|
||||
@@ -491,17 +502,6 @@ void PVRecordStructure::init()
|
||||
new PVRecordField(pvField,self,pvRecord));
|
||||
pvRecordFields->push_back(pvRecordField);
|
||||
pvRecordField->init();
|
||||
// Master field listeners will be called before
|
||||
// calling listeners for the first subfield
|
||||
if (!masterFieldCallbackSet) {
|
||||
masterFieldCallbackSet = true;
|
||||
// Find master field
|
||||
PVRecordStructurePtr p = pvRecordField->parent.lock();
|
||||
while (p) {
|
||||
pvRecordField->master = p;
|
||||
p = p->parent.lock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
#ifndef CHANNELPROVIDERLOCAL_H
|
||||
#define CHANNELPROVIDERLOCAL_H
|
||||
|
||||
#ifdef epicsExportSharedSymbols
|
||||
# define channelProviderLocalEpicsExportSharedSymbols
|
||||
# undef epicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
@@ -20,29 +25,79 @@
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvType.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvCopy.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/status.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
#include <pv/pvDatabase.h>
|
||||
|
||||
#ifdef channelProviderLocalEpicsExportSharedSymbols
|
||||
# define epicsExportSharedSymbols
|
||||
# undef channelProviderLocalEpicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <shareLib.h>
|
||||
#include <asLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
#include <pv/pvDatabase.h>
|
||||
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
|
||||
class MonitorFactory;
|
||||
typedef std::tr1::shared_ptr<MonitorFactory> MonitorFactoryPtr;
|
||||
|
||||
class MonitorLocal;
|
||||
typedef std::tr1::shared_ptr<MonitorLocal> MonitorLocalPtr;
|
||||
|
||||
|
||||
class ChannelProviderLocal;
|
||||
typedef std::tr1::shared_ptr<ChannelProviderLocal> ChannelProviderLocalPtr;
|
||||
typedef std::tr1::weak_ptr<ChannelProviderLocal> ChannelProviderLocalWPtr;
|
||||
class ChannelLocal;
|
||||
typedef std::tr1::shared_ptr<ChannelLocal> ChannelLocalPtr;
|
||||
typedef std::tr1::weak_ptr<ChannelLocal> ChannelLocalWPtr;
|
||||
|
||||
epicsShareFunc MonitorFactoryPtr getMonitorFactory();
|
||||
|
||||
/**
|
||||
* @brief MonitorFactory
|
||||
*
|
||||
* This class provides a static method to create a monitor for a PVRecord
|
||||
*/
|
||||
class epicsShareClass MonitorFactory
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(MonitorFactory);
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~MonitorFactory();
|
||||
/**
|
||||
* @brief Destroy the monitor factory.
|
||||
*/
|
||||
virtual void destroy();
|
||||
/**
|
||||
* @brief Create a monitor on a record.
|
||||
*
|
||||
* This is called by the local channel provider.
|
||||
* @param pvRecord The record to monitor.
|
||||
* @param monitorRequester The client callback.
|
||||
* @param pvRequest Options specified by the client.
|
||||
* This includes the subset of the fields in the record to monitor.
|
||||
* @return A shared pointer to the newly created monitor.
|
||||
* If the monitor can not be created a null monitor is returned.
|
||||
* This means the pvRequest specified options that could not be satisfied.
|
||||
*/
|
||||
epics::pvData::MonitorPtr createMonitor(
|
||||
PVRecordPtr const & pvRecord,
|
||||
epics::pvData::MonitorRequester::shared_pointer const & monitorRequester,
|
||||
epics::pvData::PVStructurePtr const & pvRequest);
|
||||
private:
|
||||
MonitorFactory();
|
||||
friend class MonitorLocal;
|
||||
friend epicsShareFunc MonitorFactoryPtr getMonitorFactory();
|
||||
bool isDestroyed;
|
||||
epics::pvData::Mutex mutex;
|
||||
};
|
||||
|
||||
epicsShareFunc epics::pvData::MonitorPtr createMonitorLocal(
|
||||
PVRecordPtr const & pvRecord,
|
||||
epics::pvData::MonitorRequester::shared_pointer const & monitorRequester,
|
||||
epics::pvData::PVStructurePtr const & pvRequest);
|
||||
|
||||
epicsShareFunc ChannelProviderLocalPtr getChannelProviderLocal();
|
||||
|
||||
@@ -54,41 +109,27 @@ epicsShareFunc ChannelProviderLocalPtr getChannelProviderLocal();
|
||||
*/
|
||||
class epicsShareClass ChannelProviderLocal :
|
||||
public epics::pvAccess::ChannelProvider,
|
||||
public epics::pvAccess::ChannelFind,
|
||||
public std::tr1::enable_shared_from_this<ChannelProviderLocal>
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(ChannelProviderLocal);
|
||||
/**
|
||||
* @brief Initialize access security configuration
|
||||
* @param filePath AS definition file path
|
||||
* @param substitutions macro substitutions
|
||||
* @throws std::runtime_error in case of configuration problem
|
||||
*/
|
||||
static void initAs(const std::string& filePath, const std::string& substitutions="");
|
||||
/**
|
||||
* @brief Is access security active?
|
||||
* @return true is AS is active
|
||||
*/
|
||||
static bool isAsActive();
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
ChannelProviderLocal();
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~ChannelProviderLocal();
|
||||
/**
|
||||
* @brief Returns the channel provider name.
|
||||
* @brief Destroy the channel provider.
|
||||
*
|
||||
* Probably never called.
|
||||
*/
|
||||
virtual void destroy();
|
||||
/**
|
||||
* @brief Returns the channel provider name.
|
||||
* @return <b>local</b>
|
||||
*/
|
||||
virtual std::string getProviderName();
|
||||
/**
|
||||
* @brief Returns either a null channelFind or a channelFind for records in the PVDatabase.
|
||||
*
|
||||
* @param channelName The name of the channel desired.
|
||||
* @param channelFindRequester The client callback.
|
||||
* @return shared pointer to ChannelFind.
|
||||
@@ -102,7 +143,7 @@ public:
|
||||
virtual epics::pvAccess::ChannelFind::shared_pointer channelFind(
|
||||
std::string const &channelName,
|
||||
epics::pvAccess::ChannelFindRequester::shared_pointer const & channelFindRequester);
|
||||
/**
|
||||
/**
|
||||
* @brief Calls method channelListRequester::channelListResult.
|
||||
*
|
||||
* This provides the caller with a list of the record names on the PVDatabase.
|
||||
@@ -110,7 +151,7 @@ public:
|
||||
* @param channelListRequester The client callback.
|
||||
* @return shared pointer to ChannelFind.
|
||||
* The interface for SyncChannelFind is defined by pvAccessCPP.
|
||||
*/
|
||||
*/
|
||||
virtual epics::pvAccess::ChannelFind::shared_pointer channelList(
|
||||
epics::pvAccess::ChannelListRequester::shared_pointer const & channelListRequester);
|
||||
/**
|
||||
@@ -144,35 +185,20 @@ public:
|
||||
epics::pvAccess::ChannelRequester::shared_pointer const &channelRequester,
|
||||
short priority,
|
||||
std::string const &address);
|
||||
/**
|
||||
* @brief get trace level (0,1,2) means (nothing,lifetime,process)
|
||||
* @return the level
|
||||
*/
|
||||
int getTraceLevel() {return traceLevel;}
|
||||
/**
|
||||
* @brief set trace level (0,1,2) means (nothing,lifetime,process)
|
||||
* @param level The level
|
||||
*/
|
||||
void setTraceLevel(int level) {traceLevel = level;}
|
||||
/**
|
||||
* @brief ChannelFind method.
|
||||
*
|
||||
* @return pointer to self.
|
||||
*/
|
||||
virtual std::tr1::shared_ptr<ChannelProvider> getChannelProvider();
|
||||
/**
|
||||
* @brief ChannelFind method.
|
||||
*
|
||||
*/
|
||||
virtual void cancel() {}
|
||||
private:
|
||||
shared_pointer getPtrSelf()
|
||||
{
|
||||
return shared_from_this();
|
||||
}
|
||||
ChannelProviderLocal();
|
||||
friend epicsShareFunc ChannelProviderLocalPtr getChannelProviderLocal();
|
||||
PVDatabaseWPtr pvDatabase;
|
||||
int traceLevel;
|
||||
PVDatabasePtr pvDatabase;
|
||||
epics::pvData::Mutex mutex;
|
||||
bool beingDestroyed;
|
||||
epics::pvAccess::ChannelFind::shared_pointer channelFinder;
|
||||
friend class ChannelProviderLocalRun;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Channel for accessing a PVRecord.
|
||||
*
|
||||
@@ -196,23 +222,33 @@ public:
|
||||
epics::pvAccess::ChannelRequester::shared_pointer const & requester,
|
||||
PVRecordPtr const & pvRecord
|
||||
);
|
||||
/**
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~ChannelLocal();
|
||||
/**
|
||||
/**
|
||||
* @brief Destroy the channel.
|
||||
*
|
||||
* It cleans up all resources used to access the record.
|
||||
* Note that this assumes that client has destroyed any objects that
|
||||
* have been created for the channel like channelGet, etc.
|
||||
* The remote pvAccess server does this cleanup.
|
||||
*/
|
||||
virtual void destroy();
|
||||
/**
|
||||
* @brief Detach from the record.
|
||||
*
|
||||
* This is called when a record is being removed from the database.
|
||||
* @param pvRecord The record being removed.
|
||||
* Calls destroy.
|
||||
* @param pvRecord The record being destroyed.
|
||||
*/
|
||||
virtual void detach(PVRecordPtr const &pvRecord);
|
||||
/**
|
||||
/**
|
||||
* @brief Get the requester name.
|
||||
* @return returns the name of the channel requester.
|
||||
*/
|
||||
virtual std::string getRequesterName();
|
||||
/**
|
||||
/**
|
||||
* @brief Passes the message to the channel requester.
|
||||
* @param message The message.
|
||||
* @param messageType The message type.
|
||||
@@ -220,37 +256,40 @@ public:
|
||||
virtual void message(
|
||||
std::string const & message,
|
||||
epics::pvData::MessageType messageType);
|
||||
/**
|
||||
/**
|
||||
* @brief Get the channel provider
|
||||
* @return The provider.
|
||||
*/
|
||||
virtual epics::pvAccess::ChannelProvider::shared_pointer getProvider();
|
||||
/**
|
||||
virtual epics::pvAccess::ChannelProvider::shared_pointer getProvider()
|
||||
{
|
||||
return provider;
|
||||
}
|
||||
/**
|
||||
* @brief Get the remote address
|
||||
* @return <b>local</b>
|
||||
*/
|
||||
virtual std::string getRemoteAddress();
|
||||
/**
|
||||
/**
|
||||
* Get the connection state.
|
||||
* @return Channel::CONNECTED.
|
||||
*/
|
||||
virtual epics::pvAccess::Channel::ConnectionState getConnectionState();
|
||||
/**
|
||||
/**
|
||||
* @brief Get the channel name.
|
||||
* @return the record name.
|
||||
*/
|
||||
virtual std::string getChannelName();
|
||||
/**
|
||||
/**
|
||||
* @brief Get the channel requester
|
||||
* @return The channel requester.
|
||||
*/
|
||||
virtual epics::pvAccess::ChannelRequester::shared_pointer getChannelRequester();
|
||||
/**
|
||||
/**
|
||||
* @brief Is the channel connected?
|
||||
* @return true.
|
||||
*/
|
||||
virtual bool isConnected();
|
||||
/**
|
||||
/**
|
||||
* @brief Get the introspection interface for subField.
|
||||
*
|
||||
* The introspection interface is given via GetFieldRequester::getDone.
|
||||
@@ -262,14 +301,14 @@ public:
|
||||
virtual void getField(
|
||||
epics::pvAccess::GetFieldRequester::shared_pointer const &requester,
|
||||
std::string const & subField);
|
||||
/**
|
||||
/**
|
||||
* Get the access rights for the record.
|
||||
* This throws an exception because it is assumed that access rights are
|
||||
* handled by a higher level.
|
||||
*/
|
||||
virtual epics::pvAccess::AccessRights getAccessRights(
|
||||
epics::pvData::PVField::shared_pointer const &pvField);
|
||||
/**
|
||||
/**
|
||||
* @brief Create a channelProcess.
|
||||
*
|
||||
* @param requester The client callback.
|
||||
@@ -280,9 +319,9 @@ public:
|
||||
virtual epics::pvAccess::ChannelProcess::shared_pointer createChannelProcess(
|
||||
epics::pvAccess::ChannelProcessRequester::shared_pointer const &requester,
|
||||
epics::pvData::PVStructurePtr const &pvRequest);
|
||||
/**
|
||||
/**
|
||||
* @brief Create a channelGet.
|
||||
*
|
||||
*
|
||||
* @param requester The client callback.
|
||||
* @param pvRequest The options specified by the client.
|
||||
* @return A shared pointer to the newly created implementation.
|
||||
@@ -291,7 +330,7 @@ public:
|
||||
virtual epics::pvAccess::ChannelGet::shared_pointer createChannelGet(
|
||||
epics::pvAccess::ChannelGetRequester::shared_pointer const &requester,
|
||||
epics::pvData::PVStructurePtr const &pvRequest);
|
||||
/**
|
||||
/**
|
||||
* @brief Create a channelPut.
|
||||
*
|
||||
* @param requester The client callback.
|
||||
@@ -302,9 +341,9 @@ public:
|
||||
virtual epics::pvAccess::ChannelPut::shared_pointer createChannelPut(
|
||||
epics::pvAccess::ChannelPutRequester::shared_pointer const &requester,
|
||||
epics::pvData::PVStructurePtr const &pvRequest);
|
||||
/**
|
||||
/**
|
||||
* @brief Create a channelPutGet.
|
||||
*
|
||||
*
|
||||
* @param requester The client callback.
|
||||
* @param pvRequest The options specified by the client.
|
||||
* @return A shared pointer to the newly created implementation.
|
||||
@@ -313,7 +352,7 @@ public:
|
||||
virtual epics::pvAccess::ChannelPutGet::shared_pointer createChannelPutGet(
|
||||
epics::pvAccess::ChannelPutGetRequester::shared_pointer const &requester,
|
||||
epics::pvData::PVStructurePtr const &pvRequest);
|
||||
/**
|
||||
/**
|
||||
* @brief Create a channelRPC.
|
||||
*
|
||||
* The PVRecord must implement <b>getService</b> or an empty shared pointer is returned.
|
||||
@@ -324,9 +363,9 @@ public:
|
||||
virtual epics::pvAccess::ChannelRPC::shared_pointer createChannelRPC(
|
||||
epics::pvAccess::ChannelRPCRequester::shared_pointer const &requester,
|
||||
epics::pvData::PVStructurePtr const &pvRequest);
|
||||
/**
|
||||
/**
|
||||
* @brief Create a monitor.
|
||||
*
|
||||
*
|
||||
* @param requester The client callback.
|
||||
* @param pvRequest The options specified by the client.
|
||||
* @return A shared pointer to the newly created implementation.
|
||||
@@ -335,9 +374,9 @@ public:
|
||||
virtual epics::pvData::Monitor::shared_pointer createMonitor(
|
||||
epics::pvData::MonitorRequester::shared_pointer const &requester,
|
||||
epics::pvData::PVStructurePtr const &pvRequest);
|
||||
/**
|
||||
/**
|
||||
* @brief Create a channelArray.
|
||||
*
|
||||
*
|
||||
* @param requester The client callback.
|
||||
* @param pvRequest The options specified by the client.
|
||||
* @return A shared pointer to the newly created implementation.
|
||||
@@ -346,28 +385,16 @@ public:
|
||||
virtual epics::pvAccess::ChannelArray::shared_pointer createChannelArray(
|
||||
epics::pvAccess::ChannelArrayRequester::shared_pointer const &requester,
|
||||
epics::pvData::PVStructurePtr const &pvRequest);
|
||||
/**
|
||||
/**
|
||||
* @brief calls printInfo(std::cout);
|
||||
*/
|
||||
virtual void printInfo();
|
||||
/**
|
||||
/**
|
||||
* @brief displays a message
|
||||
*
|
||||
*
|
||||
* @param out the stream on which the message is displayed.
|
||||
*/
|
||||
virtual void printInfo(std::ostream& out);
|
||||
/**
|
||||
* @brief determines if client can write
|
||||
*
|
||||
* @return true if client can write
|
||||
*/
|
||||
virtual bool canWrite();
|
||||
/**
|
||||
* @brief determines if client can read
|
||||
*
|
||||
* @return true if client can read
|
||||
*/
|
||||
virtual bool canRead();
|
||||
protected:
|
||||
shared_pointer getPtrSelf()
|
||||
{
|
||||
@@ -375,22 +402,10 @@ protected:
|
||||
}
|
||||
private:
|
||||
epics::pvAccess::ChannelRequester::shared_pointer requester;
|
||||
ChannelProviderLocalWPtr provider;
|
||||
PVRecordWPtr pvRecord;
|
||||
ChannelProviderLocalPtr provider;
|
||||
PVRecordPtr pvRecord;
|
||||
bool isDestroyed;
|
||||
epics::pvData::Mutex mutex;
|
||||
|
||||
// AS-specific variables/methods
|
||||
std::vector<char> toCharArray(const std::string& s);
|
||||
std::vector<char> getAsGroup(const PVRecordPtr& pvRecord);
|
||||
std::vector<char> getAsUser(const epics::pvAccess::ChannelRequester::shared_pointer& requester);
|
||||
std::vector<char> getAsHost(const epics::pvAccess::ChannelRequester::shared_pointer& requester);
|
||||
|
||||
int asLevel;
|
||||
std::vector<char> asGroup;
|
||||
std::vector<char> asUser;
|
||||
std::vector<char> asHost;
|
||||
ASMEMBERPVT asMemberPvt;
|
||||
ASCLIENTPVT asClientPvt;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2019.06.01
|
||||
*/
|
||||
#ifndef CONTROLSUPPORT_H
|
||||
#define CONTROLSUPPORT_H
|
||||
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/pvSupport.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class ControlSupport;
|
||||
typedef std::tr1::shared_ptr<ControlSupport> ControlSupportPtr;
|
||||
|
||||
/**
|
||||
* @brief Base interface for a ControlSupport.
|
||||
*
|
||||
*/
|
||||
class epicsShareClass ControlSupport :
|
||||
PVSupport
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(ControlSupport);
|
||||
/**
|
||||
* The Destructor.
|
||||
*/
|
||||
virtual ~ControlSupport();
|
||||
/**
|
||||
* @brief Connects to contol fields.
|
||||
*
|
||||
* @param pvValue The field to support.
|
||||
* @param pvSupport Support specific fields.
|
||||
* @return <b>true</b> for success and <b>false</b> for failure.
|
||||
*/
|
||||
virtual bool init(
|
||||
epics::pvData::PVFieldPtr const & pvValue,
|
||||
epics::pvData::PVFieldPtr const & pvSupport);
|
||||
/**
|
||||
* @brief Honors control fields.
|
||||
*
|
||||
*
|
||||
* @return Returns true is any fields were modified; otherwise false.
|
||||
*/
|
||||
virtual bool process();
|
||||
/**
|
||||
* @brief If implementing minSteps it sets isMinStep to false.
|
||||
*
|
||||
* @return Returns true is any fields were modified; otherwise false.
|
||||
*/
|
||||
virtual void reset();
|
||||
/**
|
||||
* @brief create a ControlSupport
|
||||
*
|
||||
* @param pvRecord - The pvRecord to which the support is attached.
|
||||
* @return The new ControlSupport
|
||||
*/
|
||||
static ControlSupportPtr create(PVRecordPtr const & pvRecord);
|
||||
/**
|
||||
* @brief create a controlSupport required by ControlSupport
|
||||
*
|
||||
* @param scalarType The type for outputValue.
|
||||
* @return The controlField introspection structure.
|
||||
*/
|
||||
static epics::pvData::StructureConstPtr controlField(epics::pvData::ScalarType scalarType);
|
||||
private:
|
||||
ControlSupport(PVRecordPtr const & pvRecord);
|
||||
PVRecordPtr pvRecord;
|
||||
epics::pvData::PVScalarPtr pvValue;
|
||||
epics::pvData::PVStructurePtr pvControl;
|
||||
epics::pvData::PVDoublePtr pvLimitLow;
|
||||
epics::pvData::PVDoublePtr pvLimitHigh;
|
||||
epics::pvData::PVDoublePtr pvMinStep;
|
||||
epics::pvData::PVScalarPtr pvOutputValue;
|
||||
double currentValue;
|
||||
bool isMinStep;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* CONTROLSUPPORT_H */
|
||||
@@ -1,167 +0,0 @@
|
||||
// Copyright information and license terms for this software can be
|
||||
// found in the file LICENSE that is included with the distribution
|
||||
|
||||
#ifndef DATA_DISTRIBUTOR_PLUGIN_H
|
||||
#define DATA_DISTRIBUTOR_PLUGIN_H
|
||||
|
||||
// The data distributor plugin enables distribution of channel data between
|
||||
// multiple client applications.
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvPlugin.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvCopy {
|
||||
|
||||
class DataDistributorPlugin;
|
||||
class DataDistributorFilter;
|
||||
class DataDistributor;
|
||||
|
||||
typedef std::tr1::shared_ptr<DataDistributorPlugin> DataDistributorPluginPtr;
|
||||
typedef std::tr1::shared_ptr<DataDistributorFilter> DataDistributorFilterPtr;
|
||||
typedef std::tr1::shared_ptr<DataDistributor> DataDistributorPtr;
|
||||
|
||||
struct ClientSet;
|
||||
typedef std::tr1::shared_ptr<ClientSet> ClientSetPtr;
|
||||
typedef std::tr1::shared_ptr<const ClientSet> ClientSetConstPtr;
|
||||
|
||||
struct ClientSet
|
||||
{
|
||||
POINTER_DEFINITIONS(ClientSet);
|
||||
|
||||
ClientSet(const std::string& setId_, const std::string triggerField_, int nUpdatesPerClient_, int updateMode_)
|
||||
: setId(setId_)
|
||||
, triggerField(triggerField_)
|
||||
, nUpdatesPerClient(nUpdatesPerClient_)
|
||||
, updateMode(updateMode_)
|
||||
, clientIdList()
|
||||
, lastUpdateValue()
|
||||
, updateCounter(0)
|
||||
, currentClientIdIter(clientIdList.end())
|
||||
{}
|
||||
~ClientSet() {}
|
||||
std::string setId;
|
||||
std::string triggerField;
|
||||
int nUpdatesPerClient;
|
||||
int updateMode;
|
||||
std::list<int> clientIdList;
|
||||
std::string lastUpdateValue;
|
||||
int updateCounter;
|
||||
std::list<int>::iterator currentClientIdIter;
|
||||
};
|
||||
|
||||
class DataDistributor
|
||||
{
|
||||
public:
|
||||
enum ClientUpdateMode {
|
||||
DD_UPDATE_ONE_PER_GROUP = 0, // Update goes to one client per set
|
||||
DD_UPDATE_ALL_IN_GROUP = 1, // Update goes to all clients in set
|
||||
DD_N_UPDATE_MODES = 2 // Number of valid update modes
|
||||
};
|
||||
|
||||
static DataDistributorPtr getInstance(const std::string& groupId);
|
||||
static void removeUnusedInstance(DataDistributorPtr dataDistributorPtr);
|
||||
|
||||
virtual ~DataDistributor();
|
||||
std::string getGroupId() const { return groupId; }
|
||||
std::string addClient(int clientId, const std::string& setId, const std::string& triggerField, int nUpdatesPerClient, int updateMode);
|
||||
void removeClient(int clientId, const std::string& setId);
|
||||
bool updateClient(int clientId, const std::string& setId, const std::string& triggerFieldValue);
|
||||
|
||||
private:
|
||||
DataDistributor(const std::string& id);
|
||||
DataDistributor(const DataDistributor& distributor);
|
||||
DataDistributor& operator=(const DataDistributor& distributor);
|
||||
|
||||
static std::map<std::string, DataDistributorPtr> dataDistributorMap;
|
||||
static epics::pvData::Mutex dataDistributorMapMutex;
|
||||
|
||||
std::string groupId;
|
||||
epics::pvData::Mutex mutex;
|
||||
std::map<std::string, ClientSetPtr> clientSetMap;
|
||||
std::list<std::string> clientSetIdList;
|
||||
std::list<std::string>::iterator currentSetIdIter;
|
||||
std::string lastUpdateValue;
|
||||
};
|
||||
|
||||
class epicsShareClass DataDistributorPlugin : public PVPlugin
|
||||
{
|
||||
private:
|
||||
DataDistributorPlugin();
|
||||
public:
|
||||
POINTER_DEFINITIONS(DataDistributorPlugin);
|
||||
virtual ~DataDistributorPlugin();
|
||||
/**
|
||||
* Factory
|
||||
*/
|
||||
static void create();
|
||||
/**
|
||||
* Create a PVFilter.
|
||||
* @param requestValue The value part of a name=value request option.
|
||||
* @param pvCopy The PVCopy to which the PVFilter will be attached.
|
||||
* @param master The field in the master PVStructure to which the PVFilter will be attached
|
||||
* @return The PVFilter.
|
||||
* Null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
virtual PVFilterPtr create(
|
||||
const std::string& requestValue,
|
||||
const PVCopyPtr& pvCopy,
|
||||
const epics::pvData::PVFieldPtr& master);
|
||||
private:
|
||||
static bool initialize();
|
||||
static bool initialized;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A Plugin for a filter that gets a sub array from a PVScalarDeadband.
|
||||
*/
|
||||
class epicsShareClass DataDistributorFilter : public PVFilter
|
||||
{
|
||||
private:
|
||||
DataDistributorPtr dataDistributorPtr;
|
||||
int clientId;
|
||||
std::string setId;
|
||||
std::string triggerField;
|
||||
epics::pvData::PVFieldPtr masterFieldPtr;
|
||||
epics::pvData::PVFieldPtr triggerFieldPtr;
|
||||
bool firstUpdate;
|
||||
|
||||
DataDistributorFilter(const std::string& groupId, int clientId, const std::string& setId, const std::string& triggerField, int nUpdatesPerClient, int updateMode, const epics::pvCopy::PVCopyPtr& copyPtr, const epics::pvData::PVFieldPtr& masterFieldPtr);
|
||||
|
||||
public:
|
||||
POINTER_DEFINITIONS(DataDistributorFilter);
|
||||
virtual ~DataDistributorFilter();
|
||||
/**
|
||||
* Create a DataDistributorFilter.
|
||||
* @param requestValue The value part of a name=value request option.
|
||||
* @param master The field in the master PVStructure to which the PVFilter will be attached.
|
||||
* @return The PVFilter.
|
||||
* A null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
static DataDistributorFilterPtr create(
|
||||
const std::string& requestValue,
|
||||
const PVCopyPtr& pvCopy,
|
||||
const epics::pvData::PVFieldPtr & master);
|
||||
/**
|
||||
* Perform a filter operation
|
||||
* @param pvCopy The field in the copy PVStructure.
|
||||
* @param bitSet A bitSet for copyPVStructure.
|
||||
* @param toCopy (true,false) means copy (from master to copy,from copy to master)
|
||||
* @return if filter (modified, did not modify) destination.
|
||||
* Null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
bool filter(const epics::pvData::PVFieldPtr & pvCopy,const epics::pvData::BitSetPtr & bitSet,bool toCopy);
|
||||
/**
|
||||
* Get the filter name.
|
||||
* @return The name.
|
||||
*/
|
||||
std::string getName();
|
||||
};
|
||||
|
||||
}}
|
||||
#endif
|
||||
@@ -1,101 +0,0 @@
|
||||
/* pvArrayPlugin.h */
|
||||
/*
|
||||
* The License for this software can be found in the file LICENSE that is included with the distribution.
|
||||
*/
|
||||
|
||||
#ifndef PVARRAYPLUGIN_H
|
||||
#define PVARRAYPLUGIN_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvPlugin.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvCopy{
|
||||
|
||||
class PVArrayPlugin;
|
||||
class PVArrayFilter;
|
||||
|
||||
typedef std::tr1::shared_ptr<PVArrayPlugin> PVArrayPluginPtr;
|
||||
typedef std::tr1::shared_ptr<PVArrayFilter> PVArrayFilterPtr;
|
||||
|
||||
|
||||
/**
|
||||
* @brief A plugin for a filter that gets a sub array from a PVScalarArray.
|
||||
*
|
||||
* @author mrk
|
||||
* @since date 2017.02.23
|
||||
*/
|
||||
class epicsShareClass PVArrayPlugin : public PVPlugin
|
||||
{
|
||||
private:
|
||||
PVArrayPlugin();
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVArrayPlugin);
|
||||
virtual ~PVArrayPlugin();
|
||||
/**
|
||||
* Factory
|
||||
*/
|
||||
static void create();
|
||||
/**
|
||||
* Create a PVFilter.
|
||||
* @param requestValue The value part of a name=value request option.
|
||||
* @param pvCopy The PVCopy to which the PVFilter will be attached.
|
||||
* @param master The field in the master PVStructure to which the PVFilter will be attached
|
||||
* @return The PVFilter.
|
||||
* Null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
virtual PVFilterPtr create(
|
||||
const std::string & requestValue,
|
||||
const PVCopyPtr & pvCopy,
|
||||
const epics::pvData::PVFieldPtr & master);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A filter that gets a sub array from a PVScalarArray.
|
||||
*/
|
||||
class epicsShareClass PVArrayFilter : public PVFilter
|
||||
{
|
||||
private:
|
||||
long start;
|
||||
long increment;
|
||||
long end;
|
||||
epics::pvData::PVFieldPtr masterField;
|
||||
epics::pvData::PVScalarArrayPtr masterArray;
|
||||
|
||||
PVArrayFilter(
|
||||
long start,long increment,long end,
|
||||
const epics::pvData::PVFieldPtr & masterField,
|
||||
const epics::pvData::PVScalarArrayPtr masterArray);
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVArrayFilter);
|
||||
virtual ~PVArrayFilter();
|
||||
/**
|
||||
* Create a PVArrayFilter.
|
||||
* @param requestValue The value part of a name=value request option.
|
||||
* @param master The field in the master PVStructure to which the PVFilter will be attached.
|
||||
* @return The PVFilter.
|
||||
* A null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
static PVArrayFilterPtr create(const std::string & requestValue,const epics::pvData::PVFieldPtr & master);
|
||||
/**
|
||||
* Perform a filter operation
|
||||
* @param pvCopy The field in the copy PVStructure.
|
||||
* @param bitSet A bitSet for copyPVStructure.
|
||||
* @param toCopy (true,false) means copy (from master to copy,from copy to master)
|
||||
* @return if filter (modified, did not modify) destination.
|
||||
* Null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
bool filter(const epics::pvData::PVFieldPtr & pvCopy,const epics::pvData::BitSetPtr & bitSet,bool toCopy);
|
||||
/**
|
||||
* Get the filter name.
|
||||
* @return The name.
|
||||
*/
|
||||
std::string getName();
|
||||
};
|
||||
|
||||
}}
|
||||
#endif /* PVARRAYPLUGIN_H */
|
||||
@@ -6,17 +6,29 @@
|
||||
#ifndef PVDATABASE_H
|
||||
#define PVDATABASE_H
|
||||
|
||||
#ifdef epicsExportSharedSymbols
|
||||
# define pvdatabaseEpicsExportSharedSymbols
|
||||
# undef epicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvCopy.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
|
||||
#ifdef pvdatabaseEpicsExportSharedSymbols
|
||||
# define epicsExportSharedSymbols
|
||||
# undef pvdatabaseEpicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class PVRecord;
|
||||
typedef std::tr1::shared_ptr<PVRecord> PVRecordPtr;
|
||||
@@ -34,7 +46,6 @@ typedef std::tr1::weak_ptr<PVRecordStructure> PVRecordStructureWPtr;
|
||||
|
||||
class PVRecordClient;
|
||||
typedef std::tr1::shared_ptr<PVRecordClient> PVRecordClientPtr;
|
||||
typedef std::tr1::weak_ptr<PVRecordClient> PVRecordClientWPtr;
|
||||
|
||||
class PVListener;
|
||||
typedef std::tr1::shared_ptr<PVListener> PVListenerPtr;
|
||||
@@ -42,7 +53,6 @@ typedef std::tr1::weak_ptr<PVListener> PVListenerWPtr;
|
||||
|
||||
class PVDatabase;
|
||||
typedef std::tr1::shared_ptr<PVDatabase> PVDatabasePtr;
|
||||
typedef std::tr1::weak_ptr<PVDatabase> PVDatabaseWPtr;
|
||||
|
||||
/**
|
||||
* @brief Base interface for a PVRecord.
|
||||
@@ -54,12 +64,11 @@ typedef std::tr1::weak_ptr<PVDatabase> PVDatabaseWPtr;
|
||||
* @date 2012.11.20
|
||||
*/
|
||||
class epicsShareClass PVRecord :
|
||||
public epics::pvCopy::PVCopyTraverseMasterCallback,
|
||||
public epics::pvData::PVCopyTraverseMasterCallback,
|
||||
public std::tr1::enable_shared_from_this<PVRecord>
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVRecord);
|
||||
|
||||
/**
|
||||
* The Destructor.
|
||||
*/
|
||||
@@ -88,39 +97,36 @@ public:
|
||||
*/
|
||||
virtual void process();
|
||||
/**
|
||||
* @brief remove record from database.
|
||||
* @brief Optional method for derived class.
|
||||
*
|
||||
* Remove the PVRecord. Release any resources used and
|
||||
* Destroy the PVRecord. Release any resources used and
|
||||
* get rid of listeners and requesters.
|
||||
* If derived class overrides this then it must call PVRecord::remove()
|
||||
* If derived class overrides this then it must call PVRecord::destroy()
|
||||
* after it has destroyed any resorces it uses.
|
||||
*/
|
||||
virtual void remove();
|
||||
virtual void destroy();
|
||||
/**
|
||||
* @brief Optional method for derived class.
|
||||
*
|
||||
* Return a service corresponding to the specified request PVStructure.
|
||||
* @param pvRequest The request PVStructure
|
||||
* @param pvRequest The request PVStructure
|
||||
* @return The corresponding service
|
||||
*/
|
||||
virtual epics::pvAccess::RPCServiceAsync::shared_pointer getService(
|
||||
virtual epics::pvAccess::Service::shared_pointer getService(
|
||||
epics::pvData::PVStructurePtr const & pvRequest)
|
||||
{
|
||||
return epics::pvAccess::RPCServiceAsync::shared_pointer();
|
||||
return epics::pvAccess::Service::shared_pointer();
|
||||
}
|
||||
/**
|
||||
* @brief Creates a <b>soft</b> record.
|
||||
* @brief Creates a <b>soft</b> record.
|
||||
*
|
||||
* @param recordName The name of the record, which is also the channelName.
|
||||
* @param pvStructure The top level structure.
|
||||
* @param asLevel AS level (default: ASL0)
|
||||
* @param asGroup AS group (default: DEFAULT)
|
||||
* @return A shared pointer to the newly created record.
|
||||
*/
|
||||
static PVRecordPtr create(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel = 0, const std::string& asGroup = "DEFAULT");
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
/**
|
||||
* @brief Get the name of the record.
|
||||
*
|
||||
@@ -189,6 +195,13 @@ public:
|
||||
* @return <b>true</b> if the client is added.
|
||||
*/
|
||||
bool addPVRecordClient(PVRecordClientPtr const & pvRecordClient);
|
||||
/**
|
||||
* @brief Remove a client.
|
||||
*
|
||||
* @param pvRecordClient The client.
|
||||
* @return <b>true</b> if the client is removed.
|
||||
*/
|
||||
bool removePVRecordClient(PVRecordClientPtr const & pvRecordClient);
|
||||
/**
|
||||
* @brief Add a PVListener.
|
||||
*
|
||||
@@ -199,7 +212,7 @@ public:
|
||||
*/
|
||||
bool addListener(
|
||||
PVListenerPtr const & pvListener,
|
||||
epics::pvCopy::PVCopyPtr const & pvCopy);
|
||||
epics::pvData::PVCopyPtr const & pvCopy);
|
||||
/**
|
||||
* @brief PVCopyTraverseMasterCallback method
|
||||
*
|
||||
@@ -215,7 +228,7 @@ public:
|
||||
*/
|
||||
bool removeListener(
|
||||
PVListenerPtr const & pvListener,
|
||||
epics::pvCopy::PVCopyPtr const & pvCopy);
|
||||
epics::pvData::PVCopyPtr const & pvCopy);
|
||||
|
||||
|
||||
/**
|
||||
@@ -236,50 +249,30 @@ public:
|
||||
* @param level The level
|
||||
*/
|
||||
void setTraceLevel(int level) {traceLevel = level;}
|
||||
/**
|
||||
* @brief Get the ASlevel
|
||||
*
|
||||
* @return The level.
|
||||
*/
|
||||
int getAsLevel() const {return asLevel;}
|
||||
/**
|
||||
* @brief Get the AS group name
|
||||
*
|
||||
* @return The name.
|
||||
*/
|
||||
std::string getAsGroup() const {return asGroup;}
|
||||
/**
|
||||
* @brief set access security level.
|
||||
* @param level The level
|
||||
*/
|
||||
void setAsLevel(int level) {asLevel=level;}
|
||||
/**
|
||||
* @brief set access security group
|
||||
* @param group The group name
|
||||
*/
|
||||
void setAsGroup(const std::string& group) {asGroup = group;}
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param recordName The name of the record
|
||||
* @param pvStructure The top level PVStructutre
|
||||
* @param asLevel AS level (default: ASL0)
|
||||
* @param asGroup AS group (default: DEFAULT)
|
||||
*/
|
||||
PVRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel = 0, const std::string& asGroup = "DEFAULT");
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
/**
|
||||
* @brief Initializes the base class.
|
||||
*
|
||||
*
|
||||
* Must be called by derived classes.
|
||||
*/
|
||||
void initPVRecord();
|
||||
/**
|
||||
* @brief Get shared pointer to self.
|
||||
* @return The shared pointer.
|
||||
*/
|
||||
PVRecordPtr getPtrSelf()
|
||||
{
|
||||
return shared_from_this();
|
||||
}
|
||||
private:
|
||||
friend class PVDatabase;
|
||||
void unlistenClients();
|
||||
|
||||
PVRecordFieldPtr findPVRecordField(
|
||||
PVRecordStructurePtr const & pvrs,
|
||||
epics::pvData::PVFieldPtr const & pvField);
|
||||
@@ -288,19 +281,18 @@ private:
|
||||
epics::pvData::PVStructurePtr pvStructure;
|
||||
PVRecordStructurePtr pvRecordStructure;
|
||||
std::list<PVListenerWPtr> pvListenerList;
|
||||
std::list<PVRecordClientWPtr> clientList;
|
||||
std::list<PVRecordClientPtr> clientList;
|
||||
epics::pvData::Mutex mutex;
|
||||
std::size_t depthGroupPut;
|
||||
int traceLevel;
|
||||
// following only valid while addListener or removeListener is active.
|
||||
bool isAddListener;
|
||||
PVListenerWPtr pvListener;
|
||||
bool isDestroyed;
|
||||
|
||||
epics::pvData::PVTimeStamp pvTimeStamp;
|
||||
epics::pvData::TimeStamp timeStamp;
|
||||
|
||||
int asLevel;
|
||||
std::string asGroup;
|
||||
// following only valid while addListener or removeListener is active.
|
||||
bool isAddListener;
|
||||
PVListenerWPtr pvListener;
|
||||
};
|
||||
|
||||
epicsShareFunc std::ostream& operator<<(std::ostream& o, const PVRecord& record);
|
||||
@@ -376,7 +368,6 @@ private:
|
||||
std::list<PVListenerWPtr> pvListenerList;
|
||||
epics::pvData::PVField::weak_pointer pvField;
|
||||
bool isStructure;
|
||||
PVRecordStructureWPtr master;
|
||||
PVRecordStructureWPtr parent;
|
||||
PVRecordWPtr pvRecord;
|
||||
std::string fullName;
|
||||
@@ -513,6 +504,12 @@ public:
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~PVDatabase();
|
||||
/**
|
||||
* @brief Destroy the PVDatabase.
|
||||
*
|
||||
* For each record in the database the record is removed and it's destroy method is called.
|
||||
*/
|
||||
virtual void destroy();
|
||||
/**
|
||||
* Find a record.
|
||||
* An empty pointer is returned if the record is not in the database.
|
||||
@@ -530,7 +527,6 @@ public:
|
||||
/**
|
||||
* @brief Remove a record.
|
||||
* @param record The record to remove.
|
||||
*
|
||||
* @return <b>true</b> if record was removed.
|
||||
*/
|
||||
bool removeRecord(PVRecordPtr const & record);
|
||||
@@ -540,17 +536,15 @@ public:
|
||||
*/
|
||||
epics::pvData::PVStringArrayPtr getRecordNames();
|
||||
private:
|
||||
friend class PVRecord;
|
||||
|
||||
PVRecordWPtr removeFromMap(PVRecordPtr const & record);
|
||||
PVDatabase();
|
||||
void lock();
|
||||
void unlock();
|
||||
PVRecordMap recordMap;
|
||||
epics::pvData::Mutex mutex;
|
||||
static bool getMasterFirstCall;
|
||||
bool isDestroyed;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PVDATABASE_H */
|
||||
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
/* pvDeadbandPlugin.h */
|
||||
/*
|
||||
* The License for this software can be found in the file LICENSE that is included with the distribution.
|
||||
*/
|
||||
|
||||
#ifndef PVDEADBANDPLUGIN_H
|
||||
#define PVDEADBANDPLUGIN_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvPlugin.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvCopy{
|
||||
|
||||
class PVDeadbandPlugin;
|
||||
class PVDeadbandFilter;
|
||||
|
||||
typedef std::tr1::shared_ptr<PVDeadbandPlugin> PVDeadbandPluginPtr;
|
||||
typedef std::tr1::shared_ptr<PVDeadbandFilter> PVDeadbandFilterPtr;
|
||||
|
||||
|
||||
/**
|
||||
* @brief A plugin for a filter that gets a sub array from a PVScalarDeadband.
|
||||
*
|
||||
* @author mrk
|
||||
* @since date 2017.02.23
|
||||
*/
|
||||
class epicsShareClass PVDeadbandPlugin : public PVPlugin
|
||||
{
|
||||
private:
|
||||
PVDeadbandPlugin();
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVDeadbandPlugin);
|
||||
virtual ~PVDeadbandPlugin();
|
||||
/**
|
||||
* Factory
|
||||
*/
|
||||
static void create();
|
||||
/**
|
||||
* Create a PVFilter.
|
||||
* @param requestValue The value part of a name=value request option.
|
||||
* @param pvCopy The PVCopy to which the PVFilter will be attached.
|
||||
* @param master The field in the master PVStructure to which the PVFilter will be attached
|
||||
* @return The PVFilter.
|
||||
* Null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
virtual PVFilterPtr create(
|
||||
const std::string & requestValue,
|
||||
const PVCopyPtr & pvCopy,
|
||||
const epics::pvData::PVFieldPtr & master);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A Plugin for a filter that gets a sub array from a PVScalarDeadband.
|
||||
*/
|
||||
class epicsShareClass PVDeadbandFilter : public PVFilter
|
||||
{
|
||||
private:
|
||||
bool absolute;
|
||||
double deadband;
|
||||
epics::pvData::PVScalarPtr master;
|
||||
bool firstTime;
|
||||
double lastReportedValue;
|
||||
|
||||
|
||||
PVDeadbandFilter(bool absolute,double deadband,epics::pvData::PVScalarPtr const & master);
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVDeadbandFilter);
|
||||
virtual ~PVDeadbandFilter();
|
||||
/**
|
||||
* Create a PVDeadbandFilter.
|
||||
* @param requestValue The value part of a name=value request option.
|
||||
* @param master The field in the master PVStructure to which the PVFilter will be attached.
|
||||
* @return The PVFilter.
|
||||
* A null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
static PVDeadbandFilterPtr create(
|
||||
const std::string & requestValue,
|
||||
const epics::pvData::PVFieldPtr & master);
|
||||
/**
|
||||
* Perform a filter operation
|
||||
* @param pvCopy The field in the copy PVStructure.
|
||||
* @param bitSet A bitSet for copyPVStructure.
|
||||
* @param toCopy (true,false) means copy (from master to copy,from copy to master)
|
||||
* @return if filter (modified, did not modify) destination.
|
||||
* Null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
bool filter(const epics::pvData::PVFieldPtr & pvCopy,const epics::pvData::BitSetPtr & bitSet,bool toCopy);
|
||||
/**
|
||||
* Get the filter name.
|
||||
* @return The name.
|
||||
*/
|
||||
std::string getName();
|
||||
};
|
||||
|
||||
}}
|
||||
#endif /* PVDEADBANDPLUGIN_H */
|
||||
@@ -1,109 +0,0 @@
|
||||
/* pvPlugin.h */
|
||||
/*
|
||||
* The License for this software can be found in the file LICENSE that is included with the distribution.
|
||||
*/
|
||||
/**
|
||||
* @author Marty Kraimer
|
||||
* @date 2017.03
|
||||
*/
|
||||
#ifndef PVPLUGIN_H
|
||||
#define PVPLUGIN_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/bitSet.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvCopy{
|
||||
|
||||
class PVPlugin;
|
||||
class PVFilter;
|
||||
class PVPluginRegistry;
|
||||
|
||||
class PVCopy;
|
||||
typedef std::tr1::shared_ptr<PVCopy> PVCopyPtr;
|
||||
|
||||
typedef std::tr1::shared_ptr<PVPlugin> PVPluginPtr;
|
||||
typedef std::tr1::shared_ptr<PVFilter> PVFilterPtr;
|
||||
typedef std::map<std::string,PVPluginPtr> PVPluginMap;
|
||||
|
||||
|
||||
/**
|
||||
* @brief A filter plugin that attaches to a field of a PVStrcture.
|
||||
*
|
||||
* PVCopy looks for plugins defined in pvRequest and calls the filter when a pvCopy is updated.
|
||||
* @author mrk
|
||||
* @since 2017.03.17
|
||||
*
|
||||
* Interface for a filter plugin for PVCopy.
|
||||
*
|
||||
*/
|
||||
|
||||
class epicsShareClass PVPlugin {
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVPlugin);
|
||||
virtual ~PVPlugin() {}
|
||||
/**
|
||||
* Create a PVFilter.
|
||||
* @param requestValue The value part of a name=value request option.
|
||||
* @param pvCopy The PVCopy to which the PVFilter will be attached.
|
||||
* @param master The field in the master PVStructure to which the PVFilter will be attached.
|
||||
* @return The PVFilter.
|
||||
* A null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
virtual PVFilterPtr create(
|
||||
const std::string & requestValue,
|
||||
const PVCopyPtr & pvCopy,
|
||||
const epics::pvData::PVFieldPtr & master) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A Filter that is called when a copy PVStructure is being updated.
|
||||
*
|
||||
* This interface defines a filter to update a copy of a field from a master PVStructure.
|
||||
* of the data in the master.
|
||||
*/
|
||||
class epicsShareClass PVFilter {
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVFilter);
|
||||
virtual ~PVFilter() {}
|
||||
/**
|
||||
* Update copy or master.
|
||||
* @param copy The data for copy.
|
||||
* @param bitSet The BitSet for copy.
|
||||
* @param toCopy (true,false) means copy (from master to copy,from copy to master)
|
||||
* @return (true,false) if filter modified destination.
|
||||
*/
|
||||
virtual bool filter(const epics::pvData::PVFieldPtr & copy,const epics::pvData::BitSetPtr & bitSet,bool toCopy) = 0;
|
||||
/**
|
||||
* Get the filter name.
|
||||
* This is the name part of a request name=value pair.
|
||||
* @return The name.
|
||||
*/
|
||||
virtual std::string getName() = 0;
|
||||
};
|
||||
/**
|
||||
* @brief A registry for filter plugins for PVCopy.
|
||||
*
|
||||
*/
|
||||
class epicsShareClass PVPluginRegistry {
|
||||
public:
|
||||
/**
|
||||
* Register a plugin.
|
||||
* @param name The name that appears in [name=value] of a field request option.
|
||||
* @param pvPlugin The implementation for the plugin.
|
||||
*/
|
||||
static void registerPlugin(const std::string & name,const PVPluginPtr & pvPlugin);
|
||||
/**
|
||||
* Find a plugin.
|
||||
* @param name The name that appears in [name=value] of a field request option.
|
||||
* @return The plugin implementation or null if no pluging by that name has been registered.
|
||||
*/
|
||||
static PVPluginPtr find(const std::string & name);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PVPLUGIN_H */
|
||||
@@ -1,247 +0,0 @@
|
||||
/* pvStructureCopy.h */
|
||||
/*
|
||||
* Copyright information and license terms for this software can be
|
||||
* found in the file LICENSE that is included with the distribution
|
||||
*/
|
||||
/**
|
||||
* @author Marty Kraimer
|
||||
* @date 2013.04
|
||||
*/
|
||||
#ifndef PVSTRUCTURECOPY_H
|
||||
#define PVSTRUCTURECOPY_H
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/bitSet.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvCopy{
|
||||
|
||||
class PVCopyTraverseMasterCallback;
|
||||
typedef std::tr1::shared_ptr<PVCopyTraverseMasterCallback> PVCopyTraverseMasterCallbackPtr;
|
||||
|
||||
/**
|
||||
* @brief Callback for traversing master structure
|
||||
*
|
||||
* Must be implemented by code that creates pvCopy.
|
||||
*
|
||||
* This was originally name pvCopy.h and implemented in pvDataCPP
|
||||
* When it was moved to pvDatabaseCPP it was renamed to prevent conflicts with
|
||||
* the version in pvDataCPP.
|
||||
* Also the namespace was changed from epics::pvData to epics::pvCopy
|
||||
*/
|
||||
class epicsShareClass PVCopyTraverseMasterCallback
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVCopyTraverseMasterCallback);
|
||||
virtual ~PVCopyTraverseMasterCallback() {}
|
||||
/**
|
||||
* Called once for each field in master.
|
||||
* @param pvField The field in master.
|
||||
*/
|
||||
virtual void nextMasterPVField(epics::pvData::PVFieldPtr const &pvField) = 0;
|
||||
};
|
||||
|
||||
|
||||
class PVCopy;
|
||||
typedef std::tr1::shared_ptr<PVCopy> PVCopyPtr;
|
||||
|
||||
struct CopyNode;
|
||||
typedef std::tr1::shared_ptr<CopyNode> CopyNodePtr;
|
||||
|
||||
struct CopyStructureNode;
|
||||
typedef std::tr1::shared_ptr<CopyStructureNode> CopyStructureNodePtr;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Support for subset of fields in a pvStructure.
|
||||
*
|
||||
* Class that manages one or more PVStructures that holds an arbitrary subset of the fields
|
||||
* in another PVStructure called master.
|
||||
*/
|
||||
class epicsShareClass PVCopy :
|
||||
public std::tr1::enable_shared_from_this<PVCopy>
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVCopy);
|
||||
/**
|
||||
* Create a new pvCopy
|
||||
* @param pvMaster The top-level structure for which a copy of
|
||||
* an arbitrary subset of the fields in master will be created and managed.
|
||||
* @param pvRequest Selects the set of subfields desired and options for each field.
|
||||
* @param structureName The name for the top level of any PVStructure created.
|
||||
*/
|
||||
static PVCopyPtr create(
|
||||
epics::pvData::PVStructurePtr const &pvMaster,
|
||||
epics::pvData::PVStructurePtr const &pvRequest,
|
||||
std::string const & structureName);
|
||||
virtual ~PVCopy(){}
|
||||
/**
|
||||
* Get the top-level structure of master
|
||||
* @returns The master top-level structure.
|
||||
* This should not be modified.
|
||||
*/
|
||||
epics::pvData::PVStructurePtr getPVMaster();
|
||||
/**
|
||||
* Traverse all the fields in master.
|
||||
* @param callback This is called for each field on master.
|
||||
*/
|
||||
void traverseMaster(PVCopyTraverseMasterCallbackPtr const & callback);
|
||||
/**
|
||||
* Get the introspection interface for a PVStructure for e copy.
|
||||
*/
|
||||
epics::pvData::StructureConstPtr getStructure();
|
||||
/**
|
||||
* Create a copy instance. Monitors keep a queue of monitor elements.
|
||||
* Since each element needs a PVStructure, multiple top-level structures will be created.
|
||||
*/
|
||||
epics::pvData::PVStructurePtr createPVStructure();
|
||||
/**
|
||||
* Given a field in pvMaster. return the offset in copy for the same field.
|
||||
* A value of std::string::npos means that the copy does not have this field.
|
||||
* @param masterPVField The field in master.
|
||||
*/
|
||||
std::size_t getCopyOffset(epics::pvData::PVFieldPtr const &masterPVField);
|
||||
/**
|
||||
* Given a field in pvMaster. return the offset in copy for the same field.
|
||||
* A value of std::string::npos means that the copy does not have this field.
|
||||
* @param masterPVStructure A structure in master that has masterPVField.
|
||||
* @param masterPVField The field in master.
|
||||
*/
|
||||
std::size_t getCopyOffset(
|
||||
epics::pvData::PVStructurePtr const &masterPVStructure,
|
||||
epics::pvData::PVFieldPtr const &masterPVField);
|
||||
/**
|
||||
* Given an offset in the copy get the corresponding field in pvMaster.
|
||||
* @param structureOffset The offset in the copy.
|
||||
*/
|
||||
epics::pvData::PVFieldPtr getMasterPVField(std::size_t structureOffset);
|
||||
/**
|
||||
* Initialize the fields in copyPVStructure by giving each field
|
||||
* the value from the corresponding field in pvMaster.
|
||||
* bitSet will be set to show that all fields are changed.
|
||||
* @param copyPVStructure A copy top-level structure.
|
||||
* @param bitSet A bitSet for copyPVStructure.
|
||||
*/
|
||||
void initCopy(
|
||||
epics::pvData::PVStructurePtr const ©PVStructure,
|
||||
epics::pvData::BitSetPtr const &bitSet);
|
||||
/**
|
||||
* Set all fields in copyPVStructure to the value of the corresponding field in pvMaster.
|
||||
* Each field that is changed has it's corresponding bit set in bitSet.
|
||||
* @param copyPVStructure A copy top-level structure.
|
||||
* @param bitSet A bitSet for copyPVStructure.
|
||||
* @returns (false,true) if client (should not,should) receive changes.
|
||||
*/
|
||||
bool updateCopySetBitSet(
|
||||
epics::pvData::PVStructurePtr const ©PVStructure,
|
||||
epics::pvData::BitSetPtr const &bitSet);
|
||||
/**
|
||||
* For each set bit in bitSet
|
||||
* set the field in copyPVStructure to the value of the corresponding field in pvMaster.
|
||||
* @param copyPVStructure A copy top-level structure.
|
||||
* @param bitSet A bitSet for copyPVStructure.
|
||||
* @returns (false,true) if client (should not,should) receive changes.
|
||||
*/
|
||||
bool updateCopyFromBitSet(
|
||||
epics::pvData::PVStructurePtr const ©PVStructure,
|
||||
epics::pvData::BitSetPtr const &bitSet);
|
||||
/**
|
||||
* For each set bit in bitSet
|
||||
* set the field in pvMaster to the value of the corresponding field in copyPVStructure
|
||||
* @param copyPVStructure A copy top-level structure.
|
||||
* @param bitSet A bitSet for copyPVStructure.
|
||||
*/
|
||||
void updateMaster(
|
||||
epics::pvData::PVStructurePtr const ©PVStructure,
|
||||
epics::pvData::BitSetPtr const &bitSet);
|
||||
/**
|
||||
* Get the options for the field at the specified offset.
|
||||
* @param fieldOffset the offset in copy.
|
||||
* @returns A NULL is returned if no options were specified for the field.
|
||||
* If options were specified,PVStructurePtr is a structures
|
||||
* with a set of PVString subfields that specify name,value pairs.s
|
||||
* name is the subField name and value is the subField value.
|
||||
*/
|
||||
epics::pvData::PVStructurePtr getOptions(std::size_t fieldOffset);
|
||||
/**
|
||||
* For debugging.
|
||||
*/
|
||||
std::string dump();
|
||||
private:
|
||||
|
||||
PVCopyPtr getPtrSelf()
|
||||
{
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
epics::pvData::PVStructurePtr pvMaster;
|
||||
epics::pvData::StructureConstPtr structure;
|
||||
CopyNodePtr headNode;
|
||||
epics::pvData::PVStructurePtr cacheInitStructure;
|
||||
epics::pvData::BitSetPtr ignorechangeBitSet;
|
||||
|
||||
void traverseMaster(
|
||||
CopyNodePtr const &node,
|
||||
PVCopyTraverseMasterCallbackPtr const & callback);
|
||||
void updateCopySetBitSet(
|
||||
epics::pvData::PVFieldPtr const &pvCopy,
|
||||
epics::pvData::PVFieldPtr const &pvMaster,
|
||||
epics::pvData::BitSetPtr const &bitSet);
|
||||
void updateCopySetBitSet(
|
||||
epics::pvData::PVFieldPtr const &pvCopy,
|
||||
CopyNodePtr const &node,
|
||||
epics::pvData::BitSetPtr const &bitSet);
|
||||
void updateCopyFromBitSet(
|
||||
epics::pvData::PVFieldPtr const &pvCopy,
|
||||
CopyNodePtr const &node,
|
||||
epics::pvData::BitSetPtr const &bitSet);
|
||||
void updateMasterField(
|
||||
CopyNodePtr const & node,
|
||||
epics::pvData::PVFieldPtr const & pvCopy,
|
||||
epics::pvData::PVFieldPtr const &pvMaster,
|
||||
epics::pvData::BitSetPtr const &bitSet);
|
||||
void updateMasterCheckBitSet(
|
||||
epics::pvData::PVStructurePtr const ©PVStructure,
|
||||
epics::pvData::BitSetPtr const &bitSet,
|
||||
size_t nextSet);
|
||||
CopyNodePtr getCopyNode(std::size_t fieldOffset);
|
||||
|
||||
PVCopy(epics::pvData::PVStructurePtr const &pvMaster);
|
||||
bool init(epics::pvData::PVStructurePtr const &pvRequest);
|
||||
epics::pvData::StructureConstPtr createStructure(
|
||||
epics::pvData::PVStructurePtr const &pvMaster,
|
||||
epics::pvData::PVStructurePtr const &pvFromRequest);
|
||||
CopyNodePtr createStructureNodes(
|
||||
epics::pvData::PVStructurePtr const &pvMasterStructure,
|
||||
epics::pvData::PVStructurePtr const &pvFromRequest,
|
||||
epics::pvData::PVStructurePtr const &pvFromField);
|
||||
void initPlugin(
|
||||
CopyNodePtr const & node,
|
||||
epics::pvData::PVStructurePtr const & pvOptions,
|
||||
epics::pvData::PVFieldPtr const & pvMasterField);
|
||||
void traverseMasterInitPlugin();
|
||||
void traverseMasterInitPlugin(CopyNodePtr const & node);
|
||||
|
||||
CopyNodePtr getCopyOffset(
|
||||
CopyStructureNodePtr const &structureNode,
|
||||
epics::pvData::PVFieldPtr const &masterPVField);
|
||||
bool checkIgnore(
|
||||
epics::pvData::PVStructurePtr const & copyPVStructure,
|
||||
epics::pvData::BitSetPtr const & bitSet);
|
||||
void setIgnore(CopyNodePtr const & node);
|
||||
CopyNodePtr getMasterNode(
|
||||
CopyStructureNodePtr const &structureNode,
|
||||
std::size_t structureOffset);
|
||||
void dump(
|
||||
std::string *builder,
|
||||
CopyNodePtr const &node,
|
||||
int indentLevel);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PVSTRUCTURECOPY_H */
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2019.06.01
|
||||
*/
|
||||
#ifndef PVSUPPORT_H
|
||||
#define PVSUPPORT_H
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class PVSupport;
|
||||
typedef std::tr1::shared_ptr<PVSupport> PVSupportPtr;
|
||||
|
||||
/**
|
||||
* @brief Base interface for a PVSupport.
|
||||
*
|
||||
*/
|
||||
class epicsShareClass PVSupport
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVSupport);
|
||||
/**
|
||||
* The Destructor.
|
||||
*/
|
||||
virtual ~PVSupport(){}
|
||||
/**
|
||||
* @brief Optional initialization method.
|
||||
*
|
||||
* Called after PVRecord is created but before record is installed into PVDatabase.
|
||||
*
|
||||
* @param pvValue The field to support.
|
||||
* @param pvSupport Support specific fields.
|
||||
* @return <b>true</b> for success and <b>false</b> for failure.
|
||||
*/
|
||||
virtual bool init(
|
||||
epics::pvData::PVFieldPtr const & pvValue,
|
||||
epics::pvData::PVFieldPtr const & pvSupport) {return true;}
|
||||
/**
|
||||
* @brief Optional method for derived class.
|
||||
*
|
||||
* It is called before record is added to database.
|
||||
*/
|
||||
virtual void start() {}
|
||||
/**
|
||||
* @brief Virtual method for derived class.
|
||||
*
|
||||
* Called when record is processed.
|
||||
* It is the method that implements support.
|
||||
* It is called each time the record is processed.
|
||||
*
|
||||
* @return Returns true is any fields were modified; otherwise false.
|
||||
*/
|
||||
virtual bool process() = 0;
|
||||
/**
|
||||
* @brief Optional method for derived class.
|
||||
*
|
||||
*/
|
||||
virtual void reset() {};
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PVSUPPORT_H */
|
||||
@@ -1,100 +0,0 @@
|
||||
/* pvTimeStampPlugin.h */
|
||||
/*
|
||||
* The License for this software can be found in the file LICENSE that is included with the distribution.
|
||||
*/
|
||||
|
||||
#ifndef PVTIMESTAMPPLUGIN_H
|
||||
#define PVTIMESTAMPPLUGIN_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvPlugin.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvCopy{
|
||||
|
||||
class PVTimestampPlugin;
|
||||
class PVTimestampFilter;
|
||||
|
||||
typedef std::tr1::shared_ptr<PVTimestampPlugin> PVTimestampPluginPtr;
|
||||
typedef std::tr1::shared_ptr<PVTimestampFilter> PVTimestampFilterPtr;
|
||||
|
||||
|
||||
/**
|
||||
* @brief A plugin for a filter that sets a timeStamp to the current time.
|
||||
*
|
||||
* @author mrk
|
||||
* @since date 2017.03.24
|
||||
*/
|
||||
class epicsShareClass PVTimestampPlugin : public PVPlugin
|
||||
{
|
||||
private:
|
||||
PVTimestampPlugin();
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVTimestampPlugin);
|
||||
virtual ~PVTimestampPlugin();
|
||||
/**
|
||||
* Factory
|
||||
*/
|
||||
static void create();
|
||||
/**
|
||||
* Create a PVFilter.
|
||||
* @param requestValue The value part of a name=value request option.
|
||||
* @param pvCopy The PVCopy to which the PVFilter will be attached.
|
||||
* @param master The field in the master PVStructure to which the PVFilter will be attached
|
||||
* @return The PVFilter.
|
||||
* Null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
virtual PVFilterPtr create(
|
||||
const std::string & requestValue,
|
||||
const PVCopyPtr & pvCopy,
|
||||
const epics::pvData::PVFieldPtr & master);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A filter that sets a timeStamp to/from the current field or pvCopy.
|
||||
*/
|
||||
class epicsShareClass PVTimestampFilter : public PVFilter
|
||||
{
|
||||
private:
|
||||
epics::pvData::PVTimeStamp pvTimeStamp;
|
||||
epics::pvData::TimeStamp timeStamp;
|
||||
bool current;
|
||||
bool copy;
|
||||
epics::pvData::PVFieldPtr master;
|
||||
|
||||
|
||||
PVTimestampFilter(bool current,bool copy,epics::pvData::PVFieldPtr const & pvField);
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVTimestampFilter);
|
||||
virtual ~PVTimestampFilter();
|
||||
/**
|
||||
* Create a PVTimestampFilter.
|
||||
* @param requestValue The value part of a name=value request option.
|
||||
* @param master The field in the master PVStructure to which the PVFilter will be attached.
|
||||
* @return The PVFilter.
|
||||
* A null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
static PVTimestampFilterPtr create(const std::string & requestValue,const epics::pvData::PVFieldPtr & master);
|
||||
/**
|
||||
* Perform a filter operation
|
||||
* @param pvCopy The field in the copy PVStructure.
|
||||
* @param bitSet A bitSet for copyPVStructure.
|
||||
* @param toCopy (true,false) means copy (from master to copy,from copy to master)
|
||||
* @return if filter (modified, did not modify) destination.
|
||||
* Null is returned if master or requestValue is not appropriate for the plugin.
|
||||
*/
|
||||
bool filter(const epics::pvData::PVFieldPtr & pvCopy,const epics::pvData::BitSetPtr & bitSet,bool toCopy);
|
||||
/**
|
||||
* Get the filter name.
|
||||
* @return The name.
|
||||
*/
|
||||
std::string getName();
|
||||
};
|
||||
|
||||
}}
|
||||
#endif /* PVTIMESTAMPPLUGIN_H */
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* 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.04.11
|
||||
*/
|
||||
#ifndef PVDBCRADDARRAY_H
|
||||
#define PVDBCRADDARRAY_H
|
||||
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/pvSupport.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class PvdbcrAddRecord;
|
||||
typedef std::tr1::shared_ptr<PvdbcrAddRecord> PvdbcrAddRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief PvdbcrAddRecord A record that adds a record to the master database.
|
||||
*
|
||||
*/
|
||||
class epicsShareClass PvdbcrAddRecord :
|
||||
public PVRecord
|
||||
{
|
||||
private:
|
||||
PvdbcrAddRecord(
|
||||
std::string const & recordName,epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel,std::string const & asGroup);
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
public:
|
||||
POINTER_DEFINITIONS(PvdbcrAddRecord);
|
||||
/**
|
||||
* The Destructor.
|
||||
*/
|
||||
virtual ~PvdbcrAddRecord() {}
|
||||
/**
|
||||
* @brief Create a record.
|
||||
*
|
||||
* @param recordName The record name.
|
||||
* @param asLevel The access security level.
|
||||
* @param asGroup The access security group.
|
||||
* @return The PVRecord
|
||||
*/
|
||||
static PvdbcrAddRecordPtr create(
|
||||
std::string const & recordName,
|
||||
int asLevel=0,std::string const & asGroup = std::string("DEFAULT"));
|
||||
/**
|
||||
* @brief a PVRecord method
|
||||
* @return success or failure
|
||||
*/
|
||||
virtual bool init();
|
||||
/**
|
||||
* @brief process method that adds a record to the master database.
|
||||
*/
|
||||
virtual void process();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PVDBCRADDARRAY_H */
|
||||
@@ -1,105 +0,0 @@
|
||||
/**
|
||||
* 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.04.11
|
||||
*/
|
||||
#ifndef PVDBCRPROCESSARRAY_H
|
||||
#define PVDBCRPROCESSARRAY_H
|
||||
#include <epicsThread.h>
|
||||
#include <epicsGuard.h>
|
||||
#include <pv/event.h>
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/pvSupport.h>
|
||||
#include <pv/pvStructureCopy.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 PvdbcrProcessRecord A record that processes other records in the master database.
|
||||
*
|
||||
*/
|
||||
class epicsShareClass PvdbcrProcessRecord :
|
||||
public PVRecord,
|
||||
public epicsThreadRunable
|
||||
{
|
||||
private:
|
||||
PvdbcrProcessRecord(
|
||||
std::string const & recordName,epics::pvData::PVStructurePtr const & pvStructure,
|
||||
double delay,
|
||||
int asLevel,std::string const & asGroup);
|
||||
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;
|
||||
public:
|
||||
POINTER_DEFINITIONS(PvdbcrProcessRecord);
|
||||
/**
|
||||
* The Destructor.
|
||||
*/
|
||||
virtual ~PvdbcrProcessRecord() {}
|
||||
/**
|
||||
* @brief Create a record.
|
||||
*
|
||||
* @param recordName The record name.
|
||||
* @param asLevel The access security level.
|
||||
* @param asGroup The access security group.
|
||||
* @return The PVRecord
|
||||
*/
|
||||
static PvdbcrProcessRecordPtr create(
|
||||
std::string const & recordName,
|
||||
double delay= 1.0,
|
||||
int asLevel=0,std::string const & asGroup = std::string("DEFAULT"));
|
||||
/**
|
||||
* @brief set the delay between prcocessing.
|
||||
*
|
||||
* @param delay in seconds
|
||||
*/
|
||||
void setDelay(double delay);
|
||||
/**
|
||||
* @brief get the delay between prcocessing.
|
||||
*
|
||||
* @return delay in seconds
|
||||
*/
|
||||
double getDelay();
|
||||
/**
|
||||
* @brief a PVRecord method
|
||||
* @return success or failure
|
||||
*/
|
||||
virtual bool init();
|
||||
/**
|
||||
* @brief method that processes other records in the master database.
|
||||
*/
|
||||
virtual void process();
|
||||
/**
|
||||
* @brief thread method
|
||||
*/
|
||||
virtual void run();
|
||||
/**
|
||||
* @brief thread method
|
||||
*/
|
||||
void startThread();
|
||||
/**
|
||||
* @brief thread method
|
||||
*/
|
||||
void stop();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PVDBCRPROCESSARRAY_H */
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* 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.04.11
|
||||
*/
|
||||
#ifndef PVDBCRREMOVEARRAY_H
|
||||
#define PVDBCRREMOVEARRAY_H
|
||||
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/pvSupport.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class PvdbcrRemoveRecord;
|
||||
typedef std::tr1::shared_ptr<PvdbcrRemoveRecord> PvdbcrRemoveRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief PvdbcrRemoveRecord A record that removes a record from the master database.
|
||||
*
|
||||
*/
|
||||
class epicsShareClass PvdbcrRemoveRecord :
|
||||
public PVRecord
|
||||
{
|
||||
private:
|
||||
PvdbcrRemoveRecord(
|
||||
std::string const & recordName,epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel,std::string const & asGroup);
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
public:
|
||||
POINTER_DEFINITIONS(PvdbcrRemoveRecord);
|
||||
/**
|
||||
* The Destructor.
|
||||
*/
|
||||
virtual ~PvdbcrRemoveRecord() {}
|
||||
/**
|
||||
* @brief Create a record.
|
||||
*
|
||||
* @param recordName The record name.
|
||||
* @param asLevel The access security level.
|
||||
* @param asGroup The access security group.
|
||||
* @return The PVRecord
|
||||
*/
|
||||
static PvdbcrRemoveRecordPtr create(
|
||||
std::string const & recordName,
|
||||
int asLevel=0,std::string const & asGroup = std::string("DEFAULT"));
|
||||
/**
|
||||
* @brief a PVRecord method
|
||||
* @return success or failure
|
||||
*/
|
||||
virtual bool init();
|
||||
/**
|
||||
* @brief process method that removes a record from the master database.
|
||||
*/
|
||||
virtual void process();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PVDBCRREMOVEARRAY_H */
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* 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.04.11
|
||||
*/
|
||||
#ifndef PVDBCRSCALARARRAYRECORD_H
|
||||
#define PVDBCRSCALARARRAYRECORD_H
|
||||
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/pvSupport.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class PvdbcrScalarArrayRecord;
|
||||
typedef std::tr1::shared_ptr<PvdbcrScalarArrayRecord> PvdbcrScalarArrayRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief PvdbcrScalarArrayRecord creates a record with a scalar array value, alarm, and timeStamp.
|
||||
*
|
||||
*/
|
||||
class epicsShareClass PvdbcrScalarArrayRecord :
|
||||
public PVRecord
|
||||
{
|
||||
private:
|
||||
PvdbcrScalarArrayRecord(
|
||||
std::string const & recordName,epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel,std::string const & asGroup);
|
||||
public:
|
||||
POINTER_DEFINITIONS(PvdbcrScalarArrayRecord);
|
||||
/**
|
||||
* The Destructor.
|
||||
*/
|
||||
virtual ~PvdbcrScalarArrayRecord() {}
|
||||
/**
|
||||
* @brief Create a record.
|
||||
*
|
||||
* @param recordName The record name.
|
||||
* @param scalarType The type for the value field
|
||||
* @param asLevel The access security level.
|
||||
* @param asGroup The access security group.
|
||||
* @return The PVRecord
|
||||
*/
|
||||
static PvdbcrScalarArrayRecordPtr create(
|
||||
std::string const & recordName,std::string const & scalarType,
|
||||
int asLevel=0,std::string const & asGroup = std::string("DEFAULT"));
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PVDBCRSCALARARRAYRECORD_H */
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* 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.04.11
|
||||
*/
|
||||
#ifndef PVDBCRSCALARRECORD_H
|
||||
#define PVDBCRSCALARRECORD_H
|
||||
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/pvSupport.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class PvdbcrScalarRecord;
|
||||
typedef std::tr1::shared_ptr<PvdbcrScalarRecord> PvdbcrScalarRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief PvdbcrScalarRecord creates a record with a scalar value, alarm, and timeStamp.
|
||||
*
|
||||
*/
|
||||
class epicsShareClass PvdbcrScalarRecord :
|
||||
public PVRecord
|
||||
{
|
||||
private:
|
||||
PvdbcrScalarRecord(
|
||||
std::string const & recordName,epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel,std::string const & asGroup);
|
||||
public:
|
||||
POINTER_DEFINITIONS(PvdbcrScalarRecord);
|
||||
/**
|
||||
* The Destructor.
|
||||
*/
|
||||
virtual ~PvdbcrScalarRecord() {}
|
||||
/**
|
||||
* @brief Create a record.
|
||||
*
|
||||
* @param recordName The record name.
|
||||
* @param scalarType The type for the value field
|
||||
* @param asLevel The access security level.
|
||||
* @param asGroup The access security group.
|
||||
* @return The PVRecord
|
||||
*/
|
||||
static PvdbcrScalarRecordPtr create(
|
||||
std::string const & recordName,std::string const & scalarType,
|
||||
int asLevel=0,std::string const & asGroup = std::string("DEFAULT"));
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PVDBCRSCALARRECORD_H */
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* 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.04.11
|
||||
*/
|
||||
#ifndef PVDBCRTRACEARRAY_H
|
||||
#define PVDBCRTRACEARRAY_H
|
||||
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/pvSupport.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class PvdbcrTraceRecord;
|
||||
typedef std::tr1::shared_ptr<PvdbcrTraceRecord> PvdbcrTraceRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief PvdbcrTraceRecord A record sets trace level for a record in the master database.
|
||||
*
|
||||
*/
|
||||
class epicsShareClass PvdbcrTraceRecord :
|
||||
public PVRecord
|
||||
{
|
||||
private:
|
||||
PvdbcrTraceRecord(
|
||||
std::string const & recordName,epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel,std::string const & asGroup);
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVIntPtr pvLevel;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
public:
|
||||
POINTER_DEFINITIONS(PvdbcrTraceRecord);
|
||||
/**
|
||||
* The Destructor.
|
||||
*/
|
||||
virtual ~PvdbcrTraceRecord() {}
|
||||
/**
|
||||
* @brief Create a record.
|
||||
*
|
||||
* @param recordName The record name.
|
||||
* @param asLevel The access security level.
|
||||
* @param asGroup The access security group.
|
||||
* @return The PVRecord
|
||||
*/
|
||||
static PvdbcrTraceRecordPtr create(
|
||||
std::string const & recordName,
|
||||
int asLevel=0,std::string const & asGroup = std::string("DEFAULT"));
|
||||
/**
|
||||
* @brief a PVRecord method
|
||||
* @return success or failure
|
||||
*/
|
||||
virtual bool init();
|
||||
/**
|
||||
* @brief process method that sets trace level for a record in the master database.
|
||||
*/
|
||||
virtual void process();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* PVDBCRTRACEARRAY_H */
|
||||
64
src/pv/removeRecord.h
Normal file
64
src/pv/removeRecord.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* removeRecord.h */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
#ifndef REMOVERECORD_H
|
||||
#define REMOVERECORD_H
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
#include <pv/channelProviderLocal.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
|
||||
class RemoveRecord;
|
||||
typedef std::tr1::shared_ptr<RemoveRecord> RemoveRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief Remove another record in the same database.
|
||||
*
|
||||
* A record to remove another record
|
||||
* It is meant to be used via a channelPutGet request.
|
||||
* The argument has one field: recordName.
|
||||
* The result has a field named status.
|
||||
*/
|
||||
class epicsShareClass RemoveRecord :
|
||||
public PVRecord
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(RemoveRecord);
|
||||
/**
|
||||
* Factory methods to create RemoveRecord.
|
||||
* @param recordName The name for the RemoveRecord.
|
||||
* @return A shared pointer to RemoveRecord..
|
||||
*/
|
||||
static RemoveRecordPtr create(
|
||||
std::string const & recordName);
|
||||
/**
|
||||
* standard init method required by PVRecord
|
||||
* @return true unless record name already exists.
|
||||
*/
|
||||
virtual bool init();
|
||||
/**
|
||||
* @brief Remove the record specified by recordName.
|
||||
*/
|
||||
virtual void process();
|
||||
private:
|
||||
RemoveRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
PVDatabasePtr pvDatabase;
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* REMOVERECORD_H */
|
||||
@@ -1,110 +0,0 @@
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2019.06.01
|
||||
*/
|
||||
#ifndef SCALARALARMSUPPORT_H
|
||||
#define SCALARALARMSUPPORT_H
|
||||
|
||||
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/pvSupport.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class ScalarAlarmSupport;
|
||||
typedef std::tr1::shared_ptr<ScalarAlarmSupport> ScalarAlarmSupportPtr;
|
||||
|
||||
/**
|
||||
* @brief Base interface for a ScalarAlarmSupport.
|
||||
*
|
||||
*/
|
||||
class epicsShareClass ScalarAlarmSupport :
|
||||
PVSupport
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(ScalarAlarmSupport);
|
||||
/**
|
||||
* The Destructor.
|
||||
*/
|
||||
virtual ~ScalarAlarmSupport();
|
||||
/**
|
||||
* @brief Connects to contol fields.
|
||||
*
|
||||
* @param pvValue The field to support.
|
||||
* @param pvAlarm The alarm field.
|
||||
* @param pvSupport Support specific fields.
|
||||
* @return <b>true</b> for success and <b>false</b> for failure.
|
||||
*/
|
||||
virtual bool init(
|
||||
epics::pvData::PVFieldPtr const & pvValue,
|
||||
epics::pvData::PVStructurePtr const & pvAlarm,
|
||||
epics::pvData::PVFieldPtr const & pvSupport);
|
||||
/**
|
||||
* @brief Honors scalarAlarm fields.
|
||||
*
|
||||
*
|
||||
* @return Returns true is any fields were modified; otherwise false.
|
||||
*/
|
||||
virtual bool process();
|
||||
/**
|
||||
* @brief If implementing minSteps it sets isMinStep to false.
|
||||
*
|
||||
*/
|
||||
virtual void reset();
|
||||
/**
|
||||
* @brief create a ScalarAlarm
|
||||
*
|
||||
* @param pvRecord - The pvRecord to which the support is attached.
|
||||
* @return The new ScalarAlarm
|
||||
*/
|
||||
static ScalarAlarmSupportPtr create(PVRecordPtr const & pvRecord);
|
||||
/**
|
||||
* @brief create a scalarAlarm required by ScalarAlarm
|
||||
*
|
||||
* @return The scalarAlarmField introspection structure.
|
||||
*/
|
||||
static epics::pvData::StructureConstPtr scalarAlarmField();
|
||||
private:
|
||||
|
||||
ScalarAlarmSupport(PVRecordPtr const & pvRecord);
|
||||
enum {
|
||||
range_Lolo = 0,
|
||||
range_Low,
|
||||
range_Normal,
|
||||
range_High,
|
||||
range_Hihi,
|
||||
range_Invalid,
|
||||
range_Undefined
|
||||
} AlarmRange;
|
||||
void setAlarm(
|
||||
epics::pvData::PVStructurePtr const & pvAlarm,
|
||||
int alarmRange);
|
||||
PVRecordPtr pvRecord;
|
||||
int prevAlarmRange;
|
||||
epics::pvData::PVScalarPtr pvValue;
|
||||
epics::pvData::PVStructurePtr pvAlarm;
|
||||
epics::pvData::PVStructurePtr pvScalarAlarm;
|
||||
epics::pvData::PVBooleanPtr pvActive;
|
||||
epics::pvData::PVDoublePtr pvLowAlarmLimit;
|
||||
epics::pvData::PVDoublePtr pvLowWarningLimit;
|
||||
epics::pvData::PVDoublePtr pvHighWarningLimit;
|
||||
epics::pvData::PVDoublePtr pvHighAlarmLimit;
|
||||
epics::pvData::PVDoublePtr pvHysteresis;
|
||||
double requestedValue;
|
||||
double currentValue;
|
||||
bool isHystersis;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* SCALARALARMSUPPORT_H */
|
||||
66
src/pv/traceRecord.h
Normal file
66
src/pv/traceRecord.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* traceRecord.h */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
#ifndef TRACERECORD_H
|
||||
#define TRACERECORD_H
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
#include <pv/channelProviderLocal.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
|
||||
class TraceRecord;
|
||||
typedef std::tr1::shared_ptr<TraceRecord> TraceRecordPtr;
|
||||
|
||||
/**
|
||||
* @brief Trace activity of PVRecord.
|
||||
*
|
||||
* A record to set the trace value for another record
|
||||
* It is meant to be used via a channelPutGet request.
|
||||
* The argument has two fields: recordName and level.
|
||||
* The result has a field named status.
|
||||
*/
|
||||
class epicsShareClass TraceRecord :
|
||||
public PVRecord
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(TraceRecord);
|
||||
/**
|
||||
* @brief Factory method to create TraceRecord.
|
||||
*
|
||||
* @param recordName The name for the TraceRecord.
|
||||
* @return A shared pointer to TraceRecord..
|
||||
*/
|
||||
static TraceRecordPtr create(
|
||||
std::string const & recordName);
|
||||
/**
|
||||
* standard init method required by PVRecord
|
||||
* @return true unless record name already exists.
|
||||
*/
|
||||
virtual bool init();
|
||||
/**
|
||||
* @brief Set the trace level for record specified by recordName.
|
||||
*/
|
||||
virtual void process();
|
||||
private:
|
||||
TraceRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
PVDatabasePtr pvDatabase;
|
||||
epics::pvData::PVStringPtr pvRecordName;
|
||||
epics::pvData::PVIntPtr pvLevel;
|
||||
epics::pvData::PVStringPtr pvResult;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* TRACERECORD_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/* channelProviderLocal.cpp */
|
||||
/* channelChannelProviderLocal.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -9,84 +9,96 @@
|
||||
* @date 2013.04
|
||||
*/
|
||||
|
||||
#include <epicsThread.h>
|
||||
#include <asLib.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/syncChannelFind.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/timeStamp.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/channelProviderLocal.h"
|
||||
|
||||
#include <pv/channelProviderLocal.h>
|
||||
#include <pv/traceRecord.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvCopy;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using std::tr1::dynamic_pointer_cast;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
static string providerName("local");
|
||||
static ChannelProviderLocalPtr channelProvider;
|
||||
|
||||
|
||||
class LocalChannelProviderFactory;
|
||||
typedef std::tr1::shared_ptr<LocalChannelProviderFactory> LocalChannelProviderFactoryPtr;
|
||||
|
||||
class LocalChannelProviderFactory : public ChannelProviderFactory
|
||||
{
|
||||
|
||||
public:
|
||||
POINTER_DEFINITIONS(LocalChannelProviderFactory);
|
||||
virtual string getFactoryName() { return providerName;}
|
||||
static LocalChannelProviderFactoryPtr create(
|
||||
ChannelProviderLocalPtr const &channelProvider)
|
||||
{
|
||||
LocalChannelProviderFactoryPtr xxx(
|
||||
new LocalChannelProviderFactory(channelProvider));
|
||||
registerChannelProviderFactory(xxx);
|
||||
return xxx;
|
||||
}
|
||||
virtual ChannelProvider::shared_pointer sharedInstance()
|
||||
{
|
||||
if(!channelProvider) channelProvider = ChannelProviderLocalPtr(new ChannelProviderLocal());
|
||||
return channelProvider;
|
||||
}
|
||||
virtual ChannelProvider::shared_pointer newInstance()
|
||||
{
|
||||
throw std::logic_error(
|
||||
"LocalChannelProviderFactory::newInstance() not Implemented");
|
||||
throw std::logic_error("newInstance not Implemented");
|
||||
}
|
||||
private:
|
||||
LocalChannelProviderFactory(
|
||||
ChannelProviderLocalPtr const &channelProvider)
|
||||
: channelProvider(channelProvider)
|
||||
{}
|
||||
ChannelProviderLocalPtr channelProvider;
|
||||
};
|
||||
|
||||
|
||||
ChannelProviderLocalPtr getChannelProviderLocal()
|
||||
{
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
ChannelProviderFactory::shared_pointer factory(
|
||||
new LocalChannelProviderFactory());
|
||||
ChannelProviderRegistry::servers()->add(factory);
|
||||
static ChannelProviderLocalPtr channelProviderLocal;
|
||||
static Mutex mutex;
|
||||
Lock xx(mutex);
|
||||
if(!channelProviderLocal) {
|
||||
channelProviderLocal = ChannelProviderLocalPtr(
|
||||
new ChannelProviderLocal());
|
||||
ChannelProvider::shared_pointer xxx =
|
||||
dynamic_pointer_cast<ChannelProvider>(channelProviderLocal);
|
||||
channelProviderLocal->channelFinder =
|
||||
SyncChannelFind::shared_pointer(new SyncChannelFind(xxx));
|
||||
LocalChannelProviderFactoryPtr factory(LocalChannelProviderFactory::create(channelProviderLocal));
|
||||
|
||||
}
|
||||
ChannelProvider::shared_pointer channelProvider =
|
||||
ChannelProviderRegistry::servers()->getProvider(providerName);
|
||||
return std::tr1::dynamic_pointer_cast<ChannelProviderLocal>(channelProvider);
|
||||
return channelProviderLocal;
|
||||
}
|
||||
|
||||
ChannelProviderLocal::ChannelProviderLocal()
|
||||
: pvDatabase(PVDatabase::getMaster()),
|
||||
traceLevel(0)
|
||||
beingDestroyed(false)
|
||||
{
|
||||
if(traceLevel>0) {
|
||||
cout << "ChannelProviderLocal::ChannelProviderLocal()\n";
|
||||
}
|
||||
}
|
||||
|
||||
ChannelProviderLocal::~ChannelProviderLocal()
|
||||
{
|
||||
if(traceLevel>0) {
|
||||
cout << "ChannelProviderLocal::~ChannelProviderLocal()\n";
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
|
||||
std::tr1::shared_ptr<ChannelProvider> ChannelProviderLocal::getChannelProvider()
|
||||
void ChannelProviderLocal::destroy()
|
||||
{
|
||||
return shared_from_this();
|
||||
Lock xx(mutex);
|
||||
if(beingDestroyed) return;
|
||||
beingDestroyed = true;
|
||||
pvDatabase->destroy();
|
||||
pvDatabase.reset();
|
||||
}
|
||||
|
||||
string ChannelProviderLocal::getProviderName()
|
||||
@@ -98,46 +110,35 @@ ChannelFind::shared_pointer ChannelProviderLocal::channelFind(
|
||||
string const & channelName,
|
||||
ChannelFindRequester::shared_pointer const &channelFindRequester)
|
||||
{
|
||||
if(traceLevel>1) {
|
||||
cout << "ChannelProviderLocal::channelFind " << "channelName" << endl;
|
||||
}
|
||||
PVDatabasePtr pvdb(pvDatabase.lock());
|
||||
if(!pvdb) {
|
||||
Status notFoundStatus(Status::STATUSTYPE_ERROR,"pvDatabase was deleted");
|
||||
channelFindRequester->channelFindResult(
|
||||
notFoundStatus,
|
||||
shared_from_this(),
|
||||
false);
|
||||
}
|
||||
PVRecordPtr pvRecord = pvdb->findRecord(channelName);
|
||||
Lock xx(mutex);
|
||||
PVRecordPtr pvRecord = pvDatabase->findRecord(channelName);
|
||||
if(pvRecord) {
|
||||
channelFindRequester->channelFindResult(
|
||||
Status::Ok,
|
||||
shared_from_this(),
|
||||
channelFinder,
|
||||
true);
|
||||
|
||||
|
||||
} else {
|
||||
Status notFoundStatus(Status::STATUSTYPE_ERROR,"pv not found");
|
||||
channelFindRequester->channelFindResult(
|
||||
notFoundStatus,
|
||||
shared_from_this(),
|
||||
channelFinder,
|
||||
false);
|
||||
}
|
||||
return shared_from_this();
|
||||
return channelFinder;
|
||||
}
|
||||
|
||||
ChannelFind::shared_pointer ChannelProviderLocal::channelList(
|
||||
ChannelListRequester::shared_pointer const & channelListRequester)
|
||||
{
|
||||
if(traceLevel>1) {
|
||||
cout << "ChannelProviderLocal::channelList\n";
|
||||
PVStringArrayPtr records;
|
||||
{
|
||||
Lock guard(mutex);
|
||||
records = pvDatabase->getRecordNames();
|
||||
}
|
||||
PVDatabasePtr pvdb(pvDatabase.lock());
|
||||
if(!pvdb)throw std::logic_error("pvDatabase was deleted");
|
||||
PVStringArrayPtr records(pvdb->getRecordNames());
|
||||
channelListRequester->channelListResult(
|
||||
Status::Ok, shared_from_this(), records->view(), false);
|
||||
return shared_from_this();
|
||||
|
||||
channelListRequester->channelListResult(Status::Ok, channelFinder, records->view(), false);
|
||||
return channelFinder;
|
||||
}
|
||||
|
||||
Channel::shared_pointer ChannelProviderLocal::createChannel(
|
||||
@@ -145,26 +146,23 @@ Channel::shared_pointer ChannelProviderLocal::createChannel(
|
||||
ChannelRequester::shared_pointer const &channelRequester,
|
||||
short priority)
|
||||
{
|
||||
if(traceLevel>1) {
|
||||
cout << "ChannelProviderLocal::createChannel " << "channelName" << endl;
|
||||
}
|
||||
ChannelLocalPtr channel;
|
||||
Status status = Status::Ok;
|
||||
PVDatabasePtr pvdb(pvDatabase.lock());
|
||||
if(!pvdb) {
|
||||
status = Status::error("pvDatabase was deleted");
|
||||
} else {
|
||||
PVRecordPtr pvRecord = pvdb->findRecord(channelName);
|
||||
if(pvRecord) {
|
||||
channel = ChannelLocalPtr(new ChannelLocal(
|
||||
shared_from_this(),channelRequester,pvRecord));
|
||||
pvRecord->addPVRecordClient(channel);
|
||||
} else {
|
||||
status = Status::error("pv not found");
|
||||
}
|
||||
}
|
||||
channelRequester->channelCreated(status,channel);
|
||||
return channel;
|
||||
Lock xx(mutex);
|
||||
PVRecordPtr pvRecord = pvDatabase->findRecord(channelName);
|
||||
if(pvRecord) {
|
||||
ChannelLocalPtr channel(new ChannelLocal(
|
||||
getPtrSelf(),channelRequester,pvRecord));
|
||||
channelRequester->channelCreated(
|
||||
Status::Ok,
|
||||
channel);
|
||||
pvRecord->addPVRecordClient(channel);
|
||||
return channel;
|
||||
}
|
||||
Status notFoundStatus(Status::STATUSTYPE_ERROR,"pv not found");
|
||||
channelRequester->channelCreated(
|
||||
notFoundStatus,
|
||||
Channel::shared_pointer());
|
||||
return Channel::shared_pointer();
|
||||
|
||||
}
|
||||
|
||||
Channel::shared_pointer ChannelProviderLocal::createChannel(
|
||||
@@ -177,18 +175,4 @@ Channel::shared_pointer ChannelProviderLocal::createChannel(
|
||||
return createChannel(channelName, channelRequester, priority);
|
||||
}
|
||||
|
||||
void ChannelProviderLocal::initAs(const std::string& filePath, const std::string& substitutions)
|
||||
{
|
||||
int status = asInitFile(filePath.c_str(), substitutions.c_str());
|
||||
if(status) {
|
||||
throw std::runtime_error("Invalid AS configuration.");
|
||||
}
|
||||
}
|
||||
|
||||
bool ChannelProviderLocal::isAsActive()
|
||||
{
|
||||
return asActive;
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
@@ -14,137 +14,52 @@
|
||||
#include <epicsGuard.h>
|
||||
#include <pv/thread.h>
|
||||
#include <pv/bitSetUtil.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/queue.h>
|
||||
#include <pv/timeStamp.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/channelProviderLocal.h"
|
||||
|
||||
#include <pv/channelProviderLocal.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvCopy;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class MonitorLocal;
|
||||
typedef std::tr1::shared_ptr<MonitorLocal> MonitorLocalPtr;
|
||||
|
||||
static MonitorPtr nullMonitor;
|
||||
static MonitorElementPtr NULLMonitorElement;
|
||||
static Status failedToCreateMonitorStatus(
|
||||
Status::STATUSTYPE_ERROR,"failed to create monitor");
|
||||
static Status failedToCreateMonitorStatus(Status::STATUSTYPE_ERROR,"failed to create monitor");
|
||||
static Status wasDestroyedStatus(Status::STATUSTYPE_ERROR,"was destroyed");
|
||||
static Status alreadyStartedStatus(Status::STATUSTYPE_ERROR,"already started");
|
||||
static Status notStartedStatus(Status::STATUSTYPE_ERROR,"not started");
|
||||
static Status deletedStatus(Status::STATUSTYPE_ERROR,"record is deleted");
|
||||
|
||||
class MonitorElementQueue;
|
||||
|
||||
|
||||
typedef Queue<MonitorElement> MonitorElementQueue;
|
||||
typedef std::tr1::shared_ptr<MonitorElementQueue> MonitorElementQueuePtr;
|
||||
|
||||
class MonitorElementQueue
|
||||
{
|
||||
private:
|
||||
MonitorElementPtrArray elements;
|
||||
// TODO use size_t instead
|
||||
int size;
|
||||
int numberFree;
|
||||
int numberUsed;
|
||||
int nextGetFree;
|
||||
int nextSetUsed;
|
||||
int nextGetUsed;
|
||||
int nextReleaseUsed;
|
||||
public:
|
||||
POINTER_DEFINITIONS(MonitorElementQueue);
|
||||
|
||||
MonitorElementQueue(std::vector<MonitorElementPtr> monitorElementArray)
|
||||
: elements(monitorElementArray),
|
||||
size(monitorElementArray.size()),
|
||||
numberFree(size),
|
||||
numberUsed(0),
|
||||
nextGetFree(0),
|
||||
nextSetUsed(0),
|
||||
nextGetUsed(0),
|
||||
nextReleaseUsed(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~MonitorElementQueue() {}
|
||||
|
||||
void clear()
|
||||
{
|
||||
numberFree = size;
|
||||
numberUsed = 0;
|
||||
nextGetFree = 0;
|
||||
nextSetUsed = 0;
|
||||
nextGetUsed = 0;
|
||||
nextReleaseUsed = 0;
|
||||
}
|
||||
|
||||
MonitorElementPtr getFree()
|
||||
{
|
||||
if(numberFree==0) return MonitorElementPtr();
|
||||
numberFree--;
|
||||
int ind = nextGetFree;
|
||||
MonitorElementPtr queueElement = elements[nextGetFree++];
|
||||
if(nextGetFree>=size) nextGetFree = 0;
|
||||
return elements[ind];
|
||||
}
|
||||
|
||||
void setUsed(MonitorElementPtr const &element)
|
||||
{
|
||||
if(element!=elements[nextSetUsed++]) {
|
||||
throw std::logic_error("not correct queueElement");
|
||||
}
|
||||
numberUsed++;
|
||||
if(nextSetUsed>=size) nextSetUsed = 0;
|
||||
}
|
||||
|
||||
MonitorElementPtr getUsed()
|
||||
{
|
||||
if(numberUsed==0) return MonitorElementPtr();
|
||||
int ind = nextGetUsed;
|
||||
MonitorElementPtr queueElement = elements[nextGetUsed++];
|
||||
if(nextGetUsed>=size) nextGetUsed = 0;
|
||||
return elements[ind];
|
||||
}
|
||||
void releaseUsed(MonitorElementPtr const &element)
|
||||
{
|
||||
if(element!=elements[nextReleaseUsed++]) {
|
||||
throw std::logic_error(
|
||||
"not queueElement returned by last call to getUsed");
|
||||
}
|
||||
if(nextReleaseUsed>=size) nextReleaseUsed = 0;
|
||||
numberUsed--;
|
||||
numberFree++;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
typedef std::tr1::shared_ptr<MonitorRequester> MonitorRequesterPtr;
|
||||
|
||||
|
||||
|
||||
class MonitorLocal :
|
||||
public Monitor,
|
||||
public PVListener,
|
||||
public std::tr1::enable_shared_from_this<MonitorLocal>
|
||||
{
|
||||
enum MonitorState {idle,active,deleted};
|
||||
enum MonitorState {idle,active, destroyed};
|
||||
public:
|
||||
POINTER_DEFINITIONS(MonitorLocal);
|
||||
virtual ~MonitorLocal();
|
||||
virtual Status start();
|
||||
virtual Status stop();
|
||||
virtual MonitorElementPtr poll();
|
||||
virtual void detach(PVRecordPtr const & pvRecord){}
|
||||
virtual void destroy();
|
||||
virtual void detach(PVRecordPtr const & pvRecord){destroy();}
|
||||
virtual void release(MonitorElementPtr const & monitorElement);
|
||||
virtual void dataPut(PVRecordFieldPtr const & pvRecordField);
|
||||
virtual void dataPut(
|
||||
@@ -190,9 +105,29 @@ MonitorLocal::MonitorLocal(
|
||||
|
||||
MonitorLocal::~MonitorLocal()
|
||||
{
|
||||
//cout << "MonitorLocal::~MonitorLocal()" << endl;
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "MonitorLocal::~MonitorLocal()" << endl;
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
|
||||
void MonitorLocal::destroy()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "MonitorLocal::destroy state " << state << endl;
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(state==destroyed) return;
|
||||
}
|
||||
if(state==active) stop();
|
||||
{
|
||||
Lock xx(mutex);
|
||||
state = destroyed;
|
||||
}
|
||||
}
|
||||
|
||||
Status MonitorLocal::start()
|
||||
{
|
||||
@@ -202,8 +137,8 @@ Status MonitorLocal::start()
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(state==destroyed) return wasDestroyedStatus;
|
||||
if(state==active) return alreadyStartedStatus;
|
||||
if(state==deleted) return deletedStatus;
|
||||
}
|
||||
pvRecord->addListener(getPtrSelf(),pvCopy);
|
||||
epicsGuard <PVRecord> guard(*pvRecord);
|
||||
@@ -226,10 +161,10 @@ Status MonitorLocal::stop()
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(state==destroyed) return wasDestroyedStatus;
|
||||
if(state==idle) return notStartedStatus;
|
||||
if(state==deleted) return deletedStatus;
|
||||
state = idle;
|
||||
}
|
||||
}
|
||||
pvRecord->removeListener(getPtrSelf(),pvCopy);
|
||||
return Status::Ok;
|
||||
}
|
||||
@@ -269,10 +204,9 @@ void MonitorLocal::releaseActiveElement()
|
||||
{
|
||||
Lock xx(queueMutex);
|
||||
if(state!=active) return;
|
||||
bool result = pvCopy->updateCopyFromBitSet(activeElement->pvStructurePtr,activeElement->changedBitSet);
|
||||
if(!result) return;
|
||||
MonitorElementPtr newActive = queue->getFree();
|
||||
if(!newActive) return;
|
||||
pvCopy->updateCopyFromBitSet(activeElement->pvStructurePtr,activeElement->changedBitSet);
|
||||
BitSetUtil::compress(activeElement->changedBitSet,activeElement->pvStructurePtr);
|
||||
BitSetUtil::compress(activeElement->overrunBitSet,activeElement->pvStructurePtr);
|
||||
queue->setUsed(activeElement);
|
||||
@@ -290,7 +224,7 @@ void MonitorLocal::dataPut(PVRecordFieldPtr const & pvRecordField)
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "MonitorLocal::dataPut(pvRecordField)" << endl;
|
||||
cout << "PVCopyMonitor::dataPut(pvRecordField)" << endl;
|
||||
}
|
||||
if(state!=active) return;
|
||||
{
|
||||
@@ -315,7 +249,7 @@ void MonitorLocal::dataPut(
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "MonitorLocal::dataPut(requested,pvRecordField)" << endl;
|
||||
cout << "PVCopyMonitor::dataPut(requested,pvRecordField)" << endl;
|
||||
}
|
||||
if(state!=active) return;
|
||||
{
|
||||
@@ -342,7 +276,7 @@ void MonitorLocal::beginGroupPut(PVRecordPtr const & pvRecord)
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "MonitorLocal::beginGroupPut()" << endl;
|
||||
cout << "PVCopyMonitor::beginGroupPut()" << endl;
|
||||
}
|
||||
if(state!=active) return;
|
||||
{
|
||||
@@ -356,7 +290,7 @@ void MonitorLocal::endGroupPut(PVRecordPtr const & pvRecord)
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "MonitorLocal::endGroupPut dataChanged " << dataChanged << endl;
|
||||
cout << "PVCopyMonitor::endGroupPut dataChanged " << dataChanged << endl;
|
||||
}
|
||||
if(state!=active) return;
|
||||
{
|
||||
@@ -373,20 +307,17 @@ void MonitorLocal::unlisten(PVRecordPtr const & pvRecord)
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "MonitorLocal::unlisten\n";
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
state = deleted;
|
||||
cout << "PVCopyMonitor::unlisten\n";
|
||||
}
|
||||
MonitorRequesterPtr requester = monitorRequester.lock();
|
||||
if(requester) {
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "MonitorLocal::unlisten calling requester->unlisten\n";
|
||||
cout << "PVCopyMonitor::unlisten calling requester->unlisten\n";
|
||||
}
|
||||
requester->unlisten(getPtrSelf());
|
||||
}
|
||||
pvRecord->removeListener(getPtrSelf(),pvCopy);
|
||||
}
|
||||
|
||||
|
||||
@@ -451,27 +382,62 @@ bool MonitorLocal::init(PVStructurePtr const & pvRequest)
|
||||
return true;
|
||||
}
|
||||
|
||||
MonitorPtr createMonitorLocal(
|
||||
|
||||
MonitorFactory::MonitorFactory()
|
||||
: isDestroyed(false)
|
||||
{
|
||||
}
|
||||
|
||||
MonitorFactory::~MonitorFactory()
|
||||
{
|
||||
}
|
||||
|
||||
void MonitorFactory::destroy()
|
||||
{
|
||||
Lock lock(mutex);
|
||||
isDestroyed = true;
|
||||
}
|
||||
|
||||
MonitorPtr MonitorFactory::createMonitor(
|
||||
PVRecordPtr const & pvRecord,
|
||||
MonitorRequester::shared_pointer const & monitorRequester,
|
||||
PVStructurePtr const & pvRequest)
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) {
|
||||
monitorRequester->message("MonitorFactory is destroyed",errorMessage);
|
||||
return nullMonitor;
|
||||
}
|
||||
MonitorLocalPtr monitor(new MonitorLocal(
|
||||
monitorRequester,pvRecord));
|
||||
bool result = monitor->init(pvRequest);
|
||||
if(!result) {
|
||||
MonitorPtr monitor;
|
||||
StructureConstPtr structure;
|
||||
monitorRequester->monitorConnect(
|
||||
failedToCreateMonitorStatus,monitor,structure);
|
||||
monitorRequester->monitorConnect(failedToCreateMonitorStatus,monitor,structure);
|
||||
return nullMonitor;
|
||||
}
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "MonitorFactory::createMonitor"
|
||||
<< " recordName " << pvRecord->getRecordName() << endl;
|
||||
cout << "MonitorFactory::createMonitor";
|
||||
cout << " recordName " << pvRecord->getRecordName() << endl;
|
||||
}
|
||||
return monitor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
MonitorFactoryPtr getMonitorFactory()
|
||||
{
|
||||
static MonitorFactoryPtr monitorFactoryPtr;
|
||||
static Mutex mutex;
|
||||
Lock xx(mutex);
|
||||
|
||||
if(!monitorFactoryPtr) {
|
||||
monitorFactoryPtr = MonitorFactoryPtr(
|
||||
new MonitorFactory());
|
||||
}
|
||||
return monitorFactoryPtr;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -11,19 +11,30 @@
|
||||
|
||||
/* 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 <shareLib.h>
|
||||
#include <epicsExit.h>
|
||||
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/syncChannelFind.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/timeStamp.h>
|
||||
|
||||
// The following must be the last include for code pvDatabase uses
|
||||
// this declared epicsExportSharedSymbols
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/channelProviderLocal.h"
|
||||
|
||||
#include <pv/channelProviderLocal.h>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
@@ -42,6 +53,9 @@ extern "C" void pvdbl(const iocshArgBuf *args)
|
||||
for(size_t i=0; i<xxx.size(); ++i) cout<< xxx[i] << endl;
|
||||
}
|
||||
|
||||
static void channelProviderLocalExitHandler(void* /*pPrivate*/) {
|
||||
getChannelProviderLocal()->destroy();
|
||||
}
|
||||
|
||||
static void registerChannelProviderLocal(void)
|
||||
{
|
||||
@@ -50,6 +64,7 @@ static void registerChannelProviderLocal(void)
|
||||
firstTime = 0;
|
||||
iocshRegister(&pvdblFuncDef, pvdbl);
|
||||
getChannelProviderLocal();
|
||||
epicsAtExit(channelProviderLocalExitHandler, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,17 +2,5 @@
|
||||
|
||||
SRC_DIRS += $(PVDATABASE_SRC)/special
|
||||
|
||||
DBD += pvdbcrScalarRecord.dbd
|
||||
DBD += pvdbcrScalarArrayRecord.dbd
|
||||
DBD += pvdbcrAddRecord.dbd
|
||||
DBD += pvdbcrRemoveRecord.dbd
|
||||
DBD += pvdbcrProcessRecord.dbd
|
||||
DBD += pvdbcrTraceRecord.dbd
|
||||
DBD += pvdbcrAllRecords.dbd
|
||||
|
||||
LIBSRCS += pvdbcrScalarRecord.cpp
|
||||
LIBSRCS += pvdbcrScalarArrayRecord.cpp
|
||||
LIBSRCS += pvdbcrAddRecord.cpp
|
||||
LIBSRCS += pvdbcrRemoveRecord.cpp
|
||||
LIBSRCS += pvdbcrProcessRecord.cpp
|
||||
LIBSRCS += pvdbcrTraceRecord.cpp
|
||||
LIBSRCS += traceRecord.cpp
|
||||
LIBSRCS += removeRecord.cpp
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
/*
|
||||
* Copyright information and license terms for this software can be
|
||||
* found in the file LICENSE that is included with the distribution
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2021.04.07
|
||||
*/
|
||||
#include <iocsh.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/rpcService.h>
|
||||
|
||||
// The following must be the last include for code exampleLink uses
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/pvdbcrAddRecord.h"
|
||||
using namespace epics::pvData;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
PvdbcrAddRecordPtr PvdbcrAddRecord::create(
|
||||
std::string const & recordName,
|
||||
int asLevel,std::string const & asGroup)
|
||||
{
|
||||
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,asLevel,asGroup));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
PvdbcrAddRecord::PvdbcrAddRecord(
|
||||
std::string const & recordName,
|
||||
PVStructurePtr const & pvStructure,
|
||||
int asLevel,std::string const & asGroup)
|
||||
: PVRecord(recordName,pvStructure,asLevel,asGroup)
|
||||
{
|
||||
}
|
||||
|
||||
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 = std::tr1::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)
|
||||
{
|
||||
char *sval = args[0].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("pvdbcrAddRecord recordName not specified");
|
||||
}
|
||||
string recordName = string(sval);
|
||||
int asLevel = args[1].ival;
|
||||
string asGroup("DEFAULT");
|
||||
sval = args[2].sval;
|
||||
if(sval) {
|
||||
asGroup = string(sval);
|
||||
}
|
||||
epics::pvDatabase::PvdbcrAddRecordPtr record = epics::pvDatabase::PvdbcrAddRecord::create(recordName);
|
||||
record->setAsLevel(asLevel);
|
||||
record->setAsGroup(asGroup);
|
||||
epics::pvDatabase::PVDatabasePtr master = epics::pvDatabase::PVDatabase::getMaster();
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||
}
|
||||
|
||||
static void pvdbcrAddRecord(void)
|
||||
{
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
iocshRegister(&pvdbcrAddRecordFuncDef, pvdbcrAddRecordCallFunc);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
epicsExportRegistrar(pvdbcrAddRecord);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
registrar("pvdbcrAddRecord")
|
||||
@@ -1,6 +0,0 @@
|
||||
include "pvdbcrAddRecord.dbd"
|
||||
include "pvdbcrRemoveRecord.dbd"
|
||||
include "pvdbcrProcessRecord.dbd"
|
||||
include "pvdbcrTraceRecord.dbd"
|
||||
include "pvdbcrScalarRecord.dbd"
|
||||
include "pvdbcrScalarArrayRecord.dbd"
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* Copyright information and license terms for this software can be
|
||||
* found in the file LICENSE that is included with the distribution
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2021.04.07
|
||||
*/
|
||||
#include <epicsThread.h>
|
||||
#include <epicsGuard.h>
|
||||
#include <pv/event.h>
|
||||
#include <pv/lock.h>
|
||||
#include <iocsh.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/rpcService.h>
|
||||
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/pvdbcrProcessRecord.h"
|
||||
using namespace epics::pvData;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
PvdbcrProcessRecordPtr PvdbcrProcessRecord::create(
|
||||
std::string const & recordName,double delay,
|
||||
int asLevel,std::string const & asGroup)
|
||||
{
|
||||
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,asLevel,asGroup));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
|
||||
PvdbcrProcessRecord::PvdbcrProcessRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure,double delay,
|
||||
int asLevel,std::string const & asGroup)
|
||||
: PVRecord(recordName,pvStructure,asLevel,asGroup),
|
||||
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::setDelay(double delay) {this->delay = delay;}
|
||||
|
||||
double PvdbcrProcessRecord::getDelay() {return delay;}
|
||||
|
||||
void PvdbcrProcessRecord::startThread()
|
||||
{
|
||||
thread = EpicsThreadPtr(new epicsThread(
|
||||
*this,
|
||||
"processRecord",
|
||||
epicsThreadGetStackSize(epicsThreadStackSmall),
|
||||
epicsThreadPriorityLow));
|
||||
thread->start();
|
||||
}
|
||||
|
||||
void PvdbcrProcessRecord::stop()
|
||||
{
|
||||
runStop.signal();
|
||||
runReturn.wait();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
char *sval = args[0].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("pvdbcrProcessRecord recordName not specified");
|
||||
}
|
||||
string recordName = string(sval);
|
||||
double delay = args[1].dval;
|
||||
if(delay<0.0) delay = 1.0;
|
||||
int asLevel = args[2].ival;
|
||||
string asGroup("DEFAULT");
|
||||
sval = args[3].sval;
|
||||
if(sval) {
|
||||
asGroup = string(sval);
|
||||
}
|
||||
epics::pvDatabase::PvdbcrProcessRecordPtr record
|
||||
= epics::pvDatabase::PvdbcrProcessRecord::create(recordName,delay);
|
||||
record->setAsLevel(asLevel);
|
||||
record->setAsGroup(asGroup);
|
||||
epics::pvDatabase::PVDatabasePtr master = epics::pvDatabase::PVDatabase::getMaster();
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||
}
|
||||
|
||||
static void pvdbcrProcessRecord(void)
|
||||
{
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
iocshRegister(&pvdbcrProcessRecordFuncDef, pvdbcrProcessRecordCallFunc);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
epicsExportRegistrar(pvdbcrProcessRecord);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
registrar("pvdbcrProcessRecord")
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright information and license terms for this software can be
|
||||
* found in the file LICENSE that is included with the distribution
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2021.04.07
|
||||
*/
|
||||
#include <iocsh.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/rpcService.h>
|
||||
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/pvdbcrRemoveRecord.h"
|
||||
using namespace epics::pvData;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
PvdbcrRemoveRecordPtr PvdbcrRemoveRecord::create(
|
||||
std::string const & recordName,
|
||||
int asLevel,std::string const & asGroup)
|
||||
{
|
||||
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,
|
||||
asLevel,asGroup));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
PvdbcrRemoveRecord::PvdbcrRemoveRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel,std::string const & asGroup)
|
||||
: PVRecord(recordName,pvStructure,asLevel,asGroup)
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
char *sval = args[0].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("pvdbcrRemoveRecord recordName not specified");
|
||||
}
|
||||
string recordName = string(sval);
|
||||
int asLevel = args[1].ival;
|
||||
string asGroup("DEFAULT");
|
||||
sval = args[2].sval;
|
||||
if(sval) {
|
||||
asGroup = string(sval);
|
||||
}
|
||||
epics::pvDatabase::PvdbcrRemoveRecordPtr record = epics::pvDatabase::PvdbcrRemoveRecord::create(recordName);
|
||||
record->setAsLevel(asLevel);
|
||||
record->setAsGroup(asGroup);
|
||||
epics::pvDatabase::PVDatabasePtr master = epics::pvDatabase::PVDatabase::getMaster();
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||
}
|
||||
|
||||
static void pvdbcrRemoveRecord(void)
|
||||
{
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
iocshRegister(&pvdbcrRemoveRecordFuncDef, pvdbcrRemoveRecordCallFunc);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
epicsExportRegistrar(pvdbcrRemoveRecord);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
registrar("pvdbcrRemoveRecord")
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright information and license terms for this software can be
|
||||
* found in the file LICENSE that is included with the distribution
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2021.04.07
|
||||
*/
|
||||
#include <iocsh.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/rpcService.h>
|
||||
|
||||
// The following must be the last include for code pvDatabase implements
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/pvdbcrScalarArrayRecord.h"
|
||||
using namespace epics::pvData;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
PvdbcrScalarArrayRecord::PvdbcrScalarArrayRecord(
|
||||
std::string const & recordName,epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel,std::string const & asGroup)
|
||||
: PVRecord(recordName,pvStructure,asLevel,asGroup)
|
||||
{}
|
||||
|
||||
PvdbcrScalarArrayRecordPtr PvdbcrScalarArrayRecord::create(
|
||||
std::string const & recordName,std::string const & scalarType,
|
||||
int asLevel,std::string const & asGroup)
|
||||
{
|
||||
ScalarType st = epics::pvData::ScalarTypeFunc::getScalarType(scalarType);
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
StandardFieldPtr standardField = getStandardField();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr top = fieldCreate->createFieldBuilder()->
|
||||
addArray("value",st) ->
|
||||
add("timeStamp",standardField->timeStamp()) ->
|
||||
add("alarm",standardField->alarm()) ->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
|
||||
PvdbcrScalarArrayRecordPtr pvRecord(new PvdbcrScalarArrayRecord(recordName,pvStructure,asLevel,asGroup));
|
||||
pvRecord->initPVRecord();
|
||||
return pvRecord;
|
||||
};
|
||||
}}
|
||||
|
||||
static const iocshArg arg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg arg1 = { "scalarType", iocshArgString };
|
||||
static const iocshArg arg2 = { "asLevel", iocshArgInt };
|
||||
static const iocshArg arg3 = { "asGroup", iocshArgString };
|
||||
static const iocshArg *args[] = {&arg0,&arg1,&arg2,&arg3};
|
||||
|
||||
static const iocshFuncDef pvdbcrScalarArrayFuncDef = {"pvdbcrScalarArrayRecord", 4,args};
|
||||
|
||||
static void pvdbcrScalarArrayCallFunc(const iocshArgBuf *args)
|
||||
{
|
||||
char *sval = args[0].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("pvdbcrScalarArrayRecord recordName not specified");
|
||||
}
|
||||
string recordName = string(sval);
|
||||
sval = args[1].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("pvdbcrScalarArrayRecord scalarType not specified");
|
||||
}
|
||||
string scalarType = string(sval);
|
||||
int asLevel = args[2].ival;
|
||||
string asGroup("DEFAULT");
|
||||
sval = args[3].sval;
|
||||
if(sval) {
|
||||
asGroup = string(sval);
|
||||
}
|
||||
epics::pvDatabase::PvdbcrScalarArrayRecordPtr record
|
||||
= epics::pvDatabase::PvdbcrScalarArrayRecord::create(recordName,scalarType);
|
||||
epics::pvDatabase::PVDatabasePtr master = epics::pvDatabase::PVDatabase::getMaster();
|
||||
record->setAsLevel(asLevel);
|
||||
record->setAsGroup(asGroup);
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||
}
|
||||
|
||||
static void pvdbcrScalarArrayRecord(void)
|
||||
{
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
iocshRegister(&pvdbcrScalarArrayFuncDef, pvdbcrScalarArrayCallFunc);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
epicsExportRegistrar(pvdbcrScalarArrayRecord);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
registrar("pvdbcrScalarArrayRecord")
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright information and license terms for this software can be
|
||||
* found in the file LICENSE that is included with the distribution
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2021.04.07
|
||||
*/
|
||||
#include <iocsh.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/rpcService.h>
|
||||
|
||||
// The following must be the last include for code pvDatabase implements
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/pvdbcrScalarRecord.h"
|
||||
using namespace epics::pvData;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
PvdbcrScalarRecord::PvdbcrScalarRecord(
|
||||
std::string const & recordName,epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel,std::string const & asGroup)
|
||||
: PVRecord(recordName,pvStructure,asLevel,asGroup)
|
||||
{}
|
||||
|
||||
PvdbcrScalarRecordPtr PvdbcrScalarRecord::create(
|
||||
std::string const & recordName,std::string const & scalarType,
|
||||
int asLevel,std::string const & asGroup)
|
||||
{
|
||||
ScalarType st = epics::pvData::ScalarTypeFunc::getScalarType(scalarType);
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
StandardFieldPtr standardField = getStandardField();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr top = fieldCreate->createFieldBuilder()->
|
||||
add("value",st) ->
|
||||
add("timeStamp",standardField->timeStamp()) ->
|
||||
add("alarm",standardField->alarm()) ->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
|
||||
PvdbcrScalarRecordPtr pvRecord(new PvdbcrScalarRecord(recordName,pvStructure,asLevel,asGroup));
|
||||
pvRecord->initPVRecord();
|
||||
return pvRecord;
|
||||
};
|
||||
}}
|
||||
|
||||
static const iocshArg arg0 = { "recordName", iocshArgString };
|
||||
static const iocshArg arg1 = { "scalarType", iocshArgString };
|
||||
static const iocshArg arg2 = { "asLevel", iocshArgInt };
|
||||
static const iocshArg arg3 = { "asGroup", iocshArgString };
|
||||
static const iocshArg *args[] = {&arg0,&arg1,&arg2,&arg3};
|
||||
|
||||
static const iocshFuncDef pvdbcrScalarFuncDef = {"pvdbcrScalarRecord", 4,args};
|
||||
|
||||
static void pvdbcrScalarCallFunc(const iocshArgBuf *args)
|
||||
{
|
||||
char *sval = args[0].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("pvdbcrScalarRecord recordName not specified");
|
||||
}
|
||||
string recordName = string(sval);
|
||||
sval = args[1].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("pvdbcrScalarRecord scalarType not specified");
|
||||
}
|
||||
string scalarType = string(sval);
|
||||
int asLevel = args[2].ival;
|
||||
string asGroup("DEFAULT");
|
||||
sval = args[3].sval;
|
||||
if(sval) {
|
||||
asGroup = string(sval);
|
||||
}
|
||||
epics::pvDatabase::PvdbcrScalarRecordPtr record
|
||||
= epics::pvDatabase::PvdbcrScalarRecord::create(recordName,scalarType);
|
||||
epics::pvDatabase::PVDatabasePtr master = epics::pvDatabase::PVDatabase::getMaster();
|
||||
record->setAsLevel(asLevel);
|
||||
record->setAsGroup(asGroup);
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||
}
|
||||
|
||||
static void pvdbcrScalarRecord(void)
|
||||
{
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
iocshRegister(&pvdbcrScalarFuncDef, pvdbcrScalarCallFunc);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
epicsExportRegistrar(pvdbcrScalarRecord);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
registrar("pvdbcrScalarRecord")
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright information and license terms for this software can be
|
||||
* found in the file LICENSE that is included with the distribution
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2021.04.07
|
||||
*/
|
||||
#include <iocsh.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/rpcService.h>
|
||||
|
||||
// The following must be the last include
|
||||
#include <epicsExport.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/pvdbcrTraceRecord.h"
|
||||
using namespace epics::pvData;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
PvdbcrTraceRecordPtr PvdbcrTraceRecord::create(
|
||||
std::string const & recordName,
|
||||
int asLevel,std::string const & asGroup)
|
||||
{
|
||||
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,asLevel,asGroup));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
PvdbcrTraceRecord::PvdbcrTraceRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure,
|
||||
int asLevel,std::string const & asGroup)
|
||||
: PVRecord(recordName,pvStructure,asLevel,asGroup)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
char *sval = args[0].sval;
|
||||
if(!sval) {
|
||||
throw std::runtime_error("pvdbcrTraceRecord recordName not specified");
|
||||
}
|
||||
string recordName = string(sval);
|
||||
int asLevel = args[1].ival;
|
||||
string asGroup("DEFAULT");
|
||||
sval = args[2].sval;
|
||||
if(sval) {
|
||||
asGroup = string(sval);
|
||||
}
|
||||
epics::pvDatabase::PvdbcrTraceRecordPtr record
|
||||
= epics::pvDatabase::PvdbcrTraceRecord::create(recordName);
|
||||
record->setAsLevel(asLevel);
|
||||
record->setAsGroup(asGroup);
|
||||
epics::pvDatabase::PVDatabasePtr master = epics::pvDatabase::PVDatabase::getMaster();
|
||||
bool result = master->addRecord(record);
|
||||
if(!result) cout << "recordname " << recordName << " not added" << endl;
|
||||
}
|
||||
|
||||
static void pvdbcrTraceRecord(void)
|
||||
{
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
iocshRegister(&pvdbcrTraceRecordFuncDef, pvdbcrTraceRecordCallFunc);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
epicsExportRegistrar(pvdbcrTraceRecord);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
registrar("pvdbcrTraceRecord")
|
||||
75
src/special/removeRecord.cpp
Normal file
75
src/special/removeRecord.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/* removeRecord.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
#define epicsExportSharedSymbols
|
||||
|
||||
#include <pv/removeRecord.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
RemoveRecordPtr RemoveRecord::create(
|
||||
std::string const & recordName)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
addNestedStructure("argument")->
|
||||
add("recordName",pvString)->
|
||||
endNested()->
|
||||
addNestedStructure("result") ->
|
||||
add("status",pvString) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
RemoveRecordPtr pvRecord(
|
||||
new RemoveRecord(recordName,pvStructure));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
RemoveRecord::RemoveRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure)
|
||||
: PVRecord(recordName,pvStructure),
|
||||
pvDatabase(PVDatabase::getMaster())
|
||||
{
|
||||
}
|
||||
|
||||
bool RemoveRecord::init()
|
||||
{
|
||||
initPVRecord();
|
||||
PVStructurePtr pvStructure = getPVStructure();
|
||||
pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
|
||||
if(!pvRecordName) return false;
|
||||
pvResult = pvStructure->getSubField<PVString>("result.status");
|
||||
if(!pvResult) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RemoveRecord::process()
|
||||
{
|
||||
string name = pvRecordName->get();
|
||||
PVRecordPtr pvRecord = pvDatabase->findRecord(name);
|
||||
if(!pvRecord) {
|
||||
pvResult->put(name + " not found");
|
||||
return;
|
||||
}
|
||||
pvRecord->destroy();
|
||||
pvResult->put("success");
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
79
src/special/traceRecord.cpp
Normal file
79
src/special/traceRecord.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/* traceRecord.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.04.18
|
||||
*/
|
||||
#define epicsExportSharedSymbols
|
||||
|
||||
#include <pv/traceRecord.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
TraceRecordPtr TraceRecord::create(
|
||||
std::string const & recordName)
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
StructureConstPtr topStructure = fieldCreate->createFieldBuilder()->
|
||||
addNestedStructure("argument")->
|
||||
add("recordName",pvString)->
|
||||
add("level",pvInt)->
|
||||
endNested()->
|
||||
addNestedStructure("result") ->
|
||||
add("status",pvString) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
|
||||
TraceRecordPtr pvRecord(
|
||||
new TraceRecord(recordName,pvStructure));
|
||||
if(!pvRecord->init()) pvRecord.reset();
|
||||
return pvRecord;
|
||||
}
|
||||
|
||||
TraceRecord::TraceRecord(
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure)
|
||||
: PVRecord(recordName,pvStructure),
|
||||
pvDatabase(PVDatabase::getMaster())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TraceRecord::init()
|
||||
{
|
||||
initPVRecord();
|
||||
PVStructurePtr pvStructure = getPVStructure();
|
||||
pvRecordName = pvStructure->getSubField<PVString>("argument.recordName");
|
||||
if(!pvRecordName) return false;
|
||||
pvLevel = pvStructure->getSubField<PVInt>("argument.level");
|
||||
if(!pvLevel) return false;
|
||||
pvResult = pvStructure->getSubField<PVString>("result.status");
|
||||
if(!pvResult) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TraceRecord::process()
|
||||
{
|
||||
string name = pvRecordName->get();
|
||||
PVRecordPtr pvRecord = pvDatabase->findRecord(name);
|
||||
if(!pvRecord) {
|
||||
pvResult->put(name + " not found");
|
||||
return;
|
||||
}
|
||||
pvRecord->setTraceLevel(pvLevel->get());
|
||||
pvResult->put("success");
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
# This is a Makefile fragment, see ../Makefile
|
||||
|
||||
SRC_DIRS += $(PVDATABASE_SRC)/support
|
||||
|
||||
LIBSRCS += controlSupport.cpp
|
||||
LIBSRCS += scalarAlarmSupport.cpp
|
||||
@@ -1,138 +0,0 @@
|
||||
/* controlSupport.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 2019.06.01
|
||||
*/
|
||||
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/convert.h>
|
||||
#include <pv/standardField.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include <pv/pvSupport.h>
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/controlSupport.h"
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
ControlSupport::~ControlSupport()
|
||||
{
|
||||
//cout << "ControlSupport::~ControlSupport()\n";
|
||||
}
|
||||
|
||||
epics::pvData::StructureConstPtr ControlSupport::controlField(ScalarType scalarType)
|
||||
{
|
||||
return FieldBuilder::begin()
|
||||
->setId("control_t")
|
||||
->add("limitLow", pvDouble)
|
||||
->add("limitHigh", pvDouble)
|
||||
->add("minStep", pvDouble)
|
||||
->add("outputValue", scalarType)
|
||||
->createStructure();
|
||||
}
|
||||
|
||||
|
||||
ControlSupportPtr ControlSupport::create(PVRecordPtr const & pvRecord)
|
||||
{
|
||||
cerr << "ControlSupport IS DEPRECATED\n";
|
||||
ControlSupportPtr support(new ControlSupport(pvRecord));
|
||||
return support;
|
||||
}
|
||||
|
||||
ControlSupport::ControlSupport(PVRecordPtr const & pvRecord)
|
||||
: pvRecord(pvRecord)
|
||||
{}
|
||||
|
||||
bool ControlSupport::init(PVFieldPtr const & pv,PVFieldPtr const & pvsup)
|
||||
{
|
||||
if(pv) {
|
||||
if(pv->getField()->getType()==epics::pvData::scalar) {
|
||||
ScalarConstPtr s = static_pointer_cast<const Scalar>(pv->getField());
|
||||
if(ScalarTypeFunc::isNumeric(s->getScalarType())) {
|
||||
pvValue = static_pointer_cast<PVScalar>(pv);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!pvValue) {
|
||||
cout << "ControlSupport for record " << pvRecord->getRecordName()
|
||||
<< " failed because not numeric scalar\n";
|
||||
return false;
|
||||
}
|
||||
pvControl = static_pointer_cast<PVStructure>(pvsup);
|
||||
if(pvControl) {
|
||||
pvLimitLow = pvControl->getSubField<PVDouble>("limitLow");
|
||||
pvLimitHigh = pvControl->getSubField<PVDouble>("limitHigh");
|
||||
pvMinStep = pvControl->getSubField<PVDouble>("minStep");
|
||||
pvOutputValue = pvControl->getSubField<PVScalar>("outputValue");
|
||||
}
|
||||
if(!pvControl || !pvLimitLow || !pvLimitHigh || !pvMinStep || !pvOutputValue) {
|
||||
cout << "ControlSupport for record " << pvRecord->getRecordName()
|
||||
<< " failed because pvSupport not a valid control structure\n";
|
||||
return false;
|
||||
}
|
||||
ConvertPtr convert = getConvert();
|
||||
currentValue = convert->toDouble(pvValue);
|
||||
isMinStep = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ControlSupport::process()
|
||||
{
|
||||
ConvertPtr convert = getConvert();
|
||||
double value = convert->toDouble(pvValue);
|
||||
if(!isMinStep && value==currentValue) return false;
|
||||
double limitLow = pvLimitLow->get();
|
||||
double limitHigh = pvLimitHigh->get();
|
||||
double minStep = pvMinStep->get();
|
||||
bool setValue = false;
|
||||
if(limitHigh>limitLow) {
|
||||
if(value>limitHigh) {value = limitHigh;setValue=true;}
|
||||
if(value<limitLow) {value = limitLow;setValue=true;}
|
||||
}
|
||||
if(setValue) convert->fromDouble(pvValue,value);
|
||||
double diff = value - currentValue;
|
||||
double outputValue = value;
|
||||
if(minStep>0.0) {
|
||||
if(diff<0.0) {
|
||||
outputValue = currentValue - minStep;
|
||||
if(limitHigh>limitLow && outputValue<=limitLow) outputValue = limitLow;
|
||||
isMinStep = true;
|
||||
if(outputValue<value) {
|
||||
outputValue = value;
|
||||
isMinStep = false;
|
||||
}
|
||||
} else {
|
||||
outputValue = currentValue + minStep;
|
||||
if(limitHigh>limitLow && outputValue>=limitHigh) outputValue = limitHigh;
|
||||
isMinStep = true;
|
||||
if(outputValue>value) {
|
||||
outputValue = value;
|
||||
isMinStep = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(outputValue==currentValue) return false;
|
||||
currentValue = outputValue;
|
||||
convert->fromDouble(pvOutputValue,outputValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ControlSupport::reset()
|
||||
{
|
||||
isMinStep = false;
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
@@ -1,219 +0,0 @@
|
||||
/* scalarAlarmSupport.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 2019.06.01
|
||||
*/
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/rpcService.h>
|
||||
#include <pv/convert.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/alarm.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "pv/pvStructureCopy.h"
|
||||
#include "pv/pvSupport.h"
|
||||
#include "pv/pvDatabase.h"
|
||||
#include "pv/scalarAlarmSupport.h"
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
ScalarAlarmSupport::~ScalarAlarmSupport()
|
||||
{
|
||||
//cout << "ScalarAlarmSupport::~ScalarAlarmSupport()\n";
|
||||
}
|
||||
|
||||
|
||||
epics::pvData::StructureConstPtr ScalarAlarmSupport::scalarAlarmField()
|
||||
{
|
||||
return FieldBuilder::begin()
|
||||
->setId("scalarAlarm_t")
|
||||
->add("lowAlarmLimit", pvDouble)
|
||||
->add("lowWarningLimit", pvDouble)
|
||||
->add("highWarningLimit", pvDouble)
|
||||
->add("highAlarmLimit", pvDouble)
|
||||
->add("hysteresis", pvDouble)
|
||||
->createStructure();
|
||||
}
|
||||
|
||||
ScalarAlarmSupportPtr ScalarAlarmSupport::create(PVRecordPtr const & pvRecord)
|
||||
{
|
||||
cerr << "ScalarAlarmSupport IS DEPRECATED\n";
|
||||
ScalarAlarmSupportPtr support(new ScalarAlarmSupport(pvRecord));
|
||||
return support;
|
||||
}
|
||||
|
||||
ScalarAlarmSupport::ScalarAlarmSupport(PVRecordPtr const & pvRecord)
|
||||
: pvRecord(pvRecord),
|
||||
prevAlarmRange(range_Undefined)
|
||||
{}
|
||||
|
||||
|
||||
bool ScalarAlarmSupport::init(
|
||||
PVFieldPtr const & pvval,
|
||||
PVStructurePtr const & pvalarm,
|
||||
PVFieldPtr const & pvsup)
|
||||
{
|
||||
if(pvval->getField()->getType()==epics::pvData::scalar) {
|
||||
ScalarConstPtr s = static_pointer_cast<const Scalar>(pvval->getField());
|
||||
if(ScalarTypeFunc::isNumeric(s->getScalarType())) {
|
||||
pvValue = static_pointer_cast<PVScalar>(pvval);
|
||||
}
|
||||
}
|
||||
if(!pvValue) {
|
||||
cout << "ScalarAlarmSupport for record " << pvRecord->getRecordName()
|
||||
<< " failed because not numeric scalar\n";
|
||||
return false;
|
||||
}
|
||||
pvScalarAlarm = static_pointer_cast<PVStructure>(pvsup);
|
||||
if(pvScalarAlarm) {
|
||||
pvLowAlarmLimit = pvScalarAlarm->getSubField<PVDouble>("lowAlarmLimit");
|
||||
pvLowWarningLimit = pvScalarAlarm->getSubField<PVDouble>("lowWarningLimit");
|
||||
pvHighWarningLimit = pvScalarAlarm->getSubField<PVDouble>("highWarningLimit");
|
||||
pvHighAlarmLimit = pvScalarAlarm->getSubField<PVDouble>("highAlarmLimit");
|
||||
pvHysteresis = pvScalarAlarm->getSubField<PVDouble>("hysteresis");
|
||||
}
|
||||
if(!pvScalarAlarm
|
||||
|| !pvLowAlarmLimit || !pvLowWarningLimit
|
||||
|| !pvLowWarningLimit || !pvHighAlarmLimit
|
||||
|| !pvHysteresis)
|
||||
{
|
||||
cout << "ScalarAlarmSupport for record " << pvRecord->getRecordName()
|
||||
<< " failed because pvSupport not a valid scalarAlarm structure\n";
|
||||
return false;
|
||||
}
|
||||
pvAlarm = pvalarm;
|
||||
ConvertPtr convert = getConvert();
|
||||
requestedValue = convert->toDouble(pvValue);
|
||||
currentValue = requestedValue;
|
||||
isHystersis = false;
|
||||
setAlarm(pvAlarm,range_Undefined);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScalarAlarmSupport::process()
|
||||
{
|
||||
ConvertPtr convert = getConvert();
|
||||
double value = convert->toDouble(pvValue);
|
||||
double lowAlarmLimit = pvLowAlarmLimit->get();
|
||||
double lowWarningLimit = pvLowWarningLimit->get();
|
||||
double highWarningLimit = pvHighWarningLimit->get();
|
||||
double highAlarmLimit = pvHighAlarmLimit->get();
|
||||
double hysteresis = pvHysteresis->get();
|
||||
int alarmRange = range_Normal;
|
||||
if(highAlarmLimit>lowAlarmLimit) {
|
||||
if(value>=highAlarmLimit
|
||||
||(prevAlarmRange==range_Hihi && value>=highAlarmLimit-hysteresis)) {
|
||||
alarmRange = range_Hihi;
|
||||
} else if(value<=lowAlarmLimit
|
||||
||(prevAlarmRange==range_Lolo && value<=lowAlarmLimit+hysteresis)) {
|
||||
alarmRange = range_Lolo;
|
||||
}
|
||||
}
|
||||
if(alarmRange==range_Normal && (highWarningLimit>lowWarningLimit)) {
|
||||
if(value>=highWarningLimit
|
||||
||(prevAlarmRange==range_High && value>=highWarningLimit-hysteresis)) {
|
||||
alarmRange = range_High;
|
||||
} else if(value<=lowWarningLimit
|
||||
||(prevAlarmRange==range_Low && value<=lowWarningLimit+hysteresis)) {
|
||||
alarmRange = range_Low;
|
||||
}
|
||||
}
|
||||
bool retValue = false;
|
||||
if(alarmRange!=prevAlarmRange) {
|
||||
setAlarm(pvAlarm,alarmRange);
|
||||
retValue = true;
|
||||
}
|
||||
prevAlarmRange = alarmRange;
|
||||
currentValue = value;
|
||||
return retValue;
|
||||
}
|
||||
|
||||
void ScalarAlarmSupport::reset()
|
||||
{
|
||||
isHystersis = false;
|
||||
}
|
||||
|
||||
void ScalarAlarmSupport::setAlarm(
|
||||
epics::pvData::PVStructurePtr const & pva,
|
||||
int alarmRange)
|
||||
{
|
||||
Alarm alarm;
|
||||
PVAlarm pvAlarm;
|
||||
if(!pvAlarm.attach(pva)) throw std::logic_error("bad alarm field");
|
||||
epics::pvData::AlarmStatus status(epics::pvData::noStatus);
|
||||
epics::pvData::AlarmSeverity severity(epics::pvData::noAlarm);
|
||||
string message;
|
||||
switch (alarmRange) {
|
||||
case range_Lolo :
|
||||
{
|
||||
severity = epics::pvData::majorAlarm;
|
||||
status = epics::pvData::recordStatus;
|
||||
message = "major low alarm";
|
||||
break;
|
||||
}
|
||||
case range_Low :
|
||||
{
|
||||
severity = epics::pvData::minorAlarm;
|
||||
status = epics::pvData::recordStatus;
|
||||
message = "minor low alarm";
|
||||
break;
|
||||
}
|
||||
case range_Normal :
|
||||
{
|
||||
break;
|
||||
}
|
||||
case range_High :
|
||||
{
|
||||
severity = epics::pvData::minorAlarm;
|
||||
status = epics::pvData::recordStatus;
|
||||
message = "minor high alarm";
|
||||
break;
|
||||
}
|
||||
case range_Hihi :
|
||||
{
|
||||
severity = epics::pvData::majorAlarm;
|
||||
status = epics::pvData::recordStatus;
|
||||
message = "major high alarm";
|
||||
break;
|
||||
}
|
||||
case range_Invalid :
|
||||
{
|
||||
severity = epics::pvData::invalidAlarm;
|
||||
status = epics::pvData::recordStatus;
|
||||
message = "invalid alarm";
|
||||
break;
|
||||
}
|
||||
case range_Undefined :
|
||||
{
|
||||
severity = epics::pvData::undefinedAlarm;
|
||||
status = epics::pvData::recordStatus;
|
||||
message = "undefined alarm";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
severity = epics::pvData::undefinedAlarm;
|
||||
status = epics::pvData::recordStatus;
|
||||
message = "bad alarm definition";
|
||||
break;
|
||||
}
|
||||
}
|
||||
alarm.setStatus(status);
|
||||
alarm.setSeverity(severity);
|
||||
alarm.setMessage(message);
|
||||
pvAlarm.set(alarm);
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
@@ -5,28 +5,24 @@ include $(TOP)/configure/CONFIG
|
||||
|
||||
PVDATABASE_TEST = $(TOP)/test
|
||||
|
||||
PROD_LIBS += pvDatabase
|
||||
PROD_LIBS += $(EPICS_BASE_PVA_CORE_LIBS)
|
||||
PROD_LIBS += $(EPICS_BASE_IOC_LIBS)
|
||||
PROD_LIBS += pvDatabase pvAccess pvData Com
|
||||
|
||||
include $(PVDATABASE_TEST)/src/Makefile
|
||||
|
||||
# pvDatabaseAllTests runs all the test programs in a known working order.
|
||||
# The testHarness runs all the test programs in a known working order.
|
||||
testHarness_SRCS += pvDatabaseAllTests.c
|
||||
|
||||
# Name the application pvDbTestHarness
|
||||
pvDbTestHarness_SRCS = $(testHarness_SRCS)
|
||||
PROD_vxWorks = vxTestHarness
|
||||
vxTestHarness_SRCS += $(testHarness_SRCS)
|
||||
TESTSPEC_vxWorks = vxTestHarness.$(MUNCH_SUFFIX); pvDatabaseAllTests
|
||||
|
||||
# Build for vxWorks
|
||||
PROD_vxWorks = pvDbTestHarness
|
||||
TESTSPEC_vxWorks = pvDbTestHarness.$(MUNCH_SUFFIX); pvDatabaseAllTests
|
||||
PROD_RTEMS += rtemsTestHarness
|
||||
rtemsTestHarness_SRCS += rtemsTestHarness.c rtemsConfig.c
|
||||
rtemsTestHarness_SRCS += $(testHarness_SRCS)
|
||||
TESTSPEC_RTEMS = rtemsTestHarness.$(MUNCH_SUFFIX); pvDatabaseAllTests
|
||||
|
||||
# Build for RTEMS, with harness code & configuration
|
||||
PROD_RTEMS += pvDbTestHarness
|
||||
pvDbTestHarness_SRCS_RTEMS += rtemsTestHarness.c
|
||||
TESTSPEC_RTEMS = pvDbTestHarness.$(MUNCH_SUFFIX); pvDatabaseAllTests
|
||||
|
||||
# Build test scripts for hosts
|
||||
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
|
||||
|
||||
|
||||
@@ -8,12 +8,10 @@
|
||||
#include <stdio.h>
|
||||
#include <epicsThread.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <epicsExit.h>
|
||||
|
||||
/* src */
|
||||
int testExampleRecord(void);
|
||||
int testPVCopy(void);
|
||||
int testPlugin(void);
|
||||
int testPVRecord(void);
|
||||
int testLocalProvider(void);
|
||||
int testPVAServer(void);
|
||||
@@ -25,10 +23,8 @@ void pvDatabaseAllTests(void)
|
||||
/* src */
|
||||
runTest(testExampleRecord);
|
||||
runTest(testPVCopy);
|
||||
runTest(testPlugin);
|
||||
runTest(testPVRecord);
|
||||
runTest(testLocalProvider);
|
||||
runTest(testPVAServer);
|
||||
|
||||
epicsExit(0); /* Trigger test harness */
|
||||
}
|
||||
|
||||
|
||||
72
test/rtemsConfig.c
Normal file
72
test/rtemsConfig.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/*************************************************************************\
|
||||
* Copyright (c) 2002 The University of Saskatchewan
|
||||
* EPICS BASE Versions 3.13.7
|
||||
* and higher are distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
/*
|
||||
* RTEMS configuration for EPICS
|
||||
* Revision-Id: anj@aps.anl.gov-20101005192737-disfz3vs0f3fiixd
|
||||
* Author: W. Eric Norum
|
||||
* norume@aps.anl.gov
|
||||
* (630) 252-4793
|
||||
*/
|
||||
|
||||
#include <rtems.h>
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* RTEMS CONFIGURATION *
|
||||
***********************************************************************
|
||||
*/
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#if __RTEMS_MAJOR__>4 || (__RTEMS_MAJOR__==4 && __RTEMS_MINOR__>9) || (__RTEMS_MAJOR__==4 && __RTEMS_MINOR__==9 && __RTEMS_REVISION__==99)
|
||||
# define CONFIGURE_UNIFIED_WORK_AREAS
|
||||
#else
|
||||
# define CONFIGURE_EXECUTIVE_RAM_SIZE (2000*1024)
|
||||
#endif
|
||||
|
||||
#define CONFIGURE_MAXIMUM_TASKS rtems_resource_unlimited(30)
|
||||
#define CONFIGURE_MAXIMUM_SEMAPHORES rtems_resource_unlimited(500)
|
||||
#define CONFIGURE_MAXIMUM_TIMERS rtems_resource_unlimited(20)
|
||||
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES rtems_resource_unlimited(5)
|
||||
#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
|
||||
|
||||
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 150
|
||||
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
|
||||
#define CONFIGURE_MAXIMUM_DRIVERS 8
|
||||
|
||||
#define CONFIGURE_MICROSECONDS_PER_TICK 20000
|
||||
|
||||
#define CONFIGURE_INIT_TASK_PRIORITY 80
|
||||
|
||||
#define CONFIGURE_MALLOC_STATISTICS 1
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
|
||||
RTEMS_NO_TIMESLICE | \
|
||||
RTEMS_NO_ASR | \
|
||||
RTEMS_INTERRUPT_LEVEL(0))
|
||||
#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_FLOATING_POINT | RTEMS_LOCAL)
|
||||
#define CONFIGURE_INIT_TASK_STACK_SIZE (16*1024)
|
||||
rtems_task Init (rtems_task_argument argument);
|
||||
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
|
||||
|
||||
#define CONFIGURE_FILESYSTEM_NFS
|
||||
#define CONFIGURE_FILESYSTEM_IMFS
|
||||
|
||||
/*
|
||||
* This should be made BSP dependent, not CPU dependent but I know of no
|
||||
* appropriate conditionals to use.
|
||||
* The new general time support makes including the RTC driver less important.
|
||||
*/
|
||||
#if !defined(mpc604) && !defined(__mc68040__) && !defined(__mcf5200__) && !defined(mpc7455) && !defined(__arm__) /* don't have RTC code */
|
||||
#define CONFIGURE_APPLICATION_NEEDS_RTC_DRIVER
|
||||
#endif
|
||||
|
||||
|
||||
#include <bsp.h>
|
||||
#include <rtems/confdefs.h>
|
||||
294
test/rtemsNetworking.h
Normal file
294
test/rtemsNetworking.h
Normal file
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Network configuration -- QEMU NOT using DHCP
|
||||
*
|
||||
************************************************************
|
||||
* EDIT THIS FILE TO REFLECT YOUR NETWORK CONFIGURATION *
|
||||
* BEFORE RUNNING ANY RTEMS PROGRAMS WHICH USE THE NETWORK! *
|
||||
************************************************************
|
||||
*
|
||||
* The dynamic probing is based upon the EPICS network
|
||||
* configuration file written by:
|
||||
* W. Eric Norum
|
||||
* eric.norum@usask.ca
|
||||
* (306) 966-5394
|
||||
*/
|
||||
|
||||
#ifndef _RTEMS_NETWORKCONFIG_H_
|
||||
#define _RTEMS_NETWORKCONFIG_H_
|
||||
|
||||
/* #define USE_LIBBSDPORT */
|
||||
|
||||
#if defined(USE_LIBBSDPORT)
|
||||
#include <bsp/libbsdport_api.h>
|
||||
#define CONFIGURE_MAXIMUM_TIMERS 10
|
||||
#endif
|
||||
/*
|
||||
* For TFTP test application
|
||||
*/
|
||||
#if (defined (RTEMS_USE_BOOTP))
|
||||
#define RTEMS_TFTP_TEST_HOST_NAME "BOOTP_HOST"
|
||||
#define RTEMS_TFTP_TEST_FILE_NAME "BOOTP_FILE"
|
||||
#else
|
||||
#define RTEMS_TFTP_TEST_HOST_NAME "XXX.YYY.ZZZ.XYZ"
|
||||
#define RTEMS_TFTP_TEST_FILE_NAME "tftptest"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* For NFS test application
|
||||
*
|
||||
* NFS mount and a directory to ls once mounted
|
||||
*/
|
||||
#define RTEMS_NFS_SERVER "192.168.1.210"
|
||||
#define RTEMS_NFS_SERVER_PATH "/home"
|
||||
#define RTEMS_NFS_LS_PATH "/mnt/nfstest"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* This file can be copied to an application source directory
|
||||
* and modified to override the values shown below.
|
||||
*
|
||||
* The following CPP symbols may be passed from the Makefile:
|
||||
*
|
||||
* symbol default description
|
||||
*
|
||||
* NETWORK_TASK_PRIORITY 150 can be read by app from public
|
||||
* var 'gesysNetworkTaskPriority'
|
||||
* FIXED_IP_ADDR <undefined> hardcoded IP address (e.g.,
|
||||
* "192.168.0.10"); disables BOOTP;
|
||||
* must also define FIXED_NETMASK
|
||||
* FIXED_NETMASK <undefined> IP netmask string
|
||||
* (e.g. "255.255.255.0")
|
||||
* MULTI_NETDRIVER <undefined> ugly hack; if defined try to probe
|
||||
* a variety of PCI and ISA drivers
|
||||
* (i386 ONLY) use is discouraged!
|
||||
* NIC_NAME <undefined> Ethernet driver name (e.g. "pcn1");
|
||||
* must also define NIC_ATTACH
|
||||
* NIC_ATTACH <undefined> Ethernet driver attach function
|
||||
* (e.g., rtems_fxp_attach).
|
||||
* If these are undefined then
|
||||
* a) MULTI_NETDRIVER is used
|
||||
* (if defined)
|
||||
* b) RTEMS_BSP_NETWORK_DRIVER_NAME/
|
||||
* RTEMS_BSP_NETWORK_DRIVER_ATTACH
|
||||
* are tried
|
||||
* MEMORY_CUSTOM <undefined> Allocate the defined amount of
|
||||
* memory for mbufs and mbuf clusters,
|
||||
* respectively. Define to a comma ','
|
||||
* separated pair of two numerical
|
||||
* values, e.g: 100*1024,200*1024
|
||||
* MEMORY_SCARCE <undefined> Allocate few memory for mbufs
|
||||
* (hint for how much memory the
|
||||
* board has)
|
||||
* MEMORY_HUGE <undefined> Allocate a lot of memory for mbufs
|
||||
* (hint for how much memory the
|
||||
* board has)
|
||||
* If none of MEMORY_CUSTOM/
|
||||
* MEMORY_SCARCE/MEMORY_HUGE are
|
||||
* defined then a medium amount of
|
||||
* memory is allocated for mbufs.
|
||||
*/
|
||||
|
||||
#include <rtems/bspIo.h>
|
||||
#include <bsp.h>
|
||||
#include <rtems/rtems_bsdnet.h>
|
||||
|
||||
#if 0
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#else
|
||||
#include "verscheck.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//#define MULTI_NETDRIVER
|
||||
//#define RTEMS_BSP_NETWORK_DRIVER_NAME 1
|
||||
|
||||
#define FIXED_IP_ADDR "192.168.1.249"
|
||||
#define FIXED_NETMASK "255.255.255.0"
|
||||
|
||||
#ifndef NETWORK_TASK_PRIORITY
|
||||
#define NETWORK_TASK_PRIORITY 150 /* within EPICS' range */
|
||||
#endif
|
||||
|
||||
/* make publicly available for startup scripts... */
|
||||
const int gesysNetworkTaskPriority = NETWORK_TASK_PRIORITY;
|
||||
|
||||
#ifdef FIXED_IP_ADDR
|
||||
#define RTEMS_DO_BOOTP 0
|
||||
#else
|
||||
#define RTEMS_DO_BOOTP rtems_bsdnet_do_bootp
|
||||
#define FIXED_IP_ADDR 0
|
||||
#undef FIXED_NETMASK
|
||||
#define FIXED_NETMASK 0
|
||||
#endif
|
||||
|
||||
#if !defined(NIC_NAME)
|
||||
|
||||
#ifdef MULTI_NETDRIVER
|
||||
|
||||
#if 0
|
||||
#if RTEMS_VERSION_ATLEAST(4,6,99)
|
||||
#define pcib_init pci_initialize
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern int rtems_3c509_driver_attach (struct rtems_bsdnet_ifconfig *, int);
|
||||
extern int rtems_fxp_attach (struct rtems_bsdnet_ifconfig *, int);
|
||||
extern int rtems_elnk_driver_attach (struct rtems_bsdnet_ifconfig *, int);
|
||||
extern int rtems_dec21140_driver_attach (struct rtems_bsdnet_ifconfig *, int);
|
||||
|
||||
/* these don't probe and will be used even if there's no device :-( */
|
||||
extern int rtems_ne_driver_attach (struct rtems_bsdnet_ifconfig *, int);
|
||||
extern int rtems_wd_driver_attach (struct rtems_bsdnet_ifconfig *, int);
|
||||
|
||||
static struct rtems_bsdnet_ifconfig isa_netdriver_config[] = {
|
||||
{
|
||||
"ep0", rtems_3c509_driver_attach, isa_netdriver_config + 1,
|
||||
},
|
||||
{
|
||||
"ne1", rtems_ne_driver_attach, 0, irno: 9 /* qemu cannot configure irq-no :-(; has it hardwired to 9 */
|
||||
},
|
||||
};
|
||||
|
||||
static struct rtems_bsdnet_ifconfig pci_netdriver_config[]={
|
||||
{
|
||||
"dc1", rtems_dec21140_driver_attach, pci_netdriver_config+1,
|
||||
},
|
||||
#if !defined(USE_LIBBSDPORT)
|
||||
{
|
||||
"fxp1", rtems_fxp_attach, pci_netdriver_config+2,
|
||||
},
|
||||
#else
|
||||
{
|
||||
"", libbsdport_netdriver_attach, pci_netdriver_config+2,
|
||||
},
|
||||
#endif
|
||||
{
|
||||
"elnk1", rtems_elnk_driver_attach, isa_netdriver_config,
|
||||
},
|
||||
};
|
||||
|
||||
static int pci_check(struct rtems_bsdnet_ifconfig *ocfg, int attaching)
|
||||
{
|
||||
struct rtems_bsdnet_ifconfig *cfg;
|
||||
int if_index_pre;
|
||||
extern int if_index;
|
||||
if ( attaching ) {
|
||||
cfg = pci_initialize() ?
|
||||
isa_netdriver_config : pci_netdriver_config;
|
||||
}
|
||||
while ( cfg ) {
|
||||
printk("Probing '%s'", cfg->name);
|
||||
/* unfortunately, the return value is unreliable - some drivers report
|
||||
* success even if they fail.
|
||||
* Check if they chained an interface (ifnet) structure instead
|
||||
*/
|
||||
if_index_pre = if_index;
|
||||
cfg->attach(cfg, attaching);
|
||||
if ( if_index > if_index_pre ) {
|
||||
/* assume success */
|
||||
printk(" .. seemed to work\n");
|
||||
ocfg->name = cfg->name;
|
||||
ocfg->attach = cfg->attach;
|
||||
return 0;
|
||||
}
|
||||
printk(" .. failed\n");
|
||||
cfg = cfg->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#define NIC_NAME "dummy"
|
||||
#define NIC_ATTACH pci_check
|
||||
|
||||
#else
|
||||
|
||||
#if defined(RTEMS_BSP_NETWORK_DRIVER_NAME) /* Use NIC provided by BSP */
|
||||
|
||||
/* force ne2k_isa on i386 for qemu */
|
||||
#if defined(__i386__)
|
||||
# define NIC_NAME BSP_NE2000_NETWORK_DRIVER_NAME
|
||||
# define NIC_ATTACH BSP_NE2000_NETWORK_DRIVER_ATTACH
|
||||
|
||||
#else
|
||||
|
||||
# define NIC_NAME RTEMS_BSP_NETWORK_DRIVER_NAME
|
||||
# define NIC_ATTACH RTEMS_BSP_NETWORK_DRIVER_ATTACH
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* ifdef MULTI_NETDRIVER */
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef NIC_NAME
|
||||
|
||||
extern int NIC_ATTACH();
|
||||
|
||||
#if RTEMS_BSP_NETWORK_DRIVER_ATTACH == BSP_NE2000_NETWORK_DRIVER_ATTACH
|
||||
static char ethernet_address[6] = { 0x00, 0xab, 0xcd, 0xef, 0x12, 0x34 };
|
||||
#endif
|
||||
|
||||
static struct rtems_bsdnet_ifconfig netdriver_config[1] = {{
|
||||
NIC_NAME, /* name */
|
||||
(int (*)(struct rtems_bsdnet_ifconfig*,int))NIC_ATTACH, /* attach function */
|
||||
0, /* link to next interface */
|
||||
FIXED_IP_ADDR,
|
||||
FIXED_NETMASK
|
||||
#if RTEMS_BSP_NETWORK_DRIVER_ATTACH == BSP_NE2000_NETWORK_DRIVER_ATTACH
|
||||
,
|
||||
ethernet_address,
|
||||
irno:9,
|
||||
port:0xc100
|
||||
#endif
|
||||
}};
|
||||
#else
|
||||
#warning "NO KNOWN NETWORK DRIVER FOR THIS BSP -- YOU MAY HAVE TO EDIT networkconfig.h"
|
||||
#endif
|
||||
|
||||
struct rtems_bsdnet_config rtems_bsdnet_config = {
|
||||
#ifdef NIC_NAME
|
||||
netdriver_config, /* link to next interface */
|
||||
RTEMS_DO_BOOTP, /* Use BOOTP to get network configuration */
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
NETWORK_TASK_PRIORITY, /* Network task priority */
|
||||
#if defined(MEMORY_CUSTOM)
|
||||
MEMORY_CUSTOM,
|
||||
#elif defined(MEMORY_SCARCE)
|
||||
100*1024, /* MBUF space */
|
||||
200*1024, /* MBUF cluster space */
|
||||
#elif defined(MEMORY_HUGE)
|
||||
2*1024*1024, /* MBUF space */
|
||||
5*1024*1024, /* MBUF cluster space */
|
||||
#else
|
||||
180*1024, /* MBUF space */
|
||||
350*1024, /* MBUF cluster space */
|
||||
#endif
|
||||
#if (!defined (RTEMS_USE_BOOTP)) && defined(ON_RTEMS_LAB_WINSYSTEMS)
|
||||
"rtems", /* Host name */
|
||||
"nodomain.com", /* Domain name */
|
||||
"192.168.1.14", /* Gateway */
|
||||
"192.168.1.1", /* Log host */
|
||||
{"89.212.75.6" }, /* Name server(s) */
|
||||
{"192.168.1.1" }, /* NTP server(s) */
|
||||
#else
|
||||
NULL, /* Host name */
|
||||
NULL, /* Domain name */
|
||||
NULL, /* Gateway */
|
||||
NULL, /* Log host */
|
||||
{ NULL }, /* Name server(s) */
|
||||
{ NULL }, /* NTP server(s) */
|
||||
#endif /* !RTEMS_USE_BOOTP */
|
||||
0, /* efficiency */
|
||||
0, /* udp TX buffer */
|
||||
0, /* udp RX buffer */
|
||||
0, /* tcp TX buffer */
|
||||
0, /* tcp RX buffer */
|
||||
};
|
||||
#endif /* _RTEMS_NETWORKCONFIG_H_ */
|
||||
@@ -1,12 +1,38 @@
|
||||
/*
|
||||
* Copyright information and license terms for this software can be
|
||||
* found in the file LICENSE that is included with the distribution
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <rtems/rtems_bsdnet.h>
|
||||
#include <rtems/error.h>
|
||||
|
||||
#include "rtemsNetworking.h"
|
||||
|
||||
#include <epicsExit.h>
|
||||
#include <osdTime.h>
|
||||
|
||||
extern void pvDatabaseAllTests(void);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
rtems_task
|
||||
Init (rtems_task_argument ignored)
|
||||
{
|
||||
rtems_bsdnet_initialize_network ();
|
||||
//rtems_bsdnet_show_if_stats ();
|
||||
|
||||
rtems_time_of_day timeOfDay;
|
||||
if (rtems_clock_get(RTEMS_CLOCK_GET_TOD,&timeOfDay) != RTEMS_SUCCESSFUL) {
|
||||
timeOfDay.year = 2014;
|
||||
timeOfDay.month = 1;
|
||||
timeOfDay.day = 1;
|
||||
timeOfDay.hour = 0;
|
||||
timeOfDay.minute = 0;
|
||||
timeOfDay.second = 0;
|
||||
timeOfDay.ticks = 0;
|
||||
|
||||
rtems_status_code ret = rtems_clock_set(&timeOfDay);
|
||||
if (ret != RTEMS_SUCCESSFUL) {
|
||||
printf("**** Can't set time %s\n", rtems_status_text(ret));
|
||||
}
|
||||
}
|
||||
osdTimeRegister();
|
||||
|
||||
pvDatabaseAllTests();
|
||||
return 0;
|
||||
epicsExit(0);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,6 @@
|
||||
|
||||
SRC_DIRS += $(PVDATABASE_TEST)/src
|
||||
|
||||
|
||||
TESTPROD_HOST += testPlugin
|
||||
testPlugin_SRCS += testPlugin.cpp
|
||||
testHarness_SRCS += testPlugin.cpp
|
||||
TESTS += testPlugin
|
||||
|
||||
TESTPROD_HOST += testPVCopy
|
||||
testPVCopy_SRCS += testPVCopy.cpp
|
||||
testHarness_SRCS += testPVCopy.cpp
|
||||
@@ -29,6 +23,7 @@ testLocalProvider_SRCS += testLocalProvider.cpp
|
||||
testHarness_SRCS += testLocalProvider.cpp
|
||||
TESTS += testLocalProvider
|
||||
|
||||
|
||||
TESTPROD_HOST += testPVAServer
|
||||
testPVAServer_SRCS += testPVAServer.cpp
|
||||
testHarness_SRCS += testPVAServer.cpp
|
||||
|
||||
@@ -22,18 +22,17 @@
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/pvAlarm.h>
|
||||
#include <pv/pvDatabase.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
|
||||
#ifdef listenerEpicsExportSharedSymbols
|
||||
# define epicsExportSharedSymbols
|
||||
# undef listenerEpicsExportSharedSymbols
|
||||
# undef listenerEpicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
//epicsShareFunc epics::pvData::PVStructurePtr createListener();
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
namespace epics { namespace pvDatabase {
|
||||
using namespace epics::pvData;
|
||||
using namespace std;
|
||||
|
||||
@@ -59,7 +58,7 @@ public:
|
||||
}
|
||||
virtual void dataPut(PVRecordFieldPtr const & pvRecordField)
|
||||
{
|
||||
cout << "Listener::dataPut record " << recordName
|
||||
cout << "Listener::dataPut record " << recordName
|
||||
<< " pvRecordField " << pvRecordField->getPVField()->getFullName()
|
||||
<< endl;
|
||||
}
|
||||
@@ -67,7 +66,7 @@ public:
|
||||
PVRecordStructurePtr const & requested,
|
||||
PVRecordFieldPtr const & pvRecordField)
|
||||
{
|
||||
cout << "Listener::dataPut record " << recordName
|
||||
cout << "Listener::dataPut record " << recordName
|
||||
<< " requested " << requested->getPVStructure()->getFullName()
|
||||
<< " pvRecordField " << pvRecordField->getPVField()->getFullName()
|
||||
<< endl;
|
||||
@@ -84,11 +83,11 @@ public:
|
||||
{
|
||||
cout << "Listener::unlisten record " << recordName << endl;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Listener(PVRecordPtr const & pvRecord)
|
||||
: pvCopy(
|
||||
epics::pvCopy::PVCopy::create(
|
||||
PVCopy::create(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
pvRecord->getPVRecordStructure()->getPVStructure()),
|
||||
CreateRequest::create()->createRequest(""),
|
||||
@@ -97,7 +96,7 @@ private:
|
||||
recordName(pvRecord->getRecordName())
|
||||
{
|
||||
}
|
||||
epics::pvCopy::PVCopyPtr pvCopy;
|
||||
PVCopyPtr pvCopy;
|
||||
PVStructurePtr pvStructure;
|
||||
string recordName;
|
||||
};
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
|
||||
#ifdef powerSupplyEpicsExportSharedSymbols
|
||||
# define epicsExportSharedSymbols
|
||||
# undef powerSupplyEpicsExportSharedSymbols
|
||||
# undef powerSupplyEpicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
//epicsShareFunc epics::pvData::PVStructurePtr createPowerSupply();
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class PowerSupply;
|
||||
typedef std::tr1::shared_ptr<PowerSupply> PowerSupplyPtr;
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
std::string const & recordName,
|
||||
epics::pvData::PVStructurePtr const & pvStructure);
|
||||
virtual ~PowerSupply();
|
||||
virtual void destroy();
|
||||
virtual bool init();
|
||||
virtual void process();
|
||||
void put(double power,double voltage);
|
||||
@@ -110,6 +111,11 @@ inline PowerSupply::~PowerSupply()
|
||||
{
|
||||
}
|
||||
|
||||
inline void PowerSupply::destroy()
|
||||
{
|
||||
PVRecord::destroy();
|
||||
}
|
||||
|
||||
inline bool PowerSupply::init()
|
||||
{
|
||||
initPVRecord();
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
|
||||
#ifdef pvRecordClientEpicsExportSharedSymbols
|
||||
# define epicsExportSharedSymbols
|
||||
# undef pvRecordClientEpicsExportSharedSymbols
|
||||
# undef pvRecordClientEpicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <shareLib.h>
|
||||
|
||||
namespace epics { namespace pvDatabase {
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
class RecordClient;
|
||||
typedef std::tr1::shared_ptr<RecordClient> RecordClientPtr;
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
std::cout << "RecordClient::detach record " << pvRecord->getRecordName() << std::endl;
|
||||
this->pvRecord.reset();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
RecordClient(PVRecordPtr const & pvRecord)
|
||||
: pvRecord(pvRecord)
|
||||
|
||||
@@ -68,6 +68,7 @@ static void test()
|
||||
exampleRecord->unlock();
|
||||
}
|
||||
if(debug) {cout << "processed exampleDouble " << endl; }
|
||||
exampleRecord->destroy();
|
||||
recordName = "powerSupplyExample";
|
||||
PowerSupplyPtr psr;
|
||||
pvStructure = createPowerSupply();
|
||||
@@ -126,6 +127,7 @@ static void test()
|
||||
testOk1(psr->getVoltage()==1.0);
|
||||
testOk1(psr->getPower()==1.0);
|
||||
testOk1(psr->getCurrent()==1.0);
|
||||
psr->destroy();
|
||||
}
|
||||
|
||||
MAIN(testExampleRecord)
|
||||
@@ -134,3 +136,4 @@ MAIN(testExampleRecord)
|
||||
test();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ static void test()
|
||||
pvRecord->unlock();
|
||||
}
|
||||
if(debug) {cout << "processed exampleDouble " << endl; }
|
||||
channelProvider->destroy();
|
||||
}
|
||||
|
||||
MAIN(testLocalProvider)
|
||||
@@ -79,3 +80,4 @@ MAIN(testLocalProvider)
|
||||
test();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ static void test()
|
||||
ServerContext::shared_pointer ctx =
|
||||
startPVAServer("local",0,true,true);
|
||||
testOk1(ctx.get()!=0);
|
||||
ctx->destroy();
|
||||
}
|
||||
|
||||
MAIN(testPVAServer)
|
||||
@@ -75,3 +76,4 @@ MAIN(testPVAServer)
|
||||
test();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ using namespace std;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvCopy;
|
||||
using namespace epics::pvDatabase;
|
||||
|
||||
static bool debug = false;
|
||||
@@ -273,34 +272,7 @@ static void testPVScalarArray(
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void testMasterField(PVRecordPtr const& pvRecord)
|
||||
{
|
||||
CreateRequest::shared_pointer createRequest = CreateRequest::create();
|
||||
PVStructurePtr pvRequest = createRequest->createRequest("field(_)");
|
||||
if(debug) {
|
||||
cout << "pvRequest" << *pvRequest << endl ;
|
||||
}
|
||||
PVStructurePtr pvStructureRecord = pvRecord->getPVRecordStructure()->getPVStructure();
|
||||
PVCopyPtr pvCopy = PVCopy::create(pvStructureRecord,pvRequest,"");
|
||||
PVStructurePtr pvMasterField = pvCopy->getPVMaster();
|
||||
if(debug) {
|
||||
cout << "PV structure from record" << endl << *pvStructureRecord << endl;
|
||||
cout << "Master PV structure from copy" << endl << *pvMasterField << endl;
|
||||
cout << "Master PV structure from copy offset " << pvMasterField->getFieldOffset() << endl;
|
||||
}
|
||||
testOk1(pvMasterField->getNumberFields() == pvStructureRecord->getNumberFields());
|
||||
testOk1(pvMasterField->getFieldOffset() == 0);
|
||||
PVStructurePtr pvStructureCopy = pvCopy->createPVStructure();
|
||||
BitSetPtr bitSet = BitSetPtr(new BitSet(pvStructureCopy->getNumberFields()));
|
||||
pvCopy->initCopy(pvStructureCopy, bitSet);
|
||||
if(debug) {
|
||||
cout << "PV structure from copy" << endl << *pvStructureCopy << endl;
|
||||
cout << "PV structure from copy offset " << pvStructureCopy->getFieldOffset() << endl;
|
||||
}
|
||||
testOk1(pvMasterField->getNumberFields() == pvStructureCopy->getNumberFields());
|
||||
}
|
||||
|
||||
|
||||
static void scalarTest()
|
||||
{
|
||||
if(debug) {cout << endl << endl << "****scalarTest****" << endl;}
|
||||
@@ -309,6 +281,7 @@ static void scalarTest()
|
||||
string request;
|
||||
PVStructurePtr pvRequest;
|
||||
PVCopyPtr pvCopy;
|
||||
string builder;
|
||||
string valueNameRecord;
|
||||
string valueNameCopy;
|
||||
|
||||
@@ -340,6 +313,7 @@ static void scalarTest()
|
||||
pvCopy = PVCopy::create(pvRecord->getPVRecordStructure()->getPVStructure(),pvRequest,"");
|
||||
valueNameCopy = "value";
|
||||
testPVScalar(valueNameRecord,valueNameCopy,pvRecord,pvCopy);
|
||||
pvRecord->destroy();
|
||||
}
|
||||
|
||||
static void arrayTest()
|
||||
@@ -350,6 +324,7 @@ static void arrayTest()
|
||||
string request;
|
||||
PVStructurePtr pvRequest;
|
||||
PVCopyPtr pvCopy;
|
||||
string builder;
|
||||
string valueNameRecord;
|
||||
string valueNameCopy;
|
||||
|
||||
@@ -375,6 +350,7 @@ static void arrayTest()
|
||||
pvCopy = PVCopy::create(pvRecord->getPVRecordStructure()->getPVStructure(),pvRequest,"");
|
||||
valueNameCopy = "value";
|
||||
testPVScalarArray(valueNameRecord,valueNameCopy,pvRecord,pvCopy);
|
||||
pvRecord->destroy();
|
||||
}
|
||||
|
||||
static void powerSupplyTest()
|
||||
@@ -385,6 +361,7 @@ static void powerSupplyTest()
|
||||
string request;
|
||||
PVStructurePtr pvRequest;
|
||||
PVCopyPtr pvCopy;
|
||||
string builder;
|
||||
string valueNameRecord;
|
||||
string valueNameCopy;
|
||||
|
||||
@@ -418,23 +395,15 @@ static void powerSupplyTest()
|
||||
pvCopy = PVCopy::create(pvRecord->getPVRecordStructure()->getPVStructure(),pvRequest,"");
|
||||
valueNameCopy = "power.value";
|
||||
testPVScalar(valueNameRecord,valueNameCopy,pvRecord,pvCopy);
|
||||
}
|
||||
|
||||
static void masterFieldTest()
|
||||
{
|
||||
if(debug) {
|
||||
cout << endl << endl << "****masterFieldTest****" << endl;
|
||||
}
|
||||
PVRecordPtr pvRecord = createScalar("doubleRecord",pvDouble,"alarm,timeStamp,display");
|
||||
testMasterField(pvRecord);
|
||||
pvRecord->destroy();
|
||||
}
|
||||
|
||||
MAIN(testPVCopy)
|
||||
{
|
||||
testPlan(70);
|
||||
testPlan(67);
|
||||
scalarTest();
|
||||
arrayTest();
|
||||
powerSupplyTest();
|
||||
masterFieldTest();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
#include <pv/pvCopy.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "powerSupply.h"
|
||||
|
||||
@@ -37,7 +37,6 @@ using namespace std;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvDatabase;
|
||||
using namespace epics::pvCopy;
|
||||
using std::string;
|
||||
|
||||
static bool debug = false;
|
||||
@@ -70,6 +69,7 @@ static void scalarTest()
|
||||
if(pvRecord && debug) {
|
||||
cout << pvRecord << endl;
|
||||
}
|
||||
pvRecord->destroy();
|
||||
}
|
||||
|
||||
static void arrayTest()
|
||||
@@ -81,6 +81,7 @@ static void arrayTest()
|
||||
if(pvRecord && debug) {
|
||||
cout << pvRecord << endl;
|
||||
}
|
||||
pvRecord->destroy();
|
||||
}
|
||||
|
||||
static void powerSupplyTest()
|
||||
@@ -93,6 +94,7 @@ static void powerSupplyTest()
|
||||
if(pvRecord && debug) {
|
||||
cout << pvRecord << endl;
|
||||
}
|
||||
pvRecord->destroy();
|
||||
}
|
||||
|
||||
MAIN(testPVRecord)
|
||||
@@ -103,3 +105,4 @@ MAIN(testPVRecord)
|
||||
powerSupplyTest();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,459 +0,0 @@
|
||||
/*testPluginMain.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 <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
#include <epicsStdio.h>
|
||||
#include <epicsMutex.h>
|
||||
#include <epicsEvent.h>
|
||||
#include <epicsThread.h>
|
||||
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
#include <pv/channelProviderLocal.h>
|
||||
#include <pv/convert.h>
|
||||
#include <pv/pvStructureCopy.h>
|
||||
#include <pv/pvDatabase.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include "powerSupply.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvCopy;
|
||||
using namespace epics::pvDatabase;
|
||||
|
||||
static bool debug = true;
|
||||
|
||||
static void deadbandTest()
|
||||
{
|
||||
if(debug) {cout << endl << endl << "****deadbandTest****" << endl;}
|
||||
bool result = false;
|
||||
uint32 nset = 0;
|
||||
|
||||
PVStructurePtr pvRecordStructure(getStandardPVField()->scalar(pvDouble,""));
|
||||
PVRecordPtr pvRecord(PVRecord::create("doubleRecord",pvRecordStructure));
|
||||
PVStructurePtr pvRequest(CreateRequest::create()->createRequest("value[deadband=abs:1.0]"));
|
||||
PVCopyPtr pvCopy(PVCopy::create(pvRecordStructure,pvRequest,""));
|
||||
PVStructurePtr pvStructureCopy(pvCopy->createPVStructure());
|
||||
BitSetPtr bitSet(new BitSet(pvStructureCopy->getNumberFields()));
|
||||
PVDoublePtr pvValue(pvRecordStructure->getSubField<PVDouble>("value"));
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "initial"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< " pvRecordStructure\n" << pvRecordStructure
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==true);
|
||||
testOk1(nset==1);
|
||||
pvValue->put(.1);
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "after pvValue"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< " pvRecordStructure\n" << pvRecordStructure
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==false);
|
||||
testOk1(nset==0);
|
||||
pvValue->put(1.0);
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "after pvValue"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< " pvRecordStructure\n" << pvRecordStructure
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==true);
|
||||
testOk1(nset==1);
|
||||
}
|
||||
|
||||
static void arrayTest()
|
||||
{
|
||||
if(debug) {cout << endl << endl << "****arrayTest****" << endl;}
|
||||
bool result = false;
|
||||
uint32 nset = 0;
|
||||
size_t n = 10;
|
||||
shared_vector<double> values(n);
|
||||
|
||||
PVStructurePtr pvRecordStructure(getStandardPVField()->scalarArray(pvDouble,""));
|
||||
PVRecordPtr pvRecord(PVRecord::create("doubleArrayRecord",pvRecordStructure));
|
||||
PVStructurePtr pvRequest(CreateRequest::create()->createRequest("value[array=1:3]"));
|
||||
PVCopyPtr pvCopy(PVCopy::create(pvRecordStructure,pvRequest,""));
|
||||
PVStructurePtr pvStructureCopy(pvCopy->createPVStructure());
|
||||
BitSetPtr bitSet(new BitSet(pvStructureCopy->getNumberFields()));
|
||||
PVDoubleArrayPtr pvValue(pvRecordStructure->getSubField<PVDoubleArray>("value"));
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "initial"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==false);
|
||||
testOk1(nset==0);
|
||||
for(size_t i=0; i<n; i++) values[i] = i + .06;
|
||||
const shared_vector<const double> yyy(freeze(values));
|
||||
pvValue->putFrom(yyy);
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "after pvValue"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< " pvRecordStructure\n" << pvRecordStructure
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==true);
|
||||
testOk1(nset==1);
|
||||
}
|
||||
|
||||
static void unionArrayTest()
|
||||
{
|
||||
if(debug) {cout << endl << endl << "****unionArrayTest****" << endl;}
|
||||
bool result = false;
|
||||
uint32 nset = 0;
|
||||
size_t n = 10;
|
||||
shared_vector<double> values(n);
|
||||
for(size_t i=0; i<n; i++) values[i] = i + .06;
|
||||
PVDoubleArrayPtr pvDoubleArray =
|
||||
static_pointer_cast<PVDoubleArray>(PVDataCreate::getPVDataCreate()->createPVScalarArray(pvDouble));
|
||||
const shared_vector<const double> yyy(freeze(values));
|
||||
pvDoubleArray->putFrom(yyy);
|
||||
|
||||
StandardFieldPtr standardField = getStandardField();
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
StructureConstPtr top = fieldCreate->createFieldBuilder()->
|
||||
add("value",fieldCreate->createVariantUnion()) ->
|
||||
add("timeStamp", standardField->timeStamp()) ->
|
||||
addNestedStructure("subfield") ->
|
||||
add("value",fieldCreate->createVariantUnion()) ->
|
||||
endNested()->
|
||||
createStructure();
|
||||
PVStructurePtr pvRecordStructure(PVDataCreate::getPVDataCreate()->createPVStructure(top));
|
||||
PVRecordPtr pvRecord(PVRecord::create("unionArrayRecord",pvRecordStructure));
|
||||
PVUnionPtr pvUnion = pvRecord->getPVStructure()->getSubField<PVUnion>("value");
|
||||
pvUnion->set(pvDoubleArray);
|
||||
pvUnion = pvRecord->getPVStructure()->getSubField<PVUnion>("subfield.value");
|
||||
pvUnion->set(pvDoubleArray);
|
||||
if(debug) { cout << "initial\n" << pvRecordStructure << "\n";}
|
||||
|
||||
PVStructurePtr pvRequest(CreateRequest::create()->createRequest("value[array=1:3]"));
|
||||
PVCopyPtr pvCopy(PVCopy::create(pvRecordStructure,pvRequest,""));
|
||||
PVStructurePtr pvStructureCopy(pvCopy->createPVStructure());
|
||||
BitSetPtr bitSet(new BitSet(pvStructureCopy->getNumberFields()));
|
||||
PVDoubleArrayPtr pvValue(pvRecordStructure->getSubField<PVDoubleArray>("value"));
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "after get value"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==true);
|
||||
testOk1(nset==1);
|
||||
|
||||
pvRequest = CreateRequest::create()->createRequest("subfield.value[array=1:3]");
|
||||
pvCopy = PVCopy::create(pvRecordStructure,pvRequest,"");
|
||||
pvStructureCopy = pvCopy->createPVStructure();
|
||||
bitSet = BitSetPtr(new BitSet(pvStructureCopy->getNumberFields()));
|
||||
pvValue = pvRecordStructure->getSubField<PVDoubleArray>("subfield.value");
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "after get subfield.value"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==true);
|
||||
testOk1(nset==1);
|
||||
}
|
||||
|
||||
static void timeStampTest()
|
||||
{
|
||||
if(debug) {cout << endl << endl << "****timeStampTest****" << endl;}
|
||||
bool result = false;
|
||||
uint32 nset = 0;
|
||||
|
||||
PVStructurePtr pvRecordStructure(getStandardPVField()->scalar(pvDouble,"timeStamp"));
|
||||
PVRecordPtr pvRecord(PVRecord::create("doubleRecord",pvRecordStructure));
|
||||
PVStructurePtr pvRequest(CreateRequest::create()->createRequest("value,timeStamp[timestamp=current]"));
|
||||
PVCopyPtr pvCopy(PVCopy::create(pvRecordStructure,pvRequest,""));
|
||||
PVStructurePtr pvStructureCopy(pvCopy->createPVStructure());
|
||||
BitSetPtr bitSet(new BitSet(pvStructureCopy->getNumberFields()));
|
||||
PVDoublePtr pvValue(pvRecordStructure->getSubField<PVDouble>("value"));
|
||||
if(debug) {
|
||||
cout << "initial"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< " pvRecordStructure\n" << pvRecordStructure
|
||||
<< "\n";
|
||||
}
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "after update"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< " pvRecordStructure\n" << pvRecordStructure
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==true);
|
||||
testOk1(nset==1);
|
||||
pvRecord->process();
|
||||
pvValue->put(1.0);
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "after pvValue"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< " pvRecordStructure\n" << pvRecordStructure
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==true);
|
||||
testOk1(nset==2);
|
||||
}
|
||||
|
||||
static void ignoreTest()
|
||||
{
|
||||
if(debug) {cout << endl << endl << "****ignoreTest****" << endl;}
|
||||
bool result = false;
|
||||
uint32 nset = 0;
|
||||
|
||||
PVStructurePtr pvRecordStructure(getStandardPVField()->scalar(pvDouble,"alarm,timeStamp"));
|
||||
PVRecordPtr pvRecord(PVRecord::create("doubleRecord",pvRecordStructure));
|
||||
PVStructurePtr pvRequest(CreateRequest::create()->createRequest("value,alarm[ignore=true],timeStamp[ignore=true]"));
|
||||
PVCopyPtr pvCopy(PVCopy::create(pvRecordStructure,pvRequest,""));
|
||||
PVStructurePtr pvStructureCopy(pvCopy->createPVStructure());
|
||||
BitSetPtr bitSet(new BitSet(pvStructureCopy->getNumberFields()));
|
||||
PVDoublePtr pvValue(pvRecordStructure->getSubField<PVDouble>("value"));
|
||||
PVStringPtr pvMessage(pvRecordStructure->getSubField<PVString>("alarm.message"));
|
||||
PVIntPtr pvUserTag(pvRecordStructure->getSubField<PVInt>("timeStamp.userTag"));
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "initial"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==false);
|
||||
testOk1(nset==0);
|
||||
pvMessage->put("test message");
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "after pvMessage"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==false);
|
||||
testOk1(nset==1);
|
||||
pvUserTag->put(50);
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "after pvMessage"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==false);
|
||||
testOk1(nset==2);
|
||||
pvValue->put(1.0);
|
||||
result = pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet);
|
||||
nset = bitSet->cardinality();
|
||||
if(debug) {
|
||||
cout << "after pvValue"
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nset " << nset
|
||||
<< " bitSet " << *bitSet
|
||||
<< " pvStructureCopy\n" << pvStructureCopy
|
||||
<< "\n";
|
||||
}
|
||||
testOk1(result==true);
|
||||
testOk1(nset==3);
|
||||
}
|
||||
|
||||
static void debugOutput(const string& what, bool result, uint32 nSet, BitSetPtr bitSet, PVStructurePtr pvStructureCopy)
|
||||
{
|
||||
if(debug) {
|
||||
cout << what
|
||||
<< " result " << (result ? "true" : "false")
|
||||
<< " nSet " << nSet
|
||||
<< " bitSet " << *bitSet
|
||||
<< "\n pvStructureCopy\n" << pvStructureCopy
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
||||
static void dataDistributorTest()
|
||||
{
|
||||
if(debug) {cout << endl << endl << "****dataDistributorTest****" << endl;}
|
||||
bool result = false;
|
||||
uint32 nSet = 0;
|
||||
|
||||
// Create test structure
|
||||
PVStructurePtr pvRecordStructure(getStandardPVField()->scalar(pvInt,""));
|
||||
PVIntPtr pvValue(pvRecordStructure->getSubField<PVInt>("value"));
|
||||
PVRecordPtr pvRecord(PVRecord::create("intRecord",pvRecordStructure));
|
||||
if(debug) {
|
||||
cout << " pvRecordStructure\n" << pvRecordStructure
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
// Request distributor plugin with trigger field value
|
||||
PVStructurePtr pvRequest(CreateRequest::create()->createRequest("_[distributor=trigger:value]"));
|
||||
|
||||
// Create clients
|
||||
PVCopyPtr pvCopy1(PVCopy::create(pvRecordStructure,pvRequest,""));
|
||||
PVStructurePtr pvStructureCopy1(pvCopy1->createPVStructure());
|
||||
BitSetPtr bitSet1(new BitSet(pvStructureCopy1->getNumberFields()));
|
||||
|
||||
PVCopyPtr pvCopy2(PVCopy::create(pvRecordStructure,pvRequest,""));
|
||||
PVStructurePtr pvStructureCopy2(pvCopy2->createPVStructure());
|
||||
BitSetPtr bitSet2(new BitSet(pvStructureCopy2->getNumberFields()));
|
||||
|
||||
// Update 0: both clients get it
|
||||
result = pvCopy1->updateCopySetBitSet(pvStructureCopy1,bitSet1);
|
||||
nSet = bitSet1->cardinality();
|
||||
debugOutput("client 1: update 0", result, nSet, bitSet1, pvStructureCopy1);
|
||||
testOk1(result==true);
|
||||
testOk1(nSet==1);
|
||||
|
||||
result = pvCopy2->updateCopySetBitSet(pvStructureCopy2,bitSet2);
|
||||
nSet = bitSet2->cardinality();
|
||||
debugOutput("client 2: update 0", result, nSet, bitSet2, pvStructureCopy2);
|
||||
testOk1(result==true);
|
||||
testOk1(nSet==1);
|
||||
|
||||
// Update 1: only client 1 gets it
|
||||
pvValue->put(1);
|
||||
|
||||
result = pvCopy1->updateCopySetBitSet(pvStructureCopy1,bitSet1);
|
||||
nSet = bitSet1->cardinality();
|
||||
debugOutput("client 1: update 1", result, nSet, bitSet1, pvStructureCopy1);
|
||||
testOk1(result==true);
|
||||
testOk1(nSet==1);
|
||||
|
||||
result = pvCopy2->updateCopySetBitSet(pvStructureCopy2,bitSet2);
|
||||
nSet = bitSet2->cardinality();
|
||||
debugOutput("client 2: update 1", result, nSet, bitSet2, pvStructureCopy2);
|
||||
testOk1(result==false);
|
||||
testOk1(nSet==0);
|
||||
|
||||
// Update 2: only client 2 gets it
|
||||
pvValue->put(2);
|
||||
|
||||
result = pvCopy1->updateCopySetBitSet(pvStructureCopy1,bitSet1);
|
||||
nSet = bitSet1->cardinality();
|
||||
debugOutput("client 1: update 2", result, nSet, bitSet1, pvStructureCopy1);
|
||||
testOk1(result==false);
|
||||
testOk1(nSet==0);
|
||||
|
||||
result = pvCopy2->updateCopySetBitSet(pvStructureCopy2,bitSet2);
|
||||
nSet = bitSet2->cardinality();
|
||||
debugOutput("client 2: update 2", result, nSet, bitSet2, pvStructureCopy2);
|
||||
testOk1(result==true);
|
||||
testOk1(nSet==1);
|
||||
|
||||
// Update 3: only client 1 gets it
|
||||
pvValue->put(3);
|
||||
|
||||
result = pvCopy1->updateCopySetBitSet(pvStructureCopy1,bitSet1);
|
||||
nSet = bitSet1->cardinality();
|
||||
debugOutput("client 1: update 3", result, nSet, bitSet1, pvStructureCopy1);
|
||||
testOk1(result==true);
|
||||
testOk1(nSet==1);
|
||||
|
||||
result = pvCopy2->updateCopySetBitSet(pvStructureCopy2,bitSet2);
|
||||
nSet = bitSet2->cardinality();
|
||||
debugOutput("client 2: update 3", result, nSet, bitSet2, pvStructureCopy2);
|
||||
testOk1(result==false);
|
||||
testOk1(nSet==0);
|
||||
|
||||
// Update 4: only client 2 gets it
|
||||
pvValue->put(4);
|
||||
|
||||
result = pvCopy1->updateCopySetBitSet(pvStructureCopy1,bitSet1);
|
||||
nSet = bitSet1->cardinality();
|
||||
debugOutput("client 1: update 4", result, nSet, bitSet1, pvStructureCopy1);
|
||||
testOk1(result==false);
|
||||
testOk1(nSet==0);
|
||||
|
||||
result = pvCopy2->updateCopySetBitSet(pvStructureCopy2,bitSet2);
|
||||
nSet = bitSet2->cardinality();
|
||||
debugOutput("client 2: update 4", result, nSet, bitSet2, pvStructureCopy2);
|
||||
testOk1(result==true);
|
||||
testOk1(nSet==1);
|
||||
}
|
||||
|
||||
MAIN(testPlugin)
|
||||
{
|
||||
testPlan(46);
|
||||
PVDatabasePtr pvDatabase(PVDatabase::getMaster());
|
||||
deadbandTest();
|
||||
arrayTest();
|
||||
unionArrayTest();
|
||||
timeStampTest();
|
||||
ignoreTest();
|
||||
dataDistributorTest();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user