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

📄 settings.hpp

📁 一个WinCE6。0下的IP phone的源代码
💻 HPP
字号:
//
// 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.
//
#pragma once

#ifndef __SETTINGMANAGER_HPP__
#define __SETTINGMANAGER_HPP__

#include <windows.h>
#include <list.hxx>     //ce::list support
#include <string.hxx>   //ce::wstring support
#include "Timers.hpp"   //ITimerHandler_t
#include <regext.h>

class Setting_t
{
public: 

    virtual
    ~Setting_t(
        void
        ); 

    virtual
    HRESULT
    RegisterForNotification(
        HWND    WindowHandle, 
        UINT    Message, 
        DWORD   UserData
        ); 

    virtual
    HRESULT 
    Update(
        void
        ) = 0; 

protected: 
    Setting_t(
        HKEY                RootKey, 
        __in const WCHAR*   c_pSubKey, 
        __in const WCHAR*   c_pValueName
        ); 
    

protected: 
    HKEY        m_RootKey; 
    ce::wstring m_SubKey; 
    ce::wstring m_ValueName; 
    HREGNOTIFY  m_NotifyHandle; 
    
}; 

class StringSetting_t : public Setting_t
{
public: 
    StringSetting_t(
        HKEY                    RootKey, 
        __in const WCHAR*       c_pSubKey, 
        __in const WCHAR*       c_pValueName, 
        __in_opt const WCHAR*   pDefaultValue = NULL
        ); 
        
    
    HRESULT 
    Update(
        void
        ); 

    //overloaded operators for accessing wstring/wchar* versions of the object
    operator ce::wstring &() 
    {
        return m_SettingValue;
    }

    operator const WCHAR * const() const
    {
        return (const WCHAR*)m_SettingValue;
    }

    WCHAR operator[](int i)
    {
        return m_SettingValue[i]; 
    }

    size_t size()
    {
        return m_SettingValue.size();
    }


private: 
    ce::wstring m_SettingValue; 
    ce::wstring m_DefaultValue; 
}; 


class IntegerSetting_t : public Setting_t
{
public:
    IntegerSetting_t(
        HKEY                RootKey, 
        __in const WCHAR*   c_pSubKey, 
        __in const WCHAR*   c_pValueName, 
        DWORD               DefaultValue = -1
        ); 


    HRESULT
    Update(
        void
        ); 

    operator DWORD()
    {
        return m_SettingValue;
    }


private: 
    DWORD   m_SettingValue; 
    DWORD   m_DefaultValue; 
    
}; 

//forward declarations
interface IRTCClient;
interface IRTCProfile;
class     VoIPApp_t;


//all the settings that we care about, which includes not only VoIP settings, but also
//something like WiFi status and Phone Status Flags
const UINT  SEF_NONE                        = 0x00000000;
const UINT  SEF_VOIP_SIP_SETTINGS           = 0x00000001;
const UINT  SEF_VOIP_VOICEMAIL_SETTINGS     = 0x00000002;
const UINT  SEF_VOIP_VOICEMAIL_NUMBER       = 0x00000004;
const UINT  SEF_VOIP_BACKUP_SIP_SETTINGS    = 0x00000008;
const UINT  SEF_VOIP_DIALPLAN               = 0x00000010;
const UINT  SEF_SPEAKERPHONE_TOGGLE         = 0x00000020; 

//pure vitual class ISettingChangeHandler_t
//anybody who wants to listen to some setting changes and react upon that
//needs to implement this interface
class ISettingChangeHandler_t
{
public:

    virtual
    HRESULT
    OnSettingsChange(
        DWORD SettingFlags
        ) = 0;

};


