hlswmaster-ng/gamescanner.cpp

51 lines
866 B
C++
Raw Normal View History

2006-02-02 16:55:44 +01:00
#include "logging.h"
#include "timerservice.h"
#include "gamescanner.h"
#define DEFAULT_INTERVAL 30
GameScanner::GameScanner(Config& conf, ModuleList& modList)
: modList(modList)
{
msock = new MultiSock(conf);
pktCount = new Semaphore(0);
int interval = conf.getInteger("global", "scan_interval", DEFAULT_INTERVAL);
TimerService::registerTimer(new Timer(new ScanEvent(this), interval));
}
GameScanner::~GameScanner()
{
while (!pktList.isEmpty())
delete pktList.get();
delete pktCount;
delete msock;
}
int GameScanner::execute(void* arg)
{
while (1) {
int fd = msock->getRecvSocket();
NetPkt* pkt = NetPkt::createFromSocket(fd);
if (pkt != NULL) {
pktList.addTail(pkt);
pktCount->post();
}
}
return 0;
}
void GameScanner::scan()
{
modList.scan(msock);
}
NetPkt* GameScanner::getPkt()
{
pktCount->wait();
return pktList.get();
}