IDS peak genericC++ v1.12.0
Loading...
Searching...
No Matches
peak_firmware_updater.hpp
Go to the documentation of this file.
1
10
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
25namespace peak
26{
27namespace core
28{
29using namespace std::chrono_literals;
30
45class FirmwareUpdater final
46{
47public:
50 FirmwareUpdater(const FirmwareUpdater& other) = delete;
51 FirmwareUpdater& operator=(const FirmwareUpdater& other) = delete;
54
71 std::vector<std::shared_ptr<FirmwareUpdateInformation>> CollectFirmwareUpdateInformation(
72 const std::string& gufPath) const;
73
93 std::vector<std::shared_ptr<FirmwareUpdateInformation>> CollectFirmwareUpdateInformation(
94 const std::string& gufPath, const std::shared_ptr<DeviceDescriptor>& device) const;
95
121 void UpdateDevice(const std::shared_ptr<DeviceDescriptor>& device,
122 const std::shared_ptr<FirmwareUpdateInformation>& updateInformation,
123 const FirmwareUpdateProgressObserver* progressObserver = nullptr,
124 Timeout deviceResetDiscoveryTimeout = Timeout(60000ms));
125
126private:
127 PEAK_FIRMWARE_UPDATER_HANDLE m_backendHandle;
128};
129
130} /* namespace core */
131} /* namespace peak */
132
133/* Implementation */
134namespace peak
135{
136namespace core
137{
138
140 : m_backendHandle(QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATER_HANDLE>(
141 [](PEAK_FIRMWARE_UPDATER_HANDLE* firmwareUpdaterHandle) {
142 return PEAK_C_ABI_PREFIX PEAK_FirmwareUpdater_Construct(firmwareUpdaterHandle);
143 }))
144{}
145
150
151inline std::vector<std::shared_ptr<FirmwareUpdateInformation>> FirmwareUpdater::CollectFirmwareUpdateInformation(
152 const std::string& gufPath) const
153{
154 CallAndCheckCInterfaceFunction([&] {
156 m_backendHandle, gufPath.c_str(), gufPath.size() + 1);
157 });
158
159 auto numFirmwareUpdateInformation = QueryNumericFromCInterfaceFunction<size_t>(
160 [&](size_t* _numFirmwareUpdateInformation) {
162 m_backendHandle, _numFirmwareUpdateInformation);
163 });
164
165 std::vector<std::shared_ptr<FirmwareUpdateInformation>> firmwareUpdateInformation;
166 for (size_t x = 0; x < numFirmwareUpdateInformation; ++x)
167 {
168 auto firmwareUpdateInformationHandle =
169 QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE>(
170 [&](PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE* _firmwareUpdateInformationHandle) {
172 m_backendHandle, x, _firmwareUpdateInformationHandle);
173 });
174
175 firmwareUpdateInformation.emplace_back(
176 std::make_shared<ClassCreator<FirmwareUpdateInformation>>(firmwareUpdateInformationHandle));
177 }
178
179 return firmwareUpdateInformation;
180}
181
182inline std::vector<std::shared_ptr<FirmwareUpdateInformation>> FirmwareUpdater::CollectFirmwareUpdateInformation(
183 const std::string& gufPath, const std::shared_ptr<DeviceDescriptor>& device) const
184{
185 if (device == nullptr)
186 {
187 throw InvalidArgumentException("The given device is a nullptr!");
188 }
189
190 CallAndCheckCInterfaceFunction([&] {
192 m_backendHandle, gufPath.c_str(), gufPath.size() + 1, device->m_backendHandle);
193 });
194
195 auto numFirmwareUpdateInformation = QueryNumericFromCInterfaceFunction<size_t>(
196 [&](size_t* _numFirmwareUpdateInformation) {
198 m_backendHandle, _numFirmwareUpdateInformation);
199 });
200
201 std::vector<std::shared_ptr<FirmwareUpdateInformation>> firmwareUpdateInformation;
202 for (size_t x = 0; x < numFirmwareUpdateInformation; ++x)
203 {
204 auto firmwareUpdateInformationHandle =
205 QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE>(
206 [&](PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE* _firmwareUpdateInformationHandle) {
208 m_backendHandle, x, _firmwareUpdateInformationHandle);
209 });
210
211 firmwareUpdateInformation.emplace_back(
212 std::make_shared<ClassCreator<FirmwareUpdateInformation>>(firmwareUpdateInformationHandle));
213 }
214
215 return firmwareUpdateInformation;
216}
217
218inline void FirmwareUpdater::UpdateDevice(const std::shared_ptr<DeviceDescriptor>& device,
219 const std::shared_ptr<FirmwareUpdateInformation>& updateInformation,
220 const FirmwareUpdateProgressObserver* progressObserver /* = nullptr */,
221 Timeout deviceResetDiscoveryTimeout /* = Timeout{ 60000ms }*/)
222{
223 if (device == nullptr)
224 {
225 throw InvalidArgumentException("The given device is a nullptr!");
226 }
227 if (updateInformation == nullptr)
228 {
229 throw InvalidArgumentException("The given updateInformation is a nullptr!");
230 }
231
232 CallAndCheckCInterfaceFunction([&] {
234 device->m_backendHandle, updateInformation->m_backendHandle,
235 progressObserver ? progressObserver->m_backendHandle : nullptr, deviceResetDiscoveryTimeout);
236 });
237}
238
239} /* namespace core */
240} /* namespace peak */
Allows to observe a firmware update process.
Definition peak_firmware_update_progress_observer.hpp:53
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:218
~FirmwareUpdater()
Definition peak_firmware_updater.hpp:146
FirmwareUpdater(FirmwareUpdater &&other)=delete
FirmwareUpdater()
Definition peak_firmware_updater.hpp:139
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:151
FirmwareUpdater & operator=(FirmwareUpdater &&other)=delete
FirmwareUpdater & operator=(const FirmwareUpdater &other)=delete
FirmwareUpdater(const FirmwareUpdater &other)=delete
The exception thrown for passing an invalid argument to a function.
Definition peak_exception.hpp:109
Represents a timeout value in milliseconds.
Definition peak_timeout.hpp:31
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:34
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:33
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_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_Construct(PEAK_FIRMWARE_UPDATER_HANDLE *firmwareUpdaterHandle)
Creates a firmware updater.
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.
PEAK_C_API PEAK_FirmwareUpdater_Destruct(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle)
Destroys the given firmware updater.
struct PEAK_FIRMWARE_UPDATE_INFORMATION * PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE
Definition peak_backend.h:497
struct PEAK_FIRMWARE_UPDATER * PEAK_FIRMWARE_UPDATER_HANDLE
Definition peak_backend.h:493
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.
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.
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:16