|
1 // Copyright (c) 2006-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 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <centralrepository.h> |
|
21 #include "cenrepobserver.h" |
|
22 #include "HWRMtrace.h" |
|
23 #include "HWRMLightDomainCRKeys.h" |
|
24 #include "HWRMLightsTimeoutObserver.h" |
|
25 |
|
26 // EXTERNAL DATA STRUCTURES |
|
27 // None |
|
28 |
|
29 // EXTERNAL FUNCTION PROTOTYPES |
|
30 // None |
|
31 |
|
32 // CONSTANTS |
|
33 // None |
|
34 |
|
35 // MACROS |
|
36 // None |
|
37 |
|
38 // LOCAL CONSTANTS AND MACROS |
|
39 // None |
|
40 |
|
41 // MODULE DATA STRUCTURES |
|
42 // None |
|
43 |
|
44 // LOCAL FUNCTION PROTOTYPES |
|
45 // None |
|
46 |
|
47 // FORWARD DECLARATIONS |
|
48 // None |
|
49 |
|
50 // ============================= LOCAL FUNCTIONS =============================== |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS =============================== |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CHWRMLightsTimeoutObserver::CHWRMLightsTimeoutObserver |
|
56 // C++ constructor |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CHWRMLightsTimeoutObserver::CHWRMLightsTimeoutObserver() |
|
60 { |
|
61 COMPONENT_TRACE1(_L( "HWRM Common - CHWRMLightsTimeoutObserver::CHWRMLightsTimeoutObserver()" ) ); |
|
62 COMPONENT_TRACE1(_L( "HWRM Common - CHWRMLightsTimeoutObserver::CHWRMLightsTimeoutObserver - return" ) ); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CHWRMLightsTimeoutObserver::ConstructL |
|
67 // Symbian 2nd phase constructor can leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CHWRMLightsTimeoutObserver::ConstructL(MHWRMLightsTimeoutObserver* aCallback) |
|
71 { |
|
72 COMPONENT_TRACE2(_L( "HWRM Common - CHWRMLightsTimeoutObserver::ConstructL(0x%x)" ), aCallback ); |
|
73 |
|
74 // To get access to cenrep |
|
75 iRepository = CRepository::NewL(KCRUidLightSettings); |
|
76 |
|
77 // set up notify handler |
|
78 iNotifyHandler = CCenRepListener::NewL(*this, |
|
79 *iRepository, |
|
80 KDisplayLightsTimeout); |
|
81 iNotifyHandler->StartListeningL(); |
|
82 |
|
83 iCallback = aCallback; |
|
84 |
|
85 // Get initial value of vibra enabled |
|
86 TInt value(0); |
|
87 TInt err = iRepository->Get(KDisplayLightsTimeout, value); |
|
88 |
|
89 if ( err == KErrNone ) |
|
90 { |
|
91 iCallback->LightsTimeoutChange(value); |
|
92 } |
|
93 else |
|
94 { |
|
95 COMPONENT_TRACE1(_L( "HWRM Common - CHWRMLightsTimeoutObserver::ConstructL - Unable to read KDisplayLightsTimeout from Cenrep" ) ); |
|
96 User::Leave(err); |
|
97 } |
|
98 |
|
99 COMPONENT_TRACE1(_L( "HWRM Common - CHWRMLightsTimeoutObserver::ConstructL - return " ) ); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CHWRMLightsTimeoutObserver::NewL |
|
104 // Two-phased constructor. |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 EXPORT_C CHWRMLightsTimeoutObserver* CHWRMLightsTimeoutObserver::NewL(MHWRMLightsTimeoutObserver* aCallback) |
|
108 { |
|
109 COMPONENT_TRACE2(_L( "HWRM Common - CHWRMLightsTimeoutObserver::NewL(0x%x)" ), aCallback ); |
|
110 |
|
111 // There must be a callback instance |
|
112 if ( !aCallback ) |
|
113 { |
|
114 User::Leave(KErrBadHandle); |
|
115 } |
|
116 |
|
117 CHWRMLightsTimeoutObserver* self = new( ELeave ) CHWRMLightsTimeoutObserver(); |
|
118 |
|
119 CleanupStack::PushL( self ); |
|
120 self->ConstructL(aCallback); |
|
121 CleanupStack::Pop(); |
|
122 |
|
123 COMPONENT_TRACE2(_L( "HWRM Common - CHWRMLightsTimeoutObserver::NewL - return 0x%x" ), self ); |
|
124 |
|
125 return self; |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // Destructor |
|
130 // --------------------------------------------------------- |
|
131 // |
|
132 EXPORT_C CHWRMLightsTimeoutObserver::~CHWRMLightsTimeoutObserver() |
|
133 { |
|
134 COMPONENT_TRACE1(_L( "HWRM Common - CHWRMLightsTimeoutObserver::~CHWRMLightsTimeoutObserver()" ) ); |
|
135 |
|
136 // Stop listening to cenrep |
|
137 if(iNotifyHandler) |
|
138 { |
|
139 iNotifyHandler->StopListening(); |
|
140 delete iNotifyHandler; |
|
141 } |
|
142 |
|
143 delete iRepository; |
|
144 |
|
145 iCallback = NULL; // PCLint demands |
|
146 |
|
147 COMPONENT_TRACE1(_L( "HWRM Common - CHWRMLightsTimeoutObserver::~CHWRMLightsTimeoutObserver - return" ) ); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CHWRMLightsTimeoutObserver::HandleNotifyInt |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CHWRMLightsTimeoutObserver::HandleNotifyInt(TUint32 aId, TInt aNewValue) |
|
155 { |
|
156 COMPONENT_TRACE3(_L("HWRM Common - CHWRMLightsTimeoutObserver::HandleNotifyInt(0x%x, 0x%x)"), aId, aNewValue); |
|
157 |
|
158 if (aId == KDisplayLightsTimeout) |
|
159 { |
|
160 if (iCallback) |
|
161 { |
|
162 // Inform user about change of the user profile vibra setting |
|
163 iCallback->LightsTimeoutChange(aNewValue); |
|
164 } |
|
165 } |
|
166 |
|
167 COMPONENT_TRACE1(_L("HWRM Common - CHWRMLightsTimeoutObserver::HandleNotifyInt - return") ); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CHWRMLightsTimeoutObserver::HandleNotifyError |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 #if defined(COMPONENT_TRACE_FLAG) && defined(_DEBUG) |
|
175 void CHWRMLightsTimeoutObserver::HandleNotifyError(TUint32 aId, TInt error, CCenRepListener* aHandler) |
|
176 #else |
|
177 void CHWRMLightsTimeoutObserver::HandleNotifyError(TUint32 /*aId*/, TInt /*error*/, CCenRepListener* aHandler) |
|
178 #endif |
|
179 { |
|
180 COMPONENT_TRACE4(_L("HWRM Common - CHWRMLightsTimeoutObserver::HandleNotifyError(0x%x, 0x%x, 0x%x)"), aId, error, aHandler); |
|
181 |
|
182 // retry notification |
|
183 if ( aHandler ) |
|
184 { |
|
185 TRAPD(err,aHandler->StartListeningL()); |
|
186 if ( err != KErrNone ) |
|
187 { |
|
188 COMPONENT_TRACE2(_L("HWRM Common - CHWRMLightsTimeoutObserver::HandleNotifyError - error: %d "), err ); |
|
189 } |
|
190 } |
|
191 |
|
192 COMPONENT_TRACE1(_L("HWRM Common - CHWRMLightsTimeoutObserver::HandleNotifyError - return") ); |
|
193 } |
|
194 |
|
195 |
|
196 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
197 |
|
198 // End of File |