Resolve merge conflicts master into devicesettings

pull/4/head
Paul Hollinsky 2018-09-26 18:24:59 -04:00
commit 399c72e61d
40 changed files with 142 additions and 123 deletions

View File

@ -7,7 +7,9 @@
#include "device/include/device.h"
namespace icsneo {
std::vector<std::shared_ptr<Device>> FindAllDevices();
};
std::vector<std::shared_ptr<Device>> FindAllDevices();
}
#endif

View File

@ -58,6 +58,6 @@ private:
void readTask();
};
};
}
#endif

View File

@ -38,6 +38,6 @@ protected:
std::atomic<bool> closing{false};
};
};
}
#endif

View File

@ -98,6 +98,6 @@ private:
void readTask();
};
};
}
#endif

View File

@ -400,6 +400,6 @@ private:
}
};
};
}
#endif

View File

@ -1,37 +1,37 @@
#ifndef __MESSAGECALLBACK_H_
#define __MESSAGECALLBACK_H_
#include "communication/message/include/message.h"
#include "communication/message/filter/include/messagefilter.h"
#include <memory>
#include <functional>
namespace icsneo {
class MessageCallback {
public:
typedef std::function< void( std::shared_ptr<Message> ) > fn_messageCallback;
MessageCallback(fn_messageCallback cb, std::shared_ptr<MessageFilter> f) : callback(cb), filter(f) {}
MessageCallback(fn_messageCallback cb, MessageFilter f = MessageFilter()) : callback(cb), filter(std::make_shared<MessageFilter>(f)) {}
// Allow the filter to be placed first if the user wants (maybe in the case of a lambda)
MessageCallback(MessageFilter f, fn_messageCallback cb) { MessageCallback(cb, f); }
virtual bool callIfMatch(const std::shared_ptr<Message>& message) const {
bool ret = filter->match(message);
if(ret)
callback(message);
return ret;
}
const MessageFilter& getFilter() const { return *filter; }
const fn_messageCallback& getCallback() const { return callback; }
protected:
fn_messageCallback callback;
std::shared_ptr<MessageFilter> filter;
};
};
#ifndef __MESSAGECALLBACK_H_
#define __MESSAGECALLBACK_H_
#include "communication/message/include/message.h"
#include "communication/message/filter/include/messagefilter.h"
#include <memory>
#include <functional>
namespace icsneo {
class MessageCallback {
public:
typedef std::function< void( std::shared_ptr<Message> ) > fn_messageCallback;
MessageCallback(fn_messageCallback cb, std::shared_ptr<MessageFilter> f) : callback(cb), filter(f) {}
MessageCallback(fn_messageCallback cb, MessageFilter f = MessageFilter()) : callback(cb), filter(std::make_shared<MessageFilter>(f)) {}
// Allow the filter to be placed first if the user wants (maybe in the case of a lambda)
MessageCallback(MessageFilter f, fn_messageCallback cb) { MessageCallback(cb, f); }
virtual bool callIfMatch(const std::shared_ptr<Message>& message) const {
bool ret = filter->match(message);
if(ret)
callback(message);
return ret;
}
const MessageFilter& getFilter() const { return *filter; }
const fn_messageCallback& getCallback() const { return callback; }
protected:
fn_messageCallback callback;
std::shared_ptr<MessageFilter> filter;
};
}
#endif

View File

@ -1,47 +1,47 @@
#ifndef __MESSAGEFILTER_H_
#define __MESSAGEFILTER_H_
#include "communication/include/network.h"
#include "communication/message/include/message.h"
#include <memory>
namespace icsneo {
class MessageFilter {
public:
MessageFilter() : matchAny(true) {}
MessageFilter(Network::Type type) : type(type) {}
MessageFilter(Network::NetID netid) : netid(netid) {}
virtual ~MessageFilter() {}
virtual bool match(const std::shared_ptr<Message>& message) const {
if(matchAny)
return true;
if(!matchType(message->network.getType()))
return false;
if(!matchNetID(message->network.getNetID()))
return false;
return true;
}
private:
bool matchAny = false;
Network::Type type = Network::Type::Invalid; // Matching a type of invalid will match any
bool matchType(Network::Type mtype) const {
if(type == Network::Type::Invalid)
return true;
return type == mtype;
}
Network::NetID netid = Network::NetID::Invalid; // Matching a netid of invalid will match any
bool matchNetID(Network::NetID mnetid) const {
if(netid == Network::NetID::Invalid)
return true;
return netid == mnetid;
}
};
};
#ifndef __MESSAGEFILTER_H_
#define __MESSAGEFILTER_H_
#include "communication/include/network.h"
#include "communication/message/include/message.h"
#include <memory>
namespace icsneo {
class MessageFilter {
public:
MessageFilter() : matchAny(true) {}
MessageFilter(Network::Type type) : type(type) {}
MessageFilter(Network::NetID netid) : netid(netid) {}
virtual ~MessageFilter() {}
virtual bool match(const std::shared_ptr<Message>& message) const {
if(matchAny)
return true;
if(!matchType(message->network.getType()))
return false;
if(!matchNetID(message->network.getNetID()))
return false;
return true;
}
private:
bool matchAny = false;
Network::Type type = Network::Type::Invalid; // Matching a type of invalid will match any
bool matchType(Network::Type mtype) const {
if(type == Network::Type::Invalid)
return true;
return type == mtype;
}
Network::NetID netid = Network::NetID::Invalid; // Matching a netid of invalid will match any
bool matchNetID(Network::NetID mnetid) const {
if(netid == Network::NetID::Invalid)
return true;
return netid == mnetid;
}
};
}
#endif

View File

@ -10,6 +10,6 @@ public:
uint32_t arbid;
};
};
}
#endif

View File

