[Bio] / ModelEditor / MeAGMgr.py Repository:
ViewVC logotype

View of /ModelEditor/MeAGMgr.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (as text) (annotate)
Tue Nov 2 17:48:26 2004 UTC (14 years, 9 months ago) by efrank
Branch: MAIN
CVS Tags: post-st-migration2, pre-wxPython-2515-migration, sc04-finalDay, post-st-migration, before-dynamics-persistence, sc2004-3, lwc, sc2004-4, treatman-lastDay-0, preTreatmanDyn, HEAD
Changes since 1.2: +34 -2 lines
eggbeater

#-----------------------------------------------------------------------------
# Name:        MeAGMgr.py
# Defines:     MeAGMgr.py
#
# History:
#              21Oct04 efrank      First version
#
# Bugs:
#
# RCS-ID:      $Id: MeAGMgr.py,v 1.3 2004/11/02 17:48:26 efrank Exp $
# Copyright:   (c) 2004
# Licence:     See COPYING.TXT
#-----------------------------------------------------------------------------
__revision__ = "$Id: MeAGMgr.py,v 1.3 2004/11/02 17:48:26 efrank Exp $"
__docformat__ = "restructuredtext en"


import xmlrpclib
from KahDataServices.KahCatAGCfgMgr    import KahCatAGCfgMgr


class MeAGMgr( KahCatAGCfgMgr ):
    """
    Extends the KahCatAGCfgMgr beyond managing AG rendezvous for datafactories.
    In addition, we manage event passing related to shared clipboards.
    """

    #----------------------------------------------------------------------
    def __init__(self, uri):
    #----------------------------------------------------------------------
        KahCatAGCfgMgr.__init__(self, uri )

        # whether or not we're sharing now
        self.sharing= 0

        # connect info for the clipboard
        self.cbName = None
        self.host   = None
        self.port   = None

        return

    #------------------------------------------------------------------------
    def __del__(self):
    #------------------------------------------------------------------------
        """
        @rtype: None

        Make sure done is called.
        """

        self.done()
        return
    
    #------------------------------------------------------------------------
    def done(self):
    #------------------------------------------------------------------------
        """
        @rtype: None
        """

        self.delCb()
        KahCatAGCfgMgr.done(self)

        return

    #----------------------------------------------------------------------
    def registerHandlers(self, newCbHandler, changedCbHandler, delCbHandler):
    #----------------------------------------------------------------------
        """
        Until this is called, we're just a kahCatAGCfgMgr.  Once called,
        we are wired in to handle clipboard sharing.

        BUG: we are completel ignoringn threading right now.  Seems the
        norm in AG shared apps???
        """

        self.sharedAppClient.RegisterEventCallback("newCb", newCbHandler)
        self.sharedAppClient.RegisterEventCallback("changedCb", changedCbHandler)
        self.sharedAppClient.RegisterEventCallback("delCb", delCbHandler)

        return

    

    #----------------------------------------------------------------------
    def nameUsed(self, cbName):
    #----------------------------------------------------------------------
        """
        @type cbName: string  name for displaying clipboard

        Makes sure no one else is using this name.
        """

        state = self.getAllCbState()
        for cb in state:
            # [(self.cbName, self.host, self.port), descList]
            if (cbName == cb[0][0] ):
                return 1

        return 0
            

    #----------------------------------------------------------------------
    def newCb(self, name, host, port):
    #----------------------------------------------------------------------
        """
        @type name: string  name for displaying clipboard
        @type host: string  connect info for data server
        @type port: int     connect info for data server
        Announce we're here
        """

        # make sure name isn't used

        if self.nameUsed( name ):
            raise KeyError
            
        self.cbName = name
        self.host   = host
        self.port   = port

        #from AccessGrid.GUID import GUID
        #id = str(GUID())

        # each instance maintains state in server under a unique key.
        # That state is the name of the clipboard and a list of pairs.
        # Each pair is a name to display on the clipboard and a
        # string key that can be used to retreive the actual data.

        key = self.sharedAppClient.GetPublicId()+"_cb"

        l = [(self.cbName, self.host, self.port), []]
        s = xmlrpclib.dumps( (l,) )

        self.sharedAppClient.SetData(key,s)
        self.sharing = 1

        # let the world know
        self.sharedAppClient.SendEvent("newCb", l)

        return

    #----------------------------------------------------------------------
    def delCb(self):
    #----------------------------------------------------------------------
        """
        @rtype: none

        Delete our clipboard from the shared space.
        """

        if not self.sharing: return

        #Zero our state in the shared app (No RemoveData, so can't purge it

        key = self.sharedAppClient.GetPublicId()+"_cb"
        self.sharedAppClient.SetData(key, "")

        #Notify others.  We send no data because right now we rebuild
        #the whole cb display each time anyway...we'll just disappear

        self.sharedAppClient.SendEvent("delCb", 1)

        return

        
    #----------------------------------------------------------------------
    def cbChanged(self, descriptor):
    #----------------------------------------------------------------------
        """
        @type descriptor: list of pairs.  each pair=(recoElem name, int id)
        @rtype: none

        Broadcast that our cb has changed and record cb state in shared app
        """

        l = [ (self.cbName, self.host, self.port), descriptor ]
        s = xmlrpclib.dumps( (l,) )


        key = self.sharedAppClient.GetPublicId()+"_cb"
        self.sharedAppClient.SetData(key, s)

        self.sharedAppClient.SendEvent("changedCb", l)

        return

    #----------------------------------------------------------------------
    def getAllCbState(self):
    #----------------------------------------------------------------------
        """ 
        Gets all stored state related to clipboards and returns as
        a list
        """
        
        participants = self.sharedAppClient.GetParticipants()

        state = []
        
        for participant in participants:
            exists = 0
            key = participant.appId + "_cb"

            try:
                d = self.sharedAppClient.GetData(key)
                if d=="": continue
                l = xmlrpclib.loads(d)[0][0]
                state.append( l )
            except Exception, e:
                print e
                continue

        print "state is ", state
        return state


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3