| OpenZWave Library 1.6.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
39 class TiXmlElement;
40
41 namespace OpenZWave
42 {
43 class Node;
44
48 class Value: public Ref
49 {
50 friend class Driver;
51 friend class ValueStore;
52
53 public:
54 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 );
55 Value();
56
57 virtual void ReadXML( uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const* _valueElement );
58 virtual void WriteXML( TiXmlElement* _valueElement );
59
60 ValueID const& GetID()const{ return m_id; }
61 bool IsReadOnly()const{ return m_readOnly; }
62 bool IsWriteOnly()const{ return m_writeOnly; }
63 bool IsSet()const{ return m_isSet; }
64 bool IsPolled()const{ return m_pollIntensity != 0; }
65
66 string const GetLabel()const;
67 void SetLabel( string const& _label, string const lang="");
68
69 string const& GetUnits()const{ return m_units; }
70 void SetUnits( string const& _units ){ m_units = _units; }
71
72 string const GetHelp()const;
73 void SetHelp( string const& _help, string const lang="");
74
75 uint8 const& GetPollIntensity()const{ return m_pollIntensity; }
76 void SetPollIntensity( uint8 const& _intensity ){ m_pollIntensity = _intensity; }
77
78 int32 GetMin()const{ return m_min; }
79 int32 GetMax()const{ return m_max; }
80
81 void SetChangeVerified( bool _verify ){ m_verifyChanges = _verify; }
82 bool GetChangeVerified() { return m_verifyChanges; }
83
84 virtual string const GetAsString() const { return ""; }
85 virtual bool SetFromString( string const& ) { return false; }
86
87 bool Set(); // For the user to change a value in a device
88
89 // Helpers
90 static ValueID::ValueGenre GetGenreEnumFromName( char const* _name );
91 static char const* GetGenreNameFromEnum( ValueID::ValueGenre _genre );
92 static ValueID::ValueType GetTypeEnumFromName( char const* _name );
93 static char const* GetTypeNameFromEnum( ValueID::ValueType _type );
94
95 protected:
96 virtual ~Value();
97
98 // void SetIsSet() { m_isSet = true; } // TODO: consider removing this...it's never called since m_isSet is set in ValueChanged and ValueRefreshed
99 bool IsCheckingChange()const{ return m_checkChange; }
100 void SetCheckingChange( bool _check ) { m_checkChange = _check; }
101 void OnValueRefreshed(); // A value in a device has been refreshed
102 void OnValueChanged(); // The refreshed value actually changed
103 int VerifyRefreshedValue( void* _originalValue, void* _checkValue, void* _newValue, ValueID::ValueType _type, int _originalValueLength = 0, int _checkValueLength = 0, int _newValueLength = 0 );
104
105 int32 m_min;
106 int32 m_max;
107
108 time_t m_refreshTime; // time_t identifying when this value was last refreshed
109 bool m_verifyChanges; // if true, apparent changes are verified; otherwise, they're not
110 ValueID m_id;
111
112
113 private:
114 string m_units;
115 bool m_readOnly;
116 bool m_writeOnly;
117 bool m_isSet;
118 uint8 m_affectsLength;
119 uint8* m_affects;
120 bool m_affectsAll;
121 bool m_checkChange;
122 uint8 m_pollIntensity;
123 };
124
125 } // namespace OpenZWave
126
127 #endif
128
129
130
uint32
unsigned int uint32
Definition: Defs.h:95
OpenZWave::Value::SetHelp
void SetHelp(string const &_help, string const lang="")
Definition: Value.cpp:762
OpenZWave::Value::IsSet
bool IsSet() const
Definition: Value.h:63
OpenZWave::Value::GetTypeNameFromEnum
static char const * GetTypeNameFromEnum(ValueID::ValueType _type)
Definition: Value.cpp:538
OpenZWave::Value::m_id
ValueID m_id
Definition: Value.h:110
ValueID.h
OpenZWave::ValueID
Provides a unique ID for a value reported by a Z-Wave device.
Definition: ValueID.h:63
OpenZWave::ValueID::ValueGenre
ValueGenre
Definition: ValueID.h:81
uint8
unsigned char uint8
Definition: Defs.h:89
OpenZWave::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:555
OpenZWave::Value::GetGenreNameFromEnum
static char const * GetGenreNameFromEnum(ValueID::ValueGenre _genre)
Definition: Value.cpp:501
OpenZWave::Value::GetTypeEnumFromName
static ValueID::ValueType GetTypeEnumFromName(char const *_name)
Definition: Value.cpp:513
OpenZWave::Value::GetMax
int32 GetMax() const
Definition: Value.h:79
OpenZWave::ValueID::ValueType
ValueType
Definition: ValueID.h:95
OpenZWave::Value::m_max
int32 m_max
Definition: Value.h:106
OpenZWave::Value::m_min
int32 m_min
Definition: Value.h:105
OpenZWave::Value::m_verifyChanges
bool m_verifyChanges
Definition: Value.h:109
OpenZWave::Value::GetID
ValueID const & GetID() const
Definition: Value.h:60
OpenZWave::Value::Value
Value()
Definition: Value.cpp:112
OpenZWave::ValueStore
Container that holds all of the values associated with a given node.
Definition: ValueStore.h:45
OpenZWave::Ref
Definition: Ref.h:47
OpenZWave::Value::IsReadOnly
bool IsReadOnly() const
Definition: Value.h:61
OpenZWave::Value::GetGenreEnumFromName
static ValueID::ValueGenre GetGenreEnumFromName(char const *_name)
Definition: Value.cpp:476
int32
signed int int32
Definition: Defs.h:94
OpenZWave::Value::Set
bool Set()
Definition: Value.cpp:343
OpenZWave::Value::GetChangeVerified
bool GetChangeVerified()
Definition: Value.h:82
OpenZWave::Value::GetAsString
virtual string const GetAsString() const
Definition: Value.h:84
OpenZWave::Value::IsCheckingChange
bool IsCheckingChange() const
Definition: Value.h:99
OpenZWave::Value::m_refreshTime
time_t m_refreshTime
Definition: Value.h:108
OpenZWave::Value::WriteXML
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: Value.cpp:286
OpenZWave::Value::GetMin
int32 GetMin() const
Definition: Value.h:78
OpenZWave::Value
Base class for values associated with a node.
Definition: Value.h:49
OpenZWave::Value::OnValueRefreshed
void OnValueRefreshed()
Definition: Value.cpp:405
OpenZWave::Value::IsPolled
bool IsPolled() const
Definition: Value.h:64
OpenZWave::Value::SetCheckingChange
void SetCheckingChange(bool _check)
Definition: Value.h:100
OpenZWave::Value::SetChangeVerified
void SetChangeVerified(bool _verify)
Definition: Value.h:81
OpenZWave::Value::~Value
virtual ~Value()
Definition: Value.cpp:134
OpenZWave::Value::GetUnits
string const & GetUnits() const
Definition: Value.h:69
OpenZWave::Value::SetUnits
void SetUnits(string const &_units)
Definition: Value.h:70
OpenZWave::Value::GetPollIntensity
uint8 const & GetPollIntensity() const
Definition: Value.h:75
OpenZWave::Value::ReadXML
virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const *_valueElement)
Definition: Value.cpp:148
Ref.h
OpenZWave::Value::SetFromString
virtual bool SetFromString(string const &)
Definition: Value.h:85
OpenZWave::Value::SetPollIntensity
void SetPollIntensity(uint8 const &_intensity)
Definition: Value.h:76
OpenZWave::Driver
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:65
OpenZWave::Value::OnValueChanged
void OnValueChanged()
Definition: Value.cpp:435
OpenZWave::Value::GetHelp
string const GetHelp() const
Definition: Value.cpp:756
OpenZWave::Value::IsWriteOnly
bool IsWriteOnly() const
Definition: Value.h:62
OpenZWave::Value::GetLabel
string const GetLabel() const
Definition: Value.cpp:771
OpenZWave::Value::SetLabel
void SetLabel(string const &_label, string const lang="")
Definition: Value.cpp:777
Defs.h
uint16
unsigned short uint16
Definition: Defs.h:92
OpenZWave
Definition: Bitfield.h:35