3 * @brief Nokia MCE screen unblanking for VLC media player
5 /*****************************************************************************
6 * Copyright © 2009-2011 Rémi Denis-Courmont
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1
11 * of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 ****************************************************************************/
27 #include <vlc_common.h>
28 #include <vlc_plugin.h>
29 #include <vlc_inhibit.h>
30 #include <dbus/dbus.h>
32 static int Open (vlc_object_t *);
33 static void Close (vlc_object_t *);
39 set_shortname (N_("MCE"))
40 set_description (N_("Nokia MCE screen unblanking"))
41 set_category (CAT_ADVANCED)
42 set_subcategory (SUBCAT_ADVANCED_MISC)
43 set_capability ("inhibit", 20)
44 set_callbacks (Open, Close)
47 static void Inhibit (vlc_inhibit_t *, bool);
48 static void Timer (void *data);
50 struct vlc_inhibit_sys
56 static int Open (vlc_object_t *obj)
58 vlc_inhibit_t *ih = (vlc_inhibit_t *)obj;
59 vlc_inhibit_sys_t *sys = malloc (sizeof (*sys));
60 if (unlikely(sys == NULL))
65 dbus_error_init (&err);
66 sys->conn = dbus_bus_get_private (DBUS_BUS_SYSTEM, &err);
67 if (sys->conn == NULL)
69 msg_Err (obj, "cannot connect to system bus: %s", err.message);
70 dbus_error_free (&err);
74 if (vlc_timer_create (&sys->timer, Timer, sys->conn))
76 dbus_connection_unref (sys->conn);
81 ih->inhibit = Inhibit;
89 static void Close (vlc_object_t *obj)
91 vlc_inhibit_t *ih = (vlc_inhibit_t *)obj;
92 vlc_inhibit_sys_t *sys = ih->p_sys;
94 vlc_timer_destroy (sys->timer);
95 dbus_connection_close (sys->conn);
96 dbus_connection_unref (sys->conn);
100 static void Inhibit (vlc_inhibit_t *ih, bool unblank)
102 vlc_inhibit_sys_t *sys = ih->p_sys;
104 /* The shortest blanking interval is 10s on N900, 15s on N9 */
105 const mtime_t interval = 9 * CLOCK_FREQ;
106 vlc_timer_schedule (sys->timer, false, unblank, interval);
109 /* NOTE: This plug-in could be compiled without MCE development files easily.
110 * But then it would get included on all platforms with D-Bus. */
111 #include <mce/dbus-names.h>
113 static void Timer (void *data)
115 DBusConnection *conn = data;
116 DBusMessage *msg = dbus_message_new_method_call (MCE_SERVICE,
120 if (unlikely(msg == NULL))
123 if (dbus_connection_send (conn, msg, NULL))
124 dbus_connection_flush (conn);
125 dbus_message_unref (msg);