|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "ssmpropertymonitor.h" |
|
17 #include "cmnpanic.h" |
|
18 #include "ssmdebug.h" |
|
19 |
|
20 /** |
|
21 |
|
22 */ |
|
23 CSsmPropertyMonitor* CSsmPropertyMonitor::NewL(CSsmSystemWideProperty& aObserver, TUint aSwpKey, TUid aProcessSid) |
|
24 { |
|
25 CSsmPropertyMonitor* self = new (ELeave) CSsmPropertyMonitor(aObserver); |
|
26 CleanupStack::PushL(self); |
|
27 self->ConstructL(aSwpKey, aProcessSid); |
|
28 CleanupStack::Pop(self); |
|
29 return self; |
|
30 } //lint !e1746 Suppress parameter 'aProcessSid' could be made const reference |
|
31 |
|
32 /** |
|
33 |
|
34 */ |
|
35 CSsmPropertyMonitor::CSsmPropertyMonitor(CSsmSystemWideProperty& aObserver) : |
|
36 CActive(CActive::EPriorityStandard), |
|
37 iObserver(aObserver), |
|
38 iSwpLocal(TSsmSwp(0,0)) |
|
39 { |
|
40 CActiveScheduler::Add(this); |
|
41 } |
|
42 |
|
43 /** |
|
44 |
|
45 */ |
|
46 CSsmPropertyMonitor::~CSsmPropertyMonitor() |
|
47 { |
|
48 Cancel(); |
|
49 iSwpRemote.Close(); |
|
50 } |
|
51 |
|
52 /** |
|
53 |
|
54 */ |
|
55 void CSsmPropertyMonitor::ConstructL(TUint aSwpKey, TUid aProcessSid) |
|
56 { |
|
57 SSMLOGLEAVEIFERROR(iSwpRemote.Connect(aSwpKey, aProcessSid)); |
|
58 |
|
59 //Setup change subscription |
|
60 iStatus = KRequestPending; |
|
61 iSwpRemote.Subscribe(iStatus); |
|
62 SetActive(); |
|
63 |
|
64 //Read current value and store locally |
|
65 TInt value = 0; |
|
66 if(KErrNone == iSwpRemote.GetValue(value)) |
|
67 { |
|
68 iDefined = ETrue; |
|
69 } |
|
70 iSwpLocal.Set(aSwpKey, value); |
|
71 } //lint !e1746 Suppress parameter 'aProcessSid' could be made const reference |
|
72 |
|
73 /** |
|
74 |
|
75 */ |
|
76 void CSsmPropertyMonitor::DoCancel() |
|
77 { |
|
78 iSwpRemote.SubscribeCancel(); |
|
79 } |
|
80 |
|
81 /** |
|
82 |
|
83 */ |
|
84 void CSsmPropertyMonitor::RunL() |
|
85 { |
|
86 SSMLOGLEAVEIFERROR(iStatus.Int()); |
|
87 |
|
88 //Re-issue a subscription request before retrieving the current value |
|
89 iStatus = KRequestPending; |
|
90 iSwpRemote.Subscribe(iStatus); |
|
91 SetActive(); |
|
92 |
|
93 //Read current value and store locally |
|
94 TInt newValue = 0; |
|
95 SSMLOGLEAVEIFERROR(iSwpRemote.GetValue(newValue)); |
|
96 iSwpLocal.Set(iSwpLocal.Key(), newValue); |
|
97 |
|
98 //Notify our clients |
|
99 iObserver.NotifySubscribers(iSwpLocal); |
|
100 } |
|
101 |
|
102 /** |
|
103 @panic ECmnPropMonError1 if an error occurs in RunL |
|
104 */ |
|
105 TInt CSsmPropertyMonitor::RunError(TInt aError) |
|
106 { |
|
107 //All possible RProperty errors; KErrPermissionDenied, KErrNotFound and KErrArgument |
|
108 //should occur already in ConstructL and never in RunL. |
|
109 |
|
110 DEBUGPRINT2A("CSsmPropertyMonitor::RunError: %d", aError); |
|
111 User::Panic(KPanicSsmCmn, ECmnPropMonError1); //A panic here is easier to track than a panic in CActive |
|
112 return aError; //lint !e527 Unreachable |
|
113 } |
|
114 |
|
115 /** |
|
116 |
|
117 */ |
|
118 TInt CSsmPropertyMonitor::GetValue(TSsmSwp& aSwp) const |
|
119 { |
|
120 if(iDefined) |
|
121 { |
|
122 aSwp.Set(iSwpLocal.Key(), iSwpLocal.Value()); |
|
123 return KErrNone; |
|
124 } |
|
125 |
|
126 //The property was not yet defined when this monitor was created |
|
127 TInt value = 0; |
|
128 const TInt err = iSwpRemote.GetValue(value); |
|
129 if(KErrNone == err) |
|
130 { |
|
131 const_cast<TSsmSwp&>(iSwpLocal).Set(iSwpLocal.Key(), value); |
|
132 aSwp.Set(iSwpLocal.Key(), value); |
|
133 } |
|
134 return err; |
|
135 } |