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