summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-08-27 22:11:51 +0200
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-08-28 18:18:29 +0200
commita2f8af08ce37b9c0f322a1c3cb596658b0593e7c (patch)
treeb15358683c48bda37d1dfbc0ec2bf9cada5c400e /main.c
parent4457911ae7d38d7bef7abe11bc43d060ba4bf6a2 (diff)
osx support WIP
Diffstat (limited to 'main.c')
-rw-r--r--main.c194
1 files changed, 114 insertions, 80 deletions
diff --git a/main.c b/main.c
index e651aee9..f6bd4eca 100644
--- a/main.c
+++ b/main.c
@@ -697,6 +697,109 @@ restore_resume_state (void) {
}
}
+typedef struct {
+ int argc;
+ char **argv;
+ char *cmdline;
+ int size;
+} main_args_t;
+
+uintptr_t gui_cond, gui_mutex;
+void
+plugloader (void *ctx) {
+ main_args_t *args = ctx;
+ int argc = args->argc;
+ char **argv = args->argv;
+ char *cmdline = args->cmdline;
+ int size = args->size;
+
+ messagepump_init (); // required to push messages while handling commandline
+ if (plug_load_all ()) { // required to add files to playlist from commandline
+ exit (-1);
+ }
+
+ cond_signal (gui_cond);
+
+ pl_load_all ();
+ plt_set_curr_idx (conf_get_int ("playlist.current", 0));
+
+ // execute server commands in local context
+ int noloadpl = 0;
+ if (argc > 1) {
+ int res = server_exec_command_line (cmdline, size, NULL, 0);
+ // some of the server commands ran on 1st instance should terminate it
+ if (res == 2) {
+ noloadpl = 1;
+ }
+ else if (res > 0) {
+ exit (0);
+ }
+ else if (res < 0) {
+ exit (-1);
+ }
+ }
+
+ free (cmdline);
+
+#if 0
+ signal (SIGTERM, sigterm_handler);
+ atexit (atexit_handler); // helps to save in simple cases
+#endif
+
+ // start all subsystems
+ messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
+
+ streamer_init ();
+
+ plug_connect_all ();
+ messagepump_push (DB_EV_PLUGINSLOADED, 0, 0, 0);
+
+ if (!noloadpl) {
+ restore_resume_state ();
+ }
+
+ server_tid = thread_start (server_loop, NULL);
+ // this runs in main thread (blocks right here)
+ player_mainloop ();
+
+ // terminate server and wait for completion
+ if (server_tid) {
+ server_terminate = 1;
+ thread_join (server_tid);
+ server_tid = 0;
+ }
+
+ // save config
+ pl_save_all ();
+ conf_save ();
+
+ // delete legacy session file
+ {
+ char sessfile[1024]; // $HOME/.config/deadbeef/session
+ if (snprintf (sessfile, sizeof (sessfile), "%s/deadbeef/session", confdir) < sizeof (sessfile)) {
+ unlink (sessfile);
+ }
+ }
+
+ // stop receiving messages from outside
+ server_close ();
+
+ // plugins might still hold references to playitems,
+ // and query configuration in background
+ // so unload everything 1st before final cleanup
+ plug_disconnect_all ();
+ plug_unload_all ();
+
+ // at this point we can simply do exit(0), but let's clean up for debugging
+ pl_free (); // may access conf_*
+ conf_free ();
+ messagepump_free ();
+ plug_cleanup ();
+
+ fprintf (stderr, "hej-hej!\n");
+ return;
+}
+
int
main (int argc, char *argv[]) {
int portable = 0;
@@ -940,87 +1043,18 @@ main (int argc, char *argv[]) {
conf_set_str ("deadbeef_version", VERSION);
volume_set_db (conf_get_float ("playback.volume", 0)); // volume need to be initialized before plugins start
- messagepump_init (); // required to push messages while handling commandline
- if (plug_load_all ()) { // required to add files to playlist from commandline
- exit (-1);
- }
- pl_load_all ();
- plt_set_curr_idx (conf_get_int ("playlist.current", 0));
-
- // execute server commands in local context
- int noloadpl = 0;
- if (argc > 1) {
- int res = server_exec_command_line (cmdline, size, NULL, 0);
- // some of the server commands ran on 1st instance should terminate it
- if (res == 2) {
- noloadpl = 1;
- }
- else if (res > 0) {
- exit (0);
- }
- else if (res < 0) {
- exit (-1);
- }
- }
-
- free (cmdline);
-
-#if 0
- signal (SIGTERM, sigterm_handler);
- atexit (atexit_handler); // helps to save in simple cases
-#endif
+
+
+ gui_cond = cond_create ();
+ gui_mutex = mutex_create ();
+ main_args_t args = {argc,argv,cmdline,size};
+ thread_start (plugloader, NULL);
+ printf ("waiting for GUI\n");
+ cond_wait (gui_cond, gui_mutex);
+
+ DB_plugin_t *gui = plug_get_for_id ("gtkui3_1");
+ gui->command (10, 0);
- // start all subsystems
- messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
-
- streamer_init ();
-
- plug_connect_all ();
- messagepump_push (DB_EV_PLUGINSLOADED, 0, 0, 0);
-
- if (!noloadpl) {
- restore_resume_state ();
- }
-
- server_tid = thread_start (server_loop, NULL);
- // this runs in main thread (blocks right here)
- player_mainloop ();
-
- // terminate server and wait for completion
- if (server_tid) {
- server_terminate = 1;
- thread_join (server_tid);
- server_tid = 0;
- }
-
- // save config
- pl_save_all ();
- conf_save ();
-
- // delete legacy session file
- {
- char sessfile[1024]; // $HOME/.config/deadbeef/session
- if (snprintf (sessfile, sizeof (sessfile), "%s/deadbeef/session", confdir) < sizeof (sessfile)) {
- unlink (sessfile);
- }
- }
-
- // stop receiving messages from outside
- server_close ();
-
- // plugins might still hold references to playitems,
- // and query configuration in background
- // so unload everything 1st before final cleanup
- plug_disconnect_all ();
- plug_unload_all ();
-
- // at this point we can simply do exit(0), but let's clean up for debugging
- pl_free (); // may access conf_*
- conf_free ();
- messagepump_free ();
- plug_cleanup ();
-
- fprintf (stderr, "hej-hej!\n");
return 0;
}