]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
config: add universal fcns to access to global variables
authorJaroslav Kysela <perex@perex.cz>
Fri, 13 Feb 2015 15:01:37 +0000 (16:01 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 11 Mar 2015 20:41:12 +0000 (21:41 +0100)
src/config.c
src/config.h

index 890e212f32877888be1a42937285fcaf25194559..9eac90ecd747c42301a36441191ebed28b2afabc 100644 (file)
@@ -1442,8 +1442,14 @@ htsmsg_t *config_get_all ( void )
   return htsmsg_copy(config);
 }
 
-static int
-_config_set_str ( const char *fld, const char *val )
+const char *
+config_get_str ( const char *fld )
+{
+  return htsmsg_get_str(config, fld);
+}
+
+int
+config_set_str ( const char *fld, const char *val )
 {
   const char *c = htsmsg_get_str(config, fld);
   if (!c || strcmp(c, val)) {
@@ -1454,6 +1460,26 @@ _config_set_str ( const char *fld, const char *val )
   return 0;
 }
 
+int
+config_get_int ( const char *fld, int deflt )
+{
+  return htsmsg_get_s32_or_default(config, fld, deflt);
+}
+
+int
+config_set_int ( const char *fld, int val )
+{
+  const char *c = htsmsg_get_str(config, fld);
+  char buf[16];
+  snprintf(buf, sizeof(buf), "%d", val);
+  if (!c || strcmp(c, buf)) {
+    if (c) htsmsg_delete_field(config, fld);
+    htsmsg_add_s32(config, fld, val);
+    return 1;
+  }
+  return 0;
+}
+
 const char *config_get_language ( void )
 {
   return htsmsg_get_str(config, "language");
@@ -1461,7 +1487,7 @@ const char *config_get_language ( void )
 
 int config_set_language ( const char *lang )
 {
-  return _config_set_str("language", lang);
+  return config_set_str("language", lang);
 }
 
 const char *config_get_muxconfpath ( void )
@@ -1471,7 +1497,7 @@ const char *config_get_muxconfpath ( void )
 
 int config_set_muxconfpath ( const char *path )
 {
-  return _config_set_str("muxconfpath", path);
+  return config_set_str("muxconfpath", path);
 }
 
 int config_get_prefer_picon ( void )
@@ -1483,7 +1509,7 @@ int config_get_prefer_picon ( void )
 
 int config_set_prefer_picon ( const char *str )
 {
-  return _config_set_str("prefer_picon", str);
+  return config_set_str("prefer_picon", str);
 }
 
 const char *config_get_chicon_path ( void )
@@ -1493,7 +1519,7 @@ const char *config_get_chicon_path ( void )
 
 int config_set_chicon_path ( const char *str )
 {
-  return _config_set_str("chiconpath", str);
+  return config_set_str("chiconpath", str);
 }
 
 const char *config_get_picon_path ( void )
@@ -1503,5 +1529,5 @@ const char *config_get_picon_path ( void )
 
 int config_set_picon_path ( const char *str )
 {
-  return _config_set_str("piconpath", str);
+  return config_set_str("piconpath", str);
 }
index c24d5141b4e3d9aa3fed7b87282808af038b771c..d9176e2d9a36618b3d0f9c71c56caa2010b5b818 100644 (file)
@@ -29,6 +29,11 @@ void        config_save    ( void );
 
 htsmsg_t   *config_get_all ( void );
 
+const char *config_get_str ( const char *fld );
+int         config_set_str ( const char *fld, const char *val );
+int         config_get_int ( const char *fld, int dflt );
+int         config_set_int ( const char *fld, int val );
+
 const char *config_get_muxconfpath ( void );
 int         config_set_muxconfpath ( const char *str )
   __attribute__((warn_unused_result));