00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #include "subscribe.h"
00024 LOCAL_D CConsoleBase* console;
00025
00029 CArrayPropertyWatch::CArrayPropertyWatch():CActive(EPriority)
00030 {
00031 }
00032
00037 void CArrayPropertyWatch::ConstructL(CConsoleBase* aConsole)
00038 {
00039 User::LeaveIfError(iProperty.Attach(KMyPropertyCat,KMyPropertyName));
00040 iConsole = aConsole;
00041 CActiveScheduler::Add(this);
00042 }
00043
00049 CArrayPropertyWatch* CArrayPropertyWatch::NewL(CConsoleBase* aConsole)
00050 {
00051 CArrayPropertyWatch* self = new (ELeave) CArrayPropertyWatch;
00052 CleanupStack::PushL(self);
00053 self->ConstructL(aConsole);
00054 CleanupStack::Pop(self);
00055 return self;
00056 }
00057
00061 CArrayPropertyWatch::~CArrayPropertyWatch()
00062 {
00063 iProperty.Close();
00064 Cancel();
00065 }
00066
00070 void CArrayPropertyWatch::DoCancel()
00071 {
00072 iProperty.Cancel();
00073 }
00074
00079 void CArrayPropertyWatch::RunL()
00080 {
00081
00082 TBuf16<KArraySize> buf;
00083 TInt err = iProperty.Get(buf);
00084 if(err == KErrNotFound)
00085 {
00086
00087 CActiveScheduler::Stop();
00088 User::Leave(err);
00089 }
00090 else
00091 {
00092 if(buf == KStop)
00093 {
00094 CActiveScheduler::Stop();
00095 }
00096 else
00097 {
00098
00099 WatchL();
00100 }
00101 }
00102 }
00103
00108 void CArrayPropertyWatch::PrintProperty(TDes16& aBuf)
00109 {
00110 iConsole->Printf(KTxtArray);
00111 TInt bufLength = aBuf.Length();
00112 for(TInt ix = 0; ix < bufLength;ix++)
00113 {
00114 iConsole->Printf(KTxtArrayElement,aBuf[ix]);
00115 }
00116 iConsole->Printf(KTxtNewLine);
00117 }
00118
00122 void CArrayPropertyWatch::WatchL()
00123 {
00124
00125 TBuf16<KArraySize> buf;
00126 TInt err = iProperty.Get(buf);
00127 if(err == KErrNotFound)
00128 {
00129
00130 User::Leave(err);
00131 }
00132 PrintProperty(buf);
00133
00134 iProperty.Subscribe(iStatus);
00135
00136 SetActive();
00137 }
00138
00139 void DoExampleL()
00140 {
00141 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00142 CleanupStack::PushL(scheduler);
00143 CActiveScheduler::Install(scheduler);
00144
00145 console->Printf(KTxtSpecSt);
00146
00147
00148 CArrayPropertyWatch* obj = CArrayPropertyWatch::NewL(console);
00149 CleanupStack::PushL(obj);
00150
00151
00152 obj->WatchL();
00153 CActiveScheduler::Start();
00154
00155 CleanupStack::PopAndDestroy(obj);
00156 CleanupStack::PopAndDestroy(scheduler);
00157 }
00158
00159 GLDEF_C TInt E32Main()
00160 {
00161 __UHEAP_MARK;
00162 CTrapCleanup* cleanup = CTrapCleanup::New();
00163
00164 TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
00165 if (createError)
00166 return createError;
00167
00168 TRAPD(mainError, DoExampleL());
00169 if (mainError)
00170 console->Printf(KTextFailed, mainError);
00171 console->Printf(KTextPressAnyKey);
00172 console->Getch();
00173
00174 delete console;
00175 delete cleanup;
00176 __UHEAP_MARKEND;
00177 return KErrNone;
00178 }