// NATEM.h : Declaration of the CNATDynamicPortMappingService #ifndef __NATEVENTMANAGER_H_ #define __NATEVENTMANAGER_H_ #include #include #include #include ///////////////////////////////////////////////////////////////////////////// // CNATEventManager class ATL_NO_VTABLE CNATEventManager : public CComObjectRootEx, // public CComCoClass, public IDispatchImpl { private: CComPtr m_spUPSCP; std::list m_listOfCookies; public: CNATEventManager() { } ~CNATEventManager() { // run through list of cookies and remove each callback std::list::iterator iterCookies = m_listOfCookies.begin(); for (DWORD dwCookie = *iterCookies; iterCookies != m_listOfCookies.end(); dwCookie = *++iterCookies) { HRESULT hr = m_spUPSCP->RemoveTransientCallback (dwCookie); _ASSERT (hr == S_OK); } m_listOfCookies.clear(); } //DECLARE_REGISTRY_RESOURCEID(IDR_NATEVENTMANAGER) DECLARE_PROTECT_FINAL_CONSTRUCT() BEGIN_COM_MAP(CNATEventManager) COM_INTERFACE_ENTRY(INATEventManager) COM_INTERFACE_ENTRY(IDispatch) END_COM_MAP() // INATEventManager public: STDMETHOD(put_ExternalIPAddressCallback)(/*[in]*/ IUnknown * pUnk); STDMETHOD(put_NumberOfEntriesCallback)(/*[in]*/ IUnknown * pUnk); // CNATEventManager public: HRESULT Initialize (IUPnPService * pUPS) { if (!pUPS) return E_INVALIDARG; _ASSERT (m_spUPSCP == NULL); return pUPS->QueryInterface (__uuidof(IUPnPServiceCallbackPrivate), (void**)&m_spUPSCP); } HRESULT AddTransientCallback (IUnknown * punk) { DWORD dwCookie = 0; HRESULT hr = m_spUPSCP->AddTransientCallback (punk, &dwCookie); if (SUCCEEDED(hr)) { // add cookie to list m_listOfCookies.push_back (dwCookie); } return hr; } }; class ATL_NO_VTABLE CExternalIPAddressCallback : public CComObjectRootEx , public IUPnPServiceCallback { private: CComPtr m_spUnk; public: BEGIN_COM_MAP(CExternalIPAddressCallback) COM_INTERFACE_ENTRY(IUPnPServiceCallback) END_COM_MAP() // IUPnPServiceCallback public: STDMETHODIMP StateVariableChanged(IUPnPService *pus, LPCWSTR pcwszStateVarName, VARIANT vaValue); STDMETHODIMP ServiceInstanceDied(IUPnPService *pus); // CExternalIPAddressCallback public: HRESULT Initialize (IUnknown * punk) { _ASSERT (m_spUnk == NULL); m_spUnk = punk; return S_OK; } }; class ATL_NO_VTABLE CNumberOfEntriesCallback : public CComObjectRootEx , public IUPnPServiceCallback { private: CComPtr m_spUnk; public: BEGIN_COM_MAP(CNumberOfEntriesCallback) COM_INTERFACE_ENTRY(IUPnPServiceCallback) END_COM_MAP() // IUPnPServiceCallback public: STDMETHODIMP StateVariableChanged(IUPnPService *pus, LPCWSTR pcwszStateVarName, VARIANT vaValue); STDMETHODIMP ServiceInstanceDied(IUPnPService *pus); // CNumberOfEntriesCallback public: HRESULT Initialize (IUnknown * punk) { _ASSERT (m_spUnk == NULL); m_spUnk = punk; return S_OK; } }; #endif //__NATEVENTMANAGER_H_