Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/network_manager.h @ 6673

Last change on this file since 6673 was 6673, checked in by patrick, 18 years ago

newtork: now only entities created on the server get a valiable uniqueID

File size: 2.5 KB
Line 
1/*!
2 * @file network_manager.h
3  *  Main interface for the network module. Manages all the modules
4*/
5
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*/
8#ifndef _NETWORK_MANGER
9#define _NETWORK_MANAGER
10
11/* include this file, it contains some default definitions */
12#include "netdefs.h"
13
14/* include base_object.h since all classes are derived from this one */
15#include "base_object.h"
16
17
18/* forward declarations for the header file (include the header via #include "bla.h" in the source file) */
19class NetworkStream;
20class Synchronizeable;
21template<typename>
22class tList;
23
24/* and here is the class itsself*/
25class NetworkManager : public BaseObject
26{
27
28  public:
29
30    inline static NetworkManager* getInstance() { if (!NetworkManager::singletonRef) NetworkManager::singletonRef = new NetworkManager();
31      return NetworkManager::singletonRef; }
32    ~NetworkManager();
33
34    void initialize();
35    void shutdown();
36
37    int establishConnection(const char* name, unsigned int port);
38    int createServer(unsigned int port);
39
40    NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
41    void shutdownConnection();
42
43
44    void setHostID(int id);
45    /** Returns the hostID @return The hostID of the object */
46    inline int getHostID() { return this->hostID; }
47    inline bool isGameServer() { return this->bGameServer; }
48
49
50    void connectSynchronizeable(Synchronizeable& sync);
51    void synchronize();
52
53    inline NetworkStream* getDefaultSyncStream() { return this->defaultSyncStream; }
54
55    /** @returns the next uniqueID free for an object */
56    inline int getNewUniqueID() { return ( this->bGameServer)?this->newUniqueID++:-1; }
57
58    void debug();
59
60
61  private:
62    NetworkManager();
63
64
65  private:
66    const std::list<BaseObject*>*    netStreamList;           // list with refs to all network streams
67    const std::list<BaseObject*>*    syncList;                // list of synchronizeables
68    static NetworkManager*           singletonRef;            //!< Pointer to the only instance of this Class
69    NetworkStream*                   defaultSyncStream;       //!< FIXME: this is only for testing purposes
70    int                              hostID;                  //!< The Host-ID of the Manager
71    bool                             bGameServer;             //!< true if it is a server
72    int                              newUniqueID;
73
74};
75
76
77
78#endif /* _NETWORK_MANAGER */
Note: See TracBrowser for help on using the repository browser.