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

📄 provisionmanager.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 __PROVISIONMANAGER_HPP__
#define __PROVISIONMANAGER_HPP__

#include <windows.h>
#include <msxml2.h>
#include <SAXContentHandlerImpl.h>
#include <string.hxx>
#include <list.hxx>
#include <atlbase.h>
#include "rtccore.h"
#include "ProvisionSetting.hpp"
#include "Provision.hpp"

//forward declariations
class DialPlanParser_t; 

class ProvisionManager_t :
    public CSAXContentHandlerImpl, 
    public IRTCEventNotification    
{
public:

    static 
    LRESULT WINAPI 
    s_ListenerWindowProc(
        HWND    WindowHandle, 
        UINT    Message, 
        WPARAM  wParam, 
        LPARAM  lParam
        )
    {
        return DefWindowProc(WindowHandle, Message, wParam, lParam); 
    }; 


    // member functions
    // Constructor
    ProvisionManager_t();

    // Destructor
    ~ProvisionManager_t();

    // IUnknown methods
    ULONG
    STDMETHODCALLTYPE
    AddRef(
        void
        )
    {
        //we have the full control of the object life time, so we don't actually need ref counting
        return 0; 
    }; 

    ULONG
    STDMETHODCALLTYPE
    Release(
        void
        )
    {
        //we have the full control of the object life time, so we don't actually need ref counting
        return 0; 
    }; 

    HRESULT
    STDMETHODCALLTYPE
    QueryInterface(
        REFIID riid,
        __deref_out_opt void** ppvObject
        );

    // ISAXContentHandler methods
    HRESULT
    STDMETHODCALLTYPE
    endDocument(
        void
        );

    HRESULT
    STDMETHODCALLTYPE
    endElement(
        /* [in] */ __in_ecount(cchNamespaceUri) const wchar_t *pwchNamespaceUri,
        /* [in] */ int cchNamespaceUri,
        /* [in] */ __in_ecount(cchLocalName) const wchar_t *pwchLocalName,
        /* [in] */ int cchLocalName,
        /* [in] */ __in_ecount_opt(cchQName) const wchar_t *pwchQName,
        /* [in] */ int cchQName
        );

    HRESULT
    STDMETHODCALLTYPE
    startDocument(
        void
        );

    HRESULT
    STDMETHODCALLTYPE
    startElement(
        /* [in] */ __in_ecount(cchNamespaceUri) const wchar_t *pwchNamespaceUri,
        /* [in] */ int cchNamespaceUri,
        /* [in] */ __in_ecount(cchLocalName) const wchar_t *pwchLocalName,
        /* [in] */ int cchLocalName,
        /* [in] */ __in_ecount_opt(cchQName) const wchar_t *pwchQName,
        /* [in] */ int cchQName,
        /* [in] */ __in_opt ISAXAttributes *pAttributes
        );

    //IRTCEventNotification implementation
    HRESULT 
    STDMETHODCALLTYPE 
    Event(
        RTC_EVENT       RTCEvent,
        __in IDispatch* piEvent
        );


    // Parses the XML and processes it at the same time
    HRESULT
    ProcessXML(
        __in BSTR   ProvisionXML,
        bool        ValidateOnly, 
        BSTR*       pOutputXML = NULL
        );


private:
    
    enum ProvisionElement_e
    {
        ElementStart, 
        ElementSet,
        ElementDelete,
        ElementQuery,
        ElementUnknown,     // MUST be last in the enumeration
    };

    struct XMLElement_t
    {
        const WCHAR*        m_pName;
        ProvisionElement_e  m_Element; 
        ProvisionElement_e  m_ParentElement;
        BYTE                m_Level;
    };

    enum ProvisionAttribute_e
    {
        AttributeName, 
        AttributeValue, 
        AttributeUnknown,   // Must be last in the enumeration
    }; 

    struct XMLAttribute_t
    {
        const WCHAR*            m_pName; 
        ProvisionAttribute_e    m_Attribute; 
    }; 

    typedef bool (ProvisionManager_t::*pfnValidator)(const WCHAR* c_pValue, int ValueSize);  

private:

    // Gets type of dial plan element
    static
    HRESULT
    GetElementType(
        __in_ecount_opt(ElementNameLength) const WCHAR *pElementName,
        int ElementNameLength,
        __out ProvisionElement_e *pElementType, 
        __out int* pIndex
        );

    HRESULT
    GetAttributeType(
        __in_ecount_opt(AttributeNameLength) const WCHAR*   pAttributeName,
        int                                                 AttributeNameLength,
        __out ProvisionAttribute_e*                         pRuleAttributeType
        );


    // member functions
    // verifies hierarchy for an XMLElement_t 
    bool
    IsXMLElementHierarchyValid(
        __in const XMLElement_t* pThisElement
        );

    HRESULT
    HandleVerbs(
        ProvisionElement_e  ElementType, 
        ISAXAttributes*     pAttributes
        ); 

    HRESULT
    HandleSet(
        ISAXAttributes*     pAttributes
        ); 

    HRESULT
    HandleDelete(
        ISAXAttributes*     pAttributes
        ); 

    HRESULT
    HandleQuery(
        ISAXAttributes*     pAttributes
        ); 

    //others
    HRESULT
    GetProvisionSetting(
        const WCHAR*            pSettingName, 
        int                     SettingLength, 
        ProvisionSetting_t**    ppSetting,
        pfnValidator*           pValidator = NULL
        ); 

    HRESULT
    DoPreparation(
        void
        );

    HRESULT
    CopyUntouchedSettingFromActiveToUpdate(
        void
        ); 

    HRESULT
    DeleteObsoleteSettings(
        bool    IsUpdated
        ); 

    HRESULT
    FinishUp(
        bool*   pUpdateHappened
        ); 

    void
    ClearQuerySettingsStack(
        void
        ); 

    HRESULT
    GetReturnXML(
        BSTR*   pOutputXML
        ); 

    //validators
    bool
    IsValidRTCXML(
        const WCHAR*    c_pValue, 
        int             ValueSize
        ); 

    bool
    IsValidDialPlan(
        const WCHAR*    c_pValue, 
        int             ValueSize
        ); 

    bool
    IsValidPhoneNumber(
        const WCHAR*    c_pValue, 
        int             ValueSize
        ); 

    //misc
    HRESULT
    CreateListenerWindow(
        void
        ); 

    HRESULT
    RegisterCallbackInterface(
        void
        ); 

    HRESULT
    UnregisterCallbackInterface(
        void
        ); 
    
private: 

    struct SettingValidatorMap
    {
        ProvisionSetting_t* pSetting; 
        pfnValidator        Validator; 
    }; 
    
    // constants
    static const XMLElement_t   sc_ProvisionElements[];     // supported XML elements
    static const XMLAttribute_t sc_ProvisionAttributes[];   // supported XML attributes

    static const WCHAR          sc_QueryElement[]; 
    static const WCHAR          sc_StartElement[]; 
    
    // ProvisionManager_t Flags
    static const DWORD PROCESSING_XML;                      // enabled when parsing an XML
    static const DWORD VALIDATE_XML_ONLY;                   // enabled when parser should only validate the XML (avoid allocations)

    static const WCHAR  sc_MutexName[]; 
    static const DWORD  sc_MutexTimeoutValue; 

    // Provision Settings
    static ProvisionSetting_t   s_SIPSettings; 
    static ProvisionSetting_t   s_VoicemailSettings; 
    static ProvisionSetting_t   s_VoicemailNumber; 
    static ProvisionSetting_t   s_BackupSIPSettings; 
    static ProvisionSetting_t   s_DialPlan; 

    static SettingValidatorMap  sc_ProvisionSettings[]; 

    // members
    DWORD   m_Flags;                                        // ProvisionManager_t Flags

    ce::list<ProvisionElement_e>    m_ElementsStack;        // stack of XML elements (for parsing)
    ce::list<ProvisionSetting_t*>   m_QuerySettingsStack;   // stack of settings that been successfully quried

    HANDLE  m_Mutex; 

    SettingCategory_e   m_ActiveSettingCategory; 
    SettingCategory_e   m_UpdateSettingCategory; 

    DWORD               m_UpdatedFlags; 

    CComPtr<IRTCClient>         m_cpRTCClient;                      //smart pointer to RTCClient
    CComPtr<DialPlanParser_t>   m_cpDialPlanParser;                 //smart pointer to DialPlanParser

    HWND                        m_ListenerWindow;                   //listner window handler
    CComPtr<IConnectionPoint>   m_cpConnectionPt;                   //smart pointer to RTC connection point
    DWORD                       m_ConnectionPtCookie;               //RTC connection pointer cookie
    
};

#endif

⌨️ 快捷键说明

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