def testHandleMessage(self):
     self.clientFactory = SCCPClientFactory(self.unused, self.unused)
     self.clientFactory.addHandler(SCCPMessageType.RegisterAckMessage,
                                   self.handleMessage)
     self.clientFactory.handleMessage(SCCPRegisterAck())
     self.assertTrue(self.handled)
     self.assertEquals(SCCPMessageType.RegisterAckMessage,
                       self.lastMessageTypeReceived)
Esempio n. 2
0
    def createClient(self):
        log.info('creating sccp client factory')
        self.client = SCCPClientFactory(
                        self.on_sccp_connect_success,
                        self.on_sccp_connect_fail)

        self.client.handleUnknownMessage(self.onUnknownMessage)

        self.client.addHandler(SCCPMessageType.RegisterAckMessage,self.onRegisteredAck)
        self.client.addHandler(SCCPMessageType.KeepAliveAckMessage,self.onKeepAliveAck)

        self.client.addHandler(SCCPMessageType.CapabilitiesReqMessage,self.onCapabilitiesReq)
        self.client.addHandler(SCCPMessageType.OpenReceiveChannel, self.onOpenReceiveChannel)

        self.client.addHandler(SCCPMessageType.DefineTimeDate,self.onDefineTimeDate)
        self.client.addHandler(SCCPMessageType.SetSpeakerModeMessage,self.onSetSpeakerMode)
        self.client.addHandler(SCCPMessageType.CallStateMessage,self.onCallState)
        self.client.addHandler(SCCPMessageType.ActivateCallPlaneMessage,self.onActivateCallPlane)
        self.client.addHandler(SCCPMessageType.StartToneMessage,self.onStartTone)
        self.client.addHandler(SCCPMessageType.LineStatMessage,self.onLineStat)
        self.client.addHandler(SCCPMessageType.SetRingerMessage, self.onSetRinger)
        self.client.addHandler(SCCPMessageType.DisplayPromptStatusMessage, self.onDisplayPromptStatus)
        self.client.addHandler(SCCPMessageType.SelectSoftKeysMessage, self.onSelectSoftKeys)

        return self.client
Esempio n. 3
0
 def createClient(self):
     self.log('creating sccp client factory')
     self.client = SCCPClientFactory(
                     self.on_sccp_connect_success,
                     self.on_sccp_connect_fail)
     self.client.handleUnknownMessage(self.onUnknownMessage)
     self.client.addHandler(SCCPMessageType.RegisterAckMessage,self.onRegisteredAck)
     self.client.addHandler(SCCPMessageType.CapabilitiesReqMessage,self.onCapabilitiesReq)
     self.client.addHandler(SCCPMessageType.KeepAliveAckMessage,self.onKeepAliveAck)
     self.client.addHandler(SCCPMessageType.DefineTimeDate,self.onDefineTimeDate)
     self.client.addHandler(SCCPMessageType.SetSpeakerModeMessage,self.onSetSpeakerMode)
     self.client.addHandler(SCCPMessageType.CallStateMessage,self.onCallState)
     self.client.addHandler(SCCPMessageType.ActivateCallPlaneMessage,self.onActivateCallPlane)
     self.client.addHandler(SCCPMessageType.StartToneMessage,self.onStartTone)
     self.client.addHandler(SCCPMessageType.LineStatMessage,self.onLineStat)
     
     return self.client
class TestSCCPClientFactory(unittest.TestCase):
    handled = False

    def setUp(self):
        self.handled = False
        self.unkown = False
        self.lastMessageTypeReceived = 0x0000
        self.clientFactory = SCCPClientFactory(self.unused, self.unused)

    def unused(self):
        '''
        unused callback
        '''

    def handleUnknown(self, message):
        self.lastMessageTypeReceived = message.sccpmessageType
        self.unkown = True

    def handleMessage(self, message):
        self.lastMessageTypeReceived = message.sccpmessageType
        self.handled = True

    def testHandleMessage(self):
        self.clientFactory = SCCPClientFactory(self.unused, self.unused)
        self.clientFactory.addHandler(SCCPMessageType.RegisterAckMessage,
                                      self.handleMessage)
        self.clientFactory.handleMessage(SCCPRegisterAck())
        self.assertTrue(self.handled)
        self.assertEquals(SCCPMessageType.RegisterAckMessage,
                          self.lastMessageTypeReceived)

    def testHandleUnknownMessage(self):
        message = SCCPMessage(0xFFFF)
        self.clientFactory.handleUnknownMessage(self.handleUnknown)
        self.clientFactory.handleMessage(message)
        self.assertTrue(self.unkown)
        self.assertEquals(0xFFFF, self.lastMessageTypeReceived)

    def testSendSccpMessage(self):
        message = SCCPMessage(SCCPMessageType.ButtonTemplateReqMessage)
        networkClient = Mock()
        self.clientFactory.client = networkClient
        self.clientFactory.sendSccpMessage(message)
        networkClient.sendString.assert_called_with(message.pack())
