1 | /*! |
---|
2 | * @file connection_monitor.h |
---|
3 | \brief interface for all classes that have to be synchronized |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _SYNCHRONIZEABLE_H |
---|
7 | #define _SYNCHRONIZEABLE_H |
---|
8 | |
---|
9 | #include "base_object.h" |
---|
10 | #include "netdefs.h" |
---|
11 | #include "converter.h" |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | #include <vector> |
---|
16 | #include <list> |
---|
17 | |
---|
18 | //State constants: They have to be of the form 2^n |
---|
19 | #define STATE_SERVER 1 |
---|
20 | #define STATE_OUTOFSYNC 2 |
---|
21 | #define STATE_REQUESTEDSYNC 4 |
---|
22 | |
---|
23 | //macros to help writing data in byte buffer |
---|
24 | #define SYNCHELP_WRITE_BEGIN() { int __synchelp_write_i = 0; \ |
---|
25 | bool __synchelp_write_err = false; \ |
---|
26 | int __synchelp_write_n; } |
---|
27 | #define SYNCHELP_WRITE_RESET() { __synchelp_write_i = 0; __synchelp_write_err = false; } |
---|
28 | #define SYNCHELP_WRITE_INT(i) { __synchelp_write_n = } |
---|
29 | #define SYNCHELP_WIRTE_FLOAT() |
---|
30 | #define SYNCHELP_WRITE_BYTE() |
---|
31 | #define SYNCHELP_WRITE_STRING() |
---|
32 | |
---|
33 | class NetworkStream; |
---|
34 | |
---|
35 | |
---|
36 | class Synchronizeable : virtual public BaseObject |
---|
37 | { |
---|
38 | public: |
---|
39 | Synchronizeable(); |
---|
40 | ~Synchronizeable(); |
---|
41 | |
---|
42 | virtual void writeBytes(const byte* data, int length, int sender); |
---|
43 | virtual int readBytes(byte* data, int maxLength, int * reciever); |
---|
44 | virtual void writeDebug() const; |
---|
45 | virtual void readDebug() const; |
---|
46 | |
---|
47 | void setIsServer( bool isServer ); |
---|
48 | void setIsOutOfSync( bool outOfSync ); |
---|
49 | void setRequestedSync( bool requestedSync ); |
---|
50 | bool isServer(); |
---|
51 | bool isOutOfSync(); |
---|
52 | bool requestedSync(); |
---|
53 | inline void setUniqueID( int id ){ uniqueID = id; } |
---|
54 | inline int getUniqueID() const { return uniqueID; }; |
---|
55 | inline void requestSync( int hostID ){ this->synchronizeRequests.push_back( hostID ); } |
---|
56 | inline int getRequestSync( void ){ if ( this->synchronizeRequests.size()>0 ){ int n = *(synchronizeRequests.begin()); synchronizeRequests.pop_front(); return n; } else { return -1; } }; |
---|
57 | inline int getHostID() { return this->hostID; } |
---|
58 | |
---|
59 | inline int getOwner(){ return owner; } |
---|
60 | inline void setOwner(int owner){ this->owner = owner; } |
---|
61 | |
---|
62 | inline void setNetworkStream(NetworkStream* stream) { this->networkStream = stream; } |
---|
63 | |
---|
64 | private: |
---|
65 | |
---|
66 | int uniqueID; |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | //static std::vector<Synchronizeable*> classList; |
---|
71 | int owner; |
---|
72 | int hostID; |
---|
73 | |
---|
74 | std::list<int> synchronizeRequests; |
---|
75 | |
---|
76 | protected: |
---|
77 | NetworkStream* networkStream; |
---|
78 | int state; |
---|
79 | |
---|
80 | }; |
---|
81 | #endif /* _SYNCHRONIZEABLE_H */ |
---|