Update of /cvsroot/freevo/freevo/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13806/src

Modified Files:
        childapp.py main.py rc.py 
Log Message:
More event / main loop cleanup. rc.py has a changed interface now

Index: childapp.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/childapp.py,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** childapp.py 29 May 2004 19:06:46 -0000      1.53
--- childapp.py 30 May 2004 18:27:53 -0000      1.54
***************
*** 10,13 ****
--- 10,16 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.54  2004/05/30 18:27:53  dischi
+ # More event / main loop cleanup. rc.py has a changed interface now
+ #
  # Revision 1.53  2004/05/29 19:06:46  dischi
  # register poll function to rc
***************
*** 16,29 ****
  # let the child stdout handled by main
  #
- # Revision 1.51  2004/03/14 11:43:08  dischi
- # prevent crash
- #
- # Revision 1.50  2004/02/19 04:43:47  gsbarbieri
- # Fix string problems and add a work around to avoid isAlive() being called
- # during __init__()
- #
- # Revision 1.49  2004/01/12 19:52:46  dischi
- # store return value for ChildApp2
- #
  # -----------------------------------------------------------------------
  # Freevo - A Home Theater PC framework
--- 19,22 ----
***************
*** 54,58 ****
  import threading, thread
  import signal
- import traceback
  import copy
  
--- 47,50 ----
***************
*** 63,97 ****
  
  from event import *
- import rc
- 
- # list of all ChildApp (internal use)
- __all_childapps__ = []
- 
- # list of all running ChildApp2 children
- running_children = []
- 
- 
- def shutdown():
-     """
-     shutdown all running childapps
-     """
-     global __all_childapps__
-     global running_children
-     
-     if not len(__all_childapps__):
-         return
-         
-     print '%d child(s) still running, terminate them' % len(__all_childapps__)
- 
-     while running_children:
-         print 'shutting down %s' % running_children[0].binary
-         running_children[0].stop()
-     while __all_childapps__:
-         print 'shutting down %s' % __all_childapps__[0].binary
-         __all_childapps__[0].kill()
  
  
- 
-         
  class ChildApp:
      """
--- 55,60 ----
***************
*** 101,113 ****
  
      def __init__(self, app, debugname=None, doeslogging=0):
-         global __all_childapps__
-         __all_childapps__.append(self)
- 
          self.lock = thread.allocate_lock()
  
-         if config.DEBUG > 1:
-             _debug_('starting new child: %s', app)
-             traceback.print_stack()
- 
          prio = 0
  
--- 64,69 ----
***************
*** 226,237 ****
          
      def kill(self, signal=15):
-         global __all_childapps__
- 
-         if self in __all_childapps__:
-             __all_childapps__.remove(self)
-             
-         if config.DEBUG > 1:
-             _debug_('killing my child')
-             traceback.print_stack()
  
          # killed already
--- 182,185 ----
***************
*** 374,378 ****
                      if self.logger:
                          self.logger.write(saved + lines[0]+'\n')
!                     rc.callback(self.callback, saved + lines[0])
                      saved = ''
  
--- 322,326 ----
                      if self.logger:
                          self.logger.write(saved + lines[0]+'\n')
!                     rc.register(self.callback, saved + lines[0])
                      saved = ''
  
***************
*** 386,390 ****
                              if self.logger:
                                  self.logger.write(line+'\n')
!                             rc.callback(self.callback, line)
                      else:
                          # Send all lines to the app
--- 334,338 ----
                              if self.logger:
                                  self.logger.write(line+'\n')
!                             rc.register(self.callback, line)
                      else:
                          # Send all lines to the app
***************
*** 392,396 ****
                              if self.logger:
                                  self.logger.write(line+'\n')
!                             rc.callback(self.callback, line)
                          
  
--- 340,344 ----
                              if self.logger:
                                  self.logger.write(line+'\n')
!                             rc.register(self.callback, line)
                          
  
***************
*** 402,407 ****
      """
      def __init__(self, app, debugname=None, doeslogging=0, stop_osd=2):
-         global running_children
-         running_children.append(self)
          rc.register(self)
          
