Resolve compilation errors and warnings with MSVC

pull/4/head
Paul Hollinsky 2018-11-13 16:18:57 -05:00
parent f05f96822e
commit 0cf1e7fe7f
9 changed files with 39 additions and 40 deletions

View File

@ -17,11 +17,11 @@ APIError::APIError(ErrorType error, const Device* forDevice) : errorStruct({}) {
} }
void APIError::init(ErrorType error) { void APIError::init(ErrorType error) {
timepoint = std::chrono::high_resolution_clock::now(); timepoint = ErrorClock::now();
errorStruct.description = DescriptionForType(error); errorStruct.description = DescriptionForType(error);
errorStruct.errorNumber = (uint32_t)error; errorStruct.errorNumber = (uint32_t)error;
errorStruct.severity = (uint8_t)SeverityForType(error); errorStruct.severity = (uint8_t)SeverityForType(error);
errorStruct.timestamp = std::chrono::high_resolution_clock::to_time_t(timepoint); errorStruct.timestamp = ErrorClock::to_time_t(timepoint);
} }
std::string APIError::describe() const noexcept { std::string APIError::describe() const noexcept {
@ -35,10 +35,10 @@ std::string APIError::describe() const noexcept {
return ss.str(); return ss.str();
} }
bool APIError::isForDevice(std::string serial) const noexcept { bool APIError::isForDevice(std::string filterSerial) const noexcept {
if(!device || serial.length() == 0) if(!device || filterSerial.length() == 0)
return false; return false;
return device->getSerial() == serial; return device->getSerial() == filterSerial;
} }
// API Errors // API Errors

View File

@ -26,6 +26,9 @@ class Device;
class APIError { class APIError {
public: public:
typedef std::chrono::system_clock ErrorClock;
typedef std::chrono::time_point<ErrorClock> ErrorTimePoint;
enum ErrorType : uint32_t { enum ErrorType : uint32_t {
Any = 0, // Used for filtering, should not appear in data Any = 0, // Used for filtering, should not appear in data
@ -73,7 +76,7 @@ public:
Severity getSeverity() const noexcept { return Severity(errorStruct.severity); } Severity getSeverity() const noexcept { return Severity(errorStruct.severity); }
std::string getDescription() const noexcept { return std::string(errorStruct.description); } std::string getDescription() const noexcept { return std::string(errorStruct.description); }
const Device* getDevice() const noexcept { return device; } // Will return nullptr if this is an API-wide error const Device* getDevice() const noexcept { return device; } // Will return nullptr if this is an API-wide error
std::chrono::time_point<std::chrono::high_resolution_clock> getTimestamp() const noexcept { return timepoint; } ErrorTimePoint getTimestamp() const noexcept { return timepoint; }
bool isForDevice(const Device* forDevice) const noexcept { return forDevice == device; } bool isForDevice(const Device* forDevice) const noexcept { return forDevice == device; }
bool isForDevice(std::string serial) const noexcept; bool isForDevice(std::string serial) const noexcept;
@ -91,7 +94,7 @@ public:
private: private:
neoerror_t errorStruct; neoerror_t errorStruct;
std::string serial; std::string serial;
std::chrono::time_point<std::chrono::high_resolution_clock> timepoint; ErrorTimePoint timepoint;
const Device* device; const Device* device;
void init(ErrorType error); void init(ErrorType error);

View File

@ -26,9 +26,9 @@ public:
get(ret, filter, max); get(ret, filter, max);
return ret; return ret;
} }
void get(std::vector<APIError>& errors, ErrorFilter filter, size_t max = 0) { get(errors, max, filter); } void get(std::vector<APIError>& outErrors, ErrorFilter filter, size_t max = 0) { get(outErrors, max, filter); }
void get(std::vector<APIError>& errors, size_t max = 0, ErrorFilter filter = ErrorFilter()); void get(std::vector<APIError>& outErrors, size_t max = 0, ErrorFilter filter = ErrorFilter());
bool getLastError(APIError& error, ErrorFilter filter = ErrorFilter()); bool getLastError(APIError& outErrors, ErrorFilter filter = ErrorFilter());
void add(APIError error) { void add(APIError error) {
std::lock_guard<std::mutex> lk(mutex); std::lock_guard<std::mutex> lk(mutex);

View File

@ -103,29 +103,29 @@ protected:
template<typename Transport> template<typename Transport>
std::unique_ptr<ICommunication> makeTransport() { return std::unique_ptr<ICommunication>(new Transport(err, getWritableNeoDevice())); } std::unique_ptr<ICommunication> makeTransport() { return std::unique_ptr<ICommunication>(new Transport(err, getWritableNeoDevice())); }
virtual void setupTransport(ICommunication* transport) {} virtual void setupTransport(ICommunication* stransport) { (void)stransport; }
virtual std::shared_ptr<Packetizer> makePacketizer() { return std::make_shared<Packetizer>(err); } virtual std::shared_ptr<Packetizer> makePacketizer() { return std::make_shared<Packetizer>(err); }
virtual void setupPacketizer(Packetizer* packetizer) {} virtual void setupPacketizer(Packetizer* spacketizer) { (void)spacketizer; }
virtual std::unique_ptr<Encoder> makeEncoder(std::shared_ptr<Packetizer> p) { return std::unique_ptr<Encoder>(new Encoder(err, p)); } virtual std::unique_ptr<Encoder> makeEncoder(std::shared_ptr<Packetizer> p) { return std::unique_ptr<Encoder>(new Encoder(err, p)); }
virtual void setupEncoder(Encoder* encoder) {} virtual void setupEncoder(Encoder* sencoder) { (void)sencoder; }
virtual std::unique_ptr<Decoder> makeDecoder() { return std::unique_ptr<Decoder>(new Decoder(err)); } virtual std::unique_ptr<Decoder> makeDecoder() { return std::unique_ptr<Decoder>(new Decoder(err)); }
virtual void setupDecoder(Decoder* decoder) {} virtual void setupDecoder(Decoder* sdecoder) { (void)sdecoder; }
virtual std::shared_ptr<Communication> makeCommunication( virtual std::shared_ptr<Communication> makeCommunication(
std::unique_ptr<ICommunication> t, std::unique_ptr<ICommunication> t,
std::shared_ptr<Packetizer> p, std::shared_ptr<Packetizer> p,
std::unique_ptr<Encoder> e, std::unique_ptr<Encoder> e,
std::unique_ptr<Decoder> d) { return std::make_shared<Communication>(err, std::move(t), p, std::move(e), std::move(d)); } std::unique_ptr<Decoder> d) { return std::make_shared<Communication>(err, std::move(t), p, std::move(e), std::move(d)); }
virtual void setupCommunication(Communication* com) {} virtual void setupCommunication(Communication* scom) { (void)scom; }
template<typename Settings> template<typename Settings>
std::unique_ptr<IDeviceSettings> makeSettings(std::shared_ptr<Communication> com) { std::unique_ptr<IDeviceSettings> makeSettings(std::shared_ptr<Communication> com) {
return std::unique_ptr<IDeviceSettings>(new Settings(com)); return std::unique_ptr<IDeviceSettings>(new Settings(com));
} }
virtual void setupSettings(IDeviceSettings* settings) {} virtual void setupSettings(IDeviceSettings* ssettings) { (void)ssettings; }
// END Initialization Functions // END Initialization Functions
void handleInternalMessage(std::shared_ptr<Message> message); void handleInternalMessage(std::shared_ptr<Message> message);

View File

@ -15,13 +15,12 @@ public:
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto& foundDev : PCAP::FindAll()) { for(auto& foundDev : PCAP::FindAll()) {
auto packetizer = std::make_shared<Packetizer>(); auto fakedev = std::shared_ptr<NeoVIFIRE2ETH>(new NeoVIFIRE2ETH({}));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
for (auto& payload : foundDev.discoveryPackets) for (auto& payload : foundDev.discoveryPackets)
packetizer->input(payload); fakedev->com->packetizer->input(payload);
for(auto& packet : packetizer->output()) { for (auto& packet : fakedev->com->packetizer->output()) {
std::shared_ptr<Message> msg; std::shared_ptr<Message> msg;
if(!decoder->decode(msg, packet)) if (!fakedev->com->decoder->decode(msg, packet))
continue; // We failed to decode this packet continue; // We failed to decode this packet
if(!msg || msg->network.getNetID() != Network::NetID::Main51) if(!msg || msg->network.getNetID() != Network::NetID::Main51)
@ -44,17 +43,16 @@ public:
return found; return found;
} }
protected:
virtual void setupSettings(IDeviceSettings* settings) {
// TODO Check firmware version, old firmwares will reset Ethernet settings on settings send
settings->readonly = true;
}
private:
NeoVIFIRE2ETH(neodevice_t neodevice) : NeoVIFIRE2(neodevice) { NeoVIFIRE2ETH(neodevice_t neodevice) : NeoVIFIRE2(neodevice) {
initialize<PCAP, NeoVIFIRE2Settings>(); initialize<PCAP, NeoVIFIRE2Settings>();
productId = PRODUCT_ID; productId = PRODUCT_ID;
} }
protected:
virtual void setupSettings(IDeviceSettings* ssettings) {
// TODO Check firmware version, old firmwares will reset Ethernet settings on settings send
ssettings->readonly = true;
}
}; };
} }

View File

@ -47,18 +47,17 @@ public:
return found; return found;
} }
protected:
void setupPacketizer(Packetizer* packetizer) override {
packetizer->disableChecksum = true;
packetizer->align16bit = false;
}
private:
RADGalaxy(neodevice_t neodevice) : Device(neodevice) { RADGalaxy(neodevice_t neodevice) : Device(neodevice) {
initialize<PCAP>(); initialize<PCAP>();
getWritableNeoDevice().type = DEVICE_TYPE; getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID; productId = PRODUCT_ID;
} }
protected:
void setupPacketizer(Packetizer* packetizer) override {
packetizer->disableChecksum = true;
packetizer->align16bit = false;
}
}; };
} }

