Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
•OT_Classes/TNetworkEventHandler.cp
// TNetworkEventHandler.cp - Macintosh OpenTransport network class object |
// |
// Apple Macintosh Developer Technical Support |
// Written by: Vinne Moscaritolo |
// |
// Copyright (work in progress) Apple Computer, Inc All rights reserved. |
// |
// You may incorporate this sample code into your applications without |
// restriction, though the sample code has been provided "AS IS" and the |
// responsibility for its operation is 100% yours. However, what you are |
// not permitted to do is to redistribute the source as "DSC Sample Code" |
// after having made changes. If you're going to re-distribute the source, |
// we require that you make it clear in the source that the code was |
// descended from Apple Sample Code, but that you've made changes. |
// |
#include "TNetworkEventHandler.h" |
// --------------------------------------------------------------------------- |
// TNetworkEventHandler::fgActiveList |
// --------------------------------------------------------------------------- |
// List of active TNetworkEventHandler objects |
// |
TList TNetworkEventHandler::fgActiveList; |
// --------------------------------------------------------------------------- |
// TNetworkEventHandler |
// --------------------------------------------------------------------------- |
// Default Constructor |
TNetworkEventHandler::TNetworkEventHandler() |
{ |
// add this to the end list of network event handlers |
fgActiveList.Append(this); |
} |
// --------------------------------------------------------------------------- |
// ~TNetworkEventHandler |
// --------------------------------------------------------------------------- |
// Destructor |
TNetworkEventHandler::~TNetworkEventHandler() |
{ |
TNetworkEvent* aEvent; |
// dispose of any outstanding events.. |
while( aEvent = (TNetworkEvent*) fEventQueue.Dequeue() ) |
delete aEvent; |
// remove this from list of network event handlers |
fgActiveList.Remove(this); |
}; |
// --------------------------------------------------------------------------- |
// TNetworkEventHandler::ProcessAnEvent |
// --------------------------------------------------------------------------- |
// Process Network Event for this handler |
void TNetworkEventHandler::ProcessEvents() |
{ |
TNetworkEvent* aEvent; |
TLifo eventList; |
if(! fEventQueue.IsEmpty()){ |
// get head of event list |
eventList.fHead = fEventQueue.StealList(); |
eventList.Reverse(); |
// Process each event on list |
while( aEvent = (TNetworkEvent*) eventList.Dequeue() ) |
{ |
HandleEvent(aEvent); |
delete aEvent; |
} |
} |
} |
// --------------------------------------------------------------------------- |
// TNetworkEventHandler::ScanEventHandlerQueue |
// --------------------------------------------------------------------------- |
// Scan Network Event list looking for things to do |
void TNetworkEventHandler::ScanEventHandlerQueue() |
{ |
TNetworkEventHandler *aTask; |
for (aTask = (TNetworkEventHandler*) fgActiveList.GetFirst(); |
aTask ; |
aTask = (TNetworkEventHandler*) aTask->Next()) |
{ |
aTask->ProcessEvents(); |
} |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14