|
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: fcsender.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <in_sock.h> |
|
23 #include "fcsender.h" |
|
24 #include "fcconnectioncontainer.h" |
|
25 #include "fcnotifier.h" |
|
26 |
|
27 const TInt KSendBufferLen = 10; |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CFCSender::NewL |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CFCSender* CFCSender::NewL(RSocket& aSocket, MFCNotifier& aNotifier) |
|
34 { |
|
35 CFCSender* self = new (ELeave) CFCSender(aSocket, aNotifier); |
|
36 CleanupStack::PushL(self); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CFCSender::CFCSender |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CFCSender::CFCSender(RSocket& aSocket, MFCNotifier& aNotifier) : |
|
46 CActive(EPriorityStandard), |
|
47 iFCNotifier( aNotifier ) |
|
48 { |
|
49 iSocket = &aSocket; |
|
50 CActiveScheduler::Add(this); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CFCSender::~CFCSender |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CFCSender::~CFCSender() |
|
58 { |
|
59 Cancel(); |
|
60 delete iData; |
|
61 iSendBuffer.ResetAndDestroy(); |
|
62 iSendBuffer.Close(); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CFCSender::SendL |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CFCSender::SendL (HBufC8* aData, |
|
70 TInetAddr& aAddr) |
|
71 { |
|
72 if (!IsActive() && iConnected ) |
|
73 { |
|
74 iData = aData; |
|
75 iOutgoingData.Set(*iData); |
|
76 iSocket->SendTo(iOutgoingData, aAddr, 0, iStatus); |
|
77 SetActive(); |
|
78 } |
|
79 else |
|
80 { |
|
81 User::LeaveIfError( iSendBuffer.Count() <= KSendBufferLen ? |
|
82 KErrNone : KErrNotReady ); |
|
83 iRemoteAddr = aAddr; |
|
84 iSendBuffer.AppendL(aData); |
|
85 } |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CFCSender::ConnectedL |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CFCSender::ConnectedL() |
|
93 { |
|
94 iConnected = ETrue; |
|
95 SendFromBufferL(); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CFCSender::RunL |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CFCSender::RunL () |
|
103 { |
|
104 TInt err = iStatus.Int(); |
|
105 if (err == KErrNoMemory) |
|
106 { |
|
107 // This will leave to RunError-function. See below. |
|
108 User::Leave(err); |
|
109 } |
|
110 if (err != KErrNone) |
|
111 { |
|
112 iFCNotifier.ErrorNotify(iStatus.Int()); |
|
113 } |
|
114 delete iData; |
|
115 iData = 0; |
|
116 |
|
117 SendFromBufferL(); |
|
118 |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CFCSender::DoCancel |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void CFCSender::DoCancel () |
|
126 { |
|
127 iSocket->CancelSend(); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CFCSender::RunError |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CFCSender::RunError (TInt aError) |
|
135 { |
|
136 if(aError != KErrNoMemory) |
|
137 { |
|
138 return KErrNone; |
|
139 } |
|
140 return aError; |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CFCSender::RunError |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void CFCSender::SendFromBufferL() |
|
148 { |
|
149 if (iSendBuffer.Count() > 0) |
|
150 { |
|
151 HBufC8* data = iSendBuffer[0]; |
|
152 iSendBuffer.Remove(0); |
|
153 SendL(data, iRemoteAddr); |
|
154 } |
|
155 } |
|
156 |