Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7508 was 7508, checked in by rennerc, 18 years ago

implemented synchronizeable

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