00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 00002 // All rights reserved. 00003 // This component and the accompanying materials are made available 00004 // under the terms of "Eclipse Public License v1.0" 00005 // which accompanies this distribution, and is available 00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". 00007 // 00008 // Initial Contributors: 00009 // Nokia Corporation - initial contribution. 00010 // 00011 // Contributors: 00012 // 00013 // Description: 00014 // Contains the definition of member functions of the CUserInterface class. 00015 // 00016 00017 00018 00023 #include "userinterface.h" 00024 00032 CUserInterface* CUserInterface::NewL(CConsoleBase* aConsole,CProducer* aProducer) 00033 { 00034 CUserInterface* self = new (ELeave)CUserInterface; 00035 self->Initialize(aConsole,aProducer); 00036 return self; 00037 } 00038 00045 void CUserInterface::Initialize(CConsoleBase* aConsole,CProducer* aProducer) 00046 { 00047 iConsole = aConsole; 00048 iProducer = aProducer; 00049 CActiveScheduler::Add(this); 00050 } 00051 00055 CUserInterface::CUserInterface():CActive(CActive::EPriorityUserInput) 00056 { 00057 } 00058 00066 void CUserInterface::RunL() 00067 { 00068 // Get the key code. 00069 TUint8 option = iConsole->KeyCode(); 00070 // Print the selected option. 00071 _LIT(KTextFormat,"%c\n"); 00072 iConsole->Printf(KTextFormat,option); 00073 switch(option) 00074 { 00075 case 'p': 00076 { 00077 // If the user input is 'p', insert tokens into the CUserInterface::iQueue queue. 00078 iProducer->Produce(); 00079 ReadFunc(); 00080 } 00081 break; 00082 case 'd': 00083 { 00084 // If the user input is 'd', display the contents of the CUserInterface::iQueue queue. 00085 iProducer->Display(); 00086 ReadFunc(); 00087 } 00088 break; 00089 default: 00090 { 00091 // Stop the active scheduler for other user inputs. 00092 CActiveScheduler::Stop(); 00093 } 00094 } 00095 } 00096 00100 void CUserInterface::ReadFunc() 00101 { 00102 // Print the menu. 00103 _LIT(KTxtOption,"***\nMenu:\n[p]roduce a token\n[d]isplay the contents of the queue\nAny other key to stop\n***\n"); 00104 iConsole->Printf(KTxtOption); 00105 // Wait for a key press event. 00106 iConsole->Read(iStatus); 00107 SetActive(); 00108 } 00109 00113 void CUserInterface::DoCancel() 00114 { 00115 if(IsActive()) 00116 { 00117 // Cancel any outstanding read requests. 00118 iConsole->ReadCancel(); 00119 } 00120 } 00121 00125 CUserInterface::~CUserInterface() 00126 { 00127 DoCancel(); 00128 }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.