www.pudn.com > CP_IVR.zip > HErrLogger.cpp


// HErrLogger.cpp: implementation of the CHErrLogger class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "HErrLogger.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
CString CHErrLogger::m_path=_T("errors.log"); 
extern CString g_path; 
CHErrLogger::CHErrLogger() 
{ 
//_path = ; 
	m_path = g_path + m_path; 
} 
 
CHErrLogger::~CHErrLogger() 
{ 
 
} 
 
BOOL CHErrLogger::LogError(CString err) 
{ 
    CStdioFile File; 
    CFileException ex; 
 
	if (m_path == "") m_path=_T("errors.log"); 
 
	if (!File.Open(m_path, CFile::modeWrite | CFile::modeCreate|  
		CFile::modeNoTruncate | CFile::typeText, 0)) { 
 
        ex.ReportError(); 
        return FALSE; 
    } ; 
	 
	TRY { 
 
		File.SeekToEnd(); 
		File.WriteString(err); 
		File.Close(); 
 
	} CATCH (CFileException, e) { 
 
        //AfxMessageBox(_T("Unable to save error.")); 
        return FALSE; 
 
    } END_CATCH 
	 
	return TRUE; 
} 
 
BOOL CHErrLogger::LogError(UINT errCode) 
{ 
    CStdioFile File; 
    CFileException ex; 
	static CString sErr; 
//		CString sz; 
//		sz.Format(_T("Err: [code:%d], [date:%s], [time:%s], [reason:%s]\n"),e.code,e.date,e.time,e.result); 
 
	if (m_path == "") m_path=_T("errors.log"); 
 
	if (!File.Open(m_path, CFile::modeWrite | CFile::modeCreate|  
		CFile::modeNoTruncate | CFile::typeText, 0)) { 
 
        ex.ReportError(); 
        return FALSE; 
    } ; 
	 
	TRY { 
 
		sErr = GetErrorString(errCode); 
		File.SeekToEnd(); 
		File.WriteString(sErr); 
		File.Close(); 
 
	} CATCH (CFileException, e) { 
        return FALSE; 
    } END_CATCH 
	 
	return TRUE; 
} 
 
void CHErrLogger::SetFilePath(CString path) 
{ 
	m_path = path; 
} 
 
BOOL CHErrLogger::LogError(CTapiObj::TEx e) 
{ 
    CStdioFile File; 
    CFileException ex; 
	static CString sErr; 
//	CString sz; 
 
	sErr.Format(_T("Err: [code:%d], [date:%s], [time:%s], [reason:%s]\n"),e.code,e.date,e.time,GetErrorString(e.code)+_T(" ")+e.result); 
	if (m_path == "") m_path=_T("errors.log"); 
 
	if (!File.Open(m_path, CFile::modeWrite | CFile::modeCreate|  
		CFile::modeNoTruncate | CFile::typeText, 0)) { 
 
        ex.ReportError(); 
        return FALSE; 
    } ; 
	 
	TRY { 
		File.SeekToEnd(); 
		File.WriteString(sErr); 
		File.Close(); 
 
	} CATCH (CFileException, e) { 
        return FALSE; 
    } END_CATCH 
	 
	return TRUE; 
} 
 
