From 47882d759d231b878842d348f4e846be5b769908 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sun, 13 Dec 2020 12:07:37 -0800 Subject: [PATCH] add target_information() Print from: pvxinfo -D and new iocsh iocsh pvxs_target_info() --- documentation/util.rst | 2 + ioc/iochooks.cpp | 20 +++++-- src/Makefile | 9 +++ src/describe.cpp | 132 +++++++++++++++++++++++++++++++++++++++++ src/describe.h@ | 4 ++ src/pvxs/util.h | 12 ++++ test/testioc.cpp | 3 +- tools/info.cpp | 6 +- 8 files changed, 182 insertions(+), 6 deletions(-) create mode 100644 src/describe.cpp create mode 100644 src/describe.h@ diff --git a/documentation/util.rst b/documentation/util.rst index f77c3ce..64d397a 100644 --- a/documentation/util.rst +++ b/documentation/util.rst @@ -136,3 +136,5 @@ Misc. utility code. :: .. doxygenfunction:: pvxs::cleanup_for_valgrind .. doxygenclass:: pvxs::SigInt + +.. doxygenfunction:: pvxs::target_information diff --git a/ioc/iochooks.cpp b/ioc/iochooks.cpp index c5c420f..3071530 100644 --- a/ioc/iochooks.cpp +++ b/ioc/iochooks.cpp @@ -72,6 +72,17 @@ void pvxsr(int detail) } } +void pvxs_target_info() +{ + try { + std::ostringstream capture; + target_information(capture); + printf("%s", capture.str().c_str()); + } catch(std::exception& e) { + fprintf(stderr, "Error in %s : %s\n", __func__, e.what()); + } +} + // index_sequence from: //http://stackoverflow.com/questions/17424477/implementation-c14-make-integer-sequence @@ -127,11 +138,11 @@ struct ToStr { typedef const char* type; }; template struct Reg { const char* const name; - const char* const argnames[sizeof...(Args)]; + const char* const argnames[1+sizeof...(Args)]; constexpr explicit Reg(const char* name, typename ToStr::type... descs) :name(name) - ,argnames{descs...} + ,argnames{descs..., 0} {} template @@ -144,8 +155,8 @@ struct Reg { template void doit(index_sequence) { - static const iocshArg argstack[sizeof...(Args)] = {{argnames[Idxs], Arg::code}...}; - static const iocshArg * const args[] = {&argstack[Idxs]...}; + static const iocshArg argstack[1+sizeof...(Args)] = {{argnames[Idxs], Arg::code}...}; + static const iocshArg * const args[] = {&argstack[Idxs]..., 0}; static const iocshFuncDef def = {name, sizeof...(Args), args}; iocshRegister(&def, &call); @@ -207,6 +218,7 @@ void pvxsRegistrar() Reg("pvxsl", "detail").ister<&pvxsl>(); Reg("pvxsr", "detail").ister<&pvxsr>(); + Reg<>("pvxs_target_info").ister<&pvxs_target_info>(); auto serv = instance.load(); if(!serv) { diff --git a/src/Makefile b/src/Makefile index a48baf8..71929ee 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,9 +34,16 @@ ifeq (,$(PVXS_MAJOR_VERSION)) $(error PVXS_MAJOR_VERSION undefined, problem reading cfg/CONFIG_PVXS_VERSION) endif +# see below for special case versionNum.h +EXPAND += describe.h + EXPANDVARS += PVXS_MAJOR_VERSION EXPANDVARS += PVXS_MINOR_VERSION EXPANDVARS += PVXS_MAINTENANCE_VERSION +EXPANDVARS += EPICS_HOST_ARCH T_A OS_CLASS +ifdef BASE_3_15 +EXPANDVARS += CMPLR_CLASS +endif EXPANDFLAGS += $(foreach var,$(EXPANDVARS),-D$(var)="$(strip $($(var)))") @@ -61,6 +68,7 @@ INC += pvxs/client.h LIBRARY = pvxs +LIB_SRCS += describe.cpp LIB_SRCS += log.cpp LIB_SRCS += unittest.cpp LIB_SRCS += util.cpp @@ -118,6 +126,7 @@ include $(TOP)/configure/RULES_PVXS_MODULE $(MKDIR) $(COMMON_DIR)/pvxs $(EXPAND_TOOL) $(EXPANDFLAGS) $($@_EXPANDFLAGS) $< $@ +describe$(DEP): describe.h util$(DEP): $(COMMON_DIR)/$(GENVERSION) ifndef GENVERSIONHEADER diff --git a/src/describe.cpp b/src/describe.cpp new file mode 100644 index 0000000..78829e7 --- /dev/null +++ b/src/describe.cpp @@ -0,0 +1,132 @@ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvxs is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ + +#if !defined(_WIN32) +# include +#endif + +#include +#include +#include + +#include +#include +#include + +#include "evhelper.h" +#include "describe.h" + +namespace pvxs { + +std::ostream& target_information(std::ostream& strm) +{ + strm<=VERSION_INT(3,15,0,1) + strm<<" "< "<=VERSION_INT(3,15,0,2) + strm< "< "<\n"; + Indented J(strm); + for(auto& addr : dummy.interfaces()) { + strm< Operation timeout in seconds. default 5 sec.\n" ; } @@ -44,7 +45,7 @@ int main(int argc, char *argv[]) { int opt; - while ((opt = getopt(argc, argv, "hVvdw:")) != -1) { + while ((opt = getopt(argc, argv, "hVvdDw:")) != -1) { switch(opt) { case 'h': usage(argv[0]); @@ -60,6 +61,9 @@ int main(int argc, char *argv[]) case 'd': logger_level_set("pvxs.*", Level::Debug); break; + case 'D': + target_information(std::cout); + return 0; case 'w': timeout = parseTo(optarg); break;