Added error checking and removed some redundancy from device isOpen()

This commit is contained in:
EricLiu2000
2019-06-13 16:01:35 -04:00
parent 2806c935f1
commit 965679c370
8 changed files with 73 additions and 35 deletions
+12 -6
View File
@@ -18,11 +18,12 @@ using namespace icsneo;
int Communication::messageCallbackIDCounter = 1;
bool Communication::open() {
if(isOpen)
return true;
if(isOpen()) {
err(APIError::DeviceCurrentlyOpen);
return false;
}
spawnThreads();
isOpen = true;
return impl->open();
}
@@ -38,15 +39,20 @@ void Communication::joinThreads() {
}
bool Communication::close() {
if(!isOpen)
if(!isOpen()) {
err(APIError::DeviceCurrentlyClosed);
return false;
}
isOpen = false;
joinThreads();
return impl->close();
}
bool Communication::isOpen() {
return impl->isOpen();
}
bool Communication::sendPacket(std::vector<uint8_t>& bytes) {
// This is here so that other communication types (like multichannel) can override it
return rawWrite(bytes);