class TestSCCPClientFactory(unittest.TestCase):
    handled = False
    
    def setUp(self):
        self.handled = False
        self.unkown = False
        self.lastMessageTypeReceived = 0x0000
        self.clientFactory = SCCPClientFactory(self.unused, self.unused) 

    def unused(self):
        '''
        unused callback
        '''
    def handleUnknown(self,message):
        self.lastMessageTypeReceived = message.sccpmessageType
        self.unkown = True
    
    def handleMessage(self,message):
        self.lastMessageTypeReceived = message.sccpmessageType
        self.handled = True
        

    def testHandleMessage(self):
        self.clientFactory = SCCPClientFactory(self.unused, self.unused) 
        self.clientFactory.addHandler(SCCPMessageType.RegisterAckMessage, self.handleMessage)
        self.clientFactory.handleMessage(SCCPRegisterAck())
        self.assertTrue(self.handled)
        self.assertEquals(SCCPMessageType.RegisterAckMessage,self.lastMessageTypeReceived)
        
    def testHandleUnknownMessage(self):
        message = SCCPMessage(0xFFFF)
        self.clientFactory.handleUnknownMessage(self.handleUnknown)
        self.clientFactory.handleMessage(message)
        self.assertTrue(self.unkown)
        self.assertEquals(0xFFFF,self.lastMessageTypeReceived)
        
    
    def testSendSccpMessage(self):
        message = SCCPMessage(SCCPMessageType.ButtonTemplateReqMessage)
        networkClient = Mock()
        self.clientFactory.client=networkClient
        self.clientFactory.sendSccpMessage(message)
        networkClient.sendString.assert_called_with(message.pack())
Esempio n. 6
0
    def createClient(self):
        log.info('creating sccp client factory')
        self.client = SCCPClientFactory(
                        self.on_sccp_connect_success,
                        self.on_sccp_connect_fail)

        self.client.handleUnknownMessage(self.onUnknownMessage)

        self.client.addHandler(SCCPMessageType.RegisterAckMessage,self.onRegisteredAck)

        self.client.addHandler(SCCPMessageType.CapabilitiesReqMessage,self.onCapabilitiesReq)
        self.client.addHandler(SCCPMessageType.OpenReceiveChannel, self.onOpenReceiveChannel)

        return self.client
 def testHandleMessage(self):
     self.clientFactory = SCCPClientFactory(self.unused, self.unused) 
     self.clientFactory.addHandler(SCCPMessageType.RegisterAckMessage, self.handleMessage)
     self.clientFactory.handleMessage(SCCPRegisterAck())
     self.assertTrue(self.handled)
     self.assertEquals(SCCPMessageType.RegisterAckMessage,self.lastMessageTypeReceived)
 def setUp(self):
     self.handled = False
     self.unkown = False
     self.lastMessageTypeReceived = 0x0000
     self.clientFactory = SCCPClientFactory(self.unused, self.unused) 
Esempio n. 9
0
class SCCPDumbPhone():
    '''
    Main sccp phone class
    '''


    def __init__(self,host,deviceName):
        self.host = host
        self.deviceName = deviceName
        self.callHandlers = set()
        self.toneHandler = None
        self.softKeysHandler = None
        
    def setLogger(self,logger):
        self.log = logger
    
    def setTimerProvider(self,timerProvider):
        self.timerProvider = timerProvider
    
    def createClient(self):
        log.info('creating sccp client factory')
        self.client = SCCPClientFactory(
                        self.on_sccp_connect_success,
                        self.on_sccp_connect_fail)

        self.client.handleUnknownMessage(self.onUnknownMessage)

        self.client.addHandler(SCCPMessageType.RegisterAckMessage,self.onRegisteredAck)

        self.client.addHandler(SCCPMessageType.CapabilitiesReqMessage,self.onCapabilitiesReq)
        self.client.addHandler(SCCPMessageType.OpenReceiveChannel, self.onOpenReceiveChannel)

        return self.client

    def onUnknownMessage(self,message):
        log.info('receive unkown message ' + message.toStr())

    def on_sccp_connect_success(self):
        log.info('Connected to server. Sending register with phone set : ' + self.deviceName)
        registerMessage = SCCPRegister(self.deviceName, self.host)
        self.client.sendSccpMessage(registerMessage)
        
    def on_sccp_connect_fail(self, reason):
        # reason is a twisted.python.failure.Failure  object
        log.info('Connection failed: %s' % reason.getErrorMessage())
        
    def onKeepAliveTimer(self):
        log.info('on keep alive')
        message = SCCPMessage(SCCPMessageType.KeepAliveMessage)
        self.client.sendSccpMessage(message)
        
    def onRegisteredAck(self,registerAck):
        log.info("sccp phone registered")
        log.info("--          keepAliveInterval : " + `registerAck.keepAliveInterval`)
        log.info("--               dateTemplate : " + `registerAck.dateTemplate`)
        log.info("-- secondaryKeepAliveInterval : " + `registerAck.secondaryKeepAliveInterval`)
        self.createTimer(registerAck.keepAliveInterval,self.onKeepAliveTimer)
        self.onRegistered()

    def onOpenReceiveChannel(self,message):
        self.client.sendSccpMessage(SCCPOpenReceiveChannelAck(0, self.host, 40000, message.conferenceId))


    def onCapabilitiesReq(self,message):
        log.info("sending capabilities response")
        self.client.sendSccpMessage(SCCPCapabilitiesRes())
        log.info("sending button template request message")
        self.client.sendSccpMessage(SCCPButtonTemplateReq())
        log.info("sending line status request message")
        self.client.sendSccpMessage(SCCPLineStatReq(1))
        log.info("sending register available lines")
        self.client.sendSccpMessage(SCCPRegisterAvailableLines())
        log.info("sending time date request message")
        self.client.sendSccpMessage(SCCPTimeDateReq())
 def setUp(self):
     self.handled = False
     self.unkown = False
     self.lastMessageTypeReceived = 0x0000
     self.clientFactory = SCCPClientFactory(self.unused, self.unused)
