2 * registry - zavai resource registry
4 * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 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 General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 public class Registry : Object, Resource
27 List<Resource> resources;
28 public DBus.Connection sbus;
29 public string bus_name;
33 resources = new List<Resource>();
35 sbus = DBus.Bus.get(DBus.BusType.SYSTEM);
36 } catch (DBus.Error e) {
37 stderr.printf("Cannot access system DBus bus: %s\n", e.message);
41 bus_name = DBus.bus_get_unique_name(sbus.get_connection());
42 zavai.log.info("My bus name: " + bus_name);
44 dynamic DBus.Object tmp_dbus = sbus.get_object(
45 "org.freedesktop.DBus",
46 "/org/freedesktop/DBus",
47 "org.freedesktop.DBus");
48 bus_name = "org.enricozini.zavai";
49 uint res = tmp_dbus.RequestName(bus_name, (uint)DBus.NameFlag.DO_NOT_QUEUE);
52 case DBus.RequestNameReply.PRIMARY_OWNER:
53 zavai.log.info("Registered to dbus as " + bus_name);
55 case DBus.RequestNameReply.IN_QUEUE:
56 zavai.log.info("In queue, but I asked not to");
58 case DBus.RequestNameReply.EXISTS:
59 zavai.log.info(bus_name + " already exists");
61 case DBus.RequestNameReply.ALREADY_OWNER:
62 zavai.log.info("I already own the name " + bus_name + " but I do not remember asking for it");
67 public void shutdown()
69 // Shutdown in reverse registration order
70 for (weak List<Resource> i = resources; i != null; i = i.next)
74 public void register(Resource obj)
76 resources.prepend(obj);
80 public zavai.Registry registry;