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
00065 RProperty::Delete(KMyPropertyCat, KMyPropertyName);
00066 Cancel();
00067 }
00068
00072 void CArrayPropertyWatch::DoCancel()
00073 {
00074 iProperty.Cancel();
00075 }
00076
00081 void CArrayPropertyWatch::RunL()
00082 {
00083
00084 TBuf16<KArraySize> buf;
00085 TInt err = iProperty.Get(buf);
00086 if(err == KErrNotFound)
00087 {
00088
00089 CActiveScheduler::Stop();
00090 User::Leave(err);
00091 }
00092 else
00093 {
00094
00095 PrintProperty(buf);
00096 if(buf == KStop)
00097 {
00098 CActiveScheduler::Stop();
00099 }
00100 else
00101 {
00102
00103 iProperty.Subscribe(iStatus);
00104 SetActive();
00105 }
00106 }
00107 }
00108
00113 void CArrayPropertyWatch::PrintProperty(TDes16& aBuf)
00114 {
00115 iConsole->Printf(KTxtArray);
00116 TInt bufLength = aBuf.Length();
00117 for(TInt ix = 0; ix < bufLength;ix++)
00118 {
00119 iConsole->Printf(KTxtArrayElement,aBuf[ix]);
00120 }
00121 iConsole->Printf(KTxtNewLine);
00122 }
00123
00127 void CArrayPropertyWatch::DefinePropertyL()
00128 {
00129 iConsole->Printf(KTxtDefine);
00130
00131 TInt err = RProperty::Define(KMyPropertyCat, KMyPropertyName,RProperty::EByteArray,KAllowAllPolicy,KAllowAllPolicy,KArraySize);
00132 if(err == KErrAlreadyExists || err == KErrNone)
00133 {
00134
00135 TBuf16<KArraySize> buf;
00136
00137
00138 err = iProperty.Get(buf);
00139 User::LeaveIfError(err);
00140
00141 iProperty.Subscribe(iStatus);
00142 SetActive();
00143 }
00144 else
00145 {
00146
00147 User::Leave(err);
00148 }
00149 }
00150
00151 void DoExampleL()
00152 {
00153 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00154 CleanupStack::PushL(scheduler);
00155 CActiveScheduler::Install(scheduler);
00156
00157 console->Printf(KTxtSpecSub);
00158
00159
00160 CArrayPropertyWatch* obj = CArrayPropertyWatch::NewL(console);
00161 CleanupStack::PushL(obj);
00162
00163
00164 obj->DefinePropertyL();
00165 CActiveScheduler::Start();
00166
00167 CleanupStack::PopAndDestroy(obj);
00168 CleanupStack::PopAndDestroy(scheduler);
00169 }
00170
00171 GLDEF_C TInt E32Main()
00172 {
00173 __UHEAP_MARK;
00174 CTrapCleanup* cleanup = CTrapCleanup::New();
00175
00176 TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
00177 if (createError)
00178 return createError;
00179
00180 TRAPD(mainError, DoExampleL());
00181 if (mainError)
00182 console->Printf(KTextFailed, mainError);
00183 console->Printf(KTextPressAnyKey);
00184 console->Getch();
00185
00186 delete console;
00187 delete cleanup;
00188 __UHEAP_MARKEND;
00189 return KErrNone;
00190 }