remove recvqueue.[ch]

- put pktlist in gamescanner
- let gameparser use this instead of recvqueue
This commit is contained in:
Olaf Rempel 2006-04-16 20:26:01 +02:00
parent 6cd4589640
commit 9e6e2a4d32
8 changed files with 34 additions and 66 deletions

View File

@ -6,7 +6,7 @@ LIBS := -lpthread
HLSWMASTER_SRC := config.o gameentry.o gamelist.o gameparser.o gamescanner.o \ HLSWMASTER_SRC := config.o gameentry.o gamelist.o gameparser.o gamescanner.o \
hlswmaster.o hlswserver.o logging.o modhelper.o modulelist.o \ hlswmaster.o hlswserver.o logging.o modhelper.o modulelist.o \
multisock.o netpkt.o recvqueue.o socket.o timerservice.o thread.o \ multisock.o netpkt.o socket.o timerservice.o thread.o \
mod_d3engine.o mod_gamespy1.o mod_gamespy2.o mod_halflife.o \ mod_d3engine.o mod_gamespy1.o mod_gamespy2.o mod_halflife.o \
mod_q3engine.o mod_quake2.o mod_ut.o mod_q3engine.o mod_quake2.o mod_ut.o
@ -31,7 +31,7 @@ dist: clean
--exclude hlswmaster-ng/.gitignore \ --exclude hlswmaster-ng/.gitignore \
--exclude hlswmaster-ng/doc \ --exclude hlswmaster-ng/doc \
--exclude hlswmaster-ng/hlswmaster-ng-$(VERSION).tar.gz \ --exclude hlswmaster-ng/hlswmaster-ng-$(VERSION).tar.gz \
--exclude hlswmaster-ng/hlswmaster-ng --exclude hlswmaster-ng/hlswmaster-ng
rm hlswmaster-ng rm hlswmaster-ng
clean: clean:

View File

