📄 iomain.cpp
字号:
{
TWsEvent notUsed;
const TArray<MEventSource*> emptyArray(ZeroReturner, NULL, NULL);
WaitForEvent(aCoeEnv, notUsed, EUserEventsNone, emptyArray, &aMaximumNumberOfCompletedEventsToHandle);
}
void CWsEventHandler::WaitWhileSuspended(CCoeEnv& aCoeEnv)
{
__ASSERT_DEBUG(iIsSuspended, User::Panic(KOplIOSystem, 22));
TWsEvent notUsed;
const TArray<MEventSource*> emptyArray(ZeroReturner, NULL, NULL);
WaitForEvent(aCoeEnv, notUsed, EUserEventsNone|EPriorityKeyEventsTerminatingSuspendedState, emptyArray, NULL);
__ASSERT_DEBUG(!iIsSuspended, User::Panic(KOplIOSystem, 16));
}
void CWsEventHandler::WaitForAnyOplAsynchronousRequestCompletion(CCoeEnv& aCoeEnv)
{
TWsEvent notUsed;
const TArray<MEventSource*> emptyArray(ZeroReturner, NULL, NULL);
WaitForEvent(aCoeEnv, notUsed, EUserEventsNone|EOplAsynchronousRequestCompletion, emptyArray, NULL);
}
#pragma warning (disable: 4310) // cast truncates constant
void CWsEventHandler::WaitForOplAsynchronousRequestCompletion16(CCoeEnv& aCoeEnv, TAny* aRequestStatus16)
{
TInt numberOfSignalsToReplace=0;
FOREVER
{
WaitForAnyOplAsynchronousRequestCompletion(aCoeEnv);
if (OplUtil::GetWord(aRequestStatus16)!=(TInt16)KOplErrFilePending)
{
break;
}
++numberOfSignalsToReplace;
}
Signal(numberOfSignalsToReplace);
}
#pragma warning (default: 4310)
void CWsEventHandler::WaitForOplAsynchronousRequestCompletion32(CCoeEnv& aCoeEnv, TAny* aRequestStatus32)
{
TInt numberOfSignalsToReplace=0;
FOREVER
{
WaitForAnyOplAsynchronousRequestCompletion(aCoeEnv);
if (OplUtil::GetLong(aRequestStatus32)!=KRequestPending)
{
break;
}
++numberOfSignalsToReplace;
}
Signal(numberOfSignalsToReplace);
}
void CWsEventHandler::WaitForEvent(CCoeEnv& aCoeEnv, TWsEvent& aEvent, TUserEventsRequired aUserEventsRequired)
{
__ASSERT_DEBUG(aUserEventsRequired!=EUserEventsNone, User::Panic(KOplIOSystem, 3));
const TArray<MEventSource*> emptyArray(ZeroReturner, NULL, NULL);
WaitForEvent(aCoeEnv, aEvent, aUserEventsRequired, emptyArray);
}
void CWsEventHandler::WaitForEvent(CCoeEnv& aCoeEnv, TRequestStatus& aRequestStatus, TInt aPriority)
{
TSingleEventSource singleEventSource(aRequestStatus, aPriority);
TFixedArray<MEventSource*, 1> singleEventSourceArray;
singleEventSourceArray[0]=&singleEventSource;
TWsEvent event;
WaitForEvent(aCoeEnv, event, EUserEventsNone, singleEventSourceArray.Array());
}
void CWsEventHandler::WaitForEvent(CCoeEnv& aCoeEnv, TWsEvent& aEvent, TUserEventsRequired aUserEventsRequired, const TArray<MEventSource*>& aArrayOfAdditionalEventSources)
{
WaitForEvent(aCoeEnv, aEvent, aUserEventsRequired, aArrayOfAdditionalEventSources, NULL);
}
void CWsEventHandler::WaitForEvent(CCoeEnv& aCoeEnv, TWsEvent& aEvent, TUint aEventsRequired, const TArray<MEventSource*>& aArrayOfAdditionalEventSources, const TInt* aMaximumNumberOfCompletedEventsToHandle)
// If aMaximumNumberOfCompletedEventsToHandle!=NULL, only events that have completed are to
// be handled, and only *aMaximumNumberOfCompletedEventsToHandle of them (at most) are to be
// handled. This function does not return whilst iIsSuspended is ETrue, with one exception:
// if aMaximumNumberOfCompletedEventsToHandle!=NULL.
{
__ASSERT_DEBUG(iEventQueue->BackupIsEmpty(), User::Panic(KOplIOSystem, 21));
if ((aEventsRequired&EUserEvents)==EUserEventsKeysOnly)
{
iEventQueue->PurgeAllNonKeyEvents();
}
TArrayOfAdditionalEventSources arrayOfAdditionalEventSources(aArrayOfAdditionalEventSources);
SEventHandler::SParameters eventHandlerParameters(aCoeEnv, aEvent, aEventsRequired, arrayOfAdditionalEventSources, aMaximumNumberOfCompletedEventsToHandle);
if (aMaximumNumberOfCompletedEventsToHandle!=NULL)
{
__ASSERT_DEBUG(((aEventsRequired&EUserEvents)==EUserEventsNone) && (aArrayOfAdditionalEventSources.Count()==0), User::Panic(KOplIOSystem, 9));
Signal(1); // signal a dummy event, so that we do not have to wait for non-completed
// events if aMaximumNumberOfCompletedEventsToHandle!=NULL
}
for (; !eventHandlerParameters.iDone; ++eventHandlerParameters.iNumberOfCompletedEventsHandled)
{
if ((aMaximumNumberOfCompletedEventsToHandle!=NULL) && (eventHandlerParameters.iNumberOfCompletedEventsHandled>=*aMaximumNumberOfCompletedEventsToHandle))
{
User::WaitForAnyRequest(); // returns straightaway as we're consuming the dummy signal
break;
}
User::WaitForAnyRequest();
// Set up the members of eventHandlerParameters that may change between
// iterations of the loop
eventHandlerParameters.iFep=aCoeEnv.Fep();
eventHandlerParameters.iCompletedAdditionalEventSourceWithHighestPriority=arrayOfAdditionalEventSources.CompletedAdditionalEventSourceWithHighestPriority();
eventHandlerParameters.iCompletedOplAsynchronousRequestWithHighestPriority=iIOCollection->HandleAnyCompletedOplAsynchronousRequests();
if (OfferEventToPriorityKeyHandler(eventHandlerParameters)==CCoeFep::EEventWasNotConsumed)
{
TFixedArray<SEventHandler, 4> arrayOfEventHandlers;
SetUpArrayOfEventHandlers(arrayOfEventHandlers, eventHandlerParameters.iCompletedAdditionalEventSourceWithHighestPriority, eventHandlerParameters.iCompletedOplAsynchronousRequestWithHighestPriority);
for (TInt i=0; ; ++i) // must iterate *forwards* through arrayOfEventHandlers
{
if (OfferEventToActiveScheduler(eventHandlerParameters.iFep, arrayOfEventHandlers[i].iPriority)==CCoeFep::EEventWasConsumed)
{
break; // wait for another event
}
if ((*arrayOfEventHandlers[i].iOfferEventFunction)(*this, eventHandlerParameters)==CCoeFep::EEventWasConsumed)
{
break; // wait for another event
}
}
}
iWs.Flush();
}
arrayOfAdditionalEventSources.CancelAll();
Signal(eventHandlerParameters.iNumberOfSignalsToReplace);
iEventQueue->RestoreAllEventsFromBackup();
if ((aEventsRequired&EUserEvents)==EUserEventsKeysOnly)
{
iEventQueue->PurgeAllNonKeyEvents();
}
}
CWsEventHandler::SEventHandler::SParameters::SParameters(CCoeEnv& aCoeEnv, TWsEvent& aEvent, TUint aEventsRequired, TArrayOfAdditionalEventSources& aArrayOfAdditionalEventSources, const TInt* aMaximumNumberOfCompletedEventsToHandle)
:iCoeEnv(aCoeEnv),
iDone(EFalse),
iFep(NULL),
iEvent(aEvent),
iEventsRequired(aEventsRequired),
iArrayOfAdditionalEventSources(aArrayOfAdditionalEventSources),
iMaximumNumberOfCompletedEventsToHandle(aMaximumNumberOfCompletedEventsToHandle),
iNumberOfCompletedEventsHandled(0),
iNumberOfSignalsToReplace(0),
iCompletedAdditionalEventSourceWithHighestPriority(NULL),
iCompletedOplAsynchronousRequestWithHighestPriority(NULL)
{
}
CCoeFep::TEventResponse CWsEventHandler::OfferEventToPriorityKeyHandler(SEventHandler::SParameters& aParameters)
{
if (PriorityKeyStatus()!=KRequestPending)
{
const TBool wasSuspended=iIsSuspended;
HandlePriorityKeyCompletion();
if (!iIsSuspended)
{
if (aParameters.iEventsRequired&EPriorityKeyEventsTerminatingSuspendedState)
{
__ASSERT_DEBUG(wasSuspended, User::Panic(KOplIOSystem, 17));
aParameters.iDone=ETrue;
return CCoeFep::EEventWasConsumed;
}
if (wasSuspended)
{
// Check if an additional event source completed while iIsSuspended was true
if (aParameters.iArrayOfAdditionalEventSources.AtLeastOneHasCompletedAndBeenConsumed())
{
aParameters.iDone=ETrue;
return CCoeFep::EEventWasConsumed;
}
Signal(aParameters.iNumberOfSignalsToReplace); // replace the signals of any OPL
// asynchronous requests that
// completed while iIsSuspended
// was true
aParameters.iNumberOfSignalsToReplace=0;
iEventQueue->RestoreAllEventsFromBackup();
}
}
return CCoeFep::EEventWasConsumed;
}
return CCoeFep::EEventWasNotConsumed;
}
void CWsEventHandler::SetUpArrayOfEventHandlers(TFixedArray<SEventHandler, 4>& aArrayOfEventHandlers, const MEventSource* aCompletedAdditionalEventSourceWithHighestPriority, const TIORequest* aCompletedOplAsynchronousRequestWithHighestPriority)
{
aArrayOfEventHandlers[0].iPriority=KMinTInt;
aArrayOfEventHandlers[0].iOfferEventFunction=FinalOfferEventFunction;
aArrayOfEventHandlers[1].iPriority=KMinTInt;
aArrayOfEventHandlers[1].iOfferEventFunction=FinalOfferEventFunction;
aArrayOfEventHandlers[2].iPriority=KMinTInt;
aArrayOfEventHandlers[2].iOfferEventFunction=FinalOfferEventFunction;
aArrayOfEventHandlers[3].iPriority=KMinTInt;
aArrayOfEventHandlers[3].iOfferEventFunction=FinalOfferEventFunction;
if (aCompletedAdditionalEventSourceWithHighestPriority==NULL)
{
if (aCompletedOplAsynchronousRequestWithHighestPriority==NULL)
{
aArrayOfEventHandlers[0].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[0].iOfferEventFunction=OfferEventToUserEventHandler;
}
else
{
const TInt priorityOfCompletedOplAsynchronousRequest=aCompletedOplAsynchronousRequestWithHighestPriority->Priority();
if (priorityOfCompletedOplAsynchronousRequest>EActivePriorityWsEvents)
{
aArrayOfEventHandlers[0].iPriority=priorityOfCompletedOplAsynchronousRequest;
aArrayOfEventHandlers[0].iOfferEventFunction=OfferEventToOplAsynchronousRequest;
aArrayOfEventHandlers[1].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[1].iOfferEventFunction=OfferEventToUserEventHandler;
}
else
{
aArrayOfEventHandlers[0].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[0].iOfferEventFunction=OfferEventToUserEventHandler;
aArrayOfEventHandlers[1].iPriority=priorityOfCompletedOplAsynchronousRequest;
aArrayOfEventHandlers[1].iOfferEventFunction=OfferEventToOplAsynchronousRequest;
}
}
}
else
{
if (aCompletedOplAsynchronousRequestWithHighestPriority==NULL)
{
const TInt priorityOfCompletedAdditionalEventSource=aCompletedAdditionalEventSourceWithHighestPriority->Priority();
if (priorityOfCompletedAdditionalEventSource>EActivePriorityWsEvents)
{
aArrayOfEventHandlers[0].iPriority=priorityOfCompletedAdditionalEventSource;
aArrayOfEventHandlers[0].iOfferEventFunction=OfferEventToArrayOfAdditionalEventSources;
aArrayOfEventHandlers[1].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[1].iOfferEventFunction=OfferEventToUserEventHandler;
}
else
{
aArrayOfEventHandlers[0].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[0].iOfferEventFunction=OfferEventToUserEventHandler;
aArrayOfEventHandlers[1].iPriority=priorityOfCompletedAdditionalEventSource;
aArrayOfEventHandlers[1].iOfferEventFunction=OfferEventToArrayOfAdditionalEventSources;
}
}
else
{
const TInt priorityOfCompletedAdditionalEventSource=aCompletedAdditionalEventSourceWithHighestPriority->Priority();
const TInt priorityOfCompletedOplAsynchronousRequest=aCompletedOplAsynchronousRequestWithHighestPriority->Priority();
if (priorityOfCompletedAdditionalEventSource>priorityOfCompletedOplAsynchronousRequest)
{
if (EActivePriorityWsEvents>priorityOfCompletedAdditionalEventSource)
{
aArrayOfEventHandlers[0].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[0].iOfferEventFunction=OfferEventToUserEventHandler;
aArrayOfEventHandlers[1].iPriority=priorityOfCompletedAdditionalEventSource;
aArrayOfEventHandlers[1].iOfferEventFunction=OfferEventToArrayOfAdditionalEventSources;
aArrayOfEventHandlers[2].iPriority=priorityOfCompletedOplAsynchronousRequest;
aArrayOfEventHandlers[2].iOfferEventFunction=OfferEventToOplAsynchronousRequest;
}
else
{
aArrayOfEventHandlers[0].iPriority=priorityOfCompletedAdditionalEventSource;
aArrayOfEventHandlers[0].iOfferEventFunction=OfferEventToArrayOfAdditionalEventSources;
if (priorityOfCompletedOplAsynchronousRequest>EActivePriorityWsEvents)
{
aArrayOfEventHandlers[1].iPriority=priorityOfCompletedOplAsynchronousRequest;
aArrayOfEventHandlers[1].iOfferEventFunction=OfferEventToOplAsynchronousRequest;
aArrayOfEventHandlers[2].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[2].iOfferEventFunction=OfferEventToUserEventHandler;
}
else
{
aArrayOfEventHandlers[1].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[1].iOfferEventFunction=OfferEventToUserEventHandler;
aArrayOfEventHandlers[2].iPriority=priorityOfCompletedOplAsynchronousRequest;
aArrayOfEventHandlers[2].iOfferEventFunction=OfferEventToOplAsynchronousRequest;
}
}
}
else
{
if (EActivePriorityWsEvents>priorityOfCompletedOplAsynchronousRequest)
{
aArrayOfEventHandlers[0].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[0].iOfferEventFunction=OfferEventToUserEventHandler;
aArrayOfEventHandlers[1].iPriority=priorityOfCompletedOplAsynchronousRequest;
aArrayOfEventHandlers[1].iOfferEventFunction=OfferEventToOplAsynchronousRequest;
aArrayOfEventHandlers[2].iPriority=priorityOfCompletedAdditionalEventSource;
aArrayOfEventHandlers[2].iOfferEventFunction=OfferEventToArrayOfAdditionalEventSources;
}
else
{
aArrayOfEventHandlers[0].iPriority=priorityOfCompletedOplAsynchronousRequest;
aArrayOfEventHandlers[0].iOfferEventFunction=OfferEventToOplAsynchronousRequest;
if (priorityOfCompletedAdditionalEventSource>EActivePriorityWsEvents)
{
aArrayOfEventHandlers[1].iPriority=priorityOfCompletedAdditionalEventSource;
aArrayOfEventHandlers[1].iOfferEventFunction=OfferEventToArrayOfAdditionalEventSources;
aArrayOfEventHandlers[2].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[2].iOfferEventFunction=OfferEventToUserEventHandler;
}
else
{
aArrayOfEventHandlers[1].iPriority=EActivePriorityWsEvents;
aArrayOfEventHandlers[1].iOfferEventFunction=OfferEventToUserEventHandler;
aArrayOfEventHandlers[2].iPriority=priorityOfCompletedAdditionalEventSource;
aArrayOfEventHandlers[2].iOfferEventFunction=OfferEventToArrayOfAdditionalEventSources;
}
}
}
}
}
}
CCoeFep::TEventResponse CWsEventHandler::FinalOfferEventFunction(CWsEventHandler& aThis, SEventHandler::SParameters& aParameters)
{
if (aParameters.iMaximumNumberOfCompletedEventsToHandle!=NULL)
{
aParameters.iDone=ETrue;
}
else
{
// Must corrsepond to an explicit IOSIGNAL OPL-call
if (aThis.iIsSuspended || !(aParameters.iEventsRequired&EOplAsynchronousRequestCompletion))
{
++aParameters.iNumberOfSignalsToReplace;
}
else
{
aParameters.iDone=ETrue;
}
}
return CCoeFep::EEventWasConsumed;
}
CCoeFep::TEventResponse CWsEventHandler::OfferEventToArrayOfAdditionalEventSources(CWsEventHandler& aThis, SEventHandler::SParameters& aParameters)
{
aParameters.iArrayOfAdditionalEventSources.MarkAsConsumed(aParameters.iCompletedAdditionalEventSourceWithHighestPriority);
if (!aThis.iIsSuspended)
{
aParameters.iDone=ETrue;
}
return CCoeFep::EEventWasConsumed;
}
CCoeFep::TEventResponse CWsEventHandler::OfferEventToOplAsynchronousRequest(CWsEventHandler& aThis, SEventHandler::SParameters& aParameters)
{
if (aThis.iIsSuspended || !(aParameters.iEventsRequired&EOplAsynchronousRequestCompletion))
{
++aParameters.iNumberOfSignalsToReplace;
}
else
{
aThis.iIOCollection->RemoveCompletedOplAsynchronousRequest(aParameters.iCompletedOplAsynchronousRequestWithHighestPriority);
aParameters.iDone=ETrue;
}
return CCoeFep::EEventWasConsumed;
}
CCoeFep::TEventResponse CWsEventHandler::OfferEventToUserEventHandler(CWsEventHandler& aThis, SEventHandler::SParameters& aParameters)
{
// For Crystal we need to acknowledge focus changes because application views
// get dimmed in the background. This method was altered by PhilS on
// 24/10/2001 to include the HandleSpecialWsEvent() check below to
// allow for this. Doing this check here ensures all event GET functions from
// GET to GETEVENT still get Focus gained/lost events actioned before, for example
// GET discards them (since it only stores key presses).
const TUserEventsRequired userEventsRequired=(TUserEventsRequired)(aParameters.iEventsRequired&EUserEvents);
if (aThis.iEventQueue->IsNotEmpty())
{
if (!aThis.iIsSuspended)
{
aThis.iEventQueue->PeekNextEvent(aParameters.iEvent);
if ((userEventsRequired==EUserEventsAny) ||
((userEventsRequired==EUserEventsKeysOnly) && (aParameters.iEvent.Type()==EEventKey)))
{
aThis.iEventQueue->ConsumeNextEvent();
aParameters.iDone=ETrue;
return CCoeFep::EEventWasConsumed;
}
if (aThis.EventCompletesAnyOplAsynchronousWservRequest(aParameters.iCoeEnv, aParameters.iEvent))
{
aThis.iEventQueue->ConsumeNextEvent();
if (aParameters.iEventsRequired&EOplAsynchronousRequestCompletion)
{
aParameters.iDone=ETrue;
}
return CCoeFep::EEventWasConsumed;
}
}
aThis.iEventQueue->PutNextEventInBackup();
--aParameters.iNumberOfCompletedEventsHandled; // we don't want the event queue swamping
// *aParameters.iMaximumNumberOfCompletedEventsToHandle
// (which it would do if there are
// >*aParameters.iMaximumNumberOfCompletedEventsToHandle
// events of the "wrong" type in the event
// queue). Therefore we need to decrement
// it to cancel the effect of it being
// incremented at the end of the iteration
// of the top-level loop.
return CCoeFep::EEventWasConsumed;
}
if (aThis.iStatus!=KRequestPending)
{
//!!TODOUIQ Test this additional test.
if(aThis.iStatus!=KErrCancel)
aThis.iWs.GetEvent(aParameters.iEvent);
aThis.iWs.EventReady(&aThis.iStatus);
if ((aParameters.iFep==NULL) || (aThis.OfferEventToFep(*aParameters.iFep, aParameters.iEvent)==CCoeFep::EEventWasNotConsumed))
{
if (!aThis.iIsSuspended)
{
// Here we can do checks for special events/keys, calling HandleSpecialWsEvent()
// if appropriate. Currently we check for:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -