OpenZWave Library 1.7.0
Loading...
Searching...
No Matches
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"
38#include "platform/Log.h"
39
40class TiXmlElement;
41
42namespace 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
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
unsigned short uint16
Definition: Defs.h:88
unsigned int uint32
Definition: Defs.h:91
signed int int32
Definition: Defs.h:90
unsigned char uint8
Definition: Defs.h:85
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:85
void AddRef()
Definition: Ref.h:69
int32 Release()
Definition: Ref.h:80
Container that holds all of the values associated with a given node.
Definition: ValueStore.h:50
Base class for values associated with a node.
Definition: Value.h:54
static OpenZWave::ValueID::ValueGenre GetGenreEnumFromName(char const *_name)
Definition: Value.cpp:404
virtual string const GetAsString() const
Definition: Value.h:137
string const & GetUnits() const
Definition: Value.h:89
void SetLabel(string const &_label, string const lang="")
Definition: Value.cpp:682
void SetChangeVerified(bool _verify)
Definition: Value.h:119
int32 m_min
Definition: Value.h:180
bool IsReadOnly() const
Definition: Value.h:69
static OpenZWave::ValueID::ValueType GetTypeEnumFromName(char const *_name)
Definition: Value.cpp:435
bool IsWriteOnly() const
Definition: Value.h:73
void SetRefreshAfterSet(bool _refreshAfterSet)
Definition: Value.h:128
ValueID m_id
Definition: Value.h:186
bool IsSet() const
Definition: Value.h:77
bool GetChangeVerified()
Definition: Value.h:123
bool IsCheckingChange() const
Definition: Value.h:168
int32 GetMax() const
Definition: Value.h:114
void SetUnits(string const &_units)
Definition: Value.h:93
static char const * GetTypeNameFromEnum(ValueID::ValueType _type)
Definition: Value.cpp:457
void SetPollIntensity(uint8 const &_intensity)
Definition: Value.h:105
void OnValueChanged()
Definition: Value.cpp:365
virtual ~Value()
Definition: Value.cpp:78
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: Value.cpp:222
int32 m_max
Definition: Value.h:181
int VerifyRefreshedValue(void *_originalValue, void *_checkValue, void *_newValue, ValueID::ValueType _type, int _originalValueLength=0, int _checkValueLength=0, int _newValueLength=0)
Definition: Value.cpp:472
void SetHelp(string const &_help, string const lang="")
Definition: Value.cpp:673
time_t m_refreshTime
Definition: Value.h:183
bool m_refreshAfterSet
Definition: Value.h:185
bool IsPolled() const
Definition: Value.h:81
bool Set()
Definition: Value.cpp:276
static char const * GetGenreNameFromEnum(ValueID::ValueGenre _genre)
Definition: Value.cpp:426
virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const *_valueElement)
Definition: Value.cpp:90
uint8 const & GetPollIntensity() const
Definition: Value.h:101
int32 GetMin() const
Definition: Value.h:110
void SetCheckingChange(bool _check)
Definition: Value.h:172
Value()
Definition: Value.cpp:69
bool GetRefreshAfterSet()
Definition: Value.h:132
virtual bool SetFromString(string const &)
Definition: Value.h:141
string const GetHelp() const
Definition: Value.cpp:669
bool m_verifyChanges
Definition: Value.h:184
ValueID const & GetID() const
Definition: Value.h:65
string const GetLabel() const
Definition: Value.cpp:678
void OnValueRefreshed()
Definition: Value.cpp:338
static void Write(LogLevel _level, char const *_format,...)
Write an entry to the log.
Definition: Log.cpp:202
Provides a unique ID for a value reported by a Z-Wave device.
Definition: ValueID.h:77
ValueType
Definition: ValueID.h:99
uint64 GetId() const
Definition: ValueID.h:214
ValueGenre
Definition: ValueID.h:85
@ LogLevel_Warning
Definition: Log.h:59
Definition: Bitfield.cpp:31