diff -r 000000000000 -r 7f85d04be362 upnpframework/upnpcommand/inc/loadupnpcommand.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/upnpframework/upnpcommand/inc/loadupnpcommand.h Thu Dec 17 08:52:00 2009 +0200 @@ -0,0 +1,88 @@ +/* +* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: helper function for loading CUpnpCommand plugin +* +*/ + + +#include +#include // REComSession +#include +#include "upnpcommand.h" + +/** + * ------------------------------------------------------------------------- + * LoadUpnpCommandL + * A helper inline function to load the upnp plugin. + * The method guarantees the correct instance is loaded in a secure way. + * If plugin can not be located, leaves with KErrNotSupported + * + * @param aCommandId the identity of command to load + * @param aCalback callback interface pointer (may be left NULL) + * ------------------------------------------------------------------------- + */ +inline CUpnpCommand* LoadUpnpCommandL( + UpnpCommand::TUpnpCommandId aCommandId, + MUpnpCommandCallback* aCallback = 0 ) + { + CUpnpCommand* command = NULL; + + // Create resolver parameters to pin point the implementation + TEComResolverParams resolverParams; + _LIT8( KCommandDataType, "UpnpCommand" ); + resolverParams.SetDataType( KCommandDataType ); + resolverParams.SetWildcardMatch( EFalse ); + + RImplInfoPtrArray implArray; + CleanupResetAndDestroyPushL( implArray ); + + // Find implementation for the interface + const TUid implIFUid = {0x200075DB}; + REComSession::ListImplementationsL( implIFUid, implArray ); + for( TInt i=0; iVendorId() == VID_DEFAULT && implInfo->RomBased() ) + { + TAny* impl = REComSession::CreateImplementationL( + implIFUid, + CUpnpCommand::DtorKeyOffset(), + resolverParams ); + + // Cast the object to correct type before returning + command = REINTERPRET_CAST( CUpnpCommand*, impl ); + + // Set the command ID + CleanupStack::PushL( command ); + command->SetCommandIdL( aCommandId ); + if ( aCallback ) + { + command->SetObserver( aCallback ); + } + CleanupStack::Pop( command ); + } + } + CleanupStack::PopAndDestroy(); // empties implArray + + if ( command == 0 ) + { + User::Leave( KErrNotSupported ); + } + + // Return the object + return command; + } + +// End of File