13 #include <epicsGetopt.h> 42 ->addNestedStructureArray(
"clients")
50 ->addNestedStructureArray(
"servers")
63 void usage(
const char *me)
65 std::cerr<<
"Usage: "<<me<<
" [-vhiIC] <config file>\n";
71 bool checkonly =
false;
73 while( (opt=
getopt(argc, argv,
"qvhiIC"))!=-1)
92 std::cerr<<
"Unknown argument -"<<char(opt)<<
"\n";
100 std::cerr<<
"Exactly one positional argument expected\n";
106 std::ifstream strm(argv[
optind]);
111 unsigned version = arg.
conf->getSubFieldT<
pvd::PVUInt>(
"version")->
get();
113 std::cerr<<
"Warning: config file missing \"version\" key. Assuming 1\n";
114 }
else if(version!=1) {
115 std::cerr<<
"config file version mis-match. expect 1 found "<<version<<
"\n";
119 std::cerr<<
"No clients configured\n";
123 std::cerr<<
"No servers configured\n";
128 std::cerr<<
"Config file OK\n";
138 LOG(
pva::logLevelInfo,
"Configure client '%s' with provider '%s'", name.c_str(), provider.c_str());
141 .add(
"EPICS_PVA_ADDR_LIST", conf->getSubFieldT<
pvd::PVString>(
"addrlist")->
get())
142 .add(
"EPICS_PVA_AUTO_ADDR_LIST", conf->getSubFieldT<
pvd::PVScalar>(
"autoaddrlist")->
getAs<std::string>())
145 .
add(
"EPICS_PVA_DEBUG", arg.
debug>=5 ? 5 : 0)
151 throw std::runtime_error(
"Can't create ChannelProvider");
164 .add(
"EPICS_PVAS_INTF_ADDR_LIST", conf->getSubFieldT<
pvd::PVString>(
"interface")->
get())
165 .add(
"EPICS_PVAS_BEACON_ADDR_LIST", conf->getSubFieldT<
pvd::PVString>(
"addrlist")->
get())
166 .add(
"EPICS_PVAS_AUTO_BEACON_ADDR_LIST", conf->getSubFieldT<
pvd::PVScalar>(
"autoaddrlist")->
getAs<std::string>())
169 .
add(
"EPICS_PVA_DEBUG", arg.
debug>=5 ? 5 : 0)
175 std::vector<pva::ChannelProvider::shared_pointer> providers;
177 for(pvd::PVStringArray::const_svector::const_iterator it(names.begin()), end(names.end()); it!=end; ++it)
179 ServerConfig::clients_t::const_iterator it2(arg.
clients.find(*it));
181 throw std::runtime_error(
"Server references non-existant client");
187 .providers(providers)));
195 void sigdone(
int num)
205 void iocsh_drop(
const char *
client,
const char *channel)
210 theserver->
drop(client, channel);
211 }
catch(std::exception& e){
212 std::cout<<
"Error: "<<e.what()<<
"\n";
216 void gwsr(
int lvl,
const char *server)
222 }
catch(std::exception& e){
223 std::cout<<
"Error: "<<e.what()<<
"\n";
227 void gwcr(
int lvl,
const char *client,
const char *channel)
233 }
catch(std::exception& e){
234 std::cout<<
"Error: "<<e.what()<<
"\n";
240 int main(
int argc,
char *argv[])
245 epics::iocshRegister<const char*, const char*, &iocsh_drop>(
"drop",
"client",
"channel");
246 epics::iocshRegister<int, const char*, &gwsr>(
"gwsr",
"level",
"channel");
247 epics::iocshRegister<int, const char*, const char*, &gwcr>(
"gwcr",
"level",
"client",
"channel");
259 getargs(arg, argc, argv);
262 std::cout<<
"Notice: This p2p gateway prototype has been superceded by the p4p.gw gateway\n" 263 " which has exciting new features including granular access control,\n" 264 " and status PVs including bandwidth usage reports.\n" 265 " p2p is considered deprecated by its author, and will receive\n" 266 " minimal maintainance effort going forward.\n" 267 " Users are encouraged to migrate to p4p.gw.\n" 269 " https://mdavidsaver.github.io/p4p/gw.html\n" 275 else if(arg.
debug==0)
277 else if(arg.
debug==1)
279 else if(arg.
debug==2)
281 else if(arg.
debug==3)
283 else if(arg.
debug>=4)
293 for(
size_t i=0;
i<arr.size();
i++) {
294 if(!arr[
i])
continue;
299 throw std::runtime_error(
"Client with empty name not allowed");
301 ServerConfig::clients_t::const_iterator it(arg.
clients.find(name));
303 throw std::runtime_error(std::string(
"Duplicate client name not allowed : ")+name);
305 arg.
clients[name] = configure_client(arg, client);
310 for(
size_t i=0;
i<arr.size();
i++) {
311 if(!arr[
i])
continue;
316 throw std::runtime_error(
"Server with empty name not allowed");
318 ServerConfig::servers_t::const_iterator it(arg.
servers.find(name));
320 throw std::runtime_error(std::string(
"Duplicate server name not allowed : ")+name);
322 arg.
servers[name] = configure_server(arg, server);
330 signal(SIGINT, sigdone);
331 signal(SIGTERM, sigdone);
332 signal(SIGQUIT, sigdone);
343 }
catch(std::exception& e){
344 std::cerr<<
"Fatal Error : "<<e.what()<<
"\n";
int main(int argc, char *argv[])
Configuration::shared_pointer build()
int getopt(int nargc, char *const *nargv, const char *ostr)
PVScalar is the base class for each scalar field.
bool empty() const
shorthand for size()==0
#define SET_LOG_LEVEL(level)
std::tr1::shared_ptr< const Structure > StructureConstPtr
::epics::pvData::shared_vector< const PVStructurePtr > const_svector
storage_t::arg_type get() const
epicsShareExtern void refTrackRegistrar()
int epicsStdCall iocsh(const char *pathname)
void status_client(int lvl, const char *client, const char *channel)
PVString is special case, since it implements SerializableArray.
#define LOG(level, format,...)
epics::pvData::PVStructure::shared_pointer conf
void push_back(param_type v)
template class for all extensions of PVArray.
ChannelProviderRegistry::shared_pointer clients
ConfigurationBuilder & push_map()
epics::pvData::PVStructure::shared_pointer parseJSON(std::istream &strm)
static ChannelProviderRegistry::shared_pointer clients()
FORCE_INLINE const FieldCreatePtr & getFieldCreate()
void registerRefCounter(const char *name, const size_t *counter)
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Data class for a structureArray.
void epicsStdCall libComRegister(void)
static size_t num_instances
static size_t num_instances
void drop(const char *client, const char *channel)
Class that holds the data for each possible scalar type.
static size_t num_instances
virtual const_svector view() const OVERRIDE FINAL
Fetch a read-only view of the current array data.
void status_server(int lvl, const char *server)
static ServerContext::shared_pointer create(const Config &conf=Config())
static size_t num_instances
ConfigurationBuilder & add(const std::string &name, const V &val)
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
::epics::pvData::shared_vector< const T > const_svector
static size_t num_instances