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