|
1 /* |
|
2 * Copyright (c) 2006 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: Command handler for SSY <--> Sensor messages |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32property.h> |
|
20 #include "ssyreferencecmdhandler.h" |
|
21 #include "ssyreferencecontrol.h" |
|
22 #include "ssyreferencechannel.h" |
|
23 #include "ssyreferencetrace.h" |
|
24 |
|
25 // ======== CONSTANTS ======== |
|
26 const TInt KSsyRefShortDelay = 100; |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CSsyReferenceCmdHandler C++ constructor |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CSsyReferenceCmdHandler::CSsyReferenceCmdHandler( CSsyReferenceChannel& aSsyChannel ) : |
|
35 CActive( EPriorityNormal ), |
|
36 iSsyChannel( aSsyChannel ) |
|
37 { |
|
38 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::CSsyReferenceCmdHandler()" ) ) ); |
|
39 CActiveScheduler::Add( this ); |
|
40 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::CSsyReferenceCmdHandler() - return" ) ) ); |
|
41 } |
|
42 |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // Symbian 2nd phase constructor |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 void CSsyReferenceCmdHandler::ConstructL() |
|
49 { |
|
50 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::ConstructL()" ) ) ); |
|
51 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::ConstructL() - return" ) ) ); |
|
52 } |
|
53 |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CSsyReferenceCmdHandler::NewL |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CSsyReferenceCmdHandler* CSsyReferenceCmdHandler::NewL( CSsyReferenceChannel& aSsyChannel ) |
|
60 { |
|
61 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::NewL()" ) ) ); |
|
62 CSsyReferenceCmdHandler* self = new ( ELeave ) CSsyReferenceCmdHandler( aSsyChannel ); |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop( self ); |
|
66 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::NewL() - return" ) ) ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Destructor |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CSsyReferenceCmdHandler::~CSsyReferenceCmdHandler() |
|
75 { |
|
76 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::~CSsyReferenceCmdHandler()" ) ) ); |
|
77 |
|
78 if ( iMessage ) |
|
79 { |
|
80 // Send ProcessResponse |
|
81 iMessage->SetError( KErrCancel ); |
|
82 iSsyChannel.ProcessResponse( iMessage ); |
|
83 delete iMessage; |
|
84 iMessage = NULL; |
|
85 } |
|
86 |
|
87 if ( iTimer ) |
|
88 { |
|
89 iTimer->Cancel(); |
|
90 delete iTimer; |
|
91 } |
|
92 |
|
93 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::~CSsyReferenceCmdHandler() - return" ) ) ); |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CSsyReferenceCmdHandler::ProcessCommand |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 TInt CSsyReferenceCmdHandler::ProcessCommand( TSsyReferenceMsg aMessage ) |
|
101 { |
|
102 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::ProcessCommand()" ) ) ); |
|
103 TInt err( KErrAlreadyExists ); |
|
104 |
|
105 // Special case, when channel is reciving, iMessage is not deleted after ProcessCommand |
|
106 if ( aMessage.Function() == ESsyReferenceStopChannelData ) |
|
107 { |
|
108 // Stop 'receiving'. No need to handle this asynchronously |
|
109 if ( iTimer ) |
|
110 { |
|
111 iTimer->Cancel(); |
|
112 delete iTimer; |
|
113 iTimer = NULL; |
|
114 } |
|
115 |
|
116 iDataItemArray.Reset(); |
|
117 iDataItemPtr = 0; |
|
118 err = KErrNone; |
|
119 // No need to send ProcessResponse either |
|
120 delete iMessage; |
|
121 iMessage = NULL; |
|
122 } |
|
123 else if ( !iMessage ) |
|
124 { |
|
125 TRAP(err, iMessage = new ( ELeave ) TSsyReferenceMsg( aMessage )); |
|
126 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::ProcessCommand() - error %d creatig TSsyReferenceMsg" ), err ) ); |
|
127 |
|
128 switch( aMessage.Function() ) |
|
129 { |
|
130 case ESsyReferenceStartChannelData: |
|
131 { |
|
132 // Get channel data items and start 'receiving' |
|
133 IssueRequest(); |
|
134 err = KErrNone; |
|
135 break; |
|
136 } |
|
137 case ESsyReferenceOpenChannel: |
|
138 { |
|
139 // Open channel specific handling here |
|
140 IssueRequest(); |
|
141 err = KErrNone; |
|
142 break; |
|
143 } |
|
144 case ESsyReferenceCloseChannel: |
|
145 { |
|
146 // Close channel specific handling here |
|
147 IssueRequest(); |
|
148 err = KErrNone; |
|
149 break; |
|
150 } |
|
151 default: |
|
152 { |
|
153 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::ProcessCommand() - Unknown function" ) ) ); |
|
154 err = KErrNotFound; |
|
155 } |
|
156 } |
|
157 } |
|
158 else |
|
159 { |
|
160 err = KErrUnknown; |
|
161 } |
|
162 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::ProcessCommand() - return" ) ) ); |
|
163 return err; |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CSsyReferenceCmdHandler::IssueRequest |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 void CSsyReferenceCmdHandler::IssueRequest( TInt aError ) |
|
171 { |
|
172 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::IssueRequest()" ) ) ); |
|
173 // Provides synchronous function calls to be handled as asynchronous |
|
174 if ( !IsActive() ) |
|
175 { |
|
176 TRequestStatus *s = &iStatus; |
|
177 User::RequestComplete( s, aError ); |
|
178 SetActive(); |
|
179 } |
|
180 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::IssueRequest() - return" ) ) ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // CSsyReferenceCmdHandler::SendResponse |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CSsyReferenceCmdHandler::SendResponse( TInt aError ) |
|
188 { |
|
189 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::SendResponse()" ) ) ); |
|
190 // Send response to channel |
|
191 if ( iMessage ) |
|
192 { |
|
193 iMessage->SetError( aError ); |
|
194 iSsyChannel.ProcessResponse( iMessage ); |
|
195 delete iMessage; |
|
196 iMessage = NULL; |
|
197 } |
|
198 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::SendResponse() - return" ) ) ); |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CSsyReferenceCmdHandler::RunL |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 void CSsyReferenceCmdHandler::RunL() |
|
206 { |
|
207 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::RunL() - %i" ), iStatus.Int() ) ); |
|
208 |
|
209 TInt err( iStatus.Int() ); |
|
210 |
|
211 if ( iMessage ) |
|
212 { |
|
213 switch( iMessage->Function() ) |
|
214 { |
|
215 case ESsyReferenceStartChannelData: |
|
216 { |
|
217 TInt startInterval( 0 ); |
|
218 |
|
219 // Get all Channel data information from config file |
|
220 iSsyChannel.SsyControl().SsyConfig(). |
|
221 GetChannelDataInformationL( iMessage->ChannelId(), iDataItemArray, startInterval ); |
|
222 |
|
223 // Check that channel data items were found |
|
224 if ( iDataItemArray.Count() ) |
|
225 { |
|
226 // If interval is zero, set small interval |
|
227 if ( startInterval == 0 ) |
|
228 { |
|
229 startInterval = KSsyRefShortDelay; |
|
230 } |
|
231 |
|
232 // wait that interval |
|
233 if ( iTimer ) |
|
234 { |
|
235 iTimer->Cancel(); |
|
236 delete iTimer; |
|
237 iTimer = NULL; |
|
238 } |
|
239 |
|
240 // Reset pointer |
|
241 iDataItemPtr = 0; |
|
242 |
|
243 // Start timer and continue processing in callback function |
|
244 iTimer = CPeriodic::NewL( EPriorityNormal ); |
|
245 iTimer->Start( startInterval * 1000, 0, TCallBack( DataItemCallback, this ) ); |
|
246 } |
|
247 break; |
|
248 } |
|
249 case ESsyReferenceOpenChannel: |
|
250 { |
|
251 // Open channel response specific handling here |
|
252 iMessage->SetFunction( ESsyReferenceOpenChannelResp ); |
|
253 SendResponse(); |
|
254 break; |
|
255 } |
|
256 case ESsyReferenceCloseChannel: |
|
257 { |
|
258 // Close channel response specific handling here |
|
259 iMessage->SetFunction( ESsyReferenceCloseChannelResp ); |
|
260 SendResponse(); |
|
261 break; |
|
262 } |
|
263 default: |
|
264 { |
|
265 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::ProcessCommand() - Unknown function" ) ) ); |
|
266 err = KErrNotFound; |
|
267 } |
|
268 } |
|
269 } |
|
270 |
|
271 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::RunL() - return" ) ) ); |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // CSsyReferenceCmdHandler::DoCancel |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 void CSsyReferenceCmdHandler::DoCancel() |
|
279 { |
|
280 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::DoCancel()" ) ) ); |
|
281 |
|
282 // Handle cancel for this channel. Cancel any ongoing requests |
|
283 |
|
284 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::DoCancel() - return" ) ) ); |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // CSsyReferenceCmdHandler::RunError |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 TInt CSsyReferenceCmdHandler::RunError( TInt /*aError*/ ) |
|
292 { |
|
293 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::RunError()" ) ) ); |
|
294 |
|
295 // Handle possible errors here and return KErrNone to prevent SSY from panic |
|
296 |
|
297 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::RunError() - return" ) ) ); |
|
298 return KErrNone; |
|
299 } |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // CSsyReferenceCmdHandler::DataItemCallback |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 TInt CSsyReferenceCmdHandler::DataItemCallback( TAny* aThis ) |
|
306 { |
|
307 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::DataItemCallback()" ) ) ); |
|
308 return static_cast<CSsyReferenceCmdHandler*>( aThis )->GenerateChannelDataItem(); |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // CSsyReferenceCmdHandler::GenerateChannelDataItem |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 TInt CSsyReferenceCmdHandler::GenerateChannelDataItem() |
|
316 { |
|
317 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::GenerateChannelDataItem()" ) ) ); |
|
318 |
|
319 // Get next item from list and set pointer to next item |
|
320 TSsyRefChannelDataBase dataItem = iDataItemArray[iDataItemPtr++]; |
|
321 |
|
322 // Get next item interval from data item |
|
323 TInt nextInterval( dataItem.Interval() ); |
|
324 |
|
325 // Set timestamp to data item |
|
326 TTime time; |
|
327 time.HomeTime(); |
|
328 dataItem.SetTimestamp( time ); |
|
329 |
|
330 // If interval is zero, set small interval |
|
331 if ( nextInterval == 0 ) |
|
332 { |
|
333 nextInterval = KSsyRefShortDelay; |
|
334 } |
|
335 |
|
336 // Add data item to message |
|
337 iMessage->SetDataItem( &dataItem ); |
|
338 |
|
339 // If in last data item, set pointer back to first item |
|
340 if ( iDataItemArray.Count() == iDataItemPtr ) |
|
341 { |
|
342 iDataItemPtr = 0; |
|
343 } |
|
344 |
|
345 // Send response and start new timer |
|
346 iMessage->SetFunction( ESsyReferenceDataItemReceived ); |
|
347 iSsyChannel.ProcessResponse( iMessage ); |
|
348 |
|
349 if ( iTimer ) |
|
350 { |
|
351 delete iTimer; |
|
352 iTimer = NULL; |
|
353 } |
|
354 |
|
355 TRAP_IGNORE( iTimer = CPeriodic::NewL( EPriorityNormal ); |
|
356 iTimer->Start( nextInterval * 1000, 0, TCallBack( DataItemCallback, this ) ); ) |
|
357 |
|
358 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::GenerateChannelDataItem() - return" ) ) ); |
|
359 return KErrNone; |
|
360 } |
|
361 |
|
362 // End of file |