Skip to content

Commit 81e1151

Browse files
christiankerlxlz
authored andcommitted
Use LOG_* macros in all classes except packet processors
1 parent a50e58d commit 81e1151

14 files changed

+93
-58
lines changed

examples/protonect/include/libfreenect2/depth_packet_stream_parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <stdint.h>
3232

3333
#include <libfreenect2/config.h>
34+
#include <libfreenect2/logging.h>
3435

3536
#include <libfreenect2/double_buffer.h>
3637
#include <libfreenect2/depth_packet_processor.h>
@@ -51,7 +52,7 @@ LIBFREENECT2_PACK(struct LIBFREENECT2_API DepthSubPacketFooter
5152
uint32_t fields[32];
5253
});
5354

54-
class LIBFREENECT2_API DepthPacketStreamParser : public DataCallback
55+
class LIBFREENECT2_API DepthPacketStreamParser : public DataCallback, public WithLoggerImpl
5556
{
5657
public:
5758
DepthPacketStreamParser();

examples/protonect/include/libfreenect2/logging.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ class LIBFREENECT2_API WithLogger
8181
virtual Logger *logger() = 0;
8282
};
8383

84+
template<class T>
85+
void trySetLogger(T *obj, Logger *logger)
86+
{
87+
WithLogger *obj_with_logger = dynamic_cast<WithLogger *>(obj);
88+
if(obj_with_logger != 0)
89+
{
90+
obj_with_logger->setLogger(logger);
91+
}
92+
}
93+
8494
class LIBFREENECT2_API WithLoggerImpl : public WithLogger
8595
{
8696
protected:

examples/protonect/include/libfreenect2/packet_pipeline.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define PACKET_PIPELINE_H_
2929

3030
#include <libfreenect2/config.h>
31+
#include <libfreenect2/logging.h>
3132
#include <libfreenect2/data_callback.h>
3233
#include <libfreenect2/rgb_packet_stream_parser.h>
3334
#include <libfreenect2/depth_packet_stream_parser.h>
@@ -50,7 +51,7 @@ class LIBFREENECT2_API PacketPipeline
5051
virtual DepthPacketProcessor *getDepthPacketProcessor() const = 0;
5152
};
5253

53-
class LIBFREENECT2_API BasePacketPipeline : public PacketPipeline
54+
class LIBFREENECT2_API BasePacketPipeline : public PacketPipeline, public WithLoggerImpl
5455
{
5556
protected:
5657
RgbPacketStreamParser *rgb_parser_;
@@ -63,6 +64,8 @@ class LIBFREENECT2_API BasePacketPipeline : public PacketPipeline
6364

6465
virtual void initialize();
6566
virtual DepthPacketProcessor *createDepthPacketProcessor() = 0;
67+
68+
virtual void onLoggerChanged(Logger *logger);
6669
public:
6770
virtual ~BasePacketPipeline();
6871

examples/protonect/include/libfreenect2/protocol/command_transaction.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
#define COMMAND_TRANSACTION_H_
2929

3030
#include <libusb.h>
31+
#include <libfreenect2/logging.h>
3132
#include <libfreenect2/protocol/command.h>
3233

3334
namespace libfreenect2
3435
{
3536
namespace protocol
3637
{
3738

38-
class CommandTransaction
39+
class CommandTransaction : public WithLoggerImpl
3940
{
4041
public:
4142
static const int ResponseCompleteLength = 16;
@@ -63,7 +64,7 @@ class CommandTransaction
6364
};
6465

6566
CommandTransaction(libusb_device_handle *handle, int inbound_endpoint, int outbound_endpoint);
66-
~CommandTransaction();
67+
virtual ~CommandTransaction();
6768

6869
void execute(const CommandBase& command, Result& result);
6970
private:

examples/protonect/include/libfreenect2/protocol/usb_control.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define USB_CONTROL_H_
2929

3030
#include <libusb.h>
31+
#include <libfreenect2/logging.h>
3132

3233
namespace libfreenect2
3334
{
@@ -61,7 +62,7 @@ namespace protocol
6162
*
6263
* The 2. interface can be enabled/disabled by changing its alternate setting to 1/0
6364
*/
64-
class UsbControl
65+
class UsbControl : public WithLoggerImpl
6566
{
6667
public:
6768
UsbControl(libusb_device_handle *handle);

examples/protonect/include/libfreenect2/rgb_packet_stream_parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <stddef.h>
3131

3232
#include <libfreenect2/config.h>
33+
#include <libfreenect2/logging.h>
3334
#include <libfreenect2/double_buffer.h>
3435
#include <libfreenect2/rgb_packet_processor.h>
3536

@@ -38,7 +39,7 @@
3839
namespace libfreenect2
3940
{
4041

41-
class LIBFREENECT2_API RgbPacketStreamParser : public DataCallback
42+
class LIBFREENECT2_API RgbPacketStreamParser : public DataCallback, public WithLoggerImpl
4243
{
4344
public:
4445
RgbPacketStreamParser();

examples/protonect/include/libfreenect2/usb/transfer_pool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <vector>
3131
#include <libusb.h>
3232

33+
#include <libfreenect2/logging.h>
3334
#include <libfreenect2/data_callback.h>
3435
#include <libfreenect2/threading.h>
3536

@@ -39,7 +40,7 @@ namespace libfreenect2
3940
namespace usb
4041
{
4142

42-
class TransferPool
43+
class TransferPool : public WithLoggerImpl
4344
{
4445
public:
4546
TransferPool(libusb_device_handle *device_handle, unsigned char device_endpoint);

examples/protonect/src/command_transaction.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <libfreenect2/protocol/command_transaction.h>
2828

2929
#include <stdint.h>
30-
#include <iostream>
3130

3231
namespace libfreenect2
3332
{
@@ -106,7 +105,7 @@ void CommandTransaction::execute(const CommandBase& command, Result& result)
106105

107106
if(complete)
108107
{
109-
std::cerr << "[CommandTransaction::execute] received premature response complete!" << std::endl;
108+
LOG_ERROR << "received premature response complete!";
110109
result.code = Error;
111110
}
112111

@@ -119,7 +118,7 @@ void CommandTransaction::execute(const CommandBase& command, Result& result)
119118

120119
if(!complete)
121120
{
122-
std::cerr << "[CommandTransaction::execute] missing response complete!" << std::endl;
121+
LOG_ERROR << "missing response complete!";
123122
result.code = Error;
124123
}
125124

@@ -135,13 +134,13 @@ CommandTransaction::ResultCode CommandTransaction::send(const CommandBase& comma
135134

136135
if(r != LIBUSB_SUCCESS)
137136
{
138-
std::cerr << "[CommandTransaction::send] bulk transfer failed! libusb error " << r << ": " << libusb_error_name(r) << std::endl;
137+
LOG_ERROR << "bulk transfer failed! libusb error " << r << ": " << libusb_error_name(r);
139138
code = Error;
140139
}
141140

142141
if(transferred_bytes != command.size())
143142
{
144-
std::cerr << "[CommandTransaction::send] sent number of bytes differs from expected number! expected: " << command.size() << " got: " << transferred_bytes << std::endl;
143+
LOG_ERROR << "sent number of bytes differs from expected number! expected: " << command.size() << " got: " << transferred_bytes;
145144
code = Error;
146145
}
147146

@@ -157,7 +156,7 @@ void CommandTransaction::receive(CommandTransaction::Result& result)
157156

158157
if(r != LIBUSB_SUCCESS)
159158
{
160-
std::cerr << "[CommandTransaction::receive] bulk transfer failed! libusb error " << r << ": " << libusb_error_name(r) << std::endl;
159+
LOG_ERROR << "bulk transfer failed! libusb error " << r << ": " << libusb_error_name(r);
161160
result.code = Error;
162161
}
163162
}
@@ -176,7 +175,7 @@ bool CommandTransaction::isResponseCompleteResult(CommandTransaction::Result& re
176175

177176
if(data[1] != sequence)
178177
{
179-
std::cerr << "[CommandTransaction::isResponseCompleteResult] response complete with wrong sequence number! expected: " << sequence << " got: " << data[1]<< std::endl;
178+
LOG_ERROR << "response complete with wrong sequence number! expected: " << sequence << " got: " << data[1];
180179
}
181180
}
182181
}

examples/protonect/src/depth_packet_stream_parser.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626

2727
#include <libfreenect2/depth_packet_stream_parser.h>
28-
#include <iostream>
2928
#include <memory.h>
3029

3130
namespace libfreenect2
@@ -79,7 +78,7 @@ void DepthPacketStreamParser::onDataReceived(unsigned char* buffer, size_t in_le
7978

8079
if(wb.length + in_length > wb.capacity)
8180
{
82-
std::cerr << "[DepthPacketStreamParser::onDataReceived] subpacket too large" << std::endl;
81+
LOG_ERROR << "subpacket too large";
8382
wb.length = 0;
8483
return;
8584
}
@@ -91,7 +90,7 @@ void DepthPacketStreamParser::onDataReceived(unsigned char* buffer, size_t in_le
9190
{
9291
if(footer->length != wb.length)
9392
{
94-
std::cerr << "[DepthPacketStreamParser::onDataReceived] image data too short!" << std::endl;
93+
LOG_ERROR << "image data too short!";
9594
}
9695
else
9796
{
@@ -113,12 +112,12 @@ void DepthPacketStreamParser::onDataReceived(unsigned char* buffer, size_t in_le
113112
}
114113
else
115114
{
116-
std::cerr << "[DepthPacketStreamParser::onDataReceived] skipping depth packet" << std::endl;
115+
LOG_WARNING << "skipping depth packet";
117116
}
118117
}
119118
else
120119
{
121-
std::cerr << "[DepthPacketStreamParser::onDataReceived] not all subsequences received " << current_subsequence_ << std::endl;
120+
LOG_ERROR << "not all subsequences received " << current_subsequence_;
122121
}
123122

124123
current_sequence_ = footer->sequence;
@@ -132,7 +131,7 @@ void DepthPacketStreamParser::onDataReceived(unsigned char* buffer, size_t in_le
132131

133132
if(footer->subsequence * footer->length > fb.length)
134133
{
135-
std::cerr << "[DepthPacketStreamParser::onDataReceived] front buffer too short! subsequence number is " << footer->subsequence << std::endl;
134+
LOG_ERROR << "front buffer too short! subsequence number is " << footer->subsequence;
136135
}
137136
else
138137
{

examples/protonect/src/libfreenect2.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class Freenect2DeviceImpl : public Freenect2Device, public WithLoggerImpl
7474
std::string serial_, firmware_;
7575
Freenect2Device::IrCameraParams ir_camera_params_;
7676
Freenect2Device::ColorCameraParams rgb_camera_params_;
77+
protected:
78+
virtual void onLoggerChanged(Logger *logger);
7779
public:
7880
Freenect2DeviceImpl(Freenect2Impl *context, const PacketPipeline *pipeline, libusb_device *usb_device, libusb_device_handle *usb_device_handle, const std::string &serial);
7981
virtual ~Freenect2DeviceImpl();
@@ -364,6 +366,17 @@ Freenect2DeviceImpl::~Freenect2DeviceImpl()
364366
delete pipeline_;
365367
}
366368

369+
void Freenect2DeviceImpl::onLoggerChanged(Logger *logger)
370+
{
371+
rgb_transfer_pool_.setLogger(logger);
372+
ir_transfer_pool_.setLogger(logger);
373+
usb_control_.setLogger(logger);
374+
command_tx_.setLogger(logger);
375+
376+
// TODO: is this ok?
377+
trySetLogger(const_cast<PacketPipeline *>(pipeline_), logger);
378+
}
379+
367380
int Freenect2DeviceImpl::nextCommandSeq()
368381
{
369382
return command_seq_++;

0 commit comments

Comments
 (0)