pvAccessCPP
7.1.9
Toggle main menu visibility
Loading...
Searching...
No Matches
Simple Client Monitor Example
The shortest possible PVA monitor() example.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
// The simplest possible PVA monitor
#include <
iostream
>
#if !defined(_WIN32)
#include <signal.h>
#define USE_SIGNAL
#endif
#include <epicsEvent.h>
#include <pva/client.h>
static
volatile
bool
done;
#ifdef USE_SIGNAL
static
pvac::MonitorSync
*
volatile
subscription;
static
void
handler(
int
num)
{
(void)num;
done =
true
;
pvac::MonitorSync
*mon = subscription;
if
(mon)
mon->
wake
();
}
#endif
int
main(
int
argc,
char
*argv[])
{
try
{
if
(argc<=1) {
std::cerr
<<
"Usage: "
<<argv[0]<<
" <pvname>\n"
;
return
1;
}
pvac::ClientProvider
provider(
"pva"
);
pvac::ClientChannel
channel(provider.connect(argv[1]));
pvac::MonitorSync
mon(channel.monitor());
#ifdef USE_SIGNAL
subscription = &mon;
signal(SIGINT, handler);
signal(SIGTERM, handler);
signal(SIGQUIT, handler);
#endif
int
ret = 0;
while
(!done) {
if
(!mon.
wait
())
// updates mon.event
continue
;
switch
(mon.
event
.event) {
// Subscription network/internal error
case
pvac::MonitorEvent::Fail
:
std::cerr
<<mon.
name
()<<
" : Error : "
<<mon.
event
.
message
<<
"\n"
;
ret = 1;
done =
true
;
break
;
// explicit call of 'mon.cancel' or subscription dropped
case
pvac::MonitorEvent::Cancel
:
std::cout
<<mon.
name
()<<
" <Cancel>\n"
;
done =
true
;
break
;
// Underlying channel becomes disconnected
case
pvac::MonitorEvent::Disconnect
:
std::cout
<<mon.
name
()<<
" <Disconnect>\n"
;
break
;
// Data queue becomes not-empty
case
pvac::MonitorEvent::Data
:
// We drain event FIFO completely
while
(mon.
poll
()) {
std::cout
<<mon.
name
()<<
" : "
<<mon.
root
;
}
// check to see if more events might be sent
if
(mon.
complete
()) {
done =
true
;
std::cout
<<mon.
name
()<<
" : <Complete>\n"
;
}
break
;
}
}
#ifdef USE_SIGNAL
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
subscription = 0;
#endif
return
ret;
}
catch
(
std::exception
& e){
std::cerr
<<
"Error: "
<<e.
what
()<<
"\n"
;
return
1;
}
}
iostream
std::cerr
ostream cerr
std::cout
ostream cout
std::exception
std::exception::what
virtual const char * what() const noexcept
pvac::ClientChannel
Represents a single channel.
Definition
client.h:267
pvac::ClientProvider
Central client context.
Definition
client.h:518
pvac::MonitorEvent::Fail
@ Fail
subscription ends in an error
Definition
client.h:187
pvac::MonitorEvent::Cancel
@ Cancel
subscription ends in cancellation
Definition
client.h:188
pvac::MonitorEvent::Data
@ Data
Data queue not empty. Call Monitor::poll().
Definition
client.h:190
pvac::MonitorEvent::Disconnect
@ Disconnect
subscription interrupted due to loss of communication
Definition
client.h:189
pvac::MonitorEvent::message
std::string message
set for event=Fail
Definition
client.h:192
pvac::Monitor::complete
bool complete() const
pvac::Monitor::poll
bool poll()
updates root, changed, overrun
pvac::Monitor::name
std::string name() const
Channel name.
pvac::Monitor::root
epics::pvData::PVStructure::const_shared_pointer root
Monitor update data.
Definition
client.h:160
pvac::MonitorSync
Subscription usable w/o callbacks.
Definition
client.h:207
pvac::MonitorSync::wait
bool wait()
pvac::MonitorSync::wake
void wake()
pvac::MonitorSync::event
MonitorEvent event
Definition
client.h:231
Generated on
for pvAccessCPP by
1.17.0