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,147 @@
|
|
1
|
+
//-----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// HidController.h
|
4
|
+
//
|
5
|
+
// Cross-platform HID port handler
|
6
|
+
//
|
7
|
+
// Copyright (c) 2010 Jason Frazier <frazierjason@gmail.com>
|
8
|
+
//
|
9
|
+
// SOFTWARE NOTICE AND LICENSE
|
10
|
+
//
|
11
|
+
// This file is part of OpenZWave.
|
12
|
+
//
|
13
|
+
// OpenZWave is free software: you can redistribute it and/or modify
|
14
|
+
// it under the terms of the GNU Lesser General Public License as published
|
15
|
+
// by the Free Software Foundation, either version 3 of the License,
|
16
|
+
// or (at your option) any later version.
|
17
|
+
//
|
18
|
+
// OpenZWave is distributed in the hope that it will be useful,
|
19
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21
|
+
// GNU Lesser General Public License for more details.
|
22
|
+
//
|
23
|
+
// You should have received a copy of the GNU Lesser General Public License
|
24
|
+
// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
|
25
|
+
//
|
26
|
+
//-----------------------------------------------------------------------------
|
27
|
+
|
28
|
+
#ifndef _HidController_H
|
29
|
+
#define _HidController_H
|
30
|
+
|
31
|
+
#include <string>
|
32
|
+
#include "Defs.h"
|
33
|
+
#include "Controller.h"
|
34
|
+
#include "hidapi.h"
|
35
|
+
|
36
|
+
namespace OpenZWave
|
37
|
+
{
|
38
|
+
class Driver;
|
39
|
+
class Msg;
|
40
|
+
class Thread;
|
41
|
+
class Event;
|
42
|
+
|
43
|
+
class HidController: public Controller
|
44
|
+
{
|
45
|
+
public:
|
46
|
+
/**
|
47
|
+
* Constructor.
|
48
|
+
* Creates an object that represents a HID port.
|
49
|
+
*/
|
50
|
+
HidController();
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Destructor.
|
54
|
+
* Destroys the HID port object.
|
55
|
+
*/
|
56
|
+
virtual ~HidController();
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Set the USB vendor ID search value. The HID port must be closed for the setting to be accepted.
|
60
|
+
* @param _baud Vendor ID value to match when enumerating USB HID devices.
|
61
|
+
* @return True if the vendor ID value was accepted.
|
62
|
+
* @see Open, Close
|
63
|
+
*/
|
64
|
+
bool SetVendorId( uint32 const _vendorId );
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Set the USB product ID search value. The HID port must be closed for the setting to be accepted.
|
68
|
+
* @param _parity Product ID value to match when enumerating USB HID devices.
|
69
|
+
* @return True if the product ID value was accepted.
|
70
|
+
* @see Open, Close
|
71
|
+
*/
|
72
|
+
bool SetProductId( uint32 const _productId );
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Set the USB serial number search value. The HID port must be closed for the setting to be accepted.
|
76
|
+
* @param _parity Serial number string to match when enumerating USB HID devices. If empty, any serial number will be accepted.
|
77
|
+
* @return True if the serial number value was accepted.
|
78
|
+
* @see Open, Close
|
79
|
+
*/
|
80
|
+
bool SetSerialNumber( string const& _serialNumber );
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Open a HID port.
|
84
|
+
* Attempts to open a HID port and initialize it with the specified paramters.
|
85
|
+
* @param _HidControllerName The name of the port to open. For example, ttyS1 on Linux, or \\.\COM2 in Windows.
|
86
|
+
* @return True if the port was opened and configured successfully.
|
87
|
+
* @see Close, Read, Write
|
88
|
+
*/
|
89
|
+
bool Open( string const& _hidControllerName );
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Close a HID port.
|
93
|
+
* Closes the HID port.
|
94
|
+
* @return True if the port was closed successfully, or false if the port was already closed, or an error occurred.
|
95
|
+
* @see Open
|
96
|
+
*/
|
97
|
+
bool Close();
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Write to a HID port.
|
101
|
+
* Attempts to write data to an open HID port.
|
102
|
+
* @param _buffer Pointer to a block of memory containing the data to be written.
|
103
|
+
* @param _length Length in bytes of the data.
|
104
|
+
* @return The number of bytes written.
|
105
|
+
* @see Read, Open, Close
|
106
|
+
*/
|
107
|
+
uint32 Write( uint8* _buffer, uint32 _length );
|
108
|
+
|
109
|
+
private:
|
110
|
+
bool Init( uint32 const _attempts );
|
111
|
+
void Read();
|
112
|
+
|
113
|
+
// helpers for internal use only
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Read bytes from the specified HID feature report
|
117
|
+
* @param _buffer Buffer array for receiving the feature report bytes.
|
118
|
+
* @param _length Length of the buffer array.
|
119
|
+
* @param _reportId ID of the report to read.
|
120
|
+
* @return Actual number of bytes retrieved, or -1 on error.
|
121
|
+
*/
|
122
|
+
int GetFeatureReport( uint32 _length, uint8 _reportId, uint8* _buffer );
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Write bytes to the specified HID feature report
|
126
|
+
* @param _data Bytes to be written to the feature report.
|
127
|
+
* @param _length Length of bytes to be written.
|
128
|
+
* @return Actal number of bytes written, or -1 on error.
|
129
|
+
*/
|
130
|
+
int SendFeatureReport( uint32 _length, const uint8* _data );
|
131
|
+
|
132
|
+
static void ThreadEntryPoint( Event* _exitEvent, void* _context );
|
133
|
+
void ThreadProc( Event* _exitEvent );
|
134
|
+
|
135
|
+
hid_device* m_hHidController;
|
136
|
+
Thread* m_thread;
|
137
|
+
uint32 m_vendorId;
|
138
|
+
uint32 m_productId;
|
139
|
+
string m_serialNumber;
|
140
|
+
string m_hidControllerName;
|
141
|
+
bool m_bOpen;
|
142
|
+
};
|
143
|
+
|
144
|
+
} // namespace OpenZWave
|
145
|
+
|
146
|
+
#endif //_HidController_H
|
147
|
+
|
@@ -0,0 +1,310 @@
|
|
1
|
+
//-----------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// Log.cpp
|
4
|
+
//
|
5
|
+
// Cross-platform message and error logging
|
6
|
+
//
|
7
|
+
// Copyright (c) 2010 Mal Lansell <mal@lansell.org>
|
8
|
+
// All rights reserved.
|
9
|
+
//
|
10
|
+
// SOFTWARE NOTICE AND LICENSE
|
11
|
+
//
|
12
|
+
// This file is part of OpenZWave.
|
13
|
+
//
|
14
|
+
// OpenZWave is free software: you can redistribute it and/or modify
|
15
|
+
// it under the terms of the GNU Lesser General Public License as published
|
16
|
+
// by the Free Software Foundation, either version 3 of the License,
|
17
|
+
// or (at your option) any later version.
|
18
|
+
//
|
19
|
+
// OpenZWave is distributed in the hope that it will be useful,
|
20
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22
|
+
// GNU Lesser General Public License for more details.
|
23
|
+
//
|
24
|
+
// You should have received a copy of the GNU Lesser General Public License
|
25
|
+
// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
|
26
|
+
//
|
27
|
+
//-----------------------------------------------------------------------------
|
28
|
+
#include <stdarg.h>
|
29
|
+
|
30
|
+
#include "Defs.h"
|
31
|
+
#include "Mutex.h"
|
32
|
+
#include "Log.h"
|
33
|
+
|
34
|
+
#include "LogImpl.h" // Platform-specific implementation of a log
|
35
|
+
|
36
|
+
|
37
|
+
using namespace OpenZWave;
|
38
|
+
|
39
|
+
Log* Log::s_instance = NULL;
|
40
|
+
i_LogImpl* Log::m_pImpl = NULL;
|
41
|
+
static bool s_dologging;
|
42
|
+
|
43
|
+
//-----------------------------------------------------------------------------
|
44
|
+
// <Log::Create>
|
45
|
+
// Static creation of the singleton
|
46
|
+
//-----------------------------------------------------------------------------
|
47
|
+
Log* Log::Create
|
48
|
+
(
|
49
|
+
string const& _filename,
|
50
|
+
bool const _bAppend,
|
51
|
+
bool const _bConsoleOutput,
|
52
|
+
LogLevel const _saveLevel,
|
53
|
+
LogLevel const _queueLevel,
|
54
|
+
LogLevel const _dumpTrigger
|
55
|
+
)
|
56
|
+
{
|
57
|
+
if( NULL == s_instance )
|
58
|
+
{
|
59
|
+
s_instance = new Log( _filename, _bAppend, _bConsoleOutput, _saveLevel, _queueLevel, _dumpTrigger );
|
60
|
+
s_dologging = true; // default logging to true so no change to what people experience now
|
61
|
+
}
|
62
|
+
|
63
|
+
return s_instance;
|
64
|
+
}
|
65
|
+
|
66
|
+
//-----------------------------------------------------------------------------
|
67
|
+
// <Log::Create>
|
68
|
+
// Static creation of the singleton
|
69
|
+
//-----------------------------------------------------------------------------
|
70
|
+
/* It isn't clear this is ever called or used. If no one complains, consider
|
71
|
+
deleting this code in April 2012.
|
72
|
+
Log* Log::Create
|
73
|
+
(
|
74
|
+
i_LogImpl *LogClass
|
75
|
+
)
|
76
|
+
{
|
77
|
+
if (NULL == s_instance )
|
78
|
+
{
|
79
|
+
s_instance = new Log( "" );
|
80
|
+
s_dologging = true;
|
81
|
+
}
|
82
|
+
SetLoggingClass( LogClass );
|
83
|
+
return s_instance;
|
84
|
+
}
|
85
|
+
*/
|
86
|
+
|
87
|
+
//-----------------------------------------------------------------------------
|
88
|
+
// <Log::Destroy>
|
89
|
+
// Static method to destroy the logging singleton.
|
90
|
+
//-----------------------------------------------------------------------------
|
91
|
+
void Log::Destroy
|
92
|
+
(
|
93
|
+
)
|
94
|
+
{
|
95
|
+
delete s_instance;
|
96
|
+
s_instance = NULL;
|
97
|
+
}
|
98
|
+
|
99
|
+
//-----------------------------------------------------------------------------
|
100
|
+
// <Log::Create>
|
101
|
+
// Static creation of the singleton
|
102
|
+
//-----------------------------------------------------------------------------
|
103
|
+
bool Log::SetLoggingClass
|
104
|
+
(
|
105
|
+
i_LogImpl *LogClass
|
106
|
+
)
|
107
|
+
{
|
108
|
+
delete m_pImpl;
|
109
|
+
m_pImpl = LogClass;
|
110
|
+
return true;
|
111
|
+
}
|
112
|
+
|
113
|
+
//-----------------------------------------------------------------------------
|
114
|
+
// <Log::SetLoggingState>
|
115
|
+
// Set flag to actually write to log or skip it (legacy version)
|
116
|
+
// If logging is enabled, the default log detail settings will be used
|
117
|
+
// Write to file/screen LogLevel_Detail
|
118
|
+
// Save in queue for errors LogLevel_Debug
|
119
|
+
// Trigger for dumping queue LogLevel_Warning
|
120
|
+
// Console output? Yes
|
121
|
+
// Append to an existing log? No (overwrite)
|
122
|
+
//-----------------------------------------------------------------------------
|
123
|
+
void Log::SetLoggingState
|
124
|
+
(
|
125
|
+
bool _dologging
|
126
|
+
)
|
127
|
+
{
|
128
|
+
bool prevLogging = s_dologging;
|
129
|
+
s_dologging = _dologging;
|
130
|
+
|
131
|
+
if (!prevLogging && s_dologging) Log::Write(LogLevel_Always, "Logging started\n\n");
|
132
|
+
}
|
133
|
+
|
134
|
+
//-----------------------------------------------------------------------------
|
135
|
+
// <Log::SetLoggingState>
|
136
|
+
// Set flag to actually write to log or skip it
|
137
|
+
//-----------------------------------------------------------------------------
|
138
|
+
void Log::SetLoggingState
|
139
|
+
(
|
140
|
+
LogLevel _saveLevel,
|
141
|
+
LogLevel _queueLevel,
|
142
|
+
LogLevel _dumpTrigger
|
143
|
+
)
|
144
|
+
{
|
145
|
+
// parameter checking:
|
146
|
+
// _queueLevel cannot be less than or equal to _saveLevel (where lower ordinals are more severe conditions)
|
147
|
+
// _dumpTrigger cannot be greater than or equal to _queueLevel
|
148
|
+
if( _queueLevel <= _saveLevel )
|
149
|
+
Log::Write( LogLevel_Warning, "Only lower priority messages may be queued for error-driven display." );
|
150
|
+
if( _dumpTrigger >= _queueLevel )
|
151
|
+
Log::Write( LogLevel_Warning, "The trigger for dumping queued messages must be a higher-priority message than the level that is queued." );
|
152
|
+
|
153
|
+
bool prevLogging = s_dologging;
|
154
|
+
// s_dologging is true if any messages are to be saved in file or queue
|
155
|
+
if( (_saveLevel > LogLevel_Always) ||
|
156
|
+
(_queueLevel > LogLevel_Always) )
|
157
|
+
{
|
158
|
+
s_dologging = true;
|
159
|
+
}
|
160
|
+
else
|
161
|
+
{
|
162
|
+
s_dologging = false;
|
163
|
+
}
|
164
|
+
|
165
|
+
if( s_instance && s_dologging && s_instance->m_pImpl )
|
166
|
+
{
|
167
|
+
s_instance->m_logMutex->Lock();
|
168
|
+
s_instance->m_pImpl->SetLoggingState( _saveLevel, _queueLevel, _dumpTrigger );
|
169
|
+
s_instance->m_logMutex->Unlock();
|
170
|
+
}
|
171
|
+
|
172
|
+
if (!prevLogging && s_dologging) Log::Write(LogLevel_Always, "Logging started\n\n");
|
173
|
+
}
|
174
|
+
|
175
|
+
//-----------------------------------------------------------------------------
|
176
|
+
// <Log::GetLoggingState>
|
177
|
+
// Return a flag to indicate whether logging is enabled
|
178
|
+
//-----------------------------------------------------------------------------
|
179
|
+
bool Log::GetLoggingState
|
180
|
+
(
|
181
|
+
)
|
182
|
+
{
|
183
|
+
return s_dologging;
|
184
|
+
}
|
185
|
+
|
186
|
+
//-----------------------------------------------------------------------------
|
187
|
+
// <Log::Write>
|
188
|
+
// Write to the log
|
189
|
+
//-----------------------------------------------------------------------------
|
190
|
+
void Log::Write
|
191
|
+
(
|
192
|
+
LogLevel _level,
|
193
|
+
char const* _format,
|
194
|
+
...
|
195
|
+
)
|
196
|
+
{
|
197
|
+
if( s_instance && s_dologging && s_instance->m_pImpl )
|
198
|
+
{
|
199
|
+
s_instance->m_logMutex->Lock(); // double locks if recursive
|
200
|
+
va_list args;
|
201
|
+
va_start( args, _format );
|
202
|
+
s_instance->m_pImpl->Write( _level, 0, _format, args );
|
203
|
+
va_end( args );
|
204
|
+
s_instance->m_logMutex->Unlock();
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
//-----------------------------------------------------------------------------
|
209
|
+
// <Log::Write>
|
210
|
+
// Write to the log
|
211
|
+
//-----------------------------------------------------------------------------
|
212
|
+
void Log::Write
|
213
|
+
(
|
214
|
+
LogLevel _level,
|
215
|
+
uint8 const _nodeId,
|
216
|
+
char const* _format,
|
217
|
+
...
|
218
|
+
)
|
219
|
+
{
|
220
|
+
if( s_instance && s_dologging && s_instance->m_pImpl )
|
221
|
+
{
|
222
|
+
if( _level != LogLevel_Internal )
|
223
|
+
s_instance->m_logMutex->Lock();
|
224
|
+
va_list args;
|
225
|
+
va_start( args, _format );
|
226
|
+
s_instance->m_pImpl->Write( _level, _nodeId, _format, args );
|
227
|
+
va_end( args );
|
228
|
+
if( _level != LogLevel_Internal )
|
229
|
+
s_instance->m_logMutex->Unlock();
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
//-----------------------------------------------------------------------------
|
234
|
+
// <Log::QueueDump>
|
235
|
+
// Send queued messages to the log (and empty the queue)
|
236
|
+
//-----------------------------------------------------------------------------
|
237
|
+
void Log::QueueDump
|
238
|
+
(
|
239
|
+
)
|
240
|
+
{
|
241
|
+
if( s_instance && s_dologging && s_instance->m_pImpl )
|
242
|
+
{
|
243
|
+
s_instance->m_logMutex->Lock();
|
244
|
+
s_instance->m_pImpl->QueueDump();
|
245
|
+
s_instance->m_logMutex->Unlock();
|
246
|
+
}
|
247
|
+
}
|
248
|
+
|
249
|
+
//-----------------------------------------------------------------------------
|
250
|
+
// <Log::QueueClear>
|
251
|
+
// Empty the queued message queue
|
252
|
+
//-----------------------------------------------------------------------------
|
253
|
+
void Log::QueueClear
|
254
|
+
(
|
255
|
+
)
|
256
|
+
{
|
257
|
+
if( s_instance && s_dologging && s_instance->m_pImpl )
|
258
|
+
{
|
259
|
+
s_instance->m_logMutex->Lock();
|
260
|
+
s_instance->m_pImpl->QueueClear();
|
261
|
+
s_instance->m_logMutex->Unlock();
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
//-----------------------------------------------------------------------------
|
266
|
+
// <Log::SetLogFileName>
|
267
|
+
// Change the name of the log file (will start writing a new file)
|
268
|
+
//-----------------------------------------------------------------------------
|
269
|
+
void Log::SetLogFileName
|
270
|
+
(
|
271
|
+
string _filename
|
272
|
+
)
|
273
|
+
{
|
274
|
+
if( s_instance && s_dologging && s_instance->m_pImpl )
|
275
|
+
{
|
276
|
+
s_instance->m_logMutex->Lock();
|
277
|
+
s_instance->m_pImpl->SetLogFileName( _filename );
|
278
|
+
s_instance->m_logMutex->Unlock();
|
279
|
+
}
|
280
|
+
}
|
281
|
+
|
282
|
+
//-----------------------------------------------------------------------------
|
283
|
+
// <Log::Log>
|
284
|
+
// Constructor
|
285
|
+
//-----------------------------------------------------------------------------
|
286
|
+
Log::Log
|
287
|
+
(
|
288
|
+
string const& _filename,
|
289
|
+
bool const _bAppend,
|
290
|
+
bool const _bConsoleOutput,
|
291
|
+
LogLevel const _saveLevel,
|
292
|
+
LogLevel const _queueLevel,
|
293
|
+
LogLevel const _dumpTrigger
|
294
|
+
):
|
295
|
+
m_logMutex( new Mutex() )
|
296
|
+
{
|
297
|
+
m_pImpl = new LogImpl( _filename, _bAppend, _bConsoleOutput, _saveLevel, _queueLevel, _dumpTrigger );
|
298
|
+
}
|
299
|
+
|
300
|
+
//-----------------------------------------------------------------------------
|
301
|
+
// <Log::~Log>
|
302
|
+
// Destructor
|
303
|
+
//-----------------------------------------------------------------------------
|
304
|
+
Log::~Log
|
305
|
+
(
|
306
|
+
)
|
307
|
+
{
|
308
|
+
m_logMutex->Release();
|
309
|
+
delete m_pImpl;
|
310
|
+
}
|