Add device sharing support

This commit is contained in:
Kyle Schwarz
2022-12-13 11:46:32 -05:00
parent 78465e0f20
commit a9157c82e5
46 changed files with 1946 additions and 102 deletions
+1 -2
View File
@@ -25,7 +25,7 @@ public:
* in cdcacmlinux.cpp and cdcacmdarwin.cpp respectively
* Other POSIX systems (BSDs, QNX, etc) will need bespoke code written in the future
*/
CDCACM(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err), device(forDevice) {}
CDCACM(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err, forDevice) {}
~CDCACM();
static void Find(std::vector<FoundDevice>& found);
@@ -37,7 +37,6 @@ public:
void awaitModeChangeComplete() override;
private:
neodevice_t& device;
int fd = -1;
std::optional<ino_t> disallowedInode;
std::atomic<bool> modeChanging{false};
-2
View File
@@ -60,8 +60,6 @@ private:
void readTask();
void writeTask();
bool openable; // Set to false in the constructor if the object has not been found in searchResultDevices
neodevice_t& device;
};
}
+1 -1
View File
@@ -24,9 +24,9 @@ public:
bool isOpen() override;
bool close() override;
bool isEthernet() const override { return true; }
bool enableHeartbeat() const override { return true; }
private:
char errbuf[PCAP_ERRBUF_SIZE] = { 0 };
neodevice_t& device;
uint8_t deviceMAC[6];
bool openable = true;
EthernetPacketizer ethPacketizer;
@@ -0,0 +1,36 @@
#ifndef __SHAREDMEMORY_POSIX_H_
#define __SHAREDMEMORY_POSIX_H_
#ifdef __cplusplus
#include <string>
#include <optional>
#include "icsneo/api/eventmanager.h"
namespace icsneo {
class SharedMemory {
public:
SharedMemory() : report(makeEventHandler()) {};
~SharedMemory();
bool open(const std::string& name, uint32_t size, bool create = false);
bool close();
uint8_t* data();
private:
virtual device_eventhandler_t makeEventHandler() {
return [](APIEvent::Type type, APIEvent::Severity severity)
{ EventManager::GetInstance().add(type, severity); };
}
device_eventhandler_t report;
std::optional<std::string> mName;
std::optional<std::pair<uint8_t*, uint32_t>> mData;
std::optional<bool> mCreated;
};
}
#endif // __cplusplus
#endif
@@ -0,0 +1,40 @@
#ifndef __SHAREDSEMAPHORE_POSIX_H_
#define __SHAREDSEMAPHORE_POSIX_H_
#ifdef __cplusplus
#include <string>
#include <optional>
#include <atomic>
#include <semaphore.h>
#include "icsneo/api/eventmanager.h"
namespace icsneo {
class SharedSemaphore {
public:
~SharedSemaphore();
bool open(const std::string& name, bool create = false, unsigned initialCount = 0);
bool close();
bool wait(const std::chrono::milliseconds& timeout);
bool post();
private:
virtual device_eventhandler_t makeEventHandler() {
return [](APIEvent::Type type, APIEvent::Severity severity)
{ EventManager::GetInstance().add(type, severity); };
}
std::atomic<bool> closing = false;
std::atomic<bool> waiting = false;
device_eventhandler_t report = makeEventHandler();
std::optional<const std::string> mName;
std::optional<sem_t*> semaphore;
std::optional<const bool> created;
};
}
#endif // __cplusplus
#endif