DuoFernGateway/module_private.php
/**
     * Waits for a given response
     *
     * @param string $exptedResponse
     *            expected response msg
     * @return boolean|string response msg or false on failure
     */
Waits for a given response
@param string $exptedResponse
expected response msg
@return boolean|string response msg or false on failure
Waits for a given response @param string $exptedResponse expected response msg @return boolean|string response msg or false on failure
private function WaitForResponse($expectedResponse)
    {
        if (!preg_match(DuoFernRegex::DUOFERN_REGEX_MSG, $expectedResponse)) {
            return false;
        }
        for ($i = 0; $i < 500; $i++) {
            $response = $this->WaitForResponseBuffer->Get($expectedResponse);
            if ($response !== false) {
                if ($this->SemaphoreEnter('WaitForResponseBuffer')) {
                    $waitForResponseBuffer = $this->WaitForResponseBuffer;
                    $waitForResponseBuffer->Remove($expectedResponse);
                    $this->WaitForResponseBuffer = $waitForResponseBuffer;
                    $this->SemaphoreLeave('WaitForResponseBuffer');
                    return $response;
                }
            }
            IPS_Sleep(10);
        }
        if ($this->SemaphoreEnter('WaitForResponseBuffer')) {
            $waitForResponseBuffer = $this->WaitForResponseBuffer;
            $waitForResponseBuffer->Remove($expectedResponse);
            $this->WaitForResponseBuffer = $waitForResponseBuffer;
            $this->SemaphoreLeave('WaitForResponseBuffer');
        }
        $this->SendDebug("TIMEOUT WAITFORRESPONSE", $this->ConvertMsgToSend($expectedResponse), 1);
        return false;
    }
private function WaitForResponse ( $ expectedResponse ) { if ( ! preg_match ( DuoFernRegex :: DUOFERN_REGEX_MSG , $ expectedResponse ) ) { return false ; } for ( $ i = 0 ; $ i < 500 ; $ i ++ ) { $ response = $ this -> WaitForResponseBuffer -> Get ( $ expectedResponse ) ; if ( $ response !== false ) { if ( $ this -> SemaphoreEnter ( 'WaitForResponseBuffer' ) ) { $ waitForResponseBuffer = $ this -> WaitForResponseBuffer ; $ waitForResponseBuffer -> Remove ( $ expectedResponse ) ; $ this -> WaitForResponseBuffer = $ waitForResponseBuffer ; $ this -> SemaphoreLeave ( 'WaitForResponseBuffer' ) ; return $ response ; } } IPS_Sleep ( 10 ) ; } if ( $ this -> SemaphoreEnter ( 'WaitForResponseBuffer' ) ) { $ waitForResponseBuffer = $ this -> WaitForResponseBuffer ; $ waitForResponseBuffer -> Remove ( $ expectedResponse ) ; $ this -> WaitForResponseBuffer = $ waitForResponseBuffer ; $ this -> SemaphoreLeave ( 'WaitForResponseBuffer' ) ; } $ this -> SendDebug ( " TIMEOUT WAITFORRESPONSE " , $ this -> ConvertMsgToSend ( $ expectedResponse ) , 1 ) ; return false ; }
Waits for a given response
 @param string $exptedResponse
            expected response msg
 @return boolean|string response msg or false on failure
Waits for a given response @param string $exptedResponse expected response msg @return boolean|string response msg or false on failure
// check valid msg // try to get response 500 times // get data // remove msg from buffer (success) // $this->SendDebug ( "RECEIVED RESPONSE", $this->ConvertMsgToSend ( $expectedResponse ), 1 ); // wait 10 ms // remove msg from buffer (timeout) // send expected response as debug msg