예제 #1
0
class SVGame:
    def __init__(self, gameID, hostID):
        self.gameID = gameID
        self.hostID = hostID
        self.guestID = None
        self.hostMap = map()
        self.guestMap = map()

        self.FSMsymbols = {}
        self.FSM = StateMachine(self.FSMsymbols)
        self.FSM.add_state('init', self.st_init)
        self.FSM.set_state('init')

    def __del__(self):
        del self.hostID
        del self.guestID
        del self.hostMap
        del self.guestMap
        del self.FSM
        del self.FSMsymbols

    def getID(self):
        return self.gameID

    def getPlayerList(self):
        retVal = [self.hostID]
        if self.guestID: retVal.append(self.guestID)
        return retVal

    def st_init(self, symbols):
        if 'player_apply' in symbols:
            self.guestID = symbols['player_apply']
            return ('place_ships')
 def __init__(self, machine_of_machines):
     StateMachine.__init__(self, machine_of_machines)
     self.error_codes = [
         'REAL xx too long',
         'REAL xx with leading zeros',
         'REAL yy too long',
         'REAL yy with trailing zeros'
     ]
예제 #3
0
class PushDownAutomaton:
    def __init__(self, computationHistory = False):
        self.stateMachine = StateMachine()
        self.computationHistory = None

        if computationHistory:
            self.computationHistory = ComputationHistory()

    # Adds state.
    # param state: name of state
    def addState(self, state):
        self.stateMachine.addState(state)

    # Adds transition one state to another.
    # param fromState: state transit from
    # param inputStringSymbol: string symbol to red
    # param inputStackSymbol: stack symbol to pop
    # param outputStackSymbol: stack symbol to push
    # param toState: state to transit
    def addTransition(self, fromState, inputStringSymbol, inputStackSymbol, outputStackSymbol, toState):
        self.stateMachine.addTransition(fromState, [inputStringSymbol, inputStackSymbol], [outputStackSymbol], toState)

    # Sets state's acceptance.
    # param state: name of state
    def setStateAccepting(self, state):
        self.stateMachine.setAccept(state, True)

    # Sets state as starting state
    # param state: name of state
    def setStartState(self, state):
        self.stateMachine.setStartState(state)
예제 #4
0
class FiniteAutomaton:
    # ınitialization.
    # param computationHistory: whether store computation history list while running
    #     'True' for create compoutation history
    #     'False' for not record computation history
    def __init__(self, computationHistory = False):
        self.stateMachine = StateMachine()
        self.computationHistory = None

        if computationHistory:
            self.computationHistory = ComputationHistory()
            
    # Adds state.
    # param state: name of state
    def addState(self, state):
        self.stateMachine.addState(state)

    # Adds transition one state to another.
    # param fromState: state transit from
    # param inputSymbol: string symbol
    # param toState: state to transit
    def addTransition(self, fromState, inputSymbol, toState):
        self.stateMachine.addTransition(fromState, [inputSymbol], [], toState)

    # Sets state's acceptance.
    # param state: name of state
    def setStateAccepting(self, state):
        self.stateMachine.setAccept(state, True)

    # Sets state as starting state
    # param state: name of state
    def setStartState(self, state):
        self.stateMachine.setStartState(state)
예제 #5
0
class StateMachineManager:
    def __init__(self, json_filename, initial_state_name):
        self.state_machine = StateMachine(json_filename, initial_state_name)

    def send_message(self, message):
        if (self.state_machine.is_valid_text(message)):
            metadata = self.state_machine.get_metadata_for_text(message)
            self.state_machine.transtion_to_state_with_text(message)
            return {
                'metadata': metadata,
                'triggers': self.state_machine.get_available_display_texts()
            }
        else:
            print("Invalid text message:", message)
            return {
                'invalid': True,
                'metadata': [],
                'triggers': []
            }

    def get_current_display_texts(self):
        return self.state_machine.get_available_display_texts()

    def reset(self):
        self.state_machine.reset()
예제 #6
0
    def __init__(self, gameID, hostID):
        self.gameID = gameID
        self.hostID = hostID
        self.guestID = None
        self.hostMap = map()
        self.guestMap = map()

        self.FSMsymbols = {}
        self.FSM = StateMachine(self.FSMsymbols)
        self.FSM.add_state('init', self.st_init)
        self.FSM.set_state('init')
