#ifndef __JNET__JCONTROLHOSTOBJECTITERATOR__ #define __JNET__JCONTROLHOSTOBJECTITERATOR__ #include #include #include "JNet/JControlHost.hh" #include "JLang/JAbstractObjectIterator.hh" #include "JLang/JTimeval.hh" #include "JIO/JByteArrayIO.hh" /** * \author mdejong */ namespace JNET {} namespace JPP { using namespace JNET; } namespace JNET { using JLANG::JTimeval; using JLANG::JAbstractObjectIterator; /** * Object iteration through ControlHost. * This class implements the JLANG::JObjectIterator interface. */ template class JControlHostObjectIterator : public JControlHost, public JAbstractObjectIterator, public JTimeval { public: /** * Constructor. * * \param server host name and optional port number * \param subscription subscription * \param timeout timeout */ JControlHostObjectIterator(const JHostname& server, const JSubscription& subscription, JTimeval timeout = JTimeval::max()) : JControlHost(server), JTimeval(timeout) { Subscribe(subscription); } /** * Constructor. * * \param server host name and optional port number * \param timeout timeout * \param all subscribe all, subscribe any if false */ JControlHostObjectIterator(const JHostname& server, JTimeval timeout = JTimeval::max(), bool all = true) : JControlHost(server), JTimeval(timeout) { if (all) { Subscribe(JSubscriptionAll(getTag())); } else { Subscribe(JSubscriptionAny(getTag())); } } /** * Set object. * * \param object reference to object to be set * \return true if set; else false */ virtual bool setObject(T& object) override { if (this->CheckHead(prefix, this->getTimeval()) > 0) { buffer.resize(prefix.getSize()); this->GetFullData(buffer.data(), buffer.size()); JIO::JByteArrayReader in(buffer.data(), buffer.size()); in >> object; return true; } else { return false; } } private: JPrefix prefix; std::vector buffer; }; } #endif