add dbLoadGroup()
This commit is contained in:
@ -180,6 +180,7 @@ struct PDBProcessor
|
||||
{
|
||||
GroupConfig conf;
|
||||
|
||||
// process info(Q:Group, ...)
|
||||
for(pdbRecordIterator rec; !rec.done(); rec.next())
|
||||
{
|
||||
const char *json = rec.info("Q:group");
|
||||
@ -205,6 +206,46 @@ struct PDBProcessor
|
||||
}
|
||||
}
|
||||
|
||||
// process group definition files
|
||||
for(PDBProvider::group_files_t::const_iterator it(PDBProvider::group_files.begin()), end(PDBProvider::group_files.end());
|
||||
it != end; ++it)
|
||||
{
|
||||
std::ifstream jfile(it->c_str());
|
||||
if(!jfile.is_open()) {
|
||||
fprintf(stderr, "Error opening \"%s\"\n", it->c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<char> contents;
|
||||
size_t pos=0u;
|
||||
while(true) {
|
||||
contents.resize(pos+1024u);
|
||||
if(!jfile.read(&contents[pos], contents.size()-pos))
|
||||
break;
|
||||
pos += jfile.gcount();
|
||||
}
|
||||
|
||||
if(jfile.bad() || !jfile.eof()) {
|
||||
fprintf(stderr, "Error reading \"%s\"\n", it->c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
contents.push_back('\0');
|
||||
const char *json = &contents[0];
|
||||
|
||||
if(PDBProviderDebug>2) {
|
||||
fprintf(stderr, "Process dbGroup file \"%s\"\n", it->c_str());
|
||||
}
|
||||
|
||||
try {
|
||||
GroupConfig::parse(json, "", conf);
|
||||
if(!conf.warning.empty())
|
||||
fprintf(stderr, "warning(s) from dbGroup file \"%s\"\n%s", it->c_str(), conf.warning.c_str());
|
||||
}catch(std::exception& e){
|
||||
fprintf(stderr, "Error from dbGroup file \"%s\"\n%s", it->c_str(), e.what());
|
||||
}
|
||||
}
|
||||
|
||||
for(GroupConfig::groups_t::const_iterator git=conf.groups.begin(), gend=conf.groups.end();
|
||||
git!=gend; ++git)
|
||||
{
|
||||
@ -319,6 +360,8 @@ struct PDBProcessor
|
||||
|
||||
size_t PDBProvider::num_instances;
|
||||
|
||||
std::list<std::string> PDBProvider::group_files;
|
||||
|
||||
PDBProvider::PDBProvider(const epics::pvAccess::Configuration::const_shared_pointer &)
|
||||
{
|
||||
/* Long view
|
||||
|
@ -64,6 +64,9 @@ struct QSRV_API PDBProvider : public epics::pvAccess::ChannelProvider,
|
||||
|
||||
dbEventCtx event_context;
|
||||
|
||||
typedef std::list<std::string> group_files_t;
|
||||
static group_files_t group_files;
|
||||
|
||||
static size_t num_instances;
|
||||
};
|
||||
|
||||
|
@ -49,6 +49,9 @@ QSRV_API unsigned qsrvVersion(void);
|
||||
/** returns QSRV_ABI_VERSION_INT captured at compilation time */
|
||||
QSRV_API unsigned qsrvABIVersion(void);
|
||||
|
||||
QSRV_API
|
||||
long dbLoadGroup(const char* fname);
|
||||
|
||||
QSRV_API void testqsrvWaitForLinkEvent(struct link *plink);
|
||||
|
||||
/** Call before testIocShutdownOk()
|
||||
|
@ -46,8 +46,42 @@ void QSRVRegistrar_counters()
|
||||
epics::registerRefCounter("PDBProvider", &PDBProvider::num_instances);
|
||||
}
|
||||
|
||||
long dbLoadGroup(const char* fname)
|
||||
{
|
||||
try {
|
||||
if(!fname) {
|
||||
printf("dbLoadGroup(\"file.json\")\n"
|
||||
"\n"
|
||||
"Load additional DB group definitions from file.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(fname[0]=='-') {
|
||||
fname++;
|
||||
if(fname[0]=='*' && fname[1]=='\0') {
|
||||
PDBProvider::group_files.clear();
|
||||
} else {
|
||||
PDBProvider::group_files.remove(fname);
|
||||
}
|
||||
} else {
|
||||
PDBProvider::group_files.remove(fname);
|
||||
PDBProvider::group_files.push_back(fname);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}catch(std::exception& e){
|
||||
fprintf(stderr, "Error: %s\n", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void dbLoadGroupWrap(const char* fname)
|
||||
{
|
||||
(void)dbLoadGroup(fname);
|
||||
}
|
||||
|
||||
void dbgl(int lvl, const char *pattern)
|
||||
{
|
||||
if(!pattern)
|
||||
@ -88,6 +122,7 @@ void QSRVRegistrar()
|
||||
QSRVRegistrar_counters();
|
||||
pva::ChannelProviderRegistry::servers()->addSingleton<PDBProvider>("QSRV");
|
||||
epics::iocshRegister<int, const char*, &dbgl>("dbgl", "level", "pattern");
|
||||
epics::iocshRegister<const char*, &dbLoadGroupWrap>("dbLoadGroup", "jsonfile");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "iocsh.h"
|
||||
#include "osiFileName.h"
|
||||
|
||||
#include <pv/qsrv.h>
|
||||
|
||||
extern "C" int softIocPVA_registerRecordDeviceDriver(struct dbBase *pdbbase);
|
||||
|
||||
#ifndef EPICS_BASE
|
||||
@ -76,6 +78,8 @@ void usage(const char *arg0, const std::string& base_dbd) {
|
||||
" -a <acf> Access Security configuration file. Macro substitution is\n"
|
||||
" performed.\n"
|
||||
"\n"
|
||||
" -G <json> DB Group definition file in JSON format.\n"
|
||||
"\n"
|
||||
" -m <MAC>=<value>,... Set/replace macro definitions used by subsequent -d and\n"
|
||||
" -a.\n"
|
||||
"\n"
|
||||
@ -155,7 +159,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "ha:D:d:m:Ssx:v")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "ha:D:d:m:Ssx:G:v")) != -1) {
|
||||
switch (opt) {
|
||||
case 'h': /* Print usage */
|
||||
usage(argv[0], dbd_file);
|
||||
@ -216,6 +220,9 @@ int main(int argc, char *argv[])
|
||||
std::string("Failed to load: ")+exit_file);
|
||||
loadedDb = true;
|
||||
break;
|
||||
case 'G':
|
||||
dbLoadGroup(optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user