/********************************************************************************\
*  This sample is supplied as is with no implied warranty.  
*  It is designed to assist you in using the Cisco AnyConnect VPN API. 
*  It is assumed that you will build a production application and 
*  refer to this sample as a reference only.
\********************************************************************************/
#pragma once

//This file contains the COM object implementation of the IVpnApiEvents interface using ATL.  
//An instance of this class is given to the COM Server to use for firing notifications. 
//The defined class, CEventCallBack is then added to the object inheritance of the dialog class
//via the CComObjectStackEx template class (which requires a concrete class object argument).
//The use of CComObjectStackEx requires that you create the dialog on the stack.
//The virtual methods of this concrete class are then overridden in the dialog class by you,
//as is done in this example.
//
class ATL_NO_VTABLE CEventCallBack : 
	public CComObjectRootEx<CComMultiThreadModel>,
	public CComCoClass<CEventCallBack>,
    public ISupportErrorInfo,
    public IDispatchImpl<IVpnApiEvents, &__uuidof(IVpnApiEvents), &__uuidof(__VpnApiLib)>
{
public:
    CEventCallBack() 
    { 
        ATLTRACE(_T("Exiting %hs\n"), __FUNCTION__);
    }
    virtual ~CEventCallBack() 
    {
        ATLTRACE(_T("Exiting %hs\n"), __FUNCTION__);
    }

    HRESULT FinalConstruct() 
    {
        ATLTRACE(_T("Exiting %hs\n"), __FUNCTION__);
        return S_OK;
    }
    void FinalRelease() 
    { 
        ATLTRACE(_T("Exiting %hs\n"), __FUNCTION__);
    }

    //ISupportErrorInfo -- used to indicate that the code supports and leverages the COM Error() methods
    STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
    {
        static const IID* arr[] =  {&__uuidof(IVpnApiEvents)};

	    for (size_t i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
	    {
            if (::InlineIsEqualGUID(*arr[i],riid))
            {
			    return S_OK;
            }
	    }

        return S_FALSE;
    }

    //IVpnApiEvents -- This is the required notification interface you must implement.
    STDMETHOD(raw_VpnStatsNotification)(/*[in]*/ IVpnStats * pVpnStats) {return E_NOTIMPL;}
    
    STDMETHOD(raw_VpnStateNotification)(/*[in]*/ enum VPNState eState,
                                        /*[in]*/ enum VPNSubState eSubState,
                                        /*[in]*/ BSTR bstrState ) {return E_NOTIMPL;}
    
    STDMETHOD(raw_VpnBannerNotification)(/*[in]*/ BSTR bstrBannerMessage) {return E_NOTIMPL;}

    STDMETHOD(raw_VpnNoticeNotification)(/*[in]*/ IN BSTR bstrNoticeMessage, 
                                         /*[in]*/ enum MessageType eMessageType) {return E_NOTIMPL;}

    STDMETHOD(raw_VpnExitNotification)(/*[in]*/ BSTR bstrExitMessage,
                                       /*[in]*/ long exitCode ) {return E_NOTIMPL;}
    
    STDMETHOD(raw_VpnServiceReadyNotification)(void) {return E_NOTIMPL;}

    STDMETHOD(raw_VpnUserPromptNotification)(/*[in]*/ IConnectPromptInfo * pConnectPromptInfo) {return E_NOTIMPL;}

    STDMETHOD(raw_VpnWMHintNotification)(/*[in]*/ enum WMHint eHint,
                                         /*[in]*/ enum WMHintReason eReason){return E_NOTIMPL;} 

    STDMETHOD(raw_VpnWebLaunchHostNotification)(/*[in]*/ BSTR bstrActiveHost) {return E_NOTIMPL;}

    STDMETHOD(raw_VpnEventAvailableNotification)(void) {return E_NOTIMPL;}

    STDMETHOD(raw_VpnCertBlockedNotification)(/* [in] */ BSTR strUntrustedServer) { return E_NOTIMPL; }
        
    STDMETHOD(raw_VpnCertWarningNotification)(/* [in] */ BSTR strUntrustedServer,
                                              /* [in] */ IStringCollection *pCertErrors,
                                              /* [in] */ VARIANT_BOOL bAllowImport) { return E_NOTIMPL; }

    DECLARE_NO_REGISTRY()
    DECLARE_NOT_AGGREGATABLE(CEventCallBack)

    DECLARE_PROTECT_FINAL_CONSTRUCT()

    BEGIN_COM_MAP(CEventCallBack)
	    COM_INTERFACE_ENTRY(IVpnApiEvents)
        COM_INTERFACE_ENTRY(ISupportErrorInfo)
        COM_INTERFACE_ENTRY(IDispatch)
    END_COM_MAP()

};
