main: moved complex initialization code to glue functions
The glue_*() functions act as a glue between MPD's main() function and its libraries. They handle disabled features, and pass validated configuration options.
This commit is contained in:
parent
739984f920
commit
7bc8c7518b
53
src/main.c
53
src/main.c
@ -90,6 +90,16 @@ GMainLoop *main_loop;
|
|||||||
|
|
||||||
struct notify main_notify;
|
struct notify main_notify;
|
||||||
|
|
||||||
|
static void
|
||||||
|
glue_daemonize_init(const struct options *options)
|
||||||
|
{
|
||||||
|
daemonize_init(config_get_string(CONF_USER, NULL),
|
||||||
|
config_get_path(CONF_PID_FILE));
|
||||||
|
|
||||||
|
if (options->kill)
|
||||||
|
daemonize_kill();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the database. If this function returns false, this has not
|
* Returns the database. If this function returns false, this has not
|
||||||
* succeeded, and the caller should create the database after the
|
* succeeded, and the caller should create the database after the
|
||||||
@ -140,6 +150,29 @@ glue_db_init_and_load(const struct options *options)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure and initialize the sticker subsystem.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
glue_sticker_init(void)
|
||||||
|
{
|
||||||
|
#ifdef ENABLE_SQLITE
|
||||||
|
bool success;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
success = sticker_global_init(config_get_path(CONF_STICKER_FILE),
|
||||||
|
&error);
|
||||||
|
if (!success)
|
||||||
|
g_error("%s", error->message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
glue_state_file_init(void)
|
||||||
|
{
|
||||||
|
state_file_init(config_get_path(CONF_STATE_FILE));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Windows-only initialization of the Winsock2 library.
|
* Windows-only initialization of the Winsock2 library.
|
||||||
*/
|
*/
|
||||||
@ -231,10 +264,6 @@ int main(int argc, char *argv[])
|
|||||||
struct options options;
|
struct options options;
|
||||||
clock_t start;
|
clock_t start;
|
||||||
bool create_db;
|
bool create_db;
|
||||||
#ifdef ENABLE_SQLITE
|
|
||||||
bool success;
|
|
||||||
GError *error = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
daemonize_close_stdin();
|
daemonize_close_stdin();
|
||||||
|
|
||||||
@ -257,11 +286,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
parse_cmdline(argc, argv, &options);
|
parse_cmdline(argc, argv, &options);
|
||||||
|
|
||||||
daemonize_init(config_get_string(CONF_USER, NULL),
|
glue_daemonize_init(&options);
|
||||||
config_get_path(CONF_PID_FILE));
|
|
||||||
|
|
||||||
if (options.kill)
|
|
||||||
daemonize_kill();
|
|
||||||
|
|
||||||
stats_global_init();
|
stats_global_init();
|
||||||
tag_lib_init();
|
tag_lib_init();
|
||||||
@ -291,12 +316,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
create_db = !glue_db_init_and_load(&options);
|
create_db = !glue_db_init_and_load(&options);
|
||||||
|
|
||||||
#ifdef ENABLE_SQLITE
|
glue_sticker_init();
|
||||||
success = sticker_global_init(config_get_path(CONF_STICKER_FILE),
|
|
||||||
&error);
|
|
||||||
if (!success)
|
|
||||||
g_error("%s", error->message);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
command_init();
|
command_init();
|
||||||
initialize_decoder_and_player();
|
initialize_decoder_and_player();
|
||||||
@ -326,8 +346,7 @@ int main(int argc, char *argv[])
|
|||||||
g_error("directory update failed");
|
g_error("directory update failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glue_state_file_init();
|
||||||
state_file_init(config_get_path(CONF_STATE_FILE));
|
|
||||||
|
|
||||||
config_global_check();
|
config_global_check();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user