|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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: Declares ConnectionManager class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <upnpdlnaprotocolinfo.h> |
|
22 #include "upnpprotocolinfolocal.h" |
|
23 |
|
24 #include <e32std.h> |
|
25 #include "upnpcm.h" |
|
26 #include "upnperrors.h" |
|
27 #include "upnpargument.h" |
|
28 #include "upnpcommonupnplits.h" |
|
29 #include "upnpdeviceimplementationbase.h" |
|
30 #include "upnpsecuritymanager.h" |
|
31 |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CUpnpCM::CUpnpCM |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CUpnpCM::CUpnpCM( CUpnpDevice& aDevice ) : CUpnpServiceImplementation(aDevice) |
|
42 { |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CUpnpCM::~CUpnpCM |
|
47 // Destructor. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CUpnpCM::~CUpnpCM() |
|
51 { |
|
52 delete iSecurityManager; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CUpnpCM::ConstructL |
|
57 // Two-phased constructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 EXPORT_C CUpnpCM* CUpnpCM::NewL( CUpnpDevice& aDevice, |
|
61 const TDesC8& aMediaTypes, |
|
62 const TDesC& aDescriptionPath ) |
|
63 { |
|
64 CUpnpCM* self = new (ELeave) CUpnpCM(aDevice); |
|
65 CleanupStack::PushL( self ); |
|
66 self->ConstructL( aMediaTypes, aDescriptionPath ); |
|
67 CleanupStack::Pop( self ); |
|
68 return self; |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CUpnpCM::ConstructL |
|
73 // Symbian 2nd phase constructor can leave. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CUpnpCM::ConstructL( const TDesC8& aMediaTypes, const TDesC& aDescriptionPath ) |
|
77 { |
|
78 BaseConstructL( aDescriptionPath, KConnectionManagerType() ); |
|
79 |
|
80 // create ptocolInfos string |
|
81 HBufC8* protInfs = CreateProtocolInfosL(aMediaTypes); |
|
82 CleanupStack::PushL(protInfs); |
|
83 |
|
84 // set variable |
|
85 SetStateVariableL( KProtInf, KEmptyString); |
|
86 SetStateVariableL( KSourceInf, *protInfs ); |
|
87 SetStateVariableL( KSinkInf, KEmptyString ); |
|
88 |
|
89 // clean up |
|
90 CleanupStack::PopAndDestroy(protInfs); |
|
91 |
|
92 SetStateVariableL( KCurConId,KZero ); |
|
93 SetStateVariableL( KRcsId, UpnpCD::KMinusOne ); |
|
94 SetStateVariableL( KAvtransId, UpnpCD::KMinusOne ); |
|
95 SetStateVariableL( KConMan, KEmptyString ); |
|
96 SetStateVariableL( KConId, UpnpCD::KMinusOne ); |
|
97 SetStateVariableL( KDirection, KOutput ); |
|
98 SetStateVariableL( KConStat, KOk ); |
|
99 |
|
100 iSecurityManager = CUpnpSecurityManager::NewInstanceFromUpnpSettingsL(); |
|
101 } |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CUpnpCM::CreateProtocolInfosL |
|
104 // Handle action received from ServiceFramework |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 HBufC8* CUpnpCM::CreateProtocolInfosL(const TDesC8& aMediaTypes ) |
|
108 { |
|
109 // parse comma separated media types |
|
110 CPtrC8Array* pairs = new(ELeave) CPtrC8Array(KGranularity); |
|
111 CleanupStack::PushL(pairs); |
|
112 GetMediaListFromStringL(pairs, aMediaTypes); |
|
113 |
|
114 // buffer |
|
115 CBufFlat* buf = CBufFlat::NewL(KBufExpandSize); |
|
116 CleanupStack::PushL(buf); |
|
117 |
|
118 // for each media element |
|
119 for (TInt i = 0; i < pairs->Count(); i++ ) |
|
120 { |
|
121 // create protocolInfo |
|
122 TInt pos(KErrNotFound); |
|
123 User::LeaveIfError(pos = (*pairs)[i].Find(KColon)); |
|
124 TPtrC8 a((*pairs)[i].Left(pos)); |
|
125 CUpnpProtocolInfoLocal* protInfo = |
|
126 CUpnpProtocolInfoLocal::NewL( (*pairs)[i].Left(pos), (*pairs)[i].Mid(pos+1) ); |
|
127 CleanupStack::PushL(protInfo); |
|
128 |
|
129 // get protocolInfo string |
|
130 TPtrC8 protocolInfo = protInfo->ProtocolInfoL(); |
|
131 HBufC8* protStr = protocolInfo.Alloc(); |
|
132 CleanupStack::PushL(protStr); |
|
133 |
|
134 // add to the buffer |
|
135 buf->InsertL(buf->Size(), *protStr); |
|
136 |
|
137 // add separator |
|
138 buf->InsertL(buf->Size(), KComma); |
|
139 CleanupStack::PopAndDestroy(protStr); |
|
140 CleanupStack::PopAndDestroy(protInfo); |
|
141 } |
|
142 // delete last separator |
|
143 buf->Delete(buf->Size() - 1,KComma().Length()); |
|
144 |
|
145 // alloc heap descriptor |
|
146 HBufC8* ret = buf->Ptr(0).AllocL(); |
|
147 |
|
148 // clean up |
|
149 CleanupStack::PopAndDestroy(buf); |
|
150 CleanupStack::PopAndDestroy(pairs); |
|
151 |
|
152 // return descritpor |
|
153 return ret; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CUpnpCM::GetMediaListFromStringL |
|
158 // Handle action received from ServiceFramework |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CUpnpCM::GetMediaListFromStringL(CPtrC8Array* aList, const TDesC8& aMediaTypes) |
|
162 { |
|
163 TPtrC8 ml(aMediaTypes); |
|
164 TInt pos = KErrNotFound; |
|
165 while ((pos = ml.Find(KComma)) != KErrNotFound) |
|
166 { |
|
167 aList->AppendL(ml.Left(pos)); |
|
168 ml.Set(ml.Mid(pos+1)); |
|
169 } |
|
170 aList->AppendL(ml); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CUpnpCM::ActionReceivedLD |
|
175 // Handle action received from ServiceFramework |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CUpnpCM::ActionReceivedLD( CUpnpAction* aAction ) |
|
179 { |
|
180 CleanupStack::PushL( aAction ); |
|
181 //check security |
|
182 if ( iSecurityManager && |
|
183 KErrNone != iSecurityManager->AuthorizeAction( aAction ) ) |
|
184 { |
|
185 //server returns upnp error action failed when not authorized |
|
186 User::Leave(EActionFailed); |
|
187 } |
|
188 TUpnpErrorCode eCode = EHttpOk; |
|
189 |
|
190 if ( !aAction ) |
|
191 { |
|
192 User::Leave( KErrNotFound ); |
|
193 } |
|
194 |
|
195 if ( aAction->Name().Compare( KGetProtInfo ) == 0 ) |
|
196 { |
|
197 //Get supported Protocols |
|
198 eCode = GetProtocolInfoL( aAction ); |
|
199 } |
|
200 else if ( aAction->Name().Compare( KGetCurConIds ) == 0 ) |
|
201 { |
|
202 //Get Current Connection IDs |
|
203 eCode = GetCurrentConnectionIDsL( aAction ); |
|
204 } |
|
205 else if ( aAction->Name().Compare( KGetCurConInfo ) == 0 ) |
|
206 { |
|
207 //Get Current Connection Info |
|
208 eCode = GetCurrentConnectionInfoL( aAction ); |
|
209 } |
|
210 else if ( aAction->Name().Compare( KPrepareForConnection ) == 0 ) |
|
211 { |
|
212 eCode = PrepareForConnection( aAction ); |
|
213 } |
|
214 else if ( aAction->Name().Compare( KConnectionComplete ) == 0 ) |
|
215 { |
|
216 eCode = ConnectionComplete( aAction ); |
|
217 } |
|
218 else |
|
219 { |
|
220 // Action not defined |
|
221 eCode = EInvalidAction; |
|
222 } |
|
223 SendL( aAction, eCode ); |
|
224 CleanupStack::PopAndDestroy( aAction ); |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CUpnpCM::GetProtocolInfoL |
|
229 // Checks current stateVariables from stateVariableList returns Protocol-related |
|
230 // info |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 TUpnpErrorCode CUpnpCM::GetProtocolInfoL( CUpnpAction* aAction ) |
|
234 { |
|
235 if ( aAction->SetArgumentL( KSource, |
|
236 StateVariableValue( KSourceInf )) == KErrNone && |
|
237 |
|
238 aAction->SetArgumentL( KSink, |
|
239 StateVariableValue( KSinkInf )) == KErrNone) |
|
240 { |
|
241 return EHttpOk; |
|
242 } |
|
243 else |
|
244 { |
|
245 return EInvalidArgs; |
|
246 } |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CUpnpCM::PrepareForConnection |
|
251 // Gets source and sink protocol info |
|
252 // source = iSourceProtocolInfo |
|
253 // sink = iSinkProtocolInfo |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 TUpnpErrorCode CUpnpCM::PrepareForConnection( CUpnpAction* /*aAction*/ ) |
|
257 { |
|
258 // Not implemented in Media Server side. |
|
259 return ENotImplemented; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CUpnpCM::ConnectionComplete |
|
264 // Fetch the AVTransport ID by giving ConnectionID |
|
265 // iAVTransport->GetAVTransportID(ConnectionID) |
|
266 // remove this ID from ConnectionIDs |
|
267 // release network resources |
|
268 // Cleanup |
|
269 // Update source & sink devices information in stateVariableList |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 TUpnpErrorCode CUpnpCM::ConnectionComplete( CUpnpAction* /*aAction*/ ) |
|
273 { |
|
274 // Not implemented in Media Server side. |
|
275 return ENotImplemented; |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CUpnpCM::GetCurrentConnectionIDsL |
|
280 // Check the current connections and insert a CSV list of them into the aAction |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 TUpnpErrorCode CUpnpCM::GetCurrentConnectionIDsL( CUpnpAction* aAction ) |
|
284 { |
|
285 if ( aAction->SetArgumentL( KConnectionIDs, |
|
286 StateVariableValue( KCurConId )) == KErrNone) |
|
287 { |
|
288 return EHttpOk; |
|
289 } |
|
290 else |
|
291 { |
|
292 return EInvalidArgs; |
|
293 } |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CUpnpCM::GetCurrentConnectionInfoL |
|
298 // Checks the ConnectionInfo of the connection specified in the aAction and sets |
|
299 // the data to aAction |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 TUpnpErrorCode CUpnpCM::GetCurrentConnectionInfoL( CUpnpAction* aAction ) |
|
303 { |
|
304 /** |
|
305 *Check the given connection is set up by PrepareForConnection() |
|
306 *if(connectionID == 0){ |
|
307 *iRcsID=-1; |
|
308 *iAVTransportID = -1; |
|
309 *iProtocolInfo = NULL; |
|
310 *iPeerConnectionManager = NULL; |
|
311 *iPeerConnectionID = -1; |
|
312 *iDirection = input (or output); |
|
313 *iStatus = OK (or Unknown); |
|
314 * Gets the connection information by given connection ID.. |
|
315 * |
|
316 *Acceptable Error Codes |
|
317 * EInvalidArgs = 402 |
|
318 * EParameterMismatch = 706 |
|
319 **/ |
|
320 |
|
321 const TDesC8& connectionID = aAction->ArgumentValue( KArgument() ); |
|
322 TLex8 string( connectionID ); |
|
323 TInt testInt; |
|
324 TInt error = string.Val( testInt ); |
|
325 if ( error != KErrNone ) |
|
326 { |
|
327 return EInvalidArgs; |
|
328 } |
|
329 |
|
330 if ( connectionID.CompareC( KZero() ) == 0 ) |
|
331 { |
|
332 if ( aAction->SetArgumentL( KTypeRcsID, |
|
333 StateVariableValue( KRcsId )) == KErrNone && |
|
334 |
|
335 aAction->SetArgumentL( KTypeAVTransportID, |
|
336 StateVariableValue( KAvtransId )) == KErrNone && |
|
337 |
|
338 aAction->SetArgumentL( KTypeProtocolInfo, |
|
339 StateVariableValue( KArgTypeProtocolInfo )) == KErrNone && |
|
340 |
|
341 aAction->SetArgumentL( KTypePeerConnectionManager, |
|
342 StateVariableValue( KConMan )) == KErrNone && |
|
343 |
|
344 aAction->SetArgumentL( KTypePeerConnectionID, |
|
345 StateVariableValue( KConId )) == KErrNone && |
|
346 |
|
347 aAction->SetArgumentL( KTypeDirection, |
|
348 StateVariableValue( KDirection )) == KErrNone && |
|
349 |
|
350 aAction->SetArgumentL( KTypeStatus, |
|
351 StateVariableValue( KConStat )) == KErrNone ) |
|
352 { |
|
353 return EHttpOk; |
|
354 } |
|
355 else |
|
356 { |
|
357 return EInvalidArgs; |
|
358 } |
|
359 } |
|
360 |
|
361 return EParameterMismatch; |
|
362 } |
|
363 |
|
364 // End of File |