Doxygen Book
nnstreamer_conf.c File Reference

NNStreamer Configuration (conf file, env-var) Management. More...

#include <string.h>
#include <glib.h>
#include "nnstreamer_log.h"
#include "nnstreamer_conf.h"
#include "nnstreamer_subplugin.h"
Include dependency graph for nnstreamer_conf.c:

Go to the source code of this file.

Classes

struct  subplugin_conf
 
struct  confdata
 
struct  vstr_helper
 Data structure for _g_list_foreach_vstr_helper. More...
 
struct  dump_buf
 

Macros

#define NNSTREAMER_PREFIX_DECODER   "libnnstreamer_decoder_"
 
#define NNSTREAMER_PREFIX_FILTER   "libnnstreamer_filter_"
 
#define NNSTREAMER_PREFIX_CUSTOMFILTERS   ""
 
#define NNSTREAMER_PREFIX_CONVERTER   "libnnstreamer_converter_"
 
#define NNSTREAMER_PREFIX_TRAINER   "libnnstreamer_trainer_"
 
#define STR_BOOL(x)   ((x) ? "TRUE" : "FALSE")
 

Enumerations

enum  conf_sources {
  CONF_SOURCE_ENVVAR = 0, CONF_SOURCE_INI = 1, CONF_SOURCE_HARDCODE = 2, CONF_SOURCE_EXTRA_CONF = 3,
  CONF_SOURCE_END
}
 

Functions

static gboolean _parse_bool_string (const gchar *strval, gboolean def)
 Parse string to get boolean value. More...
 
static gchar * _strdup_getenv (const gchar *name)
 Private function to get strdup-ed env-var if it's valid. Otherwise, NULL. More...
 
static gboolean _validate_file (nnsconf_type_path type, const gchar *fullpath)
 Private function to validate .so file can be added to the list. More...
 
static gboolean _get_filenames (nnsconf_type_path type, const gchar *dir, GSList **listF, GSList **listN, guint *counter)
 Private function to fill in ".so/.dylib list" with fullpath-filenames in a directory. More...
 
static gboolean _get_subplugin_with_type (nnsconf_type_path type, gchar ***name, gchar ***filepath)
 Private function to get sub-plugins list with type. More...
 
static void _g_list_foreach_vstr_helper (gpointer data, gpointer user_data)
 Private function to help convert linked-list to vstr with foreach @data The element data of linked-list @user_data The struct to fill in vstr. More...
 
static void _fill_in_vstr (gchar ***fullpath_vstr, gchar ***name_vstr, gchar *searchpath[CONF_SOURCE_END], nnsconf_type_path type)
 Private function to fill in vstr. More...
 
static void _fill_subplugin_path (confdata *cdata, GKeyFile *key_file, conf_sources src)
 Private function to fill subplugin path. More...
 
gboolean nnsconf_loadconf (gboolean force_reload)
 Public function defined in the header. More...
 
const gchar * nnsconf_get_fullpath (const gchar *subpluginname, nnsconf_type_path type)
 Public function defined in the header. More...
 
gboolean nnsconf_validate_file (nnsconf_type_path type, const gchar *fullpath)
 Public function to validate sub-plugin library is available. More...
 
const gchar * nnsconf_get_subplugin_name_prefix (nnsconf_type_path type)
 Get sub-plugin's name prefix. More...
 
guint nnsconf_get_subplugin_info (nnsconf_type_path type, subplugin_info_s *info)
 Public function to get the list of sub-plugins name and path. More...
 
gchar * nnsconf_get_custom_value_string (const gchar *group, const gchar *key)
 Public function defined in the header. More...
 
gboolean nnsconf_get_custom_value_bool (const gchar *group, const gchar *key, gboolean def)
 Public function defined in the header. More...
 
void nnsconf_dump (gchar *str, gulong size)
 Print out configurations. More...
 
static void _foreach_custom_property (GQuark key_id, gpointer data, gpointer user_data)
 foreach callback for custom property More...
 
void nnsconf_subplugin_dump (gchar *str, gulong size)
 Print out the information of registered sub-plugins. More...
 

Variables

static const gchar * NNSTREAMER_ENVVAR [NNSCONF_PATH_END]
 
static const gchar * NNSTREAMER_PATH [NNSCONF_PATH_END]
 
static const gchar * subplugin_prefixes []
 
static confdata conf = { 0 }
 
static GHashTable * custom_table = NULL
 Internal cache for the custom key-values. More...
 

Detailed Description