--- 350,353 ----
***************
*** 453,462 ****
          stop the child
          """
-         try:
-             global running_children
-             running_children.remove(self)
-         except ValueError:
-             return
-         
          rc.unregister(self)
  
--- 399,402 ----

Index: rc.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/rc.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** rc.py       29 May 2004 19:06:26 -0000      1.33
--- rc.py       30 May 2004 18:27:53 -0000      1.34
***************
*** 10,13 ****
--- 10,16 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.34  2004/05/30 18:27:53  dischi
+ # More event / main loop cleanup. rc.py has a changed interface now
+ #
  # Revision 1.33  2004/05/29 19:06:26  dischi
  # move some code from main to rc, create main class
***************
*** 19,38 ****
  # let the child stdout handled by main
  #
- # Revision 1.30  2004/02/28 17:30:59  dischi
- # fix crash for helper
- #
- # Revision 1.29  2004/02/27 20:12:16  dischi
- # reworked rc.py to make several classes
- #
- # Revision 1.28  2003/12/14 17:24:59  dischi
- # cleanup
- #
- # Revision 1.27  2003/11/02 10:50:15  dischi
- # better error handling
- #
- # Revision 1.26  2003/10/26 17:04:26  dischi
- # Patch from Soenke Schwardt to use the time to fix repeat problems with
- # some remote receiver.
- #
  # -----------------------------------------------------------------------
  # Freevo - A Home Theater PC framework
--- 22,25 ----
***************
*** 60,66 ****
  import copy
  import time
  
  import config
! import util
  from event import Event, BUTTON
  
--- 47,55 ----
  import copy
  import time
+ import thread
+ import types
  
  import config
! 
  from event import Event, BUTTON
  
***************
*** 68,71 ****
--- 57,61 ----
  _singleton = None
  
+ 
  def get_singleton(**kwargs):
      """
***************
*** 76,80 ****
      # One-time init
      if _singleton == None:
!         _singleton = util.SynchronizedObject(RemoteControl(**kwargs))
          
      return _singleton
--- 66,70 ----
      # One-time init
      if _singleton == None:
!         _singleton = EventHandler(**kwargs)
          
      return _singleton
***************
*** 107,122 ****
      set the context (map with button->event transformation
      """
!     get_singleton().set_context(context)
! 
! 
! def callback(function, *arg):
!     get_singleton().one_time_callbacks.append((function, arg))
  
  
! def register(object):
      """
      register an object to the main loop
      """
!     get_singleton().register(object)
  
  
--- 97,108 ----
      set the context (map with button->event transformation
      """
!     return get_singleton().set_context(context)
  
  
! def register(object, *arg):
      """
      register an object to the main loop
      """
!     return get_singleton().register(object, *arg)
  
  
***************
*** 125,129 ****
      unregister an object from the main loop
      """
!     get_singleton().unregister(object)
  
  
--- 111,137 ----
      unregister an object from the main loop
      """
!     return get_singleton().unregister(object)
! 
! 
! def shutdown():
!     """
!     shutdown the rc
!     """
!     return get_singleton().shutdown()
! 
! 
! 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)
  
  
***************
*** 295,299 ****
  # --------------------------------------------------------------------------------
      
! class RemoteControl:
      """
      Class to transform input keys or buttons into events. This class
--- 303,307 ----
  # --------------------------------------------------------------------------------
      
! class EventHandler:
      """
      Class to transform input keys or buttons into events. This class
***************
*** 318,329 ****
              self.inputs.append(Network())
  
!         self.app                      = None
!         self.context                  = 'menu'
!         self.queue                    = []
!         self.event_callback           = None
!         self.one_time_callbacks       = []
!         self.poll_objects             = []
  
      def set_app(self, app, context):
          self.app     = app
          self.context = context
--- 326,343 ----
              self.inputs.append(Network())
  
!         self.app                = None
!         self.context            = 'menu'
!         self.queue              = []
!         self.event_callback     = None
!         self.one_time_callbacks = []
!         self.poll_objects       = []
!         # lock all critical parts
!         self.lock               = thread.allocate_lock()
! 
  
      def set_app(self, app, context):
+         """
+         set default eventhandler and context
+         """
          self.app     = app
          self.context = context
***************
*** 331,346 ****
--- 345,371 ----
  
      def get_app(self):
+         """
+         get current eventhandler (app)
+         """
          return self.app
  
  
      def set_context(self, context):
+         """
+         set context for key mapping
+         """
          self.context = context
          
  
      def post_event(self, e):
+         """
+         add event to the queue
+         """
+         self.lock.acquire()
          if not isinstance(e, Event):
              self.queue += [ Event(e, context=self.context) ]
          else:
              self.queue += [ e ]
+         self.lock.release()
  
          if self.event_callback:
