|
1 /* |
|
2 * Copyright (c) 2006-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: Abstract socket receiver |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "cncmreceiver.h" |
|
22 #include "mncmreceiversenderobserver.h" |
|
23 #include "ncmconnectionmultiplexerlogs.h" |
|
24 |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // CNcmReceiver::CNcmReceiver |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CNcmReceiver::CNcmReceiver( RSocket& aSocket, |
|
31 MNcmReceiverSenderObserver& aObserver ) : |
|
32 CActive( EPriorityStandard ), iSocket( aSocket ), iObserver( aObserver ), |
|
33 iFromAddr( KInetAddrNone, 0 ) |
|
34 { |
|
35 CActiveScheduler::Add( this ); |
|
36 } |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CNcmReceiver::~CNcmReceiver |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CNcmReceiver::~CNcmReceiver() |
|
44 { |
|
45 __CONNECTIONMULTIPLEXER( "CNcmReceiver::~CNcmReceiver" ) |
|
46 |
|
47 Cancel(); |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CNcmReceiver::Message |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 TDesC8& CNcmReceiver::Message() |
|
56 { |
|
57 return iBuffer; |
|
58 } |
|
59 |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // CNcmReceiver::FromAddress |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 const TInetAddr& CNcmReceiver::FromAddress() const |
|
66 { |
|
67 return iFromAddr; |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // From class CActive |
|
73 // |
|
74 // CNcmReceiver::RunL |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CNcmReceiver::RunL() |
|
78 { |
|
79 __CONNECTIONMULTIPLEXER_INT1( "CNcmReceiver::RunL", iStatus.Int() ) |
|
80 |
|
81 switch( iStatus.Int() ) |
|
82 { |
|
83 case KErrNone: |
|
84 iObserver.MessageAvailable(); |
|
85 DoReceive(); |
|
86 break; |
|
87 case KErrEof: |
|
88 // Connection closed, nothing to do |
|
89 iObserver.Error( KErrDisconnected ); |
|
90 break; |
|
91 default: |
|
92 iObserver.Error( iStatus.Int() ); |
|
93 } |
|
94 } |
|
95 |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // From class CActive |
|
99 // |
|
100 // CNcmReceiver::RunL |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 void CNcmReceiver::DoCancel() |
|
104 { |
|
105 __CONNECTIONMULTIPLEXER( "CNcmReceiver::DoCancel" ) |
|
106 |
|
107 iSocket.CancelRecv(); |
|
108 } |
|
109 |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CNcmReceiver::Activate |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CNcmReceiver::Activate() |
|
116 { |
|
117 DoReceive(); |
|
118 } |
|
119 |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CNcmReceiver::Deactivate |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CNcmReceiver::Deactivate() |
|
126 { |
|
127 Cancel(); |
|
128 } |