NNStreamer Configuration (conf file, env-var) Management.

NNStreamer Configurations / Environmental Variable Manager. Copyright (C) 2018 MyungJoo Ham myung.nosp@m.joo..nosp@m.ham@s.nosp@m.amsu.nosp@m.ng.co.nosp@m.m

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; version 2.1 of the License.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.

Date
26 Nov 2018
See also
https://github.com/nnstreamer/nnstreamer
Author
MyungJoo Ham myung.nosp@m.joo..nosp@m.ham@s.nosp@m.amsu.nosp@m.ng.co.nosp@m.m
Bug:
No known bugs except for NYI items

Definition in file nnstreamer_conf.c.

Macro Definition Documentation

◆ NNSTREAMER_PREFIX_CONVERTER

#define NNSTREAMER_PREFIX_CONVERTER   "libnnstreamer_converter_"

Definition at line 42 of file nnstreamer_conf.c.

◆ NNSTREAMER_PREFIX_CUSTOMFILTERS

#define NNSTREAMER_PREFIX_CUSTOMFILTERS   ""

Definition at line 41 of file nnstreamer_conf.c.

◆ NNSTREAMER_PREFIX_DECODER

#define NNSTREAMER_PREFIX_DECODER   "libnnstreamer_decoder_"

Note that users still can place their custom filters anywhere if they designate them with the full path.

Definition at line 39 of file nnstreamer_conf.c.

◆ NNSTREAMER_PREFIX_FILTER

#define NNSTREAMER_PREFIX_FILTER   "libnnstreamer_filter_"

Definition at line 40 of file nnstreamer_conf.c.

◆ NNSTREAMER_PREFIX_TRAINER

#define NNSTREAMER_PREFIX_TRAINER   "libnnstreamer_trainer_"

Definition at line 43 of file nnstreamer_conf.c.

◆ STR_BOOL

#define STR_BOOL (   x)    ((x) ? "TRUE" : "FALSE")

Definition at line 622 of file nnstreamer_conf.c.

Enumeration Type Documentation

◆ conf_sources

Enumerator
CONF_SOURCE_ENVVAR 
CONF_SOURCE_INI 
CONF_SOURCE_HARDCODE 
CONF_SOURCE_EXTRA_CONF 

path from extra config file

CONF_SOURCE_END 

Definition at line 73 of file nnstreamer_conf.c.

Function Documentation

◆ _fill_in_vstr()

static void _fill_in_vstr ( gchar ***  fullpath_vstr,
gchar ***  name_vstr,
gchar *  searchpath[CONF_SOURCE_END],
nnsconf_type_path  type 
)
static

Private function to fill in vstr.

Definition at line 280 of file nnstreamer_conf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _fill_subplugin_path()

static void _fill_subplugin_path ( confdata cdata,
GKeyFile *  key_file,
conf_sources  src 
)
static

Private function to fill subplugin path.

Definition at line 326 of file nnstreamer_conf.c.

Here is the caller graph for this function:

◆ _foreach_custom_property()

static void _foreach_custom_property ( GQuark  key_id,
gpointer  data,
gpointer  user_data 
)
static

foreach callback for custom property

Definition at line 681 of file nnstreamer_conf.c.

Here is the caller graph for this function:

◆ _g_list_foreach_vstr_helper()

static void _g_list_foreach_vstr_helper ( gpointer  data,
gpointer  user_data 
)
static

Private function to help convert linked-list to vstr with foreach @data The element data of linked-list @user_data The struct to fill in vstr.

library error? internal logic error?

Definition at line 268 of file nnstreamer_conf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _get_filenames()

static gboolean _get_filenames ( nnsconf_type_path  type,
const gchar *  dir,
GSList **  listF,
GSList **  listN,
guint *  counter 
)
static

Private function to fill in ".so/.dylib list" with fullpath-filenames in a directory.

Parameters
[in]typeconf type to scan.
[in]dirDirectory to be searched.
[in/out]listF The fullpath list to be updated.
[in/out]listN The name list to be updated.
[in/out]counter increased by the number of appended elements.
Returns
True if successfully updated.
Todo:
This assumes .so/.dylib for all sub plugins. Support Windows!

Definition at line 183 of file nnstreamer_conf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _get_subplugin_with_type()

static gboolean _get_subplugin_with_type ( nnsconf_type_path  type,
gchar ***  name,
gchar ***  filepath 
)
static

Private function to get sub-plugins list with type.

Definition at line 229 of file nnstreamer_conf.c.

