|
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: helper function for loading CUpnpCommand plugin |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <ecom/ecom.h> // REComSession |
|
21 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
22 #include "upnpcommand.h" |
|
23 |
|
24 /** |
|
25 * ------------------------------------------------------------------------- |
|
26 * LoadUpnpCommandL |
|
27 * A helper inline function to load the upnp plugin. |
|
28 * The method guarantees the correct instance is loaded in a secure way. |
|
29 * If plugin can not be located, leaves with KErrNotSupported |
|
30 * |
|
31 * @param aCommandId the identity of command to load |
|
32 * @param aCalback callback interface pointer (may be left NULL) |
|
33 * ------------------------------------------------------------------------- |
|
34 */ |
|
35 inline CUpnpCommand* LoadUpnpCommandL( |
|
36 UpnpCommand::TUpnpCommandId aCommandId, |
|
37 MUpnpCommandCallback* aCallback = 0 ) |
|
38 { |
|
39 CUpnpCommand* command = NULL; |
|
40 |
|
41 // Create resolver parameters to pin point the implementation |
|
42 TEComResolverParams resolverParams; |
|
43 _LIT8( KCommandDataType, "UpnpCommand" ); |
|
44 resolverParams.SetDataType( KCommandDataType ); |
|
45 resolverParams.SetWildcardMatch( EFalse ); |
|
46 |
|
47 RImplInfoPtrArray implArray; |
|
48 CleanupResetAndDestroyPushL( implArray ); |
|
49 |
|
50 // Find implementation for the interface |
|
51 const TUid implIFUid = {0x200075DB}; |
|
52 REComSession::ListImplementationsL( implIFUid, implArray ); |
|
53 for( TInt i=0; i<implArray.Count() && command==0; ++i ) |
|
54 { |
|
55 CImplementationInformation* implInfo = implArray[i]; |
|
56 |
|
57 if( implInfo->VendorId() == VID_DEFAULT && implInfo->RomBased() ) |
|
58 { |
|
59 TAny* impl = REComSession::CreateImplementationL( |
|
60 implIFUid, |
|
61 CUpnpCommand::DtorKeyOffset(), |
|
62 resolverParams ); |
|
63 |
|
64 // Cast the object to correct type before returning |
|
65 command = REINTERPRET_CAST( CUpnpCommand*, impl ); |
|
66 |
|
67 // Set the command ID |
|
68 CleanupStack::PushL( command ); |
|
69 command->SetCommandIdL( aCommandId ); |
|
70 if ( aCallback ) |
|
71 { |
|
72 command->SetObserver( aCallback ); |
|
73 } |
|
74 CleanupStack::Pop( command ); |
|
75 } |
|
76 } |
|
77 CleanupStack::PopAndDestroy(); // empties implArray |
|
78 |
|
79 if ( command == 0 ) |
|
80 { |
|
81 User::Leave( KErrNotSupported ); |
|
82 } |
|
83 |
|
84 // Return the object |
|
85 return command; |
|
86 } |
|
87 |
|
88 // End of File |