⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voipcallerinfodb.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// 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.
//
// VoIPCallerInfoDB.cpp : Implementation of CVoIPCallerInfoDB
#include "VoIPStore.h"
#include "VoIPCallerInfoDB.h"
#include "VoIPCallerInfoRecord.h"
#include "VoIPCallerInfoDBEnum.h"
#include "auto_xxx.hxx"
#include "SpeedDialEnum.h"

/////////////////////////////////////////////////////////////////////////////
// CVoIPCallerInfoDB

/*------------------------------------------------------------------------------
    CVoIPCallerInfoDB::CVoIPCallerInfoDB
    
    Constructor for CVoIPCallerInfoDB.  Most initialization is done in Init()
    so it can return status.
------------------------------------------------------------------------------*/
CVoIPCallerInfoDB::CVoIPCallerInfoDB()
{
    m_pCallerInfoDB     = NULL;
    
    m_fInit             = FALSE;
}

/*------------------------------------------------------------------------------
    CVoIPCallerInfoDB::~CVoIPCallerInfoDB
    
    Destructor for CVoIPCallerInfoDB.
------------------------------------------------------------------------------*/
CVoIPCallerInfoDB::~CVoIPCallerInfoDB()
{
    if (m_pCallerInfoDB)
    {
        delete m_pCallerInfoDB;
        m_pCallerInfoDB = NULL;
    }
}

/*------------------------------------------------------------------------------
    CVoIPCallerInfoDB::Init
    
    Initializes the database object.  This function must be called before any
    further calls are made.
    
    Parameters:
        bstrURI: The URI for which to create the database.
------------------------------------------------------------------------------*/
STDMETHODIMP CVoIPCallerInfoDB::Init(
    /* [in] */ BSTR bstrURI
    )
{
    BOOL    fOK = TRUE;
    WCHAR   wszBuf[CEDB_MAXDBASENAMELEN];

    // If already initialized, we fail
    if (m_fInit)
    {
        return VOIP_E_NOTINITIALIZED;
    }

    if (bstrURI == NULL)
    {
        return E_POINTER;
    }

    // Make a new internal CVoipDB for the caller info database
    m_pCallerInfoDB = new CVoipDB(CALLER_INFO_DB_PROPERTY_COUNT);
    if (! m_pCallerInfoDB)
    {
        return E_OUTOFMEMORY;
    }

    StringCchPrintf(
        wszBuf, 
        _countof(wszBuf),
        L"CI:%s", 
        bstrURI
        );
    
    //initialize the database with the necessary sort order...
    SORTORDERSPECEX SortSpec = {0};

    // Sort orders = URI
    SortSpec.rgdwFlags[0] = CEDB_SORT_CASEINSENSITIVE;
    SortSpec.rgPropID [0] = CALLER_INFO_URI;

    SortSpec.wKeyFlags = CEDB_SORT_UNIQUE;
    SortSpec.wNumProps = 1;
    SortSpec.wVersion  = 1;

    HRESULT hr = m_pCallerInfoDB->Initialize(
        wszBuf, 
        &SortSpec
        );
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        delete m_pCallerInfoDB;
        m_pCallerInfoDB = NULL;

        return hr;
    }

    m_fInit = TRUE;

    return S_OK;
}

/*------------------------------------------------------------------------------
    CVoIPCallerInfoDB::CreateRecord
    
    Creates a new caller info record associated with this database and hands 
    it back to the caller.
    
    Parameters:
        ppiRecord: Record interface pointer to return to the caller.
------------------------------------------------------------------------------*/
STDMETHODIMP CVoIPCallerInfoDB::CreateRecord(
    /* [out][retval] */ IVoIPCallerInfoRecord **ppiRecord
    )
{
    HRESULT hr = S_OK;
    CComObject<CVoIPCallerInfoRecord> *pRecord = NULL;
    
    // Can't call this without first initializing the database
    if (!m_fInit)
    {
        return VOIP_E_NOTINITIALIZED;
    }

    // Check parameters
    if (SUCCEEDED(hr))
    {
        if (ppiRecord == NULL)
        {
            return E_POINTER;
        }
    }
    
    *ppiRecord = NULL;

    if (SUCCEEDED(hr))
    {
        // Create the record using the internal create method.  This will
        // add a reference to the record if it succeeds.
        hr = InternalCreateRecord(&pRecord);
    }

    if (SUCCEEDED(hr))
    {
        // Now, get a real COM interface to the object.  This will also add
        // a reference to the record.
        hr = pRecord->QueryInterface(IID_IVoIPCallerInfoRecord, (void **)ppiRecord);
    }

    // Clean up
    //
    
    // Since we have two references and don't plan to store the object internally,
    // remove one of them before handing the object back to the caller.
    if (pRecord != NULL)
    {
        pRecord->Release();
        pRecord = NULL;
    }

    // There should be at most one reference on *ppiRecord at this point.

    if (FAILED(hr))
    {
        // Oops, something went wrong.  If we have still have a reference on
        // *ppiRecord, we need to release it now.
        if (ppiRecord && *ppiRecord)
        {
            (*ppiRecord)->Release();
            (*ppiRecord) = NULL;
        }
    }

    return hr;
}


