if(embedStylesPrinted != true) {document.write('');}var embedStylesPrinted = true;var content = '
Parsek EventLoop
cpp-qt
#include <boost/throw_exception.hpp>
#include <tpproto/tpsocket.h>
#include <parsekeventloop.h>
 
void boost::throw_exception(std::exception const & e) {
//do nothing
//occurs when (*signal)() call is empty - shouldn't occur
}
 
ParsekEventLoop::ParsekEventLoop()
{
//not needed to initialize
/*
readset();
writeset();
timers();
*/

}
 
ParsekEventLoop::~ParsekEventLoop()
{
/*Q_FOREACH(TPProto::TimerSignal *signal, timers)
delete signal;
*/

readset.clear();
writeset.clear();
timers.clear();
}
 
void ParsekEventLoop::listenForSocketRead(TPProto::TPSocket *sock)
{
int fd = sock->getFileDescriptor();
QSocketNotifier *notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
connect(notifier,SIGNAL(activated(int)),SLOT(activated_read(int)));
readset.insert(fd,ParsekSocket(sock,notifier));
}
 
void ParsekEventLoop::listenForSocketWrite(TPProto::TPSocket *sock)
{
int fd = sock->getFileDescriptor();
if (!writeset.contains(fd))
{
QSocketNotifier *notifier = new QSocketNotifier(fd, QSocketNotifier::Write, this);
//writeset[fd] = ParsekSocket(sock,notifier);
writeset.insert(fd,ParsekSocket(sock,notifier));
}
connect(writeset[fd].notifier, SIGNAL(activated(int)), SLOT(activated_write(int)));
}
 
 
TPProto::TimerConnection ParsekEventLoop::setTimer(uint32_t interval, const TPProto::TimerSignal::slot_type &callback)
{
TPProto::TimerSignal *signal = new TPProto::TimerSignal();
TPProto::TimerConnection tc = signal->connect(callback);
 
QTimer *timer = new QTimer(this);
//timers[timer] = signal;
timers.insert(timer,signal);
connect(timer,SIGNAL(timeout()),SLOT(timeout()));
timer->setSingleShot(true);
timer->start(interval*1000);
 
return tc;
}
 
void ParsekEventLoop::activated_read(int fd)
{
readset[fd].socket->readyToRead();
}
 
void ParsekEventLoop::activated_write(int fd)
{
writeset[fd].notifier->disconnect(this);
writeset[fd].socket->readyToSend();
}
 
void ParsekEventLoop::timeout()
{
QTimer *timeout = static_cast<QTimer*>(sender());
TPProto::TimerSignal *signal = new TPProto::TimerSignal();
signal = timers[timeout];
timers.remove(timeout);
(*signal)();
}
 
';document.write(content);