@ -14,6 +14,6 @@ public:
uint64_t timestamp;
};
};
}
#endif

View File

@ -32,8 +32,10 @@ typedef struct {
#include "communication/message/include/message.h"
namespace icsneo {
neomessage_t CreateNeoMessage(const Message& message);
};
neomessage_t CreateNeoMessage(const Message& message);
}
#endif
#endif

View File

@ -86,7 +86,7 @@ bool Packetizer::input(const std::vector<uint8_t>& inputBytes) {
break;
case ReadState::GetData:
// We do not include the checksum in packetLength so it doesn't get copied into the payload buffer
if(bytes.size() < packetLength + (checksum ? 1 : 0)) { // Read until we have the rest of the packet
if(bytes.size() < (size_t)(packetLength + (checksum ? 1 : 0))) { // Read until we have the rest of the packet
haveEnoughData = false;
break;
}

View File

@ -78,6 +78,6 @@ private:
void enforcePollingMessageLimit();
};
};
}
#endif

View File

@ -12,6 +12,6 @@ public:
static std::vector<std::shared_ptr<Device>> FindAll();
};
};
}
#endif

View File

@ -6,8 +6,10 @@
#ifdef __cplusplus
// A forward declaration is needed as there is a circular dependency
namespace icsneo {
class Device;
};
class Device;
}
typedef icsneo::Device* devicehandle_t;
#else
typedef void* devicehandle_t;

View File

@ -30,6 +30,6 @@ public:
}
};
};
}
#endif

View File

@ -30,6 +30,6 @@ public:
}
};
};
}
#endif

View File

@ -53,6 +53,6 @@ public:
}
};
};
}
#endif

View File

@ -14,6 +14,6 @@ public:
}
};
};
}
#endif

View File

@ -40,6 +40,6 @@ public:
}
};
};
}
#endif

View File

@ -29,6 +29,6 @@ public:
}
};
};
}
#endif

View File

@ -25,6 +25,6 @@ public:
}
};
};
}
#endif

View File

@ -25,6 +25,6 @@ public:
}
};
};
}
#endif

View File

@ -17,6 +17,6 @@ public:
}
};
};
}
#endif

View File

@ -44,6 +44,6 @@ public:
}
};
};
}
#endif

View File

@ -30,6 +30,6 @@ public:
}
};
};
}
#endif

View File

@ -33,6 +33,6 @@ public:
}
};
};
}
#endif

View File

@ -29,6 +29,6 @@ public:
}
};
};
}
#endif

View File

@ -30,6 +30,6 @@ public:
}
};
};
}
#endif

View File

@ -32,6 +32,6 @@ public:
}
};
};
}
#endif

View File

@ -1,6 +1,6 @@
#ifndef __DYNAMICLIB_DARWIN_H_
#define __DYNAMICLIB_DARWIN_H_
#define icsneo_dynamicLibraryLoad() dlopen("/home/paulywog/Code/icsneonext/build/libicsneoc.dylib", RTLD_LAZY)
#define icsneo_dynamicLibraryLoad() dlopen("/Users/paulywog/Code/icsneonext/build/libicsneoc.dylib", RTLD_LAZY)
#endif

View File

@ -46,6 +46,6 @@ private:
FTDIDevice ftdiDevice;
};
};
}
#endif

View File

@ -26,6 +26,6 @@ private:
void writeTask();
};
};
}
#endif

View File

@ -273,8 +273,8 @@ void STM32::writeTask() {
if(!writeQueue.wait_dequeue_timed(writeOp, std::chrono::milliseconds(100)))
continue;
const auto writeSize = writeOp.bytes.size();
int actualWritten = ::write(fd, writeOp.bytes.data(), writeSize);
const ssize_t writeSize = (ssize_t)writeOp.bytes.size();
ssize_t actualWritten = ::write(fd, writeOp.bytes.data(), writeSize);
if(actualWritten != writeSize)
std::cout << "Failure to write " << writeSize << " bytes, wrote " << actualWritten << std::endl;
}

View File

@ -11,6 +11,6 @@ public:
static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, L"serenum"); }
};
};
}
#endif

View File

@ -65,6 +65,6 @@ private:
};
};
};
}
#endif

View File

@ -28,6 +28,6 @@ private:
};
};
};
}
#endif

View File

@ -11,6 +11,6 @@ public:
static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, L"usbser"); }
};
};
}
#endif

View File

@ -43,6 +43,6 @@ private:
void writeTask();
};
};
}
#endif

View File

@ -4,12 +4,17 @@
#include <Windows.h>
#include <winsock2.h>
#include <pcap.h>
#include <memory>
namespace icsneo {
// Helper loader for the PCAP DLL
class PCAPDLL {
public:
// The first time we use the DLL we keep it in here and it won't get freed until the user unloads us (for speed reasons)
static std::shared_ptr<PCAPDLL> lazyLoadHolder;
static bool lazyLoaded;
// Functions
typedef int(__cdecl* PCAPFINDDEVICE)(char* source, struct pcap_rmtauth* auth, pcap_if_t** alldevs, char* errbuf);
typedef pcap_t*(__cdecl* PCAPOPEN)(const char* source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth* auth, char* errbuf);
@ -48,6 +53,6 @@ private:
void closeDLL();
};
};
}
#endif

View File

@ -2,7 +2,15 @@
using namespace icsneo;
std::shared_ptr<PCAPDLL> PCAPDLL::lazyLoadHolder;
bool PCAPDLL::lazyLoaded = false;
PCAPDLL::PCAPDLL() {
if(!lazyLoaded) {
lazyLoaded = true;
lazyLoadHolder = std::make_shared<PCAPDLL>();
}
dll = LoadLibrary("wpcap.dll");
if(dll == NULL) {