00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00069 TUint8 option = iConsole->KeyCode();
00070
00071 _LIT(KTextFormat,"%c\n");
00072 iConsole->Printf(KTextFormat,option);
00073 switch(option)
00074 {
00075 case 'p':
00076 {
00077
00078 iProducer->Produce();
00079 ReadFunc();
00080 }
00081 break;
00082 case 'd':
00083 {
00084
00085 iProducer->Display();
00086 ReadFunc();
00087 }
00088 break;
00089 default:
00090 {
00091
00092 CActiveScheduler::Stop();
00093 }
00094 }
00095 }
00096
00100 void CUserInterface::ReadFunc()
00101 {
00102
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
00106 iConsole->Read(iStatus);
00107 SetActive();
00108 }
00109
00113 void CUserInterface::DoCancel()
00114 {
00115 if(IsActive())
00116 {
00117
00118 iConsole->ReadCancel();
00119 }
00120 }
00121
00125 CUserInterface::~CUserInterface()
00126 {
00127 DoCancel();
00128 }