pvAccessCPP 7.1.8
Loading...
Searching...
No Matches
client.h
1/*
2 * Copyright information and license terms for this software can be
3 * found in the file LICENSE that is included with the distribution
4 */
5#ifndef PVATESTCLIENT_H
6#define PVATESTCLIENT_H
7
8#include <ostream>
9#include <stdexcept>
10#include <list>
11
12#include <epicsMutex.h>
13
14#include <pv/pvData.h>
15#include <pv/bitSet.h>
16
17class epicsEvent;
18
19namespace epics {namespace pvAccess {
20class ChannelProvider;
21class Channel;
22class Monitor;
23class Configuration;
24}}//namespace epics::pvAccess
25
27namespace pvac {
28
47class ClientProvider;
48
50struct epicsShareClass Operation
51{
52 struct Impl
53 {
54 virtual ~Impl() {}
55 virtual std::string name() const =0;
56 virtual void cancel() =0;
57 virtual void show(std::ostream&) const =0;
58 };
59
60 Operation() {}
61 Operation(const std::tr1::shared_ptr<Impl>&);
62 ~Operation();
64 std::string name() const;
67 void cancel();
68
69 bool valid() const { return !!impl; }
70
71#if __cplusplus>=201103L
72 explicit operator bool() const { return valid(); }
73#else
74private:
75 typedef bool (Operation::*bool_type)() const;
76public:
77 operator bool_type() const { return valid() ? &Operation::valid : 0; }
78#endif
79
80 void reset() { impl.reset(); }
81
82protected:
83 friend epicsShareFunc ::std::ostream& operator<<(::std::ostream& strm, const Operation& op);
84 std::tr1::shared_ptr<Impl> impl;
85};
86
88struct epicsShareClass PutEvent
89{
90 enum event_t {
94 } event;
95 std::string message;
96};
97
99struct epicsShareClass GetEvent : public PutEvent
100{
102 epics::pvData::PVStructure::const_shared_pointer value;
105 epics::pvData::BitSet::const_shared_pointer valid;
106};
107
108struct epicsShareClass InfoEvent : public PutEvent
109{
112};
113
114struct MonitorSync;
115
117struct epicsShareClass Monitor
118{
119 struct Impl;
120 Monitor() {}
121 Monitor(const std::tr1::shared_ptr<Impl>&);
122 ~Monitor();
123
125 std::string name() const;
127
132 void cancel();
141 bool poll();
144 bool complete() const;
160 epics::pvData::PVStructure::const_shared_pointer root;
161 epics::pvData::BitSet changed,
162 overrun;
163
164 bool valid() const { return !!impl; }
165
166#if __cplusplus>=201103L
167 explicit operator bool() const { return valid(); }
168#else
169private:
170 typedef bool (Monitor::*bool_type)() const;
171public:
172 operator bool_type() const { return valid() ? &Monitor::valid : 0; }
173#endif
174
175 void reset() { impl.reset(); }
176
177private:
178 std::tr1::shared_ptr<Impl> impl;
179 friend epicsShareFunc ::std::ostream& operator<<(::std::ostream& strm, const Monitor& op);
180 friend struct MonitorSync;
181};
182
185{
186 enum event_t {
191 } event;
192 std::string message;
193};
194
206struct epicsShareClass MonitorSync : public Monitor
207{
208 struct SImpl;
209 MonitorSync() {}
210 MonitorSync(const Monitor&, const std::tr1::shared_ptr<SImpl>&);
211 ~MonitorSync();
212
216 bool wait();
219 bool wait(double timeout);
222 bool test();
223
227 void wake();
228
232private:
233 std::tr1::shared_ptr<SImpl> simpl;
234};
235
238{
243 std::string peerName;
244};
245
248{
249 Timeout();
250};
251
252namespace detail {
253class PutBuilder;
254void registerRefTrack();
255}
256
266class epicsShareClass ClientChannel
267{
268#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 305)
269public:
270 // Impl is public only as a workaround on older GCC
271#endif
272 struct Impl;
273private:
274 std::tr1::shared_ptr<Impl> impl;
275 friend class ClientProvider;
276 friend void detail::registerRefTrack();
277 friend epicsShareFunc ::std::ostream& operator<<(::std::ostream& strm, const ClientChannel& op);
278
279 ClientChannel(const std::tr1::shared_ptr<Impl>& i) :impl(i) {}
280public:
282 struct epicsShareClass Options {
283 short priority;
284 std::string address;
285 Options();
286 bool operator<(const Options&) const;
287 };
288
297 ClientChannel(const std::tr1::shared_ptr<epics::pvAccess::ChannelProvider>& provider,
298 const std::string& name,
299 const Options& opt = Options());
301
303 std::string name() const;
304
305 bool valid() const { return !!impl; }
306
307#if __cplusplus>=201103L
308 explicit operator bool() const { return valid(); }
309#else
310private:
311 typedef bool (ClientChannel::*bool_type)() const;
312public:
313 operator bool_type() const { return valid() ? &ClientChannel::valid : 0; }
314#endif
315
316 void reset() { impl.reset(); }
317
319 struct GetCallback {
320 virtual ~GetCallback() {}
322 virtual void getDone(const GetEvent& evt)=0;
323 };
324
329 epics::pvData::PVStructure::const_shared_pointer pvRequest = epics::pvData::PVStructure::const_shared_pointer());
330
335 epics::pvData::PVStructure::const_shared_pointer
336 get(double timeout = 3.0,
337 epics::pvData::PVStructure::const_shared_pointer pvRequest = epics::pvData::PVStructure::const_shared_pointer());
338
339
345 const epics::pvData::PVStructure::const_shared_pointer& arguments,
346 epics::pvData::PVStructure::const_shared_pointer pvRequest = epics::pvData::PVStructure::const_shared_pointer());
347
352 epics::pvData::PVStructure::const_shared_pointer
353 rpc(double timeout,
354 const epics::pvData::PVStructure::const_shared_pointer& arguments,
355 epics::pvData::PVStructure::const_shared_pointer pvRequest = epics::pvData::PVStructure::const_shared_pointer());
356
358 struct PutCallback {
359 virtual ~PutCallback() {}
360 struct Args {
361 Args(epics::pvData::BitSet& tosend, epics::pvData::BitSet& previousmask) :tosend(tosend), previousmask(previousmask) {}
363 epics::pvData::PVStructure::const_shared_pointer root;
365 epics::pvData::BitSet& tosend;
371 epics::pvData::PVStructure::const_shared_pointer previous;
374 const epics::pvData::BitSet& previousmask;
375 };
383 virtual void putBuild(const epics::pvData::StructureConstPtr& build, Args& args) =0;
385 virtual void putDone(const PutEvent& evt)=0;
386 };
387
395 epics::pvData::PVStructure::const_shared_pointer pvRequest = epics::pvData::PVStructure::const_shared_pointer(),
396 bool getprevious = false);
397
399 inline
400 detail::PutBuilder put(const epics::pvData::PVStructure::const_shared_pointer &pvRequest = epics::pvData::PVStructure::const_shared_pointer());
401
404 virtual ~MonitorCallback() {}
412 virtual void monitorEvent(const MonitorEvent& evt)=0;
413 };
414
418 epics::pvData::PVStructure::const_shared_pointer pvRequest = epics::pvData::PVStructure::const_shared_pointer());
419
430 MonitorSync monitor(const epics::pvData::PVStructure::const_shared_pointer& pvRequest = epics::pvData::PVStructure::const_shared_pointer(),
431 epicsEvent *event =0);
432
433 struct InfoCallback {
434 virtual ~InfoCallback() {}
436 virtual void infoDone(const InfoEvent& evt) =0;
437 };
438
441 Operation info(InfoCallback *cb, const std::string& subfld = std::string());
442
444 epics::pvData::FieldConstPtr info(double timeout = 3.0,
445 const std::string& subfld = std::string());
446
449 virtual ~ConnectCallback() {}
450 virtual void connectEvent(const ConnectEvent& evt)=0;
451 };
457
458 void show(std::ostream& strm) const;
459private:
460 std::tr1::shared_ptr<epics::pvAccess::Channel> getChannel();
461};
462
463namespace detail {
464
467class epicsShareClass PutBuilder {
468 ClientChannel& channel;
469 epics::pvData::PVStructure::const_shared_pointer request;
470
471 template<typename V>
472 struct triple {
473 std::string name;
474 bool required;
475 V value;
476 triple(const std::string& name, const V& value, bool required =true)
477 :name(name), required(required), value(value)
478 {}
479 };
480
482 scalars_t scalars;
483
485 arrays_t arrays;
486
487 struct Exec;
488
489 friend class pvac::ClientChannel;
490 PutBuilder(ClientChannel& channel, const epics::pvData::PVStructure::const_shared_pointer& request)
491 :channel(channel), request(request)
492 {}
493public:
494 PutBuilder& set(const std::string& name, const epics::pvData::AnyScalar& value, bool required=true) {
495 scalars.push_back(scalars_t::value_type(name, value, required));
496 return *this;
497 }
498 template<typename T>
499 PutBuilder& set(const std::string& name, T value, bool required=true) {
500 return set(name, epics::pvData::AnyScalar(value), required);
501 }
502 PutBuilder& set(const std::string& name, const epics::pvData::shared_vector<const void>& value, bool required=true) {
503 arrays.push_back(arrays_t::value_type(name, value, required));
504 return *this;
505 }
506 template<typename T>
507 PutBuilder& set(const std::string& name, const epics::pvData::shared_vector<const T>& value, bool required=true) {
508 return set(name, epics::pvData::static_shared_vector_cast<const void>(value), required);
509 }
510 void exec(double timeout=3.0);
511};
512
513
514}// namespace detail
515
517class epicsShareClass ClientProvider
518{
519 struct Impl;
520 std::tr1::shared_ptr<Impl> impl;
521 friend void detail::registerRefTrack();
522 friend epicsShareFunc ::std::ostream& operator<<(::std::ostream& strm, const ClientProvider& op);
523public:
524
534 ClientProvider(const std::string& providerName,
535 const std::tr1::shared_ptr<epics::pvAccess::Configuration>& conf = std::tr1::shared_ptr<epics::pvAccess::Configuration>());
536 explicit ClientProvider(const std::tr1::shared_ptr<epics::pvAccess::ChannelProvider>& provider);
538
539 std::string name() const;
540
547 ClientChannel connect(const std::string& name,
549
551 bool disconnect(const std::string& name,
553
556
557 bool valid() const { return !!impl; }
558
559#if __cplusplus>=201103L
560 explicit operator bool() const { return valid(); }
561#else
562private:
563 typedef bool (ClientProvider::*bool_type)() const;
564public:
565 operator bool_type() const { return valid() ? &ClientProvider::valid : 0; }
566#endif
567
568 void reset() { impl.reset(); }
569};
570
571
572
573detail::PutBuilder
574ClientChannel::put(const epics::pvData::PVStructure::const_shared_pointer& pvRequest)
575{
576 return detail::PutBuilder(*this, pvRequest);
577}
578
579epicsShareFunc ::std::ostream& operator<<(::std::ostream& strm, const Operation& op);
580epicsShareFunc ::std::ostream& operator<<(::std::ostream& strm, const Monitor& op);
581epicsShareFunc ::std::ostream& operator<<(::std::ostream& strm, const ClientChannel& op);
582epicsShareFunc ::std::ostream& operator<<(::std::ostream& strm, const ClientProvider& op);
583
585
586}//namespace pvac
587
588#endif // PVATESTCLIENT_H
basic_ostream< _CharT, _Traits > & operator<<(basic_ostream< _CharT, _Traits > &__os, const basic_string< _CharT, _Traits, _Alloc > &__str)
bool operator<(const _CharT *__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
void push_back(const value_type &__x)
Represents a single channel.
Definition client.h:267
void removeConnectListener(ConnectCallback *)
Remove from list of listeners.
Operation info(InfoCallback *cb, const std::string &subfld=std::string())
Request PV type info.
void addConnectListener(ConnectCallback *)
Append to list of listeners.
epics::pvData::PVStructure::const_shared_pointer get(double timeout=3.0, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
Block and retrieve current PV value.
epics::pvData::FieldConstPtr info(double timeout=3.0, const std::string &subfld=std::string())
Synchronious getField opreation.
std::string name() const
Channel name or an empty string.
Operation rpc(GetCallback *cb, const epics::pvData::PVStructure::const_shared_pointer &arguments, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
Start an RPC call.
Operation get(GetCallback *cb, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
Issue request to retrieve current PV value.
Operation put(PutCallback *cb, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer(), bool getprevious=false)
Initiate request to change PV.
ClientChannel(const std::tr1::shared_ptr< epics::pvAccess::ChannelProvider > &provider, const std::string &name, const Options &opt=Options())
Construct a ClientChannel using epics::pvAccess::ChannelProvider::createChannel()
Monitor monitor(MonitorCallback *cb, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
Begin subscription.
ClientChannel()
Construct a null channel. All methods throw. May later be assigned from a valid ClientChannel.
Definition client.h:290
epics::pvData::PVStructure::const_shared_pointer rpc(double timeout, const epics::pvData::PVStructure::const_shared_pointer &arguments, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
Block and execute remote call.
MonitorSync monitor(const epics::pvData::PVStructure::const_shared_pointer &pvRequest=epics::pvData::PVStructure::const_shared_pointer(), epicsEvent *event=0)
Begin subscription w/o callbacks.
Central client context.
Definition client.h:518
void disconnect()
Clear channel cache.
ClientProvider(const std::string &providerName, const std::tr1::shared_ptr< epics::pvAccess::Configuration > &conf=std::tr1::shared_ptr< epics::pvAccess::Configuration >())
Use named provider.
ClientChannel connect(const std::string &name, const ClientChannel::Options &conf=ClientChannel::Options())
Get a new Channel.
ClientProvider()
Construct a null provider. All methods throw. May later be assigned from a valid ClientProvider.
Definition client.h:526
bool disconnect(const std::string &name, const ClientChannel::Options &conf=ClientChannel::Options())
Remove from channel cache.
Helper to accumulate values to for a Put operation.
Definition client.h:467
std::tr1::shared_ptr< const Structure > StructureConstPtr
std::tr1::shared_ptr< const Field > FieldConstPtr
Copyright - See the COPYRIGHT that is included with this distribution.
See Client API API.
Definition client.h:27
Connection state change CB.
Definition client.h:448
callback for get() and rpc()
Definition client.h:319
virtual void getDone(const GetEvent &evt)=0
get or rpc operation is complete
Monitor event notification.
Definition client.h:403
virtual void monitorEvent(const MonitorEvent &evt)=0
New monitor event.
Channel creation options.
Definition client.h:282
callbacks for put()
Definition client.h:358
virtual void putDone(const PutEvent &evt)=0
Put operation is complete.
virtual void putBuild(const epics::pvData::StructureConstPtr &build, Args &args)=0
Server provides expected structure.
information on connect/disconnect
Definition client.h:238
std::string peerName
For connection events.
Definition client.h:243
bool connected
Is this a connection, or disconnection, event.
Definition client.h:240
Information on get/rpc completion.
Definition client.h:100
epics::pvData::BitSet::const_shared_pointer valid
Mask of fields in value which have been initialized by the server.
Definition client.h:105
epics::pvData::PVStructure::const_shared_pointer value
New data. NULL unless event==Success.
Definition client.h:102
Information on monitor subscription/queue change.
Definition client.h:185
@ Fail
subscription ends in an error
Definition client.h:187
@ Cancel
subscription ends in cancellation
Definition client.h:188
@ Data
Data queue not empty. Call Monitor::poll()
Definition client.h:190
@ Disconnect
subscription interrupted due to loss of communication
Definition client.h:189
std::string message
set for event=Fail
Definition client.h:192
Handle for monitor subscription.
Definition client.h:118
bool complete() const
true if all events received.
bool poll()
updates root, changed, overrun
std::string name() const
Channel name.
void cancel()
Immediate cancellation.
epics::pvData::PVStructure::const_shared_pointer root
Monitor update data.
Definition client.h:160
Subscription usable w/o callbacks.
Definition client.h:207
bool wait()
wait for new event
bool test()
check if new event is immediately available.
bool wait(double timeout)
wait for new event
void wake()
Abort one call to wait(), either concurrent or future.
MonitorEvent event
most recent event updated only during wait() or poll()
Definition client.h:231
Handle for in-progress get/put/rpc operation.
Definition client.h:51
std::string name() const
Channel name.
void cancel()
Immediate cancellation.
Information on put completion.
Definition client.h:89
std::string message
Check when event==Fail.
Definition client.h:95
@ Fail
request ends in failure. Check message
Definition client.h:91
@ Success
It worked!
Definition client.h:93
@ Cancel
request cancelled before completion
Definition client.h:92
Thrown by blocking methods of ClientChannel on operation timeout.
Definition client.h:248