notifications.h
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 
4 #pragma once
5 
6 #include <string>
7 #include <functional>
8 #include <vector>
9 #include <chrono>
10 
11 #include "ux-window.h"
12 
13 #include "output-model.h"
14 
15 namespace rs2
16 {
18  {
19  public:
20  notification_data(std::string description,
22  rs2_notification_category category);
23 
26  double get_timestamp() const;
28  private:
30  double _timestamp;
33  };
34 
35  struct notification_model : public std::enable_shared_from_this<notification_model>
36  {
39 
40  template <class dst_type>
41  bool is()
42  {
43  return dynamic_cast<const dst_type*>(this) != nullptr;
44  }
45 
46  double get_age_in_ms(bool total = false) const;
47  bool interacted() const;
48  std::function<void()> draw(ux_window& win, int w, int y,
49  std::shared_ptr<notification_model>& selected, std::string& error_message);
50  void draw_text(const char* msg, int x, int y, int h);
51  virtual void set_color_scheme(float t) const;
52  void unset_color_scheme() const;
53  virtual int get_max_lifetime_ms() const;
54 
55  virtual int calc_height();
56  virtual void draw_pre_effect(int x, int y) {}
57  virtual void draw_content(ux_window& win, int x, int y, float t, std::string& error_message);
58  virtual void draw_dismiss(ux_window& win, int x, int y);
59  virtual void draw_expanded(ux_window& win, std::string& error_message) {}
60 
61  virtual void dismiss(bool snooze) { dismissed = true; snoozed = snooze; }
62 
63  std::string get_title();
64 
65  std::function<void()> custom_action;
66 
67  int count = 1;
68  int height = 40;
69  int index = 0;
71  double timestamp = 0.0;
73  std::chrono::system_clock::time_point created_time;
75  bool to_close = false; // true when user clicks on close notification
76 
77  int width = 320;
78  int stack_offset = 4;
79  int max_stack = 3;
80 
81  // Behaviour variables
82  bool dismissed = false;
83  bool expanded = false;
84  bool visible = true;
85  bool pinned = false;
86  bool forced = false;
87  bool snoozed = false;
88  bool enable_dismiss = true;
89  bool enable_expand = true;
90  bool enable_click = false;
91  bool enable_complex_dismiss = false;
92 
93  std::string delay_id = "";
94 
95  bool is_delayed() const;
96  void delay(int days);
97 
98  float last_x, last_y;
99  bool animating = false;
100  std::chrono::system_clock::time_point last_moved;
101  std::chrono::system_clock::time_point last_interacted;
102 
104  void invoke(std::function<void()> action);
105  };
106 
107  class device_model;
108 
109  using invoker = std::function<void(std::function<void()>)>;
110 
111  class process_manager : public std::enable_shared_from_this<process_manager>
112  {
113  public:
115  : _process_name(name) {}
116 
117  virtual ~process_manager() = default;
118 
119  void start(invoker invoke);
120  int get_progress() const { return _progress; }
121  bool done() const { return _done; }
122  bool started() const { return _started; }
123  bool failed() const { return _failed; }
124  const std::string& get_log() const { return _log; }
125  void reset();
126 
127  void check_error(std::string& error) { if (_failed) error = _last_error; }
128 
129  void log(std::string line);
130  void fail(std::string error);
131 
132  protected:
133  virtual void process_flow(
134  std::function<void()> cleanup,
135  invoker invoke) = 0;
136 
138  bool _started = false;
139  bool _done = false;
140  bool _failed = false;
141  int _progress = 0;
142 
143  std::mutex _log_lock;
146  };
147 
149  {
150  void draw(ux_window& win, int w, int progress);
151 
152  float progress_speed = 5.f;
153  std::chrono::system_clock::time_point last_progress_time;
154  int last_progress = 0;
155  float curr_progress_value = 0.f;
156  float threshold_progress = 5.f;
157  };
158 
160  {
161  process_notification_model(std::shared_ptr<process_manager> manager)
162  : update_manager(manager) {}
163 
164  void draw_progress_bar(ux_window& win, int w);
165 
166  void draw_pre_effect(int x, int y) override;
167 
168  std::shared_ptr<process_manager> update_manager = nullptr;
169  int update_state = 0;
170  int update_state_prev = 0;
172  };
173 
175  {
176  version_upgrade_model(int version);
177 
178  void set_color_scheme(float t) const override;
179  void draw_content(ux_window& win, int x, int y, float t, std::string& error_message) override;
180  int calc_height() override;
181  int get_max_lifetime_ms() const override { return 40000; }
182 
183  int _version;
184  bool _first = true;
185  };
186 
188  {
190 
191  void set_color_scheme(float t) const override;
192  void draw_content(ux_window& win, int x, int y, float t, std::string& error_message) override;
193  int calc_height() override { return 130; }
194  int get_max_lifetime_ms() const override { return 40000; }
195  };
196 
197 
199  {
200  std::shared_ptr<notification_model> add_notification(const notification_data& n);
201  std::shared_ptr<notification_model> add_notification(const notification_data& n,
202  std::function<void()> custom_action,
203  bool use_custom_action = true);
204  void add_notification(std::shared_ptr<notification_model> model);
205  bool draw(ux_window& win, int w, int h, std::string& error_message);
206 
208 
209  void add_log(std::string message)
210  {
211  output.add_log(RS2_LOG_SEVERITY_INFO, "", 0, message);
212  }
213 
215 
216  private:
217  std::vector<std::shared_ptr<notification_model>> pending_notifications;
218  int index = 1;
219  const int MAX_SIZE = 6;
220  std::recursive_mutex m;
221 
222  std::shared_ptr<notification_model> selected;
223  };
224 
226  {
227  sw_recommended_update_alert_model(const std::string & current_version, const std::string & recommended_version, const std::string &recommended_version_link);
228 
229  void set_color_scheme( float t ) const override;
230  void draw_content(
231  ux_window & win, int x, int y, float t, std::string & error_message ) override;
232  int calc_height() override { return 150; }
233  int get_max_lifetime_ms() const override { return 10000; }
237  };
238 
239  inline ImVec4 saturate(const ImVec4& a, float f)
240  {
241  return{ f * a.x, f * a.y, f * a.z, a.w };
242  }
243 
244  inline ImVec4 alpha(const ImVec4& v, float a)
245  {
246  return{ v.x, v.y, v.z, a };
247  }
248 
250  {
251  public:
252  export_manager(const std::string& fname, std::unique_ptr<rs2::filter> exporter, frame data)
253  : process_manager("Export"), _fname(fname), _exporter(std::move(exporter)), _data(data) {}
254 
255  std::string get_filename() const { return _fname; }
256  frame get_data() const { return _data; }
257 
258 
259  private:
260  void process_flow(std::function<void()> cleanup,
261  invoker invoke) override;
262 
264  std::unique_ptr<rs2::filter> _exporter;
266  };
267 
269  {
270  enum states
271  {
272  STATE_INITIAL_PROMPT = 0,
273  STATE_IN_PROGRESS = 1,
274  STATE_COMPLETE = 2,
275  STATE_FAILED = 3,
276  };
277 
279  return *std::dynamic_pointer_cast<export_manager>(update_manager);
280  }
281 
282  export_notification_model(std::shared_ptr<export_manager> manager);
283 
284  void set_color_scheme(float t) const override;
285  void draw_content(ux_window& win, int x, int y, float t, std::string& error_message) override;
286  int calc_height() override;
287  };
288 }
void draw_text(int x, int y, const char *text)
Definition: rendering.h:717
std::string _description
Definition: notifications.h:29
GLint y
GLenum GLuint GLenum severity
GLuint const GLchar * name
ImVec4 saturate(const ImVec4 &a, float f)
std::chrono::system_clock::time_point created_time
Definition: notifications.h:73
void add_log(std::string message)
GLboolean reset
string _progress
Definition: log.py:34
void log(rs2_log_severity severity, const char *message)
Definition: rs.hpp:149
std::shared_ptr< notification_model > selected
def progress(args)
Definition: log.py:43
def fail()
Definition: test.py:340
export_manager & get_manager()
Definition: cah-model.h:10
GLdouble GLdouble GLdouble w
GLsizei const GLchar *const * string
std::unique_ptr< rs2::filter > _exporter
bool failed() const
const std::string & get_log() const
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1960
GLdouble n
Definition: glext.h:1966
double get_timestamp() const
virtual void draw_pre_effect(int x, int y)
Definition: notifications.h:56
std::chrono::system_clock::time_point last_moved
GLuint index
GLdouble t
GLboolean GLboolean GLboolean GLboolean a
rs2_notification_category get_category() const
std::function< void(std::function< void()>)> invoker
GLdouble f
float w
Definition: imgui.h:100
std::string _last_error
std::function< void()> custom_action
Definition: notifications.h:65
virtual void draw_expanded(ux_window &win, std::string &error_message)
Definition: notifications.h:59
GLdouble x
rs2_log_severity _severity
Definition: notifications.h:31
std::string get_description() const
virtual void dismiss(bool snooze)
Definition: notifications.h:61
GLint GLsizei GLsizei height
std::string get_filename() const
float z
Definition: imgui.h:100
std::chrono::system_clock::time_point last_progress_time
static void draw(void)
Definition: gears.c:173
GLuint start
void check_error(std::string &error)
Definition: imgui.h:98
rs2_notification_category category
Definition: notifications.h:74
action
Definition: enums.py:62
ImVec4 alpha(const ImVec4 &v, float a)
float x
Definition: imgui.h:100
export_manager(const std::string &fname, std::unique_ptr< rs2::filter > exporter, frame data)
rs2_log_severity get_severity() const
std::chrono::system_clock::time_point last_interacted
frame get_data() const
fname
Definition: rmse.py:13
bool started() const
rs2_notification_category
Category of the librealsense notification.
Definition: rs_types.h:17
std::string _process_name
#define _log
Definition: test-scenes.cpp:24
GLint GLsizei count
process_manager(std::string name)
single_consumer_queue< std::function< void()> > dispatch_queue
int get_max_lifetime_ms() const override
std::vector< std::shared_ptr< notification_model > > pending_notifications
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
bool done() const
notification_data(std::string description, rs2_log_severity severity, rs2_notification_category category)
std::recursive_mutex m
process_notification_model(std::shared_ptr< process_manager > manager)
rs2_log_severity
Severity of the librealsense logger.
Definition: rs_types.h:153
GLdouble v
int get_max_lifetime_ms() const override
Definition: parser.hpp:150
int get_progress() const
GLint GLsizei width
float y
Definition: imgui.h:100
rs2_notification_category _category
Definition: notifications.h:32


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