Leaked source code of windows server 2003
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.

96 lines
2.3 KiB

  1. #include "precomp.h"
  2. #include <assert.h>
  3. #include <sync.h>
  4. #include <arrtempl.h>
  5. #include <wstring.h>
  6. #include <comutl.h>
  7. #include <statsync.h>
  8. #include <map>
  9. #include <wstlallc.h>
  10. #include "fconprov.h"
  11. #include "fconnspc.h"
  12. #include "fconsink.h"
  13. LPCWSTR g_wszNamespace = L"__NAMESPACE";
  14. LPCWSTR g_wszClass = L"__CLASS";
  15. LPCWSTR g_wszEventFwdCons = L"MSFT_EventForwardingConsumer";
  16. LPCWSTR g_wszDataFwdCons = L"MSFT_DataForwardingConsumer";
  17. static CStaticCritSec g_cs;
  18. typedef CWbemPtr<CFwdConsNamespace> CFwdConsNamespaceP;
  19. typedef std::map<WString,CFwdConsNamespaceP,WSiless,wbem_allocator<CFwdConsNamespaceP> > NamespaceMap;
  20. NamespaceMap* g_pNamespaces;
  21. HRESULT CFwdConsProv::InitializeModule()
  22. {
  23. g_pNamespaces = new NamespaceMap;
  24. if ( g_pNamespaces == NULL )
  25. {
  26. return WBEM_E_OUT_OF_MEMORY;
  27. }
  28. return WBEM_S_NO_ERROR;
  29. }
  30. void CFwdConsProv::UninitializeModule()
  31. {
  32. delete g_pNamespaces;
  33. }
  34. HRESULT CFwdConsProv::FindConsumer( IWbemClassObject* pCons,
  35. IWbemUnboundObjectSink** ppSink )
  36. {
  37. ENTER_API_CALL
  38. HRESULT hr;
  39. //
  40. // workaround for bogus context object left on thread by wmi.
  41. // just remove it. shouldn't leak because this call doesn't addref it.
  42. //
  43. IUnknown* pCtx;
  44. CoSwitchCallContext( NULL, &pCtx );
  45. //
  46. // first obtain the namespace object. we derive the namespace from
  47. // the consumer object. If no namespace obj is there, create one.
  48. //
  49. CPropVar vNamespace;
  50. hr = pCons->Get( g_wszNamespace, 0, &vNamespace, NULL, NULL );
  51. if ( FAILED(hr) || FAILED(hr=vNamespace.SetType(VT_BSTR)) )
  52. {
  53. return hr;
  54. }
  55. CInCritSec ics( &g_cs );
  56. CWbemPtr<CFwdConsNamespace> pNspc = (*g_pNamespaces)[V_BSTR(&vNamespace)];
  57. if ( pNspc == NULL )
  58. {
  59. pNspc = new CFwdConsNamespace;
  60. if ( pNspc == NULL )
  61. {
  62. return WBEM_E_OUT_OF_MEMORY;
  63. }
  64. hr = pNspc->Initialize( V_BSTR(&vNamespace) );
  65. if ( FAILED(hr) )
  66. {
  67. return hr;
  68. }
  69. (*g_pNamespaces)[V_BSTR(&vNamespace)] = pNspc;
  70. }
  71. return CFwdConsSink::Create( m_pControl, pNspc, pCons, ppSink );
  72. EXIT_API_CALL
  73. }