1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-11-03 04:17:18 -05:00

Expose "configuration stashing" API

This commit is contained in:
Moritz Grimm 2015-06-09 23:02:45 +02:00
parent 87275ca223
commit 744511ffe2
4 changed files with 54 additions and 6 deletions

View File

@ -63,6 +63,8 @@ _cfg_reset(struct cfg *c)
static void
_cfg_copy(struct cfg *dst, struct cfg *src)
{
dst->_master_cfg = src->_master_cfg;
memcpy(&dst->program, &src->program, sizeof(dst->program));
memcpy(&dst->server, &src->server, sizeof(dst->server));
@ -121,6 +123,7 @@ int
cfg_init(void)
{
_cfg_reset(&cfg);
cfg._master_cfg = 1;
return (0);
}
@ -130,18 +133,38 @@ cfg_exit(void)
_cfg_reset(&cfg);
}
void
cfg_save(void)
{
_cfg_reset(&cfg_tmp);
_cfg_copy(&cfg_tmp, &cfg);
}
void
cfg_pop(void)
{
if (!cfg_tmp._master_cfg)
return;
_cfg_reset(&cfg);
_cfg_copy(&cfg, &cfg_tmp);
_cfg_reset(&cfg_tmp);
}
void
cfg_clear(void)
{
_cfg_reset(&cfg_tmp);
}
int
cfg_reload(void)
{
_cfg_copy(&cfg_tmp, &cfg);
cfg_save();
if (0 > _cfg_load()) {
/* roll back */
_cfg_reset(&cfg);
_cfg_copy(&cfg, &cfg_tmp);
_cfg_reset(&cfg_tmp);
cfg_pop();
return (-1);
}
_cfg_reset(&cfg_tmp);
cfg_clear();
return (0);
}

View File

@ -65,6 +65,10 @@ enum cfg_stream_format {
int cfg_init(void);
void cfg_exit(void);
void cfg_save(void);
void cfg_pop(void);
void cfg_clear(void);
int cfg_reload(void);
int cfg_stream_str2fmt(const char *, enum cfg_stream_format *);

View File

@ -31,6 +31,7 @@
#define DEFAULT_USER "source"
struct cfg {
int _master_cfg;
struct program {
char name[PATH_MAX];
enum cfg_config_type config_type;

View File

@ -100,6 +100,25 @@ Suite * cfg_suite(void);
void setup_checked(void);
void teardown_checked(void);
START_TEST(test_stash)
{
ck_assert_ptr_eq(cfg_get_stream_name(), NULL);
ck_assert_int_eq(cfg_set_stream_name("test_stash", NULL), 0);
ck_assert_str_eq(cfg_get_stream_name(), "test_stash");
cfg_save();
ck_assert_int_eq(cfg_set_stream_name("test_stash2", NULL), 0);
ck_assert_str_eq(cfg_get_stream_name(), "test_stash2");
cfg_pop();
ck_assert_str_eq(cfg_get_stream_name(), "test_stash");
cfg_pop();
ck_assert_str_eq(cfg_get_stream_name(), "test_stash");
cfg_save();
cfg_clear();
cfg_pop();
ck_assert_str_eq(cfg_get_stream_name(), "test_stash");
}
END_TEST
START_TEST(test_stream_str2fmt)
{
enum cfg_stream_format fmt;
@ -729,6 +748,7 @@ cfg_suite(void)
tc_core = tcase_create("Core");
tcase_add_checked_fixture(tc_core, setup_checked, teardown_checked);
tcase_add_test(tc_core, test_stash);
tcase_add_test(tc_core, test_stream_str2fmt);
tcase_add_test(tc_core, test_stream_fmt2str);
tcase_add_test(tc_core, test_file_check);