OpenZWave Library  1.6.936
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  virtual string const GetAsString() const
129  {
130  return "";
131  }
132  virtual bool SetFromString(string const&)
133  {
134  return false;
135  }
136 
137  bool Set(); // For the user to change a value in a device
138 
139  // Helpers
140  static OpenZWave::ValueID::ValueGenre GetGenreEnumFromName(char const* _name);
141  static char const* GetGenreNameFromEnum(ValueID::ValueGenre _genre);
142  static OpenZWave::ValueID::ValueType GetTypeEnumFromName(char const* _name);
143  static char const* GetTypeNameFromEnum(ValueID::ValueType _type);
144 #if 0
145  inline void AddRef() {
146  Ref::AddRef();
147  Log::Write(LogLevel_Warning, "Add Ref %d - %d %s", m_refs, m_id.GetId(), __func__);
148  Internal::StackTraceGenerator::GetTrace();
149  }
150  inline int32 Release() {
151  Log::Write(LogLevel_Warning, "Del Ref %d - %d %s", m_refs -1, m_id.GetId(), __func__);
152  Internal::StackTraceGenerator::GetTrace();
153  return Ref::Release();
154  }
155 #endif
156  protected:
157  virtual ~Value();
158 
159  bool IsCheckingChange() const
160  {
161  return m_checkChange;
162  }
163  void SetCheckingChange(bool _check)
164  {
165  m_checkChange = _check;
166  }
167  void OnValueRefreshed(); // A value in a device has been refreshed
168  void OnValueChanged(); // The refreshed value actually changed
169  int VerifyRefreshedValue(void* _originalValue, void* _checkValue, void* _newValue, ValueID::ValueType _type, int _originalValueLength = 0, int _checkValueLength = 0, int _newValueLength = 0);
170 
173 
174  time_t m_refreshTime; // time_t identifying when this value was last refreshed
175  bool m_verifyChanges; // if true, apparent changes are verified; otherwise, they're not
177 
178  private:
179  string m_units;
180  bool m_readOnly;
181  bool m_writeOnly;
182  bool m_isSet;
183  uint8 m_affectsLength;
184  uint8* m_affects;
185  bool m_affectsAll;
186  bool m_checkChange;
187  uint8 m_pollIntensity;
188  };
189  } // namespace VC
190  } // namespace Internal
191 } // namespace OpenZWave
192 
193 #endif
194 
int32 GetMax() const
Definition: Value.h:114
Definition: Bitfield.cpp:30
bool Set()
Definition: Value.cpp:276
Value()
Definition: Value.cpp:69
void SetChangeVerified(bool _verify)
Definition: Value.h:119
unsigned short uint16
Definition: Defs.h:88
virtual bool SetFromString(string const &)
Definition: Value.h:132
ValueType
Definition: ValueID.h:106
void SetLabel(string const &_label, string const lang="")
Definition: Value.cpp:680
void SetHelp(string const &_help, string const lang="")
Definition: Value.cpp:671
static char const * GetGenreNameFromEnum(ValueID::ValueGenre _genre)
Definition: Value.cpp:424
void OnValueChanged()
Definition: Value.cpp:363
virtual ~Value()
Definition: Value.cpp:78
static OpenZWave::ValueID::ValueGenre GetGenreEnumFromName(char const *_name)
Definition: Value.cpp:402
Container that holds all of the values associated with a given node.
Definition: ValueStore.h:49
void OnValueRefreshed()
Definition: Value.cpp:336
time_t m_refreshTime
Definition: Value.h:174
Definition: Log.h:59
bool IsSet() const
Definition: Value.h:77
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: Value.cpp:222
int32 m_min
Definition: Value.h:171
bool IsPolled() const
Definition: Value.h:81
void AddRef()
Definition: Ref.h:69
string const & GetUnits() const
Definition: Value.h:89
virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const *_valueElement)
Definition: Value.cpp:90
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:123
signed int int32
Definition: Defs.h:90
unsigned int uint32
Definition: Defs.h:91
ValueID m_id
Definition: Value.h:176
bool IsWriteOnly() const
Definition: Value.h:73
bool IsReadOnly() const
Definition: Value.h:69
uint64 GetId() const
Definition: ValueID.h:222
void SetCheckingChange(bool _check)
Definition: Value.h:163
bool m_verifyChanges
Definition: Value.h:175
bool IsCheckingChange() const
Definition: Value.h:159
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:65
uint8 const & GetPollIntensity() const
Definition: Value.h:101
void SetPollIntensity(uint8 const &_intensity)
Definition: Value.h:105
static char const * GetTypeNameFromEnum(ValueID::ValueType _type)
Definition: Value.cpp:455
virtual string const GetAsString() const
Definition: Value.h:128
string const GetLabel() const
Definition: Value.cpp:676
int32 Release()
Definition: Ref.h:80
static OpenZWave::ValueID::ValueType GetTypeEnumFromName(char const *_name)
Definition: Value.cpp:433
string const GetHelp() const
Definition: Value.cpp:667
int32 m_max
Definition: Value.h:172
int VerifyRefreshedValue(void *_originalValue, void *_checkValue, void *_newValue, ValueID::ValueType _type, int _originalValueLength=0, int _checkValueLength=0, int _newValueLength=0)
Definition: Value.cpp:470
static void Write(LogLevel _level, char const *_format,...)
Write an entry to the log.
Definition: Log.cpp:202
int32 GetMin() const
Definition: Value.h:110
ValueGenre
Definition: ValueID.h:92
Base class for values associated with a node.
Definition: Value.h:53
void SetUnits(string const &_units)
Definition: Value.h:93
unsigned char uint8
Definition: Defs.h:85