[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 | |
---|
| 9 | #include <string> |
---|
| 10 | #include "netdefs.h" |
---|
[7559] | 11 | #include <assert.h> |
---|
[7444] | 12 | |
---|
| 13 | class SynchronizeableVar { |
---|
| 14 | |
---|
| 15 | public: |
---|
| 16 | SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = 0, int priority = 0 ); |
---|
| 17 | virtual ~SynchronizeableVar(); |
---|
[7559] | 18 | |
---|
[7444] | 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; } |
---|
[7559] | 24 | |
---|
[7459] | 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; |
---|
[7559] | 32 | |
---|
[7444] | 33 | /** |
---|
[7459] | 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; |
---|
[7559] | 40 | |
---|
[7459] | 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; |
---|
[7559] | 46 | |
---|
[7459] | 47 | /** |
---|
[7508] | 48 | * get size writeToBuf needs |
---|
| 49 | * @return size in bytes |
---|
| 50 | */ |
---|
| 51 | virtual int getSize(){ return length; } |
---|
[7559] | 52 | |
---|
[7508] | 53 | /** |
---|
[7444] | 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; } |
---|
[7559] | 58 | |
---|
[7444] | 59 | /** |
---|
| 60 | * get variable name |
---|
| 61 | * @return name |
---|
| 62 | */ |
---|
| 63 | inline std::string getName(){ return name; } |
---|
[7559] | 64 | |
---|
[7444] | 65 | /** |
---|
| 66 | * set variable name |
---|
| 67 | * @param name new name |
---|
| 68 | */ |
---|
| 69 | inline void setName( std::string name ) { this->name = name; } |
---|
[7559] | 70 | |
---|
[7508] | 71 | /** |
---|
| 72 | * get priority |
---|
| 73 | * @return priority |
---|
| 74 | */ |
---|
| 75 | inline int getPriority() { return this->priority; } |
---|
[7559] | 76 | |
---|
[7508] | 77 | /** |
---|
| 78 | * set priority |
---|
| 79 | * @param p priority |
---|
| 80 | */ |
---|
| 81 | inline void setPriority( int p ) { this->priority = p; } |
---|
[7559] | 82 | |
---|
[7508] | 83 | /** |
---|
| 84 | * reset priority to variable specific default value |
---|
| 85 | */ |
---|
[7559] | 86 | inline void resetPriority() { this->priority = this->realPriority; } |
---|
[7444] | 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 |
---|
[7559] | 98 | int realPriority; //!< priority assigned to var, increased every time not sent |
---|
| 99 | |
---|
| 100 | |
---|
[7444] | 101 | std::string name; //!< variable name (for debugging) |
---|
| 102 | |
---|
| 103 | }; |
---|
| 104 | |
---|
| 105 | #endif /* _PROTO_CLASS_H */ |
---|