Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JControlHostObjectIterator.hh
Go to the documentation of this file.
1#ifndef __JNET__JCONTROLHOSTOBJECTITERATOR__
2#define __JNET__JCONTROLHOSTOBJECTITERATOR__
3
4#include <string>
5#include <vector>
6
9#include "JLang/JTimeval.hh"
10#include "JIO/JByteArrayIO.hh"
11
12
13/**
14 * \author mdejong
15 */
16
17namespace JNET {}
18namespace JPP { using namespace JNET; }
19
20namespace JNET {
21
22 using JLANG::JTimeval;
24
25
26 /**
27 * Object iteration through ControlHost.
28 * This class implements the JLANG::JObjectIterator interface.
29 */
30 template<class T>
32 public JControlHost,
34 public JTimeval
35 {
36 public:
37 /**
38 * Constructor.
39 *
40 * \param server host name and optional port number
41 * \param subscription subscription
42 * \param timeout timeout
43 */
45 const JSubscription& subscription,
46 JTimeval timeout = JTimeval::max()) :
47 JControlHost(server),
48 JTimeval(timeout)
49 {
50 Subscribe(subscription);
51 }
52
53
54 /**
55 * Constructor.
56 *
57 * \param server host name and optional port number
58 * \param timeout timeout
59 * \param all subscribe all, subscribe any if false
60 */
62 JTimeval timeout = JTimeval::max(),
63 bool all = true) :
64 JControlHost(server),
65 JTimeval(timeout)
66 {
67 if (all) {
68 Subscribe(JSubscriptionAll(getTag<T>()));
69 } else {
70 Subscribe(JSubscriptionAny(getTag<T>()));
71 }
72 }
73
74
75 /**
76 * Set object.
77 *
78 * \param object reference to object to be set
79 * \return true if set; else false
80 */
81 virtual bool setObject(T& object) override
82 {
83 if (this->CheckHead(prefix, this->getTimeval()) > 0) {
84
85 buffer.resize(prefix.getSize());
86
87 this->GetFullData(buffer.data(), buffer.size());
88
89 JIO::JByteArrayReader in(buffer.data(), buffer.size());
90
91 in >> object;
92
93 return true;
94
95 } else {
96
97 return false;
98 }
99 }
100
101 private:
104 };
105}
106
107#endif
Byte array binary input.
Auxiliary class for time values.
Definition JTimeval.hh:29
const JTimeval & getTimeval() const
Get time value.
Definition JTimeval.hh:71
static JTimeval max()
Get maximal time value.
Definition JTimeval.hh:131
Object iteration through ControlHost.
JControlHostObjectIterator(const JHostname &server, const JSubscription &subscription, JTimeval timeout=JTimeval::max())
Constructor.
virtual bool setObject(T &object) override
Set object.
JControlHostObjectIterator(const JHostname &server, JTimeval timeout=JTimeval::max(), bool all=true)
Constructor.
ControlHost class.
int CheckHead(JPrefix &prefix, JTimeval timeout=JTimeval::min())
Check for header, without waiting.
int GetFullData(void *buffer, long long int length)
Receive data.
int Subscribe(const JSubscription &subscription)
Subscribe to single tag.
ControlHost prefix.
Definition JPrefix.hh:33
int getSize() const
Get size.
Definition JPrefix.hh:62
ControlHost subscription.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for hostname and port number.
Definition JHostname.hh:35
Auxiliary class for all subscription.
Auxiliary class for any subscription.