CString CHErrLogger::GetErrorString(long TapiErrCode) 
{ 
	switch (TapiErrCode) { 
	case LINEERR_ADDRESSBLOCKED :  
		return _T("The specified address is blocked from being dialed on the specified call."); 
 
	case LINEERR_ALLOCATED :  
		return _T("The line cannot be opened due to a persistent condition, such as that of a serial port being exclusively opened by another process."); 
 
	case LINEERR_BADDEVICEID : 
		return _T("The specified device identifier or line device identifier (such as in a dwDeviceID parameter) is invalid or out of range."); 
 
	case LINEERR_BEARERMODEUNAVAIL : 
		return _T("The bearer mode member in LINECALLPARAMS is invalid, the bearer mode specified in LINECALLPARAMS is not available, or the call's bearer mode cannot be changed to the specified bearer mode."); 
 
	case LINEERR_BILLINGREJECTED : 
		return _T("The billing mode of the call was rejected."); 
 
	case LINEERR_CALLUNAVAIL : 
		return _T("All call appearances on the specified address are currently in use."); 
 
	case LINEERR_COMPLETIONOVERRUN : 
		return _T("The maximum number of outstanding call completions has been exceeded. "); 
 
	case LINEERR_CONFERENCEFULL : 
		return _T("The maximum number of parties for a conference has been reached, or the requested number of parties cannot be satisfied."); 
 
	case LINEERR_DIALBILLING : 
		return _T("The dialable address parameter contains dialing control characters that are not processed by the service provider."); 
 
	case LINEERR_DIALDIALTONE : 
		return _T("The dialable address parameter contains dialing control characters that are not processed by the service provider. "); 
 
	case LINEERR_DIALPROMPT : 
		return _T("The dialable address parameter contains dialing control characters that are not processed by the service provider."); 
 
	case LINEERR_DIALQUIET : 
		return _T("The dialable address parameter contains dialing control characters that are not processed by the service provider."); 
 
	case LINEERR_DIALVOICEDETECT : 
		return _T("Use of the \":\" dial modifier is not supported. This value is exposed only to applications that negotiate a TAPI version of 2.0 or higher."); 
 
//	case LINEERR_DISCONNECTED : LoadStrin 
//return _T(""); 
 
	case LINEERR_INCOMPATIBLEAPIVERSION : 
		return _T("The application requested a TAPI version or version range that is either incompatible with, or cannot be supported by, the Telephony API implementation and the corresponding service provider. "); 
 
//	case LINEERR_INCOMPATIBLEEXTVERSION : 
//		return _T(""); 
 
	case LINEERR_INIFILECORRUPT : 
		return _T("The Telephon.ini file cannot be read or understood properly by TAPI because of internal inconsistencies or formatting problems. For example, the [Locations], [Cards], or [Countries] section of the Telephon.ini file may be corrupted or inconsistent."); 
 
	case LINEERR_INUSE : 
		return _T("The line device is in use and cannot currently be configured, allow a party to be added, allow a call to be answered, allow a call to be placed, or allow a call to be transferred."); 
 
	case LINEERR_INVALADDRESS : 
		return _T("A specified address is either invalid or not allowed. If invalid, the address contains invalid characters or digits, or the destination address contains dialing control characters (W, @, $, or ?) that are not supported by the service provider. If not allowed, the specified address is either not assigned to the specified line or is not valid for address redirection."); 
 
	case LINEERR_INVALADDRESSID : 
		return _T("The specified address identifier is either invalid or out of range."); 
 
	case LINEERR_INVALADDRESSMODE : 
		return _T("The specified address mode is invalid."); 
 
	case LINEERR_INVALADDRESSSTATE : 
		return _T("The specified address state contains one or more bits that are not LINEADDRESSSTATE_ constants."); 
 
//	case LINEERR_INVALADDRESSTYPE : LoadString(AfxGetApp()->m_hInstance,IDS_LINEERR_INVALADDRESSTYPE ,res.GetBuffer(nLength),nSize); break; 
//	case LINEERR_INVALAGENTACTIVITY : LoadString(AfxGetApp()->m_hInstance,IDS_ ,res.GetBuffer(nLength),nSize); break; 
	case LINEERR_INVALAGENTACTIVITY : 
		return _T("The specified agent activity is not valid.\nThe application invoking this operation is the target of the indirect handoff. That is, TAPI has determined that the calling application is also the highest priority application for the given media type. This value is exposed only to applications that negotiate a TAPI version of 2.0 or higher. \n"); 
 
	case LINEERR_INVALAGENTGROUP : 
		return _T("The specified agent group information is not valid or contains errors. The requested action has not been carried out. \nLINEERR_INVALAGENTGROUP \nThe application referenced an agent group that is not valid. This value is exposed only to applications that negotiate a TAPI version of 2.0 or higher."); 
 
//	case LINEERR_INVALAGENTGROUP : LoadString(AfxGetApp()->m_hInstance,IDS_ ,res.GetBuffer(nLength),nSize); break; 
	case LINEERR_INVALAGENTID : 
		return _T("LINEERR_INVALAGENTID \nThe specified agent identifier is invalid. \nLINEERR_INVALAGENTID \nAn invalid agent identifier was used. This value is exposed only to applications that negotiate a TAPI version of 2.0 or higher. \n"); 
 
//	case LINEERR_INVALAGENTID : LoadString(AfxGetApp()->m_hInstance,IDS_ ,res.GetBuffer(nLength),nSize); break; 
//	case LINEERR_INVALAGENTSESSIONSTATE : LoadString(AfxGetApp()->m_hInstance,IDS_LINEERR_INVALAGENTSESSIONSTATE ,res.GetBuffer(nLength),nSize); break; 
//	case LINEERR_INVALAGENTSKILL : LoadString(AfxGetApp()->m_hInstance,IDS_LINEERR_INVALAGENTSKILL ,res.GetBuffer(nLength),nSize); break; 
	case LINEERR_INVALAGENTSTATE : 
		return _T("The specified agent state is not valid or contains errors. No changes have been made to the agent state of the specified address.The application referenced an agent state that is not valid. This value is exposed only to applications that negotiate a TAPI version of 2.0 or higher. \n"); 
 
//	case LINEERR_INVALAGENTSTATE : LoadString(AfxGetApp()->m_hInstance,IDS_ ,res.GetBuffer(nLength),nSize); break; 
//	case LINEERR_INVALAGENTSUPERVISOR : LoadString(AfxGetApp()->m_hInstance,IDS_LINEERR_INVALAGENTSUPERVISOR ,res.GetBuffer(nLength),nSize); break; 
	case LINEERR_INVALAPPHANDLE : 
		return _T("The application handle (such as specified by a hLineApp parameter) or the application registration handle is invalid. "); 
 
	case LINEERR_INVALAPPNAME : 
		return _T("The specified application name is invalid. If an application name is specified by the application, it is assumed that the string does not contain any non-displayable characters, and is zero-terminated."); 
 
	case LINEERR_INVALBEARERMODE : 
		return _T("The specified bearer mode is invalid. \n"); 
 
	case LINEERR_INVALCALLCOMPLMODE : 
		return _T("The specified completion is invalid. \n"); 
 
	case LINEERR_INVALCALLHANDLE : 
		return _T("The specified call handle is not valid. For example, the handle is not NULL but does not belong to the given line. In some cases, the specified call device handle is invalid. \n"); 
 
	case LINEERR_INVALCALLPARAMS : 
		return _T("The specified call parameters are invalid."); 
 
	case LINEERR_INVALCALLPRIVILEGE : 
		return _T("The specified call privilege parameter is invalid."); 
 
	case LINEERR_INVALCALLSELECT : 
		return _T("The specified select parameter is invalid. \n"); 
 
	case LINEERR_INVALCALLSTATE : 
		return _T("The current state of a call is not in a valid state for the requested operation. \n"); 
 
	case LINEERR_INVALCALLSTATELIST : 
		return _T("The specified call state list is invalid. "); 
 
	case LINEERR_INVALCARD : 
		return _T("The permanent card identifier specified in dwCard could not be found in any entry in the [Cards] section in the registry. \n"); 
 
	case LINEERR_INVALCOMPLETIONID : 
		return _T("The completion identifier is invalid. "); 
 
	case LINEERR_INVALCONFCALLHANDLE : 
		return _T("The specified call handle for the conference call is invalid or is not a handle for a conference call."); 
 
	case LINEERR_INVALCONSULTCALLHANDLE : 
		return _T("The specified consultation call handle is invalid."); 
 
	case LINEERR_INVALCOUNTRYCODE : 
		return _T("The specified country code is invalid. \n"); 
 
	case LINEERR_INVALDEVICECLASS : 
		return _T("The line device has no associated device for the given device class, or the specified line does not support the indicated device class."); 
 
	case LINEERR_INVALDEVICEHANDLE : 
		return _T("The line device handle is invalid."); 
 
	case LINEERR_INVALDIALPARAMS : 
		return _T("The dialing parameters are invalid."); 
 
	case LINEERR_INVALDIGITLIST : 
		return _T("The specified digit list is invalid."); 
 
	case LINEERR_INVALDIGITMODE : 
		return _T("The specified digit mode is invalid."); 
 
	case LINEERR_INVALDIGITS : 
		return _T("The specified termination digits are not valid."); 
 
	case LINEERR_INVALEXTVERSION : 
		return _T("The service provider extension version number is invalid. \n"); 
 
	case LINEERR_INVALFEATURE : 
		return _T("The dwFeature parameter is invalid. \nThe application invoked a feature that is not available on this line. \n"); 
 
//	case LINEERR_INVALFEATURE : LoadS 
	case LINEERR_INVALGROUPID : 
		return _T("The specified group identifier is invalid."); 
 
	case LINEERR_INVALLINEHANDLE : 
		return _T("The specified call, device, line device, or line handle is invalid."); 
 
	case LINEERR_INVALLINESTATE : 
		return _T("The device configuration may not be changed in the current line state. The line may be in use by another application or a dwLineStates parameter contains one or more bits that are not LINEDEVSTATE_ constants. The LINEERR_INVALLINESTATE value can also indicate that the device is DISCONNECTED or OUTOFSERVICE. These states are indicated by setting the bits corresponding to the LINEDEVSTATUSFLAGS_CONNECTED and LINEDEVSTATUSFLAGS_INSERVICE values to 0 in the dwDevStatusFlags member of the LINEDEVSTATUS structure returned by the lineGetLineDevStatus function."); 
 
	case LINEERR_INVALLOCATION : 
		return _T("The permanent location identifier specified in dwLocation could not be found in any entry in the [Locations] section in the registry. \n"); 
 
	case LINEERR_INVALMEDIALIST : 
		return _T("The specified media list is invalid. \n"); 
 
	case LINEERR_INVALMEDIAMODE : 
		return _T("The list of media types (modes) to be monitored contains invalid information, the specified media type parameter is invalid, or the service provider does not support the specified media type. The media types supported on the line are listed in the dwMediaModes member in the LINEDEVCAPS structure. "); 
 
	case LINEERR_INVALMESSAGEID : 
		return _T("The number given in dwMessageID is outside the range specified by the dwNumCompletionMessages member in the LINEADDRESSCAPS structure. \n"); 
 
	case LINEERR_INVALPARAM : 
		return _T("A parameter or structure that a parameter points to contains invalid information, a country code is invalid, a window handle is invalid, or the specified forward list parameter contains invalid information. "); 
 
	case LINEERR_INVALPARKID : 
		return _T("The park identifier is invalid. "); 
 
	case LINEERR_INVALPARKMODE : 
		return _T("The specified park mode is invalid."); 
 
	case LINEERR_INVALPASSWORD : 
		return _T("The specified password is not correct and the requested action has not been carried out. \nThe application used an invalid password. This value is exposed only to applications that negotiate a TAPI version of 2.0 or higher. "); 
 
	case LINEERR_INVALPOINTER : 
		return _T("One or more of the specified pointer parameters (such as lpCallList, lpdwAPIVersion, lpExtensionID, lpdwExtVersion, lphIcon, lpLineDevCaps, and lpToneList) are invalid, or a required pointer to an output parameter is NULL."); 
 
	case LINEERR_INVALPRIVSELECT : 
		return _T("An invalid flag or combination of flags was set for the dwPrivileges parameter. \n"); 
 
	case LINEERR_INVALRATE :  
		return _T("The specified rate is invalid. \n"); 
 
	case LINEERR_INVALREQUESTMODE : 
		return _T("The LINEREQUESTMODE indicator is invalid. \n"); 
 
	case LINEERR_INVALTERMINALID : 
		return _T("The specified terminal identifier is invalid. \n"); 
 
	case LINEERR_INVALTERMINALMODE :  
		return _T("The specified terminal modes parameter is invalid. \n"); 
 
	case LINEERR_INVALTIMEOUT : 
		return _T("Timeouts are not supported or a value falls outside the valid range specified in LINEDEVCAPS. "); 
 
	case LINEERR_INVALTONE : 
		return _T("The specified custom tone does not represent a valid tone or is made up of too many frequencies or the specified tone structure does not describe a valid tone. \n"); 
 
	case LINEERR_INVALTONELIST : 
		return _T("The specified tone list is invalid. "); 
 
	case LINEERR_INVALTONEMODE : 
		return _T("The specified tone mode parameter is invalid. \n"); 
 
	case LINEERR_INVALTRANSFERMODE :  
		return _T("The specified transfer mode parameter is invalid. \n"); 
 
	case LINEERR_LINEMAPPERFAILED : 
		return _T("LINEMAPPER was the value passed in the dwDeviceID parameter, but no lines were found that match the requirements specified in the lpCallParams parameter. \n"); 
 
	case LINEERR_NOCONFERENCE : 
		return _T("The specified call is not a conference call handle or a participant call. \n"); 
 
	case LINEERR_NODEVICE : 
		return _T("The specified device identifier, which was previously valid, is no longer accepted because the associated device has been removed from the system since TAPI was last initialized. Alternately, the line device has no associated device for the given device class. \n"); 
 
	case LINEERR_NODRIVER : 
		return _T("Either Tapiaddr.dll could not be located or the telephone service provider for the specified device found that one of its components is missing or corrupt in a way that was not detected at initialization time. The user should be advised to use the Telephony Control Panel to correct the problem. \n"); 
 
 
	case LINEERR_NOMEM : 
		return _T("Insufficient memory to perform the operation, or unable to lock memory. \n"); 
 
	case LINEERR_NOMULTIPLEINSTANCE : 
		return _T("A telephony service provider that does not support multiple instances is listed more than once in the [Providers] section in the registry. The application should advise the user to use the Telephony Control Panel to remove the duplicated driver. \nMultiple instances of this service provider are not allowed. \n"); 
 
	case LINEERR_NOREQUEST : 
		return _T("There currently is no request pending of the indicated mode, or the application is no longer the highest-priority application for the specified request mode. \n"); 
 
	case LINEERR_NOTOWNER : 
		return _T("The application does not have owner privilege to the specified call. \n"); 
 
	case LINEERR_NOTREGISTERED : 
		return _T("The application is not registered as a request recipient for the indicated request mode. \n"); 
 
	case LINEERR_OPERATIONFAILED : 
		return _T("The operation failed for an unspecified or unknown reason. \n"); 
 
	case LINEERR_OPERATIONUNAVAIL : 
		return _T("The operation is not available, such as for the given device or specified line. \n"); 
 
	case LINEERR_RATEUNAVAIL : 
		return _T("The service provider currently does not have enough bandwidth available for the specified rate. \n"); 
 
	case LINEERR_REINIT : 
		return _T("If TAPI reinitialization has been requested, for example as a result of adding or removing a telephony service provider, then lineInitialize, lineInitializeEx, or lineOpen requests are rejected with this error until the last application shuts down its usage of the API (using lineShutdown), at which time the new configuration becomes effective and applications are once again permitted to call lineInitialize or lineInitializeEx. \nLINEERR_REINIT \nThe application attempted to initialize TAPI twice. \n"); 
 
	case LINEERR_REQUESTOVERRUN : 
		return _T("More requests are pending than the device can handle. \n"); 
 
	case LINEERR_RESOURCEUNAVAIL : 
		return _T("Insufficient resources to complete the operation. For example, a line cannot be opened due to a dynamic resource overcommitment. \n"); 
 
	case LINEERR_STRUCTURETOOSMALL : 
		return _T("The dwTotalSize member of a structure does not specify enough memory to contain the fixed portion of the specified structure. \n"); 
 
	case LINEERR_TARGETNOTFOUND : 
		return _T("A target for the call handoff was not found. This can occur if the named application did not open the same line with the LINECALLPRIVILEGE_OWNER bit in the dwPrivileges parameter of lineOpen. Or, in the case of media-mode handoff, no application has opened the same line with the LINECALLPRIVILEGE_OWNER bit in the dwPrivileges parameter of lineOpen and with the media type specified in the dwMediaMode parameter having been specified in the dwMediaModes parameter of lineOpen. \n"); 
 
	case LINEERR_TARGETSELF : 
		return _T("The application invoking this operation is the target of the indirect handoff. That is, TAPI has determined that the calling application is also the highest priority application for the given media type. \n"); 
 
	case LINEERR_UNINITIALIZED : 
		return _T("The operation was invoked before any application called lineInitialize or lineInitializeEx. \n"); 
 
	case LINEERR_USERUSERINFOTOOBIG : 
		return _T("The string containing user-user information exceeds the maximum number of bytes specified in the dwUUIAcceptSize, dwUUIAnswerSize, dwUUIDropSize, dwUUIMakeCallSize, or dwUUISendUserUserInfoSize member of LINEDEVCAPS, or the string containing user-user information is too long. \n"); 
	} 
	return _T("Unknown error."); 
}