[4] | 1 | ############################################################################ |
---|
| 2 | # |
---|
| 3 | # DIM - A Direct Interaction Manager for SAGE |
---|
| 4 | # Copyright (C) 2007 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 | |
---|
| 41 | # python imports |
---|
| 42 | import optparse, time, os, sys |
---|
| 43 | |
---|
| 44 | # my imports |
---|
| 45 | from deviceManager import DeviceManager |
---|
| 46 | from eventManager import EventManager |
---|
| 47 | from overlayManager import OverlayManager |
---|
| 48 | from listener import Listener |
---|
| 49 | from sageGate import SageGate |
---|
| 50 | from sageData import SageData |
---|
| 51 | from globals import * |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | # ------------------------------------------------------------------------------ |
---|
| 55 | # |
---|
| 56 | # GLOBALS |
---|
| 57 | # |
---|
| 58 | # ------------------------------------------------------------------------------ |
---|
| 59 | |
---|
| 60 | VERBOSE = False |
---|
| 61 | LISTENER_PORT = 20005 # for HW capture modules (ie HW devices sending events) |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | os.chdir(sys.path[0]) |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | class DIM: |
---|
| 68 | def __init__(self, host, port): |
---|
| 69 | # sageGate is the network connection with SAGE |
---|
| 70 | self.sageGate = SageGate() |
---|
| 71 | setSageGate(self.sageGate) |
---|
| 72 | |
---|
| 73 | # the event manager takes care of properly dispatching events |
---|
| 74 | self.evtMgr = EventManager() |
---|
| 75 | setEvtMgr(self.evtMgr) |
---|
| 76 | self.evtMgr.addHandlers() |
---|
| 77 | |
---|
| 78 | # sageData keeps the current state of the SAGE windows/apps |
---|
| 79 | self.sageData = SageData() |
---|
| 80 | setSageData(self.sageData) |
---|
| 81 | |
---|
| 82 | # overlay manager creates, destroys and updates overlays |
---|
| 83 | self.overlayMgr = OverlayManager() |
---|
| 84 | setOverlayMgr(self.overlayMgr) |
---|
| 85 | |
---|
| 86 | # contains all the devices and takes care of loading plugins for them |
---|
| 87 | # also, distributes HW messages to each device |
---|
| 88 | self.devMgr = DeviceManager() |
---|
| 89 | setDevMgr(self.devMgr) |
---|
| 90 | |
---|
| 91 | # connect to SAGE |
---|
| 92 | for i in range(5): # try to connect to SAGE for 5 seconds |
---|
| 93 | if self.sageGate.connectToSage(host, port) != 0: |
---|
| 94 | self.sageGate.registerSage() |
---|
| 95 | break |
---|
| 96 | time.sleep(1) |
---|
| 97 | else: # we didn't manage to connect to sage in 5 seconds... so quit |
---|
| 98 | exitApp() |
---|
| 99 | |
---|
| 100 | # start listening for the device events |
---|
| 101 | time.sleep(4) # wait till all the messages come in |
---|
| 102 | self.overlayMgr.addOverlay(OVERLAY_WALL) |
---|
| 103 | self.listener = Listener(LISTENER_PORT, self.devMgr.onHWMessage) |
---|
| 104 | self.listener.serve_forever() |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | ### sets up the parser for the command line options |
---|
| 109 | def get_commandline_options(): |
---|
| 110 | parser = optparse.OptionParser() |
---|
| 111 | |
---|
| 112 | h = "if set, prints output to console, otherwise to output_log.txt" |
---|
| 113 | parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help=h, default=False) |
---|
| 114 | |
---|
| 115 | h = "interaction with which sage? (default=localhost)" |
---|
| 116 | parser.add_option("-s", "--sage_host", dest="host", help=h, default="localhost") |
---|
| 117 | |
---|
| 118 | h = "the UI port number for sage (default is 20001)" |
---|
| 119 | parser.add_option("-p", "--sage_port", dest="port", help=h, type="int", default=20001) |
---|
| 120 | |
---|
| 121 | return parser.parse_args() |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | # ------------------------------------------------------------------------------ |
---|
| 127 | # |
---|
| 128 | # MAIN |
---|
| 129 | # |
---|
| 130 | # ------------------------------------------------------------------------------ |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | def main(): |
---|
| 134 | global VERBOSE |
---|
| 135 | |
---|
| 136 | # parse the command line params |
---|
| 137 | (options, args) = get_commandline_options() |
---|
| 138 | VERBOSE = options.verbose |
---|
| 139 | sagePort = options.port |
---|
| 140 | sageHost = options.host |
---|
| 141 | |
---|
| 142 | # start everything off |
---|
| 143 | DIM(sageHost, sagePort) |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | if __name__ == '__main__': |
---|
| 148 | main() |
---|