51
|
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: Context session.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "ximpcontextsession.h"
|
|
19 |
#include "ximpsrvmessage.h"
|
|
20 |
#include "ximpserverdefs.h"
|
|
21 |
|
|
22 |
#include "ximpcontexteventqueue.h"
|
|
23 |
#include "ximpcontexteventfilter.h"
|
|
24 |
#include "ximphostmanager.h"
|
|
25 |
#include "ximpglobals.h"
|
|
26 |
#include "ximppsccontextimp.h"
|
|
27 |
|
|
28 |
#include "ximpfeatureinfoimp.h"
|
|
29 |
#include "ximpobjecthelpers.h"
|
|
30 |
#include "ximppanics.h"
|
|
31 |
#include "ximptrace.h"
|
|
32 |
#include "ximpoperationdefs.h"
|
|
33 |
#include "ximpoperationbase.h"
|
|
34 |
|
|
35 |
#include "ximphoststates.h"
|
|
36 |
|
|
37 |
#include <ximpbase.h>
|
|
38 |
#include <e32base.h>
|
|
39 |
|
|
40 |
using namespace NXIMPSrv;
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
// ============================ MEMBER FUNCTIONS =============================
|
|
45 |
|
|
46 |
// ---------------------------------------------------------------------------
|
|
47 |
// CXIMPContextSession::NewL()
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
CXIMPContextSession* CXIMPContextSession::NewL( TUint32 aSessionId )
|
|
51 |
{
|
|
52 |
CXIMPContextSession* self = new( ELeave ) CXIMPContextSession();
|
|
53 |
CleanupStack::PushL( self );
|
|
54 |
self->ConstructL( aSessionId );
|
|
55 |
CleanupStack::Pop( self );
|
|
56 |
return self;
|
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
// ---------------------------------------------------------------------------
|
|
61 |
// CXIMPContextSession::~CXIMPContextSession()
|
|
62 |
// ---------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
CXIMPContextSession::~CXIMPContextSession()
|
|
65 |
{
|
|
66 |
TRACE_1( _L("CXIMPContextSession[%d]::~CXIMPContextSession()"), this );
|
|
67 |
|
|
68 |
delete iPreparedData;
|
|
69 |
|
|
70 |
if( iEventListenScout )
|
|
71 |
{
|
|
72 |
iEventListenScout->Complete( KErrCancel );
|
|
73 |
delete iEventListenScout;
|
|
74 |
}
|
|
75 |
|
|
76 |
iClientData->EventQueue().StopConsuming();
|
|
77 |
|
|
78 |
// Unbind when client has died, and unbind not send.
|
|
79 |
CXIMPOperationBase* operation = iClientData->GetCachedUnbind();
|
|
80 |
|
|
81 |
if( operation )
|
|
82 |
{
|
|
83 |
TRAP_IGNORE(
|
|
84 |
{
|
|
85 |
CleanupStack::PushL( operation );
|
|
86 |
iClientData->AppendToOpQueueL( operation );
|
|
87 |
CleanupStack::Pop( operation );
|
|
88 |
} );
|
|
89 |
}
|
|
90 |
|
|
91 |
iClientData->Close();
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
// ---------------------------------------------------------------------------
|
|
96 |
// CXIMPContextSession::CXIMPContextSession()
|
|
97 |
// ---------------------------------------------------------------------------
|
|
98 |
//
|
|
99 |
CXIMPContextSession::CXIMPContextSession()
|
|
100 |
{
|
|
101 |
TRACE_1( _L("CXIMPContextSession[%d]::CXIMPContextSession()"), this );
|
|
102 |
}
|
|
103 |
|
|
104 |
|
|
105 |
// -----------------------------------------------------------------------------
|
|
106 |
// CXIMPContextSession::ConstructL()
|
|
107 |
// -----------------------------------------------------------------------------
|
|
108 |
//
|
|
109 |
void CXIMPContextSession::ConstructL( TUint32 aSessionId )
|
|
110 |
{
|
|
111 |
iClientData = CXIMPPscContext::NewL( aSessionId );
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
// -----------------------------------------------------------------------------
|
|
116 |
// CXIMPContextSession::TryHandleMessageL()
|
|
117 |
// From MXIMPSrvSession
|
|
118 |
// -----------------------------------------------------------------------------
|
|
119 |
//
|
|
120 |
void CXIMPContextSession::TryHandleMessageL( MXIMPSrvMessage& aMessage )
|
|
121 |
{
|
|
122 |
switch( aMessage.Function() )
|
|
123 |
{
|
|
124 |
//Asynchronous context operations related
|
|
125 |
case NRequest::ECtxSsQueueOperation:
|
|
126 |
{
|
|
127 |
DoQueueOperationL( aMessage );
|
|
128 |
break;
|
|
129 |
}
|
|
130 |
//Asynchronous context operations related
|
|
131 |
case NRequest::ECtxSsQueueBindOperation:
|
|
132 |
{
|
|
133 |
DoQueueOperationL( aMessage );
|
|
134 |
break;
|
|
135 |
}
|
|
136 |
|
|
137 |
//Event handling related
|
|
138 |
case NRequest::ECtxSsInstallEventFilter:
|
|
139 |
{
|
|
140 |
DoInstallEventFilterL( aMessage );
|
|
141 |
break;
|
|
142 |
}
|
|
143 |
|
|
144 |
case NRequest::ECtxSsSetEventListenScout:
|
|
145 |
{
|
|
146 |
DoSetEventListenScoutL( aMessage );
|
|
147 |
break;
|
|
148 |
}
|
|
149 |
|
|
150 |
case NRequest::ECtxSsCancelEventListenScout:
|
|
151 |
{
|
|
152 |
DoCancelEventListenScout( aMessage );
|
|
153 |
break;
|
|
154 |
}
|
|
155 |
|
|
156 |
case NRequest::ECtxSsFetchTopEventDataSize:
|
|
157 |
{
|
|
158 |
DoFetchTopEventDataSizeL( aMessage );
|
|
159 |
break;
|
|
160 |
}
|
|
161 |
|
|
162 |
case NRequest::ECtxSsFetchTopEventData:
|
|
163 |
{
|
|
164 |
DoFetchTopEventDataL( aMessage );
|
|
165 |
break;
|
|
166 |
}
|
|
167 |
|
|
168 |
case NRequest::ECtxSsFetchTopEventReqId:
|
|
169 |
{
|
|
170 |
DoFetchTopEventReqIdL( aMessage );
|
|
171 |
break;
|
|
172 |
}
|
|
173 |
|
|
174 |
case NRequest::ECtxSsDropTopEvent:
|
|
175 |
{
|
|
176 |
DoDropTopEventL( aMessage );
|
|
177 |
break;
|
|
178 |
}
|
|
179 |
|
|
180 |
//Synchronous context data access
|
|
181 |
case NRequest::ECtxSsPrepareContextFeatures:
|
|
182 |
{
|
|
183 |
DoPrepareContextFeaturesL( aMessage );
|
|
184 |
break;
|
|
185 |
}
|
|
186 |
|
|
187 |
case NRequest::ECtxSsGetPreparedData:
|
|
188 |
{
|
|
189 |
DoGetPreparedDataL( aMessage );
|
|
190 |
break;
|
|
191 |
}
|
|
192 |
|
|
193 |
default:
|
|
194 |
{
|
|
195 |
//Unknown request type
|
|
196 |
//Nothing to do here.
|
|
197 |
}
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
|
|
202 |
// -----------------------------------------------------------------------------
|
|
203 |
// CXIMPContextSession::NewEventAvailable()
|
|
204 |
// From MXIMPEventQueueObserver
|
|
205 |
// -----------------------------------------------------------------------------
|
|
206 |
//
|
|
207 |
void CXIMPContextSession::NewEventAvailable()
|
|
208 |
{
|
|
209 |
if( iEventListenScout )
|
|
210 |
{
|
|
211 |
iEventListenScout->Complete( KErrNone );
|
|
212 |
delete iEventListenScout;
|
|
213 |
iEventListenScout = NULL;
|
|
214 |
}
|
|
215 |
}
|
|
216 |
|
|
217 |
|
|
218 |
// -----------------------------------------------------------------------------
|
|
219 |
// CXIMPContextSession::DoQueueOperationL()
|
|
220 |
// -----------------------------------------------------------------------------
|
|
221 |
//
|
|
222 |
void CXIMPContextSession::DoQueueOperationL(
|
|
223 |
MXIMPSrvMessage& aMessage )
|
|
224 |
{
|
|
225 |
const TInt operationType = aMessage.Int( MXIMPSrvMessage::Ep0 );
|
|
226 |
|
|
227 |
TPckgBuf< TXIMPRequestId > reqIdBuf;
|
|
228 |
|
|
229 |
// We can take ready unbind from context if it exists.
|
|
230 |
CXIMPOperationBase* operation = NULL;
|
|
231 |
if( operationType == NXIMPOps::EXIMPUnbindContext )
|
|
232 |
{
|
|
233 |
operation = iClientData->GetCachedUnbind();
|
|
234 |
// ownership transferred
|
|
235 |
}
|
|
236 |
|
|
237 |
if( operation )
|
|
238 |
{
|
|
239 |
// found an unbind, so put it to the queue to be processed
|
|
240 |
CleanupStack::PushL( operation );
|
|
241 |
iClientData->AppendToOpQueueL( operation );
|
|
242 |
reqIdBuf() = operation->RequestId();
|
|
243 |
CleanupStack::Pop( operation );
|
|
244 |
}
|
|
245 |
else
|
|
246 |
{
|
|
247 |
const TInt pckSize = aMessage.GetDesLengthL( MXIMPSrvMessage::Ep1 );
|
|
248 |
HBufC8* paramPck = HBufC8::NewLC( pckSize );
|
|
249 |
TPtr8 paramPckPtr = paramPck->Des();
|
|
250 |
aMessage.ReadL( MXIMPSrvMessage::Ep1, paramPckPtr );
|
|
251 |
reqIdBuf() = iClientData->AddNewOperationL( operationType,
|
|
252 |
*paramPck );
|
|
253 |
CleanupStack::PopAndDestroy( paramPck );
|
|
254 |
}
|
|
255 |
|
|
256 |
aMessage.WriteL( MXIMPSrvMessage::Ep2, reqIdBuf );
|
|
257 |
aMessage.Complete( KErrNone );
|
|
258 |
}
|
|
259 |
|
|
260 |
|
|
261 |
// -----------------------------------------------------------------------------
|
|
262 |
// CXIMPContextSession::DoInstallEventFilterL()
|
|
263 |
// -----------------------------------------------------------------------------
|
|
264 |
//
|
|
265 |
void CXIMPContextSession::DoInstallEventFilterL(
|
|
266 |
MXIMPSrvMessage& aMessage )
|
|
267 |
{
|
|
268 |
const TInt pckSize = aMessage.GetDesLengthL( MXIMPSrvMessage::Ep0 );
|
|
269 |
HBufC8* filterPck = HBufC8::NewLC( pckSize );
|
|
270 |
TPtr8 filterPckPtr( filterPck->Des() );
|
|
271 |
aMessage.ReadL( MXIMPSrvMessage::Ep0, filterPckPtr );
|
|
272 |
|
|
273 |
CXIMPContextEventFilter* newFilter = CXIMPContextEventFilter::NewLC();
|
|
274 |
TXIMPObjectPacker< CXIMPContextEventFilter >::UnPackL( *newFilter,
|
|
275 |
*filterPck );
|
|
276 |
|
|
277 |
iClientData->EventQueue().SetEventFilter( *newFilter );
|
|
278 |
CleanupStack::Pop( newFilter );
|
|
279 |
CleanupStack::PopAndDestroy( filterPck );
|
|
280 |
|
|
281 |
aMessage.Complete( KErrNone );
|
|
282 |
}
|
|
283 |
|
|
284 |
|
|
285 |
// -----------------------------------------------------------------------------
|
|
286 |
// CXIMPContextSession::DoSetEventListenScoutL()
|
|
287 |
// -----------------------------------------------------------------------------
|
|
288 |
//
|
|
289 |
void CXIMPContextSession::DoSetEventListenScoutL(
|
|
290 |
MXIMPSrvMessage& aMessage )
|
|
291 |
{
|
|
292 |
__ASSERT_ALWAYS( !iEventListenScout,
|
|
293 |
aMessage.PanicClientAndLeaveL(
|
|
294 |
NXIMPPanic::EOnSrvAlreadyListeningEvents ) );
|
|
295 |
|
|
296 |
iClientData->EventQueue().StartConsuming( *this );
|
|
297 |
|
|
298 |
//If there is already a events in que,
|
|
299 |
//signal client right a way
|
|
300 |
if( iClientData->EventQueue().HasElements() )
|
|
301 |
{
|
|
302 |
aMessage.Complete( KErrNone );
|
|
303 |
}
|
|
304 |
else
|
|
305 |
{
|
|
306 |
aMessage.PlaceOwnershipHere( iEventListenScout );
|
|
307 |
}
|
|
308 |
}
|
|
309 |
|
|
310 |
|
|
311 |
// -----------------------------------------------------------------------------
|
|
312 |
// CXIMPContextSession::DoCancelEventListenScout()
|
|
313 |
// -----------------------------------------------------------------------------
|
|
314 |
//
|
|
315 |
void CXIMPContextSession::DoCancelEventListenScout(
|
|
316 |
MXIMPSrvMessage& aMessage )
|
|
317 |
{
|
|
318 |
if( iEventListenScout )
|
|
319 |
{
|
|
320 |
iEventListenScout->Complete( KErrCancel );
|
|
321 |
delete iEventListenScout;
|
|
322 |
iEventListenScout = NULL;
|
|
323 |
}
|
|
324 |
|
|
325 |
iClientData->EventQueue().StopConsuming();
|
|
326 |
aMessage.Complete( KErrNone );
|
|
327 |
}
|
|
328 |
|
|
329 |
|
|
330 |
// -----------------------------------------------------------------------------
|
|
331 |
// CXIMPContextSession::DoFetchTopEventDataSizeL()
|
|
332 |
// -----------------------------------------------------------------------------
|
|
333 |
//
|
|
334 |
void CXIMPContextSession::DoFetchTopEventDataSizeL(
|
|
335 |
MXIMPSrvMessage& aMessage )
|
|
336 |
{
|
|
337 |
iClientData->EventQueue().SelectTopEventIfNeededL();
|
|
338 |
aMessage.Complete( iClientData->EventQueue().TopEventDataL().Size() );
|
|
339 |
}
|
|
340 |
|
|
341 |
|
|
342 |
// -----------------------------------------------------------------------------
|
|
343 |
// CXIMPContextSession::DoFetchTopEventDataL()
|
|
344 |
// -----------------------------------------------------------------------------
|
|
345 |
//
|
|
346 |
void CXIMPContextSession::DoFetchTopEventDataL(
|
|
347 |
MXIMPSrvMessage& aMessage )
|
|
348 |
{
|
|
349 |
iClientData->EventQueue().SelectTopEventIfNeededL();
|
|
350 |
aMessage.WriteL( MXIMPSrvMessage::Ep0, iClientData->EventQueue().TopEventDataL() );
|
|
351 |
aMessage.Complete( KErrNone );
|
|
352 |
}
|
|
353 |
|
|
354 |
|
|
355 |
// -----------------------------------------------------------------------------
|
|
356 |
// CXIMPContextSession::DoFetchTopEventReqIdL()
|
|
357 |
// -----------------------------------------------------------------------------
|
|
358 |
//
|
|
359 |
void CXIMPContextSession::DoFetchTopEventReqIdL(
|
|
360 |
MXIMPSrvMessage& aMessage )
|
|
361 |
{
|
|
362 |
TPckgBuf< TXIMPRequestId > reqIdBuf;
|
|
363 |
|
|
364 |
iClientData->EventQueue().SelectTopEventIfNeededL();
|
|
365 |
reqIdBuf() = iClientData->EventQueue().TopEventReqIdL();
|
|
366 |
|
|
367 |
aMessage.WriteL( MXIMPSrvMessage::Ep0, reqIdBuf );
|
|
368 |
aMessage.Complete( KErrNone );
|
|
369 |
}
|
|
370 |
|
|
371 |
|
|
372 |
// -----------------------------------------------------------------------------
|
|
373 |
// CXIMPContextSession::DoDropTopEventL()
|
|
374 |
// -----------------------------------------------------------------------------
|
|
375 |
//
|
|
376 |
void CXIMPContextSession::DoDropTopEventL(
|
|
377 |
MXIMPSrvMessage& aMessage )
|
|
378 |
{
|
|
379 |
iClientData->EventQueue().DropTopEvent();
|
|
380 |
aMessage.Complete( KErrNone );
|
|
381 |
}
|
|
382 |
|
|
383 |
|
|
384 |
// -----------------------------------------------------------------------------
|
|
385 |
// CXIMPContextSession::DoPrepareContextFeaturesL()
|
|
386 |
// -----------------------------------------------------------------------------
|
|
387 |
//
|
|
388 |
void CXIMPContextSession::DoPrepareContextFeaturesL(
|
|
389 |
MXIMPSrvMessage& aMessage )
|
|
390 |
{
|
|
391 |
__ASSERT_ALWAYS( !iPreparedData,
|
|
392 |
aMessage.PanicClientAndLeaveL(
|
|
393 |
NXIMPPanic::EOnSrvAlreadyHavingPrepearedData ) );
|
|
394 |
|
|
395 |
|
|
396 |
CXIMPFeatureInfoImp* feats = iClientData->FeaturesForSessionLC();
|
|
397 |
iPreparedData = TXIMPObjectPacker< CXIMPFeatureInfoImp >::PackL( *feats );
|
|
398 |
CleanupStack::PopAndDestroy( feats );
|
|
399 |
|
|
400 |
aMessage.Complete( iPreparedData->Size() );
|
|
401 |
}
|
|
402 |
|
|
403 |
|
|
404 |
// -----------------------------------------------------------------------------
|
|
405 |
// CXIMPContextSession::DoGetPreparedDataL()
|
|
406 |
// -----------------------------------------------------------------------------
|
|
407 |
//
|
|
408 |
void CXIMPContextSession::DoGetPreparedDataL(
|
|
409 |
MXIMPSrvMessage& aMessage )
|
|
410 |
{
|
|
411 |
//Release the prepared data from member variable
|
|
412 |
//Buffer gets cleaned even the copying to client side fails
|
|
413 |
HBufC8* tmpBuf = iPreparedData;
|
|
414 |
iPreparedData = NULL;
|
|
415 |
CleanupStack::PushL( tmpBuf );
|
|
416 |
|
|
417 |
//Assert that there is a data to copy to client
|
|
418 |
__ASSERT_ALWAYS( tmpBuf,
|
|
419 |
aMessage.PanicClientAndLeaveL(
|
|
420 |
NXIMPPanic::EOnSrvNoPrepearedDataToCopy ) );
|
|
421 |
|
|
422 |
aMessage.WriteL( MXIMPSrvMessage::Ep0, *tmpBuf );
|
|
423 |
|
|
424 |
CleanupStack::PopAndDestroy( tmpBuf );
|
|
425 |
aMessage.Complete( KErrNone );
|
|
426 |
}
|
|
427 |
|
|
428 |
|
|
429 |
// End of file
|