Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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) 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
ControlHost prefix.
Definition: JPrefix.hh:31
virtual bool setObject(T &object) override
Set object.
ControlHost class.
int Subscribe(const JSubscription &subscription)
Subscribe to single tag.
const JTimeval & getTimeval() const
Get time value.
Definition: JTimeval.hh:71
Auxiliary data structure for hostname and port number.
Definition: JHostname.hh:30
JControlHostObjectIterator(const JHostname &server, JTimeval timeout=JTimeval::max(), bool all=true)
Constructor.
int getSize() const
Get size.
Definition: JPrefix.hh:62
Auxiliary class for time values.
Definition: JTimeval.hh:26
int CheckHead(JPrefix &prefix, JTimeval timeout=JTimeval::min())
Check for header, without waiting.
static JTimeval max()
Get maximal time value.
Definition: JTimeval.hh:131
Byte array binary input.
Definition: JByteArrayIO.hh:25
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Auxiliary class for any subscription.
Auxiliary class for all subscription.
Definition: JControlHost.hh:97
JControlHostObjectIterator(const JHostname &server, const JSubscription &subscription, JTimeval timeout=JTimeval::max())
Constructor.
Object iteration through ControlHost.
int GetFullData(void *buffer, long long int length)
Receive data.
ControlHost subscription.
Definition: JControlHost.hh:50
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36