|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32base.h> |
|
20 #include <e32debug.h> |
|
21 #include <e32cons.h> |
|
22 #include <badesca.h> |
|
23 #include <sdpconnectionfield.h> |
|
24 #include <sdpmediafield.h> |
|
25 #include "nsptestconsolecenrep.h" |
|
26 #include "nsptestconsolestream.h" |
|
27 |
|
28 _LIT8( KLocalAddr, "192.168.0.2" ); |
|
29 const TUint KLocalPort = 8000; |
|
30 |
|
31 #define __PANIC( aError ) User::Panic( _L( "NSP Test console stream" ), aError ) |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CTestConsoleStream::NewL |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CTestConsoleStream* CTestConsoleStream::NewL() |
|
38 { |
|
39 CTestConsoleStream* self = CTestConsoleStream::NewLC(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CTestConsoleStream::NewLC |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CTestConsoleStream* CTestConsoleStream::NewLC() |
|
49 { |
|
50 CTestConsoleStream* self = new ( ELeave ) CTestConsoleStream(); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CTestConsoleStream::CTestConsoleStream |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CTestConsoleStream::CTestConsoleStream() |
|
61 : iLocalPort( KLocalPort ) |
|
62 { |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CTestConsoleStream::ConstructL |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CTestConsoleStream::ConstructL() |
|
70 { |
|
71 iLocalAddress = KLocalAddr().AllocL(); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CTestConsoleStream::~CTestConsoleStream |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CTestConsoleStream::~CTestConsoleStream() |
|
79 { |
|
80 delete iLocalAddress; |
|
81 delete iRemoteAddress; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CTestConsoleStream::EncodeL |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 TInt CTestConsoleStream::EncodeL( CSdpMediaField& aMediaField ) |
|
89 { |
|
90 __ASSERT_ALWAYS( &aMediaField, User::Leave( KErrArgument ) ); |
|
91 |
|
92 CSdpConnectionField* connField = |
|
93 ( aMediaField.ConnectionFields().Count() ? |
|
94 aMediaField.ConnectionFields()[0] : NULL ); |
|
95 |
|
96 if ( iLocalAddress && connField ) |
|
97 { |
|
98 connField->SetAddressL( connField->NetType(), |
|
99 connField->AddressType(), iLocalAddress->Des() ); |
|
100 } |
|
101 |
|
102 aMediaField.SetPortL( iLocalPort ); |
|
103 |
|
104 return KErrNone; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CTestConsoleStream::DecodeL |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 TInt CTestConsoleStream::DecodeL( CSdpMediaField& aMediaField ) |
|
112 { |
|
113 __ASSERT_ALWAYS( &aMediaField, User::Leave( KErrArgument ) ); |
|
114 |
|
115 CSdpConnectionField* connField = |
|
116 ( aMediaField.ConnectionFields().Count() ? |
|
117 aMediaField.ConnectionFields()[0] : NULL ); |
|
118 |
|
119 iRemoteAddress = ( connField ? connField->Address().AllocL() : NULL ); |
|
120 |
|
121 iRemotePort = aMediaField.Port(); |
|
122 |
|
123 return KErrNone; |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CTestConsoleStream::Start |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 TInt CTestConsoleStream::Start() |
|
131 { |
|
132 return KErrNotSupported; |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CTestConsoleStream::Stop |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 TInt CTestConsoleStream::Stop() |
|
140 { |
|
141 return KErrNotSupported; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CTestConsoleStream::LocalAddress |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 const TDesC8& CTestConsoleStream::LocalAddress() const |
|
149 { |
|
150 return *iLocalAddress; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CTestConsoleStream::RemoteAddress |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 const TDesC8& CTestConsoleStream::RemoteAddress() const |
|
158 { |
|
159 return *iRemoteAddress; |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CTestConsoleStream::LocalPort |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 TUint CTestConsoleStream::LocalPort() const |
|
167 { |
|
168 return iLocalPort; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CTestConsoleStream::RemotePort |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 TUint CTestConsoleStream::RemotePort() const |
|
176 { |
|
177 return iRemotePort; |
|
178 } |