def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.initUI() # define options for opening or saving a file self.file_opt = options_file = {} options_file['defaultextension'] = '.txt' options_file['filetypes'] = [('all files', '.*'), ('text files', '.txt')] options_file['initialdir'] = '../' options_file['initialfile'] = 'testFile' options_file['parent'] = self.parent options_file['title'] = 'Choose configuration file' # define options for asking local name self.ask_localname_opt = options_localName = {} options_localName['parent'] = self.parent options_localName['initialvalue'] = "alice" conf = tkFileDialog.askopenfilename(**self.file_opt) localName = tkSimpleDialog.askstring("local name", "Please enter your name:", **self.ask_localname_opt) MessagePasser.initialize(conf, localName)
def initialize(localName, role, id, localIP, localPort): global LOCALNAME, ROLE, USERSM, SELF_ADDR LOCALNAME = localName ROLE = role # TODO: conf might be changed MessagePasser.initialize(localIP, localPort, localName) SELF_ADDR = socket.gethostbyname(socket.getfqdn()) LOGGER.info("Initializing Host") # initialize dispatching and receiving thread recv_thread = threading.Thread(target=receiveThread, args = ()) recv_thread.daemon = False recv_thread.start() dipatch_thread = threading.Thread(target=dispatcherThread, args = ()) dipatch_thread.daemon = True dipatch_thread.start() # start state machine if ROLE == "USER": UserStateMachine.initialize() DISPATCHERMAP["USER_SM"] = UserStateMachine # turnOn the machine enqueue({"SM":"USER_SM", "action":"turnOn", "userId":id, "localIP":localIP, "localPort":localPort}) elif ROLE == "DRIVER": DriverStateMachine.initialize() DISPATCHERMAP["DRIVER_SM"] = DriverStateMachine RSNStateMachine.initialize() DISPATCHERMAP["RSN_SM"] = RSNStateMachine # turnOn the machine enqueue({"SM":"DRIVER_SM", "action":"turnOn", "busId":id, "localIP":localIP, "localPort":localPort}) enqueue({"SM":"RSN_SM", "action":"turnOn", "rsnId":id, "localIP":localIP, "localPort":localPort}) elif ROLE == "GSN": GSNStateMachine.initialize() DISPATCHERMAP["GSN_SM"] = GSNStateMachine # turnOn the machine enqueue({"SM":"GSN_SM", "action":"turnOn", "gsnId":id, "localIP":localIP, "localPort":localPort})
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.initUI() # define options for opening or saving a file self.file_opt = options_file = {} options_file['defaultextension'] = '.txt' options_file['filetypes'] = [('all files', '.*'), ('text files', '.txt')] options_file['initialdir'] = '../' options_file['initialfile'] = 'testFile' options_file['parent'] = self.parent options_file['title'] = 'Choose configuration file' # define options for asking local name self.ask_localname_opt = options_localName = {} options_localName['parent'] = self.parent options_localName['initialvalue'] = "alice" conf = tkFileDialog.askopenfilename(**self.file_opt) localName = tkSimpleDialog.askstring("local name", "Please enter your name:", **self.ask_localname_opt) MessagePasser.initialize(conf, localName)
def initialize(localName, role, id, localIP, localPort): global LOCALNAME, ROLE, USERSM, SELF_ADDR LOCALNAME = localName ROLE = role # TODO: conf might be changed MessagePasser.initialize(localIP, localPort, localName) SELF_ADDR = socket.gethostbyname(socket.getfqdn()) LOGGER.info("Initializing Host") # initialize dispatching and receiving thread recv_thread = threading.Thread(target=receiveThread, args=()) recv_thread.daemon = False recv_thread.start() dipatch_thread = threading.Thread(target=dispatcherThread, args=()) dipatch_thread.daemon = True dipatch_thread.start() # start state machine if ROLE == "USER": UserStateMachine.initialize() DISPATCHERMAP["USER_SM"] = UserStateMachine # turnOn the machine enqueue({ "SM": "USER_SM", "action": "turnOn", "userId": id, "localIP": localIP, "localPort": localPort }) elif ROLE == "DRIVER": DriverStateMachine.initialize() DISPATCHERMAP["DRIVER_SM"] = DriverStateMachine RSNStateMachine.initialize() DISPATCHERMAP["RSN_SM"] = RSNStateMachine # turnOn the machine enqueue({ "SM": "DRIVER_SM", "action": "turnOn", "busId": id, "localIP": localIP, "localPort": localPort }) enqueue({ "SM": "RSN_SM", "action": "turnOn", "rsnId": id, "localIP": localIP, "localPort": localPort }) elif ROLE == "GSN": GSNStateMachine.initialize() DISPATCHERMAP["GSN_SM"] = GSNStateMachine # turnOn the machine enqueue({ "SM": "GSN_SM", "action": "turnOn", "gsnId": id, "localIP": localIP, "localPort": localPort })