class StateMachineTest(TestCase):

    def setUp(self):
        self.state = Full()
        self.sm = StateMachine(self.state)

    def test_init(self):
        self.assertEqual(self.state, self.sm.currentState)

    def test_run(self):
        self.sm.run(Input.antelope)
        self.assertEqual(LionMachine.hungry, self.sm.currentState)

    def test_run_1(self):
        state1 = Hungry()
        sm1 = StateMachine(state1)
        sm1.run(Input.hunter)
        self.assertEqual(state1, sm1.currentState)

    def test_run_all(self):
        self.sm.runAll([Input.antelope, Input.hunter, Input.antelope])
        self.assertEqual(LionMachine.full, self.sm.currentState)
예제 #8
0
파일: Driver.py 프로젝트: SimionZafiu/1NG
 def __init__(self):
   # Initial state is kid
   StateMachine.__init__(self, Driver.start)
예제 #9
0
 def __init__(self):
     #Initial state
     StateMachine.__init__(self, LionMachine.full)
예제 #10
0
	def __init__(self, rtc, timeout=None):
		StateMachine.__init__(self, timeout=timeout)
		self.name = 'TURN OFF'
		self.rtc = rtc

		self.states['starting'] = State()
예제 #11
0
 def __init__(self):
     # Starting state
     StateMachine.__init__(self, Drone.Start)
예제 #12
0
 def __init__(self, json_filename, initial_state_name):
     self.state_machine = StateMachine(json_filename, initial_state_name)
예제 #13
0
pose1.latitude = 32.882112
pose1.longitude = -117.2343985
pose2 = PoseStamped()
pose2.pose.position.x = 2
pose3 = PoseStamped()
pose3.pose.position.x = 2
pose3.pose.position.y = 2

goalTracker = NextGoal([pose1, pose2, pose3])

waypoint_states = {
    "nextGoal":
    goalTracker,
    "following":
    FollowingState(MAX_SPEED_AT_DIST, MAX_SPEED_AT_ANGLE, MIN_DRIVE_SPEED,
                   MIN_TURNING_SPEED),
    "success":
    EndSuccess(),
}

waypoint_transitions = {
    "nextGoal:set": "following",
    "nextGoal:done": "success",
    "following:reached": "nextGoal",
}

waypoint = StateMachine(waypoint_states, waypoint_transitions, "nextGoal")

waypoint.attach()
rospy.spin()
예제 #14
0
 def __init__(self, machine_of_machines):
     StateMachine.__init__(self, machine_of_machines)
     self.error_codes = [
         'ID too long',
     ]
 def __init__(self, machine_of_machines):
     StateMachine.__init__(self, machine_of_machines)
     self.error_codes = [
         'Unrecognized Symbol'
     ]
 def test_run_1(self):
     state1 = Hungry()
     sm1 = StateMachine(state1)
     sm1.run(Input.hunter)
     self.assertEqual(state1, sm1.currentState)
 def __init__(self, machine_of_machines):
     StateMachine.__init__(self, machine_of_machines)
 def setUp(self):
     self.state = Full()
     self.sm = StateMachine(self.state)
예제 #19
0
 def __init__(self):
     # Initial State
     StateMachine.__init__(self, DrawingApp.start)
예제 #20
0
 def __init__(self):
     # Initial state is kid
     StateMachine.__init__(self, Driver.start)
예제 #21
0
    def __init__(self, computationHistory = False):
        self.stateMachine = StateMachine()
        self.computationHistory = None

        if computationHistory:
            self.computationHistory = ComputationHistory()
예제 #22
0
 def __init__(self):
     StateMachine.__init__(self,ArmingNoAuth())
     Observable.__init__(self)
예제 #23
0
seek_states = {
    "evaluator": Evaluator(CONFIDENCE_THRESHOLD, DIST_THRESHOLD, goalTracker),
    "seeker": Seeker(CONFIDENCE_THRESHOLD, MAX_SPEED_AT_DIST, MAX_SPEED_AT_ANGLE,
        MIN_DRIVE_SPEED, MIN_TURNING_SPEED),
}

