OpenZWave Library  1.7.0
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 "platform/Ref.h"
37 #include "value_classes/ValueID.h"
38 #include "platform/Log.h"
39 
40 class TiXmlElement;
41 
42 namespace OpenZWave
43 {
44  class Driver;
45  namespace Internal
46  {
47  namespace VC
48  {
49 
54  {
55  friend class OpenZWave::Driver;
56  friend class ValueStore;
57 
58  public:
59  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);
60  Value();
61 
62  virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const* _valueElement);
63  virtual void WriteXML(TiXmlElement* _valueElement);
64 
65  ValueID const& GetID() const
66  {
67  return m_id;
68  }
69  bool IsReadOnly() const
70  {
71  return m_readOnly;
72  }
73  bool IsWriteOnly() const
74  {
75  return m_writeOnly;
76  }
77  bool IsSet() const
78  {
79  return m_isSet;
80  }
81  bool IsPolled() const
82  {
83  return m_pollIntensity != 0;
84  }
85 
86  string const GetLabel() const;
87  void SetLabel(string const& _label, string const lang = "");
88 
89  string const& GetUnits() const
90  {
91  return m_units;
92  }
93  void SetUnits(string const& _units)
94  {
95  m_units = _units;
96  }
97 
98  string const GetHelp() const;
99  void SetHelp(string const& _help, string const lang = "");
100 
101  uint8 const& GetPollIntensity() const
102  {
103  return m_pollIntensity;
104  }
105  void SetPollIntensity(uint8 const& _intensity)
106  {
107  m_pollIntensity = _intensity;
108  }
109 
110  int32 GetMin() const
111  {
112  return m_min;
113  }
114  int32 GetMax() const
115  {
116  return m_max;
117  }
118 
119  void SetChangeVerified(bool _verify)
120  {
121  m_verifyChanges = _verify;
122  }
124  {
125  return m_verifyChanges;
126  }
127 
128  void SetRefreshAfterSet(bool _refreshAfterSet)
129  {
130  m_refreshAfterSet = _refreshAfterSet;
131  }
133  {
134  return m_refreshAfterSet;
135  }
136 
137  virtual string const GetAsString() const
138  {
139  return "";
140  }
141  virtual bool SetFromString(string const&)
142  {
143  return false;
144  }
145 
146  bool Set(); // For the user to change a value in a device
147 
148  // Helpers
149  static OpenZWave::ValueID::ValueGenre GetGenreEnumFromName(char const* _name);
150  static char const* GetGenreNameFromEnum(ValueID::ValueGenre _genre);
151  static OpenZWave::ValueID::ValueType GetTypeEnumFromName(char const* _name);
152  static char const* GetTypeNameFromEnum(ValueID::ValueType _type);
153 #if 0
154  inline void AddRef() {
155  Ref::AddRef();
156  Log::Write(LogLevel_Warning, "Add Ref %d - %d %s", m_refs, m_id.GetId(), __func__);
157  Internal::StackTraceGenerator::GetTrace();
158  }
159  inline int32 Release() {
160  Log::Write(LogLevel_Warning, "Del Ref %d - %d %s", m_refs -1, m_id.GetId(), __func__);
161  Internal::StackTraceGenerator::GetTrace();
162  return Ref::Release();
163  }
164 #endif
165  protected:
166  virtual ~Value();
167 
168  bool IsCheckingChange() const
169  {
170  return m_checkChange;
171  }
172  void SetCheckingChange(bool _check)
173  {
174  m_checkChange = _check;
175  }
176  void OnValueRefreshed(); // A value in a device has been refreshed
177  void OnValueChanged(); // The refreshed value actually changed
178  int VerifyRefreshedValue(void* _originalValue, void* _checkValue, void* _newValue, ValueID::ValueType _type, int _originalValueLength = 0, int _checkValueLength = 0, int _newValueLength = 0);
179 
182 
183  time_t m_refreshTime; // time_t identifying when this value was last refreshed
184  bool m_verifyChanges; // if true, apparent changes are verified; otherwise, they're not
185  bool m_refreshAfterSet; // if true, all value sets are followed by a get to refresh the value manually
187 
188  private:
189  string m_units;
190  bool m_readOnly;
191  bool m_writeOnly;
192  bool m_isSet;
193  uint8 m_affectsLength;
194  uint8* m_affects;
195  bool m_affectsAll;
196  bool m_checkChange;
197  uint8 m_pollIntensity;
198  };
199  } // namespace VC
200  } // namespace Internal
201 } // namespace OpenZWave
202 
203 #endif
204 
uint32
unsigned int uint32
Definition: Defs.h:91
OpenZWave::Internal::VC::Value::SetCheckingChange
void SetCheckingChange(bool _check)
Definition: Value.h:172
OpenZWave::Internal::Platform::Ref::AddRef
void AddRef()
Definition: Ref.h:69
OpenZWave::Internal::VC::Value::~Value
virtual ~Value()
Definition: Value.cpp:78
OpenZWave::Internal::VC::Value::IsPolled
bool IsPolled() const
Definition: Value.h:81
OpenZWave::Internal::VC::ValueStore
Container that holds all of the values associated with a given node.
Definition: ValueStore.h:50
ValueID.h
OpenZWave::Internal::VC::Value::SetChangeVerified
void SetChangeVerified(bool _verify)
Definition: Value.h:119
OpenZWave::LogLevel_Warning
@ LogLevel_Warning
Definition: Log.h:59
OpenZWave::Internal::VC::Value::IsWriteOnly
bool IsWriteOnly() const
Definition: Value.h:73
OpenZWave::ValueID
Provides a unique ID for a value reported by a Z-Wave device.
Definition: ValueID.h:77
OpenZWave::ValueID::ValueGenre
ValueGenre
Definition: ValueID.h:85
OpenZWave::Internal::VC::Value::IsReadOnly
bool IsReadOnly() const
Definition: Value.h:69
uint8
unsigned char uint8
Definition: Defs.h:85
OpenZWave::Internal::VC::Value::GetGenreNameFromEnum
static char const * GetGenreNameFromEnum(ValueID::ValueGenre _genre)
Definition: Value.cpp:426
OpenZWave::Internal::VC::Value::IsSet
bool IsSet() const
Definition: Value.h:77
OpenZWave::Internal::VC::Value::SetUnits
void SetUnits(string const &_units)
Definition: Value.h:93
OpenZWave::Internal::VC::Value::IsCheckingChange
bool IsCheckingChange() const
Definition: Value.h:168
OpenZWave::Internal::VC::Value::GetTypeNameFromEnum
static char const * GetTypeNameFromEnum(ValueID::ValueType _type)
Definition: Value.cpp:457
OpenZWave::Internal::VC::Value::GetMin
int32 GetMin() const
Definition: Value.h:110
OpenZWave::ValueID::ValueType
ValueType
Definition: ValueID.h:99
OpenZWave::Internal::VC::Value::VerifyRefreshedValue
int VerifyRefreshedValue(void *_originalValue, void *_checkValue, void *_newValue, ValueID::ValueType _type, int _originalValueLength=0, int _checkValueLength=0, int _newValueLength=0)
Definition: Value.cpp:472
OpenZWave::Internal::VC::Value::Set
bool Set()
Definition: Value.cpp:276
OpenZWave::Internal::VC::Value::GetHelp
string const GetHelp() const
Definition: Value.cpp:669
Log.h
OpenZWave::Internal::VC::Value::GetPollIntensity
uint8 const & GetPollIntensity() const
Definition: Value.h:101
OpenZWave::Internal::Platform::Ref::Release
int32 Release()
Definition: Ref.h:80
OpenZWave::Internal::VC::Value::Value
Value()
Definition: Value.cpp:69
int32
signed int int32
Definition: Defs.h:90
OpenZWave::Internal::VC::Value::m_max
int32 m_max
Definition: Value.h:181
OpenZWave::Internal::VC::Value::SetHelp
void SetHelp(string const &_help, string const lang="")
Definition: Value.cpp:673
OpenZWave::Internal::VC::Value::GetLabel
string const GetLabel() const
Definition: Value.cpp:678
OpenZWave::Internal::VC::Value::GetID
ValueID const & GetID() const
Definition: Value.h:65
OpenZWave::Internal::VC::Value::SetPollIntensity
void SetPollIntensity(uint8 const &_intensity)
Definition: Value.h:105
OpenZWave::Internal::VC::Value::GetRefreshAfterSet
bool GetRefreshAfterSet()
Definition: Value.h:132
OpenZWave::Internal::VC::Value::SetFromString
virtual bool SetFromString(string const &)
Definition: Value.h:141
OpenZWave::Internal::VC::Value::OnValueRefreshed
void OnValueRefreshed()
Definition: Value.cpp:338
OpenZWave::Internal::VC::Value::GetTypeEnumFromName
static OpenZWave::ValueID::ValueType GetTypeEnumFromName(char const *_name)
Definition: Value.cpp:435
OpenZWave::Internal::VC::Value::SetRefreshAfterSet
void SetRefreshAfterSet(bool _refreshAfterSet)
Definition: Value.h:128
OpenZWave::Internal::VC::Value::m_id
ValueID m_id
Definition: Value.h:186
OpenZWave::Internal::Platform::Ref
Definition: Ref.h:51
OpenZWave::Internal::VC::Value::m_refreshAfterSet
bool m_refreshAfterSet
Definition: Value.h:185
OpenZWave::Internal::VC::Value::GetGenreEnumFromName
static OpenZWave::ValueID::ValueGenre GetGenreEnumFromName(char const *_name)
Definition: Value.cpp:404
OpenZWave::Internal::VC::Value::GetUnits
string const & GetUnits() const
Definition: Value.h:89
Ref.h
OpenZWave::ValueID::GetId
uint64 GetId() const
Definition: ValueID.h:214
OpenZWave::Internal::VC::Value::m_min
int32 m_min
Definition: Value.h:180
OpenZWave::Internal::VC::Value::GetAsString
virtual string const GetAsString() const
Definition: Value.h:137
OpenZWave::Internal::VC::Value::WriteXML
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: Value.cpp:222
OpenZWave::Internal::VC::Value::ReadXML
virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const *_valueElement)
Definition: Value.cpp:90
OpenZWave::Driver
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:85
OpenZWave::Internal::VC::Value::SetLabel
void SetLabel(string const &_label, string const lang="")
Definition: Value.cpp:682
OpenZWave::Internal::VC::Value
Base class for values associated with a node.
Definition: Value.h:54
OpenZWave::Log::Write
static void Write(LogLevel _level, char const *_format,...)
Write an entry to the log.
Definition: Log.cpp:202
OpenZWave::Internal::VC::Value::GetMax
int32 GetMax() const
Definition: Value.h:114
OpenZWave::Internal::VC::Value::m_refreshTime
time_t m_refreshTime
Definition: Value.h:183
Defs.h
uint16
unsigned short uint16
Definition: Defs.h:88
OpenZWave
Definition: Bitfield.cpp:31
OpenZWave::Internal::VC::Value::GetChangeVerified
bool GetChangeVerified()
Definition: Value.h:123
OpenZWave::Internal::VC::Value::OnValueChanged
void OnValueChanged()
Definition: Value.cpp:365
OpenZWave::Internal::VC::Value::m_verifyChanges
bool m_verifyChanges
Definition: Value.h:184