Here is the caller graph for this function:

◆ _parse_bool_string()

static gboolean _parse_bool_string ( const gchar *  strval,
gboolean  def 
)
static

Parse string to get boolean value.

Definition at line 115 of file nnstreamer_conf.c.

Here is the caller graph for this function:

◆ _strdup_getenv()

static gchar* _strdup_getenv ( const gchar *  name)
static

Private function to get strdup-ed env-var if it's valid. Otherwise, NULL.

Return values
strdup-edenv-var value
Parameters
[in]nameEnvironmental variable name
Todo:
Evaluate if we need to use secure_getenv() here (and compatible with other OS

Definition at line 143 of file nnstreamer_conf.c.

Here is the caller graph for this function:

◆ _validate_file()

static gboolean _validate_file ( nnsconf_type_path  type,
const gchar *  fullpath 
)
static

Private function to validate .so file can be added to the list.

Todo:
how to validate with nnsconf type.

Definition at line 158 of file nnstreamer_conf.c.

Here is the caller graph for this function:

◆ nnsconf_dump()

void nnsconf_dump ( gchar *  str,
gulong  size 
)

Print out configurations.

NNStreamer configuration dump as string.

Todo:
Add more configuration values to dump.

Definition at line 628 of file nnstreamer_conf.c.

Here is the call graph for this function:

◆ nnsconf_get_custom_value_bool()

gboolean nnsconf_get_custom_value_bool ( const gchar *  group,
const gchar *  key,
gboolean  def 
)

Public function defined in the header.

Get the custom configuration value from .ini and envvar. @detail For predefined configurations defined in this header, use the given enum for faster configuration processing. For custom configurations not defined in this header, you may use this API to access your own custom configurations. Configuration values may be loaded only once during runtime, thus, if the values are changed in run-time, the changes are not guaranteed to be reflected. The ENVVAR is supposed to be NNSTREAMER_${group}_${key}, which has higher priority than the .ini configuration. Be careful not to use special characters in group name ([, ], _).

Note
This function is included in nnstreamer internal header for native APIs. When changing the declaration, you should update the internal header (nnstreamer_internal.h).

Definition at line 609 of file nnstreamer_conf.c.

Here is the call graph for this function:

◆ nnsconf_get_custom_value_string()

gchar* nnsconf_get_custom_value_string ( const gchar *  group,
const gchar *  key 
)

Public function defined in the header.

Get the custom configuration value from .ini and envvar. @detail For predefined configurations defined in this header, use the given enum for faster configuration processing. For custom configurations not defined in this header, you may use this API to access your own custom configurations. Configuration values may be loaded only once during runtime, thus, if the values are changed in run-time, the changes are not guaranteed to be reflected. The ENVVAR is supposed to be NNSTREAMER_${group}_${key}, which has higher priority than the .ini configuration. Be careful not to use special characters in group name ([, ], _).

Note
This function is included in nnstreamer internal header for native APIs. When changing the declaration, you should update the internal header (nnstreamer_internal.h).

Internal lib error? out-of-memory?

Definition at line 557 of file nnstreamer_conf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nnsconf_get_fullpath()

const gchar* nnsconf_get_fullpath ( const gchar *  subpluginname,
nnsconf_type_path  type 
)

Public function defined in the header.

Get the configured paths for the type with sub-plugin name.

Definition at line 483 of file nnstreamer_conf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nnsconf_get_subplugin_info()

guint nnsconf_get_subplugin_info ( nnsconf_type_path  type,
subplugin_info_s info 
)

Public function to get the list of sub-plugins name and path.

Returns
total number of sub-plugins for given type
Note
DO NOT free sub-plugins info

Definition at line 528 of file nnstreamer_conf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nnsconf_get_subplugin_name_prefix()

const gchar* nnsconf_get_subplugin_name_prefix ( nnsconf_type_path  type)

Get sub-plugin's name prefix.

Parameters
[in]typeThe type (FILTERS/DECODERS/CUSTOM_FILTERS)
Returns
Predefined prefix string for given type.

Definition at line 516 of file nnstreamer_conf.c.

◆ nnsconf_loadconf()

gboolean nnsconf_loadconf ( gboolean  force_reload)

Public function defined in the header.

Load the .ini file.

if it's not Tizen, configuration from env-var has a higher priority

Priority of reading a conf file 1) read from NNSTREAMER_CONF_FILE 2) read from NNSTREAMER_DEFAULT_CONF_FILE 3) read from env-var

default value of 'sysconfdir' in meson is 'etc'

