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,62 @@
|
|
1
|
+
//-----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// EventImpl.h
|
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
|
+
#ifndef _EventImpl_H
|
29
|
+
#define _EventImpl_H
|
30
|
+
|
31
|
+
#include <pthread.h>
|
32
|
+
#include <errno.h>
|
33
|
+
|
34
|
+
namespace OpenZWave
|
35
|
+
{
|
36
|
+
class EventImpl
|
37
|
+
{
|
38
|
+
private:
|
39
|
+
friend class Event;
|
40
|
+
friend class SocketImpl;
|
41
|
+
friend class Wait;
|
42
|
+
|
43
|
+
EventImpl();
|
44
|
+
~EventImpl();
|
45
|
+
|
46
|
+
void Set();
|
47
|
+
void Reset();
|
48
|
+
|
49
|
+
bool Wait( int32 _timeout ); // The wait method is to be used only by the Wait::Multiple method
|
50
|
+
bool IsSignalled();
|
51
|
+
|
52
|
+
pthread_mutex_t m_lock;
|
53
|
+
pthread_cond_t m_condition;
|
54
|
+
bool m_manualReset;
|
55
|
+
bool m_isSignaled;
|
56
|
+
unsigned int m_waitingThreads;
|
57
|
+
};
|
58
|
+
|
59
|
+
} // namespace OpenZWave
|
60
|
+
|
61
|
+
#endif //_EventImpl_H
|
62
|
+
|
@@ -0,0 +1,304 @@
|
|
1
|
+
//-----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// LogImpl.cpp
|
4
|
+
//
|
5
|
+
// Unix implementation of message and error logging
|
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 <string>
|
29
|
+
#include <cstring>
|
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_bConsoleOutput( _bConsoleOutput ), // true to provide a copy of output to console
|
50
|
+
m_bAppendLog( _bAppendLog ), // true to append (and not overwrite) any existing log
|
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
|
+
if ( !m_bAppendLog )
|
56
|
+
{
|
57
|
+
FILE* pFile = fopen( m_filename.c_str(), "w" );
|
58
|
+
if( pFile != NULL )
|
59
|
+
{
|
60
|
+
fclose( pFile );
|
61
|
+
}
|
62
|
+
}
|
63
|
+
setlinebuf(stdout); // To prevent buffering and lock contention issues
|
64
|
+
}
|
65
|
+
|
66
|
+
//-----------------------------------------------------------------------------
|
67
|
+
// <LogImpl::~LogImpl>
|
68
|
+
// Destructor
|
69
|
+
//-----------------------------------------------------------------------------
|
70
|
+
LogImpl::~LogImpl
|
71
|
+
(
|
72
|
+
)
|
73
|
+
{
|
74
|
+
}
|
75
|
+
|
76
|
+
//-----------------------------------------------------------------------------
|
77
|
+
// <LogImpl::Write>
|
78
|
+
// Write to the log
|
79
|
+
//-----------------------------------------------------------------------------
|
80
|
+
void LogImpl::Write
|
81
|
+
(
|
82
|
+
LogLevel _logLevel,
|
83
|
+
uint8 const _nodeId,
|
84
|
+
char const* _format,
|
85
|
+
va_list _args
|
86
|
+
)
|
87
|
+
{
|
88
|
+
// create a timestamp string
|
89
|
+
string timeStr = GetTimeStampString();
|
90
|
+
string nodeStr = GetNodeString( _nodeId );
|
91
|
+
|
92
|
+
// handle this message
|
93
|
+
if( (_logLevel <= m_queueLevel) || (_logLevel == LogLevel_Internal) ) // we're going to do something with this message...
|
94
|
+
{
|
95
|
+
char lineBuf[1024] = {};
|
96
|
+
int lineLen = 0;
|
97
|
+
if( _format != NULL && _format[0] != '\0' )
|
98
|
+
{
|
99
|
+
va_list saveargs;
|
100
|
+
va_copy( saveargs, _args );
|
101
|
+
lineLen = vsnprintf( lineBuf, sizeof(lineBuf), _format, _args );
|
102
|
+
va_end( saveargs );
|
103
|
+
}
|
104
|
+
|
105
|
+
// should this message be saved to file (and possibly written to console?)
|
106
|
+
if( (_logLevel <= m_saveLevel) || (_logLevel == LogLevel_Internal) )
|
107
|
+
{
|
108
|
+
char outBuf[1124];
|
109
|
+
char *outBufPtr = outBuf;
|
110
|
+
// save to file
|
111
|
+
FILE* pFile = fopen( m_filename.c_str(), "a" );
|
112
|
+
if ( pFile != NULL )
|
113
|
+
{
|
114
|
+
if( _logLevel != LogLevel_Internal ) // don't add a second timestamp to display of queued messages
|
115
|
+
{
|
116
|
+
strcpy( outBufPtr, timeStr.c_str() );
|
117
|
+
outBufPtr += timeStr.length();
|
118
|
+
strcpy( outBufPtr, nodeStr.c_str() );
|
119
|
+
outBufPtr += nodeStr.length();
|
120
|
+
}
|
121
|
+
|
122
|
+
if( lineLen > 0 )
|
123
|
+
{
|
124
|
+
uint32 len = ( outBufPtr - outBuf ) + lineLen;
|
125
|
+
if( len >= sizeof(outBuf) )
|
126
|
+
{
|
127
|
+
lineLen = sizeof(outBuf) - 3;
|
128
|
+
}
|
129
|
+
strncpy( outBufPtr, lineBuf, lineLen );
|
130
|
+
outBufPtr += lineLen;
|
131
|
+
}
|
132
|
+
|
133
|
+
*outBufPtr++ = '\n';
|
134
|
+
*outBufPtr = '\0';
|
135
|
+
|
136
|
+
// print message to file (and possibly screen)
|
137
|
+
fputs( outBuf, pFile );
|
138
|
+
if( m_bConsoleOutput )
|
139
|
+
{
|
140
|
+
fputs( outBuf, stdout );
|
141
|
+
}
|
142
|
+
|
143
|
+
fclose( pFile );
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
if( _logLevel != LogLevel_Internal )
|
148
|
+
{
|
149
|
+
char queueBuf[1024];
|
150
|
+
string threadStr = GetThreadId();
|
151
|
+
snprintf( queueBuf, sizeof(queueBuf), "%s%s%s", timeStr.c_str(), threadStr.c_str(), lineBuf );
|
152
|
+
Queue( queueBuf );
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
// now check to see if the _dumpTrigger has been hit
|
157
|
+
if( (_logLevel <= m_dumpTrigger) && (_logLevel != LogLevel_Internal) && (_logLevel != LogLevel_Always) )
|
158
|
+
QueueDump();
|
159
|
+
}
|
160
|
+
|
161
|
+
//-----------------------------------------------------------------------------
|
162
|
+
// <LogImpl::Queue>
|
163
|
+
// Write to the log queue
|
164
|
+
//-----------------------------------------------------------------------------
|
165
|
+
void LogImpl::Queue
|
166
|
+
(
|
167
|
+
char const* _buffer
|
168
|
+
)
|
169
|
+
{
|
170
|
+
string bufStr = _buffer;
|
171
|
+
m_logQueue.push_back( bufStr );
|
172
|
+
|
173
|
+
// rudimentary queue size management
|
174
|
+
if( m_logQueue.size() > 500 )
|
175
|
+
{
|
176
|
+
m_logQueue.pop_front();
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
//-----------------------------------------------------------------------------
|
181
|
+
// <LogImpl::QueueDump>
|
182
|
+
// Dump the LogQueue to output device
|
183
|
+
//-----------------------------------------------------------------------------
|
184
|
+
void LogImpl::QueueDump
|
185
|
+
(
|
186
|
+
)
|
187
|
+
{
|
188
|
+
Log::Write( LogLevel_Always, "" );
|
189
|
+
Log::Write( LogLevel_Always, "Dumping queued log messages");
|
190
|
+
Log::Write( LogLevel_Always, "" );
|
191
|
+
list<string>::iterator it = m_logQueue.begin();
|
192
|
+
while( it != m_logQueue.end() )
|
193
|
+
{
|
194
|
+
string strTemp = *it;
|
195
|
+
Log::Write( LogLevel_Internal, strTemp.c_str() );
|
196
|
+
it++;
|
197
|
+
}
|
198
|
+
m_logQueue.clear();
|
199
|
+
Log::Write( LogLevel_Always, "" );
|
200
|
+
Log::Write( LogLevel_Always, "End of queued log message dump");
|
201
|
+
Log::Write( LogLevel_Always, "" );
|
202
|
+
}
|
203
|
+
|
204
|
+
//-----------------------------------------------------------------------------
|
205
|
+
// <LogImpl::Clear>
|
206
|
+
// Clear the LogQueue
|
207
|
+
//-----------------------------------------------------------------------------
|
208
|
+
void LogImpl::QueueClear
|
209
|
+
(
|
210
|
+
)
|
211
|
+
{
|
212
|
+
m_logQueue.clear();
|
213
|
+
}
|
214
|
+
|
215
|
+
//-----------------------------------------------------------------------------
|
216
|
+
// <LogImpl::SetLoggingState>
|
217
|
+
// Sets the various log state variables
|
218
|
+
//-----------------------------------------------------------------------------
|
219
|
+
void LogImpl::SetLoggingState
|
220
|
+
(
|
221
|
+
LogLevel _saveLevel,
|
222
|
+
LogLevel _queueLevel,
|
223
|
+
LogLevel _dumpTrigger
|
224
|
+
)
|
225
|
+
{
|
226
|
+
m_saveLevel = _saveLevel;
|
227
|
+
m_queueLevel = _queueLevel;
|
228
|
+
m_dumpTrigger = _dumpTrigger;
|
229
|
+
}
|
230
|
+
|
231
|
+
//-----------------------------------------------------------------------------
|
232
|
+
// <LogImpl::GetTimeStampAndThreadId>
|
233
|
+
// Generate a string with formatted current time
|
234
|
+
//-----------------------------------------------------------------------------
|
235
|
+
string LogImpl::GetTimeStampString
|
236
|
+
(
|
237
|
+
)
|
238
|
+
{
|
239
|
+
// Get a timestamp
|
240
|
+
struct timeval tv;
|
241
|
+
gettimeofday(&tv, NULL);
|
242
|
+
struct tm *tm;
|
243
|
+
tm = localtime( &tv.tv_sec );
|
244
|
+
|
245
|
+
// create a time stamp string for the log message
|
246
|
+
char buf[100];
|
247
|
+
snprintf( buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d:%03d ",
|
248
|
+
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
249
|
+
tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec / 1000 );
|
250
|
+
string str = buf;
|
251
|
+
return str;
|
252
|
+
}
|
253
|
+
|
254
|
+
//-----------------------------------------------------------------------------
|
255
|
+
// <LogImpl::GetNodeString>
|
256
|
+
// Generate a string with formatted node id
|
257
|
+
//-----------------------------------------------------------------------------
|
258
|
+
string LogImpl::GetNodeString
|
259
|
+
(
|
260
|
+
uint8 const _nodeId
|
261
|
+
)
|
262
|
+
{
|
263
|
+
if( _nodeId == 0 )
|
264
|
+
{
|
265
|
+
return "";
|
266
|
+
}
|
267
|
+
else
|
268
|
+
if( _nodeId == 255 ) // should make distinction between broadcast and controller better for SwitchAll broadcast
|
269
|
+
{
|
270
|
+
return "contrlr, ";
|
271
|
+
}
|
272
|
+
else
|
273
|
+
{
|
274
|
+
char buf[20];
|
275
|
+
snprintf( buf, sizeof(buf), "Node%03d, ", _nodeId );
|
276
|
+
return buf;
|
277
|
+
}
|
278
|
+
}
|
279
|
+
|
280
|
+
//-----------------------------------------------------------------------------
|
281
|
+
// <LogImpl::GetThreadId>
|
282
|
+
// Generate a string with formatted thread id
|
283
|
+
//-----------------------------------------------------------------------------
|
284
|
+
string LogImpl::GetThreadId
|
285
|
+
(
|
286
|
+
)
|
287
|
+
{
|
288
|
+
char buf[20];
|
289
|
+
snprintf( buf, sizeof(buf), "%08x ", pthread_self() );
|
290
|
+
string str = buf;
|
291
|
+
return str;
|
292
|
+
}
|
293
|
+
|
294
|
+
//-----------------------------------------------------------------------------
|
295
|
+
// <LogImpl::SetLogFileName>
|
296
|
+
// Provide a new log file name (applicable to future writes)
|
297
|
+
//-----------------------------------------------------------------------------
|
298
|
+
void LogImpl::SetLogFileName
|
299
|
+
(
|
300
|
+
string _filename
|
301
|
+
)
|
302
|
+
{
|
303
|
+
m_filename = _filename;
|
304
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
//-----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// LogImpl.h
|
4
|
+
//
|
5
|
+
// Unix implementation of message and error logging
|
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
|
+
#ifndef _LogImpl_H
|
29
|
+
#define _LogImpl_H
|
30
|
+
|
31
|
+
#include <stdio.h>
|
32
|
+
#include <stdarg.h>
|
33
|
+
#include <time.h>
|
34
|
+
#include <sys/time.h>
|
35
|
+
#include "Log.h"
|
36
|
+
|
37
|
+
namespace OpenZWave
|
38
|
+
{
|
39
|
+
class LogImpl : public i_LogImpl
|
40
|
+
{
|
41
|
+
private:
|
42
|
+
friend class Log;
|
43
|
+
|
44
|
+
LogImpl( string const& _filename, bool const _bAppendLog, bool const _bConsoleOutput, LogLevel const _saveLevel, LogLevel const _queueLevel, LogLevel const _dumpTrigger );
|
45
|
+
~LogImpl();
|
46
|
+
|
47
|
+
void Write( LogLevel _level, uint8 const _nodeId, char const* _format, va_list _args );
|
48
|
+
void Queue( char const* _buffer );
|
49
|
+
void QueueDump();
|
50
|
+
void QueueClear();
|
51
|
+
void SetLoggingState( LogLevel _saveLevel, LogLevel _queueLevel, LogLevel _dumpTrigger );
|
52
|
+
void SetLogFileName( string _filename );
|
53
|
+
|
54
|
+
string GetTimeStampString();
|
55
|
+
string GetNodeString( uint8 const _nodeId );
|
56
|
+
string GetThreadId();
|
57
|
+
|
58
|
+
string m_filename; /**< filename specified by user (default is ozw_log.txt) */
|
59
|
+
bool m_bConsoleOutput; /**< if true, send log output to console as well as to the file */
|
60
|
+
bool m_bAppendLog; /**< if true, the log file should be appended to any with the same name */
|
61
|
+
list<string> m_logQueue; /**< list of queued log messages */
|
62
|
+
LogLevel m_saveLevel;
|
63
|
+
LogLevel m_queueLevel;
|
64
|
+
LogLevel m_dumpTrigger;
|
65
|
+
};
|
66
|
+
|
67
|
+
} // namespace OpenZWave
|
68
|
+
|
69
|
+
#endif //_LogImpl_H
|
70
|
+
|
@@ -0,0 +1,136 @@
|
|
1
|
+
//----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// MutexImpl.cpp
|
4
|
+
//
|
5
|
+
// POSIX implementation of the cross-platform mutex
|
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
|
+
|
29
|
+
#include "Defs.h"
|
30
|
+
#include "Log.h"
|
31
|
+
#include "MutexImpl.h"
|
32
|
+
|
33
|
+
#include <stdio.h>
|
34
|
+
#include <errno.h>
|
35
|
+
|
36
|
+
using namespace OpenZWave;
|
37
|
+
|
38
|
+
//-----------------------------------------------------------------------------
|
39
|
+
// <MutexImpl::MutexImpl>
|
40
|
+
// Constructor
|
41
|
+
//-----------------------------------------------------------------------------
|
42
|
+
MutexImpl::MutexImpl
|
43
|
+
(
|
44
|
+
):
|
45
|
+
m_lockCount( 0 )
|
46
|
+
{
|
47
|
+
pthread_mutexattr_t ma;
|
48
|
+
|
49
|
+
pthread_mutexattr_init ( &ma );
|
50
|
+
pthread_mutexattr_settype( &ma, PTHREAD_MUTEX_RECURSIVE );
|
51
|
+
int err = pthread_mutex_init( &m_criticalSection, &ma );
|
52
|
+
if( err != 0 )
|
53
|
+
{
|
54
|
+
fprintf(stderr, "MutexImpl::MutexImpl error %d (%d)\n", errno, err );
|
55
|
+
}
|
56
|
+
pthread_mutexattr_destroy( &ma );
|
57
|
+
}
|
58
|
+
|
59
|
+
//-----------------------------------------------------------------------------
|
60
|
+
// <MutexImpl::~MutexImpl>
|
61
|
+
// Destructor
|
62
|
+
//-----------------------------------------------------------------------------
|
63
|
+
MutexImpl::~MutexImpl
|
64
|
+
(
|
65
|
+
)
|
66
|
+
{
|
67
|
+
pthread_mutex_destroy( &m_criticalSection );
|
68
|
+
}
|
69
|
+
|
70
|
+
//-----------------------------------------------------------------------------
|
71
|
+
// <MutexImpl::Lock>
|
72
|
+
// Lock the mutex
|
73
|
+
//-----------------------------------------------------------------------------
|
74
|
+
bool MutexImpl::Lock
|
75
|
+
(
|
76
|
+
bool const _bWait
|
77
|
+
)
|
78
|
+
{
|
79
|
+
if( _bWait )
|
80
|
+
{
|
81
|
+
// We will wait for the lock
|
82
|
+
int err = pthread_mutex_lock( &m_criticalSection );
|
83
|
+
if( err == 0 )
|
84
|
+
{
|
85
|
+
++m_lockCount;
|
86
|
+
return true;
|
87
|
+
}
|
88
|
+
fprintf(stderr, "MutexImpl::Lock error %d (%d)\n", errno, err);
|
89
|
+
return false;
|
90
|
+
}
|
91
|
+
|
92
|
+
// Returns immediately, even if the lock was not available.
|
93
|
+
if( pthread_mutex_trylock( &m_criticalSection ) )
|
94
|
+
{
|
95
|
+
return false;
|
96
|
+
}
|
97
|
+
|
98
|
+
++m_lockCount;
|
99
|
+
return true;
|
100
|
+
}
|
101
|
+
|
102
|
+
//-----------------------------------------------------------------------------
|
103
|
+
// <MutexImpl::Unlock>
|
104
|
+
// Release our lock on the mutex
|
105
|
+
//-----------------------------------------------------------------------------
|
106
|
+
void MutexImpl::Unlock
|
107
|
+
(
|
108
|
+
)
|
109
|
+
{
|
110
|
+
if( !m_lockCount )
|
111
|
+
{
|
112
|
+
// No locks - we have a mismatched lock/release pair
|
113
|
+
assert(0);
|
114
|
+
}
|
115
|
+
else
|
116
|
+
{
|
117
|
+
--m_lockCount;
|
118
|
+
int err = pthread_mutex_unlock( &m_criticalSection );
|
119
|
+
if( err != 0 )
|
120
|
+
{
|
121
|
+
fprintf(stderr, "MutexImpl::Unlock error %d (%d)\n", errno, err);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
//-----------------------------------------------------------------------------
|
127
|
+
// <MutexImpl::IsSignalled>
|
128
|
+
// Test whether the mutex is free
|
129
|
+
//-----------------------------------------------------------------------------
|
130
|
+
bool MutexImpl::IsSignalled
|
131
|
+
(
|
132
|
+
)
|
133
|
+
{
|
134
|
+
return( 0 == m_lockCount );
|
135
|
+
}
|
136
|
+
|