diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2013-08-10 04:26:27 +0000 |
---|---|---|
committer | Tarmac <> | 2013-08-10 04:26:27 +0000 |
commit | f28653eb1a4a310987fffc44334b93da3f547d41 (patch) | |
tree | 82a72bfbb7eeca76766d73ae20f1152c5b8392c3 /src/service.vala | |
parent | 0391025f72e9e5fed972b40e63087635d50c9234 (diff) | |
parent | a0616908a817d6fad47c29ae703fc8a2ea379af6 (diff) | |
download | ayatana-indicator-bluetooth-f28653eb1a4a310987fffc44334b93da3f547d41.tar.gz ayatana-indicator-bluetooth-f28653eb1a4a310987fffc44334b93da3f547d41.tar.bz2 ayatana-indicator-bluetooth-f28653eb1a4a310987fffc44334b93da3f547d41.zip |
Add phone profile. Export menus & actions using gio. Drops the gtk, dbusmenu, and libindicator build dependencies. Drops runtime dependency on gnome-blueooth in the phone profile.
Approved by Ted Gould, PS Jenkins bot, Mathieu Trudel-Lapierre.
Diffstat (limited to 'src/service.vala')
-rw-r--r-- | src/service.vala | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/service.vala b/src/service.vala new file mode 100644 index 0000000..20fdd1e --- /dev/null +++ b/src/service.vala @@ -0,0 +1,108 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + * Robert Ancell <robert.ancell@canonical.com> + */ + +/** + * Boilerplate class to own the name on the bus, + * to create the profiles, and to export them on the bus. + */ +public class Service: Object +{ + private MainLoop loop; + private SimpleActionGroup actions; + private HashTable<string,Profile> profiles; + private DBusConnection connection; + private uint exported_action_id; + private const string OBJECT_PATH = "/com/canonical/indicator/bluetooth"; + + private void unexport () + { + if (connection != null) + { + profiles.for_each ((name, profile) + => profile.unexport_menu (connection)); + + if (exported_action_id != 0) + { + debug (@"unexporting action group '$(OBJECT_PATH)'"); + connection.unexport_action_group (exported_action_id); + exported_action_id = 0; + } + } + } + + public Service (Bluetooth bluetooth) + { + actions = new SimpleActionGroup (); + + profiles = new HashTable<string,Profile> (str_hash, str_equal); + profiles.insert ("phone", new Phone (bluetooth, actions)); + profiles.insert ("desktop", new Desktop (bluetooth, actions)); + } + + public int run () + { + if (loop != null) + { + warning ("service is already running"); + return Posix.EXIT_FAILURE; + } + + var own_name_id = Bus.own_name (BusType.SESSION, + "com.canonical.indicator.bluetooth", + BusNameOwnerFlags.NONE, + on_bus_acquired, + null, + on_name_lost); + + loop = new MainLoop (null, false); + loop.run (); + + // cleanup + unexport (); + Bus.unown_name (own_name_id); + return Posix.EXIT_SUCCESS; + } + + void on_bus_acquired (DBusConnection connection, string name) + { + debug (@"bus acquired: $name"); + this.connection = connection; + + try + { + debug (@"exporting action group '$(OBJECT_PATH)'"); + exported_action_id = connection.export_action_group (OBJECT_PATH, + actions); + } + catch (Error e) + { + critical (@"Unable to export actions on $OBJECT_PATH: $(e.message)"); + } + + profiles.for_each ((name, profile) + => profile.export_menu (connection, @"$OBJECT_PATH/$name")); + } + + void on_name_lost (DBusConnection connection, string name) + { + debug (@"name lost: $name"); + loop.quit (); + } +} |