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,85 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // TimeStamp.h
4
+ //
5
+ // Cross-platform TimeStamp
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 _TimeStamp_H
29
+ #define _TimeStamp_H
30
+
31
+ #include "Defs.h"
32
+
33
+ namespace OpenZWave
34
+ {
35
+ class TimeStampImpl;
36
+
37
+ /** \brief Implements a platform-independent TimeStamp.
38
+ */
39
+ class TimeStamp
40
+ {
41
+ public:
42
+ /**
43
+ * Constructor.
44
+ * Creates a TimeStamp object.
45
+ */
46
+ TimeStamp();
47
+
48
+ /**
49
+ * Destructor.
50
+ * Destroys the TimeStamp object.
51
+ */
52
+ ~TimeStamp();
53
+
54
+ /**
55
+ * SetTime. Sets the timestamp to now, plus the offset in milliseconds.
56
+ * \param _milliseconds optional positive or negative offset from
57
+ * now in milliseconds. Defaults to zero.
58
+ */
59
+ void SetTime( int32 _milliseconds = 0 );
60
+
61
+ /**
62
+ * TimeRemaining. Gets the difference between now and the timestamp
63
+ * time in milliseconds.
64
+ * \return milliseconds remaining until we reach the timestamp. The
65
+ * return value is negative if the timestamp is in the past.
66
+ */
67
+ int32 TimeRemaining();
68
+
69
+ /**
70
+ * Overload the subtract operator to get the difference between
71
+ * two timestamps in milliseconds.
72
+ */
73
+ int32 operator- ( TimeStamp const& _other );
74
+
75
+ private:
76
+ TimeStamp( TimeStamp const& ); // prevent copy
77
+ TimeStamp& operator = ( TimeStamp const& ); // prevent assignment
78
+
79
+ TimeStampImpl* m_pImpl; // Pointer to an object that encapsulates the platform-specific implementation of the TimeStamp.
80
+ };
81
+
82
+ } // namespace OpenZWave
83
+
84
+ #endif //_TimeStamp_H
85
+
@@ -0,0 +1,176 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // Wait.cpp
4
+ //
5
+ // Base class for objects we want to be able to wait for.
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 "Wait.h"
30
+ #include "WaitImpl.h" // Platform-specific implementation of a Wait object
31
+ #include "Event.h"
32
+ #include "Log.h"
33
+
34
+ using namespace OpenZWave;
35
+
36
+ void WaitMultipleCallback( void* _context );
37
+
38
+ //-----------------------------------------------------------------------------
39
+ // <Wait::Wait>
40
+ // Constructor
41
+ //-----------------------------------------------------------------------------
42
+ Wait::Wait
43
+ (
44
+ )
45
+ {
46
+ m_pImpl = new WaitImpl( this );
47
+ }
48
+
49
+ //-----------------------------------------------------------------------------
50
+ // <Wait::~Wait>
51
+ // Destructor
52
+ //-----------------------------------------------------------------------------
53
+ Wait::~Wait
54
+ (
55
+ )
56
+ {
57
+ delete m_pImpl;
58
+ }
59
+
60
+ //-----------------------------------------------------------------------------
61
+ // <Wait::AddWatcher>
62
+ // Add a watcher to our object.
63
+ //-----------------------------------------------------------------------------
64
+ void Wait::AddWatcher
65
+ (
66
+ pfnWaitNotification_t _callback,
67
+ void* _context
68
+ )
69
+ {
70
+ if( !_callback )
71
+ {
72
+ assert(0);
73
+ return;
74
+ }
75
+
76
+ // Add a ref so our object cannot disappear while being watched
77
+ AddRef();
78
+
79
+ // Add the watcher (platform specific code required here for thread safety)
80
+ m_pImpl->AddWatcher( _callback, _context );
81
+ }
82
+
83
+ //-----------------------------------------------------------------------------
84
+ // <Wait::RemoveWatcher>
85
+ // Remove a watcher from our object.
86
+ //-----------------------------------------------------------------------------
87
+ void Wait::RemoveWatcher
88
+ (
89
+ pfnWaitNotification_t _callback,
90
+ void* _context
91
+ )
92
+ {
93
+ if( m_pImpl->RemoveWatcher( _callback, _context ) )
94
+ {
95
+ Release();
96
+ }
97
+ }
98
+
99
+ //-----------------------------------------------------------------------------
100
+ // <Wait::Notify>
101
+ // Notify all the watchers that the object has become signalled
102
+ //-----------------------------------------------------------------------------
103
+ void Wait::Notify
104
+ (
105
+ )
106
+ {
107
+ m_pImpl->Notify();
108
+ }
109
+
110
+ //-----------------------------------------------------------------------------
111
+ // <Wait::Multiple>
112
+ // Wait for one of multiple objects to become signalled.
113
+ //-----------------------------------------------------------------------------
114
+ int32 Wait::Multiple
115
+ (
116
+ Wait** _objects,
117
+ uint32 _numObjects,
118
+ int32 _timeout // = -1
119
+ )
120
+ {
121
+ uint32 i;
122
+
123
+ // Create an event that will be set when any of the objects in the list becomes signalled.
124
+ Event* waitEvent = new Event();
125
+
126
+ // Add a watcher to each object in the list, passing in the event as the context.
127
+ for( i=0; i<_numObjects; ++i )
128
+ {
129
+ _objects[i]->AddWatcher( WaitMultipleCallback, waitEvent );
130
+ }
131
+
132
+ int32 res = -1; // Default to timeout result
133
+ string str = "";
134
+ if( waitEvent->Wait( _timeout ) )
135
+ {
136
+ // An object was signalled. Run through the list
137
+ // and see which one it was.
138
+ for( i=0; i<_numObjects; ++i )
139
+ {
140
+ if( _objects[i]->IsSignalled() )
141
+ {
142
+ if( res == -1 )
143
+ res = (int32)i;
144
+ char buf[15];
145
+ snprintf(buf, sizeof(buf), "%d, ", i);
146
+ str += buf;
147
+ }
148
+ }
149
+ }
150
+ Log::Write( LogLevel_Debug, "Wait::Multiple res=%d num=%d >%s", res, _numObjects, str.c_str() );
151
+
152
+ // Remove the watchers
153
+ for( i=0; i<_numObjects; ++i )
154
+ {
155
+ _objects[i]->RemoveWatcher( WaitMultipleCallback, waitEvent );
156
+ }
157
+
158
+ // We're done with the event now
159
+ waitEvent->Release();
160
+ return res;
161
+ }
162
+
163
+
164
+ //-----------------------------------------------------------------------------
165
+ // <WaitMultipleCallback>
166
+ // Callback handler for the watchers added during WaitImpl::Multiple
167
+ //-----------------------------------------------------------------------------
168
+ void WaitMultipleCallback
169
+ (
170
+ void* _context
171
+ )
172
+ {
173
+ Event* waitEvent = (Event*)_context;
174
+ waitEvent->Set();
175
+ }
176
+
@@ -0,0 +1,113 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // Wait.h
4
+ //
5
+ // Cross-platform abstract base class for objects we
6
+ // want to be able to wait for.
7
+ //
8
+ // Copyright (c) 2010 Mal Lansell <mal@lansell.org>
9
+ // All rights reserved.
10
+ //
11
+ // SOFTWARE NOTICE AND LICENSE
12
+ //
13
+ // This file is part of OpenZWave.
14
+ //
15
+ // OpenZWave is free software: you can redistribute it and/or modify
16
+ // it under the terms of the GNU Lesser General Public License as published
17
+ // by the Free Software Foundation, either version 3 of the License,
18
+ // or (at your option) any later version.
19
+ //
20
+ // OpenZWave is distributed in the hope that it will be useful,
21
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ // GNU Lesser General Public License for more details.
24
+ //
25
+ // You should have received a copy of the GNU Lesser General Public License
26
+ // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
27
+ //
28
+ //-----------------------------------------------------------------------------
29
+ #ifndef _Wait_H
30
+ #define _Wait_H
31
+
32
+ #include <list>
33
+ #include "Ref.h"
34
+
35
+ namespace OpenZWave
36
+ {
37
+ class WaitImpl;
38
+
39
+ /** \brief Platform-independent definition of Wait objects.
40
+ */
41
+ class Wait: public Ref
42
+ {
43
+ friend class WaitImpl;
44
+ friend class ThreadImpl;
45
+
46
+ public:
47
+ enum
48
+ {
49
+ Timeout_Immediate = 0,
50
+ Timeout_Infinite = -1
51
+ };
52
+
53
+ typedef void (*pfnWaitNotification_t)( void* _context );
54
+
55
+ /**
56
+ * Add a watcher to our object. The watcher will be triggered
57
+ * by the derived class, when it enters a certain state.
58
+ * \param _callback pointer to the function that will be called when the wait is over.
59
+ * \param _context pointer to custom data that will be sent with the callback.
60
+ */
61
+ void AddWatcher( pfnWaitNotification_t _callback, void* _context );
62
+
63
+ /**
64
+ * Remove a watcher from our object. Both the _callback and _context pointers
65
+ * must match those used in a previous call to AddWatcher.
66
+ * \param _callback pointer to the function that will be called when the wait is over.
67
+ * \param _context pointer to custom data that will be sent with the callback.
68
+ */
69
+ void RemoveWatcher( pfnWaitNotification_t _callback, void* _context );
70
+
71
+ /**
72
+ * Wait for a single object to become signalled.
73
+ * \param _object pointer to the object to wait on.
74
+ * \param _timeout optional maximum time to wait. Defaults to -1, which means wait forever.
75
+ * \return zero if the object was signalled, -1 if the wait timed out.
76
+ */
77
+ static int32 Single( Wait* _object, int32 _timeout = -1 ){ return Multiple( &_object, 1, _timeout ); }
78
+
79
+ /**
80
+ * Wait for one of multiple objects to become signalled. If more than one object is in
81
+ * a signalled state, the lowest array index will be returned.
82
+ * \param _objects array of pointers to objects to wait on.
83
+ * \param _numObjects number of objects in the array.
84
+ * \param _timeout optional maximum time to wait. Defaults to -1, which means wait forever.
85
+ * \return index into the array of the object that was signalled, -1 if the wait timed out.
86
+ */
87
+ static int32 Multiple( Wait** _objects, uint32 _numObjects, int32 _timeout = -1 );
88
+
89
+ protected:
90
+ Wait();
91
+ virtual ~Wait();
92
+
93
+ /**
94
+ * Notify the watchers that the object is signalled.
95
+ */
96
+ void Notify();
97
+
98
+ /**
99
+ * Test whether an object is signalled.
100
+ */
101
+ virtual bool IsSignalled() = 0;
102
+
103
+ private:
104
+ Wait( Wait const& ); // prevent copy
105
+ Wait& operator = ( Wait const& ); // prevent assignment
106
+
107
+ WaitImpl* m_pImpl; // Pointer to an object that encapsulates the platform-specific implementation of a Wait object.
108
+ };
109
+
110
+ } // namespace OpenZWave
111
+
112
+ #endif //_Wait_H
113
+
@@ -0,0 +1,262 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // EventImpl.cpp
4
+ //
5
+ // POSIX implementation of a cross-platform event
6
+ //
7
+ // Copyright (c) 2010, Greg Satz <satz@iranger.com>
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 "EventImpl.h"
30
+
31
+ #include <stdio.h>
32
+ #include <sys/time.h>
33
+
34
+ using namespace OpenZWave;
35
+
36
+ //-----------------------------------------------------------------------------
37
+ // <EventImpl::EventImpl>
38
+ // Constructor
39
+ //-----------------------------------------------------------------------------
40
+ EventImpl::EventImpl
41
+ (
42
+ ):
43
+ m_manualReset( true ),
44
+ m_isSignaled( false ),
45
+ m_waitingThreads( 0 )
46
+ {
47
+ pthread_mutexattr_t ma;
48
+ pthread_mutexattr_init( &ma );
49
+ pthread_mutexattr_settype( &ma, PTHREAD_MUTEX_ERRORCHECK );
50
+ pthread_mutex_init( &m_lock, &ma );
51
+ pthread_mutexattr_destroy( &ma );
52
+
53
+ pthread_condattr_t ca;
54
+ pthread_condattr_init( &ca );
55
+ pthread_condattr_setpshared( &ca, PTHREAD_PROCESS_PRIVATE );
56
+ pthread_cond_init( &m_condition, &ca );
57
+ pthread_condattr_destroy( &ca );
58
+ }
59
+
60
+ //-----------------------------------------------------------------------------
61
+ // <EventImpl::~EventImpl>
62
+ // Destructor
63
+ //-----------------------------------------------------------------------------
64
+ EventImpl::~EventImpl
65
+ (
66
+ )
67
+ {
68
+ pthread_mutex_destroy( &m_lock );
69
+ pthread_cond_destroy( &m_condition );
70
+ }
71
+
72
+ //-----------------------------------------------------------------------------
73
+ // <EventImpl::Set>
74
+ // Set the event to signalled
75
+ //-----------------------------------------------------------------------------
76
+ void EventImpl::Set
77
+ (
78
+ )
79
+ {
80
+ int err = pthread_mutex_lock( &m_lock );
81
+ if( err != 0 )
82
+ {
83
+ fprintf(stderr, "EventImpl::Set lock error %d (%d)\n", errno, err );
84
+ assert( 0 );
85
+ }
86
+ if( m_manualReset )
87
+ {
88
+ m_isSignaled = true;
89
+ err = pthread_cond_broadcast( &m_condition );
90
+ if( err != 0 )
91
+ {
92
+ fprintf(stderr, "EventImpl::Set cond broadcast error %d (%s)\n", errno, err );
93
+ assert( 0 );
94
+ }
95
+ }
96
+ else
97
+ {
98
+ if( !m_waitingThreads )
99
+ {
100
+ m_isSignaled = true;
101
+ }
102
+ else
103
+ {
104
+ err = pthread_cond_signal( &m_condition );
105
+ if( err != 0 )
106
+ {
107
+ fprintf(stderr, "EventImpl::Set cond signal error %d (%d)\n", errno, err );
108
+ assert( 0 );
109
+ }
110
+ }
111
+ }
112
+ err = pthread_mutex_unlock( &m_lock );
113
+ if( err != 0 )
114
+ {
115
+ fprintf(stderr, "EventImpl::Set unlock error %d (%d)\n", errno, err );
116
+ assert( 0 );
117
+ }
118
+ }
119
+
120
+ //-----------------------------------------------------------------------------
121
+ // <EventImpl::Reset>
122
+ // Set the event to not signalled
123
+ //-----------------------------------------------------------------------------
124
+ void EventImpl::Reset
125
+ (
126
+ )
127
+ {
128
+ int err = pthread_mutex_lock ( &m_lock );
129
+ if( err != 0 )
130
+ {
131
+ fprintf(stderr, "EventImpl::Reset lock error %d (%d)\n", errno, err );
132
+ assert( 0 );
133
+ }
134
+ m_isSignaled = false;
135
+ err = pthread_mutex_unlock( &m_lock );
136
+ if( err != 0 )
137
+ {
138
+ fprintf(stderr, "EventImpl::Reset unlock error %d (%d)\n", errno, err );
139
+ assert( 0 );
140
+ }
141
+ }
142
+
143
+ //-----------------------------------------------------------------------------
144
+ // <EventImpl::IsSignalled>
145
+ // Test whether the event is set
146
+ //-----------------------------------------------------------------------------
147
+ bool EventImpl::IsSignalled
148
+ (
149
+ )
150
+ {
151
+ return m_isSignaled;
152
+ }
153
+
154
+ //-----------------------------------------------------------------------------
155
+ // <EventImpl::Wait>
156
+ // Wait for the event to become signalled
157
+ //-----------------------------------------------------------------------------
158
+ bool EventImpl::Wait
159
+ (
160
+ int32 const _timeout /* milliseconds */
161
+ )
162
+ {
163
+ bool result = true;
164
+
165
+ int err = pthread_mutex_lock( &m_lock );
166
+ if( err != 0 )
167
+ {
168
+ fprintf(stderr, "EventImpl::Wait lock error %d (%d)\n", errno, err );
169
+ assert( 0 );
170
+ }
171
+ if( m_isSignaled )
172
+ {
173
+ if ( !m_manualReset )
174
+ {
175
+ m_isSignaled = false;
176
+ }
177
+ }
178
+ else
179
+ {
180
+ ++m_waitingThreads;
181
+ if( _timeout == 0 )
182
+ {
183
+ result = m_isSignaled;
184
+ }
185
+ else if( _timeout > 0 )
186
+ {
187
+ struct timeval now;
188
+ struct timespec abstime;
189
+
190
+ gettimeofday(&now, NULL);
191
+
192
+ abstime.tv_sec = now.tv_sec + (_timeout / 1000);
193
+
194
+ // Now add the remainder of our timeout to the microseconds part of 'now'
195
+ now.tv_usec += (_timeout % 1000) * 1000;
196
+
197
+ // Careful now! Did it wrap?
198
+ while( now.tv_usec >= ( 1000 * 1000 ) )
199
+ {
200
+ // Yes it did so bump our seconds and subtract
201
+ now.tv_usec -= (1000 * 1000);
202
+ abstime.tv_sec++;
203
+ }
204
+
205
+ abstime.tv_nsec = now.tv_usec * 1000;
206
+
207
+ while( !m_isSignaled )
208
+ {
209
+ int oldstate;
210
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
211
+
212
+ err = pthread_cond_timedwait( &m_condition, &m_lock, &abstime );
213
+
214
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
215
+
216
+ if( err == ETIMEDOUT )
217
+ {
218
+ result = false;
219
+ break;
220
+ }
221
+ else
222
+ if( err == 0 )
223
+ {
224
+ result = true;
225
+ }
226
+ else
227
+ {
228
+ fprintf(stderr, "EventImpl::Wait cond timedwait error %d (%d)\n", errno, err );
229
+ assert( 0 );
230
+ }
231
+ }
232
+ }
233
+ else
234
+ {
235
+ while( !m_isSignaled )
236
+ {
237
+ int oldstate;
238
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
239
+
240
+ err = pthread_cond_wait( &m_condition, &m_lock );
241
+
242
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
243
+
244
+ if( err != 0 )
245
+ {
246
+ fprintf(stderr, "EventImpl::Wait cond wait error %d (%d)\n", errno, err );
247
+ assert( 0 );
248
+ }
249
+ }
250
+ }
251
+ --m_waitingThreads;
252
+ }
253
+
254
+ err = pthread_mutex_unlock( &m_lock );
255
+ if( err != 0 )
256
+ {
257
+ fprintf(stderr, "EventImpl::Wait unlock error %d (%d)\n", errno, err );
258
+ assert( 0 );
259
+ }
260
+ return result;
261
+ }
262
+