devsoundextensions/ciextnfactoryplugins/ciextnclientplugin/src/ciextnclientplugin.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 /*
       
     2 * Copyright (c) 2002-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:   Class definition of plugin implementing devsound client
       
    15 *                custom interface extension.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // Include files
       
    22 #include "ciextnclientplugin.h"
       
    23 #include "citraces.h"
       
    24 #include <ecom.h>
       
    25 #include <cifactoryintfc.h>
       
    26 #include <cifactoryintfc.hrh>
       
    27 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    28 
       
    29 #define RET_ERR_IF_ERR(s) if(s!=KErrNone) return s
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // Constructs and returns an application object.
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 MDevSoundCIClientExtension* CCIExtnClientPlugin::NewL()
       
    36     {
       
    37     DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::NewL"));
       
    38     CCIExtnClientPlugin* self = new (ELeave)CCIExtnClientPlugin;
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop( self );
       
    42     MDevSoundCIClientExtension* ptr = static_cast<MDevSoundCIClientExtension*>(self);
       
    43     return ptr;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Destructor
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CCIExtnClientPlugin::~CCIExtnClientPlugin()
       
    51     {
       
    52     iMCIFactoryIntfcList.Close();
       
    53     DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::~CCIExtnClientPlugin"));
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Called by framework when plugin is constructed
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 TInt CCIExtnClientPlugin::Setup( MCustomCommand& aCustomCommand )
       
    61     {
       
    62     DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::Setup"));
       
    63     TInt status(KErrNone);
       
    64     iMCustomCommand = &aCustomCommand;
       
    65     TRAP_IGNORE(InitializeFactoryPluginsL());
       
    66     return status;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // Called by framework forwarding request to create a custom interface
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 TInt CCIExtnClientPlugin::CustomInterfaceExtension( TUid aUid, TAny*& aInterface )
       
    74     {
       
    75     DEB_TRACE1(_L("*CI* CCIExtnClientPlugin::CustomInterfaceExtension 0x%x"), aUid.iUid);
       
    76 
       
    77     TInt status(KErrNotFound);
       
    78     aInterface = NULL;
       
    79 
       
    80     // Forward request to each factory plugin in the list,
       
    81     for ( TInt index = 0; index < iMCIFactoryIntfcList.Count(); index++ )
       
    82         {
       
    83         status = iMCIFactoryIntfcList[index]->CreateInterface( aUid, aInterface );
       
    84         // The factory tried creating custom interface successfully or otherwise.
       
    85         // stop forwarding the request to other factory plugins in the list.
       
    86         // If the factory does not support a custom interface with aUid, it will
       
    87         // return KErrNotFound
       
    88         if ( status != KErrNotFound )
       
    89             {
       
    90             break;
       
    91             }
       
    92         }
       
    93     return status;
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Called by framework when plugin is to be deleted
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CCIExtnClientPlugin::Release()
       
   101     {
       
   102     DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::Release"));
       
   103 
       
   104     for ( TInt index = 0; index < iMCIFactoryIntfcList.Count(); index++ )
       
   105         {
       
   106         iMCIFactoryIntfcList[index]->Close();
       
   107         }
       
   108 
       
   109     iMCIFactoryIntfcList.Reset();
       
   110     iMCIFactoryIntfcList.Close();
       
   111 
       
   112     REComSession::DestroyedImplementation(iDestructorKey);
       
   113 
       
   114     delete this;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // Called by framework after plugin is created
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CCIExtnClientPlugin::PassDestructorKey( TUid aDestructorKey )
       
   122     {
       
   123     iDestructorKey = aDestructorKey;
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // Constructor
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 CCIExtnClientPlugin::CCIExtnClientPlugin()
       
   131     {
       
   132     // No impl
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // Second phase constructor.
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CCIExtnClientPlugin::ConstructL()
       
   140     {
       
   141     // No impl
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // Initializes factory plugins list.
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CCIExtnClientPlugin::InitializeFactoryPluginsL()
       
   149     {
       
   150     // 1. Query the implementation ids of plugins implementing
       
   151     //    KUidCIFactoryIntfcInterface
       
   152     // 2. Instantiate it and add it to the list of factories
       
   153 
       
   154     DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::InitializeFactoryPluginsL"));
       
   155 
       
   156     iMCIFactoryIntfcList.Reset();
       
   157 
       
   158     RImplInfoPtrArray factoryEComUids;
       
   159     CleanupResetAndDestroyPushL(factoryEComUids);
       
   160 
       
   161     // List all the factory plugins
       
   162     TUid factoryPluginInterfaceUid = {KUidCIFactoryIntfcInterface};
       
   163     TEComResolverParams resParams;
       
   164     REComSession::ListImplementationsL( factoryPluginInterfaceUid,  resParams, 
       
   165                                         KRomOnlyResolverUid, factoryEComUids );
       
   166 
       
   167     // Instantiate and add it to the list of factories
       
   168     TUid destructorKey;
       
   169     MCIFactoryIntfc* factoryPlugin(NULL);
       
   170     TInt status(KErrNone);
       
   171     for ( TInt index = 0; index < factoryEComUids.Count(); index++)
       
   172         {
       
   173         //<415-4087> TN: created with ImplementationUid - KRomOnlyResolverUid not used
       
   174         TRAP( status ,
       
   175               factoryPlugin = static_cast<MCIFactoryIntfc*>
       
   176                                     (REComSession::CreateImplementationL(
       
   177                                                         factoryEComUids[index]->ImplementationUid(),
       
   178                                                         destructorKey ) ) );
       
   179         // If there was problem instantiating factory plugin, continue trying
       
   180         // next one.
       
   181         if ( status != KErrNone)
       
   182             {
       
   183             DEB_TRACE1(_L("*CI* CCIExtnClientPlugin::InitializeFactoryPluginsL create failed status=%d"), status);
       
   184             continue;
       
   185             }
       
   186 
       
   187         // Initialize the factory plugin
       
   188         if ( factoryPlugin->Initialize( *iMCustomCommand, destructorKey ) == KErrNone )
       
   189             {
       
   190             status = iMCIFactoryIntfcList.Append(factoryPlugin);
       
   191             if ( status != KErrNone )
       
   192                 {// There was problem adding plugin to list, there was a system
       
   193                  // wide error. Stop trying and return error code.
       
   194                 factoryPlugin->Close();
       
   195                 User::Leave( status );
       
   196                 }
       
   197             }
       
   198         else
       
   199             {// There was problem initializing the factory plugin instance, close
       
   200              // it and continue instantiating the rest
       
   201             factoryPlugin->Close();
       
   202             }
       
   203         }
       
   204     CleanupStack::PopAndDestroy(&factoryEComUids);
       
   205     }