Use YowLayerEvent instead of Prop

We cannot use Prop in the __init__ of a YowLayer, since Prop is
initialised only after all the YowLayers are initialized.

Instead, we send a YowLayerEvent containing the values.
This commit is contained in:
moyamo 2015-02-27 16:57:00 +02:00
parent 74a09ad07f
commit ae826b1341

View file

@ -91,9 +91,14 @@ class Session():
YowNetworkLayer YowNetworkLayer
) )
self.stack = YowStack(layers) self.stack = YowStack(layers)
self.stack.setProp(SpectrumLayer.PROP_BACKEND, self.backend) self.stack.broadcastEvent(
self.stack.setProp(SpectrumLayer.PROP_USER, self.user) YowLayerEvent(SpectrumLayer.EVENT_START,
self.stack.setProp(SpectrumLayer.PROP_DB, self.db) backend = self.backend,
user = self.user,
db = self.db,
legacyName = self.legacyName
)
)
def __del__(self): # handleLogoutRequest def __del__(self): # handleLogoutRequest
self.logout() self.logout()
@ -406,19 +411,18 @@ class Session():
if receiptRequested: self.call("notification_ack", (jid, messageId)) if receiptRequested: self.call("notification_ack", (jid, messageId))
class SpectrumLayer(YowInterfaceLayer): class SpectrumLayer(YowInterfaceLayer):
PROP_BACKEND = "yowsup.prop.SpectrumLayer.backend" EVENT_START = "transwhat.event.SpectrumLayer.start"
PROP_USER = "yowsup.prop.SpectrumLayer.user"
PROP_DB = "yowsup.prop.SpectrumLayer.db"
PROP_LEGACYNAME = "yowsup.prop.SpectrumLayer.legacyName"
def __init__(self): def onEvent(self, layerEvent):
super(SpectrumLayer, self).__init__() # We cannot use __init__, since it can take no arguments
self.backend = self.getProp(SpectrumLayer.PROP_BACKEND) if layerEvent.name == SpectrumLayer.EVENT_START:
self.user = self.getProp(SpectrumLayer.PROP_USER) self.backend = layerEvent.getArg("backend")
db = self.getProp(SpectrumLayer.PROP_DB) self.user = layerEvent.getArg("user")
self.buddies = BuddyList(legacyName, db) self.legacyName = layerEvent.getArg("legacyName")
self.legacyName(self.getProp(SpectrumLayer.PROP_LEGACYNAME)) db = layerEvent.getArg("db")
self.bot = Bot(self)
self.buddies = BuddyList(legacyName, db)
self.bot = Bot(self)
@ProtocolEntityCallback("success") @ProtocolEntityCallback("success")
def onAuthSuccess(self, entity): def onAuthSuccess(self, entity):