|
1 /* |
|
2 * Copyright (c) 2005-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: fcreceiver.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "fcreceiver.h" |
|
22 |
|
23 // ----------------------------------------------------------------------------- |
|
24 // CFCReceiver::NewL |
|
25 // ----------------------------------------------------------------------------- |
|
26 // |
|
27 CFCReceiver* CFCReceiver::NewL(RSocket& aSocket, MFCNotifier& aMFCNotifier) |
|
28 { |
|
29 CFCReceiver* self = NewLC(aSocket, aMFCNotifier); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CFCReceiver::NewLC |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CFCReceiver* CFCReceiver::NewLC(RSocket& aSocket, MFCNotifier& aMFCNotifier) |
|
39 { |
|
40 CFCReceiver* self = new(ELeave) CFCReceiver(aSocket, aMFCNotifier); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CFCReceiver::ConstructL |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CFCReceiver::ConstructL() |
|
51 { |
|
52 iReceivedMsg = HBufC8::NewL(KMaxMessageLength); |
|
53 CActiveScheduler::Add(this); |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CFCReceiver::CFCReceiver |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CFCReceiver::CFCReceiver(RSocket& aSocket, MFCNotifier& aMFCNotifier) |
|
61 : CActive(EPriorityStandard), |
|
62 iFCNotifier(aMFCNotifier), |
|
63 iReceivedMsgPtr(0,0,0), |
|
64 iSocket(aSocket) |
|
65 { |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CFCReceiver::~CFCReceiver |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CFCReceiver::~CFCReceiver() |
|
73 { |
|
74 delete iReceivedMsg; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CFCReceiver::DoCancel |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CFCReceiver::DoCancel() |
|
82 { |
|
83 iSocket.CancelRecv(); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CFCReceiver::Listen |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CFCReceiver::Listen() |
|
91 { |
|
92 if(!IsActive()) |
|
93 { |
|
94 iReceivedMsgPtr.Set (iReceivedMsg->Des()); |
|
95 iSocket.RecvFrom(iReceivedMsgPtr, iAddr, 0, iStatus); |
|
96 SetActive(); |
|
97 } |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CFCReceiver::RunL |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CFCReceiver::RunL() |
|
105 { |
|
106 switch(iStatus.Int()) |
|
107 { |
|
108 case KErrNone: |
|
109 { |
|
110 HBufC8* data = HBufC8::NewL(iReceivedMsg->Length()); |
|
111 TPtr8 cptr = data->Des(); |
|
112 cptr.Copy(*iReceivedMsg); |
|
113 ReceivedData(data); |
|
114 Listen(); |
|
115 break; |
|
116 } |
|
117 case KErrCancel: |
|
118 break; |
|
119 case KErrNoMemory: |
|
120 { |
|
121 User::Leave(iStatus.Int()); |
|
122 break; |
|
123 } |
|
124 default: |
|
125 |
|
126 iFCNotifier.ErrorNotify(iStatus.Int()); |
|
127 break; |
|
128 } |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CFCReceiver::ReceivedDataL |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CFCReceiver::ReceivedData(HBufC8* aData) |
|
136 { |
|
137 iFCNotifier.ReceivedData(aData) ; |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CFCReceiver::RunError |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 TInt CFCReceiver::RunError(TInt aError) |
|
145 { |
|
146 Listen(); |
|
147 if (aError != KErrNoMemory) |
|
148 { |
|
149 return KErrNone; |
|
150 } |
|
151 return aError; |
|
152 } |