From 6982d519269855e2861f79aa400a74454866273c Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Sat, 7 Nov 2020 21:35:17 +0200
Subject: [PATCH] More documentation the exceptions

---
 SDK/CPP/private/system.cpp                    |  3 ++
 SDK/CPP/public/include/voltu/initialise.hpp   | 31 +++++++++++++++++++
 SDK/CPP/public/include/voltu/system.hpp       |  7 ++++-
 SDK/CPP/public/include/voltu/types/errors.hpp |  3 +-
 SDK/CPP/public/voltu.cpp                      |  6 ++--
 5 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/SDK/CPP/private/system.cpp b/SDK/CPP/private/system.cpp
index b93a4bdc6..84bdbcd40 100644
--- a/SDK/CPP/private/system.cpp
+++ b/SDK/CPP/private/system.cpp
@@ -50,6 +50,9 @@ SystemImpl::~SystemImpl()
 	delete feed_;
 	delete net_;
 	delete root_;
+
+	// FIXME: Check this actually works, can it be restarted? Pool issues?
+	g_isinit = false;
 }
 
 voltu::Version SystemImpl::getVersion() const
diff --git a/SDK/CPP/public/include/voltu/initialise.hpp b/SDK/CPP/public/include/voltu/initialise.hpp
index aeae10f6c..4a6e5b3ff 100644
--- a/SDK/CPP/public/include/voltu/initialise.hpp
+++ b/SDK/CPP/public/include/voltu/initialise.hpp
@@ -11,5 +11,36 @@
 
 namespace voltu
 {
+	/**
+	 * @brief Get core VolTu instance.
+	 * 
+	 * This method returns a smart pointer to a singleton VolTu runtime
+	 * instance and must be the first VolTu call. On any given machine it is
+	 * only sensible and possible to have one runtime instance of VolTu due to
+	 * its use of hardware devices. Multiple real instances are not possible.
+	 * 
+	 * @code
+	 * int main(int argc, char** argv) {
+	 *     auto vtu = voltu::instance();
+	 * 
+	 *     vtu->open("device:camera");
+	 *     ...
+	 * }
+	 * @endcode
+	 * 
+	 * @note
+	 * This method must only be called once.
+	 * 
+	 * @throw voltu::exceptions::LibraryLoadFailed
+	 * If runtime not found or is invalid.
+	 *
+	 * @throw voltu::exceptions::RuntimeVersionMismatch
+	 * If major or minor version does not match the SDK headers.
+	 * 
+	 * @throw voltu::exceptions::RuntimeAlreadyInUse
+	 * If a runtime instance is in use by another application.
+	 * 
+	 * @return Singleton VolTu runtime instance.
+	 */
 	PY_API std::shared_ptr<voltu::System> instance();
 }
diff --git a/SDK/CPP/public/include/voltu/system.hpp b/SDK/CPP/public/include/voltu/system.hpp
index 72e933bf3..6a7e4cd96 100644
--- a/SDK/CPP/public/include/voltu/system.hpp
+++ b/SDK/CPP/public/include/voltu/system.hpp
@@ -40,7 +40,12 @@ public:
 	virtual ~System() = default;
 	
 	/**
-	 * @brief Get the semantic version information.
+	 * @brief Get the runtime version information.
+	 * 
+	 * This method gets the VolTu version of the runtime shared library, which
+	 * may not be the same as the version of the SDK here.
+	 * 
+	 * @see voltu.hpp
 	 * 
 	 * @return Always returns semantic versioning structure.
 	 */
diff --git a/SDK/CPP/public/include/voltu/types/errors.hpp b/SDK/CPP/public/include/voltu/types/errors.hpp
index a69e97630..b1e77accc 100644
--- a/SDK/CPP/public/include/voltu/types/errors.hpp
+++ b/SDK/CPP/public/include/voltu/types/errors.hpp
@@ -32,7 +32,8 @@ VOLTU_EXCEPTION(BadImageChannel, Exception, "Invalid image channel");
 VOLTU_EXCEPTION(NoFrame, Exception, "No frame available");
 VOLTU_EXCEPTION(AlreadyInit, Exception, "VolTu already initialised");
 VOLTU_EXCEPTION(LibraryLoadFailed, Exception, "Could not load VolTu library");
-VOLTU_EXCEPTION(LibraryVersionMismatch, Exception, "Wrong version of library found");
+VOLTU_EXCEPTION(RuntimeVersionMismatch, Exception, "Wrong version of runtime found");
+VOLTU_EXCEPTION(RuntimeAlreadyInUse, Exception, "VolTu runtime already in use");
 VOLTU_EXCEPTION(BadSourceURI, Exception, "Bad source URI");
 VOLTU_EXCEPTION(InvalidFrameObject, Exception, "Invalid Frame object");
 VOLTU_EXCEPTION(InternalRenderError, Exception, "Internal renderer error");
diff --git a/SDK/CPP/public/voltu.cpp b/SDK/CPP/public/voltu.cpp
index 4aef0ba97..bf63ed6b4 100644
--- a/SDK/CPP/public/voltu.cpp
+++ b/SDK/CPP/public/voltu.cpp
@@ -50,6 +50,7 @@ static void unloadLibrary(Library lib)
 
 static std::string locateLibrary()
 {
+	// TODO: Use full paths and find correct versions
 #if defined(WIN32)
 	return "voltu.dll";
 #else
@@ -76,13 +77,14 @@ std::shared_ptr<voltu::System> voltu::instance()
 
 			if (!instance)
 			{
-				throw voltu::exceptions::LibraryLoadFailed();
+				throw voltu::exceptions::RuntimeAlreadyInUse();
 			}
 
+			// FIXME: Perhaps use a C method instead for safety?
 			auto ver = instance->getVersion();
 			if (ver.major != VOLTU_VERSION_MAJOR || ver.minor != VOLTU_VERSION_MINOR)
 			{
-				throw voltu::exceptions::LibraryVersionMismatch();
+				throw voltu::exceptions::RuntimeVersionMismatch();
 			}
 
 			return instance;
-- 
GitLab