os/mm/devsoundextensions/ciextnfactoryplugins/ciextnserverplugin/src/ciextnserverplugin.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsoundextensions/ciextnfactoryplugins/ciextnserverplugin/src/ciextnserverplugin.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,209 @@
     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 server
    1.18 +*                side custom interface extension.
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +
    1.24 +// Include files
    1.25 +#include "ciextnserverplugin.h"
    1.26 +#include "citraces.h"
    1.27 +#include <ecom.h>
    1.28 +#include <mmf/common/mmfcontrollerpluginresolver.h>
    1.29 +#include <cimsghndlrintfc.h>
    1.30 +#include <cimsghndlrintfc.hrh>
    1.31 +#include <e32const.h>
    1.32 +
    1.33 +// ---------------------------------------------------------------------------
    1.34 +// Constructs and returns an application object.
    1.35 +// ---------------------------------------------------------------------------
    1.36 +//
    1.37 +MDevSoundCIServerExtension* CCIExtnServerPlugin::NewL()
    1.38 +    {
    1.39 +    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::NewL")); 
    1.40 +    CCIExtnServerPlugin* self = new (ELeave)CCIExtnServerPlugin;
    1.41 +    CleanupStack::PushL( self );
    1.42 +    self->ConstructL();
    1.43 +    CleanupStack::Pop( self );
    1.44 +    MDevSoundCIServerExtension* ptr = static_cast<MDevSoundCIServerExtension*>(self);
    1.45 +    return ptr;
    1.46 +    }
    1.47 +
    1.48 +// ---------------------------------------------------------------------------
    1.49 +// Destructor
    1.50 +// ---------------------------------------------------------------------------
    1.51 +//
    1.52 +CCIExtnServerPlugin::~CCIExtnServerPlugin()
    1.53 +    {
    1.54 +    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::~CCIExtnServerPlugin")); 
    1.55 +    }
    1.56 +
    1.57 +// ---------------------------------------------------------------------------
    1.58 +// Called by framework when plugin is constructed
    1.59 +// ---------------------------------------------------------------------------
    1.60 +//
    1.61 +TInt CCIExtnServerPlugin::Setup( MCustomInterface& aInterface )
    1.62 +    {
    1.63 +    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::Setup"));
    1.64 +    TInt status(KErrNone);
    1.65 +    TRAPD(err, iCiExtnServerPluginWrapper = CIExtnServerPluginWrapper::NewL(aInterface));
    1.66 +    if (err == KErrNone)
    1.67 +        {
    1.68 +        iMCustomInterface = iCiExtnServerPluginWrapper->GetInterface();
    1.69 +        }
    1.70 +    TRAP_IGNORE(InitializeMsgHndlrPluginsL());
    1.71 +    return status;
    1.72 +    }
    1.73 +
    1.74 +// ---------------------------------------------------------------------------
    1.75 +// Called by framework forwarding passing aMessage to handle
    1.76 +// ---------------------------------------------------------------------------
    1.77 +//
    1.78 +TInt CCIExtnServerPlugin::HandleMessageL(const RMmfIpcMessage& aMessage)
    1.79 +    {
    1.80 +    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::HandleMessageL"));
    1.81 +
    1.82 +    TInt status(KErrNotSupported);
    1.83 +
    1.84 +    // Forward request to each message handler plugin in the list,
    1.85 +    TBool msgHandled(EFalse);
    1.86 +    for ( TInt index = 0; index < iMCIMsgHndlrIntfcList.Count(); index++ )
    1.87 +        {
    1.88 +        msgHandled = iMCIMsgHndlrIntfcList[index]->HandleMessage( aMessage );
    1.89 +        // If the plugin handled aMessage, stop forwarding the request to
    1.90 +        // other plugins in the list and break out of loop.
    1.91 +        if ( msgHandled == TBool(ETrue) )
    1.92 +            {
    1.93 +            status = KErrNone;
    1.94 +            break;
    1.95 +            }
    1.96 +        }
    1.97 +
    1.98 +    return status;
    1.99 +    }
   1.100 +
   1.101 +// ---------------------------------------------------------------------------
   1.102 +// Called by framework when plugin is to be deleted
   1.103 +// ---------------------------------------------------------------------------
   1.104 +//
   1.105 +void CCIExtnServerPlugin::Release()
   1.106 +    {
   1.107 +    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::Release"));
   1.108 +    
   1.109 +    for ( TInt index = 0; index < iMCIMsgHndlrIntfcList.Count(); index++ )
   1.110 +        {
   1.111 +        iMCIMsgHndlrIntfcList[index]->Close();
   1.112 +        }
   1.113 +    
   1.114 +    iMCIMsgHndlrIntfcList.Reset();
   1.115 +    iMCIMsgHndlrIntfcList.Close();
   1.116 +
   1.117 +    iCiExtnServerPluginWrapper->Release();
   1.118 +
   1.119 +    REComSession::DestroyedImplementation(iDestructorKey);
   1.120 +
   1.121 +    delete this;
   1.122 +    }
   1.123 +
   1.124 +// ---------------------------------------------------------------------------
   1.125 +// Called by framework after plugin is created
   1.126 +// ---------------------------------------------------------------------------
   1.127 +//
   1.128 +void CCIExtnServerPlugin::PassDestructorKey( TUid aDestructorKey )
   1.129 +    {
   1.130 +    iDestructorKey = aDestructorKey;
   1.131 +    }
   1.132 +
   1.133 +// ---------------------------------------------------------------------------
   1.134 +// Constructor
   1.135 +// ---------------------------------------------------------------------------
   1.136 +//
   1.137 +CCIExtnServerPlugin::CCIExtnServerPlugin()
   1.138 +    {
   1.139 +    // No impl
   1.140 +    }
   1.141 +
   1.142 +// ---------------------------------------------------------------------------
   1.143 +// Second phase constructor.
   1.144 +// ---------------------------------------------------------------------------
   1.145 +//
   1.146 +void CCIExtnServerPlugin::ConstructL()
   1.147 +    {
   1.148 +    // No impl
   1.149 +    }
   1.150 +
   1.151 +// ---------------------------------------------------------------------------
   1.152 +// Initializes factory plugins list.
   1.153 +// ---------------------------------------------------------------------------
   1.154 +//
   1.155 +void CCIExtnServerPlugin::InitializeMsgHndlrPluginsL()
   1.156 +    {
   1.157 +    // 1. Query the implementation ids of plugins implementing
   1.158 +    //    KUidCIMsgHndlrIntfcInterface
   1.159 +    // 2. Instantiate it and add it to the list of plugins
   1.160 +    DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::InitializeMsgHndlrPluginsL"));
   1.161 +
   1.162 +    iMCIMsgHndlrIntfcList.Reset();
   1.163 +
   1.164 +    RImplInfoPtrArray msgHndlrEComUids;
   1.165 +    CleanupResetAndDestroyPushL(msgHndlrEComUids);
   1.166 +
   1.167 +
   1.168 +    // List all the factory plugins
   1.169 +    TUid msgHndlrPluginInterfaceUid = {KUidCIMsgHndlrIntfcInterface};
   1.170 +    TEComResolverParams resParams;
   1.171 +    REComSession::ListImplementationsL( msgHndlrPluginInterfaceUid, resParams, 
   1.172 +                                        KRomOnlyResolverUid, msgHndlrEComUids );
   1.173 +
   1.174 +    // Instantiate and add it to the list of factories
   1.175 +    TUid destructorKey;
   1.176 +    MCIMsgHndlrIntfc* msgHndlrPlugin(NULL);
   1.177 +    TInt status(KErrNone);
   1.178 +
   1.179 +    for ( TInt index = 0; index < msgHndlrEComUids.Count(); index++)
   1.180 +        {
   1.181 +        TRAP( status ,
   1.182 +                msgHndlrPlugin = static_cast<MCIMsgHndlrIntfc*>
   1.183 +                                    (REComSession::CreateImplementationL(
   1.184 +                                            msgHndlrEComUids[index]->ImplementationUid(),
   1.185 +                                            destructorKey ) ) );
   1.186 +        // If there was problem instantiating factory plugin, continue trying
   1.187 +        // next one.
   1.188 +        if ( status != KErrNone)
   1.189 +            {
   1.190 +            DEB_TRACE1(_L("*CI* CCIExtnServerPlugin::InitializeMsgHndlrPluginsL creation status=%d"),status);
   1.191 +            continue;
   1.192 +            }
   1.193 + 
   1.194 +        // Initialize the factory plugin
   1.195 +        if ( msgHndlrPlugin->Initialize( *iMCustomInterface, destructorKey ) == KErrNone )
   1.196 +            {
   1.197 +            status = iMCIMsgHndlrIntfcList.Append(msgHndlrPlugin);
   1.198 +            if ( status != KErrNone )
   1.199 +                {// There was problem adding plugin to list, there was a system
   1.200 +                 // wide error. Stop trying and return error code.
   1.201 +                msgHndlrPlugin->Close();
   1.202 +                User::Leave( status );
   1.203 +                }
   1.204 +            }
   1.205 +        else
   1.206 +            {// There was problem initializing the factory plugin instance, close
   1.207 +             // it and continue instantiating the rest
   1.208 +            msgHndlrPlugin->Close();
   1.209 +            }
   1.210 +        }
   1.211 +    CleanupStack::PopAndDestroy(&msgHndlrEComUids);
   1.212 +    }