1 | ############################################################################ |
---|
2 | # |
---|
3 | # SAGE UI - A Graphical User Interface for SAGE |
---|
4 | # Copyright (C) 2005 Electronic Visualization Laboratory, |
---|
5 | # University of Illinois at Chicago |
---|
6 | # |
---|
7 | # All rights reserved. |
---|
8 | # |
---|
9 | # Redistribution and use in source and binary forms, with or without |
---|
10 | # modification, are permitted provided that the following conditions are met: |
---|
11 | # |
---|
12 | # * Redistributions of source code must retain the above copyright |
---|
13 | # notice, this list of conditions and the following disclaimer. |
---|
14 | # * Redistributions in binary form must reproduce the above |
---|
15 | # copyright notice, this list of conditions and the following disclaimer |
---|
16 | # in the documentation and/or other materials provided with the distribution. |
---|
17 | # * Neither the name of the University of Illinois at Chicago nor |
---|
18 | # the names of its contributors may be used to endorse or promote |
---|
19 | # products derived from this software without specific prior written permission. |
---|
20 | # |
---|
21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
22 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
23 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
24 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
25 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
26 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
27 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
28 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
29 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
30 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | # |
---|
33 | # Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum |
---|
34 | # |
---|
35 | # Author: Ratko Jagodic |
---|
36 | # |
---|
37 | ############################################################################ |
---|
38 | |
---|
39 | |
---|
40 | import sageGateBase as sgb |
---|
41 | import wx, socket, xmlrpclib, sys |
---|
42 | from globals import * |
---|
43 | import traceback as tb |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | #################################################################### |
---|
48 | # |
---|
49 | # DESCRIPTION: This class provides the main communication interface |
---|
50 | # with SAGE. It subclasses the SageGateBase in order |
---|
51 | # to customize some parameters. |
---|
52 | # |
---|
53 | # DATE: Aug, 2007 |
---|
54 | # |
---|
55 | #################################################################### |
---|
56 | |
---|
57 | class SageGate(sgb.SageGateBase): |
---|
58 | """ this class provides the main communication interface with SAGE |
---|
59 | subclasses the SageGateBase in order to customize some parameters |
---|
60 | """ |
---|
61 | |
---|
62 | def __init__(self): |
---|
63 | sgb.SageGateBase.__init__(self, |
---|
64 | sageServerHost=getSAGEServer(), |
---|
65 | useAppLauncher=True, |
---|
66 | forceAppLauncher=getAppLauncher(), |
---|
67 | onDisconnect=self.initiateClosedConnectionDialog, |
---|
68 | verbose=True) |
---|
69 | |
---|
70 | |
---|
71 | def showConnectionClosedDialog(self): |
---|
72 | """ informs the user when the connection breaks """ |
---|
73 | m = getUsersData().FindMachineByIP(self.sageHost) |
---|
74 | if m: machineName = m.GetName() |
---|
75 | else: machineName = self.sageHost |
---|
76 | |
---|
77 | msg = "Connection to <<"+machineName+">> closed.\nYou will have to reconnect when SAGE becomes available again." |
---|
78 | dlg = wx.MessageDialog(None, msg, "SAGE Connection Closed", style=wx.OK) |
---|
79 | dlg.ShowModal() |
---|
80 | dlg.Destroy() |
---|
81 | |
---|
82 | |
---|
83 | def initiateClosedConnectionDialog(self): |
---|
84 | wx.CallAfter(self.showConnectionClosedDialog) |
---|
85 | |
---|
86 | |
---|
87 | def executeApp(self, appName, configName="default", pos=False, size=False, optionalArgs="", useBridge=False, sageIP=None, sagePort=None): |
---|
88 | if self.connected == False: return 0 |
---|
89 | if not appName: return 0 |
---|
90 | |
---|
91 | # figure out the correct system ports for data streaming (if not overridden by the user) |
---|
92 | if not sageIP: |
---|
93 | machine = getUsersData().FindMachineByIP(self.sageHost) |
---|
94 | if machine: |
---|
95 | sageIP = machine.GetSystemIP() # the machine told the server what to use for streaming |
---|
96 | if not sagePort: sagePort = machine.GetSystemPort() |
---|
97 | else: |
---|
98 | sageIP = self.sageGate.sageHost # use the default ip and port |
---|
99 | if not sagePort: sagePort = self.sageGate.sagePort+1 |
---|
100 | |
---|
101 | # try running the app (return -1 if failed for whatever reason) |
---|
102 | try: |
---|
103 | res = self.appLauncher.startDefaultApp(appName, sageIP, sagePort, useBridge, configName, pos, size, optionalArgs) |
---|
104 | except: |
---|
105 | print "".join(tb.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])) |
---|
106 | return -1 |
---|
107 | else: |
---|
108 | return res |
---|
109 | |
---|
110 | |
---|
111 | def executeRemoteApp(self, launcherId, appName, configName="default", pos=False, size=False, optionalArgs="", useBridge=False, sageIP=None, sagePort=None): |
---|
112 | if self.connected == False: return 0 |
---|
113 | if not appName: return 0 |
---|
114 | |
---|
115 | # figure out the correct system ports for data streaming (if not overridden by the user) |
---|
116 | if not sageIP: |
---|
117 | machine = getUsersData().FindMachineByIP(self.sageHost) |
---|
118 | if machine: |
---|
119 | sageIP = machine.GetSystemIP() # the machine told the server what to use for streaming |
---|
120 | if not sagePort: sagePort = machine.GetSystemPort() |
---|
121 | else: |
---|
122 | sageIP = self.sageGate.sageHost # use the default ip and port |
---|
123 | if not sagePort: sagePort = self.sageGate.sagePort+1 |
---|
124 | |
---|
125 | # try running the app (return -1 if failed for whatever reason) |
---|
126 | #if launcherId in self.launchers: |
---|
127 | #server = self.launchers[launcherId].getServerHandle() |
---|
128 | try: |
---|
129 | server = xmlrpclib.ServerProxy("http://" + launcherId) |
---|
130 | res = server.startDefaultApp(appName, sageIP, sagePort, useBridge, configName, pos, size, optionalArgs) |
---|
131 | except: |
---|
132 | print "".join(tb.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])) |
---|
133 | print "\nCould not start remote app through appLauncher running on:", launcherId |
---|
134 | return -1 |
---|
135 | else: |
---|
136 | return res |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | ## def executeApp(self, appName, configName="default", pos=False, size=False, optionalArgs="", useBridge=False, sageIP=None, sagePort=None): |
---|
141 | ## """ overridden in order to figure out the correct port and host for the target machine |
---|
142 | ## The reason is that SageGateBase doesn't have access to all the machine info (ie usersData) |
---|
143 | ## """ |
---|
144 | |
---|
145 | ## # figure out the correct system ports for data streaming (if not overridden by the user) |
---|
146 | ## sageIP, sagePort = self.__getMachineInfo(sageIP, sagePort) |
---|
147 | |
---|
148 | ## return sgb.SageGateBase.executeApp(self, appName, configName, pos, size, |
---|
149 | ## optionalArgs, useBridge, sageIP, sagePort) |
---|
150 | |
---|
151 | |
---|
152 | ## def executeRemoteApp(self, launcherId, appName, configName="default", pos=False, size=False, optionalArgs="", useBridge=False, sageIP=None, sagePort=None): |
---|
153 | ## """ overridden in order to figure out the correct port and host for the target machine |
---|
154 | ## The reason is that SageGateBase doesn't have access to all the machine info (ie usersData) |
---|
155 | ## """ |
---|
156 | |
---|
157 | ## # figure out the correct system ports for data streaming (if not overridden by the user) |
---|
158 | ## sageIP, sagePort = self.__getMachineInfo(sageIP, sagePort) |
---|
159 | |
---|
160 | ## return sgb.SageGateBase.executeRemoteApp(self, launcherId, appName, configName, pos, size, |
---|
161 | ## optionalArgs, useBridge, sageIP, sagePort) |
---|
162 | |
---|
163 | |
---|
164 | def onMessage(self, code, data): |
---|
165 | """ handles the incoming messages """ |
---|
166 | if code in self.hashCallbackFunction: |
---|
167 | wx.CallAfter(self.hashCallbackFunction[ code ], data) |
---|
168 | |
---|
169 | |
---|
170 | ## def __getMachineInfo(self, sageIP, sagePort): |
---|
171 | ## if not sageIP: |
---|
172 | ## machine = getUsersData().FindMachineByIP(self.sageHost) |
---|
173 | ## if machine: |
---|
174 | ## sageIP = machine.GetSystemIP() # the machine told the server what to use for streaming |
---|
175 | ## if not sagePort: sagePort = machine.GetSystemPort() |
---|
176 | ## else: |
---|
177 | ## sageIP = self.sageHost # use the default ip and port |
---|
178 | ## if not sagePort: sagePort = self.sagePort+1 |
---|
179 | ## return (sageIP, sagePort) |
---|
180 | |
---|
181 | |
---|
182 | |
---|