CVB++ 15.0
decl_fw_updater.hpp
1#pragma once
2
3#include <map>
4#include <memory>
5
6#include "../../global.hpp"
7#include "../../string.hpp"
8#include "../../utilities/system_info.hpp"
9
10#include "../genapi.hpp"
11
12#ifdef _MSC_VER
13# pragma warning(push, 1)
14# pragma warning(disable : 4244)
15#endif
16
17namespace Cvb
18{
19
20 CVB_BEGIN_INLINE_NS
21
22 template <>
23 inline HandleGuard<GenApi::FWUpdater>::HandleGuard(void *handle) noexcept
24 : HandleGuard<GenApi::FWUpdater>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
25 {
26 }
27
28 namespace GenApi
29 {
31
37
39 class FWUpdater
40 {
41 struct PrivateTag
42 {
43 };
44
45 public:
50
57 static std::unique_ptr<FWUpdater> Create(const String &filename, bool verify = true);
58
59 FWUpdater(HandleGuard<FWUpdater> &&guard, const String &filename, PrivateTag) noexcept;
60
65
71 explicit FWUpdater(const String &filename, bool verify = true);
72
73 FWUpdater(const FWUpdater &other) = delete;
74 FWUpdater &operator=(const FWUpdater &other) = delete;
75 FWUpdater(FWUpdater &&other) noexcept = default;
76 FWUpdater &operator=(FWUpdater &&other) noexcept = default;
77 ~FWUpdater() = default;
78
80
88 static std::unique_ptr<FWUpdater> FromHandle(HandleGuard<FWUpdater> &&guard, const String &filename);
89
91
97 void *Handle() const noexcept
98 {
99 return handle_.Handle();
100 }
101
103
107 size_t UpdateFileCount();
108
110
115 size_t UpdateFileInfoCount(const size_t &fileIndex);
116
119
125 String UpdateFileInfo(size_t fileIndex, size_t infoIndex, FirmwareUpdateInfo cmd);
126
128
132
134
138
140
143 std::vector<String> UpdateFileInfos(const size_t &updateFileIndex);
144
146
151 void Update(DevicePtr &&device, const size_t updateFileSelection);
152
153 private:
154 void SetDevice(DevicePtr &&device);
155
156 String DeviceSerialNumber() const noexcept;
157
158 void ResetDevice();
159
160 static void NativeCall(std::function<CExports::cvbres_t()> fn)
161 {
162 auto result = fn();
163 if (result < 0)
164 {
166 if (message.empty())
167 message = "Error";
168
169 std::stringstream stream;
170 stream << "FWUpdater: " << message;
171 std::rethrow_exception(CvbException::FromCvbResult(result, stream.str()));
172 }
173 }
174
175 template <class T>
176 T NativeCall(std::function<CExports::cvbres_t(T &value)> fn) const
177 {
178 T value;
179 auto result = fn(value);
180 if (result < 0)
181 {
183 if (message.empty())
184 message = "Error";
185
186 std::stringstream stream;
187 stream << "FWUpdater: " << message;
188 std::rethrow_exception(CvbException::FromCvbResult(result, stream.str()));
189 }
190 return value;
191 }
192
193 static CExports::cvbbool_t __stdcall EventOnDeviceReset(unsigned int deviceDiscoveryTimeoutMs,
194 unsigned int deviceDiscoveryDelayMs,
195 CExports::NODEMAP &nodeMap, void *pPrivate);
196
197 HandleGuard<FWUpdater> handle_;
198 String filename_;
199 size_t updateFileIndex_ = 0;
200 String deviceSn_;
201 DevicePtr device_;
202 NodeMapPtr deviceNM_;
203 };
204 } // namespace GenApi
205 using GenApi::FWUpdater;
206
207 CVB_END_INLINE_NS
208
209} // namespace Cvb
210
211#ifdef _MSC_VER
212# pragma warning(pop)
213#endif
Firmware updater class.
Definition decl_fw_updater.hpp:40
std::vector< std::pair< String, String > > AvailableGufInfo()
Collects all key value pairs available in a guf file.
Definition detail_fw_updater.hpp:87
std::vector< String > UpdateFileInfos(const size_t &updateFileIndex)
Collects all information on a single update file available in a guf file.
Definition detail_fw_updater.hpp:133
std::vector< String > AvailableUpdateFiles()
Collects all mandatory update file infos available in a guf file.
Definition detail_fw_updater.hpp:108
String UpdateFileInfo(size_t fileIndex, size_t infoIndex, FirmwareUpdateInfo cmd)
Identifies a single firmware update and gets information about the firmware update as CVB::String.
Definition detail_fw_updater.hpp:66
size_t UpdateFileInfoCount(const size_t &fileIndex)
Gets the number of available update infos in a guf file.
Definition detail_fw_updater.hpp:60
static std::unique_ptr< FWUpdater > Create(const String &filename, bool verify=true)
Create a firmware updater, Validate a guf file and set the location of the guf file as CVB::String.
Definition detail_fw_updater.hpp:28
size_t UpdateFileCount()
Gets the number of available update files in a guf file.
Definition detail_fw_updater.hpp:55
static std::unique_ptr< FWUpdater > FromHandle(HandleGuard< FWUpdater > &&guard, const String &filename)
Creates a firmware updater from a classic API handle.
Definition detail_fw_updater.hpp:47
void * Handle() const noexcept
Classic API node map handle.
Definition decl_fw_updater.hpp:97
void Update(DevicePtr &&device, const size_t updateFileSelection)
Update the device.
Definition detail_fw_updater.hpp:146
cvbbool_t ReleaseObject(OBJ &Object)
Namespace for GenApi based device configuration.
Definition decl_fw_updater.hpp:29
FirmwareUpdateInfo
Defines commands to retrieve firmware information from a guf file.
Definition genapi.hpp:259
std::shared_ptr< NodeMap > NodeMapPtr
Convenience shared pointer for NodeMap.
Definition genapi.hpp:27
std::string GetLastErrorMessage()
Returns the last error message.
Definition system_info.hpp:167
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49
std::shared_ptr< Device > DevicePtr
Convenience shared pointer for Device.
Definition global.hpp:98
T rethrow_exception(T... args)