@ -2,8 +2,8 @@
#include "netpkt.h" #include "netpkt.h"
#include "gameparser.h" #include "gameparser.h"
GameParser::GameParser(RecvQueue& rxQueue, ModuleList& modList, GameList& gameList) GameParser::GameParser(GameScanner& scanner, ModuleList& modList, GameList& gameList)
: rxQueue(rxQueue), modList(modList), gameList(gameList) : scanner(scanner), modList(modList), gameList(gameList)
{ {
} }
@ -14,7 +14,7 @@ int GameParser::execute(void* arg)
int ret; int ret;
while (1) { while (1) {
pkt = rxQueue.getPkt(); pkt = scanner.getPkt();
ret = modList.parse(pkt, &gameList); ret = modList.parse(pkt, &gameList);
switch (ret) { switch (ret) {

View File

@ -3,13 +3,13 @@
#include "thread.h" #include "thread.h"
#include "config.h" #include "config.h"
#include "recvqueue.h" #include "gamescanner.h"
#include "modulelist.h" #include "modulelist.h"
#include "gamelist.h" #include "gamelist.h"
class GameParser : public Thread { class GameParser : public Thread {
public: public:
GameParser(RecvQueue& rxQueue, ModuleList& modlist, GameList& gameList); GameParser(GameScanner& scanner, ModuleList& modlist, GameList& gameList);
~GameParser() {}; ~GameParser() {};
int execute(void* arg); int execute(void* arg);
@ -19,7 +19,7 @@ protected:
GameParser& operator=(const GameParser& rp); GameParser& operator=(const GameParser& rp);
private: private:
RecvQueue& rxQueue; GameScanner& scanner;
ModuleList& modList; ModuleList& modList;
GameList& gameList; GameList& gameList;
}; };

View File

@ -5,8 +5,8 @@
#define DEFAULT_SCAN_INTERVAL 30 #define DEFAULT_SCAN_INTERVAL 30
GameScanner::GameScanner(Config& conf, ModuleList& modList, RecvQueue& rxQueue) GameScanner::GameScanner(Config& conf, ModuleList& modList)
: modList(modList), rxQueue(rxQueue) : modList(modList)
{ {
msock = new MultiSock(conf); msock = new MultiSock(conf);
@ -16,6 +16,9 @@ GameScanner::GameScanner(Config& conf, ModuleList& modList, RecvQueue& rxQueue)
GameScanner::~GameScanner() GameScanner::~GameScanner()
{ {
while (!pktList.isEmpty())
delete pktList.get();
delete msock; delete msock;
} }
@ -23,8 +26,10 @@ int GameScanner::execute(void* arg)
{ {
while (1) { while (1) {
NetPkt* pkt = msock->recv(); NetPkt* pkt = msock->recv();
if (pkt) if (pkt != NULL) {
rxQueue.addPkt(pkt); pktList.add(pkt);
pktCount.post();
}
} }
return 0; return 0;
} }
@ -33,3 +38,9 @@ void GameScanner::scan()
{ {
modList.scan(msock); modList.scan(msock);
} }
NetPkt* GameScanner::getPkt()
{
pktCount.wait();
return pktList.get();
}

View File

@ -4,19 +4,22 @@
#include "thread.h" #include "thread.h"
#include "config.h" #include "config.h"
#include "modulelist.h" #include "modulelist.h"
#include "recvqueue.h"
#include "timerservice.h" #include "timerservice.h"
#include "multisock.h" #include "multisock.h"
#include "semaphore.h"
#include "list.h"
#include "netpkt.h"
class GameScanner : public Thread { class GameScanner : public Thread {
public: public:
GameScanner(Config& conf, ModuleList& modList, RecvQueue& rxQueue); GameScanner(Config& conf, ModuleList& modList);
~GameScanner(); ~GameScanner();
int execute(void* arg); int execute(void* arg);
void scan(); void scan();
NetPkt* getPkt();
protected: protected:
GameScanner(const GameScanner& hs); GameScanner(const GameScanner& hs);
GameScanner& operator=(const GameScanner& hs); GameScanner& operator=(const GameScanner& hs);
@ -33,8 +36,10 @@ private:
}; };
ModuleList& modList; ModuleList& modList;
RecvQueue& rxQueue;
MultiSock* msock; MultiSock* msock;
Semaphore pktCount;
LockedList<NetPkt> pktList;
}; };
#endif // _SCANNER_H_ #endif // _SCANNER_H_

View File

@ -5,7 +5,6 @@
#include "logging.h" #include "logging.h"
#include "config.h" #include "config.h"
#include "recvqueue.h"
#include "modulelist.h" #include "modulelist.h"
#include "gamelist.h" #include "gamelist.h"
#include "gamescanner.h" #include "gamescanner.h"
@ -89,12 +88,11 @@ int main(int argc, char *argv[])
LogSystem::log(LOG_EVERYTIME, "hlswmaster-ng %s startup (pid:%d)", VERSION, getpid()); LogSystem::log(LOG_EVERYTIME, "hlswmaster-ng %s startup (pid:%d)", VERSION, getpid());
conf.show(); conf.show();
RecvQueue rxQueue;
ModuleList modList(conf); ModuleList modList(conf);
GameList gameList(conf); GameList gameList(conf);
GameScanner scanner(conf, modList, rxQueue); GameScanner scanner(conf, modList);
GameParser parser(rxQueue, modList, gameList); GameParser parser(scanner, modList, gameList);
HlswServer server(conf, gameList); HlswServer server(conf, gameList);
modList.reg(new ModD3Engine()); modList.reg(new ModD3Engine());

View File

@ -1,21 +0,0 @@
#include "recvqueue.h"
RecvQueue::~RecvQueue()
{
while (!pktList.isEmpty())
delete pktList.get();
}
void RecvQueue::addPkt(NetPkt* pkt)
{
if (pkt != NULL) {
pktList.add(pkt);
pktCount.post();
}
}
NetPkt* RecvQueue::getPkt()
{
pktCount.wait();
return pktList.get();
}

View File

@ -1,25 +0,0 @@
#ifndef _RECVQUEUE_H_
#define _RECVQUEUE_H_
#include "netpkt.h"
#include "semaphore.h"
#include "list.h"
class RecvQueue {
public:
RecvQueue() {};
~RecvQueue();
void addPkt(NetPkt* pkt);
NetPkt* getPkt();
protected:
RecvQueue(const RecvQueue& rq);
RecvQueue& operator=(const RecvQueue& rq);
private:
Semaphore pktCount;
LockedList<NetPkt> pktList;
};
#endif // _RECVQUEUE_H_