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.

150 lines
2.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // logschema.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class LogSchema.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 08/04/1998 Original version.
  16. // 12/02/1998 Added excludeFromLog.
  17. // 04/14/2000 Port to new dictionary API.
  18. //
  19. ///////////////////////////////////////////////////////////////////////////////
  20. #include <ias.h>
  21. #include <iastlb.h>
  22. #include <iastlutl.h>
  23. #include <iasutil.h>
  24. #include <algorithm>
  25. #include <vector>
  26. #include <sdoias.h>
  27. #include <logschema.h>
  28. LogSchema::LogSchema() throw ()
  29. : numFields(0), refCount(0)
  30. { }
  31. LogSchema::~LogSchema() throw ()
  32. { }
  33. BOOL LogSchema::excludeFromLog(DWORD iasID) const throw ()
  34. {
  35. LogField key;
  36. key.iasID = iasID;
  37. const SchemaTable::value_type* p = schema.find(key);
  38. return p ? p->exclude : FALSE;
  39. }
  40. DWORD LogSchema::getOrdinal(DWORD iasID) const throw ()
  41. {
  42. LogField key;
  43. key.iasID = iasID;
  44. const SchemaTable::value_type* p = schema.find(key);
  45. return p ? p->ordinal : 0;
  46. }
  47. HRESULT LogSchema::initialize() throw ()
  48. {
  49. std::_Lockit _Lk;
  50. // Have we already been initialized ?
  51. if (refCount != 0)
  52. {
  53. ++refCount;
  54. return S_OK;
  55. }
  56. try
  57. {
  58. // Names of various columns in the dictionary.
  59. const PCWSTR COLUMNS[] =
  60. {
  61. L"ID",
  62. L"Exclude from NT4 IAS Log",
  63. L"ODBC Log Ordinal",
  64. NULL
  65. };
  66. // Open the attributes table.
  67. IASTL::IASDictionary dnary(COLUMNS);
  68. std::vector< LogField > record;
  69. while (dnary.next())
  70. {
  71. // Read ID.
  72. DWORD iasID = (DWORD)dnary.getLong(0);
  73. // Read [Exclude from NT4 IAS Log] if present.
  74. BOOL exclude = (BOOL)dnary.getBool(1);
  75. // Read [ODBC Log Ordinal] if present.
  76. DWORD ordinal = (DWORD)dnary.getLong(2);
  77. // There's no need to save it unless one of these is set.
  78. if (exclude || ordinal)
  79. {
  80. record.push_back(LogField(iasID, ordinal, exclude));
  81. }
  82. }
  83. // Sort the fields by ordinal.
  84. std::sort(record.begin(), record.end());
  85. //////////
  86. // Insert the fields into the table.
  87. //////////
  88. numFields = 0;
  89. for (std::vector< LogField >::iterator i = record.begin();
  90. i != record.end();
  91. ++i)
  92. {
  93. // Normalize the ordinal.
  94. if (i->ordinal) { i->ordinal = ++numFields; }
  95. schema.insert(*i);
  96. }
  97. }
  98. catch (const std::bad_alloc&)
  99. {
  100. clear();
  101. return E_OUTOFMEMORY;
  102. }
  103. catch (const _com_error& ce)
  104. {
  105. clear();
  106. return ce.Error();
  107. }
  108. // We were successful so add ref.
  109. refCount = 1;
  110. return S_OK;
  111. }
  112. void LogSchema::shutdown() throw ()
  113. {
  114. std::_Lockit _Lk;
  115. _ASSERT(refCount != 0);
  116. if (--refCount == 0) { clear(); }
  117. }
  118. void LogSchema::clear() throw ()
  119. {
  120. schema.clear();
  121. }