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.

237 lines
5.9 KiB

  1. /*
  2. *
  3. * NOTES:
  4. *
  5. * REVISIONS:
  6. * sja05Nov92: Call FlushALL method of list object to destroy event attributes
  7. * sja05Nov92: Added new constructor which allows #define'ed values to
  8. * be used as values
  9. * ker19Nov92: Added GetAttributeValue function and made attribute list
  10. * work correctly, changed GetNextAttribute to return a pointer
  11. * rather than a reference.
  12. * pcy02Dec92: include err.h
  13. * jod01Feb93: Changed Do - While to While loops.
  14. * ane08Feb93: Added Copy constructor
  15. * pcy16Jan93: Have set attribute add the attribute if its not there
  16. * cad07Oct93: Plugging Memory Leaks
  17. * cad27Dec93: include file madness
  18. * pcy08Apr94: Trim size, use static iterators, dead code removal
  19. * jps15Jul94: Changed some INTs to LONG (os2 1.x)
  20. *
  21. * v-stebe 29Jul2000 Changed allocation from dyn. to heap (bug #46335)
  22. */
  23. #define INCL_BASE
  24. #define INCL_DOS
  25. #define INCL_NOPM
  26. #include "cdefine.h"
  27. #include "apc.h"
  28. #include "event.h"
  29. #if (C_OS & C_UNIX)
  30. #include "isa.h"
  31. #endif
  32. #ifdef APCDEBUG
  33. #include <iostream.h>
  34. #endif
  35. extern "C" {
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <string.h>
  39. }
  40. // Initialize static variable to count events...
  41. INT Event::EventCount = 0;
  42. //-------------------------------------------------------------------
  43. Event::Event(INT aCode, PCHAR aValue)
  44. : theEvent(aCode, aValue)
  45. {
  46. // Check against MAX?
  47. theId = ++EventCount;
  48. // theTime = new TimeStamp();
  49. theExtendedList = new List();
  50. }
  51. //-------------------------------------------------------------------
  52. Event :: Event(INT anEventCode, LONG aValue)
  53. : theEvent(anEventCode, aValue)
  54. {
  55. theId = ++EventCount;
  56. // theTime = new TimeStamp();
  57. theExtendedList = new List();
  58. }
  59. //-------------------------------------------------------------------
  60. Event :: Event (const Event &anEvent)
  61. : theEvent (anEvent.theEvent)
  62. {
  63. // Generate a new Id or copy the one from anEvent?
  64. // theId = ++EventCount;
  65. theId = anEvent.theId;
  66. // Generate a new timestamp or use the one from anEvent?
  67. // theTime = new TimeStamp();
  68. theExtendedList = new List();
  69. // Copy theExtendedList from anEvent
  70. if (anEvent.theExtendedList &&
  71. anEvent.theExtendedList->GetItemsInContainer())
  72. {
  73. PAttribute tempAttr = (PAttribute)anEvent.theExtendedList->GetHead();
  74. ListIterator tempIter(*(anEvent.theExtendedList));
  75. while(tempAttr)
  76. {
  77. PAttribute to_append =
  78. new Attribute(tempAttr->GetCode(),tempAttr->GetValue());
  79. theExtendedList->Append(to_append);
  80. tempAttr = (PAttribute)tempIter.Next();
  81. }
  82. }
  83. }
  84. //-------------------------------------------------------------------
  85. Event::~Event()
  86. {
  87. if (theExtendedList != (PList) NULL) {
  88. theExtendedList->FlushAll();
  89. delete theExtendedList;
  90. theExtendedList = NULL;
  91. }
  92. }
  93. const PCHAR Event::GetAttributeValue(INT aCode)
  94. {
  95. if (theExtendedList && theExtendedList->GetItemsInContainer()) {
  96. PAttribute the_test_attribute= (PAttribute)theExtendedList->GetHead();
  97. ListIterator the_temp_iter(*theExtendedList);
  98. while(the_test_attribute) {
  99. if( (the_test_attribute->GetCode()) == (aCode)) {
  100. return the_test_attribute->GetValue();
  101. }
  102. the_test_attribute=(PAttribute)the_temp_iter.Next();
  103. }
  104. }
  105. return (PCHAR)NULL;
  106. }
  107. INT Event::SetValue(LONG aValue)
  108. {
  109. return theEvent.SetValue(aValue);
  110. }
  111. INT Event::SetValue(const PCHAR aValue)
  112. {
  113. return theEvent.SetValue(aValue);
  114. }
  115. const PCHAR Event::GetValue()
  116. {
  117. return theEvent.GetValue();
  118. }
  119. INT Event::SetAttributeValue(INT aCode, LONG aValue)
  120. {
  121. CHAR the_temp_string[32];
  122. sprintf(the_temp_string, "%ld", aValue);
  123. INT the_return_value=SetAttributeValue(aCode, the_temp_string);
  124. return the_return_value;
  125. }
  126. INT Event::SetAttributeValue(INT aCode, const PCHAR aValue)
  127. {
  128. if(!aValue)
  129. return ErrNO_VALUE;
  130. PAttribute the_test_attribute= (PAttribute)theExtendedList->GetHead();
  131. ListIterator the_temp_iter(*theExtendedList);
  132. while(the_test_attribute)
  133. {
  134. if( (the_test_attribute->GetCode()) == (aCode))
  135. {
  136. return the_test_attribute->SetValue(aValue);
  137. }
  138. the_test_attribute=(PAttribute)the_temp_iter.Next();
  139. }
  140. //
  141. // If the attribute isn't there, add it
  142. //
  143. AppendAttribute(aCode, aValue);
  144. return ErrNO_ERROR;
  145. }
  146. //-------------------------------------------------------------------
  147. void Event::AppendAttribute(INT aCode, PCHAR aValue)
  148. {
  149. if(aValue) {
  150. PAttribute to_append = new Attribute(aCode, aValue);
  151. theExtendedList->Append(to_append);
  152. }
  153. }
  154. void Event::AppendAttribute(INT aCode, FLOAT aValue)
  155. {
  156. CHAR str_value[32];
  157. sprintf(str_value, "%.2f", aValue);
  158. AppendAttribute(aCode, str_value);
  159. }
  160. //-------------------------------------------------------------------
  161. void Event::AppendAttribute(RAttribute anAttribute)
  162. {
  163. theExtendedList->Append((PObj)(&anAttribute));
  164. }
  165. //-------------------------------------------------------------------
  166. INT Event::Equal( RObj anObject ) const
  167. {
  168. if (anObject.IsA() != IsA())
  169. return FALSE;
  170. return theEvent.Equal( *((REvent) anObject).GetEvent());
  171. }
  172. #ifdef APCDEBUG
  173. ostream& Event::printMeOut(ostream& os)
  174. {
  175. os << "Event: " << theEvent << endl;
  176. if (theExtendedList && theExtendedList->GetItemsInContainer()) {
  177. PAttribute the_test_attribute= (PAttribute)theExtendedList->GetHead();
  178. ListIterator the_temp_iter(*theExtendedList);
  179. while(the_test_attribute) {
  180. os << "\t" << *the_test_attribute << endl;
  181. the_test_attribute=(PAttribute)the_temp_iter.Next();
  182. }
  183. }
  184. return os;
  185. }
  186. #endif