00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #include "subscribepe.h"
00024
00025 LOCAL_D CConsoleBase* console;
00026
00030 CIntPropertyWatch::CIntPropertyWatch():CActive(EPriority)
00031 {
00032 }
00033
00038 void CIntPropertyWatch::ConstructL(CConsoleBase* aConsole)
00039 {
00040 User::LeaveIfError(iProperty.Attach(KMyPropertyCat,KMyPropertyName));
00041 iConsole = aConsole;
00042 CActiveScheduler::Add(this);
00043 }
00044
00050 CIntPropertyWatch* CIntPropertyWatch::NewL(CConsoleBase* aConsole)
00051 {
00052 CIntPropertyWatch* self = new (ELeave) CIntPropertyWatch;
00053 CleanupStack::PushL(self);
00054 self->ConstructL(aConsole);
00055 CleanupStack::Pop(self);
00056 return self;
00057 }
00058
00062 CIntPropertyWatch::~CIntPropertyWatch()
00063 {
00064 iProperty.Close();
00065 Cancel();
00066 }
00067
00071 void CIntPropertyWatch::DoCancel()
00072 {
00073 iProperty.Cancel();
00074 }
00075
00080 void CIntPropertyWatch::RunL()
00081 {
00082
00083
00084 TInt value;
00085 TInt err = iProperty.Get(value);
00086 if (err == KErrNotFound)
00087 {
00088
00089 CActiveScheduler::Stop();
00090 }
00091 else if (err == KErrNone)
00092 {
00093
00094 PrintProperty(value);
00095
00096 IssueRequest();
00097 }
00098 else
00099 {
00100
00101 CActiveScheduler::Stop();
00102 User::Leave(err);
00103 }
00104 }
00105
00110 void CIntPropertyWatch::PrintProperty(TInt aValue)
00111 {
00112 iConsole->Printf(KTxtValChange,aValue);
00113 }
00114
00119 void CIntPropertyWatch::WatchL()
00120 {
00121 TInt value;
00122
00123 TInt res = iProperty.Get(value);
00124 if (res == KErrNotFound)
00125 {
00126
00127 User::Leave(res);
00128 }
00129
00130
00131
00132 PrintProperty(value);
00133 IssueRequest();
00134 }
00135
00139 void CIntPropertyWatch::IssueRequest()
00140 {
00141 iProperty.Subscribe(iStatus);
00142 SetActive();
00143 }
00144
00145 void DoExampleL()
00146 {
00147 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00148 CleanupStack::PushL(scheduler);
00149 CActiveScheduler::Install(scheduler);
00150
00151 console->Printf(KTxtPESub);
00152
00153
00154 CIntPropertyWatch* obj = CIntPropertyWatch::NewL(console);
00155 CleanupStack::PushL(obj);
00156
00157
00158 obj->WatchL();
00159 CActiveScheduler::Start();
00160
00161 CleanupStack::PopAndDestroy(obj);
00162 CleanupStack::PopAndDestroy(scheduler);
00163 }
00164
00165 GLDEF_C TInt E32Main()
00166 {
00167 __UHEAP_MARK;
00168 CTrapCleanup* cleanup = CTrapCleanup::New();
00169
00170 TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
00171 if (createError)
00172 return createError;
00173
00174 TRAPD(mainError, DoExampleL());
00175 if (mainError)
00176 console->Printf(KTextFailed, mainError);
00177 console->Printf(KTextPressAnyKey);
00178 console->Getch();
00179
00180 delete console;
00181 delete cleanup;
00182 __UHEAP_MARKEND;
00183 return KErrNone;
00184 }