'Ensure that the avatar to be returned to the client is jellyable and
set up disconnection notification to call the realm\'s logout object.'

def _cbLogin(self, result):

    (interface, avatar, logout) = result
    if (not IJellyable.providedBy(avatar)):
        avatar = AsReferenceable(avatar, 'perspective')
    puid = avatar.processUniqueID()
    logout = [logout]
    def maybeLogout():
        if (not logout):
            return
        fn = logout[0]
        del logout[0]
        fn()
    self.broker._localCleanup[puid] = maybeLogout
    self.broker.notifyOnDisconnect(maybeLogout)
    return avatar
