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
26 public class Registry : Object, Resource
28 HashMap<string, Resource> memb_resources;
29 HashMap<string, Service> memb_services;
30 HashMap<string, Applet> memb_applets;
31 HashMap<string, Menu> memb_menus;
32 protected ArrayList<Resource> registration_order;
33 public DBus.Connection sbus;
34 public string bus_name;
38 memb_resources = new HashMap<string, Resource>(str_hash, str_equal);
39 memb_services = new HashMap<string, Service>(str_hash, str_equal);
40 memb_applets = new HashMap<string, Applet>(str_hash, str_equal);
41 memb_menus = new HashMap<string, Menu>(str_hash, str_equal);
42 registration_order = new ArrayList<Resource>();
43 sbus = DBus.Bus.get(DBus.BusType.SYSTEM);
45 bus_name = DBus.bus_get_unique_name(sbus.get_connection());
46 zavai.log.info("My bus name: " + bus_name);
48 dynamic DBus.Object tmp_dbus = sbus.get_object(
49 "org.freedesktop.DBus",
50 "/org/freedesktop/DBus",
51 "org.freedesktop.DBus");
52 bus_name = "org.enricozini.zavai";
53 uint res = tmp_dbus.RequestName(bus_name, (uint)DBus.NameFlag.DO_NOT_QUEUE);
56 case DBus.RequestNameReply.PRIMARY_OWNER:
57 zavai.log.info("Registered to dbus as " + bus_name);
59 case DBus.RequestNameReply.IN_QUEUE:
60 zavai.log.info("In queue, but I asked not to");
62 case DBus.RequestNameReply.EXISTS:
63 zavai.log.info(bus_name + " already exists");
65 case DBus.RequestNameReply.ALREADY_OWNER:
66 zavai.log.info("I already own the name " + bus_name + " but I do not remember asking for it");
71 public void shutdown()
73 // Shutdown in reverse registration order
74 for (int i = registration_order.size - 1; i >= 0; --i)
75 registration_order[i].shutdown();
78 public void register_resource(string name, Resource obj)
80 memb_resources[name] = obj;
81 registration_order.add(obj);
84 public void register_service(Service obj)
86 memb_services[obj.name] = obj;
87 registration_order.add(obj);
90 public void register_applet(string name, Applet obj)
92 memb_applets[name] = obj;
93 registration_order.add(obj);
96 public void register_menu(string name, Menu obj)
98 memb_applets[name] = obj;
99 memb_menus[name] = obj;
100 registration_order.add(obj);
103 public Resource? getr(string name)
105 if (name in memb_resources)
106 return memb_resources[name];
109 log.error("getr: no resource found: " + name);
114 public Service? gets(string name)
116 if (name in memb_services)
117 return memb_services[name];
120 log.error("gets: no service found: " + name);
125 public Applet? geta(string name)
127 if (name in memb_applets)
128 return memb_applets[name];
131 log.error("geta: no applet found: " + name);
136 public Menu? getmenu(string name)
138 if (name in memb_menus)
139 return memb_menus[name];
142 log.error("getmenu: no menu found: " + name);
148 zavai.Registry registry;