|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * This class implements general wait object for calling |
|
17 * a callback function after subscribed P&S key value changes. |
|
18 * |
|
19 */ |
|
20 |
|
21 #include "propertylistener.h" |
|
22 #include "logger.h" |
|
23 |
|
24 using namespace java::installer; |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 CPropertyListener* CPropertyListener::NewL(TUid aUid, TUint aKey) |
|
29 { |
|
30 CPropertyListener* self = new(ELeave) CPropertyListener(aUid, aKey); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CPropertyListener::CPropertyListener(TUid aUid, TUint aKey) |
|
38 : CActive(CActive::EPriorityStandard), iUid(aUid), iKey(aKey) |
|
39 { |
|
40 } |
|
41 |
|
42 void CPropertyListener::ConstructL() |
|
43 { |
|
44 User::LeaveIfError(iProperty.Attach(iUid, iKey)); |
|
45 // PropertyListener is always created from a thread which does |
|
46 // not have ActiveScheduler, so create ActiveScheduler now. |
|
47 iActiveScheduler = new(ELeave) CActiveScheduler; |
|
48 CActiveScheduler::Install(iActiveScheduler); |
|
49 // Add this object to the ActiveScheduler. |
|
50 CActiveScheduler::Add(this); |
|
51 } |
|
52 |
|
53 CPropertyListener::~CPropertyListener() |
|
54 { |
|
55 Cancel(); |
|
56 iProperty.Close(); |
|
57 if (iActiveScheduler) |
|
58 { |
|
59 delete iActiveScheduler; |
|
60 iActiveScheduler = 0; |
|
61 } |
|
62 } |
|
63 |
|
64 void CPropertyListener::ProcessEventsL(JNIEnv *aEnv, jobject aProvider) |
|
65 { |
|
66 // Get the java side callback method. |
|
67 jclass clazz = aEnv->GetObjectClass(aProvider); |
|
68 jmethodID method = aEnv->GetMethodID(clazz, "valueChanged", "(I)V"); |
|
69 |
|
70 iEnv = aEnv; |
|
71 iProvider = aProvider; |
|
72 iMethod = method; |
|
73 |
|
74 // Run propertyListener once so that the current property value |
|
75 // gets delivered and property value changes are subscribed. |
|
76 RunL(); |
|
77 |
|
78 // Start ActiveScheduler. |
|
79 CActiveScheduler::Start(); |
|
80 } |
|
81 |
|
82 void CPropertyListener::RunL() |
|
83 { |
|
84 if (iCancelled) |
|
85 { |
|
86 CActiveScheduler::Stop(); |
|
87 return; |
|
88 } |
|
89 |
|
90 // Resubscribe before handling the new value to prevent missing updates. |
|
91 iProperty.Subscribe(iStatus); |
|
92 SetActive(); |
|
93 |
|
94 TInt value; |
|
95 TInt err = iProperty.Get(value); |
|
96 if (KErrNone == err) |
|
97 { |
|
98 //ILOG3(EJavaInstaller, |
|
99 // "CPropertyListener::RunL: property value changed" |
|
100 // ", uid: 0x%x, key: 0x%x, value: %d", iUid.iUid, iKey, value); |
|
101 // Use callback method to deliver the changed property value to |
|
102 // Java side object. |
|
103 iEnv->CallVoidMethod(iProvider, iMethod, value); |
|
104 } |
|
105 else if (KErrNotFound == err) |
|
106 { |
|
107 // Property deleted, no actions needed. |
|
108 } |
|
109 else |
|
110 { |
|
111 // Error while reading property value. |
|
112 ELOG3(EJavaInstaller, |
|
113 "CPropertyListener::RunL: getting property value failed" |
|
114 ", uid: 0x%x, key: 0x%x, err=%d", iUid.iUid, iKey, err); |
|
115 } |
|
116 } |
|
117 |
|
118 void CPropertyListener::DoCancel() |
|
119 { |
|
120 iCancelled = ETrue; |
|
121 iProperty.Cancel(); |
|
122 } |