plugins/consoles/vt100cons/src/vt100/vtc_controller.cpp
changeset 83 706c7a69e448
parent 0 7f656887cf89
equal deleted inserted replaced
82:a6fec624de6c 83:706c7a69e448
   648 	iClientRequestStatus = &aStatus;
   648 	iClientRequestStatus = &aStatus;
   649 	*iClientRequestStatus = KRequestPending;
   649 	*iClientRequestStatus = KRequestPending;
   650 	if (iKeyCodePending)
   650 	if (iKeyCodePending)
   651 		{
   651 		{
   652 		iKeyCodePending = EFalse;
   652 		iKeyCodePending = EFalse;
   653 		CompleteKeyPressRequest(iPendingKeyCode);
   653 		CompleteReadRequest(iPendingKeyCode);
   654 		}
   654 		}
   655 	else if (iInputError)
   655 	else if (iInputError)
   656 		{
   656 		{
   657 		CompleteKeyPressRequest(iInputError);
   657 		CompleteReadRequest(iInputError);
   658 		iInputError = KErrNone;
   658 		iInputError = KErrNone;
   659 		}
   659 		}
   660 	else
   660 	else
   661 		{
   661 		{
   662 		ReadKeyPress();
   662 		ProcessInputBuffer();
   663 		}
   663 		}
   664 	}
   664 	}
   665 
   665 
   666 EXPORT_C void CVtConsoleInputController::CancelGetKeyPress()
   666 EXPORT_C void CVtConsoleInputController::CancelGetKeyPress()
   667 	{
   667 	{
   668 	Cancel();
   668 	Cancel();
   669 	if (iClientRequestStatus)
   669 	if (iClientRequestStatus)
   670 		{
   670 		{
   671 		CompleteKeyPressRequest(KErrCancel);
   671 		CompleteReadRequest(KErrCancel);
   672 		}
   672 		}
   673 	}
   673 	}
   674 
   674 
   675 EXPORT_C void CVtConsoleInputController::SetMode(ConsoleMode::TMode aMode)
   675 EXPORT_C void CVtConsoleInputController::SetMode(ConsoleMode::TMode aMode)
   676 	{
   676 	{
   677 	Reset();
   677 	Reset();
   678 	iMode = aMode;
   678 	iMode = aMode;
   679 	}
   679 	}
   680 
   680 
   681 void CVtConsoleInputController::ReadKeyPress()
   681 void CVtConsoleInputController::ProcessInputBuffer()
   682 	{
   682 	{
   683 	iEscapeTimer->Cancel();
   683 	iEscapeTimer->Cancel();
   684 
   684 
   685 	while (iClientRequestStatus && (iBufPos < iBuf.Length()))
   685 	while (iClientRequestStatus && (iBufPos < iBuf.Length()))
   686 		{
   686 		{
   687 		TUint8 c = iBuf[iBufPos++];
   687 		TUint8 c = iBuf[iBufPos++];
   688 		if (iMode == ConsoleMode::EBinary)
   688 		if (iMode == ConsoleMode::EBinary)
   689 			{
   689 			{
   690 			CompleteKeyPressRequest((TKeyCode)c);
   690 			CompleteReadRequest((TKeyCode)c);
   691 			}
   691 			}
   692 		else
   692 		else
   693 			{
   693 			{
   694 			switch (iState)
   694 			switch (iState)
   695 				{
   695 				{
   702 						iEscapeTimer->Start(KEscapeTimeoutMicros, KEscapeTimeoutMicros, TCallBack(EscapeTimeoutS, this));
   702 						iEscapeTimer->Start(KEscapeTimeoutMicros, KEscapeTimeoutMicros, TCallBack(EscapeTimeoutS, this));
   703 						}
   703 						}
   704 					}
   704 					}
   705 				else
   705 				else
   706 					{
   706 					{
   707 					CompleteKeyPressRequest((TKeyCode)c);
   707 					CompleteReadRequest((TKeyCode)c);
   708 					}
   708 					}
   709 				break;
   709 				break;
   710 			case EWaitingForEscapeChar2:
   710 			case EWaitingForEscapeChar2:
   711 				if (c == KEscapeChar2)
   711 				if (c == KEscapeChar2)
   712 					{
   712 					{
   716 					{
   716 					{
   717 					iState = EWaitingForEscapeChar3Func;
   717 					iState = EWaitingForEscapeChar3Func;
   718 					}
   718 					}
   719 				else
   719 				else
   720 					{
   720 					{
   721 					CompleteKeyPressRequest(EKeyEscape, (TKeyCode)c);
   721 					CompleteReadRequest(EKeyEscape, (TKeyCode)c);
   722 					iState = ENormal;
   722 					iState = ENormal;
   723 					}
   723 					}
   724 				break;
   724 				break;
   725 			case EWaitingForEscapeChar3:
   725 			case EWaitingForEscapeChar3:
   726 				if (c >= '0' && c <= '9')
   726 				if (c >= '0' && c <= '9')
   749 					}
   749 					}
   750 				else
   750 				else
   751 					{
   751 					{
   752 					// Gone off the rails, bail
   752 					// Gone off the rails, bail
   753 					iState = ENormal;
   753 					iState = ENormal;
   754 					CompleteKeyPressRequest((TKeyCode)c);
   754 					CompleteReadRequest((TKeyCode)c);
   755 					}
   755 					}
   756 				break;
   756 				break;
   757 				}
   757 				}
   758 			}
   758 			}
   759 		}
   759 		}
   760 
   760 
   761 	ReadInput();
   761 	RequestInput();
   762 	}
   762 	}
   763 
   763 
   764 void CVtConsoleInputController::CompleteKeyPressRequest(TInt aError)
   764 void CVtConsoleInputController::CompleteReadRequest(TInt aError)
   765 	{
   765 	{
   766 	ASSERT(iClientKeyPress && iClientRequestStatus);
   766 	ASSERT(iClientKeyPress && iClientRequestStatus);
   767 	iClientKeyPress = NULL;
   767 	iClientKeyPress = NULL;
   768 	User::RequestComplete(iClientRequestStatus, aError);
   768 	User::RequestComplete(iClientRequestStatus, aError);
   769 	}
   769 	}
   770 
   770 
   771 void CVtConsoleInputController::CompleteKeyPressRequest(TKeyCode aKeyCode)
   771 void CVtConsoleInputController::CompleteReadRequest(TKeyCode aKeyCode)
   772 	{
   772 	{
   773 	ASSERT(iClientKeyPress && iClientRequestStatus);
   773 	ASSERT(iClientKeyPress && iClientRequestStatus);
   774 	iClientKeyPress->iCode = (TKeyCode)aKeyCode;
   774 	iClientKeyPress->iCode = (TKeyCode)aKeyCode;
   775 	iClientKeyPress->iModifiers = 0;
   775 	iClientKeyPress->iModifiers = 0;
   776 	iClientKeyPress = NULL;
   776 	iClientKeyPress = NULL;
   777 	User::RequestComplete(iClientRequestStatus, KErrNone);
   777 	User::RequestComplete(iClientRequestStatus, KErrNone);
   778 	}
   778 	}
   779 
   779 
   780 void CVtConsoleInputController::CompleteKeyPressRequest(TKeyCode aKeyCode1, TKeyCode aKeyCode2)
   780 void CVtConsoleInputController::CompleteReadRequest(TKeyCode aKeyCode1, TKeyCode aKeyCode2)
   781 	{
   781 	{
   782 	ASSERT(!iKeyCodePending);
   782 	ASSERT(!iKeyCodePending);
   783 	// Store the second key-code in a member variable to be used the next time GetKeyPress is called.
   783 	// Store the second key-code in a member variable to be used the next time GetKeyPress is called.
   784 	iKeyCodePending = ETrue;
   784 	iKeyCodePending = ETrue;
   785 	iPendingKeyCode = aKeyCode2;
   785 	iPendingKeyCode = aKeyCode2;
   786 	CompleteKeyPressRequest(aKeyCode1);
   786 	CompleteReadRequest(aKeyCode1);
   787 	}
   787 	}
   788 
   788 
   789 void CVtConsoleInputController::Reset()
   789 void CVtConsoleInputController::Reset()
   790 	{
   790 	{
   791 	Cancel();
   791 	Cancel();
   792 	iEscapeTimer->Cancel();
   792 	iEscapeTimer->Cancel();
   793 	iState = ENormal;
   793 	iState = ENormal;
   794 	iKeyCodePending = EFalse;
   794 	iKeyCodePending = EFalse;
   795 	}
   795 	}
   796 
   796 
   797 void CVtConsoleInputController::ReadInput()
   797 void CVtConsoleInputController::RequestInput()
   798 	{
   798 	{
   799 	if (iClientRequestStatus && !IsActive()) // Note, if the escape timer expired we could already be active.
   799 	if (iClientRequestStatus && !IsActive()) // Note, if the escape timer expired we could already be active.
   800 		{
   800 		{
   801 		ASSERT(iBufPos == iBuf.Length());
   801 		ASSERT(iBufPos == iBuf.Length());
   802 		iBufPos = 0;
   802 		iBufPos = 0;
   810 	{
   810 	{
   811 	TInt err = iStatus.Int();
   811 	TInt err = iStatus.Int();
   812 #ifdef FSHELL_PLATFORM_OPP
   812 #ifdef FSHELL_PLATFORM_OPP
   813 	if (err == KErrAbort)
   813 	if (err == KErrAbort)
   814 		{
   814 		{
   815 		ReadInput();
   815 		RequestInput();
   816 		return;
   816 		return;
   817 		}
   817 		}
   818 #endif
   818 #endif
   819 	if (err == KErrNone)
   819 	if (err == KErrNone)
   820 		{
   820 		{
   821 		ReadKeyPress();
   821 		ProcessInputBuffer();
   822 		}
   822 		}
   823 	else if (iClientRequestStatus)
   823 	else if (iClientRequestStatus)
   824 		{
   824 		{
   825 		CompleteKeyPressRequest(err);
   825 		CompleteReadRequest(err);
   826 		}
   826 		}
   827 	else
   827 	else
   828 		{
   828 		{
   829 		// Report the error next time the client requests a key.
   829 		// Report the error next time the client requests a key.
   830 		iInputError = err;
   830 		iInputError = err;
   841 	iState = ENormal;
   841 	iState = ENormal;
   842 	for (TInt j = 0; j < aMappingCount; ++j)
   842 	for (TInt j = 0; j < aMappingCount; ++j)
   843 		{
   843 		{
   844 		if (aChar == aMappings[j].iEscapeChar)
   844 		if (aChar == aMappings[j].iEscapeChar)
   845 			{
   845 			{
   846 			CompleteKeyPressRequest(aMappings[j].iKeyCode);
   846 			CompleteReadRequest(aMappings[j].iKeyCode);
   847 			return;
   847 			return;
   848 			}
   848 			}
   849 		}
   849 		}
   850 	}
   850 	}
   851 	
   851 	
   852 TInt CVtConsoleInputController::EscapeTimeout()
   852 TInt CVtConsoleInputController::EscapeTimeout()
   853 	{
   853 	{
   854 	ASSERT(iState == EWaitingForEscapeChar2);
   854 	ASSERT(iState == EWaitingForEscapeChar2);
   855 	iState = ENormal;
   855 	iState = ENormal;
   856 	CompleteKeyPressRequest(EKeyEscape);
   856 	CompleteReadRequest(EKeyEscape);
   857 	return KErrNone;
   857 	return KErrNone;
   858 	}
   858 	}
   859 
   859 
   860 TInt CVtConsoleInputController::EscapeTimeoutS(TAny* aSelf)
   860 TInt CVtConsoleInputController::EscapeTimeoutS(TAny* aSelf)
   861 	{
   861 	{
   874 	for (TInt j = 0; j < KNumExtendedEscapeMappings; ++j)
   874 	for (TInt j = 0; j < KNumExtendedEscapeMappings; ++j)
   875 		{
   875 		{
   876 		const TLongerEscapeMapping& mapping = KExtendedEscapeMappings[j];
   876 		const TLongerEscapeMapping& mapping = KExtendedEscapeMappings[j];
   877 		if (escape1 == mapping.iEscapeChar1 && escape2 == mapping.iEscapeChar2)
   877 		if (escape1 == mapping.iEscapeChar1 && escape2 == mapping.iEscapeChar2)
   878 			{
   878 			{
   879 			CompleteKeyPressRequest(mapping.iKeyCode);
   879 			CompleteReadRequest(mapping.iKeyCode);
   880 			return;
   880 			return;
   881 			}
   881 			}
   882 		}
   882 		}
   883 	}
   883 	}