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