os/mm/devsoundextensions/ciextnfactoryplugins/ciplatformmsghndlrplugin/src/ciplatformmsghndlrplugin.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsoundextensions/ciextnfactoryplugins/ciplatformmsghndlrplugin/src/ciplatformmsghndlrplugin.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,204 @@
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 message handler
1.18 +* interface.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +
1.24 +// Include files
1.25 +#include "ciplatformmsghndlrplugin.h"
1.26 +#include "ciplatformmsghndlrplugin.hrh"
1.27 +#include "citraces.h"
1.28 +#include <ecom.h>
1.29 +#include <CustomInterfaceBuilder.h>
1.30 +#include <CustomInterfaceCustomCommandParser.h>
1.31 +
1.32 +#define RET_ERR_IF_ERR(s) if(s!=KErrNone) return s
1.33 +
1.34 +// ---------------------------------------------------------------------------
1.35 +// Constructs and returns an application object.
1.36 +// ---------------------------------------------------------------------------
1.37 +//
1.38 +MCIMsgHndlrIntfc* CCIPlatformMsgHndlrPlugin::NewL()
1.39 + {
1.40 + DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::NewL"));
1.41 + CCIPlatformMsgHndlrPlugin* self = new (ELeave) CCIPlatformMsgHndlrPlugin;
1.42 + CleanupStack::PushL( self );
1.43 + self->ConstructL();
1.44 + CleanupStack::Pop( self );
1.45 + MCIMsgHndlrIntfc* ptr = static_cast<MCIMsgHndlrIntfc*>(self);
1.46 + return ptr;
1.47 + }
1.48 +
1.49 +// ---------------------------------------------------------------------------
1.50 +// Destructor
1.51 +// ---------------------------------------------------------------------------
1.52 +//
1.53 +CCIPlatformMsgHndlrPlugin::~CCIPlatformMsgHndlrPlugin()
1.54 + {
1.55 + // No Impl
1.56 + }
1.57 +
1.58 +// ---------------------------------------------------------------------------
1.59 +// Called by framework when plugin is constructed
1.60 +// ---------------------------------------------------------------------------
1.61 +//
1.62 +TInt CCIPlatformMsgHndlrPlugin::Initialize( MCustomInterface& aCustomInterface, TUid aDestructorKey )
1.63 + {
1.64 + TInt status(KErrNone);
1.65 + iMCustomInterface = &aCustomInterface;
1.66 + iDestructorKey = aDestructorKey;
1.67 + iCIFWObjectsInitialized = EFalse;
1.68 + return status;
1.69 + }
1.70 +
1.71 +// ---------------------------------------------------------------------------
1.72 +// Called by framework when it needs to know plugin implementation uid
1.73 +// ---------------------------------------------------------------------------
1.74 +//
1.75 +TUid CCIPlatformMsgHndlrPlugin::ImplementationUid()
1.76 + {
1.77 + TUid implId = {KUidCCIPlatformMsgHndlrPlugin};
1.78 + return implId;
1.79 + }
1.80 +
1.81 +// ---------------------------------------------------------------------------
1.82 +// Called by framework forwarding request to handle aMessage
1.83 +// ---------------------------------------------------------------------------
1.84 +//
1.85 +TBool CCIPlatformMsgHndlrPlugin::HandleMessage( const RMmfIpcMessage& aMessage )
1.86 + {
1.87 + DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::HandleMessage"));
1.88 +
1.89 + TBool handled(EFalse);
1.90 + // Initialize Custom Interface Framework Objects if not done already
1.91 + if (!iCIFWObjectsInitialized)
1.92 + {
1.93 + TRAPD( status, InitializeCIFWObjectsL());
1.94 + if ( status != KErrNone )
1.95 + {
1.96 + aMessage.Complete(status);
1.97 + handled = ETrue;
1.98 + }
1.99 + }
1.100 +
1.101 + // Get the destination info from the client into TMMFMessage.
1.102 + TMMFMessage message(aMessage);
1.103 + TRAPD(status, message.FetchDestinationL());
1.104 +
1.105 + // Check if Custom Command Parser manager can handle the message...
1.106 + if (!handled)
1.107 + {
1.108 + handled = iCustomCommandParserManager->HandleRequest(message);
1.109 + }
1.110 +
1.111 + // Check if the aMessage is for one of the MMF Objects
1.112 + if (!handled)
1.113 + {
1.114 + CMMFObject* object = NULL;
1.115 + // Try to find MMFObject that handles this request
1.116 + TInt status = iMMFObjectContainer->FindMMFObject(message.Destination(),
1.117 + object);
1.118 +
1.119 + // If found, give message to the MMFObject
1.120 + if ( KErrNone == status )
1.121 + {
1.122 + object->HandleRequest(message);
1.123 + handled = ETrue;
1.124 + }
1.125 + }
1.126 +
1.127 + return handled;
1.128 + }
1.129 +
1.130 +// ---------------------------------------------------------------------------
1.131 +// Called by framework when plugin is to be deleted
1.132 +// ---------------------------------------------------------------------------
1.133 +//
1.134 +void CCIPlatformMsgHndlrPlugin::Close()
1.135 + {
1.136 + DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::Close"));
1.137 +
1.138 + iMCustomInterface = NULL;
1.139 + delete iCustomCommandParserManager;
1.140 +
1.141 + iCustomCommandParserManager = NULL;
1.142 + delete iMMFObjectContainer;
1.143 + iMMFObjectContainer = NULL;
1.144 +
1.145 + iCIFWObjectsInitialized = EFalse;
1.146 +
1.147 + REComSession::DestroyedImplementation(iDestructorKey);
1.148 +
1.149 + delete this;
1.150 + }
1.151 +
1.152 +// ---------------------------------------------------------------------------
1.153 +// Called by framework to get handle to custom interface builder
1.154 +// ---------------------------------------------------------------------------
1.155 +//
1.156 +const TMMFMessageDestination& CCIPlatformMsgHndlrPlugin::GetCustomInterfaceBuilderL()
1.157 + {
1.158 + // return the handle
1.159 + return iCustomInterfaceBuilder->Handle();
1.160 + }
1.161 +
1.162 +// ---------------------------------------------------------------------------
1.163 +// Constructor
1.164 +// ---------------------------------------------------------------------------
1.165 +//
1.166 +CCIPlatformMsgHndlrPlugin::CCIPlatformMsgHndlrPlugin()
1.167 +:iMCustomInterface(NULL),
1.168 +iCIFWObjectsInitialized(EFalse),
1.169 +iMMFObjectContainer(NULL),
1.170 +iCustomCommandParserManager(NULL),
1.171 +iCustomInterfaceBuilder(NULL)
1.172 + {
1.173 + // No Impl
1.174 + }
1.175 +
1.176 +// ---------------------------------------------------------------------------
1.177 +// Second phase constructor
1.178 +// ---------------------------------------------------------------------------
1.179 +//
1.180 +void CCIPlatformMsgHndlrPlugin::ConstructL()
1.181 + {
1.182 + // No Impl
1.183 + }
1.184 +
1.185 +// ---------------------------------------------------------------------------
1.186 +// Initializes objects required for Custom Interface Framework.
1.187 +// ---------------------------------------------------------------------------
1.188 +//
1.189 +void CCIPlatformMsgHndlrPlugin::InitializeCIFWObjectsL()
1.190 + {
1.191 + DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::InitializeCIFWObjectsL"));
1.192 +
1.193 + iMMFObjectContainer = new(ELeave) CMMFObjectContainer;
1.194 +
1.195 + iCustomCommandParserManager = CMMFCustomCommandParserManager::NewL();
1.196 +
1.197 + CCustomInterfaceCustomCommandParser* ciccParser = CCustomInterfaceCustomCommandParser::NewL(*this);
1.198 + CleanupStack::PushL( ciccParser );
1.199 +
1.200 + iCustomCommandParserManager->AddCustomCommandParserL(*ciccParser);
1.201 + CleanupStack::Pop( ciccParser );
1.202 +
1.203 + iCustomInterfaceBuilder = CCustomInterfaceBuilder::NewL( *iMMFObjectContainer, *iMCustomInterface);
1.204 + iMMFObjectContainer->AddMMFObject(*iCustomInterfaceBuilder);
1.205 +
1.206 + iCIFWObjectsInitialized = ETrue;
1.207 + }