IDS peak genericC++ v1.11.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
67 std::vector<std::shared_ptr<FirmwareUpdateInformation>> CollectFirmwareUpdateInformation(
68 const std::string& gufPath) const;
69
86 std::vector<std::shared_ptr<FirmwareUpdateInformation>> CollectFirmwareUpdateInformation(
87 const std::string& gufPath, const std::shared_ptr<DeviceDescriptor>& device) const;
88
111 void UpdateDevice(const std::shared_ptr<DeviceDescriptor>& device,
112 const std::shared_ptr<FirmwareUpdateInformation>& updateInformation,
113 const FirmwareUpdateProgressObserver* progressObserver = nullptr,
114 Timeout deviceResetDiscoveryTimeout = Timeout(60000ms));
115
116private:
117 PEAK_FIRMWARE_UPDATER_HANDLE m_backendHandle;
118};
119
120} /* namespace core */
121} /* namespace peak */
122
123/* Implementation */
124namespace peak
125{
126namespace core
127{
128
130 : m_backendHandle(QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATER_HANDLE>(
131 [](PEAK_FIRMWARE_UPDATER_HANDLE* firmwareUpdaterHandle) {
132 return PEAK_C_ABI_PREFIX PEAK_FirmwareUpdater_Construct(firmwareUpdaterHandle);
133 }))
134{}
135
140
141inline std::vector<std::shared_ptr<FirmwareUpdateInformation>> FirmwareUpdater::CollectFirmwareUpdateInformation(
142 const std::string& gufPath) const
143{
144 CallAndCheckCInterfaceFunction([&] {
146 m_backendHandle, gufPath.c_str(), gufPath.size() + 1);
147 });
148
149 auto numFirmwareUpdateInformation = QueryNumericFromCInterfaceFunction<size_t>(
150 [&](size_t* _numFirmwareUpdateInformation) {
152 m_backendHandle, _numFirmwareUpdateInformation);
153 });
154
155 std::vector<std::shared_ptr<FirmwareUpdateInformation>> firmwareUpdateInformation;
156 for (size_t x = 0; x < numFirmwareUpdateInformation; ++x)
157 {
158 auto firmwareUpdateInformationHandle =
159 QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE>(
160 [&](PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE* _firmwareUpdateInformationHandle) {
162 m_backendHandle, x, _firmwareUpdateInformationHandle);
163 });
164
165 firmwareUpdateInformation.emplace_back(
166 std::make_shared<ClassCreator<FirmwareUpdateInformation>>(firmwareUpdateInformationHandle));
167 }
168
169 return firmwareUpdateInformation;
170}
171
172inline std::vector<std::shared_ptr<FirmwareUpdateInformation>> FirmwareUpdater::CollectFirmwareUpdateInformation(
173 const std::string& gufPath, const std::shared_ptr<DeviceDescriptor>& device) const
174{
175 if (device == nullptr)
176 {
177 throw InvalidArgumentException("The given device is a nullptr!");
178 }
179
180 CallAndCheckCInterfaceFunction([&] {
182 m_backendHandle, gufPath.c_str(), gufPath.size() + 1, device->m_backendHandle);
183 });
184
185 auto numFirmwareUpdateInformation = QueryNumericFromCInterfaceFunction<size_t>(
186 [&](size_t* _numFirmwareUpdateInformation) {
188 m_backendHandle, _numFirmwareUpdateInformation);
189 });
190
191 std::vector<std::shared_ptr<FirmwareUpdateInformation>> firmwareUpdateInformation;
192 for (size_t x = 0; x < numFirmwareUpdateInformation; ++x)
193 {
194 auto firmwareUpdateInformationHandle =
195 QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE>(
196 [&](PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE* _firmwareUpdateInformationHandle) {
198 m_backendHandle, x, _firmwareUpdateInformationHandle);
199 });
200
201 firmwareUpdateInformation.emplace_back(
202 std::make_shared<ClassCreator<FirmwareUpdateInformation>>(firmwareUpdateInformationHandle));
203 }
204
205 return firmwareUpdateInformation;
206}
207
208inline void FirmwareUpdater::UpdateDevice(const std::shared_ptr<DeviceDescriptor>& device,
209 const std::shared_ptr<FirmwareUpdateInformation>& updateInformation,
210 const FirmwareUpdateProgressObserver* progressObserver /* = nullptr */,
211 Timeout deviceResetDiscoveryTimeout /* = Timeout{ 60000ms }*/)
212{
213 if (device == nullptr)
214 {
215 throw InvalidArgumentException("The given device is a nullptr!");
216 }
217 if (updateInformation == nullptr)
218 {
219 throw InvalidArgumentException("The given updateInformation is a nullptr!");
220 }
221
222 CallAndCheckCInterfaceFunction([&] {
224 device->m_backendHandle, updateInformation->m_backendHandle,
225 progressObserver ? progressObserver->m_backendHandle : nullptr, deviceResetDiscoveryTimeout);
226 });
227}
228
229} /* namespace core */
230} /* 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:208
~FirmwareUpdater()
Definition peak_firmware_updater.hpp:136
FirmwareUpdater(FirmwareUpdater &&other)=delete
FirmwareUpdater()
Definition peak_firmware_updater.hpp:129
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:141
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:74
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:31
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