Jpp
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 
7 #include "JNet/JControlHost.hh"
9 #include "JLang/JTimeval.hh"
10 #include "JIO/JByteArrayIO.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JNET {}
18 namespace JPP { using namespace JNET; }
19 
20 namespace 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,
33  public JAbstractObjectIterator<T>,
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)
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
JLANG::JAbstractObjectIterator::object
T object
object
Definition: JAbstractObjectIterator.hh:34
JLANG::JTimeval
Auxiliary class for time values.
Definition: JTimeval.hh:26
JLANG::JTimeval::getTimeval
const JTimeval & getTimeval() const
Get time value.
Definition: JTimeval.hh:71
JNET::JPrefix
ControlHost prefix.
Definition: JPrefix.hh:31
JAbstractObjectIterator.hh
JNET::JControlHostObjectIterator::JControlHostObjectIterator
JControlHostObjectIterator(const JHostname &server, const JSubscription &subscription, JTimeval timeout=JTimeval::max())
Constructor.
Definition: JControlHostObjectIterator.hh:44
JNET::JSubscriptionAny
Auxiliary class for any subscription.
Definition: JControlHost.hh:113
JNET::JControlHostObjectIterator
Object iteration through ControlHost.
Definition: JControlHostObjectIterator.hh:31
std::vector< char >
JNET::JControlHost::GetFullData
int GetFullData(void *buffer, long long int length)
Receive data.
Definition: JControlHost.hh:602
JNET
Interprocess communication.
Definition: JDataFilter.cc:67
JLANG::JTimeval::max
static JTimeval max()
Get maximal time value.
Definition: JTimeval.hh:131
JNET::JHostname
Auxiliary data structure for hostname and port number.
Definition: JHostname.hh:30
JIO::JByteArrayReader
Byte array binary input.
Definition: JByteArrayIO.hh:25
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JNET::JControlHostObjectIterator::setObject
virtual bool setObject(T &object)
Set object.
Definition: JControlHostObjectIterator.hh:81
JNET::JSubscription
ControlHost subscription.
Definition: JControlHost.hh:49
JLANG::JAbstractObjectIterator
Abstract object iterator.
Definition: JAbstractObjectIterator.hh:23
JNET::JControlHost
ControlHost class.
Definition: JControlHost.hh:247
JTimeval.hh
JNET::JControlHostObjectIterator::buffer
std::vector< char > buffer
Definition: JControlHostObjectIterator.hh:103
JByteArrayIO.hh
JControlHost.hh
JNET::JControlHostObjectIterator::JControlHostObjectIterator
JControlHostObjectIterator(const JHostname &server, JTimeval timeout=JTimeval::max(), bool all=true)
Constructor.
Definition: JControlHostObjectIterator.hh:61
JNET::JControlHost::Subscribe
int Subscribe(const JSubscription &subscription)
Subscribe to single tag.
Definition: JControlHost.hh:363
JNET::JControlHostObjectIterator::prefix
JPrefix prefix
Definition: JControlHostObjectIterator.hh:102
JNET::JControlHost::CheckHead
int CheckHead(JPrefix &prefix, JTimeval timeout=JTimeval::min())
Check for header, without waiting.
Definition: JControlHost.hh:553
JNET::JPrefix::getSize
int getSize() const
Get size.
Definition: JPrefix.hh:62
JNET::JSubscriptionAll
Auxiliary class for all subscription.
Definition: JControlHost.hh:96