hlswmaster-ng/gamelist.h

66 lines
1.1 KiB
C
Raw Normal View History

2006-02-02 16:55:44 +01:00
#ifndef _GAMELIST_H_
#define _GAMELIST_H_
2006-04-17 13:59:54 +02:00
#include <netinet/in.h>
2006-02-19 18:45:56 +01:00
#include "config.h"
2006-02-20 12:31:34 +01:00
#include "netpkt.h"
2006-03-05 02:28:19 +01:00
#include "gameentry.h"
2006-02-19 18:45:56 +01:00
#include "timerservice.h"
2006-03-05 02:28:19 +01:00
#include "list.h"
2006-04-15 19:55:07 +02:00
#include "mutex.h"
// 127 is prime!
#define MAX_BUCKETS 127
2006-02-02 16:55:44 +01:00
class GameList {
public:
2006-02-19 18:45:56 +01:00
GameList(Config& conf);
~GameList();
2006-03-07 20:30:11 +01:00
void cleanup();
2006-04-15 19:55:07 +02:00
void addGame(int gameid, NetPkt* pkt, int port2 = 0);
2006-04-17 13:59:54 +02:00
void addGame(int gameid, struct in_addr *addr, int port1, int port2 = 0);
2006-04-15 19:55:07 +02:00
Iterator<GameEntry>* createIterator();
2006-03-07 20:30:11 +01:00
2006-02-02 16:55:44 +01:00
protected:
2006-02-19 18:45:56 +01:00
GameList(const GameList& gl);
GameList& operator=(const GameList& gl);
private:
2006-02-20 21:58:59 +01:00
class CleanupEvent : public Event {
2006-02-19 18:45:56 +01:00
public:
2006-02-20 21:58:59 +01:00
CleanupEvent(GameList& gl) : gl(gl) {}
2006-02-19 18:45:56 +01:00
~CleanupEvent() {}
2006-02-20 21:58:59 +01:00
void execute() { gl.cleanup(); }
2006-03-05 02:28:19 +01:00
2006-02-19 18:45:56 +01:00
private:
2006-02-20 21:58:59 +01:00
GameList& gl;
2006-03-05 02:28:19 +01:00
};
2006-02-19 18:45:56 +01:00
2006-04-15 19:55:07 +02:00
class GameListIterator : public Iterator<GameEntry> {
public:
GameListIterator(GameList* gl);
~GameListIterator();
bool hasNext();
GameEntry* next();
void remove();
void reset();
private:
GameList* gl;
Iterator<GameEntry>* it;
int bucket;
};
Mutex mutex;
List<GameEntry> buckets[MAX_BUCKETS];
int timeout;
2006-04-17 13:35:50 +02:00
friend class GameList::GameListIterator;
2006-02-02 16:55:44 +01:00
};
#endif // _GAMELIST_H_