00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include "globals.h"
00036 #include "queue.h"
00037 #include "producer.h"
00038 #include "consumer.h"
00039 #include "userinterface.h"
00040
00041 LOCAL_D CConsoleBase* console;
00042 LOCAL_C void DoExampleL();
00043 LOCAL_C void callExampleL();
00044
00045 LOCAL_C void DoExampleL()
00046 {
00047 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00048 CleanupStack::PushL(scheduler);
00049 CActiveScheduler::Install(scheduler);
00050
00051
00052 CQueue* tokens = CQueue::NewL();
00053 CleanupStack::PushL(tokens);
00054
00055
00056 _LIT(KTextInvokeProducer,"Creating and starting the Producer Thread...[This produces a token every two seconds]\n");
00057 console->Printf(KTextInvokeProducer);
00058 _LIT(KTxtPressAnyKeyToContinue,"[press any key to continue]\n");
00059 console->Printf(KTxtPressAnyKeyToContinue);
00060 console->Getch();
00061
00062 CProducer* prod = CProducer::NewL(console,tokens);
00063 CleanupStack::PushL(prod);
00064
00065
00066 _LIT(KTextInvokeConsumer,"Creating and starting the Consumer Thread...[This consumes a token every second]\n");
00067 console->Printf(KTextInvokeConsumer);
00068 console->Printf(KTxtPressAnyKeyToContinue);
00069 console->Getch();
00070
00071
00072 CConsumer* cons = CConsumer::NewL(console,tokens);
00073 CleanupStack::PushL(cons);
00074
00075
00076
00077 CUserInterface* ui = CUserInterface::NewL(console,prod);
00078 CleanupStack::PushL(ui);
00079
00080 _LIT(KTextStartAS,"Starting the active scheduler...\n");
00081 console->Printf(KTextStartAS);
00082
00083 ui->ReadFunc();
00084
00085 CActiveScheduler::Start();
00086
00087 CleanupStack::PopAndDestroy(5,scheduler);
00088 }
00089
00090 GLDEF_C TInt E32Main()
00091 {
00092 __UHEAP_MARK;
00093 CTrapCleanup* cleanup=CTrapCleanup::New();
00094 TRAPD(error,callExampleL());
00095 delete cleanup;
00096 __ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error));
00097 __UHEAP_MARKEND;
00098 return 0;
00099 }
00100
00101 LOCAL_C void callExampleL()
00102 {
00103 console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
00104 CleanupStack::PushL(console);
00105 TRAPD(error,DoExampleL());
00106 if (error)
00107 console->Printf(KFormatFailed, error);
00108 else
00109 console->Printf(KTxtOK);
00110 console->Printf(KTxtPressAnyKey);
00111 console->Getch();
00112 CleanupStack::PopAndDestroy();
00113 }