Esempio n. 11
0
class SCCPPhone():
    '''
    Main sccp phone class
    '''


    def __init__(self,host,deviceName):
        self.host = host
        self.deviceName = deviceName
        self.callHandlers = set()
        self.toneHandler = None
        self.softKeysHandler = None
        
    def setLogger(self,logger):
        self.log = logger
    
    def setTimerProvider(self,timerProvider):
        self.timerProvider = timerProvider

    
    def setRegisteredHandler(self,registeredHandler):
        self.registeredHandler = registeredHandler

    def setToneHandler(self,toneHandler):
        self.toneHandler = toneHandler
        
    def setDateTimePicker(self,dateTimePicker):
        self.dateTimePicker = dateTimePicker

    def setDisplayHandler(self,displayHandler):
        self.displayHandler = displayHandler

    def setSoftKeysHandler(self,softKeysHandler):
        self.softKeysHandler = softKeysHandler

    def setDisplayPromptStatusHandler(self,displayPromptStatusHandler):
        self.displayPromptStatusHandler = displayPromptStatusHandler

    def setSetRingerHandler(self,setRingerHandler):
        self.setRingerHandler = setRingerHandler
        
    def addCallHandler(self,callHandler):
        log.info(self.deviceName + ' adding call handler')
        self.callHandlers.add(callHandler)
        
    def createClient(self):
        log.info('creating sccp client factory')
        self.client = SCCPClientFactory(
                        self.on_sccp_connect_success,
                        self.on_sccp_connect_fail)

        self.client.handleUnknownMessage(self.onUnknownMessage)

        self.client.addHandler(SCCPMessageType.RegisterAckMessage,self.onRegisteredAck)
        self.client.addHandler(SCCPMessageType.KeepAliveAckMessage,self.onKeepAliveAck)

        self.client.addHandler(SCCPMessageType.CapabilitiesReqMessage,self.onCapabilitiesReq)
        self.client.addHandler(SCCPMessageType.OpenReceiveChannel, self.onOpenReceiveChannel)

        self.client.addHandler(SCCPMessageType.DefineTimeDate,self.onDefineTimeDate)
        self.client.addHandler(SCCPMessageType.SetSpeakerModeMessage,self.onSetSpeakerMode)
        self.client.addHandler(SCCPMessageType.CallStateMessage,self.onCallState)
        self.client.addHandler(SCCPMessageType.ActivateCallPlaneMessage,self.onActivateCallPlane)
        self.client.addHandler(SCCPMessageType.StartToneMessage,self.onStartTone)
        self.client.addHandler(SCCPMessageType.LineStatMessage,self.onLineStat)
        self.client.addHandler(SCCPMessageType.SetRingerMessage, self.onSetRinger)
        self.client.addHandler(SCCPMessageType.DisplayPromptStatusMessage, self.onDisplayPromptStatus)
        self.client.addHandler(SCCPMessageType.SelectSoftKeysMessage, self.onSelectSoftKeys)

        return self.client

    def on_sccp_connect_success(self):
        log.info('Connected to server. Sending register with phone set : ' + self.deviceName)
        registerMessage = SCCPRegister(self.deviceName, self.host)
        self.client.sendSccpMessage(registerMessage)
        
    def on_sccp_connect_fail(self, reason):
        # reason is a twisted.python.failure.Failure  object
        log.info('Connection failed: %s' % reason.getErrorMessage())
        
    def onKeepAliveTimer(self):
        log.info('on keep alive')
        message = SCCPMessage(SCCPMessageType.KeepAliveMessage)
        self.client.sendSccpMessage(message)
        
    def onUnknownMessage(self,message):
        log.info('receive unkown message ' + message.toStr())

    def onRegisteredAck(self,registerAck):
        log.info("sccp phone registered")
        log.info("--          keepAliveInterval : " + `registerAck.keepAliveInterval`)
        log.info("--               dateTemplate : " + `registerAck.dateTemplate`)
        log.info("-- secondaryKeepAliveInterval : " + `registerAck.secondaryKeepAliveInterval`)
        self.timerProvider.createTimer(registerAck.keepAliveInterval,self.onKeepAliveTimer)
        self.registeredHandler.onRegistered()

        
    def onKeepAliveAck(self,message):
        log.info("Keepalive ack")
    
    def onCapabilitiesReq(self,message):
        log.info("sending capabilities response")
        self.client.sendSccpMessage(SCCPCapabilitiesRes())
        log.info("sending button template request message")
        self.client.sendSccpMessage(SCCPButtonTemplateReq())
        log.info("sending line status request message")
        self.client.sendSccpMessage(SCCPLineStatReq(1))
        log.info("sending register available lines")
        self.client.sendSccpMessage(SCCPRegisterAvailableLines())
        log.info("sending time date request message")
        self.client.sendSccpMessage(SCCPTimeDateReq())

        
    def onDefineTimeDate(self,message):
        log.info('define time and date')
        self.dateTimePicker.setDateTime(message.day,message.month,message.year,message.hour,message.minute,message.seconds)
    
    def onSetSpeakerMode(self,message):
        log.info('set speaker mode '+`message.mode`)

    def onCallState(self,message):
        log.info('call state line : ' + `message.line` + ' for callId '+ `message.callId` + ' is ' + SCCPCallState.sccp_channelstates[message.callState])
        self.currentLine = message.line
        self.currentCallId=message.callId
        self.callState=message.callState
        
        for callHandler in self.callHandlers:
            callHandler.handleCall(message.line,message.callId,message.callState)
        
    def onLineStat(self,message):
        log.info('line stat ' + `message.line` + ' : ' + `message.dirNumber`)
        self.displayHandler.displayLineInfo(message.line,message.dirNumber)

    def onSetRinger(self,message):
        self.setRingerHandler.onSetRinger(message.ringType, message.ringMode, message.line, message.callId)

    def onDisplayPromptStatus(self,message):
        self.displayPromptStatusHandler.onDisplayPromptStatus(message.displayMessage, message.line, message.callId)

    def onStartTone(self,message):
        log.info('start tone : '+`message.tone` + ' timeout ' + `message.toneTimeout` + ' line ' + `message.line` + ' for callId '+ `message.callId`)
        if self.toneHandler is not None:
            self.toneHandler.handleTone(message.line,message.callId,message.tone)

    def onSelectSoftKeys(self,message):
        if self.softKeysHandler is not None:
            self.softKeysHandler.handleSoftKeys(message.line,message.callId,message.softKeySet, message.softKeyMap)

    def onOpenReceiveChannel(self,message):
        self.client.sendSccpMessage(SCCPOpenReceiveChannelAck(0, self.host, 40000, message.conferenceId))

    def onActivateCallPlane(self,message):
        log.info('Activate call plane on line '+`message.line`)
        
    def onDialPadButtonPushed(self,car):
        log.info("dialed : " + car)
        if (car == '#'):
            event = 15
        elif (car == '*'):
            event = 14
        else:
            event = int(car)
        message = SCCPKeyPadButton(event)
        self.client.sendSccpMessage(message)
        
    def dial(self,numberToDial):
        log.info('dialing : '+numberToDial)
        self.client.sendSccpMessage(SCCPSoftKeyEvent(SKINNY_LBL_NEWCALL))
        for digit in numberToDial:
            self.onDialPadButtonPushed(digit)
            
    def onSoftKey(self,event):
        log.info('on soft key '+`event`)
        if (event != SKINNY_LBL_NEWCALL):
            message = SCCPSoftKeyEvent(event,self.currentLine,self.currentCallId)
        else:
            message = SCCPSoftKeyEvent(event)
        self.client.sendSccpMessage(message)
        
    def answerCall(self):
        self.onSoftKey(SKINNY_LBL_ANSWER)
        
    def endCall(self,line,callId):
        message = SCCPSoftKeyEvent(SKINNY_LBL_ENDCALL,line,callId)
        self.client.sendSccpMessage(message)
