Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: added some comments and found some small bugs

File size: 2.7 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
13class SynchronizeableVar {
14
15  public:
16    SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = 0, int priority = 0 );
17    virtual ~SynchronizeableVar();
18
19    /**
20     * check if synchronizeable wants to be informed on changes
21     * @return true if synchronizeable wants to be informed on changes
22     */
23    inline bool beWatched(){ return this->bWatched; }
24
25    /**
26     * write var data to byte buffer
27     * @param buf pointer to write to
28     * @param maxLength writeToBuf will not write more than maxLength bytes
29     * @return number bytes written
30     */
31    virtual int writeToBuf( byte * buf, int maxLength ) = 0;
32
33    /**
34     * read var data from byte buffer
35     * @param buf pointer to read from
36     * @param maxLength readFromBuf will not read more than maxLength bytes
37     * @return number bytes read
38     */
39    virtual int readFromBuf( byte * buf, int maxLength ) = 0;
40
41    /**
42     * check if writeToBuf will return the same size every time
43     * @return true if same size every time
44     */
45    virtual bool hasStaticSize() = 0;
46
47    /**
48     * get size writeToBuf needs
49     * @return size in bytes
50     */
51    virtual int getSize(){ return length; }
52
53    /**
54     * check for permission to write
55     * @return true if you can write
56     */
57    inline bool checkPremission( int permission ){ return (permission & this->permission) != 0; }
58
59    /**
60     * get variable name
61     * @return name
62     */
63    inline std::string getName(){ return name; }
64
65    /**
66     * set variable name
67     * @param name new name
68     */
69    inline void setName( std::string name ) { this->name = name; }
70
71    /**
72     * get priority
73     * @return priority
74     */
75    inline int getPriority() { return this->priority; }
76
77    /**
78     * set priority
79     * @param p priority
80     */
81    inline void setPriority( int p ) { this->priority = p; }
82
83    /**
84     * reset priority to variable specific default value
85     */
86    inline void resetPriority() { this->priority = this->realPriority; }
87
88
89  private:
90    bool bWatched;      //!< true if synchronizeable wants to be informed on changes
91
92  protected:
93    void * ptrIn;       //!< pointer to data (read)
94    void * ptrOut;      //!< pointer to data (write)
95    int length;         //!< data length
96    int permission;     //!< who is allowed to change this var
97    int priority;       //!< priority assigned to var
98    int realPriority;  //!< priority assigned to var, increased every time not sent
99
100
101    std::string name;    //!< variable name (for debugging)
102
103};
104
105#endif /* _PROTO_CLASS_H */
Note: See TracBrowser for help on using the repository browser.