os/mm/devsoundextensions/ciextnfactoryplugins/ciextnserverplugin/src/ciextnserverplugin.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 server
sl@0
    15
*                side 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 "ciextnserverplugin.h"
sl@0
    23
#include "citraces.h"
sl@0
    24
#include <ecom.h>
sl@0
    25
#include <mmf/common/mmfcontrollerpluginresolver.h>
sl@0
    26
#include <cimsghndlrintfc.h>
sl@0
    27
#include <cimsghndlrintfc.hrh>
sl@0
    28
#include <e32const.h>
sl@0
    29
sl@0
    30
// ---------------------------------------------------------------------------
sl@0
    31
// Constructs and returns an application object.
sl@0
    32
// ---------------------------------------------------------------------------
sl@0
    33
//
sl@0
    34
MDevSoundCIServerExtension* CCIExtnServerPlugin::NewL()
sl@0
    35
    {
sl@0
    36
    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::NewL")); 
sl@0
    37
    CCIExtnServerPlugin* self = new (ELeave)CCIExtnServerPlugin;
sl@0
    38
    CleanupStack::PushL( self );
sl@0
    39
    self->ConstructL();
sl@0
    40
    CleanupStack::Pop( self );
sl@0
    41
    MDevSoundCIServerExtension* ptr = static_cast<MDevSoundCIServerExtension*>(self);
sl@0
    42
    return ptr;
sl@0
    43
    }
sl@0
    44
sl@0
    45
// ---------------------------------------------------------------------------
sl@0
    46
// Destructor
sl@0
    47
// ---------------------------------------------------------------------------
sl@0
    48
//
sl@0
    49
CCIExtnServerPlugin::~CCIExtnServerPlugin()
sl@0
    50
    {
sl@0
    51
    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::~CCIExtnServerPlugin")); 
sl@0
    52
    }
sl@0
    53
sl@0
    54
// ---------------------------------------------------------------------------
sl@0
    55
// Called by framework when plugin is constructed
sl@0
    56
// ---------------------------------------------------------------------------
sl@0
    57
//
sl@0
    58
TInt CCIExtnServerPlugin::Setup( MCustomInterface& aInterface )
sl@0
    59
    {
sl@0
    60
    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::Setup"));
sl@0
    61
    TInt status(KErrNone);
sl@0
    62
    TRAPD(err, iCiExtnServerPluginWrapper = CIExtnServerPluginWrapper::NewL(aInterface));
sl@0
    63
    if (err == KErrNone)
sl@0
    64
        {
sl@0
    65
        iMCustomInterface = iCiExtnServerPluginWrapper->GetInterface();
sl@0
    66
        }
sl@0
    67
    TRAP_IGNORE(InitializeMsgHndlrPluginsL());
sl@0
    68
    return status;
sl@0
    69
    }
sl@0
    70
sl@0
    71
// ---------------------------------------------------------------------------
sl@0
    72
// Called by framework forwarding passing aMessage to handle
sl@0
    73
// ---------------------------------------------------------------------------
sl@0
    74
//
sl@0
    75
TInt CCIExtnServerPlugin::HandleMessageL(const RMmfIpcMessage& aMessage)
sl@0
    76
    {
sl@0
    77
    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::HandleMessageL"));
sl@0
    78
sl@0
    79
    TInt status(KErrNotSupported);
sl@0
    80
sl@0
    81
    // Forward request to each message handler plugin in the list,
sl@0
    82
    TBool msgHandled(EFalse);
sl@0
    83
    for ( TInt index = 0; index < iMCIMsgHndlrIntfcList.Count(); index++ )
sl@0
    84
        {
sl@0
    85
        msgHandled = iMCIMsgHndlrIntfcList[index]->HandleMessage( aMessage );
sl@0
    86
        // If the plugin handled aMessage, stop forwarding the request to
sl@0
    87
        // other plugins in the list and break out of loop.
sl@0
    88
        if ( msgHandled == TBool(ETrue) )
sl@0
    89
            {
sl@0
    90
            status = KErrNone;
sl@0
    91
            break;
sl@0
    92
            }
sl@0
    93
        }
sl@0
    94
sl@0
    95
    return status;
sl@0
    96
    }
sl@0
    97
sl@0
    98
// ---------------------------------------------------------------------------
sl@0
    99
// Called by framework when plugin is to be deleted
sl@0
   100
// ---------------------------------------------------------------------------
sl@0
   101
//
sl@0
   102
void CCIExtnServerPlugin::Release()
sl@0
   103
    {
sl@0
   104
    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::Release"));
sl@0
   105
    
sl@0
   106
    for ( TInt index = 0; index < iMCIMsgHndlrIntfcList.Count(); index++ )
sl@0
   107
        {
sl@0
   108
        iMCIMsgHndlrIntfcList[index]->Close();
sl@0
   109
        }
sl@0
   110
    
sl@0
   111
    iMCIMsgHndlrIntfcList.Reset();
sl@0
   112
    iMCIMsgHndlrIntfcList.Close();
sl@0
   113
sl@0
   114
    iCiExtnServerPluginWrapper->Release();
sl@0
   115
sl@0
   116
    REComSession::DestroyedImplementation(iDestructorKey);
sl@0
   117
sl@0
   118
    delete this;
sl@0
   119
    }
