33
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2007 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: Receiver class for TCP / UDP sockets
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include <es_sock.h>
|
|
22 |
#include "CSatBIPDataReceiver.h"
|
|
23 |
#include "CSatBIPGPRSDataChannel.h"
|
|
24 |
#include "SatLog.h"
|
|
25 |
|
|
26 |
|
|
27 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
28 |
|
|
29 |
// -----------------------------------------------------------------------------
|
|
30 |
// CSatBIPDataReceiver::CSatBIPDataReceiver
|
|
31 |
// C++ default constructor can NOT contain any code, that
|
|
32 |
// might leave.
|
|
33 |
// -----------------------------------------------------------------------------
|
|
34 |
//
|
|
35 |
CSatBIPDataReceiver::CSatBIPDataReceiver( CSatBIPGPRSDataChannel& aObserver,
|
|
36 |
RSocket& aSocket,
|
|
37 |
TBool aIsTcpSocket ) : CActive( EPriorityNormal ),
|
|
38 |
iObserver( aObserver ),
|
|
39 |
iSocket( aSocket ),
|
|
40 |
iReceiveDataLen( 0 ),
|
|
41 |
iRecvPckg( iReceiveDataLen )
|
|
42 |
{
|
|
43 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::CSatBIPDataReceiver\
|
|
44 |
calling-exiting" )
|
|
45 |
|
|
46 |
iIsTcpSocket = aIsTcpSocket;
|
|
47 |
|
|
48 |
CActiveScheduler::Add( this );
|
|
49 |
}
|
|
50 |
|
|
51 |
// -----------------------------------------------------------------------------
|
|
52 |
// CSatBIPDataReceiver::~CSatBIPDataReceiver
|
|
53 |
// Destructor
|
|
54 |
// -----------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
CSatBIPDataReceiver::~CSatBIPDataReceiver()
|
|
57 |
{
|
|
58 |
LOG( SIMPLE,
|
|
59 |
"SATENGINE: CSatBIPDataReceiver::~CSatBIPDataReceiver calling" )
|
|
60 |
// Don't have our own pointers...
|
|
61 |
LOG( SIMPLE,
|
|
62 |
"SATENGINE: CSatBIPDataReceiver::~CSatBIPDataReceiver exiting" )
|
|
63 |
}
|
|
64 |
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
// CSatBIPDataReceiver::RunL
|
|
67 |
// Two-phased constructor.
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
//
|
|
70 |
void CSatBIPDataReceiver::RunL()
|
|
71 |
{
|
|
72 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::RunL calling" )
|
|
73 |
|
|
74 |
LOG2( NORMAL, " RunL with error: %i", iStatus.Int() )
|
|
75 |
LOG2( NORMAL, " RunL Data received <buffer>: %i", iRecvBuffer.Length() )
|
|
76 |
|
|
77 |
// Notify observer
|
|
78 |
if ( KErrNone == iStatus.Int() )
|
|
79 |
{
|
|
80 |
iObserver.DataReceivedNotificationL( iRecvBuffer );
|
|
81 |
}
|
|
82 |
else
|
|
83 |
{
|
|
84 |
iObserver.DataReceiveError( iStatus.Int() );
|
|
85 |
}
|
|
86 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::RunL exiting" )
|
|
87 |
}
|
|
88 |
|
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
// CSatBIPDataReceiver::DoCancel
|
|
91 |
// Two-phased constructor.
|
|
92 |
// -----------------------------------------------------------------------------
|
|
93 |
//
|
|
94 |
void CSatBIPDataReceiver::DoCancel()
|
|
95 |
{
|
|
96 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::DoCancel calling" )
|
|
97 |
iSocket.CancelRecv();
|
|
98 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::DoCancel exiting" )
|
|
99 |
}
|
|
100 |
|
|
101 |
// -----------------------------------------------------------------------------
|
|
102 |
// CSatBIPDataReceiver::ReceiveStoreEmptyNotification
|
|
103 |
// -----------------------------------------------------------------------------
|
|
104 |
//
|
|
105 |
void CSatBIPDataReceiver::ReceiveStoreEmptyNotificationL()
|
|
106 |
{
|
|
107 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::ReceiveStoreEmptyNotification\
|
|
108 |
calling" )
|
|
109 |
// It doesn't matter, if this buffer is empty
|
|
110 |
iObserver.DataReceivedNotificationL( iRecvBuffer );
|
|
111 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::ReceiveStoreEmptyNotification\
|
|
112 |
exiting" )
|
|
113 |
}
|
|
114 |
|
|
115 |
// -----------------------------------------------------------------------------
|
|
116 |
// CSatBIPDataReceiver::StartReceive
|
|
117 |
// Starts to receive data
|
|
118 |
// -----------------------------------------------------------------------------
|
|
119 |
//
|
|
120 |
void CSatBIPDataReceiver::StartReceive( TInetAddr& aAddr )
|
|
121 |
{
|
|
122 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::StartReceive calling" )
|
|
123 |
|
|
124 |
// It may already be active
|
|
125 |
if ( !IsActive() )
|
|
126 |
{
|
|
127 |
// This is used only with TCP sockets
|
|
128 |
iReceiveDataLen = 0;
|
|
129 |
// Remove previously received data
|
|
130 |
iRecvBuffer.Zero();
|
|
131 |
// Check the socket type
|
|
132 |
if ( iIsTcpSocket )
|
|
133 |
{
|
|
134 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::StartReceive TCP" )
|
|
135 |
// Only TCP / Stream socket may receive one or more bytes
|
|
136 |
iSocket.RecvOneOrMore( iRecvBuffer, 0, iStatus, iRecvPckg );
|
|
137 |
}
|
|
138 |
else
|
|
139 |
{
|
|
140 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::StartReceive UDP" )
|
|
141 |
// Use different receive method with UPD / Datagram socket
|
|
142 |
// Destination has already been stored in iSocket during
|
|
143 |
// activation,
|
|
144 |
// so we don't have to tell it here.
|
|
145 |
iSocket.RecvFrom( iRecvBuffer, aAddr, 0, iStatus );
|
|
146 |
}
|
|
147 |
SetActive();
|
|
148 |
}
|
|
149 |
LOG( SIMPLE, "SATENGINE: CSatBIPDataReceiver::StartReceive exiting" )
|
|
150 |
}
|
|
151 |
|
|
152 |
// End of file
|