ansible4ozw 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ansible.rb +12 -9
- data/lib/ansible/ansible_device.rb +1 -1
- data/lib/ansible/ansible_value.rb +1 -1
- data/lib/ansible/config.rb +8 -5
- data/lib/ansible/devices.rb +1 -0
- data/lib/ansible/knx.rb +0 -0
- data/lib/ansible/knx/dpt/tests/test_dpt10.rb~ +45 -0
- data/lib/ansible/knx/dpt/tests/test_dpt9.rb~ +55 -0
- data/lib/ansible/transceiver.rb +0 -3
- data/lib/ansible/version.rb +3 -0
- data/lib/ansible/zwave.rb +1 -0
- data/lib/ansible/{openzwave → zwave/openzwave}/ozw_constants.rb +1 -2
- data/lib/ansible/{openzwave → zwave/openzwave}/ozw_headers.rb +2 -6
- data/lib/ansible/{openzwave → zwave/openzwave}/ozw_remote_manager.rb +0 -3
- data/lib/ansible/{openzwave → zwave/openzwave}/ozw_types.rb +0 -0
- data/lib/ansible/zwave/openzwave/src/Driver.h +695 -0
- data/lib/ansible/zwave/openzwave/src/Notification.h +165 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Alarm.cpp +142 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Alarm.h +69 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ApplicationStatus.cpp +93 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ApplicationStatus.h +57 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Association.cpp +385 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Association.h +73 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/AssociationCommandConfiguration.cpp +277 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/AssociationCommandConfiguration.h +70 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Basic.cpp +212 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Basic.h +72 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/BasicWindowCovering.cpp +118 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/BasicWindowCovering.h +64 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Battery.cpp +141 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Battery.h +65 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ClimateControlSchedule.cpp +415 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ClimateControlSchedule.h +71 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Clock.cpp +227 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Clock.h +67 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/CommandClass.cpp +546 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/CommandClass.h +145 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/CommandClasses.cpp +291 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/CommandClasses.h +79 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Configuration.cpp +258 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Configuration.h +67 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ControllerReplication.cpp +142 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ControllerReplication.h +63 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/EnergyProduction.cpp +163 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/EnergyProduction.h +65 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Hail.cpp +68 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Hail.h +58 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Indicator.cpp +159 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Indicator.h +66 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Language.cpp +159 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Language.h +65 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Lock.cpp +159 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Lock.h +66 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ManufacturerSpecific.cpp +439 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ManufacturerSpecific.h +116 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Meter.cpp +541 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Meter.h +73 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/MeterPulse.cpp +137 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/MeterPulse.h +65 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/MultiCmd.cpp +77 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/MultiCmd.h +63 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstance.cpp +568 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstance.h +96 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstanceAssociation.cpp +61 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstanceAssociation.h +59 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/NodeNaming.cpp +525 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/NodeNaming.h +66 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Powerlevel.cpp +157 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Powerlevel.h +82 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Proprietary.cpp +62 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Proprietary.h +58 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Protection.cpp +177 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Protection.h +73 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SensorAlarm.cpp +208 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SensorAlarm.h +77 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SensorBinary.cpp +134 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SensorBinary.h +65 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SensorMultilevel.cpp +237 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SensorMultilevel.h +71 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SwitchAll.cpp +219 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SwitchAll.h +69 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SwitchBinary.cpp +157 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SwitchBinary.h +66 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SwitchMultilevel.cpp +559 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SwitchMultilevel.h +83 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleBinary.cpp +151 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleBinary.h +66 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleMultilevel.cpp +195 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleMultilevel.h +75 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanMode.cpp +332 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanMode.h +77 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanState.cpp +149 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanState.h +71 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatMode.cpp +373 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatMode.h +76 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatOperatingState.cpp +147 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatOperatingState.h +71 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatSetpoint.cpp +317 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatSetpoint.h +73 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Version.cpp +255 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/Version.h +71 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/WakeUp.cpp +391 -0
- data/lib/ansible/zwave/openzwave/src/command_classes/WakeUp.h +85 -0
- data/lib/ansible/zwave/openzwave/src/platform/Controller.cpp +68 -0
- data/lib/ansible/zwave/openzwave/src/platform/Controller.h +106 -0
- data/lib/ansible/zwave/openzwave/src/platform/Event.cpp +102 -0
- data/lib/ansible/zwave/openzwave/src/platform/Event.h +91 -0
- data/lib/ansible/zwave/openzwave/src/platform/HidController.cpp +539 -0
- data/lib/ansible/zwave/openzwave/src/platform/HidController.h +147 -0
- data/lib/ansible/zwave/openzwave/src/platform/Log.cpp +310 -0
- data/lib/ansible/zwave/openzwave/src/platform/Log.h +184 -0
- data/lib/ansible/zwave/openzwave/src/platform/Mutex.cpp +96 -0
- data/lib/ansible/zwave/openzwave/src/platform/Mutex.h +88 -0
- data/lib/ansible/zwave/openzwave/src/platform/Ref.h +91 -0
- data/lib/ansible/zwave/openzwave/src/platform/SerialController.cpp +180 -0
- data/lib/ansible/zwave/openzwave/src/platform/SerialController.h +138 -0
- data/lib/ansible/zwave/openzwave/src/platform/Stream.cpp +229 -0
- data/lib/ansible/zwave/openzwave/src/platform/Stream.h +135 -0
- data/lib/ansible/zwave/openzwave/src/platform/Thread.cpp +118 -0
- data/lib/ansible/zwave/openzwave/src/platform/Thread.h +101 -0
- data/lib/ansible/zwave/openzwave/src/platform/TimeStamp.cpp +92 -0
- data/lib/ansible/zwave/openzwave/src/platform/TimeStamp.h +85 -0
- data/lib/ansible/zwave/openzwave/src/platform/Wait.cpp +176 -0
- data/lib/ansible/zwave/openzwave/src/platform/Wait.h +113 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/EventImpl.cpp +262 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/EventImpl.h +62 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/LogImpl.cpp +304 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/LogImpl.h +70 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/MutexImpl.cpp +136 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/MutexImpl.h +56 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/SerialControllerImpl.cpp +368 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/SerialControllerImpl.h +74 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/ThreadImpl.cpp +181 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/ThreadImpl.h +67 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/TimeStampImpl.cpp +121 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/TimeStampImpl.h +84 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/WaitImpl.cpp +160 -0
- data/lib/ansible/zwave/openzwave/src/platform/unix/WaitImpl.h +74 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/EventImpl.cpp +102 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/EventImpl.h +60 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/LogImpl.cpp +302 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/LogImpl.h +71 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/MutexImpl.cpp +114 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/MutexImpl.h +58 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/SerialControllerImpl.cpp +410 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/SerialControllerImpl.h +66 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/ThreadImpl.cpp +158 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/ThreadImpl.h +71 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/TimeStampImpl.cpp +95 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/TimeStampImpl.h +83 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/WaitImpl.cpp +134 -0
- data/lib/ansible/zwave/openzwave/src/platform/windows/WaitImpl.h +73 -0
- data/lib/ansible/zwave/openzwave/src/value_classes/ValueID.h +283 -0
- data/lib/ansible/zwave/{types → openzwave/types}/valuetype_bool.rb +0 -0
- data/lib/ansible/zwave/{types → openzwave/types}/valuetype_button.rb +0 -0
- data/lib/ansible/zwave/{types → openzwave/types}/valuetype_byte.rb +0 -0
- data/lib/ansible/zwave/{types → openzwave/types}/valuetype_decimal.rb +0 -0
- data/lib/ansible/zwave/{types → openzwave/types}/valuetype_int.rb +0 -0
- data/lib/ansible/zwave/{types → openzwave/types}/valuetype_list.rb +0 -0
- data/lib/ansible/zwave/{types → openzwave/types}/valuetype_short.rb +0 -0
- data/lib/ansible/zwave/{types → openzwave/types}/valuetype_string.rb +0 -0
- data/lib/ansible/zwave/zwave_transceiver.rb +2 -8
- data/lib/ansible/zwave/zwave_value.rb +6 -10
- metadata +159 -17
- data/lib/ansible/zwave/zwave_node.rb +0 -5
@@ -0,0 +1,160 @@
|
|
1
|
+
//-----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// WaitImpl.cpp
|
4
|
+
//
|
5
|
+
// POSIX implementation of an 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
|
+
#include "Defs.h"
|
30
|
+
#include "Wait.h"
|
31
|
+
#include "WaitImpl.h"
|
32
|
+
|
33
|
+
#include <stdio.h>
|
34
|
+
#include <errno.h>
|
35
|
+
|
36
|
+
using namespace OpenZWave;
|
37
|
+
|
38
|
+
//-----------------------------------------------------------------------------
|
39
|
+
// <WaitImpl::WaitImpl>
|
40
|
+
// Constructor
|
41
|
+
//-----------------------------------------------------------------------------
|
42
|
+
WaitImpl::WaitImpl
|
43
|
+
(
|
44
|
+
Wait* _owner
|
45
|
+
):
|
46
|
+
m_owner( _owner )
|
47
|
+
{
|
48
|
+
pthread_mutexattr_t ma;
|
49
|
+
pthread_mutexattr_init ( &ma );
|
50
|
+
pthread_mutexattr_settype( &ma, PTHREAD_MUTEX_RECURSIVE );
|
51
|
+
pthread_mutex_init( &m_criticalSection, &ma );
|
52
|
+
pthread_mutexattr_destroy( &ma );
|
53
|
+
}
|
54
|
+
|
55
|
+
//-----------------------------------------------------------------------------
|
56
|
+
// <WaitImpl::~WaitImpl>
|
57
|
+
// Destructor
|
58
|
+
//-----------------------------------------------------------------------------
|
59
|
+
WaitImpl::~WaitImpl
|
60
|
+
(
|
61
|
+
)
|
62
|
+
{
|
63
|
+
pthread_mutex_destroy( &m_criticalSection );
|
64
|
+
}
|
65
|
+
|
66
|
+
//-----------------------------------------------------------------------------
|
67
|
+
// <WaitImpl::AddWatcher>
|
68
|
+
// Add a watcher to our object.
|
69
|
+
//-----------------------------------------------------------------------------
|
70
|
+
void WaitImpl::AddWatcher
|
71
|
+
(
|
72
|
+
Wait::pfnWaitNotification_t _callback,
|
73
|
+
void* _context
|
74
|
+
)
|
75
|
+
{
|
76
|
+
// Add the watcher to our list
|
77
|
+
Watcher watcher;
|
78
|
+
watcher.m_callback = _callback;
|
79
|
+
watcher.m_context = _context;
|
80
|
+
|
81
|
+
if( pthread_mutex_lock( &m_criticalSection ) != 0 )
|
82
|
+
{
|
83
|
+
fprintf(stderr, "WaitImpl::AddWatcher lock error %d\n", errno );
|
84
|
+
assert( 0 );
|
85
|
+
}
|
86
|
+
m_watchers.push_back( watcher );
|
87
|
+
if( pthread_mutex_unlock( &m_criticalSection ) != 0 )
|
88
|
+
{
|
89
|
+
fprintf(stderr, "WaitImpl::AddWatcher unlock error %d\n", errno );
|
90
|
+
assert( 0 );
|
91
|
+
}
|
92
|
+
|
93
|
+
// If the object is already in a signalled state, notify the watcher immediately
|
94
|
+
if( m_owner->IsSignalled() )
|
95
|
+
{
|
96
|
+
_callback( _context );
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
//-----------------------------------------------------------------------------
|
101
|
+
// <WaitImpl::RemoveWatcher>
|
102
|
+
// Remove a watcher from our object.
|
103
|
+
//-----------------------------------------------------------------------------
|
104
|
+
bool WaitImpl::RemoveWatcher
|
105
|
+
(
|
106
|
+
Wait::pfnWaitNotification_t _callback,
|
107
|
+
void* _context
|
108
|
+
)
|
109
|
+
{
|
110
|
+
bool res = false;
|
111
|
+
|
112
|
+
if( pthread_mutex_lock( &m_criticalSection ) != 0 )
|
113
|
+
{
|
114
|
+
fprintf(stderr, "WaitImpl::RemoveWatcher lock error %d\n", errno );
|
115
|
+
assert( 0 );
|
116
|
+
}
|
117
|
+
|
118
|
+
for( list<Watcher>::iterator it=m_watchers.begin(); it!=m_watchers.end(); ++it )
|
119
|
+
{
|
120
|
+
Watcher const& watcher = *it;
|
121
|
+
if( ( watcher.m_callback == _callback ) && ( watcher.m_context == _context ) )
|
122
|
+
{
|
123
|
+
m_watchers.erase( it );
|
124
|
+
res = true;
|
125
|
+
break;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
if( pthread_mutex_unlock( &m_criticalSection ) != 0 )
|
130
|
+
{
|
131
|
+
fprintf(stderr, "WaitImpl::RemoveWatcher unlock error %d\n", errno );
|
132
|
+
assert( 0 );
|
133
|
+
}
|
134
|
+
return res;
|
135
|
+
}
|
136
|
+
|
137
|
+
//-----------------------------------------------------------------------------
|
138
|
+
// <WaitImpl::Notify>
|
139
|
+
// Notify all the watchers that the object has become signalled
|
140
|
+
//-----------------------------------------------------------------------------
|
141
|
+
void WaitImpl::Notify
|
142
|
+
(
|
143
|
+
)
|
144
|
+
{
|
145
|
+
if( pthread_mutex_lock( &m_criticalSection ) != 0 )
|
146
|
+
{
|
147
|
+
fprintf(stderr, "WaitImpl::Notify lock error %d\n", errno );
|
148
|
+
assert( 0 );
|
149
|
+
}
|
150
|
+
for( list<Watcher>::iterator it=m_watchers.begin(); it!=m_watchers.end(); ++it )
|
151
|
+
{
|
152
|
+
Watcher const& watcher = *it;
|
153
|
+
watcher.m_callback( watcher.m_context );
|
154
|
+
}
|
155
|
+
if( pthread_mutex_unlock( &m_criticalSection ) != 0 )
|
156
|
+
{
|
157
|
+
fprintf(stderr, "WaitImpl::Notify unlock error %d\n", errno );
|
158
|
+
assert( 0 );
|
159
|
+
}
|
160
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
//-----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// WaitImpl.h
|
4
|
+
//
|
5
|
+
// POSIX implementation of a 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 _WaitImpl_H
|
30
|
+
#define _WaitImpl_H
|
31
|
+
|
32
|
+
#include <stdio.h>
|
33
|
+
#include <pthread.h>
|
34
|
+
#include <list>
|
35
|
+
#include "Defs.h"
|
36
|
+
#include "Ref.h"
|
37
|
+
#include "Wait.h"
|
38
|
+
|
39
|
+
namespace OpenZWave
|
40
|
+
{
|
41
|
+
/** \brief Windows specific implementation of Wait objects.
|
42
|
+
*/
|
43
|
+
class WaitImpl
|
44
|
+
{
|
45
|
+
private:
|
46
|
+
friend class Wait;
|
47
|
+
|
48
|
+
WaitImpl( Wait* _owner );
|
49
|
+
virtual ~WaitImpl();
|
50
|
+
|
51
|
+
void AddWatcher( Wait::pfnWaitNotification_t _callback, void* _context );
|
52
|
+
bool RemoveWatcher( Wait::pfnWaitNotification_t _callback, void* _context );
|
53
|
+
void Notify();
|
54
|
+
|
55
|
+
static int32 Multiple( Wait** _objects, uint32 _numObjects, int32 _timeout = -1 );
|
56
|
+
|
57
|
+
WaitImpl( Wait const& ); // prevent copy
|
58
|
+
WaitImpl& operator = ( WaitImpl const& ); // prevent assignment
|
59
|
+
|
60
|
+
struct Watcher
|
61
|
+
{
|
62
|
+
Wait::pfnWaitNotification_t m_callback;
|
63
|
+
void* m_context;
|
64
|
+
};
|
65
|
+
|
66
|
+
list<Watcher> m_watchers;
|
67
|
+
Wait* m_owner;
|
68
|
+
pthread_mutex_t m_criticalSection;
|
69
|
+
};
|
70
|
+
|
71
|
+
} // namespace OpenZWave
|
72
|
+
|
73
|
+
#endif //_WaitImpl_H
|
74
|
+
|
@@ -0,0 +1,102 @@
|
|
1
|
+
//-----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// EventImpl.cpp
|
4
|
+
//
|
5
|
+
// Windows implementation of a cross-platform event
|
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 <windows.h>
|
29
|
+
|
30
|
+
#include "Defs.h"
|
31
|
+
#include "EventImpl.h"
|
32
|
+
|
33
|
+
using namespace OpenZWave;
|
34
|
+
|
35
|
+
|
36
|
+
//-----------------------------------------------------------------------------
|
37
|
+
// <EventImpl::EventImpl>
|
38
|
+
// Constructor
|
39
|
+
//-----------------------------------------------------------------------------
|
40
|
+
EventImpl::EventImpl
|
41
|
+
(
|
42
|
+
)
|
43
|
+
{
|
44
|
+
// Create a manual reset event
|
45
|
+
m_hEvent = ::CreateEvent( NULL, TRUE, FALSE, NULL );
|
46
|
+
}
|
47
|
+
|
48
|
+
//-----------------------------------------------------------------------------
|
49
|
+
// <EventImpl::~EventImpl>
|
50
|
+
// Destructor
|
51
|
+
//-----------------------------------------------------------------------------
|
52
|
+
EventImpl::~EventImpl
|
53
|
+
(
|
54
|
+
)
|
55
|
+
{
|
56
|
+
::CloseHandle( m_hEvent );
|
57
|
+
}
|
58
|
+
|
59
|
+
//-----------------------------------------------------------------------------
|
60
|
+
// <EventImpl::Set>
|
61
|
+
// Set the event to signalled
|
62
|
+
//-----------------------------------------------------------------------------
|
63
|
+
void EventImpl::Set
|
64
|
+
(
|
65
|
+
)
|
66
|
+
{
|
67
|
+
::SetEvent( m_hEvent );
|
68
|
+
}
|
69
|
+
|
70
|
+
//-----------------------------------------------------------------------------
|
71
|
+
// <EventImpl::Reset>
|
72
|
+
// Set the event to not signalled
|
73
|
+
//-----------------------------------------------------------------------------
|
74
|
+
void EventImpl::Reset
|
75
|
+
(
|
76
|
+
)
|
77
|
+
{
|
78
|
+
::ResetEvent( m_hEvent );
|
79
|
+
}
|
80
|
+
|
81
|
+
//-----------------------------------------------------------------------------
|
82
|
+
// <EventImpl::IsSignalled>
|
83
|
+
// Test whether the event is set
|
84
|
+
//-----------------------------------------------------------------------------
|
85
|
+
bool EventImpl::IsSignalled
|
86
|
+
(
|
87
|
+
)
|
88
|
+
{
|
89
|
+
return( WAIT_OBJECT_0 == WaitForSingleObject( m_hEvent, 0 ) );
|
90
|
+
}
|
91
|
+
|
92
|
+
//-----------------------------------------------------------------------------
|
93
|
+
// <EventImpl::Wait>
|
94
|
+
// Wait for the event to become signalled
|
95
|
+
//-----------------------------------------------------------------------------
|
96
|
+
bool EventImpl::Wait
|
97
|
+
(
|
98
|
+
int32 const _timeout
|
99
|
+
)
|
100
|
+
{
|
101
|
+
return( WAIT_TIMEOUT != ::WaitForSingleObject( m_hEvent, (DWORD)_timeout ) );
|
102
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
//-----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// EventImpl.h
|
4
|
+
//
|
5
|
+
// Windows implementation of a cross-platform event
|
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 _EventImpl_H
|
29
|
+
#define _EventImpl_H
|
30
|
+
|
31
|
+
#include <Windows.h>
|
32
|
+
#include "Defs.h"
|
33
|
+
|
34
|
+
namespace OpenZWave
|
35
|
+
{
|
36
|
+
/** \brief Windows-specific implementation of the Event class.
|
37
|
+
*/
|
38
|
+
class EventImpl
|
39
|
+
{
|
40
|
+
private:
|
41
|
+
friend class Event;
|
42
|
+
friend class SocketImpl;
|
43
|
+
friend class Wait;
|
44
|
+
|
45
|
+
EventImpl();
|
46
|
+
~EventImpl();
|
47
|
+
|
48
|
+
void Set();
|
49
|
+
void Reset();
|
50
|
+
|
51
|
+
bool Wait( int32 _timeout ); // The wait method is to be used only by the Wait::Multiple method
|
52
|
+
bool IsSignalled();
|
53
|
+
|
54
|
+
HANDLE m_hEvent;
|
55
|
+
};
|
56
|
+
|
57
|
+
} // namespace OpenZWave
|
58
|
+
|
59
|
+
#endif //_EventImpl_H
|
60
|
+
|
@@ -0,0 +1,302 @@
|
|
1
|
+
//-----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// LogImpl.cpp
|
4
|
+
//
|
5
|
+
// Windows implementation of 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
|
+
#include <windows.h>
|
29
|
+
|
30
|
+
#include "Defs.h"
|
31
|
+
#include "LogImpl.h"
|
32
|
+
|
33
|
+
using namespace OpenZWave;
|
34
|
+
|
35
|
+
//-----------------------------------------------------------------------------
|
36
|
+
// <LogImpl::LogImpl>
|
37
|
+
// Constructor
|
38
|
+
//-----------------------------------------------------------------------------
|
39
|
+
LogImpl::LogImpl
|
40
|
+
(
|
41
|
+
string const& _filename,
|
42
|
+
bool const _bAppendLog,
|
43
|
+
bool const _bConsoleOutput,
|
44
|
+
LogLevel const _saveLevel,
|
45
|
+
LogLevel const _queueLevel,
|
46
|
+
LogLevel const _dumpTrigger
|
47
|
+
):
|
48
|
+
m_filename( _filename ), // name of log file
|
49
|
+
m_bAppendLog( _bAppendLog ), // true to append (and not overwrite) any existing log
|
50
|
+
m_bConsoleOutput( _bConsoleOutput ), // true to provide a copy of output to console
|
51
|
+
m_saveLevel( _saveLevel ), // level of messages to log to file
|
52
|
+
m_queueLevel( _queueLevel ), // level of messages to log to queue
|
53
|
+
m_dumpTrigger( _dumpTrigger ) // dump queued messages when this level is seen
|
54
|
+
{
|
55
|
+
string accessType;
|
56
|
+
|
57
|
+
// create an adjusted file name and timestamp string
|
58
|
+
string timeStr = GetTimeStampString();
|
59
|
+
|
60
|
+
if ( m_bAppendLog )
|
61
|
+
{
|
62
|
+
accessType = "a";
|
63
|
+
}
|
64
|
+
else
|
65
|
+
{
|
66
|
+
accessType = "w";
|
67
|
+
}
|
68
|
+
|
69
|
+
FILE* pFile;
|
70
|
+
if( !fopen_s( &pFile, _filename.c_str(), accessType.c_str() ) )
|
71
|
+
{
|
72
|
+
fprintf( pFile, "\nLogging started %s\n\n", timeStr.c_str() );
|
73
|
+
fclose( pFile );
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
//-----------------------------------------------------------------------------
|
78
|
+
// <LogImpl::~LogImpl>
|
79
|
+
// Destructor
|
80
|
+
//-----------------------------------------------------------------------------
|
81
|
+
LogImpl::~LogImpl
|
82
|
+
(
|
83
|
+
)
|
84
|
+
{
|
85
|
+
}
|
86
|
+
|
87
|
+
//-----------------------------------------------------------------------------
|
88
|
+
// <LogImpl::Write>
|
89
|
+
// Write to the log
|
90
|
+
//-----------------------------------------------------------------------------
|
91
|
+
void LogImpl::Write
|
92
|
+
(
|
93
|
+
LogLevel _logLevel,
|
94
|
+
uint8 const _nodeId,
|
95
|
+
char const* _format,
|
96
|
+
va_list _args
|
97
|
+
)
|
98
|
+
{
|
99
|
+
// create a timestamp string
|
100
|
+
string timeStr = GetTimeStampString();
|
101
|
+
string nodeStr = GetNodeString( _nodeId );
|
102
|
+
|
103
|
+
// handle this message
|
104
|
+
if( (_logLevel <= m_queueLevel) || (_logLevel == LogLevel_Internal) ) // we're going to do something with this message...
|
105
|
+
{
|
106
|
+
char lineBuf[1024];
|
107
|
+
if( !_format || ( _format[0] == 0 ) )
|
108
|
+
{
|
109
|
+
strcpy_s( lineBuf, 1024, "" );
|
110
|
+
}
|
111
|
+
else
|
112
|
+
{
|
113
|
+
vsprintf_s( lineBuf, sizeof(lineBuf), _format, _args );
|
114
|
+
}
|
115
|
+
|
116
|
+
// should this message be saved to file (and possibly written to console?)
|
117
|
+
if( (_logLevel <= m_saveLevel) || (_logLevel == LogLevel_Internal) )
|
118
|
+
{
|
119
|
+
// save to file
|
120
|
+
FILE* pFile;
|
121
|
+
if( !fopen_s( &pFile, m_filename.c_str(), "a" ) )
|
122
|
+
{
|
123
|
+
if( _logLevel != LogLevel_Internal ) // don't add a second timestamp to display of queued messages
|
124
|
+
{
|
125
|
+
fprintf( pFile, "%s%s", timeStr.c_str(), nodeStr.c_str() );
|
126
|
+
if( m_bConsoleOutput )
|
127
|
+
{
|
128
|
+
printf( "%s%s", timeStr.c_str(), nodeStr.c_str() );
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
// print message to file (and possibly screen)
|
133
|
+
fprintf( pFile, "%s", lineBuf );
|
134
|
+
if( m_bConsoleOutput )
|
135
|
+
{
|
136
|
+
printf( "%s", lineBuf );
|
137
|
+
}
|
138
|
+
|
139
|
+
// add a newline
|
140
|
+
fprintf( pFile, "\n" );
|
141
|
+
if( m_bConsoleOutput )
|
142
|
+
{
|
143
|
+
printf( "\n" );
|
144
|
+
}
|
145
|
+
|
146
|
+
fclose( pFile );
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
if( _logLevel != LogLevel_Internal )
|
151
|
+
{
|
152
|
+
char queueBuf[1024];
|
153
|
+
string threadStr = GetThreadId();
|
154
|
+
sprintf_s( queueBuf, sizeof(queueBuf), "%s%s%s", timeStr.c_str(), threadStr.c_str(), lineBuf );
|
155
|
+
Queue( queueBuf );
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
// now check to see if the _dumpTrigger has been hit
|
160
|
+
if( (_logLevel <= m_dumpTrigger) && (_logLevel != LogLevel_Internal) && (_logLevel != LogLevel_Always) )
|
161
|
+
{
|
162
|
+
QueueDump();
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
//-----------------------------------------------------------------------------
|
167
|
+
// <LogImpl::Queue>
|
168
|
+
// Write to the log queue
|
169
|
+
//-----------------------------------------------------------------------------
|
170
|
+
void LogImpl::Queue
|
171
|
+
(
|
172
|
+
char const* _buffer
|
173
|
+
)
|
174
|
+
{
|
175
|
+
string bufStr = _buffer;
|
176
|
+
m_logQueue.push_back( bufStr );
|
177
|
+
|
178
|
+
// rudimentary queue size management
|
179
|
+
if( m_logQueue.size() > 500 )
|
180
|
+
{
|
181
|
+
m_logQueue.pop_front();
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
//-----------------------------------------------------------------------------
|
186
|
+
// <LogImpl::QueueDump>
|
187
|
+
// Dump the LogQueue to output device
|
188
|
+
//-----------------------------------------------------------------------------
|
189
|
+
void LogImpl::QueueDump
|
190
|
+
(
|
191
|
+
)
|
192
|
+
{
|
193
|
+
Log::Write( LogLevel_Internal, "\n\nDumping queued log messages\n");
|
194
|
+
list<string>::iterator it = m_logQueue.begin();
|
195
|
+
while( it != m_logQueue.end() )
|
196
|
+
{
|
197
|
+
string strTemp = *it;
|
198
|
+
Log::Write( LogLevel_Internal, strTemp.c_str() );
|
199
|
+
it++;
|
200
|
+
}
|
201
|
+
m_logQueue.clear();
|
202
|
+
Log::Write( LogLevel_Internal, "\nEnd of queued log message dump\n\n");
|
203
|
+
}
|
204
|
+
|
205
|
+
//-----------------------------------------------------------------------------
|
206
|
+
// <LogImpl::Clear>
|
207
|
+
// Clear the LogQueue
|
208
|
+
//-----------------------------------------------------------------------------
|
209
|
+
void LogImpl::QueueClear
|
210
|
+
(
|
211
|
+
)
|
212
|
+
{
|
213
|
+
m_logQueue.clear();
|
214
|
+
}
|
215
|
+
|
216
|
+
//-----------------------------------------------------------------------------
|
217
|
+
// <LogImpl::SetLoggingState>
|
218
|
+
// Sets the various log state variables
|
219
|
+
//-----------------------------------------------------------------------------
|
220
|
+
void LogImpl::SetLoggingState
|
221
|
+
(
|
222
|
+
LogLevel _saveLevel,
|
223
|
+
LogLevel _queueLevel,
|
224
|
+
LogLevel _dumpTrigger
|
225
|
+
)
|
226
|
+
{
|
227
|
+
m_saveLevel = _saveLevel;
|
228
|
+
m_queueLevel = _queueLevel;
|
229
|
+
m_dumpTrigger = _dumpTrigger;
|
230
|
+
}
|
231
|
+
|
232
|
+
//-----------------------------------------------------------------------------
|
233
|
+
// <LogImpl::GetTimeStampAndThreadId>
|
234
|
+
// Generate a string with formatted current time
|
235
|
+
//-----------------------------------------------------------------------------
|
236
|
+
string LogImpl::GetTimeStampString
|
237
|
+
(
|
238
|
+
)
|
239
|
+
{
|
240
|
+
// Get a timestamp
|
241
|
+
SYSTEMTIME time;
|
242
|
+
::GetLocalTime( &time );
|
243
|
+
|
244
|
+
// create a time stamp string for the log message
|
245
|
+
char buf[100];
|
246
|
+
sprintf_s( buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d:%03d ", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds );
|
247
|
+
string str = buf;
|
248
|
+
return str;
|
249
|
+
}
|
250
|
+
|
251
|
+
//-----------------------------------------------------------------------------
|
252
|
+
// <LogImpl::GetNodeString>
|
253
|
+
// Generate a string with formatted node id
|
254
|
+
//-----------------------------------------------------------------------------
|
255
|
+
string LogImpl::GetNodeString
|
256
|
+
(
|
257
|
+
uint8 const _nodeId
|
258
|
+
)
|
259
|
+
{
|
260
|
+
if( _nodeId == 0 )
|
261
|
+
{
|
262
|
+
return "";
|
263
|
+
}
|
264
|
+
else
|
265
|
+
if( _nodeId == 255 ) // should make distinction between broadcast and controller better for SwitchAll broadcast
|
266
|
+
{
|
267
|
+
return "contrlr, ";
|
268
|
+
}
|
269
|
+
else
|
270
|
+
{
|
271
|
+
char buf[20];
|
272
|
+
snprintf( buf, sizeof(buf), "Node%03d, ", _nodeId );
|
273
|
+
return buf;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
//-----------------------------------------------------------------------------
|
278
|
+
// <LogImpl::GetThreadId>
|
279
|
+
// Generate a string with formatted thread id
|
280
|
+
//-----------------------------------------------------------------------------
|
281
|
+
string LogImpl::GetThreadId
|
282
|
+
(
|
283
|
+
)
|
284
|
+
{
|
285
|
+
char buf[20];
|
286
|
+
DWORD dwThread = ::GetCurrentThreadId();
|
287
|
+
sprintf_s( buf, sizeof(buf), "%04d ", dwThread );
|
288
|
+
string str = buf;
|
289
|
+
return str;
|
290
|
+
}
|
291
|
+
|
292
|
+
//-----------------------------------------------------------------------------
|
293
|
+
// <LogImpl::SetLogFileName>
|
294
|
+
// Provide a new log file name (applicable to future writes)
|
295
|
+
//-----------------------------------------------------------------------------
|
296
|
+
void LogImpl::SetLogFileName
|
297
|
+
(
|
298
|
+
string _filename
|
299
|
+
)
|
300
|
+
{
|
301
|
+
m_filename = _filename;
|
302
|
+
}
|