1 | ############################################################################
|
---|
2 | #
|
---|
3 | # Copyright (C) 2005 Electronic Visualization Laboratory,
|
---|
4 | # University of Illinois at Chicago
|
---|
5 | #
|
---|
6 | # All rights reserved.
|
---|
7 | #
|
---|
8 | # Redistribution and use in source and binary forms, with or without
|
---|
9 | # modification, are permitted provided that the following conditions are met:
|
---|
10 | #
|
---|
11 | # * Redistributions of source code must retain the above copyright
|
---|
12 | # notice, this list of conditions and the following disclaimer.
|
---|
13 | # * Redistributions in binary form must reproduce the above
|
---|
14 | # copyright notice, this list of conditions and the following disclaimer
|
---|
15 | # in the documentation and/or other materials provided with the distribution.
|
---|
16 | # * Neither the name of the University of Illinois at Chicago nor
|
---|
17 | # the names of its contributors may be used to endorse or promote
|
---|
18 | # products derived from this software without specific prior written permission.
|
---|
19 | #
|
---|
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
---|
24 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
25 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
26 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
27 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
28 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
29 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
30 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
31 | #
|
---|
32 | # Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum
|
---|
33 | #
|
---|
34 | # Author: Ratko Jagodic
|
---|
35 | #
|
---|
36 | ############################################################################
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 | # python stuff
|
---|
41 | import sys, string
|
---|
42 | import os.path
|
---|
43 | import os
|
---|
44 |
|
---|
45 |
|
---|
46 | # my imports
|
---|
47 | from SAGEApp import SAGEApp, SAGEAppInitial
|
---|
48 | from sageDisplayInfo import sageDisplayInfo
|
---|
49 |
|
---|
50 |
|
---|
51 |
|
---|
52 | ## Main class to store all the messages returned by SAGE
|
---|
53 | class sageUIDataInfo:
|
---|
54 |
|
---|
55 | #### constructor initializes member values
|
---|
56 | def __init__(self):
|
---|
57 | self.hashApps = {} # all the apps available for running??
|
---|
58 | self.hashAppStatusInfo = {} # apps currently running
|
---|
59 | self.displayInfo = sageDisplayInfo()
|
---|
60 | self.newAppID = -1
|
---|
61 |
|
---|
62 | #### Set the sage status
|
---|
63 | def setSageStatus(self, appHash) :
|
---|
64 |
|
---|
65 | # loop through the available apps and create SAGEAppInitial objects for all of them
|
---|
66 | for appName, configs in appHash.iteritems():
|
---|
67 | hashSingleAppInfo = {}
|
---|
68 | self.hashApps[appName] = SAGEAppInitial(appName, configs)
|
---|
69 |
|
---|
70 |
|
---|
71 | #----------------------------------------------------------------------
|
---|
72 |
|
---|
73 |
|
---|
74 | ## ### Set the possible execution configurations for each app
|
---|
75 | ## def setSageAppExecConfig(self, data):
|
---|
76 | ## tokens = string.split( data, '\n', 1 )
|
---|
77 | ## appName = tokens[0]
|
---|
78 | ## data = tokens[1] #the rest
|
---|
79 | ## configList = string.split( data, "config ")
|
---|
80 |
|
---|
81 | ## del configList[0] #remove the first item in the list
|
---|
82 |
|
---|
83 | ## for config in configList:
|
---|
84 | ## if appName in self.hashApps.keys():
|
---|
85 | ## (name, stringConfig) = string.split(config, ":", 1)
|
---|
86 | ## self.hashApps[appName].AddConfig(name, stringConfig)
|
---|
87 |
|
---|
88 |
|
---|
89 | #----------------------------------------------------------------------
|
---|
90 |
|
---|
91 | ### sets the display information for the display we are currently connected to
|
---|
92 | ### this data is received from the fsManager
|
---|
93 | def setSageDisplayInformation(self, data):
|
---|
94 | listTokens = string.split(data, '\n')
|
---|
95 | tileNumTokens = string.split(listTokens[0], ' ')
|
---|
96 | desktopTokens = string.split(listTokens[1], ' ')
|
---|
97 | tileConfTokens = string.split(listTokens[2], ' ')
|
---|
98 |
|
---|
99 | self.displayInfo.setValues(int(tileNumTokens[0]), int(tileNumTokens[1]), int(tileNumTokens[2]),
|
---|
100 | int(desktopTokens[0]), int(desktopTokens[1]),
|
---|
101 | int(tileConfTokens[0]), int(tileConfTokens[1]))
|
---|
102 |
|
---|
103 | return
|
---|
104 |
|
---|
105 |
|
---|
106 | #----------------------------------------------------------------------
|
---|
107 |
|
---|
108 |
|
---|
109 | #### Get the new list of z values from SAGE and update local hashes
|
---|
110 | def setSageZValue(self, message):
|
---|
111 | tokens = string.split(message)
|
---|
112 | numZChanges = int(tokens[0]) #the first item that comes in is the number of z changes
|
---|
113 |
|
---|
114 | # loop through all the tokens and update the z values of the apps
|
---|
115 | for i in range(numZChanges):
|
---|
116 | self.setZvalue( int(tokens[i*2+1]), int(tokens[i*2+2]) )
|
---|
117 |
|
---|
118 |
|
---|
119 | #----------------------------------------------------------------------
|
---|
120 |
|
---|
121 |
|
---|
122 | ### returns True if the app is already on top, False otherwise
|
---|
123 | def isTopWindow(self, appId):
|
---|
124 | if self.getZvalue(appId) == 0:
|
---|
125 | return True # meaning the app was already on top
|
---|
126 | else:
|
---|
127 | return False
|
---|
128 |
|
---|
129 |
|
---|
130 | #----------------------------------------------------------------------
|
---|
131 |
|
---|
132 |
|
---|
133 | #### Set the SAGE app status
|
---|
134 | #### prints Invalid app ID if does not exists
|
---|
135 | def setSageAppInfo(self, stData):
|
---|
136 | listTokens = string.split(stData)
|
---|
137 |
|
---|
138 | iAppID = int( listTokens[ 1 ] )
|
---|
139 | if iAppID in self.hashAppStatusInfo:
|
---|
140 | self.hashAppStatusInfo[ iAppID ].setAll( listTokens[0], int(listTokens[1]),
|
---|
141 | int(listTokens[2]), int(listTokens[3]), int(listTokens[4]), int(listTokens[5]),
|
---|
142 | int(listTokens[6]), int(listTokens[7]))
|
---|
143 | else:
|
---|
144 | self.hashAppStatusInfo[ iAppID ] = SAGEApp( listTokens[0], int(listTokens[1]),
|
---|
145 | int(listTokens[2]), int(listTokens[3]), int(listTokens[4]), int(listTokens[5]),
|
---|
146 | int(listTokens[6]), int(listTokens[7]))
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 | ## ### increase the z value of all the apps (because the new one will be on top)
|
---|
152 | ## def updateZsAfterAdd(self, appId):
|
---|
153 | ## for app in self.hashAppStatusInfo.itervalues():
|
---|
154 | ## app.setZvalue(app.getZvalue() + 1)
|
---|
155 |
|
---|
156 |
|
---|
157 | #----------------------------------------------------------------------
|
---|
158 |
|
---|
159 |
|
---|
160 | ##### ShutDown the sage application
|
---|
161 | ##### prints invalid app ID if doesn't exist
|
---|
162 | def sageAppShutDown(self, stData):
|
---|
163 | listTokens = string.split(stData)
|
---|
164 | appId = int(listTokens[0])
|
---|
165 |
|
---|
166 | # self.updateZsAfterRemove(appId)
|
---|
167 |
|
---|
168 | if appId in self.hashAppStatusInfo :
|
---|
169 | del self.hashAppStatusInfo[appId]
|
---|
170 |
|
---|
171 |
|
---|
172 | ## ### decrease the z value of all the apps that were below the deleted one
|
---|
173 | ## def updateZsAfterRemove(self, appId):
|
---|
174 | ## deletedApp = self.hashAppStatusInfo[appId]
|
---|
175 | ## for app in self.hashAppStatusInfo.itervalues():
|
---|
176 | ## if app.getZvalue() > deletedApp.getZvalue() and app.getId() != deletedApp.getId():
|
---|
177 | ## app.setZvalue(app.getZvalue() - 1)
|
---|
178 |
|
---|
179 | #----------------------------------------------------------------------
|
---|
180 |
|
---|
181 |
|
---|
182 | # Get the z value of the app
|
---|
183 | def getZvalue(self, appInstId):
|
---|
184 | if appInstId in self.hashAppStatusInfo:
|
---|
185 | appInfo = self.hashAppStatusInfo.get(appInstId)
|
---|
186 | return appInfo.getZvalue()
|
---|
187 | else:
|
---|
188 | #print("getZvalue: Invalid app instance ID")
|
---|
189 | return -1
|
---|
190 |
|
---|
191 |
|
---|
192 | #----------------------------------------------------------------------
|
---|
193 |
|
---|
194 |
|
---|
195 | # Set the Z value of the app
|
---|
196 | def setZvalue(self, appId, value):
|
---|
197 | if (appId in self.hashAppStatusInfo):
|
---|
198 | self.hashAppStatusInfo[appId].setZvalue(value)
|
---|
199 | else:
|
---|
200 | print ('setZvalue: Invalid app instance ID')
|
---|
201 | return -1
|
---|
202 |
|
---|
203 |
|
---|
204 | #----------------------------------------------------------------------
|
---|
205 |
|
---|
206 |
|
---|
207 | def getSageDisplayInformation(self) :
|
---|
208 | return self.displayInfo.getValues()
|
---|
209 |
|
---|
210 |
|
---|
211 | #----------------------------------------------------------------------
|
---|
212 |
|
---|
213 |
|
---|
214 | ### Get the sage app Info
|
---|
215 | def getAppInfo(self, appId):
|
---|
216 | if appId in self.hashAppStatusInfo:
|
---|
217 | return {str(appId): self.hashAppStatusInfo[appId].getAll()}
|
---|
218 | else:
|
---|
219 | return -1
|
---|
220 |
|
---|
221 |
|
---|
222 | #----------------------------------------------------------------------
|
---|
223 |
|
---|
224 |
|
---|
225 | def getAllAppInfo(self):
|
---|
226 | appStatus = {} #key = appId, value = list of app params
|
---|
227 | for appId, sageApp in self.hashAppStatusInfo.iteritems():
|
---|
228 | appStatus[str(appId)] = sageApp.getAll()
|
---|
229 | return appStatus
|
---|
230 |
|
---|
231 |
|
---|
232 | #----------------------------------------------------------------------
|
---|
233 |
|
---|
234 |
|
---|
235 | # returns the SAGEApp associated with the given appInstId
|
---|
236 | def getSAGEApp(self, appId):
|
---|
237 | return self.hashAppStatusInfo[appId]
|
---|
238 |
|
---|
239 |
|
---|
240 | #----------------------------------------------------------------------
|
---|
241 |
|
---|
242 |
|
---|
243 | # returns true if the app with a specified appId is currently running
|
---|
244 | def appExists(self, appId):
|
---|
245 | return appId in self.hashAppStatusInfo
|
---|
246 |
|
---|
247 |
|
---|
248 | #----------------------------------------------------------------------
|
---|
249 |
|
---|
250 |
|
---|
251 | ### Get all app IDs currently running on sage
|
---|
252 | def getAllAppIDs(self) :
|
---|
253 | return self.hashAppStatusInfo.keys()
|
---|
254 |
|
---|
255 |
|
---|
256 | #----------------------------------------------------------------------
|
---|
257 |
|
---|
258 | ### Get the new APP ID
|
---|
259 | def getNewAppID(self) :
|
---|
260 | return self.newAppID
|
---|
261 |
|
---|
262 |
|
---|
263 | #----------------------------------------------------------------------
|
---|
264 |
|
---|
265 | ### Returns a list of all currently running apps
|
---|
266 | def getAllApps( self ):
|
---|
267 | return self.hashAppStatusInfo
|
---|
268 |
|
---|
269 |
|
---|
270 | #----------------------------------------------------------------------
|
---|
271 |
|
---|
272 |
|
---|
273 | ### Get list of application names that are available for running
|
---|
274 | def getAvailableAppNames( self ):
|
---|
275 | return self.hashApps.keys()
|
---|
276 |
|
---|
277 |
|
---|
278 | #----------------------------------------------------------------------
|
---|
279 |
|
---|
280 |
|
---|
281 | ### Returns a list of all the available apps
|
---|
282 | def getAvailableApps( self ):
|
---|
283 | return self.hashApps
|
---|
284 |
|
---|
285 |
|
---|
286 | #----------------------------------------------------------------------
|
---|
287 |
|
---|
288 |
|
---|
289 | ### Returns a list of z values in the following format:
|
---|
290 | ### [numChanges, appId, zValue, appId, zValue...]
|
---|
291 | def getZvalues( self ):
|
---|
292 | apps = self.getAllApps()
|
---|
293 | zValues = [] #this will hold the return list of z values
|
---|
294 | zValues.append(len(apps))
|
---|
295 | for app in apps.itervalues():
|
---|
296 | zValues.append(app.getId())
|
---|
297 | zValues.append(app.getZvalue())
|
---|
298 |
|
---|
299 | return zValues
|
---|
300 |
|
---|
301 |
|
---|
302 |
|
---|
303 |
|
---|