Mercurial > libervia-pubsub
changeset 32:ddc08757ec1d
Fire up several component.IServices that match the backend Services.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Tue, 26 Oct 2004 16:30:21 +0000 |
parents | fa866793075d |
children | 7e9bee656986 |
files | idavoll/idavoll.py |
diffstat | 1 files changed, 85 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/idavoll/idavoll.py Tue Oct 26 16:29:44 2004 +0000 +++ b/idavoll/idavoll.py Tue Oct 26 16:30:21 2004 +0000 @@ -1,6 +1,7 @@ from twisted.protocols.jabber import component from twisted.application import service from twisted.python import components +import backend import memory_backend import pubsub import xmpp_error @@ -20,84 +21,103 @@ class IdavollService(component.Service): - def componentConnected(self, xmlstream): - self.xmlstream = xmlstream - xmlstream.addObserver(VERSION, self.onVersion, 1) - xmlstream.addObserver(DISCO_INFO, self.onDiscoInfo, 1) - xmlstream.addObserver(DISCO_ITEMS, self.onDiscoItems, 1) - xmlstream.addObserver(IQ_GET, self.iqFallback, -1) - xmlstream.addObserver(IQ_SET, self.iqFallback, -1) + def componentConnected(self, xmlstream): + self.xmlstream = xmlstream + xmlstream.addObserver(VERSION, self.onVersion, 1) + xmlstream.addObserver(DISCO_INFO, self.onDiscoInfo, 1) + xmlstream.addObserver(DISCO_ITEMS, self.onDiscoItems, 1) + xmlstream.addObserver(IQ_GET, self.iqFallback, -1) + xmlstream.addObserver(IQ_SET, self.iqFallback, -1) - def getFeatures(self, node): - if not node: - return [NS_DISCO_ITEMS, NS_VERSION] - - def onVersion(self, iq): - iq.swapAttributeValues("to", "from") - iq["type"] = "result" - name = iq.addElement("name", None, 'Idavoll') - version = iq.addElement("version", None, '0.1') - self.send(iq) - iq.handled = True + def getFeatures(self, node): + if not node: + return [NS_DISCO_ITEMS, NS_VERSION] + + def onVersion(self, iq): + iq.swapAttributeValues("to", "from") + iq["type"] = "result" + name = iq.addElement("name", None, 'Idavoll') + version = iq.addElement("version", None, '0.1') + self.send(iq) + iq.handled = True - def onDiscoInfo(self, iq): - identities = [] - features = [] - node = iq.query.getAttribute("node") + def onDiscoInfo(self, iq): + identities = [] + features = [] + node = iq.query.getAttribute("node") - for c in self.parent: - if components.implements(c, component.IService): - if hasattr(c, "getIdentities"): - identities.extend(c.getIdentities(node)) - if hasattr(c, "getFeatures"): - features.extend(c.getFeatures(node)) + for c in self.parent: + if components.implements(c, component.IService): + if hasattr(c, "getIdentities"): + identities.extend(c.getIdentities(node)) + if hasattr(c, "getFeatures"): + features.extend(c.getFeatures(node)) - if not features and not identities and not node: - xmpp_error.error_from_iq(iq, 'item-not-found') - else: - iq.swapAttributeValues("to", "from") - iq["type"] = "result" - for identity in identities: - i = iq.query.addElement("identity") - i.attributes = identity - print features - for feature in features: - f = iq.query.addElement("feature") - f["var"] = feature + if not features and not identities and not node: + xmpp_error.error_from_iq(iq, 'item-not-found') + else: + iq.swapAttributeValues("to", "from") + iq["type"] = "result" + for identity in identities: + i = iq.query.addElement("identity") + i.attributes = identity + print features + for feature in features: + f = iq.query.addElement("feature") + f["var"] = feature - self.send(iq) - iq.handled = True + self.send(iq) + iq.handled = True - def onDiscoItems(self, iq): - iq.swapAttributeValues("to", "from") - iq["type"] = "result" - iq.query.children = [] - self.send(iq) - - def iqFallback(self, iq): - if iq.handled == True: - return + def onDiscoItems(self, iq): + iq.swapAttributeValues("to", "from") + iq["type"] = "result" + iq.query.children = [] + self.send(iq) + + def iqFallback(self, iq): + if iq.handled == True: + return - self.send(xmpp_error.error_from_iq(iq, 'service-unavailable')) + self.send(xmpp_error.error_from_iq(iq, 'service-unavailable')) def makeService(config): - serviceCollection = service.MultiService() + serviceCollection = service.MultiService() - b = memory_backend.MemoryBackendService() + # set up Jabber Component + sm = component.buildServiceManager(config["jid"], config["secret"], + ("tcp:%s:%s" % (config["rhost"], config["rport"]))) + + b = memory_backend + bs = b.BackendService() - # set up Jabber Component - c = component.buildServiceManager(config["jid"], config["secret"], - ("tcp:%s:%s" % (config["rhost"], config["rport"]))) + component.IService(bs).setServiceParent(sm) + + bsc = b.PublishService() + bsc.setServiceParent(bs) + component.IService(bsc).setServiceParent(sm) + + bsc = b.NotificationService() + bsc.setServiceParent(bs) + component.IService(bsc).setServiceParent(sm) - s = component.IService(b) - s.jid = config["jid"] - s.setServiceParent(c) + bsc = b.NodeCreationService() + bsc.setServiceParent(bs) + component.IService(bsc).setServiceParent(sm) + + bsc = b.NotificationService() + bsc.setServiceParent(bs) + component.IService(bsc).setServiceParent(sm) - s = IdavollService() - s.setServiceParent(c) + bsc = b.SubscriptionService() + bsc.setServiceParent(bs) + component.IService(bsc).setServiceParent(sm) - c.setServiceParent(serviceCollection) + s = IdavollService() + s.setServiceParent(sm) - # other stuff + sm.setServiceParent(serviceCollection) - return c + # other stuff + + return sm