On Sun, Feb 24, 2013 at 12:39:29PM +0900, FUJITA Tomonori wrote:
> Why a source needs to send an event in the first place?

Basically looks good. Some minor nits inlined

> 
> 
> diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
> index a9895a2..5934126 100644
> --- a/ryu/base/app_manager.py
> +++ b/ryu/base/app_manager.py
> @@ -68,15 +68,20 @@ class RyuApp(object):
>          self.event_handlers.setdefault(ev_cls, [])
>          self.event_handlers[ev_cls].append(handler)
>  
> -    def register_observer(self, ev_cls, name):
> -        self.observers.setdefault(ev_cls, [])
> -        self.observers[ev_cls].append(name)
> +    def register_observer(self, ev_cls, name, states=[]):

[] in default argument should be avoided.
       def register_observer(self, ev_cls, name, states=None):
           states = states or []

> +        self.observers.setdefault(ev_cls, {})
> +        self.observers[ev_cls][name] = states

           self.observers.setdefault(ev_cls, {})[name] = states

>  
>      def get_handlers(self, ev):
>          return self.event_handlers.get(ev.__class__, [])
>  
> -    def get_observers(self, ev):
> -        return self.observers.get(ev.__class__, [])
> +    def get_observers(self, ev, state):
> +        observers = []
> +        for k, v in self.observers.get(ev.__class__, {}).iteritems():
> +            if not state or not v or state in v:
> +                observers.append(k)
> +
> +        return observers
>  
>      def _event_loop(self):
>          while True:
> @@ -97,8 +102,8 @@ class RyuApp(object):
>              LOG.debug("EVENT LOST %s->%s %s" %
>                        (self.name, name, ev.__class__.__name__))
>  
> -    def send_event_to_observers(self, ev):
> -        for observer in self.get_observers(ev):
> +    def send_event_to_observers(self, ev, state=None):
> +        for observer in self.get_observers(ev, state):
>              self.send_event(observer, ev)
>  
>      def close(self):
> @@ -182,7 +187,8 @@ class AppManager(object):
>                      name = m.observer.split('.')[-1]
>                      if name in SERVICE_BRICKS:
>                          brick = SERVICE_BRICKS[name]
> -                        brick.register_observer(m.ev_cls, i.name)
> +                        brick.register_observer(m.ev_cls, i.name,
> +                                                m.dispatchers)
>  
>          for brick, i in SERVICE_BRICKS.items():
>              LOG.debug("BRICK %s" % brick)
> diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py
> index 9dc745a..38c4fe9 100644
> --- a/ryu/controller/controller.py
> +++ b/ryu/controller/controller.py
> @@ -141,7 +141,7 @@ class Datapath(object):
>          self.state = state
>          ev = ofp_event.EventOFPStateChange(self)
>          ev.state = state
> -        self.ofp_brick.send_event_to_observers(ev)
> +        self.ofp_brick.send_event_to_observers(ev, state)
>  
>      def set_version(self, version):
>          assert version in self.supported_ofp_version
> @@ -175,7 +175,7 @@ class Datapath(object):
>                      if self.state in handler.dispatchers:
>                          handler(ev)
>  
> -                self.ofp_brick.send_event_to_observers(ev)
> +                self.ofp_brick.send_event_to_observers(ev, self.state)
>  
>                  buf = buf[required_len:]
>                  required_len = ofproto_common.OFP_HEADER_SIZE
> 
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_feb
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 

-- 
yamahata

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to