[Filter/C++] Do not go further when failed to open NN framework
authorWook Song <wook16.song@samsung.com>
Wed, 10 Jun 2020 07:54:43 +0000 (16:54 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 10 Jun 2020 11:02:35 +0000 (20:02 +0900)
This patch adds more catch blocks that return negative error code in
cpp_open so that the execution does not go further when it failed to
open NN framework.

Signed-off-by: Wook Song <wook16.song@samsung.com>
gst/nnstreamer/tensor_filter/tensor_filter_support_cc.cc

index 877f761..9933f4b 100644 (file)
@@ -32,6 +32,9 @@
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
+#include <nnstreamer_log.h>
+
+#include <system_error>
 
 #define __NO_ANONYMOUS_NESTED_STRUCT
 #include <nnstreamer_plugin_api_filter.h>
@@ -46,6 +49,11 @@ namespace nnstreamer {
  ******************************************************/
 
 #define _SANITY_CHECK (0xFACE217714DEADE7ULL)
+#define _RETURN_ERR_WITH_MSG(c, m) \
+  do { \
+    nns_loge ("%s", m); \
+    return c; \
+  } while (0);
 
 /**
  * @brief C tensor-filter wrapper callback function, "open"
@@ -66,8 +74,17 @@ int tensor_filter_subplugin::cpp_open (const GstTensorFilterProperties * prop,
   tensor_filter_subplugin &obj = sp->getEmptyInstance();
   try {
     obj.configure_instance (prop);
+  } catch (const std::invalid_argument & e) {
+    _RETURN_ERR_WITH_MSG (-EINVAL, e.what());
+  } catch (const std::system_error & e) {
+    _RETURN_ERR_WITH_MSG (e.code().value() * -1, e.what());
+  } catch (const std::runtime_error & e) {
+    /** @todo return different error codes according to exceptions */
+    _RETURN_ERR_WITH_MSG (-1, e.what());
   } catch (const std::exception & e) {
-    /* @todo Write exception handlers. */
+    /** @todo Write exception handlers. */
+    /** @todo return different error codes according to exceptions */
+    _RETURN_ERR_WITH_MSG (-1, e.what());
   }
 
   /* 3. Mark that this is not a representative (found by nnstreamer_filter_find) empty object */