From a60fa0b390626c4fbbea1ca03c47d5399c84cc50 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Mon, 9 Nov 2020 19:41:10 +0200 Subject: [PATCH] Use more exceptions in SDK --- SDK/CPP/CMakeLists.txt | 2 +- SDK/CPP/private/room_impl.cpp | 7 ++++++- SDK/CPP/private/room_impl.hpp | 2 +- SDK/CPP/private/system.cpp | 5 +++++ SDK/CPP/public/include/voltu/room.hpp | 2 +- SDK/CPP/public/include/voltu/types/errors.hpp | 1 + SDK/CPP/public/include/voltu/voltu.hpp | 2 +- 7 files changed, 16 insertions(+), 5 deletions(-) diff --git a/SDK/CPP/CMakeLists.txt b/SDK/CPP/CMakeLists.txt index 472ac9eb1..123671c2b 100644 --- a/SDK/CPP/CMakeLists.txt +++ b/SDK/CPP/CMakeLists.txt @@ -43,7 +43,7 @@ ExternalProject_Add( BINARY_DIR ${SDK_BINARY_DIR} INSTALL_COMMAND "" BUILD_ALWAYS true - CMAKE_ARGS -DOpenCV_DIR=${OpenCV_DIR} + CMAKE_ARGS -DOpenCV_DIR=${OpenCV_DIR} -DWITH_PYTHON=True ) if (BUILD_TESTS) diff --git a/SDK/CPP/private/room_impl.cpp b/SDK/CPP/private/room_impl.cpp index 76ab1b92b..65825d515 100644 --- a/SDK/CPP/private/room_impl.cpp +++ b/SDK/CPP/private/room_impl.cpp @@ -16,7 +16,7 @@ RoomImpl::~RoomImpl() if (filter_) filter_->remove(); } -bool RoomImpl::waitNextFrame(int64_t timeout) +bool RoomImpl::waitNextFrame(int64_t timeout, bool except) { if (!filter_) { @@ -40,10 +40,15 @@ bool RoomImpl::waitNextFrame(int64_t timeout) return last_read_ < last_seen_; }); + if (except && last_read_ >= last_seen_) + { + throw voltu::exceptions::Timeout(); + } return last_read_ < last_seen_; } else if (timeout == 0) { + if (except) throw voltu::exceptions::Timeout(); return false; } else diff --git a/SDK/CPP/private/room_impl.hpp b/SDK/CPP/private/room_impl.hpp index be8516a63..67d44474d 100644 --- a/SDK/CPP/private/room_impl.hpp +++ b/SDK/CPP/private/room_impl.hpp @@ -16,7 +16,7 @@ public: ~RoomImpl() override; - bool waitNextFrame(int64_t) override; + bool waitNextFrame(int64_t, bool except) override; voltu::FramePtr getFrame() override; diff --git a/SDK/CPP/private/system.cpp b/SDK/CPP/private/system.cpp index 84bdbcd40..f711a3783 100644 --- a/SDK/CPP/private/system.cpp +++ b/SDK/CPP/private/system.cpp @@ -87,6 +87,11 @@ std::list<voltu::RoomId> SystemImpl::listRooms() voltu::RoomPtr SystemImpl::getRoom(voltu::RoomId id) { + if (feed_->getURI(id).size() == 0) + { + throw voltu::exceptions::InvalidRoomId(); + } + auto s = std::make_shared<voltu::internal::RoomImpl>(feed_); s->addFrameSet(id); return s; diff --git a/SDK/CPP/public/include/voltu/room.hpp b/SDK/CPP/public/include/voltu/room.hpp index 87f0f070c..f2578236c 100644 --- a/SDK/CPP/public/include/voltu/room.hpp +++ b/SDK/CPP/public/include/voltu/room.hpp @@ -70,7 +70,7 @@ public: * @param timeout Millisecond timeout, or 0 or -1. * @return True if a new unseen frame is available. */ - PY_API virtual bool waitNextFrame(int64_t timeout) = 0; + PY_API virtual bool waitNextFrame(int64_t timeout, bool except=false) = 0; /** * @brief Check if a new frame is available. diff --git a/SDK/CPP/public/include/voltu/types/errors.hpp b/SDK/CPP/public/include/voltu/types/errors.hpp index b1e77accc..b42964ef8 100644 --- a/SDK/CPP/public/include/voltu/types/errors.hpp +++ b/SDK/CPP/public/include/voltu/types/errors.hpp @@ -47,6 +47,7 @@ VOLTU_EXCEPTION(NotImplemented, Exception, "Functionality not implemented"); VOLTU_EXCEPTION(ReadOnly, Exception, "Read only, write not allowed"); VOLTU_EXCEPTION(WriteOnly, Exception, "Write only, read not allowed"); VOLTU_EXCEPTION(IncompatibleOperation, Exception, "The input data and operator are incompatible"); +VOLTU_EXCEPTION(Timeout, Exception, "Request timed out"); } } diff --git a/SDK/CPP/public/include/voltu/voltu.hpp b/SDK/CPP/public/include/voltu/voltu.hpp index a2c4c0a14..d3e1413b4 100644 --- a/SDK/CPP/public/include/voltu/voltu.hpp +++ b/SDK/CPP/public/include/voltu/voltu.hpp @@ -8,7 +8,7 @@ // Bump these for each release #define VOLTU_VERSION_MAJOR 0 // For API incompatible changes -#define VOLTU_VERSION_MINOR 2 // For binary compatibility and extensions +#define VOLTU_VERSION_MINOR 3 // For binary compatibility and extensions #define VOLTU_VERSION_PATCH 0 // Binary compatible internal fixes #define VOLTU_VERSION ((VOLTU_VERSION_MAJOR*10000) + (VOLTU_VERSION_MINOR*100) + VOLTU_VERSION_PATCH) -- GitLab