|
1 /* |
|
2 * Copyright (c) 2009 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: Central Repository listening |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "tmscenreplistener.h" |
|
20 #include "tmscenrepobserver.h" |
|
21 #include "tmsutility.h" |
|
22 |
|
23 using namespace TMS; |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // TMSCenRepListener::TMSCenRepListener |
|
27 // C++ default constructor |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 TMSCenRepListener* TMSCenRepListener::NewL(TUid aUid, TUint32 aMonitorSetting, |
|
31 TMSCenRepObserver* aObserver) |
|
32 { |
|
33 TRACE_PRN_FN_ENT; |
|
34 TMSCenRepListener* self = new (ELeave) TMSCenRepListener(aUid, |
|
35 aMonitorSetting, aObserver); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(); |
|
39 TRACE_PRN_FN_EXT; |
|
40 return self; |
|
41 } |
|
42 |
|
43 // Destructor |
|
44 TMSCenRepListener::~TMSCenRepListener() |
|
45 { |
|
46 TRACE_PRN_FN_ENT; |
|
47 Cancel(); |
|
48 delete iRepository; |
|
49 TRACE_PRN_FN_EXT; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // TMSCenRepListener::Get |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 gint TMSCenRepListener::Get(gint& aValue) |
|
57 { |
|
58 TRACE_PRN_FN_ENT; |
|
59 gint status(TMS_RESULT_SUCCESS); |
|
60 if (iRepository) |
|
61 { |
|
62 status = iRepository->Get(iMonitorSetting, aValue); |
|
63 } |
|
64 TRACE_PRN_FN_EXT; |
|
65 return status; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // TMSCenRepListener::Set |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 gint TMSCenRepListener::Set(gint aValue) |
|
73 { |
|
74 TRACE_PRN_FN_ENT; |
|
75 gint status(TMS_RESULT_SUCCESS); |
|
76 if (iRepository) |
|
77 { |
|
78 status = iRepository->Set(iMonitorSetting, aValue); |
|
79 } |
|
80 TRACE_PRN_FN_EXT; |
|
81 return status; |
|
82 |
|
83 } |
|
84 // ----------------------------------------------------------------------------- |
|
85 // TMSCenRepListener::DoCancel |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void TMSCenRepListener::DoCancel() |
|
89 { |
|
90 TRACE_PRN_FN_ENT; |
|
91 if (iRepository) |
|
92 { |
|
93 iRepository->NotifyCancel(iMonitorSetting); |
|
94 } |
|
95 TRACE_PRN_FN_EXT; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // TMSCenRepListener::RunError |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 gint TMSCenRepListener::RunError( |
|
103 #ifdef _DEBUG |
|
104 TInt aError // Log the leavecode from RunL |
|
105 #else |
|
106 TInt /*aError*/ |
|
107 #endif |
|
108 ) |
|
109 { |
|
110 TRACE_PRN_FN_ENT; |
|
111 #ifdef _DEBUG |
|
112 TRACE_PRN_IF_ERR(aError); |
|
113 #endif |
|
114 TRACE_PRN_FN_EXT; |
|
115 return KErrNone; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // TMSCenRepListener::RunL |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void TMSCenRepListener::RunL() |
|
123 { |
|
124 TRACE_PRN_FN_ENT; |
|
125 // Don't resubmit the request on error |
|
126 // Central repositry completes notifications with id of setting |
|
127 // so check only that value of iStatus is negative |
|
128 if (iStatus.Int() == KErrNone) |
|
129 { |
|
130 SubmitNotifyRequestL(); |
|
131 } |
|
132 |
|
133 // The loudspeaker volume has changed in repository. |
|
134 // Retrieve the current volume from repository. |
|
135 gint volume; |
|
136 Get(volume); |
|
137 if (iObserver) |
|
138 { |
|
139 iObserver->HandleNotifyCenRepL(iUid, iMonitorSetting, volume); |
|
140 } |
|
141 TRACE_PRN_FN_EXT; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // TMSCenRepListener::TMSCenRepListener |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 TMSCenRepListener::TMSCenRepListener(TUid aUid, TUint32 aMonitorSetting, |
|
149 TMSCenRepObserver* aObserver) : |
|
150 CActive(EPriorityStandard), |
|
151 iUid(aUid), |
|
152 iMonitorSetting(aMonitorSetting), |
|
153 iObserver(aObserver) |
|
154 { |
|
155 TRACE_PRN_FN_ENT; |
|
156 CActiveScheduler::Add(this); |
|
157 TRACE_PRN_FN_EXT; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // TMSCenRepListener::ConstructL |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void TMSCenRepListener::ConstructL() |
|
165 { |
|
166 TRACE_PRN_FN_ENT; |
|
167 // Create repository instance |
|
168 iRepository = CRepository::NewL(iUid); |
|
169 // Start monitoring |
|
170 SubmitNotifyRequestL(); |
|
171 TRACE_PRN_FN_EXT; |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // TMSCenRepListener::SubmitNotifyRequestL |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void TMSCenRepListener::SubmitNotifyRequestL() |
|
179 { |
|
180 TRACE_PRN_FN_ENT; |
|
181 if (iRepository) |
|
182 { |
|
183 iStatus = KRequestPending; |
|
184 iRepository->NotifyRequest(iMonitorSetting, iStatus); |
|
185 SetActive(); |
|
186 } |
|
187 TRACE_PRN_FN_EXT; |
|
188 } |
|
189 |
|
190 // End of file |