forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror-handling.cpp
80 lines (72 loc) · 2.7 KB
/
error-handling.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2019 Intel Corporation. All Rights Reserved.
#include "error-handling.h"
#include <memory>
namespace librealsense
{
polling_error_handler::polling_error_handler(unsigned int poll_intervals_ms, std::unique_ptr<option> option,
std::shared_ptr <notifications_processor> processor, std::unique_ptr<notification_decoder> decoder)
:_poll_intervals_ms(poll_intervals_ms),
_active_object([this](dispatcher::cancellable_timer cancellable_timer)
{
polling(cancellable_timer);
}),
_option(std::move(option)),
_notifications_processor(processor),
_decoder(std::move(decoder))
{
}
polling_error_handler::~polling_error_handler()
{
stop();
}
void polling_error_handler::start()
{
_active_object.start();
}
void polling_error_handler::stop()
{
_active_object.stop();
}
void polling_error_handler::polling(dispatcher::cancellable_timer cancellable_timer)
{
if (cancellable_timer.try_sleep(_poll_intervals_ms))
{
try
{
auto val = static_cast<uint8_t>(_option->query());
if (val != 0 && !_silenced)
{
auto strong = _notifications_processor.lock();
if (strong) strong->raise_notification(_decoder->decode(val));
val = static_cast<int>(_option->query());
if (val != 0)
{
// Reading from last-error control is supposed to set it to zero in the firmware
// If this is not happening there is some issue
notification postcondition_failed{
RS2_NOTIFICATION_CATEGORY_HARDWARE_ERROR,
0,
RS2_LOG_SEVERITY_WARN,
"Error polling loop is not behaving as expected!\nThis can indicate an issue with camera firmware or the underlying OS..."
};
if (strong) strong->raise_notification(postcondition_failed);
_silenced = true;
}
}
}
catch (const std::exception& ex)
{
LOG_ERROR("Error during polling error handler: " << ex.what());
}
catch (...)
{
LOG_ERROR("Unknown error during polling error handler!");
}
}
else
{
LOG_DEBUG("Notification polling loop is being shut-down");
}
}
}