📄 eventvalidator.cpp
字号:
// // // Copyright (C) 2005-2006 SIPez LLC.// Licensed to SIPfoundry under a Contributor Agreement.// // Copyright (C) 2004-2006 SIPfoundry Inc.// Licensed by SIPfoundry under the LGPL license.// // Copyright (C) 2004-2006 Pingtel Corp.// Licensed to SIPfoundry under a Contributor Agreement.// // $$//////////////////////////////////////////////////////////////////////////////#include "EventValidator.h"#include "tapi/sipXtapi.h"#include "tapi/sipXtapiEvents.h"#include "tapi/sipXtapiInternal.h"#include "os/OsBSem.h"#include "os/OsMutex.h"#include "os/OsLock.h"#include "utl/UtlSList.h"EventValidator::EventValidator(const char* szTitle) : m_semUnprocessed(OsBSem::Q_FIFO, OsBSem::EMPTY) , m_mutLists(OsMutex::Q_FIFO) { m_title = szTitle ; m_pUnfoundEvent = NULL ; reset() ;}EventValidator::~EventValidator(){ reset() ;}void EventValidator::ignoreEventCategory(SIPX_EVENT_CATEGORY category) { assert((category >= 0) && (category < MAX_EVENT_CATEGORIES)) ; m_filterCategories[category] = true ;}bool EventValidator::isIgnoredCateogry(SIPX_EVENT_CATEGORY category){ assert((category >= 0) && (category < MAX_EVENT_CATEGORIES)) ; return m_filterCategories[category] ;}void EventValidator::setDefaultTimeout(int iTimeoutInSecs){ assert(iTimeoutInSecs >= 0) ; m_iDefaultTimeoutInSecs = iTimeoutInSecs ;}void EventValidator::setMaxLookhead(int iMaxLookAhead){ assert(iMaxLookAhead >= 0) ; m_iMaxLookAhead = iMaxLookAhead ;}void EventValidator::reset(){ OsLock lock(m_mutLists) ; m_iDefaultTimeoutInSecs = 45 ; m_iMaxLookAhead = 4 ; for (int i=0; i<MAX_EVENT_CATEGORIES; i++) { m_filterCategories[i] = false ; } if (m_pUnfoundEvent) { delete m_pUnfoundEvent ; } while (!m_unprocessedEvents.isEmpty()) { UtlString* pString = (UtlString*) m_unprocessedEvents.at(0) ; m_unprocessedEvents.removeAt(0) ; delete pString ; } while (!m_processedEvents.isEmpty()) { UtlString* pString = (UtlString*) m_processedEvents.at(0) ; m_processedEvents.removeAt(0) ; delete pString ; } m_eErrorType = EVENT_VALIDATOR_ERROR_NONE ;}bool EventValidator::waitForCallEvent(SIPX_LINE hLine, SIPX_CALL hCall, SIPX_CALLSTATE_EVENT event, SIPX_CALLSTATE_CAUSE cause, bool bStrictOrderMatch, int iTimeoutInSecs, const char* remoteAssertedIdentity){ bool bFound = true ; if (!isIgnoredCateogry(EVENT_CATEGORY_CALLSTATE)) { UtlString* pString = allocCallStateEntry(hCall, hLine, event, cause, remoteAssertedIdentity) ; bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs) ; delete pString ; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000) ; report() ; } return bFound ;}bool EventValidator::waitForMessage(SIPX_LINE hLine, const char* szMsg, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound ; UtlString* pString = allocMessageEvent(hLine, szMsg) ; bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs) ; delete pString ; if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000) ; report() ; } return bFound ;}bool EventValidator::waitForLineEvent(SIPX_LINE hLine, SIPX_LINESTATE_EVENT event, SIPX_LINESTATE_CAUSE cause, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true ; if (!isIgnoredCateogry(EVENT_CATEGORY_LINESTATE)) { UtlString* pString = allocLineStateEntry(hLine, event, cause) ; bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs) ; delete pString ; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000) ; report() ; } return bFound ;}bool EventValidator::waitForInfoStatusEvent(SIPX_INFO hInfo, int status, int responseCode, const char* szResponseText, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true ; if (!isIgnoredCateogry(EVENT_CATEGORY_INFO_STATUS)) { UtlString* pString = allocInfoStatusEvent(hInfo, status, responseCode, szResponseText) ; bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs) ; delete pString ; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000) ; report() ; } return bFound ;}bool EventValidator::waitForInfoEvent(SIPX_CALL hCall, SIPX_LINE hLine, const char* szFromURL, const char* szUserAgent, const char* szContentType, const char* szContent, int nContentLength, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true ; if (!isIgnoredCateogry(EVENT_CATEGORY_INFO)) { UtlString* pString = allocInfoEvent(hCall, hLine, szFromURL, szUserAgent, szContentType, szContent, nContentLength) ; bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs) ; delete pString ; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000) ; report() ; } return bFound ;}bool EventValidator::waitForConfigEvent(SIPX_CONFIG_EVENT event, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true ; if (!isIgnoredCateogry(EVENT_CATEGORY_CONFIG)) { UtlString* pString = allocConfigEvent(event) ; bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs) ; delete pString ; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000) ; report() ; } return bFound ;}bool EventValidator::hasUnprocessedEvents() { bool bRC = false ; OsLock lock(m_mutLists) ; bRC = !m_unprocessedEvents.isEmpty() ; return bRC ;}bool EventValidator::validateNoWaitingEvent() { bool bWaitingEvents = hasUnprocessedEvents() ; if (bWaitingEvents) { m_eErrorType = EVENT_VALIDATOR_ERROR_UNEXPECTED ; report() ; } return bWaitingEvents ;}const char* EventValidator::getTitle(){ return m_title.data();}void EventValidator::report(){ int nElements, i ; OsLock lock(m_mutLists) ; printf("\r\n") ; printf("%s EventValidator Error: ", m_title.data()) ; switch (m_eErrorType) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -