OpenZWave Library  1.6.1280
Value.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Value.h
4 //
5 // Base class for all OpenZWave Value Classes
6 //
7 // Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
8 //
9 // SOFTWARE NOTICE AND LICENSE
10 //
11 // This file is part of OpenZWave.
12 //
13 // OpenZWave is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as published
15 // by the Free Software Foundation, either version 3 of the License,
16 // or (at your option) any later version.
17 //
18 // OpenZWave is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public License
24 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25 //
26 //-----------------------------------------------------------------------------
27 
28 #ifndef _Value_H
29 #define _Value_H
30 
31 #include <string>
32 #ifdef __FreeBSD__
33 #include <time.h>
34 #endif
35 #include "Defs.h"
36 #include "TimerThread.h"
37 #include "platform/Ref.h"
38 #include "value_classes/ValueID.h"
39 #include "platform/Log.h"
40 
41 class TiXmlElement;
42 
43 namespace OpenZWave
44 {
45  class Driver;
46  namespace Internal
47  {
48  namespace VC
49  {
50 
54  class Value: public Internal::Platform::Ref, private Timer
55  {
56  friend class OpenZWave::Driver;
57  friend class ValueStore;
58 
59  public:
60  Value(uint32 const _homeId, uint8 const _nodeId, ValueID::ValueGenre const _genre, uint8 const _commandClassId, uint8 const _instance, uint16 const _index, ValueID::ValueType const _type, string const& _label, string const& _units, bool const _readOnly, bool const _writeOnly, bool const _isset, uint8 const _pollIntensity);
61  Value();
62 
63  virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const* _valueElement);
64  virtual void WriteXML(TiXmlElement* _valueElement);
65 
66  ValueID const& GetID() const
67  {
68  return m_id;
69  }
70  bool IsReadOnly() const
71  {
72  return m_readOnly;
73  }
74  bool IsWriteOnly() const
75  {
76  return m_writeOnly;
77  }
78  bool IsSet() const
79  {
80  return m_isSet;
81  }
82  bool IsPolled() const
83  {
84  return m_pollIntensity != 0;
85  }
86 
87  string const GetLabel() const;
88  void SetLabel(string const& _label, string const lang = "");
89 
90  string const& GetUnits() const
91  {
92  return m_units;
93  }
94  void SetUnits(string const& _units)
95  {
96  m_units = _units;
97  }
98 
99  string const GetHelp() const;
100  void SetHelp(string const& _help, string const lang = "");
101 
102  uint8 const& GetPollIntensity() const
103  {
104  return m_pollIntensity;
105  }
106  void SetPollIntensity(uint8 const& _intensity)
107  {
108  m_pollIntensity = _intensity;
109  }
110 
111  int32 GetMin() const
112  {
113  return m_min;
114  }
115  int32 GetMax() const
116  {
117  return m_max;
118  }
119 
120  void SetChangeVerified(bool _verify)
121  {
122  m_verifyChanges = _verify;
123  }
125  {
126  return m_verifyChanges;
127  }
128 
129  void SetRefreshAfterSet(bool _refreshAfterSet)
130  {
131  m_refreshAfterSet = _refreshAfterSet;
132  }
134  {
135  return m_refreshAfterSet;
136  }
137 
138  virtual string const GetAsString() const
139  {
140  return "";
141  }
142  virtual bool SetFromString(string const&)
143  {
144  return false;
145  }
146 
147  bool Set(); // For the user to change a value in a device
148 
149  // Helpers
150  static OpenZWave::ValueID::ValueGenre GetGenreEnumFromName(char const* _name);
151  static char const* GetGenreNameFromEnum(ValueID::ValueGenre _genre);
152  static OpenZWave::ValueID::ValueType GetTypeEnumFromName(char const* _name);
153  static char const* GetTypeNameFromEnum(ValueID::ValueType _type);
154 #if 0
155  inline void AddRef() {
156  Ref::AddRef();
157  Log::Write(LogLevel_Warning, "Add Ref %d - %d %s", m_refs, m_id.GetId(), __func__);
158  Internal::StackTraceGenerator::GetTrace();
159  }
160  inline int32 Release() {
161  Log::Write(LogLevel_Warning, "Del Ref %d - %d %s", m_refs -1, m_id.GetId(), __func__);
162  Internal::StackTraceGenerator::GetTrace();
163  return Ref::Release();
164  }
165 #endif
166  void sendValueRefresh(uint32 _unused);
167 
168  protected:
169  virtual ~Value();
170 
171  bool IsCheckingChange() const
172  {
173  return m_checkChange;
174  }
175  void SetCheckingChange(bool _check)
176  {
177  m_checkChange = _check;
178  }
179  bool IsTargetValueSet() const
180  {
181  return m_targetValueSet;
182  }
183 
184  void OnValueRefreshed(); // A value in a device has been refreshed
185  void OnValueChanged(); // The refreshed value actually changed
186  int VerifyRefreshedValue(void* _originalValue, void* _checkValue, void* _newValue, void* _targetValue, ValueID::ValueType _type, int _originalValueLength = 0, int _checkValueLength = 0, int _newValueLength = 0, int _targetValueLength = 0);
187  int CheckTargetValue(void* _newValue, void* _targetValue, ValueID::ValueType _type, int _newValueLength, int _targetValueLength);
188 
191 
192  time_t m_refreshTime; // time_t identifying when this value was last refreshed
193  bool m_verifyChanges; // if true, apparent changes are verified; otherwise, they're not
194  bool m_refreshAfterSet; // if true, all value sets are followed by a get to refresh the value manually
196  bool m_targetValueSet; // If the Target Value is Set
197  uint32 m_duration; // The Duration, if the CC supports it
198 
199  private:
200  string m_units;
201  bool m_readOnly;
202  bool m_writeOnly;
203  bool m_isSet;
204  uint8 m_affectsLength;
205  uint8* m_affects;
206  bool m_affectsAll;
207  bool m_checkChange;
208  uint8 m_pollIntensity;
209  };
210  } // namespace VC
211  } // namespace Internal
212 } // namespace OpenZWave
213 
214 #endif
215 
int32 GetMax() const
Definition: Value.h:115
Definition: Bitfield.cpp:30
bool Set()
Definition: Value.cpp:289
Value()
Definition: Value.cpp:73
void SetChangeVerified(bool _verify)
Definition: Value.h:120
unsigned short uint16
Definition: Defs.h:88
virtual bool SetFromString(string const &)
Definition: Value.h:142
ValueType
Definition: ValueID.h:98
void SetLabel(string const &_label, string const lang="")
Definition: Value.cpp:732
void SetHelp(string const &_help, string const lang="")
Definition: Value.cpp:723
bool m_targetValueSet
Definition: Value.h:196
static char const * GetGenreNameFromEnum(ValueID::ValueGenre _genre)
Definition: Value.cpp:439
uint32 m_duration
Definition: Value.h:197
void sendValueRefresh(uint32 _unused)
Definition: Value.cpp:819
void OnValueChanged()
Definition: Value.cpp:378
virtual ~Value()
Definition: Value.cpp:82
static OpenZWave::ValueID::ValueGenre GetGenreEnumFromName(char const *_name)
Definition: Value.cpp:417
Container that holds all of the values associated with a given node.
Definition: ValueStore.h:49
void OnValueRefreshed()
Definition: Value.cpp:351
int CheckTargetValue(void *_newValue, void *_targetValue, ValueID::ValueType _type, int _newValueLength, int _targetValueLength)
Definition: Value.cpp:741
time_t m_refreshTime
Definition: Value.h:192
Definition: Log.h:59
bool IsSet() const
Definition: Value.h:78
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: Value.cpp:235
int32 m_min
Definition: Value.h:189
bool IsPolled() const
Definition: Value.h:82
void AddRef()
Definition: Ref.h:69
int VerifyRefreshedValue(void *_originalValue, void *_checkValue, void *_newValue, void *_targetValue, ValueID::ValueType _type, int _originalValueLength=0, int _checkValueLength=0, int _newValueLength=0, int _targetValueLength=0)
Definition: Value.cpp:485
string const & GetUnits() const
Definition: Value.h:90
virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const *_valueElement)
Definition: Value.cpp:94
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:84
bool GetChangeVerified()
Definition: Value.h:124
signed int int32
Definition: Defs.h:90
unsigned int uint32
Definition: Defs.h:91
ValueID m_id
Definition: Value.h:195
bool m_refreshAfterSet
Definition: Value.h:194
Timer SubClass for automatically registering/unregistering Timer Callbacks if the instance goes out o...
Definition: TimerThread.h:127
bool IsWriteOnly() const
Definition: Value.h:74
bool IsReadOnly() const
Definition: Value.h:70
void SetRefreshAfterSet(bool _refreshAfterSet)
Definition: Value.h:129
uint64 GetId() const
Definition: ValueID.h:214
void SetCheckingChange(bool _check)
Definition: Value.h:175
bool m_verifyChanges
Definition: Value.h:193
bool IsCheckingChange() const
Definition: Value.h:171
Provides a unique ID for a value reported by a Z-Wave device.The ValueID is used to uniquely identify...
Definition: ValueID.h:76
ValueID const & GetID() const
Definition: Value.h:66
uint8 const & GetPollIntensity() const
Definition: Value.h:102
void SetPollIntensity(uint8 const &_intensity)
Definition: Value.h:106
static char const * GetTypeNameFromEnum(ValueID::ValueType _type)
Definition: Value.cpp:470
virtual string const GetAsString() const
Definition: Value.h:138
string const GetLabel() const
Definition: Value.cpp:728
int32 Release()
Definition: Ref.h:80
static OpenZWave::ValueID::ValueType GetTypeEnumFromName(char const *_name)
Definition: Value.cpp:448
string const GetHelp() const
Definition: Value.cpp:719
int32 m_max
Definition: Value.h:190
bool GetRefreshAfterSet()
Definition: Value.h:133
static void Write(LogLevel _level, char const *_format,...)
Write an entry to the log.
Definition: Log.cpp:202
bool IsTargetValueSet() const
Definition: Value.h:179
int32 GetMin() const
Definition: Value.h:111
ValueGenre
Definition: ValueID.h:84
Base class for values associated with a node.
Definition: Value.h:54
void SetUnits(string const &_units)
Definition: Value.h:94
unsigned char uint8
Definition: Defs.h:85