Try again to set alarms
authorEnrico Zini <enrico@enricozini.org>
Mon, 17 Aug 2009 14:35:31 +0000 (15:35 +0100)
committerEnrico Zini <enrico@enricozini.org>
Mon, 17 Aug 2009 14:35:31 +0000 (15:35 +0100)
src/clock.vala
src/registry.vala

index 083b566529fc88da258c6d083a0786f8f6493388..928bf69933ce759bfe86be807b093cb74b31f61c 100644 (file)
@@ -105,8 +105,8 @@ public class Clock: zavai.Service
         if (alarms != null)
         {
             try {
-                otimed_alarm.ClearAlarm((string)null);
-                otimed_alarm.SetAlarm((string)null, alarms.data.deadline);
+                otimed_alarm.ClearAlarm("");
+                otimed_alarm.SetAlarm("", alarms.data.deadline);
             } catch (Error e) {
                 zavai.log.error("Cannot reschedule alarms: " + e.message);
             }
index 1a3d0016e590db81298a5b8721e50f43b276c768..20051db25c69c9a71104b602af1be48517f2b228 100644 (file)
@@ -128,62 +128,6 @@ stderr.printf("SERVICE %s stopped\n", name);
        }
 }
 
-// class Service(Resource):
-//     "Service that is activated only when someone is listening"
-//     def __init__(self, types = []):
-//         """
-//         Initialise a service that can emit signals for the given event types
-//         """
-//         super(Service, self).__init__()
-//         self.callbacks = dict()
-//         for t in types:
-//             self.callbacks[t] = set()
-//         self.started = False
-// 
-//     def notify(self, type, *args, **kw):
-//         "Call all callbacks with the given parameters"
-//         for cb in self.callbacks[type]:
-//             cb(*args, **kw)
-// 
-//     def has_callbacks(self):
-//         for i in self.callbacks.values():
-//             if i: return True
-//         return False
-// 
-//     def connect(self, type, callback):
-//         "Connect a callback to this resource, activating it if needed"
-//         do_start = not self.has_callbacks()
-//         self.callbacks[type].add(callback)
-//         if do_start:
-//             self.start()
-//             self.started = True
-// 
-//     def disconnect(self, type, callback):
-//         "Disconnect a callback to this resource, activating it if needed"
-//         if not self.has_callbacks(): return
-//         self.callbacks[type].discard(callback)
-//         if not self.has_callbacks():
-//             self.stop()
-//             self.started = False
-
-
-// import zavai
-// import gtk
-// 
-// def get_parent(s):
-//     "Get the parent name for s"
-//     pos = s.rfind(".")
-//     if pos == -1: return None
-//     res = s[:pos]
-//     if res == "menu": return None
-//     return res
-// 
-// def default_label(s):
-//     "Compute a default label given the last element of a path"
-//     pos = s.rfind(".")
-//     if pos == -1: return s.capitalize()
-//     return s[pos+1:].capitalize()
-
 public class Registry : Object, Resource
 {
        HashMap<string, Resource> memb_resources;
@@ -192,6 +136,7 @@ public class Registry : Object, Resource
        HashMap<string, Menu> memb_menus;
        protected ArrayList<Resource> registration_order;
        public DBus.Connection sbus;
+    public string bus_name;
 
        public Registry()
        {
@@ -201,6 +146,34 @@ public class Registry : Object, Resource
                memb_menus = new HashMap<string, Menu>(str_hash, str_equal);
                registration_order = new ArrayList<Resource>();
                sbus = DBus.Bus.get(DBus.BusType.SYSTEM);
+
+/*
+stderr.printf("ZA1\n");
+        dynamic DBus.Object tmp_dbus = sbus.get_object(
+            "org.freedesktop.DBus",
+            "/org/freedesktop/DBus",
+            "org.freedesktop.DBus");
+stderr.printf("ZA2\n");
+        bus_name = "org.freedesktop.zavai";
+        uint res = tmp_dbus.RequestName(bus_name, (uint)DBus.NameFlag.DO_NOT_QUEUE);
+        stderr.printf("RN: %u\n", res);
+        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;
+        }
+stderr.printf("ZA3\n");
+        */
        }
 
        public void shutdown()
@@ -280,117 +253,6 @@ public class Registry : Object, Resource
        }
 }
 
