|
1 // Copyright (c) 2002-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 // Implements the active object that controls the Write() requests. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include "Sender.h" |
|
23 #include "Constants.h" |
|
24 |
|
25 CSender::CSender(CBcaIoController& aObserver, CBttLogger* aTheLogger) |
|
26 /** |
|
27 * Constructor. Performs standard active object initialisation. |
|
28 * |
|
29 * @param aObserver Reference to the observer of this state machine |
|
30 */ |
|
31 : CActive(EPriorityNormal), |
|
32 iObserver(aObserver), |
|
33 iTheLogger(aTheLogger) |
|
34 { |
|
35 CActiveScheduler::Add(this); |
|
36 } |
|
37 |
|
38 CSender::~CSender() |
|
39 /** |
|
40 * Destructor. |
|
41 */ |
|
42 { |
|
43 Cancel(); |
|
44 } |
|
45 |
|
46 void CSender::RunL() |
|
47 /** |
|
48 * This method checks if any error occured in the write operation. |
|
49 */ |
|
50 { |
|
51 _LOG_L1C2(_L8("CSender::RunL [iStatus=%d]"), iStatus.Int()); |
|
52 |
|
53 if (iStatus!=KErrNone) |
|
54 { |
|
55 if(iStatus == KErrNoMemory) |
|
56 { |
|
57 _LOG_L2C1(_L8("WARNING! CSender: Write failed with KErrNoMemory")); |
|
58 _LOG_L2C1(_L8("WARNING! CSender: Ignoring packet!!!!")); |
|
59 // Write operation failed!! Nif will ignore this packet. |
|
60 iObserver.SendComplete(); |
|
61 } |
|
62 else if (iStatus == KErrNotReady) |
|
63 { |
|
64 _LOG_L2C1(_L8("WARNING! CSender: Write failed with KErrNotReady")); |
|
65 _LOG_L2C1(_L8("WARNING! CSender: Ignoring packet!!!!")); |
|
66 // Write operation failed!! Nif will ignore this packet. |
|
67 iObserver.SendComplete(); |
|
68 } |
|
69 else |
|
70 { |
|
71 _LOG_L2C1(_L8("ERROR! CSender: Write failed!!!!")); |
|
72 // Nif will shut down |
|
73 iObserver.Stop(iStatus.Int()); |
|
74 } |
|
75 return; |
|
76 } |
|
77 |
|
78 else |
|
79 { |
|
80 // The Ip packet was sent successfuly |
|
81 _LOG_L1C1(_L8("***** CSender: Packet Sent.")); |
|
82 iObserver.SendComplete(); |
|
83 } |
|
84 } |
|
85 |
|
86 void CSender::DoCancel() |
|
87 /** |
|
88 * Cancel active request |
|
89 */ |
|
90 { |
|
91 _LOG_L1C1(_L8("CSender::DoCancel")); |
|
92 |
|
93 (iObserver.Bca())->CancelWrite(); |
|
94 } |
|
95 |
|
96 void CSender::Send(RMBufChain& aPdu) |
|
97 /** |
|
98 * Copies the specified RMBufChain into a descriptor and sends it. |
|
99 * |
|
100 * @param aPdu The IP packet to be sent. |
|
101 * @return KStopSending, or KErrArgument if the packet is too large. |
|
102 */ |
|
103 { |
|
104 _LOG_L1C1(_L8("CSender::Send")); |
|
105 |
|
106 // Copy the IP portion of the RMBufChain to the buffer. |
|
107 iSendBuffer.SetMax(); |
|
108 aPdu.CopyOut(iSendBuffer, aPdu.First()->Length()); |
|
109 |
|
110 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
111 iObserver.AddHeader(iSendBuffer); |
|
112 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|
113 |
|
114 aPdu.Free(); |
|
115 |
|
116 SendBuffer(iSendBuffer); |
|
117 } |
|
118 |
|
119 void CSender::SendBuffer(const TDesC8& aBuffer) |
|
120 /** |
|
121 * Sends an IP packet, contained in the specified descriptor |
|
122 * |
|
123 * @param aBuffer The IP packet to send. |
|
124 * @return Always KStopSending. |
|
125 */ |
|
126 { |
|
127 _LOG_L1C1(_L8("CSender::SendBuffer")); |
|
128 |
|
129 // Finally, send the packet to BCA |
|
130 (iObserver.Bca())->Write(iStatus, aBuffer); |
|
131 SetActive(); |
|
132 } |