os/mm/devsoundextensions/ciextnfactoryplugins/ciextnclientplugin/src/ciextnclientplugin.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsoundextensions/ciextnfactoryplugins/ciextnclientplugin/src/ciextnclientplugin.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,205 @@
     1.4 +/*
     1.5 +* Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:   Class definition of plugin implementing devsound client
    1.18 +*                custom interface extension.
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +
    1.24 +// Include files
    1.25 +#include "ciextnclientplugin.h"
    1.26 +#include "citraces.h"
    1.27 +#include <ecom.h>
    1.28 +#include <cifactoryintfc.h>
    1.29 +#include <cifactoryintfc.hrh>
    1.30 +#include <mmf/common/mmfcontrollerpluginresolver.h>
    1.31 +
    1.32 +#define RET_ERR_IF_ERR(s) if(s!=KErrNone) return s
    1.33 +
    1.34 +// ---------------------------------------------------------------------------
    1.35 +// Constructs and returns an application object.
    1.36 +// ---------------------------------------------------------------------------
    1.37 +//
    1.38 +MDevSoundCIClientExtension* CCIExtnClientPlugin::NewL()
    1.39 +    {
    1.40 +    DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::NewL"));
    1.41 +    CCIExtnClientPlugin* self = new (ELeave)CCIExtnClientPlugin;
    1.42 +    CleanupStack::PushL( self );
    1.43 +    self->ConstructL();
    1.44 +    CleanupStack::Pop( self );
    1.45 +    MDevSoundCIClientExtension* ptr = static_cast<MDevSoundCIClientExtension*>(self);
    1.46 +    return ptr;
    1.47 +    }
    1.48 +
    1.49 +// ---------------------------------------------------------------------------
    1.50 +// Destructor
    1.51 +// ---------------------------------------------------------------------------
    1.52 +//
    1.53 +CCIExtnClientPlugin::~CCIExtnClientPlugin()
    1.54 +    {
    1.55 +    iMCIFactoryIntfcList.Close();
    1.56 +    DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::~CCIExtnClientPlugin"));
    1.57 +    }
    1.58 +
    1.59 +// ---------------------------------------------------------------------------
    1.60 +// Called by framework when plugin is constructed
    1.61 +// ---------------------------------------------------------------------------
    1.62 +//
    1.63 +TInt CCIExtnClientPlugin::Setup( MCustomCommand& aCustomCommand )
    1.64 +    {
    1.65 +    DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::Setup"));
    1.66 +    TInt status(KErrNone);
    1.67 +    iMCustomCommand = &aCustomCommand;
    1.68 +    TRAP_IGNORE(InitializeFactoryPluginsL());
    1.69 +    return status;
    1.70 +    }
    1.71 +
    1.72 +// ---------------------------------------------------------------------------
    1.73 +// Called by framework forwarding request to create a custom interface
    1.74 +// ---------------------------------------------------------------------------
    1.75 +//
    1.76 +TInt CCIExtnClientPlugin::CustomInterfaceExtension( TUid aUid, TAny*& aInterface )
    1.77 +    {
    1.78 +    DEB_TRACE1(_L("*CI* CCIExtnClientPlugin::CustomInterfaceExtension 0x%x"), aUid.iUid);
    1.79 +
    1.80 +    TInt status(KErrNotFound);
    1.81 +    aInterface = NULL;
    1.82 +
    1.83 +    // Forward request to each factory plugin in the list,
    1.84 +    for ( TInt index = 0; index < iMCIFactoryIntfcList.Count(); index++ )
    1.85 +        {
    1.86 +        status = iMCIFactoryIntfcList[index]->CreateInterface( aUid, aInterface );
    1.87 +        // The factory tried creating custom interface successfully or otherwise.
    1.88 +        // stop forwarding the request to other factory plugins in the list.
    1.89 +        // If the factory does not support a custom interface with aUid, it will
    1.90 +        // return KErrNotFound
    1.91 +        if ( status != KErrNotFound )
    1.92 +            {
    1.93 +            break;
    1.94 +            }
    1.95 +        }
    1.96 +    return status;
    1.97 +    }
    1.98 +
    1.99 +// ---------------------------------------------------------------------------
   1.100 +// Called by framework when plugin is to be deleted
   1.101 +// ---------------------------------------------------------------------------
   1.102 +//
   1.103 +void CCIExtnClientPlugin::Release()
   1.104 +    {
   1.105 +    DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::Release"));
   1.106 +
   1.107 +    for ( TInt index = 0; index < iMCIFactoryIntfcList.Count(); index++ )
   1.108 +        {
   1.109 +        iMCIFactoryIntfcList[index]->Close();
   1.110 +        }
   1.111 +
   1.112 +    iMCIFactoryIntfcList.Reset();
   1.113 +    iMCIFactoryIntfcList.Close();
   1.114 +
   1.115 +    REComSession::DestroyedImplementation(iDestructorKey);
   1.116 +
   1.117 +    delete this;
   1.118 +    }
   1.119 +
   1.120 +// ---------------------------------------------------------------------------
   1.121 +// Called by framework after plugin is created
   1.122 +// ---------------------------------------------------------------------------
   1.123 +//
   1.124 +void CCIExtnClientPlugin::PassDestructorKey( TUid aDestructorKey )
   1.125 +    {
   1.126 +    iDestructorKey = aDestructorKey;
   1.127 +    }
   1.128 +
   1.129 +// ---------------------------------------------------------------------------
   1.130 +// Constructor
   1.131 +// ---------------------------------------------------------------------------
   1.132 +//
   1.133 +CCIExtnClientPlugin::CCIExtnClientPlugin()
   1.134 +    {
   1.135 +    // No impl
   1.136 +    }
   1.137 +
   1.138 +// ---------------------------------------------------------------------------
   1.139 +// Second phase constructor.
   1.140 +// ---------------------------------------------------------------------------
   1.141 +//
   1.142 +void CCIExtnClientPlugin::ConstructL()
   1.143 +    {
   1.144 +    // No impl
   1.145 +    }
   1.146 +
   1.147 +// ---------------------------------------------------------------------------
   1.148 +// Initializes factory plugins list.
   1.149 +// ---------------------------------------------------------------------------
   1.150 +//
   1.151 +void CCIExtnClientPlugin::InitializeFactoryPluginsL()
   1.152 +    {
   1.153 +    // 1. Query the implementation ids of plugins implementing
   1.154 +    //    KUidCIFactoryIntfcInterface
   1.155 +    // 2. Instantiate it and add it to the list of factories
   1.156 +
   1.157 +    DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::InitializeFactoryPluginsL"));
   1.158 +
   1.159 +    iMCIFactoryIntfcList.Reset();
   1.160 +
   1.161 +    RImplInfoPtrArray factoryEComUids;
   1.162 +    CleanupResetAndDestroyPushL(factoryEComUids);
   1.163 +
   1.164 +    // List all the factory plugins
   1.165 +    TUid factoryPluginInterfaceUid = {KUidCIFactoryIntfcInterface};
   1.166 +    TEComResolverParams resParams;
   1.167 +    REComSession::ListImplementationsL( factoryPluginInterfaceUid,  resParams, 
   1.168 +                                        KRomOnlyResolverUid, factoryEComUids );
   1.169 +
   1.170 +    // Instantiate and add it to the list of factories
   1.171 +    TUid destructorKey;
   1.172 +    MCIFactoryIntfc* factoryPlugin(NULL);
   1.173 +    TInt status(KErrNone);
   1.174 +    for ( TInt index = 0; index < factoryEComUids.Count(); index++)
   1.175 +        {
   1.176 +        //<415-4087> TN: created with ImplementationUid - KRomOnlyResolverUid not used
   1.177 +        TRAP( status ,
   1.178 +              factoryPlugin = static_cast<MCIFactoryIntfc*>
   1.179 +                                    (REComSession::CreateImplementationL(
   1.180 +                                                        factoryEComUids[index]->ImplementationUid(),
   1.181 +                                                        destructorKey ) ) );
   1.182 +        // If there was problem instantiating factory plugin, continue trying
   1.183 +        // next one.
   1.184 +        if ( status != KErrNone)
   1.185 +            {
   1.186 +            DEB_TRACE1(_L("*CI* CCIExtnClientPlugin::InitializeFactoryPluginsL create failed status=%d"), status);
   1.187 +            continue;
   1.188 +            }
   1.189 +
   1.190 +        // Initialize the factory plugin
   1.191 +        if ( factoryPlugin->Initialize( *iMCustomCommand, destructorKey ) == KErrNone )
   1.192 +            {
   1.193 +            status = iMCIFactoryIntfcList.Append(factoryPlugin);
   1.194 +            if ( status != KErrNone )
   1.195 +                {// There was problem adding plugin to list, there was a system
   1.196 +                 // wide error. Stop trying and return error code.
   1.197 +                factoryPlugin->Close();
   1.198 +                User::Leave( status );
   1.199 +                }
   1.200 +            }
   1.201 +        else
   1.202 +            {// There was problem initializing the factory plugin instance, close
   1.203 +             // it and continue instantiating the rest
   1.204 +            factoryPlugin->Close();
   1.205 +            }
   1.206 +        }
   1.207 +    CleanupStack::PopAndDestroy(&factoryEComUids);
   1.208 +    }