Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_var.h @ 9347

Last change on this file since 9347 was 9347, checked in by bensch, 18 years ago

orxonox/proxy: merged the proxy.old back again, and it seems to work.

Merged with command
svn merge -r9247:HEAD https://svn.orxonox.net/orxonox/branches/proxy.old .

no conflicts

File size: 4.0 KB
Line 
1/*!
2 * @file synchronizeable_var.h
3 * @brief Definition of SynchronizeableVar
4*/
5
6#ifndef _SYNCHRONIZEABLE_VAR_H
7#define _SYNCHRONIZEABLE_VAR_H
8
9#include <string>
10#include "netdefs.h"
11#include <assert.h>
12
13enum {
14  PERMISSION_MASTER_SERVER = 1,
15  PERMISSION_PROXY_SERVER  = 2,
16  PERMISSION_OWNER         = 4,
17  PERMISSION_ALL           = 8
18};
19
20class SynchronizeableVar {
21
22  public:
23    SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
24    virtual ~SynchronizeableVar();
25
26    /**
27     * check if synchronizeable wants to be informed on changes
28     * @return true if synchronizeable wants to be informed on changes
29     */
30    inline bool beWatched(){ return this->bWatched; }
31
32    /**
33     * set flag if synchronizeable wants to be informed on changes
34     */
35    inline void setWatched( bool watched ){ this->bWatched = watched; }
36
37    /**
38     * write var data to byte buffer
39     * @param buf pointer to write to
40     * @param maxLength writeToBuf will not write more than maxLength bytes
41     * @return number bytes written
42     */
43    virtual int writeToBuf( byte * buf, int maxLength ) = 0;
44
45    /**
46     * read var data from byte buffer
47     * @param buf pointer to read from
48     * @param maxLength readFromBuf will not read more than maxLength bytes
49     * @return number bytes read
50     */
51    virtual int readFromBuf( byte * buf, int maxLength ) = 0;
52
53    /**
54     * check if writeToBuf will return the same size every time
55     * @return true if same size every time
56     */
57    virtual bool hasStaticSize() = 0;
58
59    /**
60     * get size writeToBuf needs
61     * @return size in bytes
62     */
63    virtual int getSize(){ return length; }
64
65    /**
66     * check for permission to write
67     * @return true if you can write
68     */
69    inline bool checkPermission( int permission ){ return (permission & this->permission) != 0; }
70
71    /**
72     * get variable name
73     * @return name
74     */
75    inline std::string getName(){ return name; }
76
77    /**
78     * set variable name
79     * @param name new name
80     */
81    inline void setName( std::string name ) { this->name = name; }
82
83    /**
84     * get priority
85     * @return priority
86     */
87    inline int getPriority() { return this->priority; }
88
89    /**
90     * set priority
91     * @param p priority
92     */
93    inline void setPriority( int p ) { this->priority = p; }
94
95    /**
96     * reset priority to variable specific default value
97     */
98    inline void resetPriority() { this->priority = this->realPriority; }
99
100    /**
101     * reads actual size from buffer. this is used when size is not constant
102     * @param buf pointer to data
103     * @param maxLength maximal size of data
104     * @return same as readFromBuf would return
105     */
106    virtual inline int getSizeFromBuf( byte * buf, int maxLength ){ return this->getSize(); }
107
108    /**
109     * set variable id
110     * @param id
111     */
112    inline void setVarId( int id ){ this->varId = id; }
113
114    /**
115     * get variable id
116     * @return variable id
117     */
118    inline int getVarId(){ return varId; }
119
120    /**
121     * set hasChanged
122     * @param changed
123     */
124    inline void setHasChanged( bool changed ){ this->changed = changed; }
125
126    /**
127     * get hasChanged
128     * @return variable id
129     */
130    inline bool getHasChanged(){ return changed; }
131
132    /**
133     * print out variable value
134     */
135    virtual void debug() = 0;
136
137
138  private:
139    bool bWatched;      //!< true if synchronizeable wants to be informed on changes
140
141    int permission;     //!< who is allowed to change this var
142    int priority;       //!< priority assigned to var
143    int realPriority;   //!< priority assigned to var, increased every time not sent
144    int varId;          //!< id to identify varables
145
146    bool changed;       //!< true if last readFromBuf changed anything
147
148  protected:
149    void * ptrIn;       //!< pointer to data (read)
150    void * ptrOut;      //!< pointer to data (write)
151    int length;         //!< data length
152
153
154    std::string name;    //!< variable name (for debugging)
155
156};
157
158#endif /* _PROTO_CLASS_H */
Note: See TracBrowser for help on using the repository browser.