class Settings_t :
    public ITimerHandler_t
{

private:

    struct SettingHandlerMapping_t
    {
        DWORD                       SettingFlags;
        ISettingChangeHandler_t*    pSettingChangeHandler;
    };

    typedef ce::list<SettingHandlerMapping_t> HandlerList_t;

    //constants
    static const WCHAR              sc_ListenerWindowClassName[];   //listener window class name
    static const WCHAR              sc_DialPlanFile[];              //copy of dialplan file
    static const UINT               sc_RetryTimeout;                //time out value for retry

    static const WCHAR              sc_DefaultRingTone[];           //default ringtone

    static Setting_t*               s_PhoneSettings[]; 

    //member variables
    HWND            m_ListenerWindow;           //listener window for StatStore notifications
    HandlerList_t   m_HandlerList;              //list of setting handlers

    const WCHAR*    m_pActiveRegKeyName;        //string of 'active' reg key name
    const WCHAR*    m_pActiveFilePrefix;        //string of 'active' file prefix
    HANDLE          m_VoIPSettingMutex;         //mutex handle that guards the accessing to settings

    UINT            m_RetryTimerIdentifier;     //the timer id for retry purpose
    DWORD           m_PendingSettingUpdateFlags; //the update setting flags that is in the pending status
    HREGNOTIFY      m_NotifyHandleForProvisionSettings;     //the handle of notification of provision settings

    

public:

    //enumation about the storage types we support
    enum StorageType_e
    {
        StorageTypeRegistry = 0,
        StorageTypeFile,
    };


    //enumation for all VoIP settings
    enum SettingType_e
    {
        SettingTypeSIPSettings = 0,
        SettingTypeVoicemailSettings,
        SettingTypeVoicemailNumber,
        SettingTypeBackupSIPSettings,
        SettingTypeDialPlan,
    };


    //struct of VoIP settings
    struct VoIPSetting
    {
        const SettingType_e SettingType;
        const WCHAR*        pSettingName;
        const bool          ShouldBeEncrypted;
        const StorageType_e StorageType;
        //below are VoIP CSP related fields
        const DWORD         SettingFlag;
        const WCHAR*        pCSPParmName;
    };

    static const WCHAR          sc_VoIPSettingsMutexName[];     //name of the mutex that we used to gain exclusive access to settings
    static const VoIPSetting    sc_VoIPSettings[];              //Array of all the VoIP settings
    static const int            sc_NumberOfVoIPSettings;        //number of VoIP settings
    static const WCHAR          sc_SettingFilePrefix0[];        //file name prefix for settings 0
    static const WCHAR          sc_SettingFilePrefix1[];        //file name prefix for settings 1
    static const WCHAR          sc_SettingFileDirectory[];      //name of the directory that holds all the VoIP setting files

    static StringSetting_t      s_ForwardingNumber;

    static const UINT           s_dwGenerateKeydown; 
    static const UINT           s_msPressAndHold; 
    static const UINT           s_msInactivityTimeout; 
    
public:
    //static functions, below functions are shared by both Settings_t and VoIPCSP_t
    //they all related with accessing setting information from either registry or file
    static
    HRESULT
    RegQueryValueHR(
        HKEY                RegKey,
        __in const WCHAR*   pValueName,
        __in_opt DWORD*     pValueType,
        __out_opt BYTE*     pData,
        __inout_opt DWORD*  pDataSize,
        __in_opt bool*      pDoesNotExist = NULL
    );

    static
    HRESULT
    RegGetValueSize(
        HKEY                RegKey,
        __in const WCHAR*   pValueName,
        __out DWORD*        pDataSize,
        __out_opt bool*     pDoesNotExist = NULL
        );

    static
    HRESULT
    GetSettingValueFromRegistryByKey(
        HKEY                    RegKey,
        __in const WCHAR*       pSettingName,
        __deref_out_opt BYTE**  ppSettingValue,
        __out DWORD*            pSettingValueSize,
        __out_opt bool*         pValueDoesNotExist = NULL
        );

    static
    HRESULT
    GetSettingFileName(
        __in const WCHAR*               pPrefix,
        __in const WCHAR*               pSettingName,
        __out_ecount(BufferSize) WCHAR* pBuffer,
        size_t                          BufferSize
        );

    static
    HRESULT
    GetSettingValueFromFile(
        __in const WCHAR*       pFilePrefix,
        __in const WCHAR*       pSettingName,
        __deref_out_opt BYTE**  ppSettingValue,
        __out DWORD*            pSettingValueSize,
        __out_opt bool*         pValueDoesNotExist = NULL
        );

    static
    HRESULT
    GetSettingValueFromFile(
        __in const WCHAR*       pFileName,
        __deref_out_opt BYTE**  ppSettingValue,
        __out DWORD*            pSettingValueSize,
        __out_opt bool*         pValueDoesNotExist = NULL
        );

    static
    HRESULT
    CreateProfileFromXML(
        __in BSTR                       bstrXML,
        __in IRTCClient*                pRTCClient,
        __deref_out_opt IRTCProfile**   ppProfile
        );


    //member functions
    Settings_t();
    ~Settings_t();

    //initializes the setting manager object
    HRESULT
    Initialize(
        void
        );

    //start listening the setting changes
    HRESULT
    StartListening(
        void
        );

    //register a setting handler
    HRESULT
    RegisterHandler(
        DWORD                           SettingFlags,
        __in ISettingChangeHandler_t*   pSettingHandler
        );

    //unregister a setting handler
    HRESULT
    UnregisterHandler(
        __in ISettingChangeHandler_t*   pSettingHandler
        );

    //get registration profile
    HRESULT
    GetRegistrationProfile(
        SettingType_e                   SIPServerType,
        __deref_out_opt IRTCProfile**   pRegistrationProfile
        );

    //get voice mail profile
    HRESULT
    GetVoicemailProfile(
        __deref_out_opt IRTCProfile**   ppVoicemailProfile
        );

    //check whether a given settings is available
    bool
    IsSettingAvailable(
        SettingType_e           SettingType
        );

    //get the custom dialplan
    HRESULT
    GetDialPlan(
        __deref_out_opt BSTR*   pDialPlanXML
        );

    //get the voice mail number
    HRESULT
    UpdateVoicemailNumber(
        void
        );

    //implements the ITimerHandler_t interface
    void
    OnTimerExpires(
        UINT TimerIdentifier
        );

    HRESULT
    GetSystemRingTone(
        WCHAR*          pBuffer, 
        unsigned int    BufferSize
        );

private:

    static
    LRESULT
    s_ListenerWindowProc(
        HWND hwnd,
        UINT Message,
        WPARAM wParam,
        LPARAM lParam
        );

    LRESULT
    ListenerWindowProc(
        HWND hwnd,
        UINT Message,
        WPARAM wParam,
        LPARAM lParam
        );


    //member functions
    HRESULT
    GetSettingValue(
        SettingType_e           SettingType,
        __deref_out_opt BSTR*   pSettingValue
        );


    HRESULT
    GetRawSettingValue(
        SettingType_e           SettingType,
        __deref_out_opt BYTE**  ppValue,
        __out DWORD*            pValueSize
        );


    HRESULT
    GetSettingValueFromRegistry(
        const WCHAR*            pSettingName,
        __deref_out_opt BYTE**  ppValue,
        __out DWORD*            pValueSize
        );


    bool
    SettingAlreadyExistsInRegistry(
        __in const WCHAR*    pSettingName
        );


    bool
    SettingFileAlreadyExists(
        __in const WCHAR*    pSettingName
        );

    DWORD
    GetUpdatedVoIPSettingFlags(
        void
        );


    HRESULT
    NotifySettingHandlers(
        DWORD   UpdatedSettingFlags
        );

    HRESULT
    InitializeActiveRegKeyNameAndFilePrefix(
        void
        );

};

#endif /* __SETTINGMANAGER_HPP__ */


⌨️ 快捷键说明

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