|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "CTcMCEReceiveQueue.h" |
|
21 #include "CTcMCEReceived.h" |
|
22 #include "CTcMCEContext.h" |
|
23 |
|
24 CTcMCEReceiveQueue* CTcMCEReceiveQueue::NewL( CTcMCEContext& aContext ) |
|
25 { |
|
26 CTcMCEReceiveQueue* self = new (ELeave) CTcMCEReceiveQueue( aContext ); |
|
27 |
|
28 CleanupStack::PushL( self ); |
|
29 self->ConstructL(); |
|
30 CleanupStack::Pop( self ); |
|
31 |
|
32 return self; |
|
33 } |
|
34 |
|
35 CTcMCEReceiveQueue::CTcMCEReceiveQueue( CTcMCEContext& aContext ) : |
|
36 iReceiveQueue( 1 ), |
|
37 iContext( aContext ) |
|
38 { |
|
39 } |
|
40 |
|
41 void CTcMCEReceiveQueue::ConstructL() |
|
42 { |
|
43 iTimer = CDeltaTimer::NewL( CActive::EPriorityStandard ); |
|
44 TCallBack cb( ReceiveTimeout, this ); |
|
45 iReceiveTimeout.Set( cb ); |
|
46 } |
|
47 |
|
48 CTcMCEReceiveQueue::~CTcMCEReceiveQueue() |
|
49 { |
|
50 delete iTimer; |
|
51 iReceiveQueue.Reset(); |
|
52 } |
|
53 |
|
54 |
|
55 // -- Received queue handling ------------------------------------------------- |
|
56 |
|
57 CTcMCEReceived& CTcMCEReceiveQueue::ReceivedItemL( TInt aTimeout ) |
|
58 { |
|
59 if( iReceiveQueue.Count() == 0 ) |
|
60 { |
|
61 iTimer->Queue( aTimeout * KSecondAsMicros, iReceiveTimeout ); |
|
62 iActiveWait.Start(); |
|
63 } |
|
64 |
|
65 // Check if the queue is still empty (i.e. timeout occurred) |
|
66 if( iReceiveQueue.Count() == 0 ) |
|
67 { |
|
68 User::Leave( KErrTimedOut ); |
|
69 } |
|
70 |
|
71 // Get the first (oldest) item from the array |
|
72 TBuf8< KTcMaxObjectName > itemName = iReceiveQueue[ 0 ]; |
|
73 |
|
74 // ..and remove it from the array |
|
75 iReceiveQueue.Delete( 0 ); |
|
76 iReceiveQueue.Compress(); |
|
77 |
|
78 // Fetch the corresponding object from the registry |
|
79 CTcMCEReceived* item = |
|
80 reinterpret_cast<CTcMCEReceived*> |
|
81 (iContext.Registry().ObjectPtrL( itemName )); |
|
82 |
|
83 return *item; |
|
84 |
|
85 } |
|
86 |
|
87 void CTcMCEReceiveQueue::QueueReceivedL( CTcMCEReceived* aItem ) |
|
88 { |
|
89 // Add to registry and fetch name |
|
90 iContext.Registry().AddObjectL( reinterpret_cast< CBase* >( aItem ) ); |
|
91 TBuf8< KTcMaxObjectName > itemName = |
|
92 iContext.Registry().ObjectNameL( aItem ); |
|
93 |
|
94 // Add name to queue |
|
95 iReceiveQueue.AppendL( itemName ); |
|
96 |
|
97 if( iActiveWait.IsStarted() ) |
|
98 { |
|
99 iTimer->Remove( iReceiveTimeout ); |
|
100 iActiveWait.AsyncStop(); |
|
101 } |
|
102 |
|
103 } |
|
104 |
|
105 TInt CTcMCEReceiveQueue::ReceiveTimeout( TAny* aSelf ) |
|
106 { |
|
107 CTcMCEReceiveQueue& self = |
|
108 *reinterpret_cast< CTcMCEReceiveQueue* >( aSelf ); |
|
109 if( self.iActiveWait.IsStarted() ) |
|
110 { |
|
111 self.iActiveWait.AsyncStop(); |
|
112 } |
|
113 |
|
114 return KErrNone; |
|
115 } |