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