OpenZWave Library  1.6.778
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 #include "Utils.h"
40 
41 class TiXmlElement;
42 
43 namespace OpenZWave
44 {
45  class Driver;
46  namespace Internal
47  {
48  namespace VC
49  {
50 
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  virtual string const GetAsString() const
130  {
131  return "";
132  }
133  virtual bool SetFromString(string const&)
134  {
135  return false;
136  }
137 
138  bool Set(); // For the user to change a value in a device
139 
140  // Helpers
141  static OpenZWave::ValueID::ValueGenre GetGenreEnumFromName(char const* _name);
142  static char const* GetGenreNameFromEnum(ValueID::ValueGenre _genre);
143  static OpenZWave::ValueID::ValueType GetTypeEnumFromName(char const* _name);
144  static char const* GetTypeNameFromEnum(ValueID::ValueType _type);
145 #if 0
146  inline void AddRef() {
147  Ref::AddRef();
148  Log::Write(LogLevel_Warning, "Add Ref %d - %d %s", m_refs, m_id.GetId(), __func__);
149  Internal::StackTraceGenerator::GetTrace();
150  }
151  inline int32 Release() {
152  Log::Write(LogLevel_Warning, "Del Ref %d - %d %s", m_refs -1, m_id.GetId(), __func__);
153  Internal::StackTraceGenerator::GetTrace();
154  return Ref::Release();
155  }
156 #endif
157  protected:
158  virtual ~Value();
159 
160  bool IsCheckingChange() const
161  {
162  return m_checkChange;
163  }
164  void SetCheckingChange(bool _check)
165  {
166  m_checkChange = _check;
167  }
168  void OnValueRefreshed(); // A value in a device has been refreshed
169  void OnValueChanged(); // The refreshed value actually changed
170  int VerifyRefreshedValue(void* _originalValue, void* _checkValue, void* _newValue, ValueID::ValueType _type, int _originalValueLength = 0, int _checkValueLength = 0, int _newValueLength = 0);
171 
174 
175  time_t m_refreshTime; // time_t identifying when this value was last refreshed
176  bool m_verifyChanges; // if true, apparent changes are verified; otherwise, they're not
178 
179  private:
180  string m_units;
181  bool m_readOnly;
182  bool m_writeOnly;
183  bool m_isSet;
184  uint8 m_affectsLength;
185  uint8* m_affects;
186  bool m_affectsAll;
187  bool m_checkChange;
188  uint8 m_pollIntensity;
189  };
190  } // namespace VC
191  } // namespace Internal
192 } // namespace OpenZWave
193 
194 #endif
195 
int32 GetMax() const
Definition: Value.h:115
Definition: Bitfield.cpp:30
bool Set()
Definition: Value.cpp:276
Value()
Definition: Value.cpp:69
void SetChangeVerified(bool _verify)
Definition: Value.h:120
unsigned short uint16
Definition: Defs.h:89
virtual bool SetFromString(string const &)
Definition: Value.h:133
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:175
Definition: Log.h:58
bool IsSet() const
Definition: Value.h:78
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: Value.cpp:222
int32 m_min
Definition: Value.h:172
bool IsPolled() const
Definition: Value.h:82
void AddRef()
Definition: Ref.h:69
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: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:124
signed int int32
Definition: Defs.h:91
unsigned int uint32
Definition: Defs.h:92
ValueID m_id
Definition: Value.h:177
bool IsWriteOnly() const
Definition: Value.h:74
bool IsReadOnly() const
Definition: Value.h:70
uint64 GetId() const
Definition: ValueID.h:222
void SetCheckingChange(bool _check)
Definition: Value.h:164
bool m_verifyChanges
Definition: Value.h:176
bool IsCheckingChange() const
Definition: Value.h:160
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:455
virtual string const GetAsString() const
Definition: Value.h:129
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:173
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:198
int32 GetMin() const
Definition: Value.h:111
ValueGenre
Definition: ValueID.h:92
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:86