Esempio n. 1
0
class VNCServerAppObject:
    def __init__(self,venueUrl,vncserverexe,displayID,geometry,depth,name, clientProfile):
        log.debug('VNCServerAppObject.__init__')
        self.running = 0
        
        # Create VNC server
        self.vncServer=vncServer(vncserverexe,displayID,geometry,depth)
        self.vncServer.start()
        
        # Create the App object
        self.venueProxy=VenueIW(venueUrl)
        try:
            self.appDescription=self.venueProxy.CreateApplication(name,
                                                      "VNC Server at %s"%(self.vncServer.getContactString()),
                                                      "application/x-ag-venuevnc")
        except:
            log.exception("Failed to create application session")
            self.vncServer.destroy()
            raise

        # Attach to it
        self.appProxy=SharedApplicationIW(self.appDescription.uri)

        log.info("App URL = %s"%(self.appDescription.uri))

        try:
            # Join the App Object
            (self.publicID,self.privateID)=self.appProxy.Join(clientProfile)

            # Upload the auth file to the app object
            self.appProxy.SetData(self.privateID,"VNC_Pwd",base64.encodestring(self.vncServer.getPassword()))

            # Set the contact string
            self.appProxy.SetData(self.privateID,"VNC_Contact",self.vncServer.getContactString())
            # Set the geometry
            self.appProxy.SetData(self.privateID,"VNC_Geometry",self.vncServer.getGeometry())
            # Set the depth
            self.appProxy.SetData(self.privateID,"VNC_Depth",self.vncServer.getDepth())

            self.appProxy.Leave(self.privateID)
        except:
            log.exception("Failed to configure application session")
            self.vncServer.destroy()
            raise

    def run(self):
        log.debug('VNCServerAppObject.run')
        self.running = 1
        while self.running:
            time.sleep(1)

    def shutdown(self):
        log.debug('VNCServerAppObject.shutdown')
        # Stop while loop
        self.running = 0
        # Stop and cleanup vnc server
        self.vncServer.destroy()
        # Stop application service and remove from venue.
        self.venueProxy.DestroyApplication(self.appDescription.id)
urlOption = Option("-u",
                   "--url",
                   dest="url",
                   default=None,
                   help="Specify a venue url on the command line.")
app.AddCmdLineOption(urlOption)

args = app.Initialize()

venueUrl = app.GetOption("url")

print "URL: ", venueUrl

if venueUrl is None:
    print "Exiting, no url specified."
    sys.exit(0)

venueClient = VenueIW(venueUrl)

# Enter the specified venue
print "Creating shared application."
appDesc = venueClient.CreateApplication(
    "Charles and Ed's Model Editor", "Bio Shared Model Editory",
    "application/x-ag-shared-bio-model-editor")

print "Application url is: %s" % appDesc.uri

print "Destroying shared application."
venueClient.DestroyApplication(appDesc.id)