29 #include "xmms_configuration.h" 64 static void install_scripts (
const gchar *into_dir);
65 static void spawn_script_setup (gpointer data);
98 static GMainLoop *mainloop;
101 static gchar *conffile = NULL;
112 ret = g_tree_new_full ((GCompareDataFunc) strcmp, NULL,
117 g_tree_insert (ret, (gpointer)
"version",
119 g_tree_insert (ret, (gpointer)
"uptime",
126 xmms_main_client_list_foreach (
xmms_plugin_t *plugin, gpointer data)
139 *list = g_list_prepend (*list, dict);
163 do_scriptdir (
const gchar *scriptdir,
const gchar *arg1)
168 gchar *argv[3] = {NULL, NULL, NULL};
170 XMMS_DBG (
"Running scripts in %s", scriptdir);
171 if (!g_file_test (scriptdir, G_FILE_TEST_IS_DIR)) {
172 g_mkdir_with_parents (scriptdir, 0755);
173 install_scripts (scriptdir);
176 dir = g_dir_open (scriptdir, 0, &err);
178 xmms_log_error (
"Could not open script dir '%s' error: %s", scriptdir, err->message);
182 argv[1] = g_strdup (arg1);
183 while ((f = g_dir_read_name (dir))) {
184 argv[0] = g_strdup_printf (
"%s/%s", scriptdir, f);
185 if (g_file_test (argv[0], G_FILE_TEST_IS_EXECUTABLE)) {
186 if (!g_spawn_async (g_get_home_dir (), argv, NULL, 0,
187 spawn_script_setup, NULL, NULL, &err)) {
189 argv[0], err->message);
204 spawn_script_setup (gpointer data)
226 }
else if (!g_file_test (configdir, G_FILE_TEST_IS_DIR)) {
227 g_mkdir_with_parents (configdir, 0755);
244 const gchar *outname;
246 if (!mainobj->output)
255 xmms_log_error (
"Baaaaad output plugin, try to change the output.plugin config variable to something useful");
258 xmms_log_error (
"Baaaaad output plugin, try to change the output.plugin config variable to something useful");
284 g_usleep (G_USEC_PER_SEC);
297 xmms_main_unregister_ipc_commands ();
315 XMMS_DBG (
"Client '%s' connected", client);
319 kill_server (gpointer
object) {
342 g_timeout_add (1, kill_server,
object);
346 install_scripts (
const gchar *into_dir)
354 s = strrchr (into_dir, G_DIR_SEPARATOR);
360 g_snprintf (path,
XMMS_PATH_MAX,
"%s/scripts/%s", SHAREDDIR, s);
362 dir = g_dir_open (path, 0, &err);
368 while ((f = g_dir_read_name (dir))) {
369 gchar *source = g_strdup_printf (
"%s/%s", path, f);
370 gchar *dest = g_strdup_printf (
"%s/%s", into_dir, f);
389 printf (
"XMMS2 version " XMMS_VERSION
"\n");
390 printf (
"Copyright (C) 2003-2011 XMMS2 Team\n");
391 printf (
"This is free software; see the source for copying conditions.\n");
392 printf (
"There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n");
393 printf (
"PARTICULAR PURPOSE.\n");
394 printf (
" Using glib version %d.%d.%d (compiled against " 395 G_STRINGIFY (GLIB_MAJOR_VERSION)
"." 396 G_STRINGIFY (GLIB_MINOR_VERSION)
"." 397 G_STRINGIFY (GLIB_MICRO_VERSION)
")\n",
418 gboolean verbose = FALSE;
419 gboolean quiet = FALSE;
420 gboolean version = FALSE;
421 gboolean runasroot = FALSE;
422 gboolean showhelp = FALSE;
423 const gchar *outname = NULL;
424 const gchar *ipcpath = NULL;
427 GOptionContext *context = NULL;
428 GError *error = NULL;
430 setlocale (LC_ALL,
"");
435 GOptionEntry opts[] = {
436 {
"verbose",
'v', 0, G_OPTION_ARG_NONE, &verbose,
"Increase verbosity", NULL},
437 {
"quiet",
'q', 0, G_OPTION_ARG_NONE, &quiet,
"Decrease verbosity", NULL},
438 {
"version",
'V', 0, G_OPTION_ARG_NONE, &version,
"Print version", NULL},
439 {
"output",
'o', 0, G_OPTION_ARG_STRING, &outname,
"Use 'x' as output plugin",
"<x>"},
440 {
"ipc-socket",
'i', 0, G_OPTION_ARG_FILENAME, &ipcpath,
"Listen to socket 'url'",
"<url>"},
441 {
"plugindir",
'p', 0, G_OPTION_ARG_FILENAME, &ppath,
"Search for plugins in directory 'foo'",
"<foo>"},
442 {
"conf",
'c', 0, G_OPTION_ARG_FILENAME, &conffile,
"Specify alternate configuration file",
"<file>"},
443 {
"status-fd",
's', 0, G_OPTION_ARG_INT, &status_fd,
"Specify a filedescriptor to write to when started",
"fd"},
444 {
"yes-run-as-root", 0, 0, G_OPTION_ARG_NONE, &runasroot,
"Give me enough rope to shoot myself in the foot", NULL},
445 {
"show-help",
'h', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &showhelp,
"Use --help or -? instead", NULL},
450 if (glib_major_version != GLIB_MAJOR_VERSION ||
451 glib_minor_version < GLIB_MINOR_VERSION) {
452 g_print (
"xmms2d is build against version %d.%d,\n" 453 "but is (runtime) linked against %d.%d.\n" 454 "Refusing to start.\n",
455 GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
456 glib_major_version, glib_minor_version);
462 context = g_option_context_new (
"- XMMS2 Daemon");
463 g_option_context_add_main_entries (context, opts, NULL);
464 if (!g_option_context_parse (context, &argc, &argv, &error) || error) {
465 g_print (
"Error parsing options: %s\n", error->message);
466 g_clear_error (&error);
470 #if GLIB_CHECK_VERSION(2,14,0) 471 g_print (
"%s", g_option_context_get_help (context, TRUE, NULL));
474 g_print (
"Please use --help or -? for help\n");
478 g_option_context_free (context);
481 g_print (
"There were unknown options, aborting!\n");
487 g_print (
"***************************************\n");
488 g_print (
"Warning! You are running XMMS2D as root, this is a bad idea!\nBut I'll allow it since you asked nicely.\n");
489 g_print (
"***************************************\n\n");
491 g_print (
"PLEASE DON'T RUN XMMS2D AS ROOT!\n\n(if you really must, read the help)\n");
506 g_thread_init (NULL);
508 g_random_set_seed (time (NULL));
554 change_output, mainobj);
565 "output.plugin config variable to something useful");
569 if (!mainobj->output) {
575 if (status_fd != -1) {
576 write (status_fd,
"+", 1);
581 xmms_main_register_ipc_commands (
XMMS_OBJECT (mainobj));
584 mainobj->starttime = time (NULL);
587 g_strlcpy (default_path, ipcpath,
sizeof (default_path));
589 tmp = strchr (default_path,
';');
594 g_setenv (
"XMMS_PATH", default_path, TRUE);
597 g_setenv(
"XMMS_PATH_FULL", ipcpath, TRUE);
612 mainloop = g_main_loop_new (NULL, FALSE);
614 g_main_loop_run (mainloop);
xmms_ipc_t * xmms_ipc_init(void)
Initialize IPC.
void xmms_log_init(gint verbosity)
void xmmsv_unref(xmmsv_t *val)
Decreases the references for the xmmsv_t When the number of references reaches 0 it will be freed...
#define xmms_object_unref(obj)
#define XMMS_IPC_PROTOCOL_VERSION
xmms_plugin_type_t xmms_plugin_type_get(const xmms_plugin_t *plugin)
void on_config_ipcsocket_change(xmms_object_t *object, xmmsv_t *_data, gpointer udata)
Gets called when the config property "core.ipcsocket" has changed.
gboolean xmms_checkroot()
xmms_config_property_t * xmms_config_lookup(const gchar *path)
Look up a config key from the global config.
#define XMMSV_DICT_ENTRY_STR(k, v)
xmmsv_t * xmmsv_new_string(const char *s)
Allocates a new string xmmsv_t.
gboolean xmms_config_save(void)
void xmms_signal_block(void)
gboolean xmms_plugin_init(const gchar *path)
void xmms_sqlite_print_version(void)
const gchar * xmms_plugin_shortname_get(const xmms_plugin_t *plugin)
void xmms_config_init(const gchar *filename)
gboolean xmms_ipc_setup_server(const gchar *path)
Start the server.
#define XMMS_MAX_CONFIGFILE_LEN
xmms_output_t * xmms_output_new(xmms_output_plugin_t *plugin, xmms_playlist_t *playlist)
Allocate a new xmms_output_t.
void xmms_config_property_set_data(xmms_config_property_t *prop, const gchar *data)
Set the data of the config property to a new value.
#define xmms_log_error(fmt,...)
void xmms_object_cmd_arg_init(xmms_object_cmd_arg_t *arg)
Initialize a command argument.
gboolean xmms_output_plugin_switch(xmms_output_t *output, xmms_output_plugin_t *new_plugin)
Switch to another output plugin.
void xmms_object_emit_f(xmms_object_t *object, guint32 signalid, xmmsv_type_t type,...)
Emits a signal on the current object.
const gchar * xmms_plugin_version_get(const xmms_plugin_t *plugin)
xmmsv_t * xmmsv_new_list(void)
Allocates a new list xmmsv_t.
void xmms_signal_restore(void)
void xmms_object_cmd_call(xmms_object_t *object, guint cmdid, xmms_object_cmd_arg_t *arg)
Call a command with argument.
struct xmms_playlist_St xmms_playlist_t
struct xmms_output_St xmms_output_t
struct xmms_output_plugin_St xmms_output_plugin_t
const gchar * xmms_config_property_get_string(const xmms_config_property_t *prop)
Return the value of a config property as a string.
const char * xmms_plugin_description_get(const xmms_plugin_t *plugin)
gboolean xmms_symlink_file(gchar *source, gchar *dest)
void xmms_plugin_foreach(xmms_plugin_type_t type, xmms_plugin_foreach_func_t func, gpointer user_data)
xmms_visualization_t * xmms_visualization_new(xmms_output_t *output)
Initialize the Vis module.
xmmsv_t * xmmsv_new_int(int32_t i)
Allocates a new integer xmmsv_t.
xmmsv_t * xmmsv_build_dict(const char *firstkey,...)
#define XMMSV_DICT_ENTRY_INT(k, v)
#define xmms_log_info(fmt,...)
int main(int argc, char **argv)
The xmms2 daemon main initialisation function.
void xmms_signal_init(xmms_object_t *obj)
void xmms_ipc_shutdown(void)
Disable IPC.
#define XMMS_DBG(fmt,...)
xmms_playlist_t * xmms_playlist_init(void)
Initializes a new xmms_playlist_t.
void xmms_log_set_format(const gchar *format)
void xmms_config_shutdown()
#define xmms_object_new(objtype, destroyfunc)
G_BEGIN_DECLS struct xmms_error_St xmms_error_t
struct xmms_main_St xmms_main_t
xmms_config_property_t * xmms_config_property_register(const gchar *path, const gchar *default_value, xmms_object_handler_t cb, gpointer userdata)
Register a new config property.
xmms_bindata_t * xmms_bindata_init()
const char * xmms_userconfdir_get(char *buf, int len)
Get the absolute path to the user config dir.
struct xmms_config_property_St xmms_config_property_t
xmms_plugin_t * xmms_plugin_find(xmms_plugin_type_t type, const gchar *name)
#define xmms_log_fatal(fmt,...)
const char * xmms_plugin_name_get(const xmms_plugin_t *plugin)
void xmms_plugin_shutdown()
#define XMMS_BUILD_PATH(...)
const char * xmms_fallback_ipcpath_get(char *buf, int len)
Get the fallback connection path (if XMMS_PATH is not accessible)
struct xmms_bindata_St xmms_bindata_t
The structures for the vis module.