📄 voipcallerinfodb.cpp
字号:
if (pcepvFill)
{
LocalFree(pcepvFill);
}
return hr;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoDB::FillRecord
Internal function used to copy properties from a CEPROPVAL array into a
record. This is used to "pre-fill" a record returned from the database.
Parameters:
piRecord: Interface pointer of record to fill.
pProps: Properties to fill the record with.
cProps: The number of properties in pProps.
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoDB::FillRecord(
IVoIPCallerInfoRecord *piRecord,
CEPROPVAL *pProps,
int cProps
)
{
int i = 0;
HRESULT hr = S_OK;
ce::auto_bstr bstrPutVal;
// Can't call this without first initializing the database
if (!m_fInit)
{
return VOIP_E_NOTINITIALIZED;
}
// Check parameters
if (piRecord == NULL || pProps == NULL)
{
return E_POINTER;
}
if (cProps < 0)
{
return E_INVALIDARG;
}
// For each property
for (i = 0; i < cProps; i++)
{
// Call the appropriate put_XXX on the field in the record
switch(pProps[i].propid)
{
case CALLER_INFO_URI:
bstrPutVal = SysAllocString(pProps[i].val.lpwstr);
hr = piRecord->put_URI(bstrPutVal);
break;
case CALLER_INFO_FRIENDLYNAME:
bstrPutVal = SysAllocString(pProps[i].val.lpwstr);
hr = piRecord->put_FriendlyName(bstrPutVal);
break;
case CALLER_INFO_VOIPNAME:
bstrPutVal = SysAllocString(pProps[i].val.lpwstr);
hr = piRecord->put_VoIPName(bstrPutVal);
break;
case CALLER_INFO_SPEEDDIALENTRY:
hr = piRecord->put_SpeedDialEntry(pProps[i].val.lVal);
break;
case CALLER_INFO_FLAGS:
if(pProps[i].val.lVal & e_vcifBlocked)
{
hr = piRecord->put_Blocked(VARIANT_TRUE);
}
break;
case CALLER_INFO_FORWARDINGURI:
bstrPutVal = SysAllocString(pProps[i].val.lpwstr);
hr = piRecord->put_ForwardingURI(bstrPutVal);
break;
case CALLER_INFO_RINGTONEPATH:
bstrPutVal = SysAllocString(pProps[i].val.lpwstr);
hr = piRecord->put_RingTone(bstrPutVal);
break;
default:
// Unexpected property ID
ASSERT(FALSE);
break;
}
if (FAILED(hr))
break;
}
return hr;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoDB::get_Enumerator
Gets an enumerator for the records in this database.
Parameters:
ppiEnum: A pointer to an enumeration interface that can be used to
enumerate over the records in this database.
------------------------------------------------------------------------------*/
STDMETHODIMP CVoIPCallerInfoDB::get_Enumerator(
/* [retval][out] */ IVoIPCallerInfoDBEnum **ppiEnum
)
{
return CreateEnumerator(ppiEnum, CVoIPCallerInfoDBEnum::AcceptAll);
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoDB::get_FriendlyNameEnumerator
Gets an enumerator for the records in this database filtered by valid friendly name.
Parameters:
ppiEnum: A pointer to an enumeration interface that can be used to
enumerate over the records in this database.
------------------------------------------------------------------------------*/
STDMETHODIMP CVoIPCallerInfoDB::get_FriendlyNameEnumerator(
/* [retval][out] */ IVoIPCallerInfoDBEnum **ppiEnum
)
{
ASSERT(FALSE);
return E_NOTIMPL;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoDB::CreateEnumerator
Creates an enumerator with the specified properties
Parameters:
ppiEnum: A pointer to an enumeration interface that can be used to
enumerate over the records in this database.
pfnFilter: The function to filter the read records with
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoDB::CreateEnumerator(IVoIPCallerInfoDBEnum **ppiEnum, FilterFn *pfnFilter)
{
HRESULT hr = S_OK;
CComObject<CVoIPCallerInfoDBEnum> *pEnum = NULL;
// Can't call this without first initializing the database
if (!m_fInit)
{
return VOIP_E_NOTINITIALIZED;
}
// Check parameters
if (ppiEnum == NULL || pfnFilter == NULL)
{
return E_POINTER;
}
if (SUCCEEDED(hr))
{
// Create an internal caller info database enumerator
hr = CComObject<CVoIPCallerInfoDBEnum>::CreateInstance(&pEnum);
}
if (SUCCEEDED(hr))
{
// Give the (so far unreferenced) enumerator a reference.
pEnum->AddRef();
// Initialize the enumerator with 'this' as the callback object.
// The enumerator's Init() method will add a reference to 'this'.
hr = pEnum->Init(
m_pCallerInfoDB, //the underlying voipdb
this, //this
pfnFilter //Filter function
);
}
if (SUCCEEDED(hr))
{
// Convert the enumerator object pointer to an interface pointer.
// This will add a reference to *ppiEnum/pEnum.
hr = pEnum->QueryInterface(IID_IVoIPCallerInfoDBEnum, (void **)ppiEnum);
}
if (SUCCEEDED(hr))
{
if (*ppiEnum == NULL)
{
// Shouldn't really happen
ASSERT(FALSE);
hr = E_NOINTERFACE;
}
}
if (SUCCEEDED(hr))
{
// Reset the enumerator so it starts at the first record in the database
hr = (*ppiEnum)->Reset();
}
// Clean up
//
// We need to remove the reference to pEnum from AddRef before.
if (pEnum != NULL)
{
pEnum->Release();
pEnum = NULL;
}
// There should be at most one reference on *ppiEnum at this point.
if (FAILED(hr))
{
// Something went wrong. If there's a reference on the enumerator
// object, then release it to clean up.
if (*ppiEnum != NULL)
{
// This release call will remove the reference from "this" as well.
(*ppiEnum)->Release();
(*ppiEnum) = NULL;
}
}
return hr;
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoDB::FindCallerInfoBySpeedDialEntry
Finds a caller info record by the speed dial entry
Parameters:
idxSpeedDial: The speed dial index to locate
ppiRecord: The record to fill in
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoDB::FindCallerInfoBySpeedDialEntry(
INT idxSpeedDial,
IVoIPCallerInfoRecord** ppiRecord
)
{
HRESULT hr = S_FALSE;
if (ppiRecord == NULL)
{
return E_POINTER;
}
//make sure we are initialized
if (!m_fInit)
{
return VOIP_E_NOTINITIALIZED;
}
if (idxSpeedDial == VOIP_INVALID_SPEED_DIAL_ENTRY)
{
return E_INVALIDARG;
}
///slooooooooooooooooooow
CComPtr<IVoIPCallerInfoDBEnum> cpEnum;
hr = get_Enumerator(&cpEnum);
if (FAILED(hr))
{
return VOIP_E_RECORDNOTINDB;
}
CComPtr<IVoIPCallerInfoRecord> cpRecord;
int Idx = VOIP_INVALID_SPEED_DIAL_ENTRY;
while (1)
{
cpRecord = NULL;
//get the next record
hr = cpEnum->Next(1, &cpRecord, NULL);
if (hr != S_OK || cpRecord == NULL)
{
return VOIP_E_RECORDNOTINDB;
}
cpRecord->get_SpeedDialEntry(&Idx);
if (Idx == idxSpeedDial)
{
*ppiRecord = cpRecord;
(*ppiRecord)->AddRef();
return S_OK;
}
}
}
/*------------------------------------------------------------------------------
CVoIPCallerInfoDB::get_SpeedDialEnumerator
Gets a speed dial enumerator for the records in this database filtered by valid speed dial entry.
Parameters:
ppiEnum: A pointer to an enumeration interface that can be used to
enumerate over the records in this database.
------------------------------------------------------------------------------*/
STDMETHODIMP CVoIPCallerInfoDB::get_SpeedDialEnumerator(
/* [retval][out] */ IVoIPCallerInfoDBEnum **ppiEnum
)
{
CComObject<CSpeedDialEnumerator>* pContainer;
CComPtr<IVoIPCallerInfoDBEnum> cpEnumerator;
CComPtr<IVoIPCallerInfoRecord> cpRecord;
int Idx = -1;
HRESULT hr = get_Enumerator(&cpEnumerator);
if (FAILED(hr))
{
return hr;
}
hr = CComObject<CSpeedDialEnumerator>::CreateInstance(&pContainer);
if (FAILED(hr))
{
return hr;
}
while (1)
{
cpRecord = NULL;
//get the next record
hr = cpEnumerator->Next(1, &cpRecord, NULL);
if (hr != S_OK || cpRecord == NULL)
{
hr = S_OK;
break;
}
Idx = VOIP_INVALID_SPEED_DIAL_ENTRY;
cpRecord->get_SpeedDialEntry(&Idx);
if (Idx == VOIP_INVALID_SPEED_DIAL_ENTRY)
{
continue;
}
pContainer->AddRecord(Idx, cpRecord);
}
pContainer->Reset();
*ppiEnum = pContainer;
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -