Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/synchronizeable_var/synchronizeable_var.h @ 8290

Last change on this file since 8290 was 7954, checked in by patrick, 19 years ago

trunk: merged the network branche back to trunk.

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