|
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 <ss_glob.h> |
|
19 #include <comms-infras/ss_thread.h> |
|
20 #include <comms-infras/ss_nodemessages_factory.h> |
|
21 #include <comms-infras/ss_nodemessages_dataclient.h> |
|
22 #include "ptcpservertests.h" |
|
23 #include "upnp_cf_msgs.h" |
|
24 #include "upnpflowbase.h" |
|
25 #include "upnpflowfactory.h" |
|
26 |
|
27 #include "CTcpServerTestCase.h" |
|
28 |
|
29 using namespace Messages; |
|
30 |
|
31 const TUint KHttpDefaultPort = 80; |
|
32 |
|
33 //------------------------------------------------------------// |
|
34 /////////////////// CTcpServerTestCase ///////////////////////// |
|
35 ////// Testcase: Send the test data from the test client///////// |
|
36 //------------------------------------------------------------// |
|
37 |
|
38 /* |
|
39 CTcpServerTestCase* CTcpServerTestCase::NewL ( CProxyProvd* aProvd ) |
|
40 { |
|
41 CTcpServerTestCase* ret = new ( ELeave ) CTcpServerTestCase ( aProvd ); |
|
42 CleanupStack::PushL ( ret ); |
|
43 ret->ConstructL (); |
|
44 CleanupStack::Pop ( ret ); |
|
45 return ret; |
|
46 } |
|
47 */ |
|
48 |
|
49 CTcpServerTestCase::CTcpServerTestCase ( CProxyProvd* aProvd ) : |
|
50 CTcpServerTestBase ( aProvd ), iSocketHandler ( *this ), iHostAddr ( KInetAddrLoop, KHttpDefaultPort ), iState ( ECreateServer ) |
|
51 { |
|
52 } |
|
53 |
|
54 CTcpServerTestCase::~CTcpServerTestCase () |
|
55 { |
|
56 iServiceUri.Close (); |
|
57 |
|
58 iSocketHandler.CancelAll (); |
|
59 iClientSocket.Close (); |
|
60 delete iSocketOpener; |
|
61 |
|
62 iTimer.Close (); |
|
63 |
|
64 TUpnpMessage::DeRegister (); |
|
65 } |
|
66 |
|
67 void CTcpServerTestCase::ConstructL (const TDesC8& aDes) |
|
68 { |
|
69 TUpnpMessage::RegisterL ( SockManGlobals::Get ()->SelfWorker ()); |
|
70 |
|
71 iServiceUri.CreateL ( aDes ); |
|
72 |
|
73 iTimer.CreateLocal (); |
|
74 TRAPD ( err, iSocketOpener = CSocketOpener::NewL ( *this ) ); |
|
75 |
|
76 User::LeaveIfError ( err ); |
|
77 } |
|
78 |
|
79 TVerdict CTcpServerTestCase::RunTestL () |
|
80 { |
|
81 switch ( iState ) |
|
82 { |
|
83 case ECreateServer: |
|
84 { |
|
85 const TUint8* uriPtr = NULL; |
|
86 uriPtr = iServiceUri.Ptr (); |
|
87 |
|
88 const TUid reqUid = { CUPnPFlowFactory::iUid }; |
|
89 THttpServerFlowQuery flowQuery ( uriPtr, |
|
90 iServiceUri.Size (), |
|
91 Id (), |
|
92 EHttpServerFlow, iChunkManager ); |
|
93 TCFPlayerRole playerRole ( TCFPlayerRole::EDataPlane ); |
|
94 |
|
95 TCFFactory::TFindOrCreatePeer msg ( TCFPlayerRole::EDataPlane, reqUid, &flowQuery ); |
|
96 TNodeId factoryContainer = SockManGlobals::Get()->GetPlaneFC( playerRole ); |
|
97 |
|
98 RClientInterface::OpenPostMessageClose ( Id (), TNodeCtxId ( KActivityNull, factoryContainer ), TCFFactory::TFindOrCreatePeer ( TCFPlayerRole::EDataPlane, reqUid, &flowQuery ).CRef () ); |
|
99 |
|
100 iState = EStartServer; |
|
101 iStatus = KRequestPending; |
|
102 Reschedule (); |
|
103 return EPass; |
|
104 } |
|
105 |
|
106 case EStartServer: |
|
107 { |
|
108 |
|
109 iLogger.WriteFormat(_L("<i>Start Server..... </i>")); |
|
110 RClientInterface::OpenPostMessageClose ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iTcpServer ), TCFDataClient::TStart ().CRef () ); |
|
111 |
|
112 iState = EOpenClientSocketAndConnect; |
|
113 iStatus = KRequestPending; |
|
114 Reschedule (); |
|
115 return EPass; |
|
116 } |
|
117 |
|
118 case EOpenClientSocketAndConnect: |
|
119 { |
|
120 iLogger.WriteFormat(_L("<i>MakeSocket..... </i>")); |
|
121 iSocketOpener->MakeSocket ( KAfInet, KSockStream, KProtocolInetTcp ); |
|
122 |
|
123 iState = ESendData; |
|
124 iStatus = KRequestPending; |
|
125 Reschedule (); |
|
126 return EPass; |
|
127 } |
|
128 /* |
|
129 case ESendData: |
|
130 { |
|
131 iSendChain.CreateL ( KData ); |
|
132 iSocketHandler.Send ( iSendChain ); |
|
133 |
|
134 iState = ESendStopServer; |
|
135 iStatus = KRequestPending; |
|
136 Reschedule (); |
|
137 return EPass; |
|
138 } |
|
139 */ |
|
140 |
|
141 // just to make sure production objects are cleaned-up properly. |
|
142 case ESendStopServer: |
|
143 { |
|
144 iLogger.WriteFormat(_L("<i>ESendStopServer..... </i>")); |
|
145 // cleanup tcp server flow |
|
146 RClientInterface::OpenPostMessageClose ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iTcpServer ), TCFDataClient::TStop ( KErrNone ).CRef () ); |
|
147 |
|
148 iState = EServerStopped; |
|
149 iStatus = KRequestPending; |
|
150 Reschedule (); |
|
151 return EPass; |
|
152 } |
|
153 |
|
154 case EServerStopped: |
|
155 { |
|
156 iLogger.WriteFormat(_L("<i>EServerStopped..... </i>")); |
|
157 // cleanup udp server flow |
|
158 RClientInterface::OpenPostMessageClose ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iTcpServer ), TEChild::TDestroy ().CRef () ); |
|
159 |
|
160 iTimer.After ( iStatus, 1000000 ); //1secs |
|
161 iState = ECleanup; |
|
162 iStatus = KRequestPending; |
|
163 Reschedule (); |
|
164 return EPass; |
|
165 } |
|
166 |
|
167 case ECleanup: |
|
168 { |
|
169 iLogger.WriteFormat(_L("<i>ECleanup..... </i>")); |
|
170 return iResponse; // Here the final test case is passed back to the RSocket::Ioctl |
|
171 } |
|
172 |
|
173 default: |
|
174 { |
|
175 iLogger.WriteFormat(_L("<i> Failed: TestCase:..... </i>")); |
|
176 ASSERT(0); |
|
177 return EFail; |
|
178 } |
|
179 } |
|
180 } |
|
181 |
|
182 void CTcpServerTestCase::OpenComplete ( RInternalSocket& aSocket ) |
|
183 { |
|
184 iClientSocket = aSocket; |
|
185 iSocketHandler.Attach ( aSocket ); |
|
186 |
|
187 iSocketHandler.Connect ( iHostAddr ); |
|
188 } |
|
189 |
|
190 void CTcpServerTestCase::ConnectComplete () |
|
191 { |
|
192 CompleteSelf ( KErrNone ); |
|
193 } |
|
194 |
|
195 void CTcpServerTestCase::SendComplete ( TInt /*aLength*/ ) |
|
196 { |
|
197 iLogger.WriteFormat(_L("<i> SendComplete..... </i>")); |
|
198 iSendChain.Init (); |
|
199 iSocketHandler.Recv (); |
|
200 } |
|
201 |
|
202 |
|
203 void CTcpServerTestCase::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) |
|
204 { |
|
205 iLogger.WriteFormat(_L("<i>ReceivedL..... </i>")); |
|
206 if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () ) |
|
207 { |
|
208 const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); |
|
209 iTcpServer = msg.iNodeId; |
|
210 CompleteSelf ( KErrNone ); |
|
211 } |
|
212 else if ( aMessage.IsMessage<TCFDataClient::TStarted> () |
|
213 || aMessage.IsMessage<TCFDataClient::TStopped> () ) |
|
214 { |
|
215 CompleteSelf ( KErrNone ); |
|
216 } |
|
217 } |
|
218 |