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)
def ping(url, count): proxy = VenueIW(url) try: if proxy._IsValid(): ret = 0 except Exception, e: print sys.exc_type, sys.exc_value ret = 2
def do_GetDescription(self, line): index = int(line) if not self.isValidIndex(index): return print VenueIW(self.venueList[index].uri).GetDescription()
def do_GetEncryptMedia(self, line): index = int(line) if not self.isValidIndex(index): return print VenueIW(self.venueList[index].uri).GetEncryptMedia()
def do_RegenerateEncryptionkeys(self, line): index = int(line) if not self.isValidIndex(index): return print VenueIW(self.venueList[index].uri).RegenerateEncryptionKeys()
def do_GetName(self, line): index = int(line) if not self.isValidIndex(index): return name = VenueIW(self.venueList[index].uri).GetName() print name
def do_GetStaticStreams(self, line): index = int(line) if not self.isValidIndex(index): return streamList = VenueIW(self.venueList[index].uri).GetStaticStreams() for stream in streamList: print stream
def do_SetName(self, line): words = line.split() index = int(words[0]) if not self.isValidIndex(index): return name = string.join(words[1:], ' ') print "Setting name to ", name VenueIW(self.venueList[index].uri).SetName(name)
def do_SetDescription(self, line): words = line.split() index = int(words[0]) if not self.isValidIndex(index): return text = string.join(words[1:], ' ') print "Setting description to ", text VenueIW(self.venueList[index].uri).SetDescription(text)
def do_GetConnections(self, line): index = int(line) if not self.isValidIndex(index): return from AccessGrid.Descriptions import CreateConnectionDescription self.connectionListVenueIndex = index connectionList = VenueIW(self.venueList[index].uri).GetConnections() self.connectionList = [] for conn in connectionList: self.connectionList.append(CreateConnectionDescription(conn)) self.ListConnections(index)
def do_SetEncryptMedia(self, line): words = line.split() index = int(words[0]) if not self.isValidIndex(index): return encryptFlag = words[1] encryptKey = None if len(words) > 2: encryptKey = words[2] print "Setting encrypt to ", encryptFlag, encryptKey VenueIW(self.venueList[index].uri).SetEncryptMedia( encryptFlag, encryptKey)
def test_100_Setup(self): global venueServer, processManager, venue, venueUrl # initialize toolkit and environment app = Toolkit.Service().instance() app.Initialize("Node_test", sys.argv[:1]) log = app.GetLog() # Start process manager processManager = ProcessManager() # Find venue server exe bin = AGTkConfig.instance().GetBinDir() venueserverexe = os.path.join(bin, 'VenueServer.py') # Start the venue server exe = sys.executable opts = [ venueserverexe, '-p', str(venueserverport), ] processManager.StartProcess(exe, opts) # Create proxy to the venue server venueServer = VenueServerIW('https://localhost:%d/VenueServer' % (venueserverport, )) # Wait for server to become reachable print "Wait for venue server..." up = 0 while not up: try: up = venueServer.IsValid() print "up = ", up continue except: print "waiting for venue server..." pass time.sleep(1) venueUrl = venueServer.GetDefaultVenue() venue = VenueIW(venueUrl)
def InitTopLevel(): global venueServerClient, defVenueClient, TopLevelDomains global datafile, initializedTop, log vDict = dict() # Add connections between the two pCd = ConnectionDescription(defVenueClient.GetName(), defVenueClient.GetDescription(), defVenueUrl) for k in TopLevelDomains.keys(): vn = TopLevelDomains[k] name = "%s Lobby" % vn desc = "A Lobby for %s Virtual Venues." % vn vd = VenueDescription(name, desc) vuri = venueServerClient.AddVenue(vd) newVenue = VenueIW(vuri) vDict[k] = vuri newVenue.AddConnection(pCd) cCd = ConnectionDescription(name, desc, vuri) defVenueClient.AddConnection(cCd) name = "Geographic Lobby" desc = "A Lobby for Virtual Venues that are identified by country names." vd = VenueDescription(name, desc) vuri = venueServerClient.AddVenue(vd) newVenue = VenueIW(vuri) vDict['geo'] = vuri # Add connections between the two newVenue.AddConnection(pCd) cCd = ConnectionDescription(name, desc, vuri) defVenueClient.AddConnection(cCd) initializedTop = 1 pickle.dump(vDict, file(datafile, "wb+")) return vDict
venueUrlList.append(sec) elif typ == 'VenueServer': #print "Got venue server: ", sec venueDescList = VenueServerIW(venueServerUrl).GetVenues() venueUrls = map(lambda x: x.uri, venueDescList) venueUrlList += venueUrls # # Confirm that streams in venues are bridged # numStreams = 0 numBridgedStreams = 0 for venueUrl in venueUrlList: venue = VenueIW(venueUrl) try: venueName = venue.GetName() streamList = venue.GetStreams() if verbose: print "Venue: ", venueName for stream in streamList: numStreams += 1 found = 0 for networkLocation in stream.networkLocations: if networkLocation.profile.name == bridgeName: if verbose: print "Found bridge for %s in venue: %s" % ( stream.capability.type, venueName) numBridgedStreams += 1 found = 1
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)
def RequestVenueExt(request, test=0): global datafile, venueServerClient, TopLevelDomains, vDict, log log.debug("Got request for:") log.debug("name: %s", request['name']) log.debug("description: %s", request['description']) log.debug("email: %s", request['email']) log.debug("url: %s", request['www']) url = request['www'] if not url.startswith('http'): url = 'http://' + url hp = urlparse.urlparse(url)[1].split(':') log.debug("HP: %s", hp) domain = hp[0].split('.') log.debug("Domain: %s", domain) domain.reverse() backDomain = ".".join(domain) log.debug("Domain: %s", backDomain) if vDict.has_key(backDomain): log.debug("Venue found for domain.") return (1, vDict[backDomain]['venueurl']) tld = domain[0] log.debug("TLD: %s", tld) if tld in vDict.keys(): tldUrl = vDict[tld] else: log.debug("Didn't find top level domain, url using geo.") tldUrl = vDict['geo'] log.debug("TLD Venue URL: %s", tldUrl) tldVenue = VenueIW(tldUrl) log.debug("Got Top Level as: %s for url: %s", tldVenue.GetName(), request['www']) if test: log.debug("Test call") return (1, "Didn't do anything though! (%s -> %s)" % (request['www'], tldVenue.GetName())) else: log.debug("Continuing on...") vDesc = VenueDescription(request['name'], request['description']) log.debug("Created venue description.") venueUri = venueServerClient.AddVenue(vDesc) log.debug("Added venue, new url: %s", venueUri) newVenue = VenueIW(venueUri) log.debug("Created IW to new venue.") description = request['description'] for s in ["\r", "\r\n", "\n\r", "\n"]: description = description.replace(s, " ") vDict[backDomain] = { 'name': request['name'], 'description': request['description'], 'email': request['email'], 'url': request['www'], 'venueurl': venueUri, 'request': request } # Add connections between the two pCd = ConnectionDescription(tldVenue.GetName(), tldVenue.GetDescription(), tldUrl) newVenue.AddConnection(pCd) cCd = ConnectionDescription(request['name'], request['description'], venueUri) tldVenue.AddConnection(cCd) pickle.dump(vDict, file(datafile, "wb+")) return (1, venueUri)
serverUrl = "https://ivs.mcs.anl.gov:9000/VenueServer" datafile = "vrs-data.pickled" app = Service() try: app.Initialize("VenueRequestService") except: print "Couldn't initialize app, exiting." sys.exit(-1) log = app.GetLog() venueServerClient = VenueServerIW(serverUrl) defVenueUrl = venueServerClient.GetDefaultVenue() defVenueClient = VenueIW(defVenueUrl) print "Default Venue: %s" % defVenueUrl def InitTopLevel(): global venueServerClient, defVenueClient, TopLevelDomains global datafile, initializedTop, log vDict = dict() # Add connections between the two pCd = ConnectionDescription(defVenueClient.GetName(), defVenueClient.GetDescription(), defVenueUrl) for k in TopLevelDomains.keys():
def StartProcesses(self): ''' Start rat for audio mixing and selector for video selection. ''' global bridge fromVideoHost = 0 fromVideoPort = 0 fromAudioHost = 0 fromAudioPort = 0 # Create venue proxy venueUrl = self.app.options.venueUrl if venueUrl: vProxy = venueProxy = VenueIW(venueUrl) # Get stream information from venue producerStreams = filter(lambda s: s.capability.role == "producer", vProxy.GetStreams()) for stream in producerStreams: if stream.capability.type == "video": fromVideoHost = stream.location.host fromVideoPort = stream.location.port if stream.capability.type == "audio": fromAudioHost = stream.location.host fromAudioPort = stream.location.port else: fromVideoHost = self.app.options.videoHost fromVideoPort = int(self.app.options.videoPort) fromAudioHost = self.app.options.audioHost fromAudioPort = int(self.app.options.audioPort) if debug: print "video multicast: ", fromVideoHost, fromVideoPort print "audio multicast: ", fromAudioHost, fromAudioPort if fromVideoHost == 0 or fromVideoPort == 0: if debug: print "Video stream is not received from venue, you will not receive video" if fromAudioHost == 0 or fromAudioPort == 0: if debug: print "Audio stream is not received from venue, you will not receive audio" # We may receive odd ports from the venue (bug), so make # sure rtp only uses even ports . if fromVideoPort % 2 == 1: fromVideoPort = fromVideoPort -1 if fromAudioPort % 2 == 1: fromAudioPort = fromAudioPort -1 # Create commands to execute # Start audio down-sampler (linear16 kHz -> linear8 kHz) if debug: print "****************** START DOWN-SAMPLER", fromAudioHost, "/", fromAudioPort, " ",self.transcoderHost, "/", self.transcoderPort self.tcoder = L16_to_L8(fromAudioHost,fromAudioPort, self.transcoderHost,self.transcoderPort, self.selectAudio) self.tcoder.Start() wxapp = wxPySimpleApp() if self.selectAudio: audioSelectorUI = SelectorGUI("Audio Selector", self.tcoder) if debug: print "****************** BEFORE RAT", self.toAudioPort # Start audio transcoder (rat linear -> ulaw) ratExec = os.path.join(os.getcwd(), 'rat') roptions = [] roptions.append("-T") roptions.append("%s/%d/127/l16"%(self.transcoderHost, int(self.transcoderPort))) roptions.append("%s/%d/127/pcm"%(self.toAudioHost, int(self.toAudioPort))) if debug: print "********* START transcoder ", ratExec, roptions, '\n' self.processManager.StartProcess(ratExec, roptions) self.vselector = VideoSelector(fromVideoHost, int(fromVideoPort), self.toVideoHost, int(self.toVideoPort), 1) self.vselector.Start() videoSelectorUI = SelectorGUI("VideoSelector", self.vselector) # Start video selector if debug: print "****************** START VIDEO SELECTOR", fromVideoHost, "/", fromVideoPort, " ",self.toVideoHost, "/", self.toVideoPort if debug: print "----------------------------------------" if debug: print "*** Video from %s/%d is forwarded to %s/%d"%(fromVideoHost, fromVideoPort, self.toVideoHost, self.toVideoPort) if debug: print "*** Audio from %s/%d is forwarded to %s/%d"%(fromAudioHost, fromAudioPort, self.toAudioHost, self.toAudioPort) if debug: print "----------------------------------------" # Start the bridge print "Server URL: http://%s:%d" % (socket.gethostbyname(socket.gethostname()),9999) bridge = Bridge(self.toAudioHost, int(self.toAudioPort), self.toVideoHost, int(self.toVideoPort), 9999) bridge.start() wxapp.SetTopWindow(videoSelectorUI) if self.selectAudio: audioSelectorUI.Show() videoSelectorUI.Show() wxapp.MainLoop()
doc = """ This program gets the stream information from the venue. """ # Initialize app = CmdlineApplication() 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) streams = venueClient.GetStreams() for s in streams: print "Stream: ", s.AsINIBlock()
app.AddCmdLineOption(venueurlOption) app.AddCmdLineOption(testOption) name = "SharedPDF" app.Initialize(name) appUrl = app.GetOption("appUrl") venueUrl = app.GetOption("venueUrl") test = app.GetOption("test") conId = app.GetOption("connectionId") if test: from AccessGrid.Venue import VenueIW # Create an application session in the venue # for testing. This should normally be done via # the Venue Client menu. venue = VenueIW("https://localhost:8000/Venues/default") appDesc = venue.CreateApplication("Shared PDF", "Shared PDF", "application/x-ag-shared-pdf") appUrl = appDesc.uri if not appUrl: Usage() sys.exit(0) if not appUrl or not venueUrl: Usage() sys.exit(0) if wxPlatform == '__WXMSW__':
def do_SetConnections(self, line=None): index = int(line) if not self.isValidIndex(index): return VenueIW(self.venueList[index].uri).SetConnections(self.connectionList)