Package elisa :: Package plugins :: Package good :: Package twisted_plugin :: Module twisted_pb_service
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.good.twisted_plugin.twisted_pb_service

 1  # -*- coding: utf-8 -*- 
 2  # Elisa - Home multimedia server 
 3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
 4  # All rights reserved. 
 5  # 
 6  # This file is available under one of two license agreements. 
 7  # 
 8  # This file is licensed under the GPL version 3. 
 9  # See "LICENSE.GPL" in the root of this distribution including a special 
10  # exception to use Elisa with Fluendo's plugins. 
11  # 
12  # The GPL part of Elisa is also available under a commercial licensing 
13  # agreement from Fluendo. 
14  # See "LICENSE.Elisa" in the root directory of this distribution package 
15  # for details on that license. 
16   
17  """ 
18  """ 
19   
20  __maintainer__ = "Philippe Normand <philippe@fluendo.com>" 
21   
22  from elisa.base_components import service_provider 
23  from elisa.core import common, component 
24  from elisa.core.bus.bus_message import PBReferenceable, ComponentsLoaded 
25  from twisted.spread import pb 
26  from twisted.internet import reactor 
27  import new 
28   
29 -class Root(pb.Root):
30 pass
31
32 -class TwistedPBService(service_provider.ServiceProvider):
33 """ 34 35 36 """ 37 38 default_config = {'port': '8789'} 39 config_doc = {'port': 'TCP port to listen on'} 40
41 - def initialize(self):
42 self.root = Root() 43 port = int(self.config.get('port')) 44 try: 45 reactor.listenTCP(port, pb.PBServerFactory(self.root)) 46 except Exception, error: 47 raise component.InitializeFailure(self.name,str(error)) 48 common.application.bus.register(self._register_new_reference, 49 PBReferenceable)
50
51 - def _register_new_reference(self, msg, sender):
52 method_name = 'remote_%s' % msg.name 53 func = lambda s: msg.reference 54 func.__name__ = method_name 55 56 self.debug("Registering %r -> %r", method_name, func) 57 method = new.instancemethod(func, self.root, Root) 58 setattr(self.root, method_name, method)
59