[Conf] add option to enable symbolic link
authorJaeyun <jy1210.jung@samsung.com>
Mon, 13 May 2019 06:42:39 +0000 (15:42 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 27 May 2019 05:03:49 +0000 (14:03 +0900)
In nnstreamer ini, add new option to enable/disable symbolic link.
Add internal function to check a library is available with symlink option.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
gst/nnstreamer/nnstreamer_conf.c
gst/nnstreamer/nnstreamer_conf.h
gst/nnstreamer/nnstreamer_subplugin.c
gst/nnstreamer/tensor_filter/tensor_filter_custom.c
meson.build
meson_options.txt
nnstreamer.ini.in
packaging/nnstreamer.spec

index 6e0690a..2d6add9 100644 (file)
@@ -39,6 +39,7 @@ typedef struct
 {
   gboolean loaded;            /**< TRUE if loaded at least once */
   gboolean enable_envvar;     /**< TRUE to parse env variables */
+  gboolean enable_symlink;    /**< TRUE to allow symbolic link file */
 
   gchar *conffile;            /**< Location of conf file. */
 
@@ -117,7 +118,7 @@ _validate_file (nnsconf_type_path type, const gchar * fullpath)
   if (!g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
     return FALSE;
   /* ignore symbol link file */
-  if (g_file_test (fullpath, G_FILE_TEST_IS_SYMLINK))
+  if (!conf.enable_symlink && g_file_test (fullpath, G_FILE_TEST_IS_SYMLINK))
     return FALSE;
   /** @todo how to validate with nnsconf type. */
   return TRUE;
@@ -282,6 +283,10 @@ nnsconf_loadconf (gboolean force_reload)
     conf.enable_envvar = _parse_bool_string (value, FALSE);
     g_free (value);
 
+    value = g_key_file_get_string (key_file, "common", "enable_symlink", NULL);
+    conf.enable_symlink = _parse_bool_string (value, FALSE);
+    g_free (value);
+
     conf.pathFILTERS[1] =
         g_key_file_get_string (key_file, "filter", "filters", NULL);
     conf.pathDECODERS[1] =
@@ -370,6 +375,17 @@ nnsconf_get_fullpath (const gchar * subpluginname, nnsconf_type_path type)
 }
 
 /**
+ * @brief Public function to validate sub-plugin library is available.
+ */
+gboolean
+nnsconf_validate_file (nnsconf_type_path type, const gchar * fullpath)
+{
+  nnsconf_loadconf (FALSE);
+
+  return _validate_file (type, fullpath);
+}
+
+/**
  * @brief Get sub-plugin's name prefix.
  * @param[in] type The type (FILTERS/DECODERS/CUSTOM_FILTERS)
  * @return Predefined prefix string for given type.
index a78d3f4..4d0469a 100644 (file)
@@ -107,6 +107,15 @@ extern const gchar *
 nnsconf_get_fullpath (const gchar * subpluginname, nnsconf_type_path type);
 
 /**
+ * @brief Public function to validate sub-plugin library is available.
+ * @param[in] type The type (FILTERS/DECODERS/CUSTOM_FILTERS)
+ * @param[in] fullpath The full path to the file.
+ * @return True if the file is regular and can be added to the list.
+ */
+extern gboolean
+nnsconf_validate_file (nnsconf_type_path type, const gchar * fullpath);
+
+/**
  * @brief Get sub-plugin's name prefix.
  * @param[in] type The type (FILTERS/DECODERS/CUSTOM_FILTERS)
  * @return Predefined prefix string for given type.
index 51056d7..103c8b7 100644 (file)
@@ -76,10 +76,7 @@ get_subplugin (subpluginType type, const char *name)
     /* Search and register if found with the conf */
     const gchar *fullpath = nnsconf_get_fullpath (name, type);
 
-    /**
-     * @todo Consider to add option to open symbolic link file and version-specified library name.
-     */
-    if (fullpath == NULL || g_file_test (fullpath, G_FILE_TEST_IS_SYMLINK))
+    if (!nnsconf_validate_file (type, fullpath))
       goto error;               /* No Such Thing !!! */
 
     G_UNLOCK (splock);
index 9a8f47d..4b57c51 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "tensor_filter_custom.h"
 #include "nnstreamer_plugin_api_filter.h"
+#include "nnstreamer_conf.h"
 
 void init_filter_custom (void) __attribute__ ((constructor));
 void fini_filter_custom (void) __attribute__ ((destructor));
@@ -70,11 +71,8 @@ custom_loadlib (const GstTensorFilterProperties * prop, void **private_data)
     return -1;
   }
 
-  /**
-   * @todo Consider to add option to open symbolic link file and version-specified library name.
-   */
-  if (g_file_test (prop->model_file, G_FILE_TEST_IS_SYMLINK)) {
-    /* symbolic link */
+  if (!nnsconf_validate_file (NNSCONF_PATH_CUSTOM_FILTERS, prop->model_file)) {
+    /* Cannot load the library */
     return -1;
   }
 
index 063d3c2..5748dde 100644 (file)
@@ -202,6 +202,7 @@ if get_option('enable-test')
   nnstreamer_test_conf.merge_from(nnstreamer_conf)
 
   nnstreamer_test_conf.set('ENABLE_ENV_VAR', true)
+  nnstreamer_test_conf.set('ENABLE_SYMBOLIC_LINK', false)
   nnstreamer_test_conf.set('TF_MEM_OPTMZ', false)
 
   # meson 0.50 supports install argument in configure_file()
@@ -222,6 +223,7 @@ nnstreamer_install_conf = configuration_data()
 nnstreamer_install_conf.merge_from(nnstreamer_conf)
 
 nnstreamer_install_conf.set('ENABLE_ENV_VAR', get_option('enable-env-var'))
+nnstreamer_install_conf.set('ENABLE_SYMBOLIC_LINK', get_option('enable-symbolic-link'))
 nnstreamer_install_conf.set('TF_MEM_OPTMZ', get_option('enable-tensorflow-mem-optmz'))
 
 # Install .ini
index 2430dab..4ba8066 100644 (file)
@@ -8,5 +8,6 @@ option('install-example', type: 'boolean', value: false)
 option('disable-video-support', type: 'boolean', value: false)
 option('disable-audio-support', type: 'boolean', value: false)
 option('enable-env-var', type: 'boolean', value: true)
+option('enable-symbolic-link', type: 'boolean', value: true)
 option('enable-tizen-capi', type: 'boolean', value: false)
 option('enable-python', type: 'boolean', value: true)
index 34a957a..04fac0e 100644 (file)
@@ -2,6 +2,7 @@
 # Please be informed that, configured ini file should be in RO partition for the release binary.
 [common]
 enable_envvar=@ENABLE_ENV_VAR@
+enable_symlink=@ENABLE_SYMBOLIC_LINK@
 
 [filter]
 filters=@SUBPLUGIN_INSTALL_PREFIX@/filters/
index 275aee6..3685010 100644 (file)
@@ -179,7 +179,7 @@ enable_tf=true
 enable_tf=false
 %endif
 
-meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} --libdir=%{_libdir} --bindir=%{nnstexampledir} --includedir=%{_includedir} -Dinstall-example=true -Denable-tensorflow=${enable_tf} %{api} -Denable-env-var=false build
+meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} --libdir=%{_libdir} --bindir=%{nnstexampledir} --includedir=%{_includedir} -Dinstall-example=true -Denable-tensorflow=${enable_tf} %{api} -Denable-env-var=false -Denable-symbolic-link=false build
 
 ninja -C build %{?_smp_mflags}