def CleanCoviseCB(self, event): """ Callback for "clean_covise" menu item """ self.checkFields() self.covise.eventClient.Send( Event(SharedCovEvent.CLEAN, self.covise.channelId, (self.covise.publicId, self.covise.publicId)))
def Quit(self, data=None): """ This is the _real_ Quit method that tells the viewer to quit """ # Turn off the main loop self.log.debug("Method Quit called") if self.masterSocket != None: self.masterSocket.close() if self.masterHost == self.hostName: self.appProxy.SetData(self.privateId, SharedCovKey.MASTERHOST, "") self.appProxy.SetData(self.privateId, SharedCovKey.MASTERPORT, 0) self.eventClient.Send( Event(SharedCovEvent.MASTER, self.channelId, (self.publicId, self.publicId)))
def monitorMaster(self): data = self.masterSocket.recv(1024) while data != "" and data.find("masterLeft") < 0: #print "XX"+data+"XX"+str(data.find("masterLeft"))+"\n" data = self.masterSocket.recv(1024) #print "XX"+data+"XX\n" self.appProxy.SetData(self.privateId, SharedCovKey.MASTERHOST, "") self.appProxy.SetData(self.privateId, SharedCovKey.MASTERPORT, 0) self.eventClient.Send( Event(SharedCovEvent.MASTER, self.channelId, (self.publicId, self.publicId))) self.masterSocket.close() #print "Master Covise left\n" self.masterSocket = None
def DoJoin(self): """ This method handles NEXT button presses in the UI. The event is only sent if the local user is the "master" """ self.log.debug("Method DoJoin called") # Put the event on the queue if self.masterHost == "": #become master and start covise #tell the master which client wants to join HOST = self.hostName # Our AccessGrid Daemon PORT = self.serverPort # Our port number message = "startCovise\n" try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send(message) self.masterSocket = s self.appProxy.SetData(self.privateId, SharedCovKey.MASTERHOST, self.hostName) self.appProxy.SetData(self.privateId, SharedCovKey.MASTERPORT, self.serverPort) self.eventClient.Send( Event(SharedCovEvent.MASTER, self.channelId, (self.publicId, self.publicId))) Thread(target=self.monitorMaster).start() except: print "could not connect to AccessGridDaemon\n" ##data = s.recv(1024) else: #tell the master which client wants to join HOST = self.masterHost # The master AccessGrid Daemon PORT = self.masterPort # The master Port message = "join " + self.hostName + ":" + str( self.serverPort) + "\n" try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send(message) except: print "could not connect to masters AccessGridDaemon\n" ##data = s.recv(1024) s.close()
def CreateEvents(self): dataDescription = DataDescription3("") profile = ClientProfile() service = ServiceDescription("service", "desc", "uri", "mime") stream = StreamDescription3("") conn = ConnectionDescription("") app = ApplicationDescription(1, 'app', 'desc', 'uri', 'mime') self.sendEvents = [ Events.AddDataEvent(self.esc.GetChannelId(), dataDescription), Events.UpdateDataEvent(self.esc.GetChannelId(), dataDescription), Events.RemoveDataEvent(self.esc.GetChannelId(), dataDescription) ] self.distributeEvents = [ Event(Event.ADD_DATA, self.esc.GetChannelId(), dataDescription), Event(Event.UPDATE_DATA, self.esc.GetChannelId(), dataDescription), Event(Event.REMOVE_DATA, self.esc.GetChannelId(), dataDescription), Event(Event.ENTER, self.esc.GetChannelId(), profile), Event(Event.MODIFY_USER, self.esc.GetChannelId(), profile), Event(Event.EXIT, self.esc.GetChannelId(), profile), Event(Event.ADD_SERVICE, self.esc.GetChannelId(), service), Event(Event.REMOVE_SERVICE, self.esc.GetChannelId(), service), Event(Event.ADD_APPLICATION, self.esc.GetChannelId(), app), Event(Event.REMOVE_APPLICATION, self.esc.GetChannelId(), app), Event(Event.ADD_CONNECTION, self.esc.GetChannelId(), conn), Event(Event.REMOVE_CONNECTION, self.esc.GetChannelId(), conn), Event(Event.ADD_STREAM, self.esc.GetChannelId(), stream), Event(Event.MODIFY_STREAM, self.esc.GetChannelId(), stream), Event(Event.REMOVE_STREAM, self.esc.GetChannelId(), stream) ] # Each client will receive all events. self.totalEvents = self.nrOfClients * len( self.distributeEvents) * self.nrOfEvent print 'Starting one event service and %s event clients' % (nrOfClients)
def __init__(self, arg, url, log=None): wxApp.__init__(self, arg) """ This is the constructor for the Shared Covise. """ # Initialize state in the shared covise self.url = url self.eventQueue = Queue.Queue(5) self.log = log self.masterId = None self.numSteps = 0 self.hostName = "vision.rus.uni-stuttgart.de" self.serverPort = 31098 self.masterSocket = None # Get a handle to the application object in the venue self.log.debug("Getting application proxy (%s).", url) self.appProxy = Client.Handle(self.url).GetProxy() # Join the application object, get a private ID in response self.log.debug("Joining application.") (self.publicId, self.privateId) = self.appProxy.Join() # Get the information about our Data Channel self.log.debug("Retrieving data channel information.") (self.channelId, esl) = self.appProxy.GetDataChannel(self.privateId) # Connect to the Data Channel, using the EventClient class # The EventClient class is a general Event Channel Client, but since # we use the Event Channel for a Data Channel we can use the # Event Client Class as a Data Client. For more information on the # Event Channel look in AccessGrid\EventService.py # and AccessGrid\EventClient.py self.log.debug("Connecting to data channel.") self.eventClient = EventClient(self.privateId, esl, self.channelId) self.eventClient.start() self.eventClient.Send(ConnectEvent(self.channelId, self.privateId)) # Register callbacks with the Data Channel to handle incoming # events. self.log.debug("Registering for events.") self.eventClient.RegisterCallback(SharedCovEvent.MASTER, self.RecvMaster) self.eventClient.RegisterCallback(SharedCovEvent.CLEAN, self.CleanCovise) self.masterHost = "" self.masterPort = 0 self.masterHost = self.appProxy.GetData(self.privateId, SharedCovKey.MASTERHOST) self.masterPort = self.appProxy.GetData(self.privateId, SharedCovKey.MASTERPORT) self.frame.SetMasterHost(self.masterHost + ":" + str(self.masterPort)) self.log.debug("fit.") self.log.debug("SharedCovise V1.0") # read configueation file userapp = Platform.GetUserAppPath() configFileName = userapp + "\\SharedCovise.config" configFile = None try: configFile = file(configFileName, 'r') except: print "could no open config file" if configFile != None: entry = configFile.readline(200) if entry != "": self.hostName = entry.rstrip("\n") entry = configFile.readline(200) if entry != "": self.serverPort = int(entry) self.frame.SetPort(self.serverPort) self.frame.SetHost(self.hostName) if self.masterHost == self.hostName and self.serverPort == self.serverPort: #connect to our Daemon and find out if covise is still running message = "check" try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send(message) self.masterSocket = s self.appProxy.SetData(self.privateId, SharedCovKey.MASTERHOST, self.hostName) self.appProxy.SetData(self.privateId, SharedCovKey.MASTERPORT, self.serverPort) self.eventClient.Send( Event(SharedCovEvent.MASTER, self.channelId, (self.publicId, self.publicId))) Thread(target=self.monitorMaster).start() except: self.appProxy.SetData(self.privateId, SharedCovKey.MASTERHOST, "") self.appProxy.SetData(self.privateId, SharedCovKey.MASTERPORT, 0) self.eventClient.Send( Event(SharedCovEvent.MASTER, self.channelId, (self.publicId, self.publicId))) print "could not connect to AccessGridDaemon\n"