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

📄 voipcalllogdbenum.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 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.
//
// VoIPCallLogDBEnum.cpp : Implementation of CVoIPCallLogDBEnum
#include "VoIPStore.h"
#include "VoIPCallRecord.h"
#include "VoIPCallLogDB.h"
#include "VoIPCallLogDBEnum.h"


/////////////////////////////////////////////////////////////////////////////
// CVoIPCallLogDBEnum

CVoIPCallLogDBEnum::CVoIPCallLogDBEnum()
{
    m_fInit = FALSE;
    m_pDB = NULL;
    m_pCallLogDB = NULL;
}

CVoIPCallLogDBEnum::~CVoIPCallLogDBEnum()
{
    if (m_pCallLogDB != NULL)
    {   
        m_pCallLogDB->Release();
        m_pCallLogDB = NULL;
    }   
}

/*-------------------------
Init
    Initializes the Enumerator
    returns HRESULT
----------------------------*/
HRESULT     CVoIPCallLogDBEnum::Init(VoIPCallType vct, CVoipDB  *pDB, CVoIPCallLogDB *pcalllogdb)
{
    HRESULT hr = S_OK;

    //Check params
    if (pDB == NULL || pcalllogdb == NULL)
    {
        ASSERT(FALSE);
        return E_POINTER;
    }

    //Check params
    if (vct < VCT_FIRST || vct > VCT_LAST)
    {
        return E_INVALIDARG;
    }

    //Initialize member vars and add ref to interface pointers (or underlying classes)
    m_vct = vct;
    m_pDB = pDB;
    m_pCallLogDB = pcalllogdb;
    m_pCallLogDB->AddRef();

    //Locked DB and can now seek back to beginning
    if (!m_pDB->ResetSeek())
    {
        ASSERT(FALSE);

        m_pCallLogDB->Release();
        m_pCallLogDB = NULL;
        return E_FAIL;
    }

    //Get our version number
    m_fInit = TRUE;

    return S_OK;
}

/*--------------------------------------
Next
    Params: [in]number of elts to get, [out] array of Records to fill, [out]number of elements fetched
    Seeks to next elements in db and read current record, creates record, fills record and puts in call record array
    Returns: HRESULT
-----------------------------------------*/
STDMETHODIMP    CVoIPCallLogDBEnum::Next(unsigned long celt, IVoIPCallRecord **rgCallRecord, unsigned long FAR* pceltFetched)
{
    int                                 i           = 0;
    int                                 cCount      = 0;
    CComObject<CVoIPCallLogRecord>      *pRecord    = NULL;
    IVoIPCallRecord                     *piCallRecord = NULL;
    CEPROPVAL                           *pcpvFill   = NULL;
    HRESULT                             hr          = S_OK;
    int                                 cNum        = 0;
    CEOID                               ceoid       = 0;

    //Make sure we are inited
    if (m_fInit == FALSE)
    {
        return VOIP_E_NOTINITIALIZED;
    }

    //Check params
    if (SUCCEEDED(hr))
    {
        if (celt <= 0)
            hr = E_INVALIDARG;
    }

    //Check params
    if (SUCCEEDED(hr))
    {
        if (rgCallRecord == NULL)
            hr = E_POINTER;
    }

    if (SUCCEEDED(hr))
    {
        //reset number fetched (if available)
        if (pceltFetched != NULL)
        {
            *pceltFetched = 0;
        }
        //init array
        for(i = 0; i < (int)celt; i++)
        {
            rgCallRecord[i] = NULL;
        }
        //For each element the user is trying to get...
        for (i = 0; i < (int)celt; i++)
        {
            //get to next element in db
            if (!m_pDB->SeekToNext(1))
            {
                break;
            }
            
            //create a record
            if (SUCCEEDED(hr))
            {
                hr = m_pCallLogDB->InternalCreateRecord(m_vct, &pRecord);
            }

            //read the current record
            if (SUCCEEDED(hr))
            {
                if (!m_pDB->ReadCurrentRecord((CEPROPVAL**)&pcpvFill, &cNum, &ceoid))
                    hr = E_FAIL;
            }

            if (SUCCEEDED(hr))
            {
                pRecord->SetOID(ceoid);
                hr = pRecord->QueryInterface(IID_IVoIPCallRecord, (void**)&piCallRecord);
            }

            if (SUCCEEDED(hr))
            {
                //Internal create add ref's
                pRecord->Release();

                //the record we are returning is empty so...
                hr = m_pCallLogDB->FillRecord(pRecord, pcpvFill, cNum);
            }
            
            //Free resources
            if (pcpvFill)
            {
                LocalFree(pcpvFill);
            }

            //return the record to the user
            if (SUCCEEDED(hr))
            {
                //Don't need to do another addref, since the query interface does one for us
                rgCallRecord[i] = piCallRecord;
                           
                if (pceltFetched != NULL)
                {
                    (*pceltFetched)++;
                }
                cCount++;
            }

            if (FAILED(hr))
            {
                break;
            }   
        }
    }

    //Clean up on failure
    if (FAILED(hr))
    {
        if (piCallRecord)
        {
            piCallRecord->Release();
            piCallRecord = NULL;
        }

        // Clean up the call record array since it's probably half-baked
        for(i = 0; i < cCount; i++)
        {
            if (rgCallRecord[i] != NULL)
            {
                rgCallRecord[i]->Release();
                rgCallRecord[i] = NULL;
            }
        }
        
        return hr;
    }
    
    //return success OK if we got all the elements requested, false otherwise           
    return ((unsigned long)cCount == celt) ? S_OK : S_FALSE;    
}

//Skip next celt elements in the DB
STDMETHODIMP    CVoIPCallLogDBEnum::Skip(unsigned long celt)
{
    HRESULT     hr = S_OK;

    //Can't use if not initialized
    if (m_fInit == FALSE)
    {
        hr = VOIP_E_NOTINITIALIZED;
    }

    if (SUCCEEDED(hr))
    {
        //Check params
        if (celt < 0)
            hr = E_INVALIDARG;
    }

    if (SUCCEEDED(hr))
    {
        //internally seek to next celt number
        if (!m_pDB->SeekToNext(celt))
            hr = E_FAIL;
    }

    return hr;
}

//resets the enumerator
STDMETHODIMP    CVoIPCallLogDBEnum::Reset()
{
    HRESULT     hr = S_OK;

    //need to be initialized
    if (m_fInit == FALSE)
    {
        return VOIP_E_NOTINITIALIZED;
    }
    
    if (SUCCEEDED(hr))
    {
        //reset the seek internally
        if (!m_pDB->ResetSeek())
            hr = E_FAIL;
    }

    return hr;
}

⌨️ 快捷键说明

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