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

📄 database.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.
//

#include "Database.hpp"
#include "CommonFunctions.hpp"
#include "DatabaseAPI.hpp"
#include "Debug.hpp"
#include "Settings.hpp"
#include "VoIPApp.hpp"


Database_t::Database_t(
    void
    )
{
    ; 
}

Database_t::~Database_t(
    void
    )
{
    m_cpCallerInfoDB = NULL; 
    m_cpCallLogDB    = NULL; 
}

void
Database_t::Initialize(
    void
    )
{
    HRESULT hr = PHInitCallLogDB(&m_cpCallLogDB); 
    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at gettting calllog DB, hr = 0x%x", hr));                 
    }

    hr = PHInitCallerInfoDB(&m_cpCallerInfoDB); 
    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at getting CallerInfoDB DB, hr = 0x%x", hr));         
    }

    return; 
}


HRESULT
Database_t::AddToCallLog(
    BSTR            FriendlyNumber, 
    BSTR            FriendlyName, 
    BSTR            VoIPName, 
    VoIPCallType    CallLogType, 
    SYSTEMTIME      StartTime, 
    SYSTEMTIME      EndTime
    )
{
    if (m_cpCallLogDB == NULL)
    {
        return E_UNEXPECTED; 
    }

    //do not need to validate the parameters, we just pass them directly to the database    
    CComPtr<IVoIPCallRecord>    cpRecord; 

    HRESULT hr = m_cpCallLogDB->CreateRecord(
                                    CallLogType, 
                                    &cpRecord
                                    ); 
    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed to create a call record, error = 0x%x", hr)); 
        return hr; 
    }

    hr = cpRecord->put_StartTime(StartTime); 
    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed to put start time to call record, error = 0x%x", hr)); 
    }

    hr = cpRecord->put_URI(FriendlyNumber); 
    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed to put URI to call record, error = 0x%x", hr)); 
    }

    hr = cpRecord->put_FriendlyName(FriendlyName); 
    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed to put friendly name to call record, error = 0x%x", hr)); 
    }

    hr = cpRecord->put_VoIPName(VoIPName); 
    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed to put voip name to call record, error = 0x%x", hr)); 
    }

    hr = cpRecord->put_EndTime(EndTime); 
    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed to put end time to call record, error = 0x%x", hr)); 
    }

    hr = cpRecord->Commit(); 
    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed to commit the call record, error = 0x%x", hr)); 
    }

    return hr; 
    
}

HRESULT
Database_t::GetCallerInfo(
    BSTR    FriendlyNumber, 
    BSTR*   pFriendlyName, 
    BSTR*   pRingTonePath, 
    bool*   pIsBlocked
    )
{
    if (m_cpCallerInfoDB == NULL)
    {
        return E_UNEXPECTED; 
    }
    
    if (FriendlyNumber == NULL)
    {
        return E_INVALIDARG; 
    }

    if (pFriendlyName != NULL)
    {
        *pFriendlyName  = NULL; 
    }

    if (pRingTonePath != NULL)
    {
        *pRingTonePath  = NULL; 
    }
    
    if (pIsBlocked != NULL)
    {
        *pIsBlocked = false; 
    }
    
    CComPtr<IVoIPCallerInfoRecord>  cpRecord;         
    HRESULT hr = m_cpCallerInfoDB->FindCallerInfoByURI(
                            FriendlyNumber, 
                            &cpRecord
                            ); 
    if (FAILED(hr) || cpRecord == NULL)
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at getting caller info record, hr = 0x%x", hr)); 
        return hr; 
    }

    if (pFriendlyName != NULL)
    {
        hr = cpRecord->get_FriendlyName(pFriendlyName); 
        if (FAILED(hr))
        {
            PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at getting friendly name from record, hr = 0x%x", hr));     
        }
    }

    if (pRingTonePath != NULL)
    {
        hr = cpRecord->get_RingTone(pRingTonePath); 
        if (FAILED(hr))
        {
            PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at getting ring tone path from record, hr = 0x%x", hr)); 
        }
    }

    if (pIsBlocked != NULL)
    {
        VARIANT_BOOL    IsBlocked; 
        hr = cpRecord->get_Blocked(&IsBlocked); 
        if (FAILED(hr))
        {
            PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at getting isblocked infrom from record, hr = 0x%x", hr)); 
        }

        *pIsBlocked = (IsBlocked == VARIANT_TRUE) ? true : false; 
    }

    return hr;     
    
}

HRESULT
Database_t::GetNumberFromSpeedDialEntry(
    int     Index, 
    BSTR*   pFriendlyNumber
    )
{
    if (m_cpCallerInfoDB == NULL)
    {
        return E_UNEXPECTED; 
    }

    if (Index <= 0 ||
        pFriendlyNumber == NULL)
    {
        return E_INVALIDARG; 
    }


    *pFriendlyNumber = NULL; 
    
    CComPtr<IVoIPCallerInfoRecord>  cpRecord;         
    HRESULT hr = m_cpCallerInfoDB->FindCallerInfoBySpeedDialEntry(
                                        Index, 
                                        &cpRecord
                                        ); 
    if (FAILED(hr) || cpRecord == NULL)
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at getting caller info record, hr = 0x%x", hr)); 
        return hr; 
    }

    hr = cpRecord->get_URI(pFriendlyNumber); 
    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at getting number from caller info record, hr = 0x%x", hr)); 
    }

    return hr; 
}


⌨️ 快捷键说明

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