sl@0
   120
sl@0
   121
// ---------------------------------------------------------------------------
sl@0
   122
// Called by framework after plugin is created
sl@0
   123
// ---------------------------------------------------------------------------
sl@0
   124
//
sl@0
   125
void CCIExtnServerPlugin::PassDestructorKey( TUid aDestructorKey )
sl@0
   126
    {
sl@0
   127
    iDestructorKey = aDestructorKey;
sl@0
   128
    }
sl@0
   129
sl@0
   130
// ---------------------------------------------------------------------------
sl@0
   131
// Constructor
sl@0
   132
// ---------------------------------------------------------------------------
sl@0
   133
//
sl@0
   134
CCIExtnServerPlugin::CCIExtnServerPlugin()
sl@0
   135
    {
sl@0
   136
    // No impl
sl@0
   137
    }
sl@0
   138
sl@0
   139
// ---------------------------------------------------------------------------
sl@0
   140
// Second phase constructor.
sl@0
   141
// ---------------------------------------------------------------------------
sl@0
   142
//
sl@0
   143
void CCIExtnServerPlugin::ConstructL()
sl@0
   144
    {
sl@0
   145
    // No impl
sl@0
   146
    }
sl@0
   147
sl@0
   148
// ---------------------------------------------------------------------------
sl@0
   149
// Initializes factory plugins list.
sl@0
   150
// ---------------------------------------------------------------------------
sl@0
   151
//
sl@0
   152
void CCIExtnServerPlugin::InitializeMsgHndlrPluginsL()
sl@0
   153
    {
sl@0
   154
    // 1. Query the implementation ids of plugins implementing
sl@0
   155
    //    KUidCIMsgHndlrIntfcInterface
sl@0
   156
    // 2. Instantiate it and add it to the list of plugins
sl@0
   157
    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::InitializeMsgHndlrPluginsL"));
sl@0
   158
sl@0
   159
    iMCIMsgHndlrIntfcList.Reset();
sl@0
   160
sl@0
   161
    RImplInfoPtrArray msgHndlrEComUids;
sl@0
   162
    CleanupResetAndDestroyPushL(msgHndlrEComUids);
sl@0
   163
sl@0
   164
sl@0
   165
    // List all the factory plugins
sl@0
   166
    TUid msgHndlrPluginInterfaceUid = {KUidCIMsgHndlrIntfcInterface};
sl@0
   167
    TEComResolverParams resParams;
sl@0
   168
    REComSession::ListImplementationsL( msgHndlrPluginInterfaceUid, resParams, 
sl@0
   169
                                        KRomOnlyResolverUid, msgHndlrEComUids );
sl@0
   170
sl@0
   171
    // Instantiate and add it to the list of factories
sl@0
   172
    TUid destructorKey;
sl@0
   173
    MCIMsgHndlrIntfc* msgHndlrPlugin(NULL);
sl@0
   174
    TInt status(KErrNone);
sl@0
   175
sl@0
   176
    for ( TInt index = 0; index < msgHndlrEComUids.Count(); index++)
sl@0
   177
        {
sl@0
   178
        TRAP( status ,
sl@0
   179
                msgHndlrPlugin = static_cast<MCIMsgHndlrIntfc*>
sl@0
   180
                                    (REComSession::CreateImplementationL(
sl@0
   181
                                            msgHndlrEComUids[index]->ImplementationUid(),
sl@0
   182
                                            destructorKey ) ) );
sl@0
   183
        // If there was problem instantiating factory plugin, continue trying
sl@0
   184
        // next one.
sl@0
   185
        if ( status != KErrNone)
sl@0
   186
            {
sl@0
   187
            DEB_TRACE1(_L("*CI* CCIExtnServerPlugin::InitializeMsgHndlrPluginsL creation status=%d"),status);
sl@0
   188
            continue;
sl@0
   189
            }
sl@0
   190
 
sl@0
   191
        // Initialize the factory plugin
sl@0
   192
        if ( msgHndlrPlugin->Initialize( *iMCustomInterface, destructorKey ) == KErrNone )
sl@0
   193
            {
sl@0
   194
            status = iMCIMsgHndlrIntfcList.Append(msgHndlrPlugin);
sl@0
   195
            if ( status != KErrNone )
sl@0
   196
                {// There was problem adding plugin to list, there was a system
sl@0
   197
                 // wide error. Stop trying and return error code.
sl@0
   198
                msgHndlrPlugin->Close();
sl@0
   199
                User::Leave( status );
sl@0
   200
                }
sl@0
   201
            }
sl@0
   202
        else
sl@0
   203
            {// There was problem initializing the factory plugin instance, close
sl@0
   204
             // it and continue instantiating the rest
sl@0
   205
            msgHndlrPlugin->Close();
sl@0
   206
            }
sl@0
   207
        }
sl@0
   208
    CleanupStack::PopAndDestroy(&msgHndlrEComUids);
sl@0
   209
    }