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 / FWNotifr.cpp < prev   
Encoding:
Text File  |  1995-11-08  |  5.1 KB  |  175 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWNotifr.cpp
  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 FWNOTIFR_H
  13. #include "FWNotifr.h"
  14. #endif
  15.  
  16. #ifndef FWCONNEC_H
  17. #include "FWConnec.h"
  18. #endif
  19.  
  20. #ifndef FWNOTIFN_H
  21. #include "FWNotifn.h"
  22. #endif
  23.  
  24. #ifndef FWINTERE_H
  25. #include "FWIntere.h"
  26. #endif
  27.  
  28. #if FW_LIB_EXPORT_PRAGMAS
  29. #pragma lib_export on
  30. #endif
  31.  
  32. //========================================================================================
  33. // CLASS FW_CPrivInterestConnectionPair
  34. //========================================================================================
  35.  
  36. FW_CPrivInterestConnectionPair::FW_CPrivInterestConnectionPair() :
  37.     fInterest(),
  38.     fConnection(NULL)
  39. {
  40. }
  41.  
  42. FW_CPrivInterestConnectionPair::FW_CPrivInterestConnectionPair
  43.                                         (const FW_CPrivInterestConnectionPair& other) :
  44.     fInterest(other.fInterest),
  45.     fConnection(other.fConnection)
  46. {
  47. }
  48.  
  49. FW_CPrivInterestConnectionPair::FW_CPrivInterestConnectionPair
  50.                                         (FW_CConnection* connection,
  51.                                          const FW_CInterest* interest) :
  52.     fInterest(interest),
  53.     fConnection(connection)
  54. {
  55. }
  56.  
  57. FW_CPrivInterestConnectionPair::~FW_CPrivInterestConnectionPair()
  58. {
  59. }
  60.  
  61. FW_Boolean FW_CPrivInterestConnectionPair::operator==
  62.                                     (const FW_CPrivInterestConnectionPair& other) const
  63. {
  64.     return *fInterest == *other.fInterest && fConnection == other.fConnection;
  65. }
  66.  
  67. FW_Boolean FW_CPrivInterestConnectionPair::operator!=
  68.                                     (const FW_CPrivInterestConnectionPair& other) const
  69. {
  70.     return !(*this == other);
  71. }
  72.  
  73. FW_CPrivInterestConnectionPair& FW_CPrivInterestConnectionPair::operator=
  74.                                     (const FW_CPrivInterestConnectionPair& other)
  75. {
  76.     fInterest = other.fInterest;
  77.     fConnection = other.fConnection;
  78.     return *this;
  79. }
  80.  
  81. //========================================================================================
  82. // CLASS FW_MNotifier
  83. //========================================================================================
  84.  
  85. FW_DEFINE_CLASS_M0(FW_MNotifier)
  86.  
  87. //----------------------------------------------------------------------------------------
  88. // FW_MNotifier::~FW_MNotifier
  89. //----------------------------------------------------------------------------------------
  90.  
  91. FW_MNotifier::~FW_MNotifier()
  92. {
  93. #if 0
  94.     // [LSD] this code doesn't work, interest contains garbage
  95.     // 
  96.     FW_CInterest* interest;
  97.     while ((interest = (FW_CInterest*)fInterestList.First()) != NULL)
  98.     {
  99.         fInterestList.Remove(interest);
  100.         delete interest;
  101.     }        
  102. #endif
  103.  
  104.     fInterestList.RemoveAll();    // [LSD] do we need to delete interest too?
  105. }
  106.     
  107. //----------------------------------------------------------------------------------------
  108. // FW_MNotifier::Notify
  109. //----------------------------------------------------------------------------------------
  110.  
  111. void FW_MNotifier::Notify(const FW_CNotification ¬ification)
  112. {
  113.     FW_COrderedCollectionIterator ite(&fInterestList);
  114.     for (FW_CPrivInterestConnectionPair* pair = (FW_CPrivInterestConnectionPair*)ite.First();
  115.              ite.IsNotComplete(); pair = (FW_CPrivInterestConnectionPair*)ite.Next())
  116.     {
  117.         if (*pair->GetInterest() == *notification.GetInterest())
  118.             pair->GetConnection()->Notify(notification, *notification.GetInterest());
  119.     }
  120. }
  121.     
  122. //----------------------------------------------------------------------------------------
  123. // FW_MNotifier::AddConnection
  124. //----------------------------------------------------------------------------------------
  125.  
  126. void FW_MNotifier::AddConnection(FW_CConnection* connection,
  127.                                  const FW_CInterest* interest)
  128. {
  129.     FW_CPrivInterestConnectionPair* pair = new FW_CPrivInterestConnectionPair(connection, interest);
  130.     fInterestList.AddLast(pair);
  131. }
  132.  
  133. //----------------------------------------------------------------------------------------
  134. // FW_MNotifier::RemoveConnection
  135. //----------------------------------------------------------------------------------------
  136.  
  137. void FW_MNotifier::RemoveConnection(const FW_CConnection& connection,
  138.                                      const FW_CInterest& interest)
  139. {
  140.     FW_CPrivInterestConnectionPair* pair;
  141.     FW_CPrivOrderedCollection temp;
  142.     FW_COrderedCollectionIterator ite1(&fInterestList);
  143.     for (pair = (FW_CPrivInterestConnectionPair*)ite1.First();
  144.              ite1.IsNotComplete(); pair = (FW_CPrivInterestConnectionPair*)ite1.Next())
  145.     {
  146.         if (*pair->GetInterest() == interest && pair->GetConnection() == &connection)
  147.             temp.AddLast(pair);        
  148.     }
  149.  
  150.     FW_COrderedCollectionIterator ite2(&temp);
  151.     for (pair = (FW_CPrivInterestConnectionPair*)ite2.First();
  152.              ite2.IsNotComplete(); pair = (FW_CPrivInterestConnectionPair*)ite2.Next())
  153.     {
  154.         fInterestList.Remove(pair);
  155.     }
  156.     
  157.     // ----- delete from temp
  158.     FW_CPrivInterestConnectionPair* aPair;
  159.     while ((aPair = (FW_CPrivInterestConnectionPair*)temp.First()) != NULL)
  160.     {
  161.         temp.Remove(aPair);
  162.         delete aPair;
  163.     }        
  164. }
  165.     
  166. //----------------------------------------------------------------------------------------
  167. // FW_MNotifier::FW_MNotifier
  168. //----------------------------------------------------------------------------------------
  169.  
  170. FW_MNotifier::FW_MNotifier() :
  171.     fInterestList()
  172. {
  173. }
  174.  
  175.