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

View of /ModelEditor/MeSharedEditServer.py

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.4 - (download) (as text) (annotate)
Sun Dec 4 17:20:34 2005 UTC (12 years, 11 months ago) by efrank
Branch: MAIN
CVS Tags: before-dynamics-persistence, lwc, HEAD
Changes since 1.3: +9 -4 lines
1. migrate from deprecated xmlrpcconverter to PrimitiveConverter.  This
makes shared editing by AG work again.  Also, now trivial to add arbitrary
object networks to Model and still ship  between kah instances.  maybe.

2. fix up dynamics stuff.  dunno how charl's stuff ever worked, but it did.
then it didn't.  now it does again.  migrate to classFromPath and rationalize
a bunch of stuff.

# MeSharedEditServer.py
#    22Oct04 efrank      First version

XmlRpc based server to shuttle data around between ModelEditor
instances.  Right now, control is managed through AG shared app.

import copy
from threading import Thread
from threading import Lock
import xmlrpclib
from SimpleXMLRPCServer                import SimpleXMLRPCServer
#from KahDataServices.XmlRpcConverter   import XmlRpcConverter
#from KahDataServices.ConversionManager import ConversionManager
from KahDataServices.KahPrimitiveConverter import KahPrimitiveConverter
from KahUtils.get_local_hostname       import get_local_hostname
#from KahOMGen.KahOMDataPrimitiveHandler              import registerAll as registerKahOM
#from FoundryInfoGen.FoundryInfoDataPrimitiveHandler  import registerAll as registerFoundryInfo

__clipboard      = None
__nCb          = None
__server       = None
__serverThread = None
__cbLock       = None

def meSharedEditServerStart( ):
    @type host: string   
    @type port: int

    global __server, __clipboard, __nCb, __serverThread, __cbLock

    __clipboard = {}
    __nCb     = 0

    __cbLock  = Lock()

    __server = SimpleXMLRPCServer((host, 0))
    (ip,port) = __server.socket.getsockname()
    print "meSharedEditServerStart: using ", (host,port)
    __server.register_function( getRecoElemById )

    __serverThread = Thread(target = meSharedEditServerThread,
                            args   = () )

    print "starting server thread"
    # need to make daemon???
    print "server thread started"
    return (host,port)

def meSharedEditServerThread():
    global __server, __clipboard, __nCb, __serverThread, __cbLock
    print "in server thread"

    #server = SimpleXMLRPCServer((host, port))


def meSharedEditServerKill():
    """ kills the server thread """
    global __server, __clipboard, __nCb, __serverThread, __cbLock
    print "stopping shared edit server"

def getCbDescriptor():
    @rtype: list of pairs (itemName:string, itemId:int)

    Form descriptor for clipboard to put on AG shared AP

    global __server, __clipboard, __nCb, __serverThread, __cbLock

    desc = []
    print __clipboard.keys()
    print __clipboard.values()
    for n in range(__nCb):
        print "trying ", n, __clipboard[n]
        desc.append( ( __clipboard[n].getName(), n) )

    return desc

def putOnClipboard( re ):
    @type re: RecoElem.  The item to put on the clipboard.
    @rtype: int   Integer id to use to get it back again.

    We do not deep copy the re.  Caller should do that if
    global __server, __clipboard, __nCb, __serverThread, __cbLock

    __clipboard[__nCb] = re
    __nCb += 1

    return __nCb

def getRecoElemByIdLocal(id):
    Just returns recoElem with clipboard key, id.  No xmlrpc 

    @type id: int
    @rtype: KahOM.RecoElem

    global __server, __clipboard, __nCb, __serverThread, __cbLock

    #print "local trying for ", id
        #print "sending "
        re = copy.deepcopy( __clipboard[id] )
    except Exception, e:
        print "getRecoElemByIdLocal", e
        re = None


    return re

def getRecoElemById(id):
    """ Get RecoElem with given integer id (key into clipboard. Return xmlrpc """
    # [0] is needed because xmlrpclib.dumps is used 
    global __server, __clipboard, __nCb, __serverThread, __cbLock

    mgr = KahPrimitiveConverter( debugPrint = 1)

        print "trying for id ", id
        re = __clipboard[id]
        #print "sending re: "
        #mgr = ConversionManager (XmlRpcConverter(), debug=1)
        c = mgr.write(re)
        #print "rep is ", c
        cRe = xmlrpclib.dumps((c,))
        #print "dumps is ", cRe
    except Exception, e:
        print e
        return None
    return cRe


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3