Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.3 KiB

  1. // NATEM.h : Declaration of the CNATDynamicPortMappingService
  2. #ifndef __NATEVENTMANAGER_H_
  3. #define __NATEVENTMANAGER_H_
  4. #include <upnp.h>
  5. #include <upnpp.h>
  6. #include <netcon.h>
  7. #include <list>
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CNATEventManager
  10. class ATL_NO_VTABLE CNATEventManager :
  11. public CComObjectRootEx<CComSingleThreadModel>,
  12. // public CComCoClass<CNATEventManager, &CLSID_NATEventManager>,
  13. public IDispatchImpl<INATEventManager, &IID_INATEventManager, &LIBID_NATUPNPLib>
  14. {
  15. private:
  16. CComPtr<IUPnPServiceCallbackPrivate> m_spUPSCP;
  17. std::list<DWORD> m_listOfCookies;
  18. public:
  19. CNATEventManager()
  20. {
  21. }
  22. ~CNATEventManager()
  23. {
  24. // run through list of cookies and remove each callback
  25. std::list<DWORD>::iterator iterCookies = m_listOfCookies.begin();
  26. for (DWORD dwCookie = *iterCookies;
  27. iterCookies != m_listOfCookies.end();
  28. dwCookie = *++iterCookies) {
  29. HRESULT hr = m_spUPSCP->RemoveTransientCallback (dwCookie);
  30. _ASSERT (hr == S_OK);
  31. }
  32. m_listOfCookies.clear();
  33. }
  34. //DECLARE_REGISTRY_RESOURCEID(IDR_NATEVENTMANAGER)
  35. DECLARE_PROTECT_FINAL_CONSTRUCT()
  36. BEGIN_COM_MAP(CNATEventManager)
  37. COM_INTERFACE_ENTRY(INATEventManager)
  38. COM_INTERFACE_ENTRY(IDispatch)
  39. END_COM_MAP()
  40. // INATEventManager
  41. public:
  42. STDMETHOD(put_ExternalIPAddressCallback)(/*[in]*/ IUnknown * pUnk);
  43. STDMETHOD(put_NumberOfEntriesCallback)(/*[in]*/ IUnknown * pUnk);
  44. // CNATEventManager
  45. public:
  46. HRESULT Initialize (IUPnPService * pUPS)
  47. {
  48. if (!pUPS)
  49. return E_INVALIDARG;
  50. _ASSERT (m_spUPSCP == NULL);
  51. return pUPS->QueryInterface (__uuidof(IUPnPServiceCallbackPrivate),
  52. (void**)&m_spUPSCP);
  53. }
  54. HRESULT AddTransientCallback (IUnknown * punk)
  55. {
  56. DWORD dwCookie = 0;
  57. HRESULT hr = m_spUPSCP->AddTransientCallback (punk, &dwCookie);
  58. if (SUCCEEDED(hr)) {
  59. // add cookie to list
  60. m_listOfCookies.push_back (dwCookie);
  61. }
  62. return hr;
  63. }
  64. };
  65. class ATL_NO_VTABLE CExternalIPAddressCallback :
  66. public CComObjectRootEx <CComMultiThreadModel>,
  67. public IUPnPServiceCallback
  68. {
  69. private:
  70. CComPtr<IUnknown> m_spUnk;
  71. public:
  72. BEGIN_COM_MAP(CExternalIPAddressCallback)
  73. COM_INTERFACE_ENTRY(IUPnPServiceCallback)
  74. END_COM_MAP()
  75. // IUPnPServiceCallback
  76. public:
  77. STDMETHODIMP StateVariableChanged(IUPnPService *pus, LPCWSTR pcwszStateVarName, VARIANT vaValue);
  78. STDMETHODIMP ServiceInstanceDied(IUPnPService *pus);
  79. // CExternalIPAddressCallback
  80. public:
  81. HRESULT Initialize (IUnknown * punk)
  82. {
  83. _ASSERT (m_spUnk == NULL);
  84. m_spUnk = punk;
  85. return S_OK;
  86. }
  87. };
  88. class ATL_NO_VTABLE CNumberOfEntriesCallback :
  89. public CComObjectRootEx <CComMultiThreadModel>,
  90. public IUPnPServiceCallback
  91. {
  92. private:
  93. CComPtr<IUnknown> m_spUnk;
  94. public:
  95. BEGIN_COM_MAP(CNumberOfEntriesCallback)
  96. COM_INTERFACE_ENTRY(IUPnPServiceCallback)
  97. END_COM_MAP()
  98. // IUPnPServiceCallback
  99. public:
  100. STDMETHODIMP StateVariableChanged(IUPnPService *pus, LPCWSTR pcwszStateVarName, VARIANT vaValue);
  101. STDMETHODIMP ServiceInstanceDied(IUPnPService *pus);
  102. // CNumberOfEntriesCallback
  103. public:
  104. HRESULT Initialize (IUnknown * punk)
  105. {
  106. _ASSERT (m_spUnk == NULL);
  107. m_spUnk = punk;
  108. return S_OK;
  109. }
  110. };
  111. #endif //__NATEVENTMANAGER_H_