-// class Registry(object):
-//     """Collection of resources.
-// 
-//     Various factories can be registered by name on the registry. Then when an
-//     object is requested for the first time, it is created using the factory.
-//     When it is requested again, the existing object is reused.
-//     """
-// 
-//     def __init__(self):
-//         self.factories = dict()
-//         self.objects = dict()
-//         self.labels = dict()
-// 
-//     def register(self, obj, name=None):
-//         """Register an object at the given path.
-// 
-//         Name the path to this object, like "menu.gps.monitor".
-//         """
-//         if name is None:
-//             name = obj.props.name
-// 
-//         if name in self.objects:
-//             return KeyError("%s is already registered", name)
-//         zavai.info("Registering", name)
-//         self.objects[name] = obj
-// 
-//         if name.startswith("menu."):
-//             self.add_to_menu(name)
-// 
-//     def register_factory(self, fac, name, label = None):
-//         """Register an object factory at the given path.
-// 
-//         Name the path to this object, like "menu.gps.monitor".
-//         """
-//         if name in self.factories:
-//             return KeyError("Factory %s is already registered", name)
-//         zavai.info("Registering factory", name)
-//         self.factories[name] = fac
-//         if label is not None: self.labels[name] = label
-// 
-//     def add_to_menu(self, name):
-//         "Add the applet with the given name to the menu structure"
-//         parent = get_parent(name)
-//         if parent is not None:
-//             zavai.info("Add to menu", name, parent)
-//             menu = self.menu(parent)
-// 
-//             obj = self.resource(name)
-//             if isinstance(obj, gtk.ToggleAction):
-//                 menu.add_child(zavai.ToggleButton(self, name, action=obj))
-//             elif isinstance(obj, gtk.Action):
-//                 menu.add_child(zavai.LinkButton(self, name, action=obj))
-//             else:
-//                 menu.add_child(zavai.LinkButton(self, name, self.label(name)))
-// 
-//     def label(self, name):
-//         "Return the label for the object with the given name"
-//         res = self.labels.get(name)
-//         if res is not None:
-//             return res
-//         try:
-//             obj = self.resource(name)
-//             return obj.props.label
-//         except:
-//             return default_label(name)
-// 
-//     def resource(self, name):
-//         """Get a resource from the registry.
-// 
-//         If no resource exists at `name` but there is a factory, instantiate the
-//         object using the factory.
-// 
-//         If not even a factory exists at `name`, returns None.
-//         """
-//         res = self.objects.get(name, None)
-//         if res is None:
-//             fac = self.factories.get(name, None)
-//             if fac is not None:
-//                 res = self.objects[name] = fac(self, name)
-//         return res
-// 
-//     def menu(self, name):
-//         """Get a menu resource, automatically creating it if it is missing.
-// 
-//         Menus are created automatically linked to a parent menu, according to
-//         the hierarchy in `name`.
-//         """
-//         res = self.resource(name)
-//         if res is None:
-//             # Check if it is a toplevel menu
-//             if name.startswith("menu."):
-//                 parent = get_parent(name[5:])
-//                 if parent is not None:
-//                     parent = "menu." + parent
-//             else:
-//                 parent = get_parent(name)
-// 
-//             res = zavai.Menu(self, name, parent)
-//             self.register(res, name)
-//         return res
-// 
-//     def shutdown(self):
-//         """Shut down all objects in this Registry.
-// 
-//         After shutting down, all objects cannot be used anymore"""
-//         for o in self.objects.itervalues():
-//             if isinstance(o, Resource):
-//                 o.shutdown()
-//         self.objects.clear()
-// 
-
 zavai.Registry registry;
 
 }