www.pudn.com > acdx.rar > PendingRequest.cpp


 /*============================================================= 
 
  
 Function: 
		 
 
 
 Author: Leon Wang  
==============================================================*/ 
// PendingRequest.cpp: implementation of the PendingRequest class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "PendingRequest.h" 
#include "sha1.h" 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
//##ModelId=424BB6430101 
int PendingRequest::RINGING = 1; 
//##ModelId=424BB6430102 
int PendingRequest::TALKING = 2; 
 
 
//##ModelId=424BB64300C3 
PendingRequest::PendingRequest() 
{ 
 
} 
    /** 
     * Create a new request object. 
     * @param _priority 
     * @param _queue 
     * @param _callerEndId 
     * @param _callRef 
     * @param _callerAlias 
     * @param _callerIp 
     * @param _timeout 
     * @param _status   Ringing / Talking 
     */ 
//##ModelId=424BB64300C4 
PendingRequest::PendingRequest(int _priority,  
									  CString _queue,  
									  CString _callerEndId,  
									  CString _callRef,  
									  CString _callerAlias,  
									  CString _callerIp,  
									  long _timeout,  
									  int _status)  
{ 
        priority = _priority; 
        queue = _queue; 
        callerEndId = _callerEndId; 
        callRef = _callRef; 
        callerAlias = _callerAlias; 
        callerIp = _callerIp; 
        timeout = _timeout; 
        status = _status; 
} 
 
//##ModelId=424BB64300E2 
PendingRequest::~PendingRequest() 
{ 
 
} 
    /** 
     * Sort requests by queue priority and expire time. 
     * @param o     Object to compare to 
     * @return      -1 / 0 / 1 
     */ 
//##ModelId=424BB64300E4 
int PendingRequest::compareTo(PendingRequest obj)  
{ 
        PendingRequest r2 = obj; 
        if (priority < r2.priority) 
            return 1; 
        if (priority > r2.priority) 
            return -1; 
        if (timeout < r2.timeout) 
            return -1; 
        if (timeout > r2.timeout) 
            return 1; 
        if (callerEndId.Compare(r2.callerEndId) < 0) 
            return -1; 
        if (callerEndId.Compare(r2.callerEndId) > 0) 
            return 1; 
        return callRef.Compare(r2.callRef); 
} 
 
 /** 
     * Requests are equal if endpoint ID and callRef match. 
     * @param o Object to compare to 
     * @return  T / F 
     */ 
//##ModelId=424BB64300E6 
BOOL PendingRequest::equals(PendingRequest obj)  
{ 
       PendingRequest r2 = obj; 
       return (callerEndId==r2.callerEndId && callRef==r2.callRef); 
} 
 
    /** 
     * Implement hashCode, based on what makes the object uniqe. 
     * @return  hash code 
     */ 
//##ModelId=424BB64300F3 
void PendingRequest::hashCode(CString & hashString)  
{ 
	hashString = callerEndId + callRef; 
	 
	LPTSTR p = hashString.GetBuffer(hashString.GetLength()); 
	SHA1HashCode(p);// care it !! test it 
	hashString = p; 
	hashString.ReleaseBuffer(); 
   // return (callerEndId + callRef).hashCode(); 
} 
 
//##ModelId=424BB64300F5 
void PendingRequest::SHA1HashCode(char* &str) 
{ 
	CSHA1 sha1; 
	sha1.Reset(); 
	sha1.Update((UINT_8 *)str, strlen(str)); 
	sha1.Final(); 
 
	sha1.ReportHash(str, CSHA1::REPORT_DIGIT); 
}