📄 voipcallrecord.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
// voipcallrecord.cpp : Implementation of CVoIPCallRecord
#include "VoIPStore.h"
#include "VoIPCallRecord.h"
#include "TimeUtils.h"
#include "stringutils.h"
/////////////////////////////////////////////////////////////////////////////
// CVoIPCallRecord
//Constructor
CVoIPCallLogRecord::CVoIPCallLogRecord()
{
//Set initial params to invalid
this->m_pFriendlyName[0] = 0;
this->m_pURI[0] = 0;
this->m_vctType = e_vctInvalid;
this->m_pVoIPName[0] = 0;
//Invalidates system times
InvalidateTime(&m_StartTime);
InvalidateTime(&m_EndTime);
ZeroMemory(&m_TimeStamp, sizeof(m_TimeStamp));
this->m_pDBOwner = NULL;
this->m_ceoid = 0;
}
//Destructor
CVoIPCallLogRecord::~CVoIPCallLogRecord()
{
}
HRESULT CVoIPCallLogRecord::get_CallType(VoIPCallType *pvctType)
{
if (pvctType == NULL)
return E_POINTER;
*pvctType = m_vctType;
return S_OK;
}
//Property: Sets the call type of this call log record
HRESULT CVoIPCallLogRecord::put_CallType(VoIPCallType vctType)
{
//error check and setting
if (vctType < VCT_FIRST || vctType > VCT_LAST)
{
return E_INVALIDARG;
}
m_vctType = vctType;
return S_OK;
}
//Property: Calculates the duration of a call
HRESULT CVoIPCallLogRecord::get_Duration(SYSTEMTIME *pdate)
{
BOOL fRes = TRUE;
SYSTEMTIME stNow = {0};
//Param Check
if (pdate == NULL)
return E_POINTER;
//If we have no start time, then we can't calculate duration
if (!IsValidTime(&m_StartTime) )
return VOIP_E_TIMENOTSET;
//If there is no end time, the call must still be going on
//So subtract NOW from the start time to get the current duration
if (!IsValidTime(&m_EndTime))
{
GetLocalTime(&stNow);
//Utility function to get the difference between two system times
fRes = GetTimeDifference(&stNow, &m_StartTime, pdate);
}
else
{
//Otherwise use the valid ending time
fRes = GetTimeDifference(&m_EndTime, &m_StartTime, pdate);
}
return (fRes) ? S_OK : E_FAIL;
}
//Property: Gets the ending time of this call log record.
HRESULT CVoIPCallLogRecord::get_EndTime(SYSTEMTIME *pdate)
{
if (pdate == NULL)
return E_POINTER;
if (!IsValidTime(&m_EndTime))
{
return VOIP_E_TIMENOTSET;
}
//Utility function to copy over the properties.
if (SysTimeCopy(pdate, &m_EndTime))
return S_OK;
else
return E_FAIL;
}
//Property: puts the endtime
HRESULT CVoIPCallLogRecord::put_EndTime(SYSTEMTIME date)
{
//copy properties
return (SysTimeCopy(&m_EndTime, &date)) ? S_OK : E_FAIL;
}
//Property: gets the start time
HRESULT CVoIPCallLogRecord::get_StartTime(SYSTEMTIME *pdate)
{
if (pdate == NULL)
return E_POINTER;
if (!IsValidTime(&m_StartTime))
{
return VOIP_E_TIMENOTSET;
}
return (SysTimeCopy(pdate, &m_StartTime)) ? S_OK : E_FAIL;
}
//property: gets the start time
HRESULT CVoIPCallLogRecord::put_StartTime(SYSTEMTIME date)
{
return (SysTimeCopy(&m_StartTime, &date)) ? S_OK : E_FAIL;
}
//property: gets the friendly name
HRESULT CVoIPCallLogRecord::get_FriendlyName(BSTR *pbstrFriendlyName)
{
if (pbstrFriendlyName == NULL)
return E_POINTER;
*pbstrFriendlyName = SysAllocString(m_pFriendlyName);
return (*pbstrFriendlyName != NULL) ? S_OK : E_FAIL;
}
//property: puts the friendly name
HRESULT CVoIPCallLogRecord::put_FriendlyName(BSTR bstrFriendlyName)
{
if (!bstrFriendlyName)
return E_POINTER;
StringCchCopy(m_pFriendlyName, _countof(m_pFriendlyName), bstrFriendlyName);
return S_OK;
}
//property: gets the URI
HRESULT CVoIPCallLogRecord::get_URI(BSTR *pbstrURI)
{
if (pbstrURI == NULL)
return E_INVALIDARG;
*pbstrURI = SysAllocString(m_pURI);
return (*pbstrURI != NULL) ? S_OK : E_FAIL;
}
//property: sets the URI
HRESULT CVoIPCallLogRecord::put_URI(BSTR bstrURI)
{
if (!bstrURI)
return E_POINTER;
StringCchCopy(m_pURI, _countof(m_pURI), bstrURI);
return S_OK;
}
//property: gets the VOIP name
HRESULT CVoIPCallLogRecord::get_VoIPName(BSTR *pbstrVoIPName)
{
if (pbstrVoIPName == NULL)
return E_POINTER;
*pbstrVoIPName = SysAllocString(m_pVoIPName);
return (*pbstrVoIPName != NULL) ? S_OK : E_FAIL;
}
//property: sets the VOIP name
HRESULT CVoIPCallLogRecord::put_VoIPName(BSTR bstrVoIPName)
{
if (!bstrVoIPName)
return E_POINTER;
StringCchCopy(m_pVoIPName, _countof(m_pVoIPName), bstrVoIPName);
return S_OK;
}
HRESULT CVoIPCallLogRecord::put_TimeStamp(
FILETIME& ft
)
{
m_TimeStamp = ft;
return S_OK;
}
/*------------------------------
Commit
Commits this record to the database it belongs to
Returns HRESULT indicating success or failure
--------------------------------*/
STDMETHODIMP CVoIPCallLogRecord::Commit()
{
HRESULT hr = S_OK;
//Prototypical record that is going to be written to the DB
CEPROPVAL vals[CALL_LOG_DB_NUMBER_PROPS];
FILETIME Zeros = {0};
ZeroMemory(vals, sizeof(vals));
//Error check:
if (!m_pDBOwner)
return E_FAIL;
//Set propids and values
vals[RECORD_ID_CALLTYPE].propid = CALL_LOG_CALLTYPE;
vals[RECORD_ID_CALLTYPE].val.lVal = m_vctType;
vals[RECORD_ID_ENDTIME].propid = CALL_LOG_ENDTIME;
SystemTimeToFileTime(&m_EndTime, &(vals[RECORD_ID_ENDTIME].val.filetime));
vals[RECORD_ID_FRIENDLYNAME].propid = CALL_LOG_FRIENDLYNAME;
vals[RECORD_ID_FRIENDLYNAME].val.lpwstr = m_pFriendlyName;
vals[RECORD_ID_STARTTIME].propid = CALL_LOG_STARTTIME;
SystemTimeToFileTime(&m_StartTime, &(vals[RECORD_ID_STARTTIME].val.filetime));
vals[RECORD_ID_URI].propid = CALL_LOG_URI;
vals[RECORD_ID_URI].val.lpwstr = m_pURI;
vals[RECORD_ID_VOIPNAME].propid = CALL_LOG_VOIPNAME;
vals[RECORD_ID_VOIPNAME].val.lpwstr = m_pVoIPName;
//fill in the timestamp if necessary
//has the timestamp been set yet?
if (memcmp(&Zeros, &m_TimeStamp, sizeof(FILETIME)) == 0)
{
GetSystemTimeAsFileTime(&m_TimeStamp);
}
vals[RECORD_ID_TIMESTAMP].propid = VOIP_TIME_STAMP;
vals[RECORD_ID_TIMESTAMP].val.filetime = m_TimeStamp;
//Check to see if we already have a place in the database
if (m_ceoid != 0)
{
//If we do, then edit the current record
if (!m_pDBOwner->EditRecord(m_ceoid, (CEPROPVAL*)vals, CALL_LOG_DB_NUMBER_PROPS))
{
//if we fail again, then the record was probably deleted already.
return HRESULT_FROM_WIN32(GetLastError());
}
}
else
{
//Otherwise add a new record to the DB
HRESULT hr = m_pDBOwner->AddNewRecord((CEPROPVAL*)vals, &m_ceoid);
if (FAILED(hr))
{
return hr;
}
}
return S_OK;
}
/*------------------------------
DeleteFromDB
Deletes a record, if it has been written to the DB
It is the callers job to Release the pointer to it!
Returns HRESULT indicating success or failure
--------------------------------*/
STDMETHODIMP CVoIPCallLogRecord::DeleteFromDB()
{
HRESULT hr = S_OK;
if (m_ceoid == 0)
{
return VOIP_E_RECORDNOTINDB;
}
if (!m_pDBOwner->DeleteRecord(m_ceoid))
{
hr = VOIP_E_RECORDNOTINDB;
}
//Reset ceoid;
if (SUCCEEDED(hr))
{
m_ceoid = 0;
}
//DOES NOT RELEASE!
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -