home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / DispTabl.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  12KB  |  383 lines

  1. /* @(#)Z 1.3 com/src/ui/DispTabl.cpp, odui, od96os2, odos29712d 97/03/21 17:20:17 (96/07/15 18:26:06) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odui
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //       
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28. /*
  29.     File:        DispTabl.cpp
  30.  
  31.     Contains:    Implementation of class DispatchTable, which is private
  32.                 to the implementation of ODDispatcher
  33.  
  34.     Owned by:    Richard Rodseth
  35.  
  36.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  37.  
  38.     Change History (most recent first):
  39.  
  40.          <4>     5/26/95    RR        #1251403: Multithreading naming support
  41.          <3>     5/10/95    RR        # 1245459 Don't delete fDispatchModule in
  42.                                                                         ~DispatchInfo
  43.          <2>      5/2/95    RR        # 1245459 Delete fDispatchModule in
  44.                                     ~DispatchInfo
  45.          <1>     5/13/94    RR        first checked in
  46.          <1>     5/13/94    RR        first checked in
  47.         <13>      2/7/94    NP        Tiger Team doings.
  48.         <12>     12/3/93    Té        Stop including ODError.h, it is included
  49.                                     as ErrorDef.h inside Except.h
  50.         <11>     12/2/93    RR        Use new eventType definition
  51.         <10>     9/24/93    RR        #pragma segment
  52.          <9>     8/20/93    RR        Fixed array indexing bug
  53.          <8>     8/19/93    RR        Remove redundant workaround in destructor
  54.          <7>     8/19/93    RR        Work around apparent CFront problems with
  55.                                     delete[] in ~DispatchTable
  56.          <6>     8/19/93    NP        Work around CFront's apparent problem with
  57.                                     delete 0
  58.          <5>     8/18/93    RR        Added GetDispatchInfo/UpdateDispatchInfo
  59.          <4>     8/18/93    RR        Use DictionaryList class
  60.          <2>     8/10/93    RCR        Use OrderedCollection instead of linked list, for monitors
  61.          <1>     8/10/93    RCR        first checked in
  62.  
  63.     To Do:
  64. */
  65.  
  66. #ifndef _DISPTABL_
  67. #include "DispTabl.h"
  68. #endif
  69.  
  70. #ifndef _DISPMOD_
  71. #include "DispMod.xh"
  72. #endif
  73.  
  74. #ifndef _ORDCOLL_
  75. #include "OrdColl.h"
  76. #endif
  77.  
  78. #ifndef _DICTLIST_
  79. #include "DictList.h"
  80. #endif
  81.  
  82. #ifndef _EXCEPT_
  83. #include "Except.h"
  84. #endif
  85.  
  86. #pragma segment ODDispatcher
  87.  
  88. //=====================================================================================
  89. // Private Class: DispatchInfo
  90. //=====================================================================================
  91.  
  92. class DispatchInfo 
  93. {
  94. public:
  95.     
  96.     DispatchInfo();
  97.     
  98.         // Constructor
  99.         
  100.     ~DispatchInfo();
  101.     
  102.         // Destructor
  103.         
  104.     void SetModule(ODDispatchModule* module);
  105.     ODDispatchModule* GetModule();
  106.     void AddMonitor(ODDispatchModule* monitor);
  107.     void RemoveMonitor(ODDispatchModule* monitor);
  108.     OrderedCollection* GetMonitors();
  109.  
  110. protected:
  111.     ODDispatchModule* fDispatchModule;
  112.     OrderedCollection* fMonitors;
  113. };
  114.  
  115. //-------------------------------------------------------------------------------------
  116. // DispatchInfo::DispatchInfo
  117. //
  118. // Description
  119. //-------------------------------------------------------------------------------------
  120.  
  121. DispatchInfo::DispatchInfo()
  122. {
  123.     fDispatchModule = kODNULL;
  124.     fMonitors = kODNULL;
  125. }
  126.  
  127. //-------------------------------------------------------------------------------------
  128. // DispatchInfo::~DispatchInfo
  129. //
  130. // Description
  131. //-------------------------------------------------------------------------------------
  132.  
  133. DispatchInfo::~DispatchInfo()
  134. {
  135.     delete fMonitors;
  136.     // Don't delete fDispatchModule, because many entries in the table
  137.     // point to the same module
  138. }
  139.  
  140. //-------------------------------------------------------------------------------------
  141. // DispatchInfo::SetModule
  142. //
  143. // Description
  144. //-------------------------------------------------------------------------------------
  145.  
  146. void DispatchInfo::SetModule(ODDispatchModule* module)
  147. {
  148.     fDispatchModule = module;
  149. }
  150.  
  151. //-------------------------------------------------------------------------------------
  152. // DispatchInfo::GetModule
  153. //
  154. // Description
  155. //-------------------------------------------------------------------------------------
  156.  
  157. ODDispatchModule* DispatchInfo::GetModule()
  158. {
  159.     return fDispatchModule;
  160. }
  161.  
  162. //-------------------------------------------------------------------------------------
  163. // DispatchInfo::AddMonitor
  164. //
  165. // Exceptions thrown:
  166. //         kODErrOutOfMemory
  167. //-------------------------------------------------------------------------------------
  168.  
  169. void DispatchInfo::AddMonitor(ODDispatchModule* monitor)
  170. {
  171.     if (monitor)
  172.     {
  173.         if (!fMonitors)
  174.             fMonitors = new OrderedCollection;
  175.         THROW_IF_NULL(fMonitors);
  176.         
  177.         if (!(fMonitors->Contains((ElementType) monitor)))
  178.             fMonitors->AddLast((ElementType) monitor);
  179.     }
  180. }
  181.     
  182. //-------------------------------------------------------------------------------------
  183. // DispatchInfo::RemoveMonitor
  184. //
  185. // Description
  186. //-------------------------------------------------------------------------------------
  187.  
  188. void DispatchInfo::RemoveMonitor(ODDispatchModule* monitor)
  189. {
  190.     if (fMonitors)
  191.         fMonitors->Remove((ElementType) monitor);
  192. }
  193.  
  194. //-------------------------------------------------------------------------------------
  195. // DispatchInfo::GetMonitors
  196. //
  197. // Description
  198. //-------------------------------------------------------------------------------------
  199.  
  200. OrderedCollection* DispatchInfo::GetMonitors()
  201. {
  202.     return fMonitors;
  203. }
  204.  
  205. //=====================================================================================
  206. // Class DispatchTable
  207. //=====================================================================================
  208.  
  209. //-------------------------------------------------------------------------------------
  210. // DispatchTable::DispatchTable
  211. //
  212. // Constructor. Initializes the array entries to NULL.
  213. //-------------------------------------------------------------------------------------
  214.  
  215. DispatchTable::DispatchTable()
  216. {
  217.     for (short i = 0; i <= kODLastEvent; i++)
  218.         fDispatchInfo[i] = kODNULL;
  219.     fOverflowDispatchInfo = kODNULL;
  220. }
  221.  
  222. //-------------------------------------------------------------------------------------
  223. // DispatchTable::~DispatchTable
  224. //
  225. // Description
  226. //-------------------------------------------------------------------------------------
  227.  
  228. DispatchTable::~DispatchTable()
  229. {
  230.     for (short i = 0; i <= kODLastEvent; i++)    
  231.         delete fDispatchInfo[i];
  232.     //delete[] fDispatchInfo;    // CFront has a problem with this?
  233.     if (fOverflowDispatchInfo)
  234.         fOverflowDispatchInfo->DeleteValues();
  235.     delete fOverflowDispatchInfo;
  236. }
  237.  
  238. //-------------------------------------------------------------------------------------
  239. // DispatchTable::AddMonitor
  240. //
  241. // Description
  242. //-------------------------------------------------------------------------------------
  243.  
  244. void DispatchTable::AddMonitor(ODEventType eventType, 
  245.                                ODDispatchModule* dispatchModule)
  246. {
  247.     // Should check if dispatchModule is already installed as a regular module?
  248.     
  249.     DispatchInfo* info = this->GetDispatchInfo(eventType);
  250.     if (info == kODNULL)
  251.     {
  252.         info = new DispatchInfo;
  253.         THROW_IF_NULL(info);
  254.         this->UpdateDispatchInfo(eventType,info);
  255.     }
  256.     info->AddMonitor(dispatchModule);
  257. }
  258.  
  259. //-------------------------------------------------------------------------------------
  260. // DispatchTable::RemoveMonitor
  261. //
  262. // Description
  263. //-------------------------------------------------------------------------------------
  264.  
  265. void DispatchTable::RemoveMonitor(ODEventType eventType, ODDispatchModule* dispatchModule)
  266. {
  267.     DispatchInfo* info = this->GetDispatchInfo(eventType);
  268.     if (info)
  269.         info->RemoveMonitor(dispatchModule);
  270. }
  271.  
  272. //-------------------------------------------------------------------------------------
  273. // DispatchTable::AddDispatchModule
  274. //
  275. // Description
  276. //-------------------------------------------------------------------------------------
  277.  
  278. void DispatchTable::AddDispatchModule(ODEventType eventType, 
  279.                                ODDispatchModule* dispatchModule)
  280. {
  281.     // To Do: THROW exception if already installed
  282.  
  283.     DispatchInfo* info = this->GetDispatchInfo(eventType);
  284.     
  285.     if (info == kODNULL)
  286.     {
  287.         info = new DispatchInfo;
  288.         THROW_IF_NULL(info);
  289.         this->UpdateDispatchInfo(eventType,info);            
  290.     }
  291.     info->SetModule(dispatchModule);
  292. }
  293.  
  294. //-------------------------------------------------------------------------------------
  295. // DispatchTable::RemoveDispatchModule
  296. //
  297. // Description
  298. //-------------------------------------------------------------------------------------
  299.  
  300. void DispatchTable::RemoveDispatchModule(ODEventType eventType)
  301. {
  302.     DispatchInfo* info = this->GetDispatchInfo(eventType);
  303.     if (info)
  304.         info->SetModule(kODNULL);
  305. }
  306.  
  307. //-------------------------------------------------------------------------------------
  308. // DispatchTable::GetDispatchInfo
  309. //
  310. // Description
  311. //-------------------------------------------------------------------------------------
  312.  
  313. DispatchInfo* DispatchTable::GetDispatchInfo(ODEventType eventType)
  314. {
  315.     DispatchInfo* info = kODNULL;
  316.  
  317.     if (eventType <= kODLastEvent)
  318.         info = fDispatchInfo[eventType];
  319.     else if (fOverflowDispatchInfo)
  320.         info = (DispatchInfo*) fOverflowDispatchInfo->ValueAtKey((KeyType) eventType);
  321.     return info;
  322. }
  323.  
  324. //-------------------------------------------------------------------------------------
  325. // DispatchTable::UpdateDispatchInfo
  326. //
  327. // Description
  328. //-------------------------------------------------------------------------------------
  329.     
  330. void DispatchTable::UpdateDispatchInfo(ODEventType eventType, DispatchInfo* info)
  331. {
  332.     if (eventType <= kODLastEvent)
  333.         fDispatchInfo[eventType] = info;
  334.     else
  335.     {
  336.         if (!fOverflowDispatchInfo)
  337.             fOverflowDispatchInfo = new DictionaryList;
  338.         fOverflowDispatchInfo->AddPair((KeyType) eventType, (ValueType) info);
  339.     }
  340. }
  341.  
  342. //-------------------------------------------------------------------------------------
  343. // DispatchTable::GetDispatchModule
  344. //
  345. // Description
  346. //-------------------------------------------------------------------------------------
  347.  
  348. ODDispatchModule* DispatchTable::GetDispatchModule(ODEventType eventType)
  349. {
  350.     ODDispatchModule* module = kODNULL;
  351.     DispatchInfo* info = kODNULL;
  352.     
  353.     if (eventType <= kODLastEvent)
  354.         info = fDispatchInfo[eventType];
  355.     else if (fOverflowDispatchInfo)
  356.         info = (DispatchInfo*) fOverflowDispatchInfo->ValueAtKey((KeyType) eventType);
  357.     if (info)
  358.         module = info->GetModule();
  359.     return module;
  360. }
  361.  
  362. //-------------------------------------------------------------------------------------
  363. // DispatchTable::GetMonitors
  364. //
  365. // Description
  366. //-------------------------------------------------------------------------------------
  367.  
  368. OrderedCollection* DispatchTable::GetMonitors(ODEventType eventType)
  369. {
  370.     OrderedCollection* monitors = kODNULL;
  371.     DispatchInfo* info = kODNULL;
  372.     
  373.     if (eventType <= kODLastEvent)
  374.         info = fDispatchInfo[eventType];
  375.     else if (fOverflowDispatchInfo)
  376.         info = (DispatchInfo*) fOverflowDispatchInfo->ValueAtKey((KeyType) eventType);
  377.     if (info)
  378.         monitors = info->GetMonitors();
  379.     return monitors;
  380. }
  381.  
  382.  
  383.