24
|
1 |
// Copyright (c) 2002-2010 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 |
#include <es_ini.h>
|
|
25 |
|
|
26 |
|
|
27 |
CSender::CSender(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise)
|
|
28 |
/**
|
|
29 |
* Constructor. Performs standard active object initialisation.
|
|
30 |
*
|
|
31 |
* @param aObserver Reference to the observer of this state machine
|
|
32 |
*/
|
|
33 |
: CActive(EPriorityUserInput),
|
|
34 |
iObserver(aObserver),
|
|
35 |
iTheLogger(aTheLogger),
|
|
36 |
iMaxPacketSize(aMaxPacketSise)
|
|
37 |
{
|
|
38 |
// EPriorityUserInput is higher than the default priority but lower than
|
|
39 |
// EPriorityHigh which is used on Receiving (DL having priority), however,
|
|
40 |
// we want this to be handled in an expedited manner compared to other
|
|
41 |
// active objects in the thread.
|
|
42 |
CActiveScheduler::Add(this);
|
|
43 |
}
|
|
44 |
|
|
45 |
CSender* CSender::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise)
|
|
46 |
/**
|
|
47 |
* Two-phase constructor. Creates a new CBcaIoController object, performs
|
|
48 |
* second-phase construction, then returns it.
|
|
49 |
*
|
|
50 |
* @param aObserver The observer, to which events will be reported
|
|
51 |
* @param aTheLogger The logging object
|
|
52 |
* @return A newly constructed CBcaIoController object
|
|
53 |
*/
|
|
54 |
{
|
|
55 |
CSender* self = new (ELeave) CSender(aObserver, aTheLogger, aMaxPacketSise);
|
|
56 |
CleanupStack::PushL(self);
|
|
57 |
self->ConstructL();
|
|
58 |
CleanupStack::Pop(self);
|
|
59 |
return self;
|
|
60 |
}
|
|
61 |
|
|
62 |
void CSender::ConstructL()
|
|
63 |
/**
|
|
64 |
* Second-phase constructor. Creates all the state objects it owns.
|
|
65 |
*/
|
|
66 |
{
|
|
67 |
_LOG_L1C1(_L8("CSender::ConstructL"));
|
|
68 |
iSendBuffer.CreateL(iMaxPacketSize);
|
|
69 |
}
|
|
70 |
|
|
71 |
CSender::~CSender()
|
|
72 |
/**
|
|
73 |
* Destructor.
|
|
74 |
*/
|
|
75 |
{
|
|
76 |
iSendBuffer.Close();
|
|
77 |
Cancel();
|
|
78 |
}
|
|
79 |
|
|
80 |
void CSender::RunL()
|
|
81 |
/**
|
|
82 |
* This method checks if any error occured in the write operation.
|
|
83 |
*/
|
|
84 |
{
|
|
85 |
_LOG_L1C2(_L8("CSender::RunL [iStatus=%d]"), iStatus.Int());
|
|
86 |
|
|
87 |
if (iStatus!=KErrNone)
|
|
88 |
{
|
|
89 |
if(iStatus == KErrNoMemory)
|
|
90 |
{
|
|
91 |
_LOG_L2C1(_L8("WARNING! CSender: Write failed with KErrNoMemory"));
|
|
92 |
_LOG_L2C1(_L8("WARNING! CSender: Ignoring packet!!!!"));
|
|
93 |
// Write operation failed!! Nif will ignore this packet.
|
|
94 |
iObserver.SendComplete();
|
|
95 |
}
|
|
96 |
else if (iStatus == KErrNotReady)
|
|
97 |
{
|
|
98 |
_LOG_L2C1(_L8("WARNING! CSender: Write failed with KErrNotReady"));
|
|
99 |
_LOG_L2C1(_L8("WARNING! CSender: Ignoring packet!!!!"));
|
|
100 |
// Write operation failed!! Nif will ignore this packet.
|
|
101 |
iObserver.SendComplete();
|
|
102 |
}
|
|
103 |
else
|
|
104 |
{
|
|
105 |
_LOG_L2C1(_L8("ERROR! CSender: Write failed!!!!"));
|
|
106 |
// Nif will shut down
|
|
107 |
iObserver.Stop(iStatus.Int());
|
|
108 |
}
|
|
109 |
return;
|
|
110 |
}
|
|
111 |
|
|
112 |
else
|
|
113 |
{
|
|
114 |
// The Ip packet was sent successfuly
|
|
115 |
_LOG_L1C1(_L8("***** CSender: Packet Sent."));
|
|
116 |
iObserver.SendComplete();
|
|
117 |
}
|
|
118 |
}
|
|
119 |
|
|
120 |
void CSender::DoCancel()
|
|
121 |
/**
|
|
122 |
* Cancel active request
|
|
123 |
*/
|
|
124 |
{
|
|
125 |
_LOG_L1C1(_L8("CSender::DoCancel"));
|
|
126 |
|
|
127 |
(iObserver.Bca())->CancelWrite();
|
|
128 |
}
|
|
129 |
|
|
130 |
void CSender::Send(RMBufChain& aPdu)
|
|
131 |
/**
|
|
132 |
* Copies the specified RMBufChain into a descriptor and sends it.
|
|
133 |
*
|
|
134 |
* @param aPdu The IP packet to be sent.
|
|
135 |
* @return KStopSending, or KErrArgument if the packet is too large.
|
|
136 |
*/
|
|
137 |
{
|
|
138 |
_LOG_L1C1(_L8("CSender::Send"));
|
|
139 |
|
|
140 |
// Copy the IP portion of the RMBufChain to the buffer.
|
|
141 |
iSendBuffer.SetMax();
|
|
142 |
aPdu.CopyOut(iSendBuffer, aPdu.First()->Length());
|
|
143 |
|
|
144 |
#ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
145 |
iObserver.AddHeader(iSendBuffer);
|
|
146 |
#endif // RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
147 |
|
|
148 |
aPdu.Free();
|
|
149 |
|
|
150 |
(iObserver.Bca())->Write(iStatus, iSendBuffer);
|
|
151 |
|
|
152 |
SetActive();
|
|
153 |
}
|
|
154 |
|