/*------------------------------------------------------------------------------
    CVoIPCallerInfoDB::InternalCreateRecord
    
    Creates a record for internal use.  Hands back a COM object (not an interface)
    to the caller info record.
    
    Parameters:
        ppRecord: Record pointer to be filled with a newly-created record.
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoDB::InternalCreateRecord(
    CComObject<CVoIPCallerInfoRecord> **ppRecord
    )
{
    HRESULT hr = S_OK;
    
    // Can't call this without first initializing the database
    if (!m_fInit)
    {
        return VOIP_E_NOTINITIALIZED;
    }

    // Check parameters
    if (SUCCEEDED(hr))
    {
        if (ppRecord == NULL)
        {
            return E_POINTER;
        }
    }

    // Create an default caller info record
    if (SUCCEEDED(hr))
    {
        hr = CComObject<CVoIPCallerInfoRecord>::CreateInstance(ppRecord);
    }
    if (SUCCEEDED(hr))
    {   
        // We have no references, so add one
        (*ppRecord)->AddRef();  
        
        // Associate the record with our database
        (*ppRecord)->SetDB(m_pCallerInfoDB);
    }
    
    if (FAILED(hr))
    {
        // Oops, something went wrong.  Do we have a reference on the record?
        
        if (ppRecord && *ppRecord)
        {
            // Yes; release it
            (*ppRecord)->Release();
            (*ppRecord) = NULL;
        }
    }
    
    return hr;
}

/*------------------------------------------------------------------------------
    CVoIPCallerInfoDB::FindCallerInfoByURI
    
    Finds a caller info record whose URI matches the passed in URI.
    
    Parameters:
        bstrURI:    URI of record to find.
        ppiRecord:  Record that matches the URI.
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoDB::FindCallerInfoByURI( 
    /* [in] */ BSTR bstrURI,
    /* [retval][out] */ IVoIPCallerInfoRecord **ppiRecord
    )
{
    // Can't call this without first initializing the database
    if (!m_fInit)
    {
        return VOIP_E_NOTINITIALIZED;
    }

    // Check parameters
    if (bstrURI == NULL || ppiRecord == NULL)
    {
        return E_POINTER;
    }

    CEPROPVAL   cepv = {0};
    cepv.propid      = CALLER_INFO_URI;
    cepv.val.lpwstr  = bstrURI;
    
    //Look up the record in the db
    return FindRecordByCEPROPVAL(&cepv, ppiRecord);
}

/*------------------------------------------------------------------------------
    CVoIPCallerInfoDB::FindRecordByExactURI
    
    Finds the CallerInfoRecord associated with this cepropval's properties

    Returns: S_OK --> Found the record
             S_FALSE --> Did not find the record
             E_     --> Something went wrong
------------------------------------------------------------------------------*/
HRESULT CVoIPCallerInfoDB::FindRecordByCEPROPVAL(CEPROPVAL *pcepv, IVoIPCallerInfoRecord **ppiRecord)
{
    HRESULT             hr      = S_OK;
    int                 cProps  = 0;
    CEOID               ceoid   = 0;
    CEPROPVAL           *pcepvFill = NULL;
    CComObject<CVoIPCallerInfoRecord> *pRecord = NULL;
    BOOL                fFoundRecord = FALSE;

    if (pcepv == NULL)
    {
        return E_POINTER;
    }

    // Find the record
    ceoid = m_pCallerInfoDB->FindRecord(pcepv);
    if (! ceoid)
    {
        return VOIP_E_RECORDNOTINDB; 
    }

    // Read the record we just seeked to
    if(!m_pCallerInfoDB->ReadCurrentRecord(&pcepvFill, &cProps, &ceoid))
    {
        hr = HRESULT_FROM_WIN32(GetLastError());
        goto exit;
    }

    // Create the COM record object (sets the reference count to 1)
    hr = InternalCreateRecord(&pRecord);
    if (FAILED(hr))
    {
        goto exit;
    }
    
    // Associate the record with the database
    pRecord->SetOID(ceoid);

    // Fill the record with the propval data we got back
    hr = FillRecord(pRecord, pcepvFill, cProps);
    if (FAILED(hr))
    {
        goto exit;
    }

    // Get a COM interface from the object (sets the reference count to 2)
    hr = pRecord->QueryInterface(IID_IVoIPCallerInfoRecord, (void**)ppiRecord);
    if (FAILED(hr))
    {
        goto exit;
    }

exit:
    if (pRecord)
    {
        pRecord->Release();
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -