IDS peak genericC++  v1.7.1
peak_firmware_updater.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 
18 #include <peak/dll_interface/peak_dll_interface_util.hpp>
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 
25 namespace peak
26 {
27 namespace core
28 {
29 using namespace std::chrono_literals;
30 
45 class FirmwareUpdater final
46 {
47 public:
49  ~FirmwareUpdater();
50  FirmwareUpdater(const FirmwareUpdater& other) = delete;
51  FirmwareUpdater& operator=(const FirmwareUpdater& other) = delete;
52  FirmwareUpdater(FirmwareUpdater&& other) = delete;
53  FirmwareUpdater& operator=(FirmwareUpdater&& other) = delete;
54 
67  std::vector<std::shared_ptr<FirmwareUpdateInformation>> CollectFirmwareUpdateInformation(
68  const std::string& gufPath) const;
69 
84  std::vector<std::shared_ptr<FirmwareUpdateInformation>> CollectFirmwareUpdateInformation(
85  const std::string& gufPath, const std::shared_ptr<DeviceDescriptor>& device) const;
86 
109  void UpdateDevice(const std::shared_ptr<DeviceDescriptor>& device,
110  const std::shared_ptr<FirmwareUpdateInformation>& updateInformation,
111  const FirmwareUpdateProgressObserver* progressObserver = nullptr,
112  Timeout deviceResetDiscoveryTimeout = Timeout(60000ms));
113 
114 private:
115  PEAK_FIRMWARE_UPDATER_HANDLE m_backendHandle;
116 };
117 
118 } /* namespace core */
119 } /* namespace peak */
120 
121 /* Implementation */
122 namespace peak
123 {
124 namespace core
125 {
126 
128  : m_backendHandle(QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATER_HANDLE>(
129  [](PEAK_FIRMWARE_UPDATER_HANDLE* firmwareUpdaterHandle) {
130  return PEAK_C_ABI_PREFIX PEAK_FirmwareUpdater_Construct(firmwareUpdaterHandle);
131  }))
132 {}
133 
135 {
136  (void)PEAK_C_ABI_PREFIX PEAK_FirmwareUpdater_Destruct(m_backendHandle);
137 }
138 
139 inline std::vector<std::shared_ptr<FirmwareUpdateInformation>> FirmwareUpdater::CollectFirmwareUpdateInformation(
140  const std::string& gufPath) const
141 {
142  CallAndCheckCInterfaceFunction([&] {
144  m_backendHandle, gufPath.c_str(), gufPath.size() + 1);
145  });
146 
147  auto numFirmwareUpdateInformation = QueryNumericFromCInterfaceFunction<size_t>(
148  [&](size_t* _numFirmwareUpdateInformation) {
150  m_backendHandle, _numFirmwareUpdateInformation);
151  });
152 
153  std::vector<std::shared_ptr<FirmwareUpdateInformation>> firmwareUpdateInformation;
154  for (size_t x = 0; x < numFirmwareUpdateInformation; ++x)
155  {
156  auto firmwareUpdateInformationHandle =
157  QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE>(
158  [&](PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE* _firmwareUpdateInformationHandle) {
160  m_backendHandle, x, _firmwareUpdateInformationHandle);
161  });
162 
163  firmwareUpdateInformation.emplace_back(
164  std::make_shared<ClassCreator<FirmwareUpdateInformation>>(firmwareUpdateInformationHandle));
165  }
166 
167  return firmwareUpdateInformation;
168 }
169 
170 inline std::vector<std::shared_ptr<FirmwareUpdateInformation>> FirmwareUpdater::CollectFirmwareUpdateInformation(
171  const std::string& gufPath, const std::shared_ptr<DeviceDescriptor>& device) const
172 {
173  if (device == nullptr)
174  {
175  throw InvalidArgumentException("The given device is a nullptr!");
176  }
177 
178  CallAndCheckCInterfaceFunction([&] {
180  m_backendHandle, gufPath.c_str(), gufPath.size() + 1, device->m_backendHandle);
181  });
182 
183  auto numFirmwareUpdateInformation = QueryNumericFromCInterfaceFunction<size_t>(
184  [&](size_t* _numFirmwareUpdateInformation) {
186  m_backendHandle, _numFirmwareUpdateInformation);
187  });
188 
189  std::vector<std::shared_ptr<FirmwareUpdateInformation>> firmwareUpdateInformation;
190  for (size_t x = 0; x < numFirmwareUpdateInformation; ++x)
191  {
192  auto firmwareUpdateInformationHandle =
193  QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE>(
194  [&](PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE* _firmwareUpdateInformationHandle) {
196  m_backendHandle, x, _firmwareUpdateInformationHandle);
197  });
198 
199  firmwareUpdateInformation.emplace_back(
200  std::make_shared<ClassCreator<FirmwareUpdateInformation>>(firmwareUpdateInformationHandle));
201  }
202 
203  return firmwareUpdateInformation;
204 }
205 
206 inline void FirmwareUpdater::UpdateDevice(const std::shared_ptr<DeviceDescriptor>& device,
207  const std::shared_ptr<FirmwareUpdateInformation>& updateInformation,
208  const FirmwareUpdateProgressObserver* progressObserver /* = nullptr */,
209  Timeout deviceResetDiscoveryTimeout /* = Timeout{ 60000ms }*/)
210 {
211  if (device == nullptr)
212  {
213  throw InvalidArgumentException("The given device is a nullptr!");
214  }
215  if (updateInformation == nullptr)
216  {
217  throw InvalidArgumentException("The given updateInformation is a nullptr!");
218  }
219 
220  CallAndCheckCInterfaceFunction([&] {
222  device->m_backendHandle, updateInformation->m_backendHandle,
223  progressObserver ? progressObserver->m_backendHandle : nullptr, deviceResetDiscoveryTimeout);
224  });
225 }
226 
227 } /* namespace core */
228 } /* namespace peak */
struct PEAK_FIRMWARE_UPDATER * PEAK_FIRMWARE_UPDATER_HANDLE
Definition: peak_backend.h:471
The exception thrown for pass an invalid argument to a function.
Definition: peak_exception.hpp:73
PEAK_C_API PEAK_FirmwareUpdater_GetFirmwareUpdateInformation(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle, size_t index, PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE *firmwareUpdateInformationHandle)
Asks the given firmware updater for the update information with the given index.
PEAK_C_API PEAK_FirmwareUpdater_UpdateDeviceWithResetTimeout(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle, PEAK_DEVICE_DESCRIPTOR_HANDLE deviceDescriptorHandle, PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE firmwareUpdateInformationHandle, PEAK_FIRMWARE_UPDATE_PROGRESS_OBSERVER_HANDLE firmwareUpdateProgressObserverHandle, uint64_t deviceResetDiscoveryTimeout_ms)
Tells the given firmware updater to update the given device with the given update information...
PEAK_C_API PEAK_FirmwareUpdater_GetNumFirmwareUpdateInformation(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle, size_t *numFirmwareUpdateInformation)
Asks the given firmware updater for its number of update information.
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
void UpdateDevice(const std::shared_ptr< DeviceDescriptor > &device, const std::shared_ptr< FirmwareUpdateInformation > &updateInformation, const FirmwareUpdateProgressObserver *progressObserver=nullptr, Timeout deviceResetDiscoveryTimeout=Timeout(60000ms))
Updates a given device by using a given firmware update information.
Definition: peak_firmware_updater.hpp:206
~FirmwareUpdater()
Definition: peak_firmware_updater.hpp:134
PEAK_C_API PEAK_FirmwareUpdater_Destruct(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle)
Destroys the given firmware updater.
Allows to update the firmware of a device.
Definition: peak_firmware_updater.hpp:45
FirmwareUpdater()
Definition: peak_firmware_updater.hpp:127
std::vector< std::shared_ptr< FirmwareUpdateInformation > > CollectFirmwareUpdateInformation(const std::string &gufPath) const
Collects all firmware update information of a given *.guf file.
Definition: peak_firmware_updater.hpp:139
Represents a timeout value in milliseconds.
Definition: peak_timeout.hpp:30
Allows to observe a firmware update process.
Definition: peak_firmware_update_progress_observer.hpp:52
PEAK_C_API PEAK_FirmwareUpdater_Construct(PEAK_FIRMWARE_UPDATER_HANDLE *firmwareUpdaterHandle)
Creates a firmware updater.
PEAK_C_API PEAK_FirmwareUpdater_CollectFirmwareUpdateInformation(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle, const char *gufPath, size_t gufPathSize, PEAK_DEVICE_DESCRIPTOR_HANDLE deviceDescriptorHandle)
Tells the given firmware updater to collect all update information fitting to the given device...
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
PEAK_C_API PEAK_FirmwareUpdater_CollectAllFirmwareUpdateInformation(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle, const char *gufPath, size_t gufPathSize)
Tells the given firmware updater to collect all update information from the .guf file.
struct PEAK_FIRMWARE_UPDATE_INFORMATION * PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE
Definition: peak_backend.h:475