3
* This file is in the public domain
2
* Copyright (C) 2010 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
9
23
namespace Unity.SamplePlace {
11
static Daemon? daemon = null;
12
static MainLoop? mainloop = null;
14
25
public static int main (string[] args)
16
27
GLib.Intl.textdomain (Config.PACKAGE);
19
30
GLib.Intl.setlocale(GLib.LocaleCategory.ALL, "");
21
32
DesktopAppInfo.set_desktop_env ("GNOME");
34
var daemon = new Daemon ();
23
36
/* Export the place daemon on the session bus - as everywhere else
24
37
* these values should match those definedd in the .place file */
25
Bus.own_name (BusType.SESSION, "com.canonical.Unity.SamplePlace",
26
BusNameOwnerFlags.NONE,
27
on_bus_acquired, on_name_acquired, on_name_lost);
29
mainloop = new MainLoop ();
39
var conn = DBus.Bus.get (DBus.BusType.SESSION);
40
dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
41
"/org/freedesktop/DBus",
42
"org.freedesktop.DBus");
44
uint request_name_result = bus.request_name ("com.canonical.Unity.SamplePlace", (uint) 0);
45
if (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER)
47
debug ("Running sample place daemon.");
48
new MainLoop (null, false).run();
52
print (_("Another Sample Place daemon appears to be running.\nBailing out."));
55
} catch (DBus.Error error) {
56
print (_("Error connecting to session bus: %s.\nBailing out."), error.message);
35
private static void on_bus_acquired (DBusConnection conn, string name)
37
debug ("Connected to session bus - checking for existing instances...");
39
/* We need to set up our DBus objects *before* we know if we've acquired
40
* the name. This is a bit unfortunate because it means we might do work
41
* for no reason if another daemon is already running. See
42
* https://bugzilla.gnome.org/show_bug.cgi?id=640714 */
43
daemon = new Daemon ();
46
private static void on_name_acquired (DBusConnection conn, string name)
48
debug ("Acquired name %s. We're the main instance.\nAll system are go.",
52
private static void on_name_lost (DBusConnection conn, string name)
54
debug ("Another daemon is running.\nBailing out.");
58
62
} /* End namespace Unity.SamplePlace */