home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 6.0 KB | 194 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWHFConn.tpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWHFCONN_H
- #include "FWHFConn.h"
- #endif
-
- #ifndef FWNOTIFR_H
- #include "FWNotifr.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // CLASS FW_MReceiver
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_MReceiver::FW_MReceiver
- //----------------------------------------------------------------------------------------
-
- FW_MReceiver::FW_MReceiver()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MReceiver::~FW_MReceiver
- //----------------------------------------------------------------------------------------
-
- FW_MReceiver::~FW_MReceiver()
- {
- }
-
- //========================================================================================
- // CLASS FW_CHandleFunctionConnection
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CHandleFunctionConnection::FW_CHandleFunctionConnection
- //----------------------------------------------------------------------------------------
-
- FW_CHandleFunctionConnection::FW_CHandleFunctionConnection(FW_MReceiver* receiver) :
- fReceiver(receiver),
- fInterestList()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CHandleFunctionConnection::~FW_CHandleFunctionConnection
- //----------------------------------------------------------------------------------------
-
- FW_CHandleFunctionConnection::~FW_CHandleFunctionConnection()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CHandleFunctionConnection::AddInterest
- //----------------------------------------------------------------------------------------
-
- void FW_CHandleFunctionConnection::AddInterest(const FW_CInterest& interest)
- {
- FW_CInterest* interestCopy = new FW_CInterest(interest);
-
- if (IsConnected())
- interestCopy->GetNotifier()->AddConnection(this, interestCopy);
-
- fInterestList.AddLast(interestCopy);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CHandleFunctionConnection::RemoveAllInterests
- //----------------------------------------------------------------------------------------
-
- void FW_CHandleFunctionConnection::RemoveAllInterests()
- {
- if (IsConnected())
- {
- FW_COrderedCollectionIterator ite(&fInterestList);
- for (FW_CInterest* interest = (FW_CInterest *) ite.First();
- ite.IsNotComplete(); interest = (FW_CInterest *) ite.Next())
- {
- interest->GetNotifier()->RemoveConnection(*this, *interest);
- }
- }
-
- FW_CInterest* interest;
- while ((interest = (FW_CInterest*)fInterestList.First()) != NULL)
- {
- fInterestList.Remove(interest);
- delete interest;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CHandleFunctionConnection::RemoveInterest
- //----------------------------------------------------------------------------------------
-
- void FW_CHandleFunctionConnection::RemoveInterest(const FW_CInterest& interest)
- {
- FW_CPrivOrderedCollection temp;
- FW_COrderedCollectionIterator ite1(&fInterestList);
- for (FW_CInterest* i = (FW_CInterest *) ite1.First();
- ite1.IsNotComplete(); i = (FW_CInterest *) ite1.Next())
- {
- if (*i == interest)
- temp.AddLast(i);
- }
-
- FW_COrderedCollectionIterator ite2(&temp);
- for (FW_CInterest* j = (FW_CInterest *) ite2.First();
- ite2.IsNotComplete(); j = (FW_CInterest *) ite2.Next())
- {
- fInterestList.Remove(j);
- if (IsConnected())
- j->GetNotifier()->RemoveConnection(*this, *j);
- }
-
-
- // ----- delete from temp
- FW_CInterest* anInterest;
- while ((anInterest = (FW_CInterest*)temp.First()) != NULL)
- {
- temp.Remove(anInterest);
- delete anInterest;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CHandleFunctionConnection::Notify
- //----------------------------------------------------------------------------------------
-
- void FW_CHandleFunctionConnection::Notify
- (const FW_CNotification& notification, const FW_CInterest& interest)
- {
- FW_COrderedCollectionIterator ite(&fInterestList);
- for (FW_CInterest* i = (FW_CInterest *) ite.First();
- ite.IsNotComplete(); i = (FW_CInterest *) ite.Next())
- {
- if (*i == interest)
- {
- FW_MReceiver *receiver = GetReceiver();
- receiver->HandleNotification(notification);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CHandleFunctionConnection::Connect
- //----------------------------------------------------------------------------------------
-
- void FW_CHandleFunctionConnection::Connect()
- {
- if (!IsConnected())
- {
- FW_COrderedCollectionIterator ite(&fInterestList);
- for (FW_CInterest* i = (FW_CInterest *) ite.First();
- ite.IsNotComplete(); i = (FW_CInterest *) ite.Next())
- {
- i->GetNotifier()->AddConnection(this, i);
- }
- }
-
- FW_CConnection::Connect();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CHandleFunctionConnection::Disconnect
- //----------------------------------------------------------------------------------------
-
- void FW_CHandleFunctionConnection::Disconnect()
- {
- if (IsConnected())
- {
- FW_COrderedCollectionIterator ite(&fInterestList);
- for (FW_CInterest* i = (FW_CInterest *) ite.First();
- ite.IsNotComplete(); i = (FW_CInterest *) ite.Next())
- {
- i->GetNotifier()->RemoveConnection(*this, *i);
- }
- }
-
- FW_CConnection::Disconnect();
- }
-