home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWNotifn / Sources / FWHFConn.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  6.0 KB  |  194 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWHFConn.tpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef FWHFCONN_H
  13. #include "FWHFConn.h"
  14. #endif
  15.  
  16. #ifndef FWNOTIFR_H
  17. #include "FWNotifr.h"
  18. #endif
  19.  
  20. #if FW_LIB_EXPORT_PRAGMAS
  21. #pragma lib_export on
  22. #endif
  23.  
  24. //========================================================================================
  25. // CLASS FW_MReceiver
  26. //========================================================================================
  27.  
  28. //----------------------------------------------------------------------------------------
  29. // FW_MReceiver::FW_MReceiver
  30. //----------------------------------------------------------------------------------------
  31.  
  32. FW_MReceiver::FW_MReceiver()
  33. {
  34. }
  35.  
  36. //----------------------------------------------------------------------------------------
  37. // FW_MReceiver::~FW_MReceiver
  38. //----------------------------------------------------------------------------------------
  39.  
  40. FW_MReceiver::~FW_MReceiver()
  41. {
  42. }
  43.  
  44. //========================================================================================
  45. // CLASS FW_CHandleFunctionConnection
  46. //========================================================================================
  47.  
  48. //----------------------------------------------------------------------------------------
  49. // FW_CHandleFunctionConnection::FW_CHandleFunctionConnection
  50. //----------------------------------------------------------------------------------------
  51.  
  52. FW_CHandleFunctionConnection::FW_CHandleFunctionConnection(FW_MReceiver* receiver) :
  53.     fReceiver(receiver),
  54.     fInterestList()
  55. {
  56. }
  57.  
  58. //----------------------------------------------------------------------------------------
  59. // FW_CHandleFunctionConnection::~FW_CHandleFunctionConnection
  60. //----------------------------------------------------------------------------------------
  61.  
  62. FW_CHandleFunctionConnection::~FW_CHandleFunctionConnection()
  63. {
  64. }
  65.             
  66. //----------------------------------------------------------------------------------------
  67. // FW_CHandleFunctionConnection::AddInterest
  68. //----------------------------------------------------------------------------------------
  69.  
  70. void FW_CHandleFunctionConnection::AddInterest(const FW_CInterest& interest)
  71. {
  72.     FW_CInterest* interestCopy = new FW_CInterest(interest);
  73.     
  74.     if (IsConnected())
  75.         interestCopy->GetNotifier()->AddConnection(this, interestCopy);
  76.  
  77.     fInterestList.AddLast(interestCopy);
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. // FW_CHandleFunctionConnection::RemoveAllInterests
  82. //----------------------------------------------------------------------------------------
  83.  
  84. void FW_CHandleFunctionConnection::RemoveAllInterests()
  85. {
  86.     if (IsConnected())
  87.     {
  88.         FW_COrderedCollectionIterator ite(&fInterestList);
  89.         for (FW_CInterest* interest = (FW_CInterest *) ite.First();
  90.                  ite.IsNotComplete(); interest = (FW_CInterest *) ite.Next())
  91.         {
  92.             interest->GetNotifier()->RemoveConnection(*this, *interest);
  93.         }
  94.     }
  95.  
  96.     FW_CInterest* interest;
  97.     while ((interest = (FW_CInterest*)fInterestList.First()) != NULL)
  98.     {
  99.         fInterestList.Remove(interest);
  100.         delete interest;
  101.     }        
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. // FW_CHandleFunctionConnection::RemoveInterest
  106. //----------------------------------------------------------------------------------------
  107.  
  108. void FW_CHandleFunctionConnection::RemoveInterest(const FW_CInterest& interest)
  109. {    
  110.     FW_CPrivOrderedCollection temp;
  111.     FW_COrderedCollectionIterator ite1(&fInterestList);
  112.     for (FW_CInterest* i = (FW_CInterest *) ite1.First();
  113.                  ite1.IsNotComplete(); i = (FW_CInterest *) ite1.Next())
  114.     {
  115.         if (*i == interest)
  116.             temp.AddLast(i);
  117.     }
  118.     
  119.     FW_COrderedCollectionIterator ite2(&temp);
  120.     for (FW_CInterest* j = (FW_CInterest *) ite2.First();
  121.                  ite2.IsNotComplete(); j = (FW_CInterest *) ite2.Next())
  122.     {
  123.         fInterestList.Remove(j);
  124.         if (IsConnected())
  125.             j->GetNotifier()->RemoveConnection(*this, *j);
  126.     }
  127.     
  128.     
  129.     // ----- delete from temp
  130.     FW_CInterest* anInterest;
  131.     while ((anInterest = (FW_CInterest*)temp.First()) != NULL)
  132.     {
  133.         temp.Remove(anInterest);
  134.         delete anInterest;
  135.     }        
  136. }
  137.     
  138. //----------------------------------------------------------------------------------------
  139. // FW_CHandleFunctionConnection::Notify
  140. //----------------------------------------------------------------------------------------
  141.  
  142. void FW_CHandleFunctionConnection::Notify
  143.     (const FW_CNotification& notification, const FW_CInterest& interest)
  144. {
  145.     FW_COrderedCollectionIterator ite(&fInterestList);
  146.     for (FW_CInterest* i = (FW_CInterest *) ite.First();
  147.                  ite.IsNotComplete(); i = (FW_CInterest *) ite.Next())
  148.     {
  149.         if (*i == interest)
  150.         {
  151.             FW_MReceiver *receiver = GetReceiver();
  152.             receiver->HandleNotification(notification);
  153.         }
  154.     }
  155. }
  156.                                
  157. //----------------------------------------------------------------------------------------
  158. // FW_CHandleFunctionConnection::Connect
  159. //----------------------------------------------------------------------------------------
  160.  
  161. void FW_CHandleFunctionConnection::Connect()
  162. {
  163.     if (!IsConnected())
  164.     {
  165.         FW_COrderedCollectionIterator ite(&fInterestList);
  166.         for (FW_CInterest* i = (FW_CInterest *) ite.First();
  167.                  ite.IsNotComplete(); i = (FW_CInterest *) ite.Next())
  168.         {
  169.             i->GetNotifier()->AddConnection(this, i);
  170.         }
  171.     }
  172.     
  173.     FW_CConnection::Connect();
  174. }
  175.                                
  176. //----------------------------------------------------------------------------------------
  177. // FW_CHandleFunctionConnection::Disconnect
  178. //----------------------------------------------------------------------------------------
  179.  
  180. void FW_CHandleFunctionConnection::Disconnect()
  181. {
  182.     if (IsConnected())
  183.     {
  184.         FW_COrderedCollectionIterator ite(&fInterestList);
  185.         for (FW_CInterest* i = (FW_CInterest *) ite.First();
  186.                  ite.IsNotComplete(); i = (FW_CInterest *) ite.Next())
  187.         {
  188.             i->GetNotifier()->RemoveConnection(*this, *i);
  189.         }
  190.     }
  191.     
  192.     FW_CConnection::Disconnect();
  193. }
  194.