|
1 /** @file |
|
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: Definition of the CUpnpHttpClientEngine class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <http.h> |
|
21 #include <commdbconnpref.h> |
|
22 #include <upnphttpmessage.h> |
|
23 |
|
24 #include "upnphttpclientengine.h" |
|
25 #include "upnphttpmessagesender.h" |
|
26 #include "upnphttptransaction.h" |
|
27 |
|
28 #ifdef _DEBUG |
|
29 #define KLogFile _L("HttpClientEngine.txt") |
|
30 #endif |
|
31 #include "upnpcustomlog.h" |
|
32 |
|
33 // ---------------------------------------------------------------------------- |
|
34 // CUpnpHTTPClientEngine::NewL |
|
35 // Creates instance of CUpnpHTTPClientEngine. |
|
36 // ---------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C CUpnpHttpClientEngine* CUpnpHttpClientEngine::NewL( |
|
39 MUpnpHttpClientObserver& aObserver, TInt aActiveIap ) |
|
40 { |
|
41 CUpnpHttpClientEngine* self = CUpnpHttpClientEngine::NewLC(aObserver, aActiveIap ); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CUpnpHTTPClientEngine::NewLC |
|
48 // Creates instance of CUpnpHTTPClientEngine. |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C CUpnpHttpClientEngine* CUpnpHttpClientEngine::NewLC( |
|
52 MUpnpHttpClientObserver& aObserver, TInt aActiveIap ) |
|
53 { |
|
54 CUpnpHttpClientEngine* self = new (ELeave) CUpnpHttpClientEngine( aObserver ); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL( aActiveIap ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // CUpnpHTTPClientEngine::~CUpnpHTTPClientEngine |
|
62 // Destructor. |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 CUpnpHttpClientEngine::~CUpnpHttpClientEngine() |
|
66 { |
|
67 iSenders.ResetAndDestroy(); |
|
68 iSession.Close(); |
|
69 delete iConnectionManagerProxy; |
|
70 iSocketServ.Close(); |
|
71 } |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // CUpnpHTTPClientEngine::SendL |
|
75 // Sends request message, client can expect asynchronous response callbacks, |
|
76 // and response body in transaction object. |
|
77 // ---------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C void CUpnpHttpClientEngine::SendL( CUpnpHttpTransaction& aTransaction ) |
|
80 { |
|
81 CUpnpHttpMessageSender* messageSender = CUpnpHttpMessageSender::NewLC( |
|
82 aTransaction, iSession, *this); |
|
83 iSenders.AppendL( messageSender ); |
|
84 CleanupStack::Pop( messageSender ); |
|
85 messageSender->StartTransactionL(); |
|
86 LOGS1H( 0, "SendL ses id: %d", aTransaction.Request()->SessionId() ); |
|
87 } |
|
88 |
|
89 void CUpnpHttpClientEngine::Cancel( CUpnpHttpTransaction& aTransaction ) |
|
90 { |
|
91 TInt pos( Find( aTransaction ) ); |
|
92 if ( pos != KErrNotFound ) |
|
93 { |
|
94 iSenders[ pos ]->CancelTransaction(); |
|
95 LOGSH( 0, "Cancel ses" ); |
|
96 } |
|
97 } |
|
98 |
|
99 // ---------------------------------------------------------------------------- |
|
100 // CUpnpHTTPClientEngine::ConstructL |
|
101 // Second phase construction.Openes session and starts connection of active IAP. |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 void CUpnpHttpClientEngine::ConstructL( TInt aActiveIap ) |
|
105 { |
|
106 iSession.OpenL(); // Open default protocol ("HTTP/TCP") |
|
107 |
|
108 TCommDbConnPref pref; |
|
109 pref.SetIapId( aActiveIap ); |
|
110 pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
111 |
|
112 User::LeaveIfError( iSocketServ.Connect() ); |
|
113 iConnectionManagerProxy = CUpnpConnectionManagerProxy::NewL( iSocketServ ); |
|
114 User::LeaveIfError( iConnectionManagerProxy->EnsureStart() ); |
|
115 |
|
116 RStringPool strP = iSession.StringPool(); |
|
117 RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); |
|
118 connInfo.SetPropertyL ( |
|
119 strP.StringF(HTTP::EHttpSocketServ,RHTTPSession::GetTable() ), |
|
120 THTTPHdrVal (iSocketServ.Handle()) |
|
121 ); |
|
122 TInt connPtr = reinterpret_cast<TInt>( &iConnectionManagerProxy->ConnectionL() ); |
|
123 connInfo.SetPropertyL ( |
|
124 strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), |
|
125 THTTPHdrVal (connPtr) |
|
126 ); |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // CUpnpHTTPClientEngine::CUpnpHTTPClientEngine |
|
131 // First phase constructor. |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 CUpnpHttpClientEngine::CUpnpHttpClientEngine( MUpnpHttpClientObserver& aObserver ) |
|
135 : iObserver( aObserver ) |
|
136 { |
|
137 } |
|
138 |
|
139 // ---------------------------------------------------------------------------- |
|
140 // CUpnpHTTPClientEngine::SenderFinishedLD |
|
141 // Callback method indicatind that sender finished its job. |
|
142 // Methods notifies observer about response, and destroyes sender. |
|
143 // ---------------------------------------------------------------------------- |
|
144 // |
|
145 void CUpnpHttpClientEngine::SenderFinishedLD( CUpnpHttpMessageSender* aSenderToRelease ) |
|
146 { |
|
147 TInt index = iSenders.Find( aSenderToRelease ); |
|
148 ASSERT( KErrNotFound != index ); |
|
149 LOGS1H( 0, "CUpnpHTTPClientEngine::RemoveSender: %d", index ); |
|
150 iObserver.ClientResponseRecivedLD( aSenderToRelease->UpnpTransaction() ); |
|
151 iSenders.Remove( index ); |
|
152 delete aSenderToRelease; |
|
153 } |
|
154 |
|
155 TInt CUpnpHttpClientEngine::Find( CUpnpHttpTransaction& aTransaction ) |
|
156 { |
|
157 for ( TInt i(0) ; i < iSenders.Count() ; i++ ) |
|
158 { |
|
159 if ( &aTransaction == &( iSenders[i]->UpnpTransaction() ) ) |
|
160 { |
|
161 return i; |
|
162 } |
|
163 } |
|
164 |
|
165 return KErrNotFound; |
|
166 } |
|
167 |
|
168 //end of file |
|
169 |