***************
*** 349,352 ****
--- 374,380 ----
  
      def key_event_mapper(self, key):
+         """
+         map key to event based on current context
+         """
          if not key:
              return None
***************
*** 366,375 ****
  
  
!     def register(self, object):
          """
          register an object to the main loop
          """
!         if not object in self.poll_objects:
              self.poll_objects.append(object)
  
          
--- 394,407 ----
  
  
!     def register(self, object, *arg):
          """
          register an object to the main loop
          """
!         self.lock.acquire()
!         if type(object) in [ types.FunctionType, types.MethodType ]:
!             self.one_time_callbacks.append((object, arg))
!         elif not object in self.poll_objects:
              self.poll_objects.append(object)
+         self.lock.release()
  
          
***************
*** 378,397 ****
          unregister an object from the main loop
          """
          if object in self.poll_objects:
              self.poll_objects.remove(object)
  
          
      def poll(self):
          """
!         main loop
          """
          # run all registered callbacks
          while len(self.one_time_callbacks) > 0:
              callback, arg = self.one_time_callbacks.pop(0)
              callback(*arg)
  
          # run all registered objects having a poll() function
          # using poll_counter and poll_interval (if given)
!         for p in self.poll_objects:
              if hasattr(p, 'poll_counter'):
                  if not (self.app and p.poll_menu_only):
--- 410,442 ----
          unregister an object from the main loop
          """
+         self.lock.acquire()
          if object in self.poll_objects:
              self.poll_objects.remove(object)
+         self.lock.release()
  
          
+     def shutdown(self):
+         """
+         shutdown the rc
+         """
+         for p in copy.copy(self.poll_objects):
+             if hasattr(p, 'stop'):
+                 p.stop()
+ 
+ 
      def poll(self):
          """
!         poll all registered functions
          """
          # run all registered callbacks
          while len(self.one_time_callbacks) > 0:
+             self.lock.acquire()
              callback, arg = self.one_time_callbacks.pop(0)
+             self.lock.release()
              callback(*arg)
  
          # run all registered objects having a poll() function
          # using poll_counter and poll_interval (if given)
!         for p in copy.copy(self.poll_objects):
              if hasattr(p, 'poll_counter'):
                  if not (self.app and p.poll_menu_only):
***************
*** 403,410 ****
--- 448,475 ----
                  p.poll()
  
+ 
+ 
+     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
+                 time.sleep(0.01)
+ 
          # search for events in the queue
          if len(self.queue):
+             self.lock.acquire()
              ret = self.queue[0]
              del self.queue[0]
+             self.lock.release()
              return ret
  
***************
*** 418,423 ****
  
  
      def subscribe(self, event_callback=None):
!         # Only one thing can call poll() so we only handle one subscriber.
          if not event_callback:
              return
--- 483,491 ----
  
  
+ 
      def subscribe(self, event_callback=None):
!         """
!         subscribe to 'post_event'
!         """
          if not event_callback:
              return

Index: main.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/main.py,v
retrieving revision 1.122
retrieving revision 1.123
diff -C2 -d -r1.122 -r1.123
*** main.py     29 May 2004 19:06:26 -0000      1.122
--- main.py     30 May 2004 18:27:53 -0000      1.123
***************
*** 11,14 ****
--- 11,17 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.123  2004/05/30 18:27:53  dischi
+ # More event / main loop cleanup. rc.py has a changed interface now
+ #
  # Revision 1.122  2004/05/29 19:06:26  dischi
  # move some code from main to rc, create main class
***************
*** 117,123 ****
  
  
- # Create the remote control object
- rc_object = rc.get_singleton()
- 
  # Create the OSD object
  osd = osd.get_singleton()
--- 120,123 ----
***************
*** 281,286 ****
  
          # Send events to either the current app or the menu handler
!         elif rc_object.app:
!             if not rc_object.app(event):
                  for p in self.eventhandler_plugins:
                      if p.eventhandler(event=event):
--- 281,286 ----
  
          # Send events to either the current app or the menu handler
!         elif rc.app():
!             if not rc.app()(event):
                  for p in self.eventhandler_plugins:
                      if p.eventhandler(event=event):
***************
*** 326,334 ****
          """
          while 1:
!             event = rc_object.poll()
!             if event:
!                 self.eventhandler(event)
!             else:
!                 osd.sleep(0.01)
  
  
--- 326,330 ----
          """
          while 1:
!             self.eventhandler(rc.get_event(True))
  
  



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to