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
00027
00028
00029
00030
00031
00032
00033
00034
00039 #include "CCollector.h"
00040 _LIT(KTitle,"InputMessage");
00041 _LIT(KWelcome," Welcome to Message Queue Example application for the global queues\n");
00042 _LIT(KEnterWords, "\n Enter some words and press enter key to send to inverter or Press Esc to exit.\n");
00043 _LIT(KGlobalInverterInQ, "InverterInQ");
00044 _LIT(KGlobalInverterOutQ, "InverterOutQ");
00045 const TInt KNumberOfMsgs = 10;
00046
00050 CCollector::CCollector(TInt aPriority):CActive( aPriority )
00051 {
00052 CActiveScheduler::Add(this);
00053 }
00054
00055 CCollector::~CCollector()
00056 {
00057 Cancel();
00058 }
00059
00060 void CCollector::DoCancel()
00061 {
00062 }
00063
00069 void CCollector::ConstructL()
00070 {
00071 iConsole = Console::NewL(KTitle, TSize(KConsFullScreen, KConsFullScreen));
00072 iConsole->Printf(KWelcome);
00073 iConsole->Printf(KEnterWords);
00074
00075
00076 User::LeaveIfError(iInverterInQ.CreateGlobal(KGlobalInverterInQ, KNumberOfMsgs, EOwnerProcess));
00077
00078
00079 User::LeaveIfError(iInverterOutQ.CreateGlobal(KGlobalInverterOutQ, KNumberOfMsgs, EOwnerProcess));
00080
00081
00082 _LIT(KProcessName, "inverter.exe");
00083 User::LeaveIfError(process.Create(KProcessName, KNullDesC));
00084 process.Resume();
00085
00086 iRcvInverterInQ= CMsgQActive::NewL();
00087 }
00088
00089 CCollector* CCollector::NewL(TInt aPriority)
00090 {
00091 CCollector* self=new(ELeave)CCollector(aPriority);
00092 CleanupStack::PushL(self);
00093 self->ConstructL();
00094 CleanupStack::Pop(self);
00095 return self;
00096 }
00097
00101 void CCollector::RequestFunction()
00102 {
00103 iConsole->Read(iStatus);
00104 SetActive();
00105 }
00106
00110 void CCollector::RunL()
00111 {
00112
00113 _LIT(KChar,"%c");
00114 iConsole->Printf(KChar,(TUint8)(iConsole->KeyCode()));
00115 iBuf.Append(iConsole->KeyCode());
00116 ProcessKeyPress(TChar(iConsole->KeyCode()));
00117 }
00118
00123 void CCollector::ProcessKeyPress(TChar aChar)
00124 {
00125 if (aChar == EKeyEscape)
00126 {
00127 this->Stop();
00128 }
00129 else if(aChar == EKeyEnter)
00130 {
00131 _LIT(KNextLine , "\n");
00132 iConsole->Printf(KNextLine);
00133 this->SendMsgInQ(iBuf);
00134 iBuf.Zero();
00135 this->RequestFunction();
00136 }
00137 else
00138 {
00139 this->RequestFunction();
00140 }
00141 }
00142
00146 void CCollector::Stop()
00147 {
00148 TBuf<1> escape;
00149 escape.Append(EKeyEscape);
00150
00151 this->SendMsgInQ(escape);
00152
00153
00154 iRcvInverterInQ->Cancel();
00155 delete iRcvInverterInQ;
00156 delete iConsole;
00157 CActiveScheduler::Stop();
00158 escape.Zero();
00159 }
00160
00165 void CCollector::StartRecieving()
00166 {
00167 iRcvInverterInQ->StartRecieving();
00168 }
00169
00173 void CCollector::SendMsgInQ(TBuf<100> buf)
00174 {
00175 TInt ret = iInverterInQ.OpenGlobal(KGlobalInverterInQ);
00176 if (ret == KErrNone)
00177 {
00178 iInverterInQ.SendBlocking(buf);
00179 }
00180 }
00181
00182 LOCAL_C void DoStartL()
00183 {
00184
00185 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00186 CleanupStack::PushL(scheduler);
00187 CActiveScheduler::Install(scheduler);
00188
00189 CCollector* iCollect= CCollector::NewL();
00190 CleanupStack::PushL(iCollect);
00191
00192
00193 iCollect->RequestFunction();
00194
00195
00196 iCollect->StartRecieving();
00197 CActiveScheduler::Start();
00198
00199 CleanupStack::PopAndDestroy(iCollect);
00200 CleanupStack::PopAndDestroy(scheduler);
00201 }
00202
00203 GLDEF_C TInt E32Main()
00204 {
00205 __UHEAP_MARK;
00206 CTrapCleanup* cleanup = CTrapCleanup::New();
00207 if(cleanup == NULL)
00208 {
00209 return KErrNoMemory;
00210 }
00211 TRAPD(mainError, DoStartL());
00212 if(mainError != KErrNone)
00213 {
00214 _LIT(KUserPanic,"Failed to complete");
00215 User::Panic(KUserPanic, mainError);
00216 }
00217 delete cleanup;
00218 __UHEAP_MARKEND;
00219 return KErrNone;
00220 }
00221