Brief description of class still missing. More...
#include <TimeRequest.h>
Public Member Functions | |
virtual bool | exec () |
TimeRequest (uint16_t port, int delay=2000) |
Brief description of class still missing.
Full description of class still missing
TimeRequest::TimeRequest | ( | uint16_t | port, |
int | delay = 2000 |
||
) |
Description of constructor still missing
References GpCoreTools::Timer::setInterval().
: Timer() { setInterval(delay); _port=port; loadHostNames(); }
bool TimeRequest::exec | ( | ) | [virtual] |
Sent data are packed in a MessageRaw structure (tag code, byte length and checksum). Payload contains a TimeData object
Implements GpCoreTools::Timer.
References GpCoreTools::MessageRaw< Payload >::buffer(), GpCoreTools::TcpClientStream::connect(), TimeData::currentTime(), GpCoreTools::Address::fromString(), GpCoreTools::MessageRaw< Payload >::littleEndianValues(), GpCoreTools::MessageRaw< Payload >::payload(), and GpCoreTools::TcpClientStream::write().
{ #pragma pack(1) MessageRaw<TimeData> msg; msg.payload().currentTime(); msg.littleEndianValues(); #pragma pack() updateHostList(); Log::write(0, "send time requests...\n"); Address peer; for(std::list<std::string>::iterator it=_activeHosts.begin(); it!=_activeHosts.end(); it++) { peer.fromString(it->data()); if(peer!=Address::me()) { TimeSlaveStream * l=new TimeSlaveStream(peer); if(l->connect(_port)) { l->write(msg.buffer(), sizeof(msg)); EventLoop::instance()->addStream(l); // Automatically deleted after hungup } else { delete l; } } } return true; // Repeat this request }