diff -r 000000000000 -r 7f656887cf89 plugins/networking/winsockprt/src/wsp_scheduler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/networking/winsockprt/src/wsp_scheduler.cpp Wed Jun 23 15:52:26 2010 +0100 @@ -0,0 +1,100 @@ +// wsp_scheduler.cpp +// +// Copyright (c) 2002 - 2010 Accenture. All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Accenture - Initial contribution +// + + +#include "wsp_scheduler.h" +#include "wsp_panic.h" +#include +#include + +CWin32Scheduler* CWin32Scheduler::NewL() + { + return new(ELeave) CWin32Scheduler(); + } + +CWin32Scheduler::~CWin32Scheduler() + { + __ASSERT_DEBUG(iActiveQue.IsEmpty(), Panic(EWinSockPrtActiveQueueNotEmpty)); + } + +void CWin32Scheduler::Add(CWin32ActiveObject& aActiveObject) + { + iActiveQue.AddLast(aActiveObject); + RebuildEventList(); + } + +void CWin32Scheduler::Remove(CWin32ActiveObject& aActiveObject) + { + iActiveQue.Remove(aActiveObject); + RebuildEventList(); + } + +TBool CWin32Scheduler::IsPresent(CWin32ActiveObject& aActiveObject) const + { + TSglQueIter iterator(const_cast(this)->iActiveQue); + iterator.SetToFirst(); + CWin32ActiveObject* thisActiveObject = NULL; + while ((thisActiveObject = iterator++) != NULL) + { + if (thisActiveObject == &aActiveObject) + { + return ETrue; + } + } + return EFalse; + } + +void CWin32Scheduler::Start() + { + while (!iStopping) + { + Emulator::Escape(); + DWORD ret = WaitForMultipleObjectsEx(iNumEvents, iEventList, FALSE, INFINITE, TRUE); + Emulator::Reenter(); + if ((ret >= WAIT_OBJECT_0) && (ret < (WAIT_OBJECT_0 + iNumEvents))) + { + iActiveObjectList[ret - WAIT_OBJECT_0]->Run(); + } + else if (ret == WAIT_IO_COMPLETION) + { + // TODO: Safe to ignore? + } + else + { + __ASSERT_DEBUG(EFalse, Panic(EWinSockPrtUnexpectedWaitError)); + } + } + } + +void CWin32Scheduler::Stop() + { + iStopping = ETrue; + } + +CWin32Scheduler::CWin32Scheduler() + : iActiveQue(_FOFF(CWin32ActiveObject, iLink)) + { + } + +void CWin32Scheduler::RebuildEventList() + { + iNumEvents = 0; + TSglQueIter iterator(iActiveQue); + iterator.SetToFirst(); + CWin32ActiveObject* thisActiveObject = NULL; + while ((thisActiveObject = iterator++) != NULL) + { + iActiveObjectList[iNumEvents] = thisActiveObject; + iEventList[iNumEvents++] = thisActiveObject->iEvent; + __ASSERT_DEBUG(iNumEvents <= MAXIMUM_WAIT_OBJECTS, Panic(EWinSockPrtTooManyWaitObjects)); + } + } \ No newline at end of file