seek_transitions = {
    "evaluator:far": "exit:waypoint",
    "evaluator:close": "seeker",
    "evaluator:lost": "exit:searching",
    "seeker:reached": "exit:waypoint",
    "seeker:lost": "exit:searching",
}

waypoint = StateMachine(waypoint_states, waypoint_transitions, "nextGoal")
searching = StateMachine(searching_states, searching_transitions, "evalulator")
blob = StateMachine(blob_states, blob_transitions, "blobsearch")
seek = StateMachine(seek_states, seek_transitions, "evalulator")

main_states = {
    "waypoint": waypoint,
    "searching": searching,
    "blobsearch": blob,
    "seek": seek,
    "end": EndSuccess(),
}

main_transitions = {
    "seek": "seek",
    "searching": "searching",
예제 #24
0
class SVClient:
    def __init__(self, queuepath, sock):
        self.ID = queuepath

        outQueueManager = QueueManager(address=('/tmp/SVSqueue'), \
            authkey='gnarf')
        outQueueManager.connect()

        inQueueManager = QueueManager(address=(queuepath), \
            authkey='gnarf')
        inQueueManager.connect()

        self.inQueue = inQueueManager.get_queue()
        self.outQueue = outQueueManager.get_queue()
        self.sock = sock

        self.inBuffer = ''

        self.handleMsg = msgHandler(self.logfunc)
        self.handleMsg.register('sock', self.do_sock)
        self.handleMsg.register('lobbyMsg', self.do_lobbyMsg)
        self.handleMsg.register('clientNameAccepted', \
            self.do_clientNameAccepted)
        self.handleMsg.register('clientNameDenied', \
            self.do_clientNameDenied)
        self.handleMsg.register('sendPONG', self.do_sendPONG)
        self.handleMsg.register('userList', self.do_userList)
        self.handleMsg.register('bye', self.do_bye)
        self.handleMsg.register('privateMsg', self.do_privateMsg, 3, False)
        self.handleMsg.register('userLeft', self.do_userLeft)
        self.handleMsg.register('userJoined', self.do_userJoined)

        self.handleProtIn = msgHandler()
        self.handleProtIn.register(210, self.do_210_in_proposeName, 2)
        self.handleProtIn.register(401, self.do_401_in_listRooms, 1)
        self.handleProtIn.register(406, self.do_406_in_newRoom, 1)
        self.handleProtIn.register(501, self.do_501_in_chatLobby)
        self.handleProtIn.register(502, self.do_502_in_chatPrivate)
        self.handleProtIn.register(505, self.do_505_in_getUserList, 1)
        self.handleProtIn.register(602, self.do_602_in_ackProt, 2)
        self.handleProtIn.register(603, self.do_603_in_PING, 1)
        self.handleProtIn.register(604, self.do_604_in_PONG, 1)
        self.handleProtIn.register(699, self.do_699_in_exit, 1)

        self.handleProtOut = msgHandler()
        self.handleProtOut.register(101, self.do_ProtOut_trivial)
        self.handleProtOut.register(302, self.do_ProtOut_trivial)
        self.handleProtOut.register(303, self.do_ProtOut_trivial)
        self.handleProtOut.register(305, self.do_ProtOut_trivial)
        self.handleProtOut.register(306, self.do_ProtOut_trivial)
        self.handleProtOut.register(503, self.do_503_out_chatLobby)
        self.handleProtOut.register(504, self.do_504_out_chatPrivate)
        self.handleProtOut.register(506, self.do_ProtOut_trivial)
        self.handleProtOut.register(507, self.do_507_out_userEntry)
        self.handleProtOut.register(508, self.do_ProtOut_trivial)
        self.handleProtOut.register(509, self.do_509_out_userJoined)
        self.handleProtOut.register(510, self.do_510_out_userLeft)
        self.handleProtOut.register(601, self.do_601_out_serverHello)
        self.handleProtOut.register(603, self.do_603_out_PING)
        self.handleProtOut.register(604, self.do_ProtOut_trivial)
        self.handleProtOut.register(697, self.do_ProtOut_trivial)

        self.FSMsymbols = {}
        self.FSM = StateMachine(self.FSMsymbols)
        self.FSM.add_state('init', self.st_init)
        self.FSM.set_state('init')
        self.FSM.add_state('prot_proposed', self.st_prot_proposed)
        self.FSM.add_state('prot_accepted', self.st_prot_accepted)
        self.FSM.add_state('name_asked', self.st_name_asked)
        self.FSM.add_state('online', self.st_online)

        self.userList = []

        self.firstCycle = True
        self.keep_alive = True

    def __del__(self):
        del self.inQueue
        del self.outQueue
        del self.sock
        del self.inBuffer
        del self.handleMsg
        del self.FSMsymbols
        del self.FSM

    def cycle(self):
        if self.firstCycle: self.firstCycle = False
        else: 
            msg = self.inQueue.get() # blocking get
            self.performInQueueMsg(msg)
        self.FSM.cycle()

        return self.keep_alive

    def sendPeerRaw(self, text):
        self.sock.send(text)

    def sendSystem(self, msgtag, text, obj=None):
        self.outQueue.put((msgtag, text, obj))

    def sendProt(self, ProtNo, comment, data=None):
        if not self.handleProtOut.performMsg((ProtNo, comment, data)):
            print '[SVClient.sendProt] unknown ProtNo: ' + str(ProtNo)

    def performInQueueMsg(self, msg):
        if not self.handleMsg.performMsg(msg):
            print '[SVClient] unknown cmd: ' + msg[0]

    def logfunc(self, msg):
        self.sendSystem('syslog', str(msg), self.ID)

# callbacks for msg handling: param is (msgtag, text, obj)
    def do_sock(self, param):
        self.inBuffer += param[1]
        self.checkInBuffer()

    def do_lobbyMsg(self, param):
        if self.FSM.is_state('online'):
            self.sendProt(503, 'message written in lobby', param)

    def do_clientNameAccepted(self, param):
        self.FSMsymbols['clientNameAccepted'] = 1

    def do_clientNameDenied(self, param):
        self.FSMsymbols['clientNameDenied'] = param[1]

    def do_sendPONG(self, param):
        self.sendProt(604, 'PONG')

    def do_userList(self, param):
        self.userList = param[2]
        self.sendProt(506, 'start of user list')
        for user in self.userList:
            self.sendProt(507, 'user entry', user)
        self.sendProt(508, 'end of user list')

    def do_bye(self, param):
        self.keep_alive = False

    def do_privateMsg(self, param):
        self.sendProt(504, 'private message', param)

    def do_userLeft(self, param):
        userID = param[2]
        msg = param[1]
        if userID in [x['ID'] for x in self.userList if x['ID'] == userID]:
            userName = [x['name'] for x in self.userList \
                if x['ID'] == userID][0]
            self.sendProt(510, msg, userName)
        
        self.userList = [x for x in self.userList if x['ID'] != userID]

    def do_userJoined(self, param):
        userEntry = param[2]
        self.userList.append(userEntry)
        self.sendProt(509, 'user joined', userEntry['name'])

# callbacks for protocol input handling: param is [ProtNo, (par)*]
    def do_210_in_proposeName(self, param):
        if not self.FSM.is_state('name_asked'):
            self.sendProt(306, 'not waiting for client name')
            return

        self.FSMsymbols['clientNameProposed'] = param[1]

    def do_401_in_listRooms(self, param):
        if not self.FSM.is_state('online'):
            self.sendProt(306, 'not ready for games')
            return
        self.sendSystem('listRooms', 'list open games', self.ID)

    def do_406_in_newRoom(self, param):
        if not self.FSM.is_state('online'):
            self.sendProt(306, 'not ready for games')
            return
        self.sendSystem('newRoom', 'create new game', self.ID)

    def do_501_in_chatLobby(self, param):
        if not self.FSM.is_state('online'):
            self.sendProt(306, 'not ready for chat')
            return
        tList = param
        del tList[0]
        msg = " ".join(param)
        self.sendSystem('chatLobby', msg, self.ID)

    def do_502_in_chatPrivate(self, param):
        if not self.FSM.is_state('online'):
            self.sendProt(306, 'not ready for chat')
            return
        tList = param
        if len(tList) < 2:
            self.sendProt(303, 'no username given')
            return
        del tList[0]
        sinkName = tList[0]
        del tList[0]
        msg = " ".join(tList)

        sinkID = [x['ID'] for x in self.userList if x['name'] == sinkName]
        if len(sinkID) == 0:
            self.sendProt(303, 'requested user not found')
            return
        self.sendSystem('chatPrivate', msg, (self.ID, sinkID[0]))

    def do_505_in_getUserList(self, param):
        self.sendSystem('getUserList', 'tellme all users', self.ID)

    def do_602_in_ackProt(self, param):
        if not self.FSM.is_state('prot_proposed'):
            self.sendProt(306, 'not waiting for client protocol')
            return

        ProtNo = param[1]

        if ProtNo.isdigit():
            self.FSMsymbols['clientProt'] = int(ProtNo)
        else:
            self.sendProt(302, 'waiting for protocol version')

    def do_603_in_PING(self, param):
        self.sendSystem('PINGreceived', 'ping from peer', self.ID)

    def do_604_in_PONG(self, param):
        self.sendSystem('PONGreceived', 'pong from peer', self.ID)

    def do_699_in_exit(self, param):
        self.sendSystem('exit', 'going home... goodbye', self.ID)
        sys.exit(0)

# callbacks for protocol output handling: param is [ProtNo, (par)*]
    def do_ProtOut_trivial(self, param):
        ProtNo, comment, data = param
        msg = str(ProtNo)
        if len(comment)>0: msg += ' -- ' + comment
        msg += '\n'
        self.sendPeerRaw(msg)

    def do_503_out_chatLobby(self, param):
        ProtNo, comment, data = param
        msg = str(ProtNo)
        sendername = data[2]['name']
        chat = data[1]
        msg += ' ' + sendername + ': ' + chat
        if len(comment)>0: msg += ' -- ' + comment
        msg += '\n'
        self.sendPeerRaw(msg)

    def do_504_out_chatPrivate(self, param):
        ProtNo, comment, data = param
        msg = str(ProtNo)
        sendername = data[2]['name']
        chat = data[1]
        msg += ' ' + sendername + ': ' + chat
        if len(comment)>0: msg += ' -- ' + comment
        msg += '\n'
        self.sendPeerRaw(msg)

    def do_507_out_userEntry(self, param):
        ProtNo, comment, data = param
        msg = str(ProtNo)
        name = data['name']
        msg += ' ' + name
        if len(comment)>0: msg += ' -- ' + comment
        msg += '\n'
        self.sendPeerRaw(msg)

    def do_509_out_userJoined(self, param):
        ProtNo, comment, data = param
        msg = str(ProtNo)
        name = data
        msg += ' ' + name
        if len(comment)>0: msg += ' -- ' + comment
        msg += '\n'
        self.sendPeerRaw(msg)
       
    def do_510_out_userLeft(self, param):
        ProtNo, comment, data = param
        msg = str(ProtNo)
        name = data
        msg += ' ' + name
        if len(comment)>0: msg += ' -- ' + comment
        msg += '\n'
        self.sendPeerRaw(msg)

    def do_601_out_serverHello(self, param):
        ProtNo, comment, data = param
        msg = str(ProtNo)
        protV = str(data)
        msg += ' ' + protV
        if len(comment)>0: msg += ' -- ' + comment
        msg += '\n'
        self.sendPeerRaw(msg)

    def do_603_out_PING(self, param):
        ProtNo, comment, data = param
        msg = str(ProtNo)
        if len(comment)>0: msg += ' -- ' + comment
        msg += '\n'
        self.sendPeerRaw(msg)
        self.sendSystem('PINGsent', 'ping sent to peer', self.ID)

# callbacks for FSM
    def st_init(self, symbols):
        self.sendProt(601, 'Schiffeversenken Prot V' + \
            str(SVStaticData.protocolVersion), \
            SVStaticData.protocolVersion)
        return('prot_proposed')

    def st_prot_proposed(self, symbols):
        if 'clientProt' in symbols:
            if symbols['clientProt'] == SVStaticData.protocolVersion:
                self.sendProt(603, 'PING')
                return('prot_accepted')

            else:
                self.sendProt(697, 'Protocol mismatch. Bye')
                sys.exit(0)
                #TODO: shutdown process here
        else:
            return None

    def st_prot_accepted(self, symbols):
        # PONG from peer shall cause call of this state
        self.sendProt(101, 'select your name, max 15 chars (210)')
        return('name_asked')

    def st_name_asked(self, symbols):
        if 'clientNameProposed' in symbols and \
                'clientNameForwarded' not in symbols:
            self.sendSystem('nameProposed', \
                symbols['clientNameProposed'], self.ID)
            symbols['clientNameForwarded'] = 1
            return None

        if 'clientNameDenied' in symbols:
            self.sendProt(305, symbols['clientNameDenied'])
            self.sendProt(101, 'select your name, max 15 chars (210)')
            del symbols['clientNameProposed']
            del symbols['clientNameDenied']
            del symbols['clientNameForwarded']
            return None

        if 'clientNameAccepted' in symbols:
            self.name = symbols['clientNameProposed']

            self.sendSystem('getUserList', '', self.ID)
            return('online')

    def st_online(self, symbols): pass

# helper functions
    def checkInBuffer(self):
        if '\r' in self.inBuffer or '\n' in self.inBuffer:
            bufList = [x for x in \
                self.inBuffer.replace('\r', '\n').split('\n') \
                if len(x) > 0]
            if len(bufList) > 0:
                newMsg = bufList[0]
                del bufList[0]
                self.inBuffer = '\n'.join(bufList)
                self.parsePeerMsg(newMsg)

            else:
                self.inBuffer = ''
                self.sendProt(303, 'invalid data')

    def parsePeerMsg(self, msg):
        grepMsg = msg.split(' -- ')[0]
        catList = [x for x in grepMsg.split(' ') if len(x) > 0]

        if len(catList) == 0:
            self.sendProt(303, 'invalid data')
            return

        if not catList[0].isdigit():
            self.sendProt(303, 'protcol mismatch')
            return

        ProtNo = int(catList[0])
        catList[0] = ProtNo
        if not self.handleProtIn.performMsg(catList):
            self.sendProt(303, str(ProtNo) + \
                ': invalid protocol number or wrong number of arguments')
예제 #25
0
파일: state.py 프로젝트: pureooze/GNU-Game
	def stateGet(self, status):
		m = StateMachine()
		m.add_state("Start", self.transitions)
		m.add_state("del-x<20", self.transitions)
		m.add_state("del-x>20", self.transitions)
		m.add_state("del-y<20", self.transitions)
		m.add_state("del-y<15", self.transitions)
		m.add_state("del-y>20", self.transitions)
		m.add_state("ATK_E", None, end_state=1)
		m.add_state("ATK_Q", None, end_state=1)
		m.add_state("ATK_W", None, end_state=1)
		m.add_state("error_state", None, end_state=1)
		m.set_start("Start")
		return m.run(status)
예제 #26
0
def error_state(txt):
    logger.info("Error State reached")

    #back to ready
    return ("Ready", "parameters")



########################################
##  State Registrierung | Entry Point ##
########################################

if __name__== "__main__":
    logger.info("MainTrain started")
    #StateMachine initialize
    m = StateMachine()

    #Zustaende hinzufuegen
    m.add_state("Healthcheck", healthcheck_transitions)
    m.add_state("Transportgutsuche", transportgutsuche_state_transitions)
    m.add_state("Auflademodus", auflademodus_state_transitions)
    m.add_state("Infosignalerkennung", infosignal_erkennung_state_transitions)

    # Kein eigentlicher State, nur Hilsklasse und nuetzliche Transition
    m.add_state("Rundenerkennung", runden_erkennung_state_transitions)

    m.add_state("Haltesignalerkennung", haltesignal_erkennung_state_transitions)
    m.add_state("Praeziseshalten", praezises_halten_state_transitions)
    m.add_state("Error",None, end_state=1)
    m.add_state("Fertig",None, end_state=1)
예제 #27
0
 def __init__(self): 
   # Initial state
   StateMachine.__init__(self, MouseTrap.waiting)
예제 #28
0
 def __init__( self, man ):
     if type(man) == type( Game.Man.Man ):
         StateMachine.__init__(self, man )
     else:
         raise TypeError()
예제 #29
0
파일: GameStates.py 프로젝트: jmacleod/dotr
 def __init__(self):
     # Initial state
     StateMachine.__init__(self, GameStates.nightBegins)
예제 #30
0
 def __init__(self, machine_of_machines):
     StateMachine.__init__(self, machine_of_machines)
     self.error_codes = [
         'INT too long',
         'INT with leading zeros'
     ]
예제 #31
0
 def __init__(self):
     StateMachine.__init__(self, S1(False))
예제 #32
0
 def __init__(self):
     # Initial state
     StateMachine.__init__(self, TramControl.wait)
예제 #33
0
    def __init__(self, queuepath, sock):
        self.ID = queuepath

        outQueueManager = QueueManager(address=('/tmp/SVSqueue'), \
            authkey='gnarf')
        outQueueManager.connect()

        inQueueManager = QueueManager(address=(queuepath), \
            authkey='gnarf')
        inQueueManager.connect()

        self.inQueue = inQueueManager.get_queue()
        self.outQueue = outQueueManager.get_queue()
        self.sock = sock

        self.inBuffer = ''

        self.handleMsg = msgHandler(self.logfunc)
        self.handleMsg.register('sock', self.do_sock)
        self.handleMsg.register('lobbyMsg', self.do_lobbyMsg)
        self.handleMsg.register('clientNameAccepted', \
            self.do_clientNameAccepted)
        self.handleMsg.register('clientNameDenied', \
            self.do_clientNameDenied)
        self.handleMsg.register('sendPONG', self.do_sendPONG)
        self.handleMsg.register('userList', self.do_userList)
        self.handleMsg.register('bye', self.do_bye)
        self.handleMsg.register('privateMsg', self.do_privateMsg, 3, False)
        self.handleMsg.register('userLeft', self.do_userLeft)
        self.handleMsg.register('userJoined', self.do_userJoined)

        self.handleProtIn = msgHandler()
        self.handleProtIn.register(210, self.do_210_in_proposeName, 2)
        self.handleProtIn.register(401, self.do_401_in_listRooms, 1)
        self.handleProtIn.register(406, self.do_406_in_newRoom, 1)
        self.handleProtIn.register(501, self.do_501_in_chatLobby)
        self.handleProtIn.register(502, self.do_502_in_chatPrivate)
        self.handleProtIn.register(505, self.do_505_in_getUserList, 1)
        self.handleProtIn.register(602, self.do_602_in_ackProt, 2)
        self.handleProtIn.register(603, self.do_603_in_PING, 1)
        self.handleProtIn.register(604, self.do_604_in_PONG, 1)
        self.handleProtIn.register(699, self.do_699_in_exit, 1)

        self.handleProtOut = msgHandler()
        self.handleProtOut.register(101, self.do_ProtOut_trivial)
        self.handleProtOut.register(302, self.do_ProtOut_trivial)
        self.handleProtOut.register(303, self.do_ProtOut_trivial)
        self.handleProtOut.register(305, self.do_ProtOut_trivial)
        self.handleProtOut.register(306, self.do_ProtOut_trivial)
        self.handleProtOut.register(503, self.do_503_out_chatLobby)
        self.handleProtOut.register(504, self.do_504_out_chatPrivate)
        self.handleProtOut.register(506, self.do_ProtOut_trivial)
        self.handleProtOut.register(507, self.do_507_out_userEntry)
        self.handleProtOut.register(508, self.do_ProtOut_trivial)
        self.handleProtOut.register(509, self.do_509_out_userJoined)
        self.handleProtOut.register(510, self.do_510_out_userLeft)
        self.handleProtOut.register(601, self.do_601_out_serverHello)
        self.handleProtOut.register(603, self.do_603_out_PING)
        self.handleProtOut.register(604, self.do_ProtOut_trivial)
        self.handleProtOut.register(697, self.do_ProtOut_trivial)

        self.FSMsymbols = {}
        self.FSM = StateMachine(self.FSMsymbols)
        self.FSM.add_state('init', self.st_init)
        self.FSM.set_state('init')
        self.FSM.add_state('prot_proposed', self.st_prot_proposed)
        self.FSM.add_state('prot_accepted', self.st_prot_accepted)
        self.FSM.add_state('name_asked', self.st_name_asked)
        self.FSM.add_state('online', self.st_online)

        self.userList = []

        self.firstCycle = True
        self.keep_alive = True
예제 #34
0
    def __init__(self, computationHistory=False):
        self.stateMachine = StateMachine()
        self.computationHistory = None

        if computationHistory:
            self.computationHistory = ComputationHistory()