/* * registry - zavai resource registry * * Copyright (C) 2009 Enrico Zini * * 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; either version 2 of the License, or * (at your option) any later version. * * 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using GLib; namespace zavai { public class Registry : Object, Resource { List resources; public DBus.Connection sbus; public string bus_name; public Registry() { resources = new List(); try { sbus = DBus.Bus.get(DBus.BusType.SYSTEM); } catch (DBus.Error e) { stderr.printf("Cannot access system DBus bus: %s\n", e.message); sbus = null; } bus_name = DBus.bus_get_unique_name(sbus.get_connection()); zavai.log.info("My bus name: " + bus_name); dynamic DBus.Object tmp_dbus = sbus.get_object( "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); bus_name = "org.enricozini.zavai"; uint res = tmp_dbus.RequestName(bus_name, (uint)DBus.NameFlag.DO_NOT_QUEUE); switch (res) { case DBus.RequestNameReply.PRIMARY_OWNER: zavai.log.info("Registered to dbus as " + bus_name); break; case DBus.RequestNameReply.IN_QUEUE: zavai.log.info("In queue, but I asked not to"); break; case DBus.RequestNameReply.EXISTS: zavai.log.info(bus_name + " already exists"); break; case DBus.RequestNameReply.ALREADY_OWNER: zavai.log.info("I already own the name " + bus_name + " but I do not remember asking for it"); break; } } public void shutdown() { // Shutdown in reverse registration order for (weak List i = resources; i != null; i = i.next) i.data.shutdown(); } public void register(Resource obj) { resources.prepend(obj); } } public zavai.Registry registry; }