Skip to content

Commit

Permalink
p2p more config
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavidsaver committed Oct 5, 2018
1 parent db3fdf5 commit afead32
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
4 changes: 3 additions & 1 deletion loopback.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
{
"version":1,
/* "readOnly":true, */
"readOnly":false,
"clients":[
{
"name":"theclient",
Expand All @@ -30,6 +30,8 @@
"name":"theserver",
"clients":["theclient"],
"interface":"127.0.0.1",
"addrlist":"127.255.255.255",
"autoaddrlist":false,
"serverport":5075,
"bcastport":5076
}
Expand Down
44 changes: 36 additions & 8 deletions p2pApp/gwmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <pv/reftrack.h>
#include <pv/iocreftrack.h>
#include <pv/iocshelper.h>
#include <pv/logger.h>

#include "server.h"
#include "pva2pva.h"
Expand All @@ -50,6 +51,8 @@ pvd::StructureConstPtr schema(pvd::getFieldCreate()->createFieldBuilder()
->add("name", pvd::pvString)
->addArray("clients", pvd::pvString)
->add("interface", pvd::pvString)
->add("addrlist", pvd::pvString)
->add("autoaddrlist", pvd::pvBoolean)
->add("serverport", pvd::pvUShort)
->add("bcastport", pvd::pvUShort)
->add("control_prefix", pvd::pvString)
Expand All @@ -67,9 +70,12 @@ void getargs(ServerConfig& arg, int argc, char *argv[])
int opt;
bool checkonly = false;

while( (opt=getopt(argc, argv, "vhiIC"))!=-1)
while( (opt=getopt(argc, argv, "qvhiIC"))!=-1)
{
switch(opt) {
case 'q':
arg.debug--;
break;
case 'v':
arg.debug++;
break;
Expand Down Expand Up @@ -100,11 +106,7 @@ void getargs(ServerConfig& arg, int argc, char *argv[])
std::ifstream strm(argv[optind]);
pvd::parseJSON(strm, arg.conf);

{
pvd::PVScalarPtr V(arg.conf->getSubField<pvd::PVScalar>("readOnly"));
if(V)
p2pReadOnly = V->getAs<pvd::boolean>();
}
p2pReadOnly = arg.conf->getSubFieldT<pvd::PVScalar>("readOnly")->getAs<pvd::boolean>();

unsigned version = arg.conf->getSubFieldT<pvd::PVUInt>("version")->get();
if(version==0) {
Expand All @@ -128,15 +130,19 @@ void getargs(ServerConfig& arg, int argc, char *argv[])
}
}

GWServerChannelProvider::shared_pointer configure_client(const pvd::PVStructurePtr& conf)
GWServerChannelProvider::shared_pointer configure_client(ServerConfig& arg, const pvd::PVStructurePtr& conf)
{
std::string name(conf->getSubFieldT<pvd::PVString>("name")->get());
std::string provider(conf->getSubFieldT<pvd::PVString>("provider")->get());

LOG(pva::logLevelInfo, "Configure client '%s' with provider '%s'", name.c_str(), provider.c_str());

pva::Configuration::shared_pointer C(pva::ConfigurationBuilder()
.add("EPICS_PVA_ADDR_LIST", conf->getSubFieldT<pvd::PVString>("addrlist")->get())
.add("EPICS_PVA_AUTO_ADDR_LIST", conf->getSubFieldT<pvd::PVBoolean>("autoaddrlist")->get())
.add("EPICS_PVA_SERVER_PORT", conf->getSubFieldT<pvd::PVScalar>("serverport")->getAs<pvd::uint16>())
.add("EPICS_PVA_BROADCAST_PORT", conf->getSubFieldT<pvd::PVScalar>("bcastport")->getAs<pvd::uint16>())
.add("EPICS_PVA_DEBUG", arg.debug>=5 ? 5 : 0)
.push_map()
.build());

Expand All @@ -150,10 +156,17 @@ GWServerChannelProvider::shared_pointer configure_client(const pvd::PVStructureP

pva::ServerContext::shared_pointer configure_server(ServerConfig& arg, const pvd::PVStructurePtr& conf)
{
std::string name(conf->getSubFieldT<pvd::PVString>("name")->get());

LOG(pva::logLevelInfo, "Configure server '%s'", name.c_str());

pva::Configuration::shared_pointer C(pva::ConfigurationBuilder()
.add("EPICS_PVAS_INTF_ADDR_LIST", conf->getSubFieldT<pvd::PVString>("interface")->get())
.add("EPICS_PVAS_BEACON_ADDR_LIST", conf->getSubFieldT<pvd::PVString>("addrlist")->get())
.add("EPICS_PVAS_AUTO_BEACON_ADDR_LIST", conf->getSubFieldT<pvd::PVBoolean>("autoaddrlist")->get())
.add("EPICS_PVAS_SERVER_PORT", conf->getSubFieldT<pvd::PVScalar>("serverport")->getAs<pvd::uint16>())
.add("EPICS_PVAS_BROADCAST_PORT", conf->getSubFieldT<pvd::PVScalar>("bcastport")->getAs<pvd::uint16>())
.add("EPICS_PVA_DEBUG", arg.debug>=5 ? 5 : 0)
.push_map()
.build());

Expand Down Expand Up @@ -245,6 +258,21 @@ int main(int argc, char *argv[])
theserver = &arg;
getargs(arg, argc, argv);

pva::pvAccessLogLevel lvl;
if(arg.debug<0)
lvl = pva::logLevelError;
else if(arg.debug==0)
lvl = pva::logLevelWarn;
else if(arg.debug==1)
lvl = pva::logLevelInfo;
else if(arg.debug==2)
lvl = pva::logLevelDebug;
else if(arg.debug==3)
lvl = pva::logLevelTrace;
else if(arg.debug>=4)
lvl = pva::logLevelAll;
SET_LOG_LEVEL(lvl);

pva::ClientFactory::start();

pvd::PVStructureArray::const_svector arr;
Expand All @@ -263,7 +291,7 @@ int main(int argc, char *argv[])
if(it!=arg.clients.end())
throw std::runtime_error(std::string("Duplicate client name not allowed : ")+name);

arg.clients[name] = configure_client(client);
arg.clients[name] = configure_client(arg, client);
}

arr = arg.conf->getSubFieldT<pvd::PVStructureArray>("servers")->view();
Expand Down
2 changes: 1 addition & 1 deletion p2pApp/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct ServerConfig {
typedef std::map<std::string, epics::pvAccess::ServerContext::shared_pointer> servers_t;
servers_t servers;

ServerConfig() :debug(0), interactive(true) {}
ServerConfig() :debug(1), interactive(true) {}

void drop(const char *client, const char *channel);
void status_server(int lvl, const char *server);
Expand Down

0 comments on commit afead32

Please sign in to comment.