00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #include "consumer.h"
00024
00031 CConsumer* CConsumer::NewL(CConsoleBase* aConsole,CQueue* aTokens)
00032 {
00033 CConsumer* self = new (ELeave)CConsumer;
00034 CleanupStack::PushL(self);
00035 self->ConstructL(aConsole,aTokens);
00036 CleanupStack::Pop(self);
00037 return self;
00038 }
00039
00051 void CConsumer::ConstructL(CConsoleBase* aConsole,CQueue* aTokens)
00052 {
00053 iConsole = aConsole;
00054 iQueue = aTokens;
00055
00056
00057 iPeriodicCons = CPeriodic::NewL(CActive::EPriorityUserInput);
00058
00059
00060 _LIT(KConsumer,"ConsumerThread");
00061 User::LeaveIfError(iConsThread.Create(KConsumer,ConsThreadFunc,KDefaultStackSize,KMinHeapSize,256*KMinHeapSize,iQueue,EOwnerThread));
00062 iConsThread.SetPriority(EPriorityMore);
00063
00064
00065
00066
00067 iPeriodicCons->Start(2000000,2000000,TCallBack(RemoveFunction,this));
00068 }
00069
00073 CConsumer::CConsumer()
00074 {
00075 }
00076
00082 TInt CConsumer::ConsThreadFunc(TAny* aPtr)
00083 {
00084
00085 while(true)
00086 {
00087 CQueue* ptr = (CQueue*)aPtr;
00088 __ASSERT_ALWAYS(ptr,User::Panic(KTxtPanic,-1));
00089
00090 ptr->Remove();
00091
00092 RThread().Suspend();
00093 }
00094 return KErrNone;
00095 }
00096
00097
00101 void CConsumer::ResumeCons()
00102 {
00103
00104
00105 iConsThread.Resume();
00106 }
00107
00111 CConsumer::~CConsumer()
00112 {
00113 iConsThread.Kill(KErrCancel);
00114 delete iPeriodicCons;
00115 }
00116
00117
00123 TInt CConsumer::RemoveFunction(TAny* aPtr)
00124 {
00125 CConsumer* ptr = static_cast<CConsumer*> (aPtr);
00126 __ASSERT_ALWAYS(ptr,User::Panic(KTxtPanic,-1));
00127
00128 ptr->ResumeCons();
00129 return KErrNone;
00130 }