diff --git a/api/icsneocpp/include/icsneocpp.h b/api/icsneocpp/include/icsneocpp.h index 3755dbf..54f985a 100644 --- a/api/icsneocpp/include/icsneocpp.h +++ b/api/icsneocpp/include/icsneocpp.h @@ -7,7 +7,9 @@ #include "device/include/device.h" namespace icsneo { - std::vector> FindAllDevices(); -}; + +std::vector> FindAllDevices(); + +} #endif \ No newline at end of file diff --git a/communication/include/communication.h b/communication/include/communication.h index d945a33..2ee089e 100644 --- a/communication/include/communication.h +++ b/communication/include/communication.h @@ -58,6 +58,6 @@ private: void readTask(); }; -}; +} #endif \ No newline at end of file diff --git a/communication/include/icommunication.h b/communication/include/icommunication.h index 5b1c06b..784f72b 100644 --- a/communication/include/icommunication.h +++ b/communication/include/icommunication.h @@ -38,6 +38,6 @@ protected: std::atomic closing{false}; }; -}; +} #endif \ No newline at end of file diff --git a/communication/include/multichannelcommunication.h b/communication/include/multichannelcommunication.h index c3aab8d..db15814 100644 --- a/communication/include/multichannelcommunication.h +++ b/communication/include/multichannelcommunication.h @@ -98,6 +98,6 @@ private: void readTask(); }; -}; +} #endif \ No newline at end of file diff --git a/communication/include/network.h b/communication/include/network.h index 9f7c192..9a6040b 100644 --- a/communication/include/network.h +++ b/communication/include/network.h @@ -400,6 +400,6 @@ private: } }; -}; +} #endif \ No newline at end of file diff --git a/communication/message/callback/include/messagecallback.h b/communication/message/callback/include/messagecallback.h index 1ed7f62..84c7591 100644 --- a/communication/message/callback/include/messagecallback.h +++ b/communication/message/callback/include/messagecallback.h @@ -1,37 +1,37 @@ -#ifndef __MESSAGECALLBACK_H_ -#define __MESSAGECALLBACK_H_ - -#include "communication/message/include/message.h" -#include "communication/message/filter/include/messagefilter.h" -#include -#include - -namespace icsneo { - -class MessageCallback { -public: - typedef std::function< void( std::shared_ptr ) > fn_messageCallback; - - MessageCallback(fn_messageCallback cb, std::shared_ptr f) : callback(cb), filter(f) {} - MessageCallback(fn_messageCallback cb, MessageFilter f = MessageFilter()) : callback(cb), filter(std::make_shared(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) 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 filter; -}; - -}; - +#ifndef __MESSAGECALLBACK_H_ +#define __MESSAGECALLBACK_H_ + +#include "communication/message/include/message.h" +#include "communication/message/filter/include/messagefilter.h" +#include +#include + +namespace icsneo { + +class MessageCallback { +public: + typedef std::function< void( std::shared_ptr ) > fn_messageCallback; + + MessageCallback(fn_messageCallback cb, std::shared_ptr f) : callback(cb), filter(f) {} + MessageCallback(fn_messageCallback cb, MessageFilter f = MessageFilter()) : callback(cb), filter(std::make_shared(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) 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 filter; +}; + +} + #endif \ No newline at end of file diff --git a/communication/message/filter/include/messagefilter.h b/communication/message/filter/include/messagefilter.h index d40972d..88916f4 100644 --- a/communication/message/filter/include/messagefilter.h +++ b/communication/message/filter/include/messagefilter.h @@ -1,47 +1,47 @@ -#ifndef __MESSAGEFILTER_H_ -#define __MESSAGEFILTER_H_ - -#include "communication/include/network.h" -#include "communication/message/include/message.h" -#include - -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) 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 + +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) 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 \ No newline at end of file diff --git a/communication/message/include/canmessage.h b/communication/message/include/canmessage.h index 35aa877..2d25ca3 100644 --- a/communication/message/include/canmessage.h +++ b/communication/message/include/canmessage.h @@ -10,6 +10,6 @@ public: uint32_t arbid; }; -}; +} #endif \ No newline at end of file diff --git a/communication/message/include/message.h b/communication/message/include/message.h index 8e1f813..3379d1d 100644 --- a/communication/message/include/message.h +++ b/communication/message/include/message.h @@ -14,6 +14,6 @@ public: uint64_t timestamp; }; -}; +} #endif \ No newline at end of file diff --git a/communication/message/include/neomessage.h b/communication/message/include/neomessage.h index 56eaabe..0eae415 100644 --- a/communication/message/include/neomessage.h +++ b/communication/message/include/neomessage.h @@ -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 \ No newline at end of file diff --git a/communication/packetizer.cpp b/communication/packetizer.cpp index 9250e28..1ab4ea1 100644 --- a/communication/packetizer.cpp +++ b/communication/packetizer.cpp @@ -86,7 +86,7 @@ bool Packetizer::input(const std::vector& 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; } diff --git a/device/include/device.h b/device/include/device.h index 76d2cf5..5f8a667 100644 --- a/device/include/device.h +++ b/device/include/device.h @@ -78,6 +78,6 @@ private: void enforcePollingMessageLimit(); }; -}; +} #endif \ No newline at end of file diff --git a/device/include/devicefinder.h b/device/include/devicefinder.h index 0bfeb34..c98cf9c 100644 --- a/device/include/devicefinder.h +++ b/device/include/devicefinder.h @@ -12,6 +12,6 @@ public: static std::vector> FindAll(); }; -}; +} #endif \ No newline at end of file diff --git a/device/include/neodevice.h b/device/include/neodevice.h index bca52f7..2e996b6 100644 --- a/device/include/neodevice.h +++ b/device/include/neodevice.h @@ -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; diff --git a/device/neoobd2pro/include/neoobd2pro.h b/device/neoobd2pro/include/neoobd2pro.h index 08a067a..315138a 100644 --- a/device/neoobd2pro/include/neoobd2pro.h +++ b/device/neoobd2pro/include/neoobd2pro.h @@ -30,6 +30,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/neoobd2sim/include/neoobd2sim.h b/device/neoobd2sim/include/neoobd2sim.h index 766ca48..5098597 100644 --- a/device/neoobd2sim/include/neoobd2sim.h +++ b/device/neoobd2sim/include/neoobd2sim.h @@ -30,6 +30,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/neovifire/include/neovifire.h b/device/neovifire/include/neovifire.h index 89dd842..704e8e2 100644 --- a/device/neovifire/include/neovifire.h +++ b/device/neovifire/include/neovifire.h @@ -53,6 +53,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/neovifire2/include/neovifire2.h b/device/neovifire2/include/neovifire2.h index 2292b1b..6fa1b40 100644 --- a/device/neovifire2/include/neovifire2.h +++ b/device/neovifire2/include/neovifire2.h @@ -14,6 +14,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/neovifire2/include/neovifire2eth.h b/device/neovifire2/include/neovifire2eth.h index e5e0b83..52bf61c 100644 --- a/device/neovifire2/include/neovifire2eth.h +++ b/device/neovifire2/include/neovifire2eth.h @@ -40,6 +40,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/neovifire2/include/neovifire2usb.h b/device/neovifire2/include/neovifire2usb.h index 6dedc7e..f172939 100644 --- a/device/neovifire2/include/neovifire2usb.h +++ b/device/neovifire2/include/neovifire2usb.h @@ -29,6 +29,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/plasion/include/neoviion.h b/device/plasion/include/neoviion.h index 12275df..309bc8d 100644 --- a/device/plasion/include/neoviion.h +++ b/device/plasion/include/neoviion.h @@ -25,6 +25,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/plasion/include/neoviplasma.h b/device/plasion/include/neoviplasma.h index 84520af..e216f4e 100644 --- a/device/plasion/include/neoviplasma.h +++ b/device/plasion/include/neoviplasma.h @@ -25,6 +25,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/plasion/include/plasion.h b/device/plasion/include/plasion.h index 6001b4a..3aa8542 100644 --- a/device/plasion/include/plasion.h +++ b/device/plasion/include/plasion.h @@ -17,6 +17,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/radgalaxy/include/radgalaxy.h b/device/radgalaxy/include/radgalaxy.h index e32093c..f3b2fb2 100644 --- a/device/radgalaxy/include/radgalaxy.h +++ b/device/radgalaxy/include/radgalaxy.h @@ -44,6 +44,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/radstar2/include/radstar2.h b/device/radstar2/include/radstar2.h index fffb4d3..29b991d 100644 --- a/device/radstar2/include/radstar2.h +++ b/device/radstar2/include/radstar2.h @@ -30,6 +30,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/radsupermoon/include/radsupermoon.h b/device/radsupermoon/include/radsupermoon.h index e53518d..595af13 100644 --- a/device/radsupermoon/include/radsupermoon.h +++ b/device/radsupermoon/include/radsupermoon.h @@ -33,6 +33,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/valuecan3/include/valuecan3.h b/device/valuecan3/include/valuecan3.h index 6b3135a..f3e9719 100644 --- a/device/valuecan3/include/valuecan3.h +++ b/device/valuecan3/include/valuecan3.h @@ -29,6 +29,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/valuecan4/include/valuecan4.h b/device/valuecan4/include/valuecan4.h index 091dd3e..62cbf5c 100644 --- a/device/valuecan4/include/valuecan4.h +++ b/device/valuecan4/include/valuecan4.h @@ -30,6 +30,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/device/vividcan/include/vividcan.h b/device/vividcan/include/vividcan.h index 73870db..0b522b7 100644 --- a/device/vividcan/include/vividcan.h +++ b/device/vividcan/include/vividcan.h @@ -32,6 +32,6 @@ public: } }; -}; +} #endif \ No newline at end of file diff --git a/platform/posix/darwin/include/dynamiclib.h b/platform/posix/darwin/include/dynamiclib.h index 100a123..9b3db88 100644 --- a/platform/posix/darwin/include/dynamiclib.h +++ b/platform/posix/darwin/include/dynamiclib.h @@ -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 \ No newline at end of file diff --git a/platform/posix/include/ftdi.h b/platform/posix/include/ftdi.h index 1757098..c661fbe 100644 --- a/platform/posix/include/ftdi.h +++ b/platform/posix/include/ftdi.h @@ -46,6 +46,6 @@ private: FTDIDevice ftdiDevice; }; -}; +} #endif \ No newline at end of file diff --git a/platform/posix/include/stm32.h b/platform/posix/include/stm32.h index e986614..ff729fe 100644 --- a/platform/posix/include/stm32.h +++ b/platform/posix/include/stm32.h @@ -26,6 +26,6 @@ private: void writeTask(); }; -}; +} #endif \ No newline at end of file diff --git a/platform/posix/stm32.cpp b/platform/posix/stm32.cpp index 437c3de..ecef923 100644 --- a/platform/posix/stm32.cpp +++ b/platform/posix/stm32.cpp @@ -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; } diff --git a/platform/windows/include/ftdi.h b/platform/windows/include/ftdi.h index 033488a..b54d523 100644 --- a/platform/windows/include/ftdi.h +++ b/platform/windows/include/ftdi.h @@ -11,6 +11,6 @@ public: static std::vector FindByProduct(int product) { return VCP::FindByProduct(product, L"serenum"); } }; -}; +} #endif \ No newline at end of file diff --git a/platform/windows/include/pcap.h b/platform/windows/include/pcap.h index e2b26d4..c7aefd1 100644 --- a/platform/windows/include/pcap.h +++ b/platform/windows/include/pcap.h @@ -65,6 +65,6 @@ private: }; }; -}; +} #endif \ No newline at end of file diff --git a/platform/windows/include/registry.h b/platform/windows/include/registry.h index 7e342f4..7964833 100644 --- a/platform/windows/include/registry.h +++ b/platform/windows/include/registry.h @@ -28,6 +28,6 @@ private: }; }; -}; +} #endif \ No newline at end of file diff --git a/platform/windows/include/stm32.h b/platform/windows/include/stm32.h index fc44a7a..26314a7 100644 --- a/platform/windows/include/stm32.h +++ b/platform/windows/include/stm32.h @@ -11,6 +11,6 @@ public: static std::vector FindByProduct(int product) { return VCP::FindByProduct(product, L"usbser"); } }; -}; +} #endif \ No newline at end of file diff --git a/platform/windows/include/vcp.h b/platform/windows/include/vcp.h index 213c72c..7572d94 100644 --- a/platform/windows/include/vcp.h +++ b/platform/windows/include/vcp.h @@ -43,6 +43,6 @@ private: void writeTask(); }; -}; +} #endif \ No newline at end of file diff --git a/platform/windows/internal/include/pcapdll.h b/platform/windows/internal/include/pcapdll.h index ffd2efe..24b38ea 100644 --- a/platform/windows/internal/include/pcapdll.h +++ b/platform/windows/internal/include/pcapdll.h @@ -4,12 +4,17 @@ #include #include #include +#include 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 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 \ No newline at end of file diff --git a/platform/windows/internal/pcapdll.cpp b/platform/windows/internal/pcapdll.cpp index 3c2e8a1..7e3ac39 100644 --- a/platform/windows/internal/pcapdll.cpp +++ b/platform/windows/internal/pcapdll.cpp @@ -2,7 +2,15 @@ using namespace icsneo; +std::shared_ptr PCAPDLL::lazyLoadHolder; +bool PCAPDLL::lazyLoaded = false; + PCAPDLL::PCAPDLL() { + if(!lazyLoaded) { + lazyLoaded = true; + lazyLoadHolder = std::make_shared(); + } + dll = LoadLibrary("wpcap.dll"); if(dll == NULL) {