17 #include <epicsGetopt.h> 35 # define EXECNAME "pvget" 49 " deprecated options:\n" 50 " -q, -t, -i, -n, -F: ignored\n" 51 " -f <input file>: errors\n" 53 " -m -v: Monitor in Raw mode. Print only fields marked as changed.\n" 54 " -m -vv: Monitor in Raw mode. Highlight fields marked as changed, show all valid fields.\n" 55 " -m -vvv: Monitor in Raw mode. Highlight fields marked as changed, show all fields.\n" 56 " -vv: Get in Raw mode. Highlight valid fields, show all fields.\n" 70 op = channel.
get(
this, pvRequest);
76 std::cout<<std::setw(pvnamewidth)<<std::left<<op.
name()<<
' ';
79 std::cerr<<
"Error "<<
event.message<<
"\n";
85 pvd::PVStructure::Formatter fmt(event.
value->stream()
89 fmt.highlight(*event.
valid);
91 fmt.show(*event.
valid);
111 struct WorkQueue :
public epicsThreadRunable {
113 typedef std::tr1::shared_ptr<Worker> value_type;
114 typedef std::tr1::weak_ptr<Worker> weak_type;
117 typedef std::deque<std::pair<weak_type, pvac::MonitorEvent> > queue_t;
125 ,worker(pvd::Thread::Config()
126 .name(
"Monitor handler")
148 wake = queue.empty();
149 queue.push_back(std::make_pair(cb, evt));
164 queue_t::value_type ent(queue.front());
165 value_type cb(ent.first.lock());
171 cb->process(ent.second);
172 }
catch(std::exception& e){
173 std::cout<<
"Error in monitor handler : "<<e.what()<<
"\n";
184 public std::tr1::enable_shared_from_this<MonTracker>
190 ,mon(channel.
monitor(
this, pvRequest))
192 virtual ~MonTracker() {mon.cancel();}
207 monwork.push(shared_from_this(), evt);
215 std::cerr<<std::setw(pvnamewidth)<<std::left<<mon.
name()<<
" Error "<<evt.
message<<
"\n";
222 std::cout<<std::setw(pvnamewidth)<<std::left<<mon.
name()<<
" <Disconnect>\n";
228 for(n=0; n<2 && mon.
poll(); n++) {
231 pvd::PVStructure::Formatter fmt(mon.
root->stream()
237 fmt.highlight(mon.
changed).show(valid);
241 std::cout<<std::setw(pvnamewidth)<<std::left<<mon.
name()<<
' '<<fmt;
245 monwork.push(shared_from_this(), evt);
265 int MAIN (
int argc,
char *argv[])
272 bool monitor =
false;
279 while ((opt =
getopt(argc, argv,
":hvVRM:r:w:tmp:qdcF:f:ni")) != -1) {
289 fprintf(
stdout,
"pvAccess %u.%u.%u%s\n",
290 EPICS_PVA_MAJOR_VERSION,
291 EPICS_PVA_MINOR_VERSION,
292 EPICS_PVA_MAINTENANCE_VERSION,
293 (EPICS_PVA_DEVELOPMENT_FLAG)?
"-SNAPSHOT":
"");
294 fprintf(
stdout,
"pvData %u.%u.%u%s\n",
295 EPICS_PVD_MAJOR_VERSION,
296 EPICS_PVD_MINOR_VERSION,
297 EPICS_PVD_MAINTENANCE_VERSION,
298 (EPICS_PVD_DEVELOPMENT_FLAG)?
"-SNAPSHOT":
"");
299 fprintf(
stdout,
"Base %s\n", EPICS_VERSION_FULL);
306 if(strcmp(
optarg,
"raw")==0) {
307 outmode = pvd::PVStructure::Formatter::Raw;
308 }
else if(strcmp(
optarg,
"nt")==0) {
309 outmode = pvd::PVStructure::Formatter::NT;
310 }
else if(strcmp(
optarg,
"json")==0) {
311 outmode = pvd::PVStructure::Formatter::JSON;
314 outmode = pvd::PVStructure::Formatter::Raw;
322 fprintf(
stderr,
"'%s' is not a valid timeout value " 340 fprintf(
stderr,
"Unsupported option -f\n");
355 "Unrecognized option: '-%c'. ('" EXECNAME " -h' for help.)\n",
360 "Option '-%c' requires an argument. ('" EXECNAME " -h' for help.)\n",
373 outmode = pvd::PVStructure::Formatter::Raw;
375 pvd::PVStructure::shared_pointer pvRequest;
378 }
catch(std::exception& e){
379 fprintf(
stderr,
"failed to parse request string: %s\n", e.what());
384 pvnamewidth =
std::max(pvnamewidth, strlen(argv[
i]));
394 std::vector<std::tr1::shared_ptr<Tracker> > tracked;
396 epics::auto_ptr<WorkQueue> Q;
404 std::tr1::shared_ptr<MonTracker> mon(
new MonTracker(*Q, chan, pvRequest));
406 tracked.push_back(mon);
409 std::tr1::shared_ptr<Getter>
get(
new Getter(chan, pvRequest));
411 tracked.push_back(
get);
420 std::cerr<<
"Waiting...\n";
430 std::cerr<<
"Timeout\n";
437 if(refmon.running()) {
448 return haderror ? 1 : 0;
449 }
catch(std::exception& e) {
450 std::cerr<<
"Error: "<<e.what()<<
"\n";
std::string message
set for event=Fail
int getopt(int nargc, char *const *nargv, const char *ostr)
virtual void getDone(const GetEvent &evt)=0
get or rpc operation is complete
static epicsMutex doneLock
BitSet & clear(uint32 bitIndex)
Information on get/rpc completion.
std::string name() const
Channel name.
#define SET_LOG_LEVEL(level)
static epicsEvent doneEvt
subscription interrupted due to loss of communication
Operation get(GetCallback *cb, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
Handle for monitor subscription.
callback for get() and rpc()
#define epicsScanDouble(str, to)
PVStructure::shared_pointer createRequest(std::string const &request)
Handle for in-progress get/put/rpc operation.
subscription ends in cancellation
epics::pvData::PVStructure::const_shared_pointer root
epics::pvData::PVStructure::const_shared_pointer value
New data. NULL unless event==Success.
#define LOG(level, format,...)
epics::pvData::BitSet::const_shared_pointer valid
#define POINTER_DEFINITIONS(clazz)
enum pvac::PutEvent::event_t event
Extended replacement for the Posix exit and atexit routines.
request cancelled before completion
std::tr1::shared_ptr< PVStructure > PVStructurePtr
std::string name() const
Channel name.
Information on monitor subscription/queue change.
ClientChannel connect(const std::string &name, const ClientChannel::Options &conf=ClientChannel::Options())
request ends in failure. Check message
enum pvac::MonitorEvent::event_t event
C++ wrapper for epicsThread from EPICS base.
ChannelPut::shared_pointer op
Data queue not empty. Call Monitor::poll()
Monitor event notification.
epics::pvData::BitSet changed
static void start()
start provider ca
std::string defaultProvider
pvd::PVStructure::Formatter::format_t outmode
subscription ends in an error
Monitor monitor(MonitorCallback *cb, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())