From 69b7e5b45a0964f24da9a2271764cb971b4ea9b0 Mon Sep 17 00:00:00 2001 From: EricLiu2000 Date: Wed, 24 Jul 2019 13:40:54 -0400 Subject: [PATCH] Device::GetMessages now returns a pair of {vector, bool} instead of vector --- device/device.cpp | 15 ++++----------- include/icsneo/device/device.h | 3 ++- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/device/device.cpp b/device/device.cpp index e0cc1db..07d80de 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -100,18 +100,11 @@ bool Device::disableMessagePolling() { return ret; } -/** - * Gets all messages from the device with no limit or timeout. - * If it fails, a vector containing a single nullptr is returned. - * Otherwise, returns a vector of shared ptrs to each message. - */ -std::vector> Device::getMessages() { +// Returns a pair of {vector, bool}, where the vector contains shared_ptrs to the returned msgs and the bool is whether or not the call was successful. +std::pair>, bool> Device::getMessages() { std::vector> ret; - // if it fails, ret will always be empty - if(!getMessages(ret)) { - ret.push_back(nullptr); - } - return ret; + bool retBool = getMessages(ret); + return std::make_pair(ret, retBool); } bool Device::getMessages(std::vector>& container, size_t limit, std::chrono::milliseconds timeout) { diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index ace97df..d1fa154 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "icsneo/api/eventmanager.h" #include "icsneo/device/neodevice.h" @@ -53,7 +54,7 @@ public: bool enableMessagePolling(); bool disableMessagePolling(); bool isMessagePollingEnabled() { return messagePollingCallbackID != 0; }; - std::vector> getMessages(); + std::pair>, bool> getMessages(); bool getMessages(std::vector>& container, size_t limit = 0, std::chrono::milliseconds timeout = std::chrono::milliseconds(0)); size_t getCurrentMessageCount() { return pollingContainer.size_approx(); } size_t getPollingMessageLimit() { return pollingMessageLimit; }