Esempio n. 12
0
class SCCPPhone():
    '''
    Main sccp phone class
    '''


    def __init__(self,host,deviceName):
        self.host = host
        self.deviceName = deviceName
        self.callHandlers = set()
        
    def setLogger(self,logger):
        self.log = logger
    
    def setTimerProvider(self,timerProvider):
        self.timerProvider = timerProvider
    
    def setRegisteredHandler(self,registeredHandler):
        self.registeredHandler = registeredHandler
        
    def setDateTimePicker(self,dateTimePicker):
        self.dateTimePicker = dateTimePicker

    def setDisplayHandler(self,displayHandler):
        self.displayHandler = displayHandler
        
    def addCallHandler(self,callHandler):
        self.log(self.deviceName + ' adding call handler')
        self.callHandlers.add(callHandler)
        
    def createClient(self):
        self.log('creating sccp client factory')
        self.client = SCCPClientFactory(
                        self.on_sccp_connect_success,
                        self.on_sccp_connect_fail)
        self.client.handleUnknownMessage(self.onUnknownMessage)
        self.client.addHandler(SCCPMessageType.RegisterAckMessage,self.onRegisteredAck)
        self.client.addHandler(SCCPMessageType.CapabilitiesReqMessage,self.onCapabilitiesReq)
        self.client.addHandler(SCCPMessageType.KeepAliveAckMessage,self.onKeepAliveAck)
        self.client.addHandler(SCCPMessageType.DefineTimeDate,self.onDefineTimeDate)
        self.client.addHandler(SCCPMessageType.SetSpeakerModeMessage,self.onSetSpeakerMode)
        self.client.addHandler(SCCPMessageType.CallStateMessage,self.onCallState)
        self.client.addHandler(SCCPMessageType.ActivateCallPlaneMessage,self.onActivateCallPlane)
        self.client.addHandler(SCCPMessageType.StartToneMessage,self.onStartTone)
        self.client.addHandler(SCCPMessageType.LineStatMessage,self.onLineStat)
        
        return self.client

    def on_sccp_connect_success(self):
        self.log('Connected to server. Sending register with phone set : ' + self.deviceName)
        registerMessage = SCCPRegister(self.deviceName, self.host)
        self.client.sendSccpMessage(registerMessage)
        
    def on_sccp_connect_fail(self, reason):
        # reason is a twisted.python.failure.Failure  object
        self.log('Connection failed: %s' % reason.getErrorMessage())
        
    def onKeepAliveTimer(self):
        self.log('on keep alive')
        message = SCCPMessage(SCCPMessageType.KeepAliveMessage)
        self.client.sendSccpMessage(message)
        
    def onUnknownMessage(self,message):
        self.log('receive unkown message ' + message.toStr())

    def onRegisteredAck(self,registerAck):
        self.log("sccp phone registered")
        self.log("--          keepAliveInterval : " + `registerAck.keepAliveInterval`)
        self.log("--               dateTemplate : " + `registerAck.dateTemplate`)
        self.log("-- secondaryKeepAliveInterval : " + `registerAck.secondaryKeepAliveInterval`)
        self.timerProvider.createTimer(registerAck.keepAliveInterval,self.onKeepAliveTimer)
        self.registeredHandler.onRegistered()

        
    def onKeepAliveAck(self,message):
        self.log("Keepalive ack")
    
    def onCapabilitiesReq(self,message):
        self.log("sending capabilities response")
        self.client.sendSccpMessage(SCCPCapabilitiesRes())
        self.log("sending button template request message")
        self.client.sendSccpMessage(SCCPButtonTemplateReq())
        self.log("sending line status request message")
        self.client.sendSccpMessage(SCCPLineStatReq(1))
        self.log("sending register available lines")
        self.client.sendSccpMessage(SCCPRegisterAvailableLines())
        self.log("sending time date request message")
        self.client.sendSccpMessage(SCCPTimeDateReq())

        
    def onDefineTimeDate(self,message):
        self.log('define time and date')
        self.dateTimePicker.setDateTime(message.day,message.month,message.year,message.hour,message.minute,message.seconds)
    
    def onSetSpeakerMode(self,message):
        self.log('set speaker mode '+`message.mode`)

    def onCallState(self,message):
        self.log('call state line : ' + `message.line` + ' for callId '+ `message.callId` + ' is ' + SCCPCallState.sccp_channelstates[message.callState])
        self.currentLine = message.line
        self.currentCallId=message.callId
        self.callState=message.callState
        
        for callHandler in self.callHandlers:
            callHandler.handleCall(message.line,message.callId,message.callState)
        
    def onLineStat(self,message):
        self.log('line stat ' + `message.line` + ' : ' + `message.dirNumber`)
        self.displayHandler.displayLineInfo(message.line,message.dirNumber)

    def onStartTone(self,message):
        self.log('start tone : '+`message.tone` + ' timeout ' + `message.toneTimeout` + ' line ' + `message.line` + ' for callId '+ `message.callId`)

    def onActivateCallPlane(self,message):
        self.log('Activate call plane on line '+`message.line`)
        
    def onDialPadButtonPushed(self,car):
        self.log("dialed : " + car)
        if (car == '#'):
            event = 15
        elif (car == '*'):
            event = 14
        else:
            event = int(car)
        message = SCCPKeyPadButton(event)
        self.client.sendSccpMessage(message)
        
    def dial(self,numberToDial):
        self.log('dialing : '+numberToDial)
        self.client.sendSccpMessage(SCCPSoftKeyEvent(SKINNY_LBL_NEWCALL))
        for digit in numberToDial:
            self.onDialPadButtonPushed(digit)
            
    def onSoftKey(self,event):
        self.log('on soft key '+`event`)
        if (event != SKINNY_LBL_NEWCALL):
            message = SCCPSoftKeyEvent(event,self.currentLine,self.currentCallId)
        else:
            message = SCCPSoftKeyEvent(event)
        self.client.sendSccpMessage(message)
        
    def answerCall(self):
        self.onSoftKey(SKINNY_LBL_ANSWER)
        
    def endCall(self,line,callId):
        message = SCCPSoftKeyEvent(SKINNY_LBL_ENDCALL,line,callId)
        self.client.sendSccpMessage(message)