[Subplugin] define function to find subplugin
authorJaeyun <jy1210.jung@samsung.com>
Thu, 13 Jun 2019 03:29:02 +0000 (12:29 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 14 Jun 2019 02:30:09 +0000 (11:30 +0900)
1. add definition to find filter/decoder sub-plugins instance.
2. check duplicated name when registering sub-plugin.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
gst/nnstreamer/nnstreamer_plugin_api_decoder.h
gst/nnstreamer/nnstreamer_plugin_api_filter.h
gst/nnstreamer/nnstreamer_subplugin.c
gst/nnstreamer/tensor_decoder/tensordec.c
gst/nnstreamer/tensor_filter/tensor_filter.c

index 93a0c61..81364be 100644 (file)
@@ -60,18 +60,26 @@ typedef struct _GstTensorDecoderDef
 
 /* extern functions for subplugin management, exist in tensor_decoder.c */
 /**
- * @brief decoder's subplugins should call this function to register
- * @param[in] decoder The decoder subplugin instance
+ * @brief Decoder's sub-plugin should call this function to register itself.
+ * @param[in] decoder Decoder sub-plugin to be registered.
+ * @return TRUE if registered. FALSE is failed or duplicated.
  */
-extern gboolean
+extern int
 nnstreamer_decoder_probe (GstTensorDecoderDef * decoder);
 
 /**
- * @brief decoder's subplugin may call this to unregister
- * @param[in] name the name of decoder (modename)
+ * @brief Decoder's sub-plugin may call this to unregister itself.
+ * @param[in] name The name of decoder sub-plugin.
  */
 extern void
-nnstreamer_decoder_exit (const gchar * name);
+nnstreamer_decoder_exit (const char *name);
 
+/**
+ * @brief Find decoder sub-plugin with the name.
+ * @param[in] name The name of decoder sub-plugin.
+ * @return NULL if not found or the sub-plugin object has an error.
+ */
+extern const GstTensorDecoderDef *
+nnstreamer_decoder_find (const char *name);
 
 #endif /* __NNS_PLUGIN_API_DECODER_H__ */
index ab8969f..ca1b2b5 100644 (file)
@@ -139,18 +139,26 @@ typedef struct _GstTensorFilterFramework
 
 /* extern functions for subplugin management, exist in tensor_filter.c */
 /**
- * @brief Filter subplugin should call this to register itself
- * @param[in] tfsp Tensor-Filter Sub-Plugin to be registered
+ * @brief Filter's sub-plugin should call this function to register itself.
+ * @param[in] tfsp Tensor-Filter Sub-Plugin to be registered.
  * @return TRUE if registered. FALSE is failed or duplicated.
  */
 extern int
 nnstreamer_filter_probe (GstTensorFilterFramework * tfsp);
 
 /**
- * @brief filter sub-plugin may call this to unregister itself
- * @param[in] name the name of filter sub-plugin
+ * @brief Filter's sub-plugin may call this to unregister itself.
+ * @param[in] name The name of filter sub-plugin.
  */
 extern void
-nnstreamer_filter_exit (const char * name);
+nnstreamer_filter_exit (const char *name);
+
+/**
+ * @brief Find filter sub-plugin with the name.
+ * @param[in] name The name of filter sub-plugin.
+ * @return NULL if not found or the sub-plugin object has an error.
+ */
+extern const GstTensorFilterFramework *
+nnstreamer_filter_find (const char *name);
 
 #endif /* __NNS_PLUGIN_API_FILTER_H__ */
index b41a592..51adf4a 100644 (file)
@@ -132,6 +132,24 @@ register_subplugin (subpluginType type, const char *name, const void *data)
       return FALSE;
   }
 
+  if (subplugins[type] == NULL) {
+    subplugins[type] =
+        g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
+        _spdata_destroy);
+  } else {
+    subpluginData *data;
+
+    G_LOCK (splock);
+    data = g_hash_table_lookup (subplugins[type], name);
+    G_UNLOCK (splock);
+
+    if (data) {
+      /* already exists */
+      GST_ERROR ("Subplugin %s is already registered.", name);
+      return FALSE;
+    }
+  }
+
   spdata = g_new (subpluginData, 1);
   g_assert (spdata);
 
