Device::GetMessages now returns a pair of {vector, bool} instead of vector

checksum-failure-logging
EricLiu2000 2019-07-24 13:40:54 -04:00
parent 66126b2b61
commit 69b7e5b45a
2 changed files with 6 additions and 12 deletions

View File

@ -100,18 +100,11 @@ bool Device::disableMessagePolling() {
return ret; return ret;
} }
/** // 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.
* Gets all messages from the device with no limit or timeout. std::pair<std::vector<std::shared_ptr<Message>>, bool> Device::getMessages() {
* If it fails, a vector containing a single nullptr is returned.
* Otherwise, returns a vector of shared ptrs to each message.
*/
std::vector<std::shared_ptr<Message>> Device::getMessages() {
std::vector<std::shared_ptr<Message>> ret; std::vector<std::shared_ptr<Message>> ret;
// if it fails, ret will always be empty bool retBool = getMessages(ret);
if(!getMessages(ret)) { return std::make_pair(ret, retBool);
ret.push_back(nullptr);
}
return ret;
} }
bool Device::getMessages(std::vector<std::shared_ptr<Message>>& container, size_t limit, std::chrono::milliseconds timeout) { bool Device::getMessages(std::vector<std::shared_ptr<Message>>& container, size_t limit, std::chrono::milliseconds timeout) {

View File

@ -3,6 +3,7 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <utility>
#include <cstring> #include <cstring>
#include "icsneo/api/eventmanager.h" #include "icsneo/api/eventmanager.h"
#include "icsneo/device/neodevice.h" #include "icsneo/device/neodevice.h"
@ -53,7 +54,7 @@ public:
bool enableMessagePolling(); bool enableMessagePolling();
bool disableMessagePolling(); bool disableMessagePolling();
bool isMessagePollingEnabled() { return messagePollingCallbackID != 0; }; bool isMessagePollingEnabled() { return messagePollingCallbackID != 0; };
std::vector<std::shared_ptr<Message>> getMessages(); std::pair<std::vector<std::shared_ptr<Message>>, bool> getMessages();
bool getMessages(std::vector<std::shared_ptr<Message>>& container, size_t limit = 0, std::chrono::milliseconds timeout = std::chrono::milliseconds(0)); bool getMessages(std::vector<std::shared_ptr<Message>>& container, size_t limit = 0, std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
size_t getCurrentMessageCount() { return pollingContainer.size_approx(); } size_t getCurrentMessageCount() { return pollingContainer.size_approx(); }
size_t getPollingMessageLimit() { return pollingMessageLimit; } size_t getPollingMessageLimit() { return pollingMessageLimit; }