|
1 // Copyright (c) 2004-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 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <bluetooth/logger.h> |
|
22 #include "remconclient.h" |
|
23 #include "receiver.h" |
|
24 |
|
25 #ifdef __FLOG_ACTIVE |
|
26 _LIT8(KLogComponent, LOG_COMPONENT_REMCON_IL_RECV); |
|
27 #endif |
|
28 |
|
29 CReceiver* CReceiver::NewL(RRemCon& aRemCon, |
|
30 CRemConInterfaceSelector& aObserver, |
|
31 TUint aMaxDataLength, |
|
32 TRemConClientType aType) |
|
33 { |
|
34 LOG_STATIC_FUNC |
|
35 CReceiver* self = new(ELeave) CReceiver(aRemCon, aObserver, aType); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(aMaxDataLength); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 /** |
|
43 Destructor. |
|
44 */ |
|
45 CReceiver::~CReceiver() |
|
46 { |
|
47 LOG_FUNC |
|
48 Cancel(); |
|
49 |
|
50 iData.Close(); |
|
51 } |
|
52 |
|
53 CReceiver::CReceiver(RRemCon& aRemCon, |
|
54 CRemConInterfaceSelector& aObserver, |
|
55 TRemConClientType aType) |
|
56 : CActive(CActive::EPriorityStandard), |
|
57 iType(aType), |
|
58 iRemCon(aRemCon), |
|
59 iObserver(aObserver) |
|
60 { |
|
61 LOG_FUNC |
|
62 CActiveScheduler::Add(this); |
|
63 } |
|
64 |
|
65 void CReceiver::ConstructL(TUint aMaxDataLength) |
|
66 { |
|
67 iData.CreateL(aMaxDataLength); |
|
68 // NB If a remote sends longer data than we expect to receive here, our |
|
69 // receive will be errored and the message will effectively be dropped in |
|
70 // the intermediate layer. (It won't get passed to the outer layer.) |
|
71 |
|
72 // Start the perpetual receive cycle. |
|
73 Receive(); |
|
74 } |
|
75 |
|
76 void CReceiver::Receive() |
|
77 { |
|
78 LOG_FUNC |
|
79 |
|
80 iRemCon.Receive(iStatus, iReceivePackage, iData); |
|
81 SetActive(); |
|
82 } |
|
83 |
|
84 void CReceiver::RunL() |
|
85 { |
|
86 LOG_FUNC |
|
87 LOG1(_L("\tiStatus = %d"), iStatus.Int()); |
|
88 |
|
89 // Record the result of our last request, because the stuff we |
|
90 // do depends on it, but may also issue further requests. |
|
91 TInt err = iStatus.Int(); |
|
92 |
|
93 if(err == KErrNone) |
|
94 { |
|
95 iObserver.ReceiveComplete(iReceivePackage.iInterfaceUid, |
|
96 iReceivePackage.iOperationId, |
|
97 iReceivePackage.iMessageSubType, |
|
98 iReceivePackage.iRemoteAddress, |
|
99 iData, |
|
100 iType); |
|
101 } |
|
102 else |
|
103 { |
|
104 iObserver.Error(err); |
|
105 } |
|
106 |
|
107 if(err != KErrServerTerminated) |
|
108 { |
|
109 // Repost request. |
|
110 Receive(); |
|
111 } |
|
112 } |
|
113 |
|
114 void CReceiver::DoCancel() |
|
115 { |
|
116 LOG_FUNC |
|
117 |
|
118 // There's nothing we can do about any error here, and it probably |
|
119 // indicates that the server has gone away anyway for some reason. |
|
120 (void)iRemCon.ReceiveCancel(); |
|
121 } |