os/mm/devsoundextensions/ciextnfactoryplugins/ciplatformmsghndlrplugin/src/ciplatformmsghndlrplugin.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 message handler
    15 *                interface.
    16 *
    17 */
    18 
    19 
    20 
    21 // Include files
    22 #include "ciplatformmsghndlrplugin.h"
    23 #include "ciplatformmsghndlrplugin.hrh"
    24 #include "citraces.h"
    25 #include <ecom.h>
    26 #include <CustomInterfaceBuilder.h>
    27 #include <CustomInterfaceCustomCommandParser.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 MCIMsgHndlrIntfc* CCIPlatformMsgHndlrPlugin::NewL()
    36     {
    37     DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::NewL"));
    38     CCIPlatformMsgHndlrPlugin* self = new (ELeave) CCIPlatformMsgHndlrPlugin;
    39     CleanupStack::PushL( self );
    40     self->ConstructL();
    41     CleanupStack::Pop( self );
    42     MCIMsgHndlrIntfc* ptr = static_cast<MCIMsgHndlrIntfc*>(self);
    43     return ptr;
    44     }
    45 
    46 // ---------------------------------------------------------------------------
    47 // Destructor
    48 // ---------------------------------------------------------------------------
    49 //
    50 CCIPlatformMsgHndlrPlugin::~CCIPlatformMsgHndlrPlugin()
    51     {
    52     // No Impl
    53     }
    54 
    55 // ---------------------------------------------------------------------------
    56 // Called by framework when plugin is constructed
    57 // ---------------------------------------------------------------------------
    58 //
    59 TInt CCIPlatformMsgHndlrPlugin::Initialize( MCustomInterface& aCustomInterface, TUid aDestructorKey )
    60     {
    61     TInt status(KErrNone);
    62     iMCustomInterface = &aCustomInterface;
    63     iDestructorKey = aDestructorKey;
    64     iCIFWObjectsInitialized = EFalse;
    65     return status;
    66     }
    67 
    68 // ---------------------------------------------------------------------------
    69 // Called by framework when it needs to know plugin implementation uid
    70 // ---------------------------------------------------------------------------
    71 //
    72 TUid CCIPlatformMsgHndlrPlugin::ImplementationUid()
    73     {
    74     TUid implId = {KUidCCIPlatformMsgHndlrPlugin};
    75     return implId;
    76     }
    77 
    78 // ---------------------------------------------------------------------------
    79 // Called by framework forwarding request to handle aMessage
    80 // ---------------------------------------------------------------------------
    81 //
    82 TBool CCIPlatformMsgHndlrPlugin::HandleMessage( const RMmfIpcMessage& aMessage )
    83     {
    84     DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::HandleMessage"));
    85 
    86     TBool handled(EFalse);
    87     // Initialize Custom Interface Framework Objects if not done already
    88     if (!iCIFWObjectsInitialized)
    89         {
    90         TRAPD( status, InitializeCIFWObjectsL());
    91         if ( status != KErrNone )
    92             {
    93             aMessage.Complete(status);
    94             handled = ETrue;
    95             }
    96         }
    97 
    98     // Get the destination info from the client into TMMFMessage.
    99     TMMFMessage message(aMessage);
   100     TRAPD(status, message.FetchDestinationL());
   101 
   102     // Check if Custom Command Parser manager can handle the message...
   103     if (!handled)
   104         {
   105         handled = iCustomCommandParserManager->HandleRequest(message);
   106         }
   107 
   108     // Check if the aMessage is for one of the MMF Objects
   109     if (!handled)
   110         {
   111         CMMFObject* object = NULL;
   112         // Try to find MMFObject that handles this request
   113         TInt status = iMMFObjectContainer->FindMMFObject(message.Destination(),
   114                                                      object);
   115 
   116         // If found, give message to the MMFObject
   117         if ( KErrNone == status )
   118             {
   119             object->HandleRequest(message);
   120             handled = ETrue;
   121             }
   122         }
   123 
   124     return handled;
   125     }
   126 
   127 // ---------------------------------------------------------------------------
   128 // Called by framework when plugin is to be deleted
   129 // ---------------------------------------------------------------------------
   130 //
   131 void CCIPlatformMsgHndlrPlugin::Close()
   132     {
   133     DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::Close"));
   134 
   135     iMCustomInterface = NULL;
   136     delete iCustomCommandParserManager;
   137 
   138     iCustomCommandParserManager =  NULL;
   139     delete iMMFObjectContainer;
   140     iMMFObjectContainer = NULL;
   141 
   142     iCIFWObjectsInitialized = EFalse;
   143 
   144     REComSession::DestroyedImplementation(iDestructorKey);
   145 
   146     delete this;
   147     }
   148 
   149 // ---------------------------------------------------------------------------
   150 // Called by framework to get handle to custom interface builder
   151 // ---------------------------------------------------------------------------
   152 //
   153 const TMMFMessageDestination& CCIPlatformMsgHndlrPlugin::GetCustomInterfaceBuilderL()
   154     {
   155     // return the handle
   156     return iCustomInterfaceBuilder->Handle();
   157     }
   158 
   159 // ---------------------------------------------------------------------------
   160 // Constructor
   161 // ---------------------------------------------------------------------------
   162 //
   163 CCIPlatformMsgHndlrPlugin::CCIPlatformMsgHndlrPlugin()
   164 :iMCustomInterface(NULL),
   165 iCIFWObjectsInitialized(EFalse),
   166 iMMFObjectContainer(NULL),
   167 iCustomCommandParserManager(NULL),
   168 iCustomInterfaceBuilder(NULL)
   169     {
   170     // No Impl
   171     }
   172 
   173 // ---------------------------------------------------------------------------
   174 // Second phase constructor
   175 // ---------------------------------------------------------------------------
   176 //
   177 void CCIPlatformMsgHndlrPlugin::ConstructL()
   178     {
   179     // No Impl
   180     }
   181 
   182 // ---------------------------------------------------------------------------
   183 // Initializes objects required for Custom Interface Framework.
   184 // ---------------------------------------------------------------------------
   185 //
   186 void CCIPlatformMsgHndlrPlugin::InitializeCIFWObjectsL()
   187     {
   188     DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::InitializeCIFWObjectsL"));
   189 
   190     iMMFObjectContainer = new(ELeave) CMMFObjectContainer;
   191 
   192     iCustomCommandParserManager = CMMFCustomCommandParserManager::NewL();
   193 
   194     CCustomInterfaceCustomCommandParser* ciccParser = CCustomInterfaceCustomCommandParser::NewL(*this);
   195     CleanupStack::PushL( ciccParser );
   196 
   197     iCustomCommandParserManager->AddCustomCommandParserL(*ciccParser);
   198     CleanupStack::Pop( ciccParser );
   199 
   200     iCustomInterfaceBuilder = CCustomInterfaceBuilder::NewL( *iMMFObjectContainer, *iMCustomInterface);
   201     iMMFObjectContainer->AddMMFObject(*iCustomInterfaceBuilder);
   202 
   203     iCIFWObjectsInitialized = ETrue;
   204     }