|
1 /* |
|
2 * Copyright (c) 2006-2008 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: CSensrvPropertyHandler implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "sensrvpropertyhandler.h" |
|
20 #include "sensrvpropertyhandlerobserver.h" |
|
21 #include "sensrvtrace.h" |
|
22 |
|
23 |
|
24 // ======== LOCAL FUNCTIONS ======== |
|
25 |
|
26 static TSetPropertySuccessIndicator ErrorToSuccessIndicator( TInt aError ) |
|
27 { |
|
28 TSetPropertySuccessIndicator ret = ESetPropertyIndicationUnknown; |
|
29 switch ( aError ) |
|
30 { |
|
31 case KSensrvErrPropertySetAvailable: |
|
32 { |
|
33 ret = ESetPropertyIndicationAvailable; |
|
34 break; |
|
35 } |
|
36 case KSensrvErrPropertySetPossible: |
|
37 { |
|
38 ret = ESetPropertyIndicationPossible; |
|
39 break; |
|
40 } |
|
41 case KSensrvErrPropertySetUnavailable: |
|
42 { |
|
43 ret = ESetPropertyIndicationUnavailable; |
|
44 break; |
|
45 } |
|
46 default: |
|
47 { |
|
48 break; |
|
49 } |
|
50 } |
|
51 return ret; |
|
52 } |
|
53 |
|
54 |
|
55 // ======== MEMBER FUNCTIONS ======== |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // C++ constructor |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 |
|
62 CSensrvPropertyHandler::CSensrvPropertyHandler( RSensrvClient& aSensrvClient, |
|
63 const TSensrvChannelInfo& aChannelInfo ) |
|
64 : CActive( EPriorityStandard), |
|
65 iSensrvClient( aSensrvClient ), |
|
66 iChannelInfo( aChannelInfo ) |
|
67 { |
|
68 CActiveScheduler::Add( this ); |
|
69 } |
|
70 |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // 2-phase constructor |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CSensrvPropertyHandler* CSensrvPropertyHandler::NewL( RSensrvClient& aSensrvClient, |
|
77 const TSensrvChannelInfo& aChannelInfo ) |
|
78 { |
|
79 CSensrvPropertyHandler* self = CSensrvPropertyHandler::NewLC( aSensrvClient, aChannelInfo ); |
|
80 CleanupStack::Pop( self ); |
|
81 return self; |
|
82 } |
|
83 |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // 2-phase constructor |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CSensrvPropertyHandler* CSensrvPropertyHandler::NewLC( RSensrvClient& aSensrvClient, |
|
90 const TSensrvChannelInfo& aChannelInfo ) |
|
91 { |
|
92 CSensrvPropertyHandler* self = new( ELeave ) CSensrvPropertyHandler( aSensrvClient, aChannelInfo ); |
|
93 CleanupStack::PushL( self ); |
|
94 return self; |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // Destructor |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 CSensrvPropertyHandler::~CSensrvPropertyHandler() |
|
103 { |
|
104 Cancel(); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // From class CActive |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CSensrvPropertyHandler::DoCancel() |
|
112 { |
|
113 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvPropertyHandler::DoCancel()" ) ) ); |
|
114 |
|
115 // Stop Listening |
|
116 TInt ignore = iSensrvClient.SendReceiveSync( ESensrvSrvReqStopPropertyListening, |
|
117 TIpcArgs( iChannelInfo.iChannelId ) ); |
|
118 |
|
119 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvPropertyHandler::DoCancel - return void" ) ) ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // From class CActive |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CSensrvPropertyHandler::RunL() |
|
127 { |
|
128 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvPropertyHandler::RunL(iStatus: %d" ), iStatus.Int() ) ); |
|
129 |
|
130 Deque(); |
|
131 CActiveScheduler::Add(this); |
|
132 |
|
133 TInt err = iStatus.Int(); |
|
134 if ( err == KSensrvErrPropertySetAvailable || |
|
135 err == KSensrvErrPropertySetPossible || |
|
136 err == KSensrvErrPropertySetUnavailable ) |
|
137 { |
|
138 // Continue listening and send property set availability change |
|
139 CreateAndSendRequest(); |
|
140 iPropertyObserver->SetPropertySuccessIndicationChanged( ErrorToSuccessIndicator( err ) ); |
|
141 } |
|
142 else if( err == KErrNone ) |
|
143 { |
|
144 if( iErrorCount > 0 ) |
|
145 { |
|
146 iErrorCount = 0; |
|
147 } |
|
148 |
|
149 // Note: Callback is done intentionally before resending async request, |
|
150 // so that we don't need duplicate buffer like in data reading. |
|
151 // It shouldn't have noticeable effect on performance in real use cases, |
|
152 iPropertyObserver->PropertyChanged( iPropertyPckgBuf() ); |
|
153 CreateAndSendRequest(); |
|
154 } |
|
155 else |
|
156 { |
|
157 if( iErrorCount == 0 ) |
|
158 { |
|
159 iErrorCount++; |
|
160 CreateAndSendRequest(); |
|
161 |
|
162 // Send minor error |
|
163 iPropertyObserver->PropertyError( ESensrvErrorSeverityMinor ); |
|
164 } |
|
165 else if( iErrorCount == 1 ) |
|
166 { |
|
167 iErrorCount++; |
|
168 |
|
169 // Reopen channel |
|
170 iPropertyObserver->ReopenChannelForPropertyListeningL(); |
|
171 |
|
172 // Start listening |
|
173 CreateAndSendRequest(); |
|
174 } |
|
175 |
|
176 else |
|
177 { |
|
178 // send fatal error |
|
179 iPropertyObserver->PropertyError( ESensrvErrorSeverityFatal ); |
|
180 } |
|
181 } |
|
182 |
|
183 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvPropertyHandler::RunL - return" ) ) ); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CSensrvPropertyHandler::RunError |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 TInt CSensrvPropertyHandler::RunError( TInt /*aError*/ ) |
|
191 { |
|
192 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvPropertyHandler::RunError" ) ) ); |
|
193 // send fatal error |
|
194 iPropertyObserver->PropertyError( ESensrvErrorSeverityFatal ); |
|
195 return KErrNone; |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // CSensrvPropertyHandler::StartListening |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 void CSensrvPropertyHandler::StartListening( MSensrvPropertyHandlerObserver* aPropertyObserver ) |
|
203 { |
|
204 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvPropertyHandler::StartListening - Start" ) ) ); |
|
205 if( !IsActive() && aPropertyObserver ) |
|
206 { |
|
207 iPropertyObserver = aPropertyObserver; |
|
208 |
|
209 CreateAndSendRequest(); |
|
210 } |
|
211 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvPropertyHandler::StartListening - Return" ) ) ); |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // CSensrvPropertyHandler::CreateAndSendRequest |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void CSensrvPropertyHandler::CreateAndSendRequest() |
|
219 { |
|
220 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvPropertyHandler::CreateAndSendRequestL(Channel:%d)" ),iChannelInfo.iChannelId ) ); |
|
221 |
|
222 iSensrvClient.SendReceiveAsync( ESensrvSrvReqAsyncPropertyData, |
|
223 TIpcArgs( iChannelInfo.iChannelId, &iPropertyPckgBuf ), |
|
224 iStatus ); |
|
225 |
|
226 SetActive(); |
|
227 |
|
228 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvPropertyHandler::CreateAndSendRequestL - Return" ) ) ); |
|
229 } |
|
230 |