ansible4ozw 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. data/lib/ansible.rb +12 -9
  2. data/lib/ansible/ansible_device.rb +1 -1
  3. data/lib/ansible/ansible_value.rb +1 -1
  4. data/lib/ansible/config.rb +8 -5
  5. data/lib/ansible/devices.rb +1 -0
  6. data/lib/ansible/knx.rb +0 -0
  7. data/lib/ansible/knx/dpt/tests/test_dpt10.rb~ +45 -0
  8. data/lib/ansible/knx/dpt/tests/test_dpt9.rb~ +55 -0
  9. data/lib/ansible/transceiver.rb +0 -3
  10. data/lib/ansible/version.rb +3 -0
  11. data/lib/ansible/zwave.rb +1 -0
  12. data/lib/ansible/{openzwave → zwave/openzwave}/ozw_constants.rb +1 -2
  13. data/lib/ansible/{openzwave → zwave/openzwave}/ozw_headers.rb +2 -6
  14. data/lib/ansible/{openzwave → zwave/openzwave}/ozw_remote_manager.rb +0 -3
  15. data/lib/ansible/{openzwave → zwave/openzwave}/ozw_types.rb +0 -0
  16. data/lib/ansible/zwave/openzwave/src/Driver.h +695 -0
  17. data/lib/ansible/zwave/openzwave/src/Notification.h +165 -0
  18. data/lib/ansible/zwave/openzwave/src/command_classes/Alarm.cpp +142 -0
  19. data/lib/ansible/zwave/openzwave/src/command_classes/Alarm.h +69 -0
  20. data/lib/ansible/zwave/openzwave/src/command_classes/ApplicationStatus.cpp +93 -0
  21. data/lib/ansible/zwave/openzwave/src/command_classes/ApplicationStatus.h +57 -0
  22. data/lib/ansible/zwave/openzwave/src/command_classes/Association.cpp +385 -0
  23. data/lib/ansible/zwave/openzwave/src/command_classes/Association.h +73 -0
  24. data/lib/ansible/zwave/openzwave/src/command_classes/AssociationCommandConfiguration.cpp +277 -0
  25. data/lib/ansible/zwave/openzwave/src/command_classes/AssociationCommandConfiguration.h +70 -0
  26. data/lib/ansible/zwave/openzwave/src/command_classes/Basic.cpp +212 -0
  27. data/lib/ansible/zwave/openzwave/src/command_classes/Basic.h +72 -0
  28. data/lib/ansible/zwave/openzwave/src/command_classes/BasicWindowCovering.cpp +118 -0
  29. data/lib/ansible/zwave/openzwave/src/command_classes/BasicWindowCovering.h +64 -0
  30. data/lib/ansible/zwave/openzwave/src/command_classes/Battery.cpp +141 -0
  31. data/lib/ansible/zwave/openzwave/src/command_classes/Battery.h +65 -0
  32. data/lib/ansible/zwave/openzwave/src/command_classes/ClimateControlSchedule.cpp +415 -0
  33. data/lib/ansible/zwave/openzwave/src/command_classes/ClimateControlSchedule.h +71 -0
  34. data/lib/ansible/zwave/openzwave/src/command_classes/Clock.cpp +227 -0
  35. data/lib/ansible/zwave/openzwave/src/command_classes/Clock.h +67 -0
  36. data/lib/ansible/zwave/openzwave/src/command_classes/CommandClass.cpp +546 -0
  37. data/lib/ansible/zwave/openzwave/src/command_classes/CommandClass.h +145 -0
  38. data/lib/ansible/zwave/openzwave/src/command_classes/CommandClasses.cpp +291 -0
  39. data/lib/ansible/zwave/openzwave/src/command_classes/CommandClasses.h +79 -0
  40. data/lib/ansible/zwave/openzwave/src/command_classes/Configuration.cpp +258 -0
  41. data/lib/ansible/zwave/openzwave/src/command_classes/Configuration.h +67 -0
  42. data/lib/ansible/zwave/openzwave/src/command_classes/ControllerReplication.cpp +142 -0
  43. data/lib/ansible/zwave/openzwave/src/command_classes/ControllerReplication.h +63 -0
  44. data/lib/ansible/zwave/openzwave/src/command_classes/EnergyProduction.cpp +163 -0
  45. data/lib/ansible/zwave/openzwave/src/command_classes/EnergyProduction.h +65 -0
  46. data/lib/ansible/zwave/openzwave/src/command_classes/Hail.cpp +68 -0
  47. data/lib/ansible/zwave/openzwave/src/command_classes/Hail.h +58 -0
  48. data/lib/ansible/zwave/openzwave/src/command_classes/Indicator.cpp +159 -0
  49. data/lib/ansible/zwave/openzwave/src/command_classes/Indicator.h +66 -0
  50. data/lib/ansible/zwave/openzwave/src/command_classes/Language.cpp +159 -0
  51. data/lib/ansible/zwave/openzwave/src/command_classes/Language.h +65 -0
  52. data/lib/ansible/zwave/openzwave/src/command_classes/Lock.cpp +159 -0
  53. data/lib/ansible/zwave/openzwave/src/command_classes/Lock.h +66 -0
  54. data/lib/ansible/zwave/openzwave/src/command_classes/ManufacturerSpecific.cpp +439 -0
  55. data/lib/ansible/zwave/openzwave/src/command_classes/ManufacturerSpecific.h +116 -0
  56. data/lib/ansible/zwave/openzwave/src/command_classes/Meter.cpp +541 -0
  57. data/lib/ansible/zwave/openzwave/src/command_classes/Meter.h +73 -0
  58. data/lib/ansible/zwave/openzwave/src/command_classes/MeterPulse.cpp +137 -0
  59. data/lib/ansible/zwave/openzwave/src/command_classes/MeterPulse.h +65 -0
  60. data/lib/ansible/zwave/openzwave/src/command_classes/MultiCmd.cpp +77 -0
  61. data/lib/ansible/zwave/openzwave/src/command_classes/MultiCmd.h +63 -0
  62. data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstance.cpp +568 -0
  63. data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstance.h +96 -0
  64. data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstanceAssociation.cpp +61 -0
  65. data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstanceAssociation.h +59 -0
  66. data/lib/ansible/zwave/openzwave/src/command_classes/NodeNaming.cpp +525 -0
  67. data/lib/ansible/zwave/openzwave/src/command_classes/NodeNaming.h +66 -0
  68. data/lib/ansible/zwave/openzwave/src/command_classes/Powerlevel.cpp +157 -0
  69. data/lib/ansible/zwave/openzwave/src/command_classes/Powerlevel.h +82 -0
  70. data/lib/ansible/zwave/openzwave/src/command_classes/Proprietary.cpp +62 -0
  71. data/lib/ansible/zwave/openzwave/src/command_classes/Proprietary.h +58 -0
  72. data/lib/ansible/zwave/openzwave/src/command_classes/Protection.cpp +177 -0
  73. data/lib/ansible/zwave/openzwave/src/command_classes/Protection.h +73 -0
  74. data/lib/ansible/zwave/openzwave/src/command_classes/SensorAlarm.cpp +208 -0
  75. data/lib/ansible/zwave/openzwave/src/command_classes/SensorAlarm.h +77 -0
  76. data/lib/ansible/zwave/openzwave/src/command_classes/SensorBinary.cpp +134 -0
  77. data/lib/ansible/zwave/openzwave/src/command_classes/SensorBinary.h +65 -0
  78. data/lib/ansible/zwave/openzwave/src/command_classes/SensorMultilevel.cpp +237 -0
  79. data/lib/ansible/zwave/openzwave/src/command_classes/SensorMultilevel.h +71 -0
  80. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchAll.cpp +219 -0
  81. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchAll.h +69 -0
  82. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchBinary.cpp +157 -0
  83. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchBinary.h +66 -0
  84. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchMultilevel.cpp +559 -0
  85. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchMultilevel.h +83 -0
  86. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleBinary.cpp +151 -0
  87. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleBinary.h +66 -0
  88. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleMultilevel.cpp +195 -0
  89. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleMultilevel.h +75 -0
  90. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanMode.cpp +332 -0
  91. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanMode.h +77 -0
  92. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanState.cpp +149 -0
  93. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanState.h +71 -0
  94. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatMode.cpp +373 -0
  95. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatMode.h +76 -0
  96. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatOperatingState.cpp +147 -0
  97. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatOperatingState.h +71 -0
  98. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatSetpoint.cpp +317 -0
  99. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatSetpoint.h +73 -0
  100. data/lib/ansible/zwave/openzwave/src/command_classes/Version.cpp +255 -0
  101. data/lib/ansible/zwave/openzwave/src/command_classes/Version.h +71 -0
  102. data/lib/ansible/zwave/openzwave/src/command_classes/WakeUp.cpp +391 -0
  103. data/lib/ansible/zwave/openzwave/src/command_classes/WakeUp.h +85 -0
  104. data/lib/ansible/zwave/openzwave/src/platform/Controller.cpp +68 -0
  105. data/lib/ansible/zwave/openzwave/src/platform/Controller.h +106 -0
  106. data/lib/ansible/zwave/openzwave/src/platform/Event.cpp +102 -0
  107. data/lib/ansible/zwave/openzwave/src/platform/Event.h +91 -0
  108. data/lib/ansible/zwave/openzwave/src/platform/HidController.cpp +539 -0
  109. data/lib/ansible/zwave/openzwave/src/platform/HidController.h +147 -0
  110. data/lib/ansible/zwave/openzwave/src/platform/Log.cpp +310 -0
  111. data/lib/ansible/zwave/openzwave/src/platform/Log.h +184 -0
  112. data/lib/ansible/zwave/openzwave/src/platform/Mutex.cpp +96 -0
  113. data/lib/ansible/zwave/openzwave/src/platform/Mutex.h +88 -0
  114. data/lib/ansible/zwave/openzwave/src/platform/Ref.h +91 -0
  115. data/lib/ansible/zwave/openzwave/src/platform/SerialController.cpp +180 -0
  116. data/lib/ansible/zwave/openzwave/src/platform/SerialController.h +138 -0
  117. data/lib/ansible/zwave/openzwave/src/platform/Stream.cpp +229 -0
  118. data/lib/ansible/zwave/openzwave/src/platform/Stream.h +135 -0
  119. data/lib/ansible/zwave/openzwave/src/platform/Thread.cpp +118 -0
  120. data/lib/ansible/zwave/openzwave/src/platform/Thread.h +101 -0
  121. data/lib/ansible/zwave/openzwave/src/platform/TimeStamp.cpp +92 -0
  122. data/lib/ansible/zwave/openzwave/src/platform/TimeStamp.h +85 -0
  123. data/lib/ansible/zwave/openzwave/src/platform/Wait.cpp +176 -0
  124. data/lib/ansible/zwave/openzwave/src/platform/Wait.h +113 -0
  125. data/lib/ansible/zwave/openzwave/src/platform/unix/EventImpl.cpp +262 -0
  126. data/lib/ansible/zwave/openzwave/src/platform/unix/EventImpl.h +62 -0
  127. data/lib/ansible/zwave/openzwave/src/platform/unix/LogImpl.cpp +304 -0
  128. data/lib/ansible/zwave/openzwave/src/platform/unix/LogImpl.h +70 -0
  129. data/lib/ansible/zwave/openzwave/src/platform/unix/MutexImpl.cpp +136 -0
  130. data/lib/ansible/zwave/openzwave/src/platform/unix/MutexImpl.h +56 -0
  131. data/lib/ansible/zwave/openzwave/src/platform/unix/SerialControllerImpl.cpp +368 -0
  132. data/lib/ansible/zwave/openzwave/src/platform/unix/SerialControllerImpl.h +74 -0
  133. data/lib/ansible/zwave/openzwave/src/platform/unix/ThreadImpl.cpp +181 -0
  134. data/lib/ansible/zwave/openzwave/src/platform/unix/ThreadImpl.h +67 -0
  135. data/lib/ansible/zwave/openzwave/src/platform/unix/TimeStampImpl.cpp +121 -0
  136. data/lib/ansible/zwave/openzwave/src/platform/unix/TimeStampImpl.h +84 -0
  137. data/lib/ansible/zwave/openzwave/src/platform/unix/WaitImpl.cpp +160 -0
  138. data/lib/ansible/zwave/openzwave/src/platform/unix/WaitImpl.h +74 -0
  139. data/lib/ansible/zwave/openzwave/src/platform/windows/EventImpl.cpp +102 -0
  140. data/lib/ansible/zwave/openzwave/src/platform/windows/EventImpl.h +60 -0
  141. data/lib/ansible/zwave/openzwave/src/platform/windows/LogImpl.cpp +302 -0
  142. data/lib/ansible/zwave/openzwave/src/platform/windows/LogImpl.h +71 -0
  143. data/lib/ansible/zwave/openzwave/src/platform/windows/MutexImpl.cpp +114 -0
  144. data/lib/ansible/zwave/openzwave/src/platform/windows/MutexImpl.h +58 -0
  145. data/lib/ansible/zwave/openzwave/src/platform/windows/SerialControllerImpl.cpp +410 -0
  146. data/lib/ansible/zwave/openzwave/src/platform/windows/SerialControllerImpl.h +66 -0
  147. data/lib/ansible/zwave/openzwave/src/platform/windows/ThreadImpl.cpp +158 -0
  148. data/lib/ansible/zwave/openzwave/src/platform/windows/ThreadImpl.h +71 -0
  149. data/lib/ansible/zwave/openzwave/src/platform/windows/TimeStampImpl.cpp +95 -0
  150. data/lib/ansible/zwave/openzwave/src/platform/windows/TimeStampImpl.h +83 -0
  151. data/lib/ansible/zwave/openzwave/src/platform/windows/WaitImpl.cpp +134 -0
  152. data/lib/ansible/zwave/openzwave/src/platform/windows/WaitImpl.h +73 -0
  153. data/lib/ansible/zwave/openzwave/src/value_classes/ValueID.h +283 -0
  154. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_bool.rb +0 -0
  155. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_button.rb +0 -0
  156. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_byte.rb +0 -0
  157. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_decimal.rb +0 -0
  158. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_int.rb +0 -0
  159. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_list.rb +0 -0
  160. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_short.rb +0 -0
  161. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_string.rb +0 -0
  162. data/lib/ansible/zwave/zwave_transceiver.rb +2 -8
  163. data/lib/ansible/zwave/zwave_value.rb +6 -10
  164. metadata +159 -17
  165. data/lib/ansible/zwave/zwave_node.rb +0 -5
