Duncan Webb wrote: > Dirk Meyer wrote: >> Duncan Webb wrote: >>> Dirk Meyer wrote: >>>> Jason Tackaberry wrote: >>>>> On Sun, 2007-08-26 at 07:59 -0700, Michael Beal wrote: >>>>>> Wouldn't it make sense to use SQLite for this instead? The record >>>>>> schedule is currently a simple DB file in XML format being accessed by >>>>>> multiple threads. I can see where a race condition could be created >>>>> Freevo 2 will use an sqlite-backed EPG (kaa.epg). >>>>> >>>>> I have no idea if it would be worth Freevo 1 going this route. It may >>>>> well be more work than you'd expect. But on the other hand, I also like >>>>> the idea of Freevo 1 increasingly using kaa modules, as it's an >>>>> excellent source of testing for these modules on which Freevo 2 is being >>>>> built. >>>> Could be possible. It should be easy to replace the freevo mainloop >>>> with kaa.notifier at a minimum level so that it will work. >>>> kaa.notifier running is a must-have for kaa.epg. I could do it. >>>> Should I? >>> >>> By all means, yes that would be really good. The recordserver code has >>> become rather horrid :( >> >> Ah, you are talking about the recordserver. Sorry, I meant Freevo >> itself. The recordserver is using twisted, right? I guess someone >> should do a rewrite of the communication code using the XMLRPC code >> From kaa.base and kaa.notifier as loop. > > You mean replacing the rc code, that would be great too.
I did a small change, patch attached. Do not include it directly, it breaks helpers using the rc module, I only tested freevo itself. I removed the real mainllop part from rc. The event stuff is handled by kaa.notifier. This means Event object can just call a post() method on themself, no need for the global rc object. If somethign wants to listen to events, add a global eventhandler. I have done this in main.py, The self.event_callback is removed from rc. If someone else wants to get notified, run kaa.notifier.EventHandler(callback_to_call).register() Since all plugins require the rc module to call them, there is a poll function now calling the input plugins and the time based plugins. This function is called with a 0.01 sec timer. A future version of Freevo should not require this, plugin can register a poll function with a timer on their own, they can also register socket callbacks. For more details see http://freevo.sourceforge.net/cgi-bin/freevo-2.0/SourceDoc/KaaNotifier I hope this small patch is a path for you to get rid of twisted and give freevo a real mainloop. Dischi
Index: src/rc.py =================================================================== --- src/rc.py (revision 9860) +++ src/rc.py (working copy) @@ -35,6 +35,8 @@ import thread import types +import kaa.notifier + import config import evdev @@ -125,21 +127,6 @@ return get_singleton().resume() -def poll(): - """ - poll all registered callbacks - """ - return get_singleton().poll() - - -def get_event(blocking=False): - """ - get next event. If blocking is True, this function will block until - there is a new event (also call all registered callbacks while waiting) - """ - return get_singleton().get_event(blocking) - - # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- @@ -489,8 +476,6 @@ self.app = None self.context = 'menu' - self.queue = [] - self.event_callback = None self.callbacks = [] self.shutdown_callbacks = [] self.poll_objects = [] @@ -498,6 +483,7 @@ self.lock = thread.allocate_lock() # last time we stopped sleeping self.sleep_timer = 0 + kaa.notifier.Timer(self.poll).start(0.01) def set_app(self, app, context): @@ -526,19 +512,11 @@ """ add event to the queue """ - self.lock.acquire() - try: - if not isinstance(e, Event): - self.queue += [ Event(e, context=self.context) ] - else: - self.queue += [ e ] - finally: - self.lock.release() + if not isinstance(e, Event): + e = Event(e, context=self.context) + e.post() - if self.event_callback: - self.event_callback() - def key_event_mapper(self, key): """ map key to event based on current context @@ -622,6 +600,12 @@ """ poll all registered functions """ + # search all input objects for new events + for i in self.inputs: + e = i.poll(self) + if e: + self.post_event(self.key_event_mapper(e)) + # run all registered callbacks for c in copy.copy(self.callbacks): if c[2] == c[3]: @@ -640,57 +624,3 @@ c[0](*c[4]) else: c[3] += 1 - - - def get_event(self, blocking=False): - """ - get next event. If blocking is True, this function will block until - there is a new event (also call all registered callbacks while waiting) - """ - if blocking: - while 1: - # get non blocking event - event = self.get_event(False) - if event: - return event - # poll everything - self.poll() - - # wait some time - duration = 0.01 - (time.time() - self.sleep_timer) - if duration > 0: - time.sleep(duration) - self.sleep_timer = time.time() - - - # search for events in the queue - if len(self.queue): - self.lock.acquire() - try: - try: - ret = self.queue[0] - del self.queue[0] - return ret - except IndexError: - pass - finally: - self.lock.release() - - # search all input objects for new events - for i in self.inputs: - e = i.poll(self) - if e: - return self.key_event_mapper(e) - - return None - - - - def subscribe(self, event_callback=None): - """ - subscribe to 'post_event' - """ - if not event_callback: - return - - self.event_callback = event_callback Index: src/main.py =================================================================== --- src/main.py (revision 9860) +++ src/main.py (working copy) @@ -56,6 +56,7 @@ import config import kaa.metadata as mmpython + import kaa.notifier import kaa.imlib2 as Image @@ -248,8 +249,9 @@ self.eventlistener_plugins.append(p) else: self.eventhandler_plugins.append(p) + kaa.notifier.EventHandler(self.eventhandler).register() + - def eventhandler(self, event): """ event handling function for the main loop @@ -317,15 +319,6 @@ _debug_('no target for events given') - def run(self): - """ - the real main loop - """ - while 1: - self.eventhandler(rc.get_event(True)) - - - def signal_handler(sig, frame): """ the signal handler to shut down freevo @@ -469,9 +462,12 @@ # Kick off the main menu loop _debug_('Main loop starting...',2) - MainTread().run() + MainTread() + + kaa.notifier.loop() + except KeyboardInterrupt: print 'Shutdown by keyboard interrupt' # Shutdown the application Index: src/event.py =================================================================== --- src/event.py (revision 9860) +++ src/event.py (working copy) @@ -28,8 +28,9 @@ # # ----------------------------------------------------------------------- +import kaa.notifier -class Event: +class Event(kaa.notifier.Event): """ an event is passed to the different eventhandlers in Freevo to activate some action.
-- Backup not found! A)bort, R)etry or P)anic?
pgpVsRe4h3LWc.pgp
Description: PGP signature
------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________ Freevo-devel mailing list Freevo-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/freevo-devel