Beispiel #1
0
    def __init__(self, host=socket.gethostname(), port=20001, passwd=""):
        self.sageData = sageUIDataInfo()   # a datastructure that stores the display and app state
        
        self.sageGate = SAGEGate(WriteLog)         # communication channel with sage
        self.sageGate.registerCallbackFunction( 40000, self.sageData.setSageStatus )
        self.sageGate.registerCallbackFunction( 40001, self.sageData.setSageAppInfo )
        self.sageGate.registerCallbackFunction( 40003, self.sageData.sageAppShutDown )
        self.sageGate.registerCallbackFunction( 40004, self.sageData.setSageDisplayInformation )
        self.sageGate.registerCallbackFunction( 40005, self.sageData.setSageZValue )

        # now connect to sage and register with it
        if self.sageGate.connectToSage(host, port) == 0:
            sys.exit(0)
        self.sageGate.registerSage()
	self.sessionPassword = passwd
Beispiel #2
0
class Proxy:
    def __init__(self, host=socket.gethostname(), port=20001, passwd=""):
        self.sageData = sageUIDataInfo()   # a datastructure that stores the display and app state
        
        self.sageGate = SAGEGate(WriteLog)         # communication channel with sage
        self.sageGate.registerCallbackFunction( 40000, self.sageData.setSageStatus )
        self.sageGate.registerCallbackFunction( 40001, self.sageData.setSageAppInfo )
        self.sageGate.registerCallbackFunction( 40003, self.sageData.sageAppShutDown )
        self.sageGate.registerCallbackFunction( 40004, self.sageData.setSageDisplayInformation )
        self.sageGate.registerCallbackFunction( 40005, self.sageData.setSageZValue )

        # now connect to sage and register with it
        if self.sageGate.connectToSage(host, port) == 0:
            sys.exit(0)
        self.sageGate.registerSage()
	self.sessionPassword = passwd


    def getDisplayInfo(self):
        """ Returns: a list (integers): [totalNumTiles, numTilesX, numTilesY, totalWidth,
                                         totalHeight, tileWidth, tileHeight]
            Returns: -1 if failed for whatever reason
        """
        try:
            return self.sageData.getSageDisplayInformation()
        except:
            WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
            return -1


    def getAppList(self):
        """ Returns: a list (strings) of app names available for running
            Returns: -1 if failed for whatever reason
        """
        try:
            return self.sageData.getAvailableAppNames()
        except:
            WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
            return -1


    def getZValues(self):
        """ Returns: a list (integers) of z values [numChanges, appId, zValue, appId, zValue ....]
            Returns: -1 if failed for whatever reason
        """
        try:
            return self.sageData.getZvalues()
        except:
            WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
            return -1


    def getAppStatus(self, appId=-1):
        """ If called without parameters it will return the status for all currently running applications.
            If called with appId parameter it will return the status just for that application.
            Returns: a hash where the key is appId (string) and the value is a list of app status:
                    [string appName, int appId, int left, int right, int bottom,
                     int top, int sailID, int zValue, int configNum, string title]
            Returns: -1 if failed for whatever reason
             
        """
        try:
            if appId == -1:
                return self.sageData.getAllAppInfo()
            else:
                return self.sageData.getAppInfo(appId)
        except:
            WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
            return -1


    def getAllAppID(self):
	""" Returns all the app ID currently running on SAGE
        """
	try:
	    return self.sageData.getAllAppIDs()
	except:
	    WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
	    return -1


    def getNewAppID(self):
	try:
	   return self.sageData.getNewAppID()
	except:
	   WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
           return -1


    def bringToFront(self, appId):
        """ Brings the application window to front (on top of the other ones).
            Returns: 1 if everythin went OK and the message was sent
            Returns: -1 if the message was not sent for whatever reason (including
                     if the app was already on top)
        """
        try:
                if self.sageData.appExists(appId) and \
                   (not self.sageData.isTopWindow(appId)) and \
                   self.sageGate.bringToFront(appId):
                    return 1
                else:
                    return -1
        except:
            WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
            return -1
        

    def moveWindow(self, appId, x, y):
        """ Moves a window to the specified location (absolute position) in tiled display coordinates.
            The x,y is interpreted as the lower left corner of the application.
            All parameters are integers.
            Returns: 1 if successful.
            Returns: -1 if failed for whatever reason.
        """
        try:
            app = self.sageData.getSAGEApp(appId)
            left = x
            right = x+app.getWidth()
            bottom = y
            top = y+app.getHeight()
            if self.sageGate.resizeWindow(appId, left, right, bottom, top) == -1:
                return -1
            return 1
        except:
            WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
            return -1


    def resizeWindow(self, appId, left, right, bottom, top):
        """ Resizes a window to the specified size in tiled display coordinates.
            The lower left corner of the display is considered 0,0.
            All parameters are integers.
            Returns: 1 if successful.
            Returns: -1 if failed for whatever reason.
        """
        try:
            
            # prevent 0 or negative size
            if (right-left < 1) or (top-bottom < 1):
                app = self.sageData.getSAGEApp(appId)
                ar = app.getWidth() / float(app.getHeight())
                if ar > 1:
                    newH = 300 # min app size
                    newW = newH*ar
                else:
                    newW = 300 # min app size
                    newH = newW/ar
                
                right = left+newW
                top = bottom+newH

            if self.sageGate.resizeWindow(appId, left, right, bottom, top) == -1:
                return -1
            return 1
        except:
            WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
            return -1


    def executeApp(self, appName, configName="default", pos=False, size=False, shareable=False, optionalArgs=""):
        """ Starts a new application with appName (string) and configNum (int). You can also optionally specify
            initial position and size of the application window that you pass in as a tuple of integers.
            If the application itself requires some command line arguments during startup, those can be
            specified as well with the optionalArgs parameter (string).
            Shareable parameter is used when you want to run the application through sageBridge which
            means that it can be shared among other displays. If False it will run the app locally.
            Returns: the new status of all the apps in the same format as getAppStatus
                    (sleeps 2 seconds before returning it to ensure that the datastructure was updated
                     by the messages from SAGE about the new app)
            Returns: -1 if failed for whatever reason
        """
        try:
            if self.sageGate.executeApp(appName, configName, pos, size, shareable, optionalArgs) == -1:
                return -1
            sleep(2)        #wait for the message to arrive from sage and then return the status
            return self.sageData.getAllAppInfo()
        except:
            WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
            return -1


    def closeApp(self, appId):
        """ Closes the app corresponding to the specified appId.
            Returns: the new status of all the apps in the same format as getAppStatus
                    (sleeps 2 seconds before returning it to ensure that the datastructure was updated
                     by the messages from SAGE about the closed app)
            Returns: -1 if failed for whatever reason
        """
        try:
            if not self.sageData.appExists(appId):
                return -1
            
            if self.sageGate.shutdownApp(appId) == -1:
                return -1
            sleep(2)        #wait for the message to arrive from sage and then return the status
            return self.sageData.getAllAppInfo()
        except:
            WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
            return -1
        

    def shareDesktop(self, sz, displayNum, ip, passwd, shareable=False):
        oa = ip +" "+ str(displayNum) +" "+ str(sz[0]) +" "+ str(sz[1]) +" "+ passwd
        return self.executeApp("VNCViewer", "default", False, sz, shareable, oa)


    def shareApp(self, appId, fsIP, fsPort):
        """ Sends a request to fsManager to share the specified application to the specified display
            Parameters: - appId of the application you want to share
                        - ip address and port number of the machine to stream to
            Returns: 1 if succeeded
            Returns: -1 if failed for whatever reason
        """
        try:
            if self.sageGate.streamApp(appId, fsIP, fsPort) == -1:
                return -1
            else:
                return 1
        except:
            WriteLog( str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]) )
            return -1

        
    def authenticate(self, passwd):
	if (self.sessionPassword == passwd):
	   return 1
	else:
	   return -1