dev-updates-profile.cpp
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 #include <librealsense2/rs.hpp>
5 #include "dev-updates-profile.h"
6 
7 namespace rs2
8 {
9  namespace sw_update
10  {
11  using namespace http;
12 
13  dev_updates_profile::dev_updates_profile(const device& dev, const std::string& url, const bool use_url_as_local_path, user_callback_func_type download_callback)
14  : _versions_db(url, use_url_as_local_path, download_callback), _keep_trying(true)
15  {
16 
17  std::string dev_name = (dev.supports(RS2_CAMERA_INFO_NAME)) ? dev.get_info(RS2_CAMERA_INFO_NAME) : "Unknown";
20 
23 
25 
26  _update_profile.device_name = dev_name;
28  }
29 
31  {
32  // throw on unsupported components (Not implemented yet)
33  if (comp != LIBREALSENSE && comp != FIRMWARE)
34  {
35  std::string error_str("update component: " + sw_update::to_string(comp) + " not supported");
36  throw std::runtime_error(error_str);
37  }
38 
39  bool update_available(false);
40 
41  // We expect to get here in recovery mode (on firmware update flow) and therefore do not want to throw...
42  if (_update_profile.device_name.find("Recovery") == std::string::npos)
43  {
44  auto &versions_vec((comp == FIRMWARE) ?
46 
48  {
49  version_info experimental_update;
50  if (try_parse_update(_versions_db, _update_profile.device_name, EXPERIMENTAL, comp, experimental_update))
51  {
52  if (current_version < experimental_update.ver)
53  {
54  versions_vec[experimental_update.ver] = experimental_update;
55  update_available = true;
56  }
57  }
58 
59  version_info recommened_update;
61  {
62  if (current_version < recommened_update.ver)
63  {
64  versions_vec[recommened_update.ver] = recommened_update;
65  update_available = true;
66  }
67  }
68 
69  version_info required_update;
71  {
72  if (current_version < required_update.ver)
73  {
74  versions_vec[required_update.ver] = required_update;
75  update_available = true;
76  }
77  }
78  }
79  }
80 
81  return update_available;
82  }
83 
85  const std::string& dev_name,
86  update_policy_type policy,
89  {
90  if (_keep_trying)
91  {
92  sw_update::version required_version;
93  auto query_status = up_handler.query_versions(dev_name, part, policy, required_version);
94  if (query_status == VERSION_FOUND)
95  {
96  up_handler.get_version_download_link(part, required_version, result.download_link);
97  up_handler.get_version_release_notes(part, required_version, result.release_page);
98  up_handler.get_version_description(part, required_version, result.description);
99  result.ver = required_version;
100 
101  std::stringstream ss;
102  ss << std::string(result.ver) << " (" << sw_update::to_string(policy) << ")";
103  result.name_for_display = ss.str();
104  result.policy = policy;
105  return true;
106  }
107  else if (query_status == DB_LOAD_FAILURE)
108  {
109  _keep_trying = false;
110  }
111 
112  }
113  return false;
114  }
115 
117  version_info & info ) const
118  {
119  auto found = std::find_if( software_versions.begin(),
120  software_versions.end(),
121  [policy]( const version_to_info::value_type & ver_info ) {
122  return ver_info.second.policy == policy;
123  } );
124  if( found != software_versions.end() )
125  {
126  info = found->second;
127  return true;
128  }
129  return false;
130  }
131 
133  version_info & info ) const
134  {
135  auto found = std::find_if( firmware_versions.begin(),
136  firmware_versions.end(),
137  [policy]( const version_to_info::value_type & ver_info ) {
138  return ver_info.second.policy == policy;
139  } );
140  if( found != firmware_versions.end() )
141  {
142  info = found->second;
143  return true;
144  }
145  return false;
146  }
147  }
148 }
Definition: cah-model.h:10
GLsizei const GLchar *const * string
bool get_version_description(const component_part_type component, const version &version, std::string &version_description)
def info(name, value, persistent=False)
Definition: test.py:301
const char * get_info(rs2_camera_info info) const
Definition: rs_device.hpp:79
std::string to_string(const component_part_type &component)
bool supports(rs2_camera_info info) const
Definition: rs_device.hpp:66
std::function< callback_result(uint64_t dl_current_bytes, uint64_t dl_total_bytes)> user_callback_func_type
bool get_version_download_link(const component_part_type component, const version &version, std::string &dl_link)
bool try_parse_update(versions_db_manager &up_handler, const std::string &dev_name, update_policy_type policy, component_part_type part, version_info &result)
dev_updates_profile(const device &dev, const std::string &url, const bool use_url_as_local_path=false, http::user_callback_func_type download_callback=http::user_callback_func_type())
#define RS2_API_FULL_VERSION_STR
Definition: rs.h:44
query_status_type query_versions(const std::string &device_name, component_part_type component, const update_policy_type policy, version &out_version)
bool get_version_release_notes(const component_part_type component, const version &version, std::string &version_release_notes_link)
bool get_fw_update(update_policy_type policy, version_info &info) const
bool get_sw_update(update_policy_type policy, version_info &info) const
bool retrieve_updates(component_part_type comp)
GLuint64EXT * result
Definition: glext.h:10921


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