@@ -139,11 +157,6 @@ register_subplugin (subpluginType type, const char *name, const void *data)
   spdata->data = data;
   spdata->handle = NULL;
 
-  if (subplugins[type] == NULL)
-    subplugins[type] =
-        g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
-        _spdata_destroy);
-
   G_LOCK (splock);
   ret = g_hash_table_insert (subplugins[type], g_strdup (name), spdata);
   G_UNLOCK (splock);
index 6b71d39..969f3c8 100644 (file)
@@ -168,10 +168,11 @@ nnstreamer_decoder_validate (const GstTensorDecoderDef * decoder)
 }
 
 /**
- * @brief decoder's subplugins should call this function to register
- * @param[in] decoder The decoder subplugin instance
+ * @brief Decoder's sub-plugin should call this function to register itself.
+ * @param[in] decoder Decoder sub-plugin to be registered.
+ * @return TRUE if registered. FALSE is failed or duplicated.
  */
-gboolean
+int
 nnstreamer_decoder_probe (GstTensorDecoderDef * decoder)
 {
   g_return_val_if_fail (nnstreamer_decoder_validate (decoder), FALSE);
@@ -179,21 +180,22 @@ nnstreamer_decoder_probe (GstTensorDecoderDef * decoder)
 }
 
 /**
- * @brief decoder's subplugin may call this to unregister
- * @param[in] name the name of decoder (modename)
+ * @brief Decoder's sub-plugin may call this to unregister itself.
+ * @param[in] name The name of decoder sub-plugin.
  */
 void
-nnstreamer_decoder_exit (const gchar * name)
+nnstreamer_decoder_exit (const char *name)
 {
   unregister_subplugin (NNS_SUBPLUGIN_DECODER, name);
 }
 
 /**
- * @brief Find decoders subplugin with the name
- * @param[in] name the name of decoder (modename)
+ * @brief Find decoder sub-plugin with the name.
+ * @param[in] name The name of decoder sub-plugin.
+ * @return NULL if not found or the sub-plugin object has an error.
  */
-static const GstTensorDecoderDef *
-nnstreamer_decoder_find (const gchar * name)
+const GstTensorDecoderDef *
+nnstreamer_decoder_find (const char *name)
 {
   return get_subplugin (NNS_SUBPLUGIN_DECODER, name);
 }
index a1b12d5..5d4f501 100644 (file)
@@ -135,8 +135,8 @@ nnstreamer_filter_validate (const GstTensorFilterFramework * tfsp)
 }
 
 /**
- * @brief Filter subplugin should call this to register itself
- * @param[in] tfsp Tensor-Filter Sub-Plugin to be registered
+ * @brief Filter's sub-plugin should call this function to register itself.
+ * @param[in] tfsp Tensor-Filter Sub-Plugin to be registered.
  * @return TRUE if registered. FALSE is failed or duplicated.
  */
 int
@@ -147,8 +147,8 @@ nnstreamer_filter_probe (GstTensorFilterFramework * tfsp)
 }
 
 /**
- * @brief filter sub-plugin may call this to unregister itself
- * @param[in] name the name of filter sub-plugin
+ * @brief Filter's sub-plugin may call this to unregister itself.
+ * @param[in] name The name of filter sub-plugin.
  */
 void
 nnstreamer_filter_exit (const char *name)
@@ -157,12 +157,12 @@ nnstreamer_filter_exit (const char *name)
 }
 
 /**
- * @brief Find filter sub-plugin with the name
- * @param[in] name The name of tensor_filter sub-plugin
- * @return NULL if not found or the sub-plugin object.
+ * @brief Find filter sub-plugin with the name.
+ * @param[in] name The name of filter sub-plugin.
+ * @return NULL if not found or the sub-plugin object has an error.
  */
-static const GstTensorFilterFramework *
-nnstreamer_filter_find (const gchar * name)
+const GstTensorFilterFramework *
+nnstreamer_filter_find (const char *name)
 {
   return get_subplugin (NNS_SUBPLUGIN_FILTER, name);
 }