1 /*****************************************************************************
2 * specific.c: stubs for POSIX OS-specific initialization
3 *****************************************************************************
4 * Copyright © 2008 Rémi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
25 #include <vlc_common.h>
26 #include "../libvlc.h"
27 #include "../lib/libvlc_internal.h"
30 /* used for one-instance mode */
31 # include <dbus/dbus.h>
35 void system_Init (void)
39 static void system_ConfigureDbus(libvlc_int_t
*vlc
, int argc
,
40 const char *const argv
[])
42 /* FIXME: could be replaced by using Unix sockets */
44 # define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append"
45 # define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc"
46 # define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2"
47 # define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList"
49 dbus_threads_init_default();
51 if (var_InheritBool(vlc
, "dbus"))
52 libvlc_InternalAddIntf(vlc
, "dbus,none");
54 if (!var_InheritBool(vlc
, "one-instance")
55 && !(var_InheritBool(vlc
, "one-instance-when-started-from-file")
56 && var_InheritBool(vlc
, "started-from-file")))
59 for (int i
= 0; i
< argc
; i
++)
60 if (argv
[i
][0] == ':')
62 msg_Err(vlc
, "item option %s incompatible with single instance",
67 char *name
= var_GetString(vlc
, "dbus-mpris-name");
70 bool singleton
= !strcmp(name
, MPRIS_BUS_NAME
);
74 msg_Dbg(vlc
, "no running VLC instance - continuing normally...");
75 return; /* This is the single instance */
79 /* Initialise D-Bus interface, check for other instances */
81 dbus_error_init(&err
);
83 /* connect to the session bus */
84 DBusConnection
*conn
= dbus_bus_get(DBUS_BUS_SESSION
, &err
);
87 msg_Err(vlc
, "D-Bus session bus connection failure: %s",
89 dbus_error_free(&err
);
93 msg_Warn(vlc
, "running VLC instance - exiting...");
95 const dbus_bool_t play
= !var_InheritBool(vlc
, "playlist-enqueue");
97 for (int i
= 0; i
< argc
; i
++)
99 DBusMessage
*req
= dbus_message_new_method_call(MPRIS_BUS_NAME
,
100 MPRIS_OBJECT_PATH
, MPRIS_TRACKLIST_INTERFACE
, "AddTrack");
101 if (unlikely(req
== NULL
))
104 /* We need to resolve relative paths in this instance */
108 if (strstr(argv
[i
], "://"))
112 mrlbuf
= vlc_path2uri(argv
[i
], NULL
);
113 if (unlikely(mrlbuf
== NULL
))
115 dbus_message_unref(req
);
122 msg_Dbg(vlc
, "adding track %s to running instance", mrl
);
124 const char *after_track
= MPRIS_APPEND
;
125 dbus_bool_t ok
= dbus_message_append_args(req
, DBUS_TYPE_STRING
, &mrl
,
126 DBUS_TYPE_OBJECT_PATH
, &after_track
,
127 DBUS_TYPE_BOOLEAN
, &play
,
132 dbus_message_unref(req
);
136 /* send message and get a handle for a reply */
137 DBusMessage
*reply
= dbus_connection_send_with_reply_and_block(conn
,
139 dbus_message_unref(req
);
142 msg_Err(vlc
, "D-Bus error: %s", err
.message
);
143 dbus_error_free(&err
);
146 dbus_message_unref(reply
);
149 /* we unreference the connection when we've finished with it */
150 dbus_connection_unref(conn
);
153 (void) vlc
; (void) argc
; (void) argv
;
157 void system_Configure(libvlc_int_t
*libvlc
,
158 int argc
, const char *const argv
[])
160 system_ConfigureDbus(libvlc
, argc
, argv
);