📄 voipcallerinforecord.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.
//
// VoIPCallerInfoRecord.cpp : Implementation of CVoIPCallerInfoRecord
#include "VoIPStore.h"
#include "VoIPCallerInfoRecord.h"
#include "voipstore.h"
#include "stringutils.h"
/////////////////////////////////////////////////////////////////////////////
// CVoIPCallerInfoRecord
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::CVoIPCallerInfoRecord
Constructor for CVoIPCallerInfoRecord.
------------------------------------------------------------------------------*/
CVoIPCallerInfoRecord::CVoIPCallerInfoRecord()
{
//Set initial params to invalid
m_bstrURI = NULL;
m_bstrVoIPName = NULL;
m_bstrFriendlyName = NULL;
m_bstrRingTonePath = NULL;
m_bstrForwardingURI = NULL;
m_idxSpeedDial = VOIP_INVALID_SPEED_DIAL_ENTRY;
m_vcifFlags = 0;
m_pOwnerDB = NULL;
m_ceoid = 0;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::~CVoIPCallerInfoRecord
Destructor for CVoIPCallerInfoRecord.
------------------------------------------------------------------------------*/
CVoIPCallerInfoRecord::~CVoIPCallerInfoRecord()
{
SysFreeString(m_bstrURI);
m_bstrURI = NULL;
SysFreeString(m_bstrVoIPName);
m_bstrVoIPName = NULL;
SysFreeString(m_bstrFriendlyName);
m_bstrFriendlyName = NULL;
SysFreeString(m_bstrRingTonePath);
m_bstrRingTonePath = NULL;
SysFreeString(m_bstrForwardingURI);
m_bstrForwardingURI = NULL;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::get_URI
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::get_URI(
/* [retval][out] */ BSTR *pbstrURI
)
{
// Validation is performed in CopyBSTR
return CopyBSTR(
pbstrURI,
m_bstrURI,
FALSE
);
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::put_URI
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::put_URI(
/* [in] */ BSTR bstrURI
)
{
// Validation is performed in CopyBSTR
return CopyBSTR(
&m_bstrURI,
bstrURI,
TRUE
);
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::get_FriendlyName
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::get_FriendlyName(
/* [retval][out] */ BSTR *pbstrFriendlyName
)
{
// Validation is performed in CopyBSTR
return CopyBSTR(
pbstrFriendlyName,
m_bstrFriendlyName,
FALSE
);
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::put_FriendlyName
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::put_FriendlyName(
/* [in] */ BSTR bstrFriendlyName
)
{
// Validation is performed in CopyBSTR
return CopyBSTR(
&m_bstrFriendlyName,
bstrFriendlyName,
TRUE
);
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::get_VoIPName
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::get_VoIPName(
/* [retval][out] */ BSTR *pbstrVoIPName
)
{
// Validation is performed in CopyBSTR
return CopyBSTR(
pbstrVoIPName,
m_bstrVoIPName,
FALSE
);
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::put_VoIPName
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::put_VoIPName(
/* [in] */ BSTR bstrVoIPName
)
{
// Validation is performed in CopyBSTR
return CopyBSTR(
&m_bstrVoIPName,
bstrVoIPName,
TRUE
);
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::get_SpeedDialEntry
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::get_SpeedDialEntry(
/* [retval][out] */ INT *pidxSpeedDial
)
{
if (pidxSpeedDial == NULL)
{
return E_POINTER;
}
*pidxSpeedDial = m_idxSpeedDial;
return S_OK;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::put_SpeedDialEntry
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::put_SpeedDialEntry(
/* [in] */ INT idxSpeedDial
)
{
// No validation done here; just about any value is acceptable as a speed
// dial entry as it's the app's responsibility to honor this value.
m_idxSpeedDial = idxSpeedDial;
return S_OK;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::get_Blocked
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::get_Blocked(
/* [retval][out] */ VARIANT_BOOL * pfBlocked
)
{
if (pfBlocked == NULL)
{
return E_POINTER;
}
// Query the flags for blocked status
*pfBlocked = (m_vcifFlags & e_vcifBlocked) ? VARIANT_TRUE : VARIANT_FALSE;
return S_OK;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::put_Blocked
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::put_Blocked(
/* [in] */ VARIANT_BOOL fBlocked
)
{
if(fBlocked != VARIANT_FALSE)
{
// Set the blocked status flag
m_vcifFlags |= e_vcifBlocked;
}
else
{
// Clear the blocked status flag
m_vcifFlags &= ~e_vcifBlocked;
}
return S_OK;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::get_ForwardingURI
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::get_ForwardingURI(
/* [retval][out] */ BSTR *pbstrForwardingURI
)
{
// Validation is performed in CopyBSTR
return CopyBSTR(
pbstrForwardingURI,
m_bstrForwardingURI,
FALSE
);
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::put_ForwardingURI
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::put_ForwardingURI(
/* [in] */ BSTR bstrForwardingURI
)
{
HRESULT hr = S_OK;
if(SUCCEEDED(hr))
{
// Validation is performed in CopyBSTR
hr = CopyBSTR(
&m_bstrForwardingURI,
bstrForwardingURI,
TRUE
);
}
if(SUCCEEDED(hr))
{
if(bstrForwardingURI != NULL && bstrForwardingURI[0] != '\0')
{
// Non-empty string; enable forwarding
m_vcifFlags |= e_vcifAutoForward;
}
else
{
// Empty string; disable forwarding
m_vcifFlags &= ~e_vcifAutoForward;
}
}
return hr;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::get_RingTone
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::get_RingTone(
/* [retval][out] */ BSTR *pbstrRingTonePath
)
{
// Validation is performed in CopyMemberToBSTR
return CopyBSTR(
pbstrRingTonePath,
m_bstrRingTonePath,
FALSE
);
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::put_RingTone
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::put_RingTone(
/* [in] */ BSTR bstrRingTonePath
)
{
HRESULT hr = S_OK;
if(SUCCEEDED(hr))
{
// Validation is performed in CopyBSTR
hr = CopyBSTR(
&m_bstrRingTonePath,
bstrRingTonePath,
TRUE
);
}
if(SUCCEEDED(hr))
{
if(bstrRingTonePath != NULL && bstrRingTonePath[0] != '\0')
{
// Non-empty string; enable custom ring tone
m_vcifFlags |= e_vcifCustomRingTone;
}
else
{
// Empty string; disable custom ring tone
m_vcifFlags &= ~e_vcifCustomRingTone;
}
}
return hr;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::Commit
Commits any unsaved changes made to this record to the associated database.
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoRecord::Commit()
{
HRESULT hr = S_OK;
// Prototypical record that is going to be written to the DB
CEPROPVAL rgcepvVals[CALLER_INFO_DB_PROPERTY_COUNT] = {0};
// Error check:
if (!m_pOwnerDB)
{
return E_FAIL;
}
// Set propids and values
rgcepvVals[CALLER_INFO_ID_URI].propid = CALLER_INFO_URI;
rgcepvVals[CALLER_INFO_ID_URI].val.lpwstr = m_bstrURI;
rgcepvVals[CALLER_INFO_ID_FRIENDLYNAME].propid = CALLER_INFO_FRIENDLYNAME;
rgcepvVals[CALLER_INFO_ID_FRIENDLYNAME].val.lpwstr = m_bstrFriendlyName;
rgcepvVals[CALLER_INFO_ID_VOIPNAME].propid = CALLER_INFO_VOIPNAME;
rgcepvVals[CALLER_INFO_ID_VOIPNAME].val.lpwstr = m_bstrVoIPName;
rgcepvVals[CALLER_INFO_ID_SPEEDDIALENTRY].propid = CALLER_INFO_SPEEDDIALENTRY;
rgcepvVals[CALLER_INFO_ID_SPEEDDIALENTRY].val.lVal = m_idxSpeedDial;
rgcepvVals[CALLER_INFO_ID_FLAGS].propid = CALLER_INFO_FLAGS;
rgcepvVals[CALLER_INFO_ID_FLAGS].val.lVal = m_vcifFlags;
rgcepvVals[CALLER_INFO_ID_FORWARDINGURI].propid = CALLER_INFO_FORWARDINGURI;
rgcepvVals[CALLER_INFO_ID_FORWARDINGURI].val.lpwstr = m_bstrForwardingURI;
rgcepvVals[CALLER_INFO_ID_RINGTONEPATH].propid = CALLER_INFO_RINGTONEPATH;
rgcepvVals[CALLER_INFO_ID_RINGTONEPATH].val.lpwstr = m_bstrRingTonePath;
// 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_pOwnerDB->EditRecord(m_ceoid, rgcepvVals, CALLER_INFO_DB_PROPERTY_COUNT))
{
// 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
// Size is not required since the database was given this information
// on construction.
hr = m_pOwnerDB->AddNewRecord(rgcepvVals, &m_ceoid);
if (FAILED(hr))
{
return hr;
}
}
// Clean up
//
return hr;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoRecord::DeleteFromDB
Deltes this record if it has been written to the database. It's the caller's
job to release the COM pointer after this call; DeleteFromDB does not
do so.
------------------------------------------------------------------------------*/
STDMETHODIMP CVoIPCallerInfoRecord::DeleteFromDB()
{
HRESULT hr = S_OK;
// Check parameters
if (m_ceoid == 0)
{
return VOIP_E_RECORDNOTINDB;
}
if(SUCCEEDED(hr))
{
// Attempt to delete the record
if (!m_pOwnerDB->DeleteRecord(m_ceoid))
{
hr = VOIP_E_RECORDNOTINDB;
}
}
if (SUCCEEDED(hr))
{
// Reset the OID associated with this record. That way, the caller can
// re-commit the record after this call.
m_ceoid = 0;
}
// Clean up
//
// DOES NOT RELEASE!
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -