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