[5521] | 1 | /*! |
---|
| 2 | * @file network_manager.h |
---|
| 3 | * Main interface for the network module. Manages all the modules |
---|
| 4 | */ |
---|
| 5 | |
---|
[5533] | 6 | /* you will want to add such a a line at your header file also, since it will |
---|
| 7 | prevent c++ from including your code twice*/ |
---|
[5521] | 8 | #ifndef _NETWORK_MANGER |
---|
| 9 | #define _NETWORK_MANAGER |
---|
| 10 | |
---|
[5647] | 11 | /* include this file, it contains some default definitions */ |
---|
| 12 | #include "netdefs.h" |
---|
[5533] | 13 | |
---|
| 14 | /* include base_object.h since all classes are derived from this one */ |
---|
[5521] | 15 | #include "base_object.h" |
---|
| 16 | |
---|
[5647] | 17 | |
---|
[5572] | 18 | /* forward declarations for the header file (include the header via #include "bla.h" in the source file) */ |
---|
[5566] | 19 | class NetworkStream; |
---|
[5572] | 20 | class Synchronizeable; |
---|
[5996] | 21 | template<typename> |
---|
| 22 | class tList; |
---|
[5521] | 23 | |
---|
[5566] | 24 | /* and here is the class itsself*/ |
---|
[5521] | 25 | class NetworkManager : public BaseObject |
---|
| 26 | { |
---|
| 27 | |
---|
[5996] | 28 | public: |
---|
[5521] | 29 | |
---|
[5996] | 30 | inline static NetworkManager* getInstance() { if (!NetworkManager::singletonRef) NetworkManager::singletonRef = new NetworkManager(); |
---|
| 31 | return NetworkManager::singletonRef; } |
---|
| 32 | ~NetworkManager(); |
---|
[5533] | 33 | |
---|
[5996] | 34 | void initialize(); |
---|
| 35 | void shutdown(); |
---|
[5804] | 36 | |
---|
[5996] | 37 | int establishConnection(const char* name, unsigned int port); |
---|
| 38 | int createServer(unsigned int port); |
---|
[5804] | 39 | |
---|
[5996] | 40 | NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync); |
---|
| 41 | NetworkStream& createServer(Synchronizeable& sync, unsigned int port); |
---|
| 42 | void shutdownConnection(); |
---|
[5533] | 43 | |
---|
[5996] | 44 | |
---|
[5997] | 45 | void setHostID(int id); |
---|
| 46 | /** Returns the hostID @return The hostID of the object */ |
---|
[6139] | 47 | inline int getHostID() { return this->hostID; } |
---|
| 48 | inline bool isGameServer() { return this->bGameServer; } |
---|
[5997] | 49 | |
---|
[6139] | 50 | |
---|
[5996] | 51 | void connectSynchronizeable(Synchronizeable& sync); |
---|
| 52 | void synchronize(); |
---|
[5804] | 53 | |
---|
[6139] | 54 | private: |
---|
[5996] | 55 | NetworkManager(); |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | private: |
---|
[6139] | 59 | const std::list<BaseObject*>* netStreamList; // list with refs to all network streams |
---|
| 60 | const std::list<BaseObject*>* syncList; // list of synchronizeables |
---|
| 61 | static NetworkManager* singletonRef; //!< Pointer to the only instance of this Class |
---|
| 62 | NetworkStream* tmpStream; //!< FIXME: this is only for testing purposes |
---|
| 63 | int hostID; //!< The Host-ID of the Manager |
---|
| 64 | bool bGameServer; //!< true if it is a server |
---|
[5996] | 65 | |
---|
[5521] | 66 | }; |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | #endif /* _NETWORK_MANAGER */ |
---|