Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
config: add universal fcns to access to global variables
  • Loading branch information
perexg committed Mar 11, 2015
1 parent 2904a96 commit af698f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
40 changes: 33 additions & 7 deletions src/config.c
Expand Up @@ -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)) {
Expand All @@ -1454,14 +1460,34 @@ _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");
}

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 )
Expand All @@ -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 )
Expand All @@ -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 )
Expand All @@ -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 )
Expand All @@ -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);
}
5 changes: 5 additions & 0 deletions src/config.h
Expand Up @@ -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));
Expand Down

0 comments on commit af698f0

Please sign in to comment.