Internal lib error? out-of-memory?

Internal lib error? out-of-memory?

Failed to get the configuration. Note that Android API does not use the configuration.

Definition at line 342 of file nnstreamer_conf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nnsconf_subplugin_dump()

void nnsconf_subplugin_dump ( gchar *  str,
gulong  size 
)

Print out the information of registered sub-plugins.

Definition at line 695 of file nnstreamer_conf.c.

Here is the call graph for this function:

◆ nnsconf_validate_file()

gboolean nnsconf_validate_file ( nnsconf_type_path  type,
const gchar *  fullpath 
)

Public function to validate sub-plugin library is available.

Parameters
[in]typeThe type (FILTERS/DECODERS/CUSTOM_FILTERS)
[in]fullpathThe full path to the file.
Returns
True if the file is regular and can be added to the list.

Definition at line 503 of file nnstreamer_conf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ conf

confdata conf = { 0 }
static

Definition at line 109 of file nnstreamer_conf.c.

◆ custom_table

GHashTable* custom_table = NULL
static

Internal cache for the custom key-values.

Definition at line 549 of file nnstreamer_conf.c.

◆ NNSTREAMER_ENVVAR

const gchar* NNSTREAMER_ENVVAR[NNSCONF_PATH_END]
static
Initial value:
= {
[NNSCONF_PATH_FILTERS] = "NNSTREAMER_FILTERS",
[NNSCONF_PATH_DECODERS] = "NNSTREAMER_DECODERS",
[NNSCONF_PATH_CUSTOM_FILTERS] = "NNSTREAMER_CUSTOMFILTERS",
[NNSCONF_PATH_CONVERTERS] = "NNSTREAMER_CONVERTERS",
[NNSCONF_PATH_TRAINERS] = "NNSTREAMER_TRAINERS"
}

Definition at line 47 of file nnstreamer_conf.c.

◆ NNSTREAMER_PATH

const gchar* NNSTREAMER_PATH[NNSCONF_PATH_END]
static
Initial value:
= {
[NNSCONF_PATH_FILTERS] = "/usr/lib/nnstreamer/filters/",
[NNSCONF_PATH_DECODERS] = "/usr/lib/nnstreamer/decoders/",
[NNSCONF_PATH_CUSTOM_FILTERS] = "/usr/lib/nnstreamer/customfilters/",
[NNSCONF_PATH_CONVERTERS] = "/usr/lib/nnstreamer/converters/",
[NNSCONF_PATH_TRAINERS] = "/usr/lib/nnstreamer/trainers/"
}

Definition at line 55 of file nnstreamer_conf.c.

◆ subplugin_prefixes

NNSTREAMER_PREFIX_FILTER
#define NNSTREAMER_PREFIX_FILTER
Definition: nnstreamer_conf.c:40
NNSTREAMER_PREFIX_TRAINER
#define NNSTREAMER_PREFIX_TRAINER
Definition: nnstreamer_conf.c:43
NNSCONF_PATH_CONVERTERS
@ NNSCONF_PATH_CONVERTERS
Definition: nnstreamer_conf.h:68
NNSCONF_PATH_FILTERS
@ NNSCONF_PATH_FILTERS
Definition: nnstreamer_conf.h:64
NNSCONF_PATH_EASY_CUSTOM_FILTERS
@ NNSCONF_PATH_EASY_CUSTOM_FILTERS
Definition: nnstreamer_conf.h:67
NNSCONF_PATH_END
@ NNSCONF_PATH_END
Definition: nnstreamer_conf.h:71
NNSCONF_PATH_CUSTOM_FILTERS
@ NNSCONF_PATH_CUSTOM_FILTERS
Definition: nnstreamer_conf.h:66
NNSTREAMER_PREFIX_DECODER
#define NNSTREAMER_PREFIX_DECODER
Definition: nnstreamer_conf.c:39
NNSCONF_PATH_TRAINERS
@ NNSCONF_PATH_TRAINERS
Definition: nnstreamer_conf.h:69
NNSTREAMER_PREFIX_CUSTOMFILTERS
#define NNSTREAMER_PREFIX_CUSTOMFILTERS
Definition: nnstreamer_conf.c:41
NNSCONF_PATH_DECODERS
@ NNSCONF_PATH_DECODERS
Definition: nnstreamer_conf.h:65
NNSTREAMER_PREFIX_CONVERTER
#define NNSTREAMER_PREFIX_CONVERTER
Definition: nnstreamer_conf.c:42