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.

83 lines
1.9 KiB

  1. //******************************************************************************
  2. //
  3. // CLSCACHE.CPP
  4. //
  5. // Copyright (C) 1996-1999 Microsoft Corporation
  6. //
  7. //******************************************************************************
  8. #include "precomp.h"
  9. #include <stdio.h>
  10. #include <nsrep.h>
  11. CEssClassCache::~CEssClassCache()
  12. {
  13. Clear();
  14. }
  15. HRESULT CEssClassCache::GetClass( LPCWSTR wszClassName,
  16. IWbemContext* pContext,
  17. _IWmiObject** ppClass )
  18. {
  19. HRESULT hres;
  20. // Search the map
  21. // ==============
  22. {
  23. CInCritSec ics(&m_cs);
  24. TIterator it = m_mapClasses.find((LPWSTR)wszClassName);
  25. if(it != m_mapClasses.end())
  26. {
  27. *ppClass = it->second;
  28. (*ppClass)->AddRef();
  29. return S_OK;
  30. }
  31. }
  32. // Not found --- retrieve
  33. // ======================
  34. _IWmiObject* pClass = NULL;
  35. hres = m_pNamespace->GetClassFromCore(wszClassName, &pClass);
  36. if(FAILED(hres))
  37. return hres;
  38. CReleaseMe rm2(pClass);
  39. // Cache it if needed
  40. // ==================
  41. {
  42. CInCritSec ics(&m_cs);
  43. if(m_mapClasses.find((LPWSTR)wszClassName) == m_mapClasses.end())
  44. {
  45. try
  46. {
  47. m_mapClasses[wszClassName] = pClass;
  48. pClass->AddRef();
  49. }
  50. catch(CX_MemoryException &)
  51. {
  52. return WBEM_E_OUT_OF_MEMORY;
  53. }
  54. }
  55. }
  56. *ppClass = pClass;
  57. pClass->AddRef();
  58. return WBEM_S_NO_ERROR;
  59. }
  60. HRESULT CEssClassCache::Clear()
  61. {
  62. CInCritSec ics(&m_cs);
  63. for(TIterator it = m_mapClasses.begin(); it != m_mapClasses.end(); it++)
  64. {
  65. it->second->Release();
  66. }
  67. m_mapClasses.clear();
  68. return WBEM_S_NO_ERROR;
  69. }