mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
Device: Extend open() API for long-running tasks
This commit is contained in:
@@ -8,13 +8,13 @@
|
||||
#include <utility>
|
||||
#include <cstring>
|
||||
#include <atomic>
|
||||
#include <type_traits>
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
#include "icsneo/api/lifetime.h"
|
||||
#include "icsneo/device/neodevice.h"
|
||||
#include "icsneo/device/idevicesettings.h"
|
||||
#include "icsneo/device/nullsettings.h"
|
||||
#include "icsneo/device/devicetype.h"
|
||||
#include "icsneo/device/extensions/deviceextension.h"
|
||||
#include "icsneo/communication/communication.h"
|
||||
#include "icsneo/communication/packetizer.h"
|
||||
#include "icsneo/communication/encoder.h"
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class DeviceExtension;
|
||||
|
||||
class Device {
|
||||
public:
|
||||
virtual ~Device();
|
||||
@@ -50,7 +52,50 @@ public:
|
||||
return os;
|
||||
}
|
||||
|
||||
virtual bool open();
|
||||
class OpenFlags {
|
||||
public:
|
||||
enum Enum {
|
||||
/**
|
||||
* Even if the firmware does not match the current firmware version,
|
||||
* the device will not be updated.
|
||||
*
|
||||
* Note: The device may still be flashed if the device has no firmware
|
||||
*
|
||||
* This has no effect if the DFU extension is not present
|
||||
*/
|
||||
SuppressAutoUpdate = 1 << 0,
|
||||
|
||||
/**
|
||||
* Force reflash the device.
|
||||
*
|
||||
* This has no effect if the DFU extension is not present
|
||||
*/
|
||||
ForceReflash = 1 << 1
|
||||
};
|
||||
using EnumType = std::underlying_type<Enum>::type;
|
||||
|
||||
OpenFlags(Enum e = Enum(0)) : val(e) {}
|
||||
EnumType operator&(Enum e) const { return EnumType(val) & EnumType(e); }
|
||||
|
||||
private:
|
||||
const Enum val;
|
||||
};
|
||||
|
||||
enum class OpenDirective {
|
||||
Continue,
|
||||
Cancel,
|
||||
Skip
|
||||
};
|
||||
|
||||
enum class OpenStatusType {
|
||||
Question,
|
||||
Progress
|
||||
};
|
||||
|
||||
using OpenStatusHandler = std::function<OpenDirective(OpenStatusType type, const std::string& status, optional<double> progress)>;
|
||||
|
||||
bool open(OpenFlags flags = {}, OpenStatusHandler handler =
|
||||
[](OpenStatusType type, const std::string& _s, optional<double> _p) { return OpenDirective::Continue; });
|
||||
virtual bool close();
|
||||
virtual bool isOnline() const { return online; }
|
||||
virtual bool isOpen() const { return com->isOpen(); }
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <memory>
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
#include "icsneo/device/device.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
@@ -18,10 +19,10 @@ public:
|
||||
virtual const char* getName() const = 0;
|
||||
|
||||
// Return false to block opening
|
||||
virtual bool onDeviceOpen() { return true; }
|
||||
virtual bool onDeviceOpen(Device::OpenFlags flags, const Device::OpenStatusHandler& handler) { return true; }
|
||||
|
||||
// Return true to indicate that communication should now be back
|
||||
virtual bool onDeviceCommunicationDead() { return false; }
|
||||
virtual bool onDeviceCommunicationDead(Device::OpenFlags flags, const Device::OpenStatusHandler& handler) { return false; }
|
||||
|
||||
virtual void onGoOnline() {}
|
||||
virtual void onGoOffline() {}
|
||||
|
||||
Reference in New Issue
Block a user