View File

@ -43,7 +43,6 @@ public:
return found; return found;
} }
private:
RADStar2ETH(neodevice_t neodevice) : RADStar2(neodevice) { RADStar2ETH(neodevice_t neodevice) : RADStar2(neodevice) {
initialize<PCAP>(); initialize<PCAP>();
} }

View File

@ -27,6 +27,7 @@ public:
bool close(); bool close();
private: private:
PCAPDLL pcap; PCAPDLL pcap;
device_errorhandler_t err;
char errbuf[PCAP_ERRBUF_SIZE] = { 0 }; char errbuf[PCAP_ERRBUF_SIZE] = { 0 };
neodevice_t& device; neodevice_t& device;
uint8_t deviceMAC[6]; uint8_t deviceMAC[6];

View File

@ -270,7 +270,6 @@ void VCP::readTask() {
case WAIT: { case WAIT: {
auto ret = WaitForSingleObject(overlappedRead.hEvent, 100); auto ret = WaitForSingleObject(overlappedRead.hEvent, 100);
if(ret == WAIT_OBJECT_0) { if(ret == WAIT_OBJECT_0) {
auto err = GetLastError();
if(GetOverlappedResult(handle, &overlappedRead, &bytesRead, FALSE)) { if(GetOverlappedResult(handle, &overlappedRead, &bytesRead, FALSE)) {
readQueue.enqueue_bulk(readbuf, bytesRead); readQueue.enqueue_bulk(readbuf, bytesRead);
state = LAUNCH; state = LAUNCH;
@ -300,8 +299,8 @@ void VCP::writeTask() {
if(WriteFile(handle, writeOp.bytes.data(), (DWORD)writeOp.bytes.size(), nullptr, &overlappedWrite)) if(WriteFile(handle, writeOp.bytes.data(), (DWORD)writeOp.bytes.size(), nullptr, &overlappedWrite))
continue; continue;
auto err = GetLastError(); auto winerr = GetLastError();
if(err == ERROR_IO_PENDING) { if(winerr == ERROR_IO_PENDING) {
state = WAIT; state = WAIT;
} }
else else