This is Unofficial EPICS BASE Doxygen Site
pvlist.cpp File Reference
#include <stdio.h>
#include <iostream>
#include <map>
#include <iterator>
#include <vector>
#include <string>
#include <istream>
#include <fstream>
#include <sstream>
#include <epicsStdlib.h>
#include <epicsGetopt.h>
#include <pv/logger.h>
#include <epicsExit.h>
#include <osiSock.h>
#include <pv/byteBuffer.h>
#include <pv/serializeHelper.h>
#include <pv/pvaConstants.h>
#include <pv/inetAddressUtil.h>
#include <pv/configuration.h>
#include <pv/remote.h>
#include <pv/rpcClient.h>
+ Include dependency graph for pvlist.cpp:

Go to the source code of this file.

Macros

#define DEFAULT_TIMEOUT   3.0
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

#define DEFAULT_TIMEOUT   3.0

Definition at line 480 of file pvlist.cpp.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 519 of file pvlist.cpp.

520 {
521  int opt; /* getopt() current option */
522  bool debug = false;
523  double timeOut = DEFAULT_TIMEOUT;
524  bool printInfo = false;
525 
526  /*
527  istream* inputStream = 0;
528  ifstream ifs;
529  bool fromStream = false;
530  */
531  setvbuf(stdout,NULL,_IOLBF,BUFSIZ); /* Set stdout to line buffering */
532 
533  while ((opt = getopt(argc, argv, ":hVw:qdF:f:i")) != -1) {
534  switch (opt) {
535  case 'h': /* Print usage */
536  usage();
537  return 0;
538  case 'V': /* Print version */
539  {
540  fprintf(stdout, "pvAccess %u.%u.%u%s\n",
541  EPICS_PVA_MAJOR_VERSION,
542  EPICS_PVA_MINOR_VERSION,
543  EPICS_PVA_MAINTENANCE_VERSION,
544  (EPICS_PVA_DEVELOPMENT_FLAG)?"-SNAPSHOT":"");
545  fprintf(stdout, "pvData %u.%u.%u%s\n",
546  EPICS_PVD_MAJOR_VERSION,
547  EPICS_PVD_MINOR_VERSION,
548  EPICS_PVD_MAINTENANCE_VERSION,
549  (EPICS_PVD_DEVELOPMENT_FLAG)?"-SNAPSHOT":"");
550  fprintf(stdout, "Base %s\n", EPICS_VERSION_FULL);
551  return 0;
552  }
553  case 'w': /* Set PVA timeout value */
554  if((epicsScanDouble(optarg, &timeOut)) != 1 || timeOut <= 0.0)
555  {
556  fprintf(stderr, "'%s' is not a valid timeout value "
557  "- ignored. ('pvlist -h' for help.)\n", optarg);
558  timeOut = DEFAULT_TIMEOUT;
559  }
560  break;
561  case 'q': /* Quiet mode */
562  break;
563  case 'd': /* Debug log level */
564  debug = true;
565  break;
566  case 'i': /* Print server info */
567  printInfo = true;
568  break;
569  case '?':
570  fprintf(stderr,
571  "Unrecognized option: '-%c'. ('pvlist -h' for help.)\n",
572  optopt);
573  return 1;
574  case ':':
575  fprintf(stderr,
576  "Option '-%c' requires an argument. ('pvlist -h' for help.)\n",
577  optopt);
578  return 1;
579  default :
580  usage();
581  return 1;
582  }
583  }
584 
586 
587  bool noArgs = (optind == argc);
588 
589  bool byGUIDSearch = false;
590  for (int i = optind; i < argc; i++)
591  {
592  string serverAddress = argv[i];
593 
594  // by GUID search
595  if (serverAddress.length() == 26 &&
596  serverAddress[0] == '0' &&
597  serverAddress[1] == 'x')
598  {
599  byGUIDSearch = true;
600  break;
601  }
602  }
603 
604  bool allOK = true;
605 
606  if (noArgs || byGUIDSearch)
607  discoverServers(timeOut);
608 
609  // just list all the discovered servers
610  if (noArgs)
611  {
612  for (ServerMap::const_iterator iter = serverMap.begin();
613  iter != serverMap.end();
614  iter++)
615  {
616  const ServerEntry& entry = iter->second;
617 
618  cout << "GUID 0x" << entry.guid << " version " << (int)entry.version << ": "
619  << entry.protocol << "@[ ";
620 
621  size_t count = entry.addresses.size();
622  for (size_t i = 0; i < count; i++)
623  {
624  cout << inetAddressToString(entry.addresses[i]);
625  if (i < (count-1))
626  cout << " ";
627  }
628  cout << " ]" << endl;
629  }
630  }
631  else
632  {
633  for (int i = optind; i < argc; i++)
634  {
635  string serverAddress = argv[i];
636 
637  // by GUID search
638  if (serverAddress.length() == 26 &&
639  serverAddress[0] == '0' &&
640  serverAddress[1] == 'x')
641  {
642  bool resolved = false;
643  for (ServerMap::const_iterator iter = serverMap.begin();
644  iter != serverMap.end();
645  iter++)
646  {
647  const ServerEntry& entry = iter->second;
648 
649  if (strncmp(entry.guid.c_str(), &(serverAddress[2]), 24) == 0)
650  {
651  // found match
652 
653  // TODO for now we take only first server address
654  serverAddress = inetAddressToString(entry.addresses[0]);
655  resolved = true;
656  break;
657  }
658  }
659 
660  if (!resolved)
661  {
662  fprintf(stderr, "Failed to resolve GUID '%s'!\n", serverAddress.c_str());
663  allOK = false;
664  continue;
665  }
666  }
667 
668  StructureConstPtr argstype(getFieldCreate()->createFieldBuilder()
669  ->setId("epics:nt/NTURI:1.0")
670  ->add("scheme", pvString)
671  ->add("path", pvString)
672  ->addNestedStructure("query")
673  ->add("op", pvString)
674  ->endNested()
675  ->createStructure());
676 
677  PVStructure::shared_pointer args(getPVDataCreate()->createPVStructure(argstype));
678 
679  args->getSubFieldT<PVString>("scheme")->put("pva");
680  args->getSubFieldT<PVString>("path")->put("server");
681  args->getSubFieldT<PVString>("query.op")->put(printInfo ? "info" : "channels");
682 
683  if(debug) {
684  std::cerr<<"Query to "<<serverAddress<<"\n"<<args<<"\n";
685  }
686 
687  PVStructure::shared_pointer ret;
688  try {
689  RPCClient rpc("server",
690  createRequest("field()"),
691  ChannelProvider::shared_pointer(),
692  serverAddress);
693 
694  if(debug)
695  std::cerr<<"Execute\n";
696  ret = rpc.request(args, timeOut, true);
697  } catch(std::exception& e) {
698  std::cerr<<"Error: "<<e.what()<<"\n";
699  return 1;
700  }
701 
702  if(!printInfo) {
703  PVStringArray::shared_pointer pvs(ret->getSubField<PVStringArray>("value"));
704 
705  PVStringArray::const_svector val(pvs->view());
706 
707  std::copy(val.begin(),
708  val.end(),
709  std::ostream_iterator<std::string>(std::cout, "\n"));
710  }
711  else {
712  std::cout<<ret<<"\n";
713  }
714  }
715  }
716 
717  return allOK ? 0 : 1;
718 }
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: epicsGetopt.c:65
std::tr1::shared_ptr< detail::SharedPut > put
int i
Definition: scan.c:967
int optind
Definition: epicsGetopt.c:50
#define SET_LOG_LEVEL(level)
Definition: logger.h:50
std::tr1::shared_ptr< const Structure > StructureConstPtr
Definition: pvIntrospect.h:162
#define NULL
Definition: catime.c:38
#define DEFAULT_TIMEOUT
Definition: pvlist.cpp:480
#define epicsScanDouble(str, to)
Definition: epicsStdlib.h:78
PVStructure::shared_pointer createRequest(std::string const &request)
void copy(PVValueArray< T > &pvFrom, size_t fromOffset, size_t fromStride, PVValueArray< T > &pvTo, size_t toOffset, size_t toStride, size_t count)
Copy a subarray from one scalar array to another.
int optopt
Definition: epicsGetopt.c:50
PVString is special case, since it implements SerializableArray.
Definition: pvData.h:521
template class for all extensions of PVArray.
Definition: pvData.h:55
#define stdout
Definition: epicsStdio.h:30
FORCE_INLINE const FieldCreatePtr & getFieldCreate()
#define stderr
Definition: epicsStdio.h:32
char * optarg
Definition: epicsGetopt.c:55
string inetAddressToString(const osiSockAddr &addr, bool displayPort, bool displayHex)
void usage(void)
Definition: cainfo.c:36
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
Definition: pvData.h:1648