updates-model.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
7 #include "ux-window.h"
8 #include "notifications.h"
9 #include "fw-update-helper.h"
10 
11 #include <string>
12 #include <vector>
13 #include <regex>
14 #include <mutex>
15 #include <atomic>
16 
17 namespace rs2
18 {
20  {
21  public:
23  {
28  context contex, device_model* device_model) : profile(p), ctx(contex), dev_model(device_model) {};
29  };
31  {
32  std::lock_guard<std::mutex> lock(_lock);
33  auto it = std::find_if(_updates.begin(), _updates.end(), [&](update_profile_model& p) {
34  return (p.profile.device_name == update.profile.device_name && p.profile.serial_number == update.profile.serial_number);
35  });
36  if (it == _updates.end())
37  _updates.push_back(update);
38  else
39  {
40  *it = update;
41  }
42  }
43 
45  {
46  std::lock_guard<std::mutex> lock(_lock);
47  auto it = std::find_if(_updates.begin(), _updates.end(), [&](update_profile_model& p) {
48  return (p.profile.device_name == update.profile.device_name && p.profile.serial_number == update.profile.serial_number);
49  });
50  if (it != _updates.end())
51  {
52  *it = update;
53  }
54  }
56  {
57  std::lock_guard<std::mutex> lock(_lock);
58  auto it = std::find_if(_updates.begin(), _updates.end(), [&](update_profile_model& p) {
59  return (p.profile.device_name == update.device_name && p.profile.serial_number == update.serial_number);
60  });
61  if (it != _updates.end())
62  _updates.erase(it);
63  }
64 
65  // This is a helper function to indicate if a device is connected or not.
66  // It change its value on device connect/disconnect
67  // cause calling ctx.query_devices() is too slow for the UI
69  {
70  std::lock_guard<std::mutex> lock(_lock);
71  auto it = std::find_if(_updates.begin(), _updates.end(), [&](update_profile_model& p) {
72  return (p.profile.device_name == update.device_name && p.profile.serial_number == update.serial_number);
73  });
74  if (it != _updates.end())
75  it->profile.dev_active = active;
76  }
77 
78  bool has_updates() const
79  {
80  std::lock_guard<std::mutex> lock(_lock);
81  return !_updates.empty();
82  }
83 
84  void draw(std::shared_ptr<notifications_model> not_model, ux_window& window, std::string& error_message);
85  private:
87  {
88  float w;
89  float h;
91  float mid_y;
92  float x0;
93  float y0;
94  position_params() :w(0.0f), h(0.0f), orig_pos(), x0(0.0f), y0(0.0f) {}
95  };
96 
97  bool draw_software_section(const char * window_name, update_profile_model& selected_profile, position_params& pos_params , ux_window& window, std::string& error_message);
98  bool draw_firmware_section(std::shared_ptr<notifications_model> not_model, const char * window_name, update_profile_model& selected_profile, position_params& pos_params, ux_window& window, std::string& error_message);
99 
100 
101  int selected_index = 0;
104  bool ignore = false;
105  std::vector<update_profile_model> _updates;
106  std::shared_ptr<texture_buffer> _icon = nullptr;
107  mutable std::mutex _lock;
109 
110  std::shared_ptr<firmware_update_manager> _fw_update = nullptr;
111 
112  enum class fw_update_states
113  {
114  ready = 0,
115  downloading = 1,
116  started = 2,
117  completed = 3,
118  failed_downloading = 4,
119  failed_updating = 5
120  };
121 
123  {
124  none = 0,
125  downloading_error = 1,
126  updating_error = 2
127  };
128 
130 
132  std::atomic<int> _fw_download_progress{ 0 };
133  bool _retry = false;
134  std::shared_ptr<firmware_update_manager> _update_manager = nullptr;
135  std::vector<uint8_t> _fw_image;
136  };
137 }
static const textual_icon lock
Definition: model-views.h:218
void remove_profile(const sw_update::dev_updates_profile::update_profile &update)
Definition: updates-model.h:55
std::shared_ptr< firmware_update_manager > _update_manager
GLfloat GLfloat p
Definition: glext.h:12687
Definition: imgui.h:88
void draw(std::shared_ptr< notifications_model > not_model, ux_window &window, std::string &error_message)
void add_profile(const update_profile_model &update)
Definition: updates-model.h:30
Definition: cah-model.h:10
GLsizei const GLchar *const * string
std::atomic< int > _fw_download_progress
std::shared_ptr< firmware_update_manager > _fw_update
progress_bar _progress
std::vector< update_profile_model > _updates
int selected_firmware_update_index
void update(rs2::update_device fwu_dev, std::vector< uint8_t > fw_image)
GLdouble f
void set_device_status(const sw_update::dev_updates_profile::update_profile &update, bool active)
Definition: updates-model.h:68
std::vector< uint8_t > _fw_image
int selected_software_update_index
update_profile_model(sw_update::dev_updates_profile::update_profile p, context contex, device_model *device_model)
Definition: updates-model.h:27
std::shared_ptr< texture_buffer > _icon
bool draw_software_section(const char *window_name, update_profile_model &selected_profile, position_params &pos_params, ux_window &window, std::string &error_message)
bool has_updates() const
Definition: updates-model.h:78
static auto it
fw_update_states _fw_update_state
sw_update::dev_updates_profile::update_profile profile
Definition: updates-model.h:24
bool draw_firmware_section(std::shared_ptr< notifications_model > not_model, const char *window_name, update_profile_model &selected_profile, position_params &pos_params, ux_window &window, std::string &error_message)
void update_profile(const update_profile_model &update)
Definition: updates-model.h:44


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