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.

302 lines
7.6 KiB

  1. /*
  2. * REVISIONS:
  3. * pcy30Nov92: Added header
  4. * ane02Dec92: Changed Dispatcher to inherit from Obj (see comment)
  5. * rct09Feb93: Corrected some #ifdefs
  6. * pcy21Apr93: Added method to get list and re register
  7. * pcy15May93: Cleaned up
  8. * cad19May93: bug fix, RListIterator decl as ListIterator
  9. * cad27Sep93: Not adding to event nodes twice, returning error code in Add
  10. * cad28Feb94: nulling list after delete
  11. * pcy08Apr94: Trim size, use static iterators, dead code removal
  12. *
  13. * v-stebe 29Jul2000 Fixed PREfix errors (bug #46362)
  14. */
  15. #include "cdefine.h"
  16. #if (C_OS & C_OS2)
  17. #define INCL_BASE
  18. #define INCL_DOS
  19. #define INCL_NOPM
  20. #endif
  21. #if (C_OS & (C_WINDOWS | C_WIN311))
  22. #define NOLFILEIO
  23. #include <windows.h>
  24. #endif
  25. extern "C" {
  26. #if (C_OS & C_OS2)
  27. #include <os2.h>
  28. #endif
  29. #if (C_OS & C_NLM)
  30. #include <process.h>
  31. #endif
  32. }
  33. #include "err.h"
  34. #include "event.h"
  35. #include "dispatch.h"
  36. // =========================================================================
  37. // Method Definitions for the EventNode Class.
  38. /*
  39. Name :EventNode
  40. Synop :Constructor for the EventNode. Use this when you are first creating
  41. and eventNode. anUpdateObj is the first updateable object in the
  42. internal linked list managed by the EventNode.
  43. */
  44. EventNode::EventNode(INT anEventCode,PUpdateObj anUpdateObj)
  45. {
  46. // 1. Create the list
  47. theUpdateList = new List();
  48. theEventCode = anEventCode;
  49. // 2. Add the first node to the list.
  50. Add(anUpdateObj);
  51. }
  52. /*
  53. Name :~EventNode
  54. Synop :Destructor. Will delete the internal linked list. The Linked list
  55. flush'es its nodes and all will be well. Does not delete the updateable
  56. objects which it contains in the linked list. We don't own those.
  57. */
  58. EventNode::~EventNode()
  59. {
  60. delete theUpdateList;
  61. theUpdateList = NULL;
  62. }
  63. INT EventNode::Add(PUpdateObj anUpdateObj)
  64. {
  65. INT err = ErrNO_ERROR;
  66. if (theUpdateList)
  67. {
  68. ListIterator obj_iter(*theUpdateList);
  69. INT add_the_obj = TRUE;
  70. INT num_attrs = theUpdateList->GetItemsInContainer();
  71. for (INT i=0; i<num_attrs; i++)
  72. {
  73. RUpdateObj an_obj = (RUpdateObj)obj_iter.Current();
  74. if(an_obj == *anUpdateObj)
  75. {
  76. add_the_obj = FALSE;
  77. break;
  78. }
  79. obj_iter.Next(); // SRB: Changed from obj_iter++
  80. }
  81. if(add_the_obj)
  82. {
  83. theUpdateList->Append(anUpdateObj);
  84. }
  85. else
  86. {
  87. err = ErrALREADY_REGISTERED;
  88. }
  89. }
  90. return err;
  91. }
  92. /*
  93. Name :Detach
  94. SYnop :Removes an updateable object from the EventNode.
  95. */
  96. VOID EventNode::Detach(PUpdateObj anUpdateObj)
  97. {
  98. if (theUpdateList)
  99. {
  100. // The Equal() method for the Object must be implemented correctly
  101. // for this to work...
  102. theUpdateList->Detach(*anUpdateObj);
  103. }
  104. }
  105. /*
  106. Name :Update
  107. Synop :Update will update all the updateable objects in its internal linked
  108. list. It handles all of that. Returns after all the updateable objects
  109. have been updated.
  110. */
  111. INT EventNode::Update(PEvent anEvent)
  112. {
  113. ListIterator an_iterator(*theUpdateList);
  114. INT items_in_container = theUpdateList->GetItemsInContainer();
  115. for(INT i=0;i<items_in_container;i++) {
  116. PUpdateObj an_update_obj=(PUpdateObj)&an_iterator.Current();
  117. an_iterator.Next(); // SRB: Changed from an_iterator++
  118. an_update_obj->Update(anEvent);
  119. }
  120. return ErrNO_ERROR;
  121. }
  122. // =========================================================================
  123. // Method definitions for the Dispatcher Object.
  124. Dispatcher::Dispatcher()
  125. {
  126. theDispatchEntries = (PList)NULL;
  127. }
  128. /*
  129. Name :~Dispatcher
  130. Synop :The destructor of the dispatcher which simply delete the list
  131. object. It is important to note that this does NOT cause the
  132. list object to delete the UpdateAble objects we have stored within
  133. the list. We DO NOT WANT those object to be deleted since we do
  134. not own them. Imagine what would happen if we did. If you revise
  135. the dispatcher, don't forget that!
  136. */
  137. Dispatcher::~Dispatcher()
  138. {
  139. if(theDispatchEntries) {
  140. theDispatchEntries->FlushAll();
  141. delete theDispatchEntries;
  142. theDispatchEntries = (PList)NULL;
  143. }
  144. }
  145. INT Dispatcher::RegisterEvent(INT id, PUpdateObj item)
  146. {
  147. if (theDispatchEntries == NULL)
  148. {
  149. theDispatchEntries = new List();
  150. }
  151. INT err = ErrNO_ERROR;
  152. INT not_in_list = TRUE;
  153. if (theDispatchEntries != NULL) {
  154. ListIterator an_iterator(*theDispatchEntries);
  155. INT items_in_container=theDispatchEntries->GetItemsInContainer();
  156. for (INT i = 0; (i < items_in_container) && not_in_list; i++)
  157. {
  158. REventNode an_event_node = (REventNode) an_iterator.Current();
  159. an_iterator.Next(); // SRB: Changed from an_iterator++
  160. if (an_event_node.GetEventCode() == id)
  161. {
  162. err = an_event_node.Add(item);
  163. not_in_list = FALSE;
  164. }
  165. }
  166. if (not_in_list && (err == ErrNO_ERROR))
  167. {
  168. theDispatchEntries->Append(new EventNode(id,item));
  169. }
  170. }
  171. else {
  172. err = ErrREGISTER_FAILED;
  173. }
  174. return err;
  175. }
  176. INT Dispatcher::UnregisterEvent(INT id, PUpdateObj item)
  177. {
  178. INT err = ErrINVALID_CODE;
  179. ListIterator an_iterator(*theDispatchEntries);
  180. INT items_in_container = theDispatchEntries->GetItemsInContainer();
  181. for(INT i = 0; i < items_in_container; i++)
  182. {
  183. REventNode an_event_node=(REventNode)an_iterator.Current();
  184. an_iterator.Next(); // SRB: Changed from an_iterator++
  185. if (an_event_node.GetEventCode() == id)
  186. {
  187. an_event_node.Detach(item);
  188. err = ErrNO_ERROR;
  189. break;
  190. }
  191. }
  192. return err;;
  193. }
  194. INT Dispatcher:: Update(PEvent anEvent)
  195. {
  196. ListIterator an_iterator(*theDispatchEntries);
  197. INT items_in_container=theDispatchEntries->GetItemsInContainer();
  198. for(INT i=0;i<items_in_container;i++)
  199. {
  200. PEventNode an_event_node=(PEventNode)&an_iterator.Current();
  201. if(an_event_node->GetEventCode() == anEvent->GetCode())
  202. {
  203. an_event_node->Update(anEvent);
  204. break;
  205. }
  206. an_iterator.Next(); // SRB: Changed from an_iterator++
  207. #if (C_OS & C_NLM)
  208. ThreadSwitch();
  209. #endif
  210. }
  211. return ErrNO_ERROR;
  212. }
  213. INT
  214. Dispatcher :: RefreshEventRegistration(PUpdateObj anUpdater,
  215. PUpdateObj aRegistrant)
  216. {
  217. ListIterator an_iterator(*theDispatchEntries);
  218. INT items_in_container=theDispatchEntries->GetItemsInContainer();
  219. for(INT i=0;i<items_in_container;i++) {
  220. REventNode an_event_node=(REventNode)an_iterator.Current();
  221. INT code = an_event_node.GetEventCode();
  222. anUpdater->RegisterEvent(code, aRegistrant);
  223. an_iterator.Next(); // SRB: Changed from an_iterator++
  224. }
  225. return ErrNO_ERROR;
  226. }
  227. INT Dispatcher :: GetRegisteredCount(INT id)
  228. {
  229. INT the_count = 0;
  230. ListIterator an_iterator(*theDispatchEntries);
  231. INT items_in_container=theDispatchEntries->GetItemsInContainer();
  232. for(INT i=0;i<items_in_container;i++) {
  233. REventNode an_event_node=(REventNode)an_iterator.Current();
  234. an_iterator.Next(); // SRB: Changed from an_iterator++
  235. if (an_event_node.GetEventCode() == id) {
  236. the_count = an_event_node.GetCount();
  237. break;
  238. }
  239. }
  240. return the_count;
  241. }