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