error-handling.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 #include "error-handling.h"
4 
5 #include <memory>
6 
7 
8 namespace librealsense
9 {
10  polling_error_handler::polling_error_handler(unsigned int poll_intervals_ms, std::shared_ptr<option> option,
11  std::shared_ptr <notifications_processor> processor, std::shared_ptr<notification_decoder> decoder)
12  :_poll_intervals_ms(poll_intervals_ms),
13  _option(option),
14  _notifications_processor(processor),
15  _decoder(decoder)
16  {
17  _active_object = std::make_shared<active_object<>>([this](dispatcher::cancellable_timer cancellable_timer)
18  { polling(cancellable_timer); });
19  }
20 
22  {
23  stop();
24  }
25 
27  {
30  _option = h._option;
32  _decoder = h._decoder;
33  }
34 
35  void polling_error_handler::start( unsigned int poll_intervals_ms )
36  {
37  if( poll_intervals_ms )
38  _poll_intervals_ms = poll_intervals_ms;
39  _active_object->start();
40  }
42  {
43  _active_object->stop();
44  }
45 
47  {
48  if (cancellable_timer.try_sleep(_poll_intervals_ms))
49  {
50  try
51  {
52 
53  auto val = static_cast<uint8_t>(_option->query());
54 
55  if (val != 0 && !_silenced)
56  {
57  auto strong = _notifications_processor.lock();
58  if (strong) strong->raise_notification(_decoder->decode(val));
59 
60  val = static_cast<uint8_t>(_option->query());
61  if (val != 0)
62  {
63  // Reading from last-error control is supposed to set it to zero in the firmware
64  // If this is not happening there is some issue
65  notification postcondition_failed{
67  0,
69  "Error polling loop is not behaving as expected!\nThis can indicate an issue with camera firmware or the underlying OS..."
70  };
71  if (strong) strong->raise_notification(postcondition_failed);
72  _silenced = true;
73  }
74  }
75  }
76  catch (const std::exception& ex)
77  {
78  LOG_ERROR("Error during polling error handler: " << ex.what());
79  }
80  catch (...)
81  {
82  LOG_ERROR("Unknown error during polling error handler!");
83  }
84  }
85  else
86  {
87  LOG_DEBUG("Notification polling loop is being shut-down");
88  }
89  }
90 }
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1960
unsigned char uint8_t
Definition: stdint.h:78
GLuint GLfloat * val
std::shared_ptr< notification_decoder > _decoder
std::weak_ptr< notifications_processor > _notifications_processor
polling_error_handler(unsigned int poll_intervals_ms, std::shared_ptr< option > option, std::shared_ptr< notifications_processor > processor, std::shared_ptr< notification_decoder > decoder)
void polling(dispatcher::cancellable_timer cancellable_timer)
#define LOG_ERROR(...)
Definition: src/types.h:242
void start(unsigned int poll_intervals_ms=0)
std::shared_ptr< option > _option
std::shared_ptr< active_object<> > _active_object
#define LOG_DEBUG(...)
Definition: src/types.h:239
bool try_sleep(std::chrono::milliseconds::rep ms)
Definition: concurrency.h:204


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:14