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 "subscribepe.h"
00037
00038 LOCAL_D CConsoleBase* console;
00039
00043 CIntPropertyWatch::CIntPropertyWatch():CActive(EPriority)
00044 {
00045 }
00046
00051 void CIntPropertyWatch::ConstructL(CConsoleBase* aConsole)
00052 {
00053 User::LeaveIfError(iProperty.Attach(KMyPropertyCat,KMyPropertyName));
00054 iConsole = aConsole;
00055 CActiveScheduler::Add(this);
00056 }
00057
00063 CIntPropertyWatch* CIntPropertyWatch::NewL(CConsoleBase* aConsole)
00064 {
00065 CIntPropertyWatch* self = new (ELeave) CIntPropertyWatch;
00066 CleanupStack::PushL(self);
00067 self->ConstructL(aConsole);
00068 CleanupStack::Pop(self);
00069 return self;
00070 }
00071
00075 CIntPropertyWatch::~CIntPropertyWatch()
00076 {
00077 iProperty.Close();
00078 Cancel();
00079 }
00080
00084 void CIntPropertyWatch::DoCancel()
00085 {
00086 iProperty.Cancel();
00087 }
00088
00093 void CIntPropertyWatch::RunL()
00094 {
00095
00096
00097 TInt value;
00098 TInt err = iProperty.Get(value);
00099 if (err == KErrNotFound)
00100 {
00101
00102 CActiveScheduler::Stop();
00103 }
00104 else if (err == KErrNone)
00105 {
00106
00107 PrintProperty(value);
00108
00109 IssueRequest();
00110 }
00111 else
00112 {
00113
00114 CActiveScheduler::Stop();
00115 User::Leave(err);
00116 }
00117 }
00118
00123 void CIntPropertyWatch::PrintProperty(TInt aValue)
00124 {
00125 iConsole->Printf(KTxtValChange,aValue);
00126 }
00127
00132 void CIntPropertyWatch::WatchL()
00133 {
00134 TInt value;
00135
00136 TInt res = iProperty.Get(value);
00137 if (res == KErrNotFound)
00138 {
00139
00140 User::Leave(res);
00141 }
00142
00143
00144
00145 PrintProperty(value);
00146 IssueRequest();
00147 }
00148
00152 void CIntPropertyWatch::IssueRequest()
00153 {
00154 iProperty.Subscribe(iStatus);
00155 SetActive();
00156 }
00157
00158 void DoExampleL()
00159 {
00160 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00161 CleanupStack::PushL(scheduler);
00162 CActiveScheduler::Install(scheduler);
00163
00164 console->Printf(KTxtPESub);
00165
00166
00167 CIntPropertyWatch* obj = CIntPropertyWatch::NewL(console);
00168 CleanupStack::PushL(obj);
00169
00170
00171 obj->WatchL();
00172 CActiveScheduler::Start();
00173
00174 CleanupStack::PopAndDestroy(obj);
00175 CleanupStack::PopAndDestroy(scheduler);
00176 }
00177
00178 GLDEF_C TInt E32Main()
00179 {
00180 __UHEAP_MARK;
00181 CTrapCleanup* cleanup = CTrapCleanup::New();
00182
00183 TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
00184 if (createError)
00185 return createError;
00186
00187 TRAPD(mainError, DoExampleL());
00188 if (mainError)
00189 console->Printf(KTextFailed, mainError);
00190 console->Printf(KTextPressAnyKey);
00191 console->Getch();
00192
00193 delete console;
00194 delete cleanup;
00195 __UHEAP_MARKEND;
00196 return KErrNone;
00197 }