@@ -0,0 +1,184 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // Log.h
4
+ //
5
+ // Cross-platform message and error logging
6
+ //
7
+ // Copyright (c) 2010 Mal Lansell <mal@lansell.org>
8
+ // All rights reserved.
9
+ //
10
+ // SOFTWARE NOTICE AND LICENSE
11
+ //
12
+ // This file is part of OpenZWave.
13
+ //
14
+ // OpenZWave is free software: you can redistribute it and/or modify
15
+ // it under the terms of the GNU Lesser General Public License as published
16
+ // by the Free Software Foundation, either version 3 of the License,
17
+ // or (at your option) any later version.
18
+ //
19
+ // OpenZWave is distributed in the hope that it will be useful,
20
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ // GNU Lesser General Public License for more details.
23
+ //
24
+ // You should have received a copy of the GNU Lesser General Public License
25
+ // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
26
+ //
27
+ //-----------------------------------------------------------------------------
28
+ #ifndef _Log_H
29
+ #define _Log_H
30
+
31
+ #include <stdarg.h>
32
+ #include <string>
33
+ #include "Defs.h"
34
+
35
+ namespace OpenZWave
36
+ {
37
+ class Mutex;
38
+
39
+ enum LogLevel
40
+ {
41
+ LogLevel_None, /**< Disable all logging */
42
+ LogLevel_Always, /**< These messages should always be shown */
43
+ LogLevel_Fatal, /**< A likely fatal issue in the library */
44
+ LogLevel_Error, /**< A serious issue with the library or the network */
45
+ LogLevel_Warning, /**< A minor issue from which the library should be able to recover */
46
+ LogLevel_Alert, /**< Something unexpected by the library about which the controlling application should be aware */
47
+ LogLevel_Info, /**< Everything's working fine...these messages provide streamlined feedback on each message */
48
+ LogLevel_Detail, /**< Detailed information on the progress of each message */
49
+ LogLevel_Debug, /**< Very detailed information on progress that will create a huge log file quickly
50
+ But this level (as others) can be queued and sent to the log only on an error or warning */
51
+ LogLevel_Internal /**< Used only within the log class (uses existing timestamp, etc.) */
52
+ };
53
+
54
+ class i_LogImpl
55
+ {
56
+ public:
57
+ i_LogImpl() { } ;
58
+ virtual ~i_LogImpl() { } ;
59
+ virtual void Write( LogLevel _level, uint8 const _nodeId, char const* _format, va_list _args ) = 0;
60
+ virtual void QueueDump() = 0;
61
+ virtual void QueueClear() = 0;
62
+ virtual void SetLoggingState( LogLevel _saveLevel, LogLevel _queueLevel, LogLevel _dumpTrigger ) = 0;
63
+ virtual void SetLogFileName( string _filename ) = 0;
64
+ };
65
+
66
+ /** \brief Implements a platform-independent log...written to the console and, optionally, a file.
67
+ */
68
+ class Log
69
+ {
70
+ public:
71
+ /**
72
+ * Create a log.
73
+ * Creates the cross-platform logging singleton.
74
+ * Any previous log will be cleared.
75
+ * \return a pointer to the logging object.
76
+ * \see Destroy, Write
77
+ */
78
+ static Log* Create( string const& _filename, bool const _bAppend, bool const _bConsoleOutput, LogLevel const _saveLevel, LogLevel const _queueLevel, LogLevel const _dumpTrigger );
79
+
80
+ /**
81
+ * Create a log.
82
+ * Creates the cross-platform logging singleton.
83
+ * Any previous log will be cleared.
84
+ * \param LogClass a Logging Class that inherits the i_LogImpl Class to use to Log
85
+ * \return a pointer to the logging object.
86
+ * \see Destroy, Write
87
+ */
88
+
89
+ static Log* Create( i_LogImpl *LogClass );
90
+
91
+ /**
92
+ * Destroys the log.
93
+ * Destroys the logging singleton. The log can no longer
94
+ * be written to without another call to Create.
95
+ * \see Create, Write
96
+ */
97
+ static void Destroy();
98
+
99
+ /**
100
+ * \brief Set the Logging Implmentation Class to replace the standard File/Console Loggin
101
+ * \param LogClass A Logging Class that inherits the i_LogImpl Class used to Log to
102
+ * \return Bool Value indicating success or failure
103
+ */
104
+ static bool SetLoggingClass(i_LogImpl *LogClass );
105
+
106
+ /**
107
+ * \brief Enable or disable library logging (retained for backward compatibility)
108
+ * \param _dologging If true, logging is enabled; if false, disabled
109
+ */
110
+ static void SetLoggingState(bool _dologging);
111
+
112
+ /**
113
+ * \brief Enable or disable library logging. To disable, set _saveLevel and _queueLevel
114
+ * to LogLevel_None.
115
+ * \param _saveLevel LogLevel of messages to write in real-time
116
+ * \param _queueLevel LogLevel of messages to queue to be dumped in case of an error
117
+ * \param _dumpTrigger LogLevel of message that triggers a queue dump (probably LogLevel_Error or LogLevel_Warning)
118
+ */
119
+ static void SetLoggingState( LogLevel _saveLevel, LogLevel _queueLevel, LogLevel _dumpTrigger );
120
+
121
+ /**
122
+ * \brief Determine whether logging is enabled or not (retained for backward compatibility)
123
+ * \param _dologging If true, logging is enabled; if false, disabled
124
+ */
125
+ static bool GetLoggingState();
126
+
127
+ /**
128
+ * \brief Obtain the various logging levels.
129
+ * \param _saveLevel LogLevel of messages to write in real-time
130
+ * \param _queueLevel LogLevel of messages to queue to be dumped in case of an error
131
+ * \param _dumpTrigger LogLevel of message that triggers a queue dump (probably LogLevel_Error or LogLevel_Warning)
132
+ */
133
+ static void GetLoggingState( LogLevel* _saveLevel, LogLevel* _queueLevel, LogLevel* _dumpTrigger );
134
+
135
+ /**
136
+ * \brief Change the log file name. This will start a new log file (or potentially start appending
137
+ * information to an existing one. Developers might want to use this function, together with a timer
138
+ * in the controlling application, to create timestamped log file names.
139
+ * \param _filename Name of the new (or existing) file to use for log output.
140
+ */
141
+ static void SetLogFileName( string _filename );
142
+
143
+ /**
144
+ * Write an entry to the log.
145
+ * Writes a formatted string to the log.
146
+ * \param _level Specifies the type of log message (Error, Warning, Debug, etc.)
147
+ * \param _format. A string formatted in the same manner as used with printf etc.
148
+ * \param ... a variable number of arguments, to be included in the formatted string.
149
+ * \see Create, Destroy
150
+ */
151
+ static void Write( LogLevel _level, char const* _format, ... );
152
+
153
+ /**
154
+ * Write an entry to the log.
155
+ * Writes a formatted string to the log.
156
+ * \param _level Specifies the type of log message (Error, Warning, Debug, etc.)
157
+ * \param _nodeId Node Id this entry is about.
158
+ * \param _format. A string formatted in the same manner as used with printf etc.
159
+ * \param ... a variable number of arguments, to be included in the formatted string.
160
+ * \see Create, Destroy
161
+ */
162
+ static void Write( LogLevel _level, uint8 const _nodeId, char const* _format, ... );
163
+
164
+ /**
165
+ * Send the queued log messages to the log output.
166
+ */
167
+ static void QueueDump();
168
+
169
+ /**
170
+ * Clear the log message queue
171
+ */
172
+ static void QueueClear();
173
+
174
+ private:
175
+ Log( string const& _filename, bool const _bAppend, bool const _bConsoleOutput, LogLevel _saveLevel, LogLevel _queueLevel, LogLevel _dumpTrigger );
176
+ ~Log();
177
+
178
+ static i_LogImpl* m_pImpl; /**< Pointer to an object that encapsulates the platform-specific logging implementation. */
179
+ static Log* s_instance;
180
+ Mutex* m_logMutex;
181
+ };
182
+ } // namespace OpenZWave
183
+
184
+ #endif //_Log_H
@@ -0,0 +1,96 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // Mutex.cpp
4
+ //
5
+ // Cross-platform mutex
6
+ //
7
+ // Copyright (c) 2010 Mal Lansell <mal@lansell.org>
8
+ // All rights reserved.
9
+ //
10
+ // SOFTWARE NOTICE AND LICENSE
11
+ //
12
+ // This file is part of OpenZWave.
13
+ //
14
+ // OpenZWave is free software: you can redistribute it and/or modify
15
+ // it under the terms of the GNU Lesser General Public License as published
16
+ // by the Free Software Foundation, either version 3 of the License,
17
+ // or (at your option) any later version.
18
+ //
19
+ // OpenZWave is distributed in the hope that it will be useful,
20
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ // GNU Lesser General Public License for more details.
23
+ //
24
+ // You should have received a copy of the GNU Lesser General Public License
25
+ // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
26
+ //
27
+ //-----------------------------------------------------------------------------
28
+ #include "Defs.h"
29
+ #include "Mutex.h"
30
+ #include "MutexImpl.h" // Platform-specific implementation of a mutex
31
+
32
+
33
+ using namespace OpenZWave;
34
+
35
+ //-----------------------------------------------------------------------------
36
+ // <Mutex::Mutex>
37
+ // Constructor
38
+ //-----------------------------------------------------------------------------
39
+ Mutex::Mutex
40
+ (
41
+ ):
42
+ m_pImpl( new MutexImpl() )
43
+ {
44
+ }
45
+
46
+ //-----------------------------------------------------------------------------
47
+ // <Mutex::~Mutex>
48
+ // Destructor
49
+ //-----------------------------------------------------------------------------
50
+ Mutex::~Mutex
51
+ (
52
+ )
53
+ {
54
+ delete m_pImpl;
55
+ }
56
+
57
+ //-----------------------------------------------------------------------------
58
+ // <Mutex::Lock>
59
+ // Lock the mutex
60
+ //-----------------------------------------------------------------------------
61
+ bool Mutex::Lock
62
+ (
63
+ bool const _bWait // = true;
64
+ )
65
+ {
66
+ return m_pImpl->Lock( _bWait );
67
+ }
68
+
69
+ //-----------------------------------------------------------------------------
70
+ // <Mutex::Unlock>
71
+ // Release our lock on the mutex
72
+ //-----------------------------------------------------------------------------
73
+ void Mutex::Unlock
74
+ (
75
+ )
76
+ {
77
+ m_pImpl->Unlock();
78
+
79
+ if( IsSignalled() )
80
+ {
81
+ // The mutex has no owners, so notify the watchers
82
+ Notify();
83
+ }
84
+ }
85
+
86
+ //-----------------------------------------------------------------------------
87
+ // <Mutex::IsSignalled>
88
+ // Test whether the event is set
89
+ //-----------------------------------------------------------------------------
90
+ bool Mutex::IsSignalled
91
+ (
92
+ )
93
+ {
94
+ return m_pImpl->IsSignalled();
95
+ }
96
+
@@ -0,0 +1,88 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // Mutex.h
4
+ //
5
+ // Cross-platform mutex
6
+ //
7
+ // Copyright (c) 2010 Mal Lansell <mal@lansell.org>
8
+ // All rights reserved.
9
+ //
10
+ // SOFTWARE NOTICE AND LICENSE
11
+ //
12
+ // This file is part of OpenZWave.
13
+ //
14
+ // OpenZWave is free software: you can redistribute it and/or modify
15
+ // it under the terms of the GNU Lesser General Public License as published
16
+ // by the Free Software Foundation, either version 3 of the License,
17
+ // or (at your option) any later version.
18
+ //
19
+ // OpenZWave is distributed in the hope that it will be useful,
20
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ // GNU Lesser General Public License for more details.
23
+ //
24
+ // You should have received a copy of the GNU Lesser General Public License
25
+ // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
26
+ //
27
+ //-----------------------------------------------------------------------------
28
+ #ifndef _Mutex_H
29
+ #define _Mutex_H
30
+
31
+ #include "Wait.h"
32
+
33
+ namespace OpenZWave
34
+ {
35
+ class MutexImpl;
36
+
37
+ /** \brief Implements a platform-independent mutex--for serializing access to a shared resource.
38
+ */
39
+ class Mutex: public Wait
40
+ {
41
+ public:
42
+ /**
43
+ * Constructor.
44
+ * Creates a mutex object that can be used to serialize access to a shared resource.
45
+ */
46
+ Mutex();
47
+
48
+ /**
49
+ * Lock the mutex.
50
+ * Attempts to lock the mutex.
51
+ * There must be a matching call to Release for every call to Lock.
52
+ * \param _bWait Defaults to true. Set this argument to false if the method should return
53
+ * immediately, even if the lock is not available.
54
+ * \return True if the lock was obtained.
55
+ * \see Release
56
+ */
57
+ bool Lock( bool const _bWait = true );
58
+
59
+ /**
60
+ * Releases the lock on the mutex.
61
+ * There must be a matching call to Release for every call to Lock.
62
+ * \see Lock
63
+ */
64
+ void Unlock();
65
+
66
+ protected:
67
+ /**
68
+ * Used by the Wait class to test whether the mutex is free.
69
+ */
70
+ virtual bool IsSignalled();
71
+
72
+ /**
73
+ * Destructor.
74
+ * Destroys the mutex object.
75
+ */
76
+ ~Mutex();
77
+
78
+ private:
79
+ Mutex( Mutex const& ); // prevent copy
80
+ Mutex& operator = ( Mutex const& ); // prevent assignment
81
+
82
+ MutexImpl* m_pImpl; // Pointer to an object that encapsulates the platform-specific implementation of a mutex.
83
+ };
84
+
85
+ } // namespace OpenZWave
86
+
87
+ #endif //_Mutex_H
88
+
@@ -0,0 +1,91 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // Ref.h
4
+ //
5
+ // Reference counting for objects.
6
+ //
7
+ // Copyright (c) 2010 Mal Lansell <mal@lansell.org>
8
+ // All rights reserved.
9
+ //
10
+ // SOFTWARE NOTICE AND LICENSE
11
+ //
12
+ // This file is part of OpenZWave.
13
+ //
14
+ // OpenZWave is free software: you can redistribute it and/or modify
15
+ // it under the terms of the GNU Lesser General Public License as published
16
+ // by the Free Software Foundation, either version 3 of the License,
17
+ // or (at your option) any later version.
18
+ //
19
+ // OpenZWave is distributed in the hope that it will be useful,
20
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ // GNU Lesser General Public License for more details.
23
+ //
24
+ // You should have received a copy of the GNU Lesser General Public License
25
+ // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
26
+ //
27
+ //-----------------------------------------------------------------------------
28
+ #ifndef _Ref_H
29
+ #define _Ref_H
30
+
31
+ #pragma once
32
+
33
+ #include "Defs.h"
34
+
35
+ namespace OpenZWave
36
+ {
37
+ /**
38
+ * Provides reference counting for objects.
39
+ * Any class wishing to include reference counting should be derived from Ref.
40
+ * Derived classes must declare their destructor as protected virtual.
41
+ * On construction, the reference count is set to one. Calls to AddRef increment
42
+ * the count. Calls to Release decrement the count. When the count reaches
43
+ * zero, the object is deleted.
44
+ */
45
+ class Ref
46
+ {
47
+ public:
48
+ /**
49
+ * Initializes the RefCount to one. The object
50
+ * can only be deleted through a call to Release.
51
+ * \see AddRef, Release
52
+ */
53
+ Ref(){ m_refs = 1; }
54
+
55
+ /**
56
+ * Increases the reference count of the object.
57
+ * Every call to AddRef requires a matching call
58
+ * to Release before the object will be deleted.
59
+ * \see Release
60
+ */
61
+ void AddRef(){ ++m_refs; }
62
+
63
+ /**
64
+ * Removes a reference to an object.
65
+ * If this was the last reference to the message, the
66
+ * object is deleted.
67
+ * \see AddRef
68
+ */
69
+ int32 Release()
70
+ {
71
+ if( 0 >= ( --m_refs ) )
72
+ {
73
+ delete this;
74
+ return 0;
75
+ }
76
+ return m_refs;
77
+ }
78
+
79
+ protected:
80
+ virtual ~Ref(){}
81
+
82
+ private:
83
+ // Reference counting
84
+ int32 m_refs;
85
+
86
+ }; // class Ref
87
+
88
+ } // namespace OpenZWave
89
+
90
+ #endif // _Ref_H
91
+