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
00036 #include "subscribe.h"
00037 LOCAL_D CConsoleBase* console;
00038
00042 CArrayPropertyWatch::CArrayPropertyWatch():CActive(EPriority)
00043 {
00044 }
00045
00050 void CArrayPropertyWatch::ConstructL(CConsoleBase* aConsole)
00051 {
00052 User::LeaveIfError(iProperty.Attach(KMyPropertyCat,KMyPropertyName));
00053 iConsole = aConsole;
00054 CActiveScheduler::Add(this);
00055 }
00056
00062 CArrayPropertyWatch* CArrayPropertyWatch::NewL(CConsoleBase* aConsole)
00063 {
00064 CArrayPropertyWatch* self = new (ELeave) CArrayPropertyWatch;
00065 CleanupStack::PushL(self);
00066 self->ConstructL(aConsole);
00067 CleanupStack::Pop(self);
00068 return self;
00069 }
00070
00074 CArrayPropertyWatch::~CArrayPropertyWatch()
00075 {
00076 iProperty.Close();
00077 Cancel();
00078 }
00079
00083 void CArrayPropertyWatch::DoCancel()
00084 {
00085 iProperty.Cancel();
00086 }
00087
00092 void CArrayPropertyWatch::RunL()
00093 {
00094
00095 TBuf16<KArraySize> buf;
00096 TInt err = iProperty.Get(buf);
00097 if(err == KErrNotFound)
00098 {
00099
00100 CActiveScheduler::Stop();
00101 User::Leave(err);
00102 }
00103 else
00104 {
00105 if(buf == KStop)
00106 {
00107 CActiveScheduler::Stop();
00108 }
00109 else
00110 {
00111
00112 WatchL();
00113 }
00114 }
00115 }
00116
00121 void CArrayPropertyWatch::PrintProperty(TDes16& aBuf)
00122 {
00123 iConsole->Printf(KTxtArray);
00124 TInt bufLength = aBuf.Length();
00125 for(TInt ix = 0; ix < bufLength;ix++)
00126 {
00127 iConsole->Printf(KTxtArrayElement,aBuf[ix]);
00128 }
00129 iConsole->Printf(KTxtNewLine);
00130 }
00131
00135 void CArrayPropertyWatch::WatchL()
00136 {
00137
00138 TBuf16<KArraySize> buf;
00139 TInt err = iProperty.Get(buf);
00140 if(err == KErrNotFound)
00141 {
00142
00143 User::Leave(err);
00144 }
00145 PrintProperty(buf);
00146
00147 iProperty.Subscribe(iStatus);
00148
00149 SetActive();
00150 }
00151
00152 void DoExampleL()
00153 {
00154 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00155 CleanupStack::PushL(scheduler);
00156 CActiveScheduler::Install(scheduler);
00157
00158 console->Printf(KTxtSpecSt);
00159
00160
00161 CArrayPropertyWatch* obj = CArrayPropertyWatch::NewL(console);
00162 CleanupStack::PushL(obj);
00163
00164
00165 obj->WatchL();
00166 CActiveScheduler::Start();
00167
00168 CleanupStack::PopAndDestroy(obj);
00169 CleanupStack::PopAndDestroy(scheduler);
00170 }
00171
00172 GLDEF_C TInt E32Main()
00173 {
00174 __UHEAP_MARK;
00175 CTrapCleanup* cleanup = CTrapCleanup::New();
00176
00177 TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
00178 if (createError)
00179 return createError;
00180
00181 TRAPD(mainError, DoExampleL());
00182 if (mainError)
00183 console->Printf(KTextFailed, mainError);
00184 console->Printf(KTextPressAnyKey);
00185 console->Getch();
00186
00187 delete console;
00188 delete cleanup;
00189 __UHEAP_MARKEND;
00190 return KErrNone;
00191 }