home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.1 KB | 175 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWNotifr.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWNOTIFR_H
- #include "FWNotifr.h"
- #endif
-
- #ifndef FWCONNEC_H
- #include "FWConnec.h"
- #endif
-
- #ifndef FWNOTIFN_H
- #include "FWNotifn.h"
- #endif
-
- #ifndef FWINTERE_H
- #include "FWIntere.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // CLASS FW_CPrivInterestConnectionPair
- //========================================================================================
-
- FW_CPrivInterestConnectionPair::FW_CPrivInterestConnectionPair() :
- fInterest(),
- fConnection(NULL)
- {
- }
-
- FW_CPrivInterestConnectionPair::FW_CPrivInterestConnectionPair
- (const FW_CPrivInterestConnectionPair& other) :
- fInterest(other.fInterest),
- fConnection(other.fConnection)
- {
- }
-
- FW_CPrivInterestConnectionPair::FW_CPrivInterestConnectionPair
- (FW_CConnection* connection,
- const FW_CInterest* interest) :
- fInterest(interest),
- fConnection(connection)
- {
- }
-
- FW_CPrivInterestConnectionPair::~FW_CPrivInterestConnectionPair()
- {
- }
-
- FW_Boolean FW_CPrivInterestConnectionPair::operator==
- (const FW_CPrivInterestConnectionPair& other) const
- {
- return *fInterest == *other.fInterest && fConnection == other.fConnection;
- }
-
- FW_Boolean FW_CPrivInterestConnectionPair::operator!=
- (const FW_CPrivInterestConnectionPair& other) const
- {
- return !(*this == other);
- }
-
- FW_CPrivInterestConnectionPair& FW_CPrivInterestConnectionPair::operator=
- (const FW_CPrivInterestConnectionPair& other)
- {
- fInterest = other.fInterest;
- fConnection = other.fConnection;
- return *this;
- }
-
- //========================================================================================
- // CLASS FW_MNotifier
- //========================================================================================
-
- FW_DEFINE_CLASS_M0(FW_MNotifier)
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::~FW_MNotifier
- //----------------------------------------------------------------------------------------
-
- FW_MNotifier::~FW_MNotifier()
- {
- #if 0
- // [LSD] this code doesn't work, interest contains garbage
- //
- FW_CInterest* interest;
- while ((interest = (FW_CInterest*)fInterestList.First()) != NULL)
- {
- fInterestList.Remove(interest);
- delete interest;
- }
- #endif
-
- fInterestList.RemoveAll(); // [LSD] do we need to delete interest too?
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::Notify
- //----------------------------------------------------------------------------------------
-
- void FW_MNotifier::Notify(const FW_CNotification ¬ification)
- {
- FW_COrderedCollectionIterator ite(&fInterestList);
- for (FW_CPrivInterestConnectionPair* pair = (FW_CPrivInterestConnectionPair*)ite.First();
- ite.IsNotComplete(); pair = (FW_CPrivInterestConnectionPair*)ite.Next())
- {
- if (*pair->GetInterest() == *notification.GetInterest())
- pair->GetConnection()->Notify(notification, *notification.GetInterest());
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::AddConnection
- //----------------------------------------------------------------------------------------
-
- void FW_MNotifier::AddConnection(FW_CConnection* connection,
- const FW_CInterest* interest)
- {
- FW_CPrivInterestConnectionPair* pair = new FW_CPrivInterestConnectionPair(connection, interest);
- fInterestList.AddLast(pair);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::RemoveConnection
- //----------------------------------------------------------------------------------------
-
- void FW_MNotifier::RemoveConnection(const FW_CConnection& connection,
- const FW_CInterest& interest)
- {
- FW_CPrivInterestConnectionPair* pair;
- FW_CPrivOrderedCollection temp;
- FW_COrderedCollectionIterator ite1(&fInterestList);
- for (pair = (FW_CPrivInterestConnectionPair*)ite1.First();
- ite1.IsNotComplete(); pair = (FW_CPrivInterestConnectionPair*)ite1.Next())
- {
- if (*pair->GetInterest() == interest && pair->GetConnection() == &connection)
- temp.AddLast(pair);
- }
-
- FW_COrderedCollectionIterator ite2(&temp);
- for (pair = (FW_CPrivInterestConnectionPair*)ite2.First();
- ite2.IsNotComplete(); pair = (FW_CPrivInterestConnectionPair*)ite2.Next())
- {
- fInterestList.Remove(pair);
- }
-
- // ----- delete from temp
- FW_CPrivInterestConnectionPair* aPair;
- while ((aPair = (FW_CPrivInterestConnectionPair*)temp.First()) != NULL)
- {
- temp.Remove(aPair);
- delete aPair;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::FW_MNotifier
- //----------------------------------------------------------------------------------------
-
- FW_MNotifier::FW_MNotifier() :
- fInterestList()
- {
- }
-
-