os/mm/devsoundextensions/ciextnfactoryplugins/ciplatformmsghndlrplugin/src/ciplatformmsghndlrplugin.cpp
First public contribution.
2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Class definition of plugin implementing message handler
22 #include "ciplatformmsghndlrplugin.h"
23 #include "ciplatformmsghndlrplugin.hrh"
26 #include <CustomInterfaceBuilder.h>
27 #include <CustomInterfaceCustomCommandParser.h>
29 #define RET_ERR_IF_ERR(s) if(s!=KErrNone) return s
31 // ---------------------------------------------------------------------------
32 // Constructs and returns an application object.
33 // ---------------------------------------------------------------------------
35 MCIMsgHndlrIntfc* CCIPlatformMsgHndlrPlugin::NewL()
37 DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::NewL"));
38 CCIPlatformMsgHndlrPlugin* self = new (ELeave) CCIPlatformMsgHndlrPlugin;
39 CleanupStack::PushL( self );
41 CleanupStack::Pop( self );
42 MCIMsgHndlrIntfc* ptr = static_cast<MCIMsgHndlrIntfc*>(self);
46 // ---------------------------------------------------------------------------
48 // ---------------------------------------------------------------------------
50 CCIPlatformMsgHndlrPlugin::~CCIPlatformMsgHndlrPlugin()
55 // ---------------------------------------------------------------------------
56 // Called by framework when plugin is constructed
57 // ---------------------------------------------------------------------------
59 TInt CCIPlatformMsgHndlrPlugin::Initialize( MCustomInterface& aCustomInterface, TUid aDestructorKey )
61 TInt status(KErrNone);
62 iMCustomInterface = &aCustomInterface;
63 iDestructorKey = aDestructorKey;
64 iCIFWObjectsInitialized = EFalse;
68 // ---------------------------------------------------------------------------
69 // Called by framework when it needs to know plugin implementation uid
70 // ---------------------------------------------------------------------------
72 TUid CCIPlatformMsgHndlrPlugin::ImplementationUid()
74 TUid implId = {KUidCCIPlatformMsgHndlrPlugin};
78 // ---------------------------------------------------------------------------
79 // Called by framework forwarding request to handle aMessage
80 // ---------------------------------------------------------------------------
82 TBool CCIPlatformMsgHndlrPlugin::HandleMessage( const RMmfIpcMessage& aMessage )
84 DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::HandleMessage"));
86 TBool handled(EFalse);
87 // Initialize Custom Interface Framework Objects if not done already
88 if (!iCIFWObjectsInitialized)
90 TRAPD( status, InitializeCIFWObjectsL());
91 if ( status != KErrNone )
93 aMessage.Complete(status);
98 // Get the destination info from the client into TMMFMessage.
99 TMMFMessage message(aMessage);
100 TRAPD(status, message.FetchDestinationL());
102 // Check if Custom Command Parser manager can handle the message...
105 handled = iCustomCommandParserManager->HandleRequest(message);
108 // Check if the aMessage is for one of the MMF Objects
111 CMMFObject* object = NULL;
112 // Try to find MMFObject that handles this request
113 TInt status = iMMFObjectContainer->FindMMFObject(message.Destination(),
116 // If found, give message to the MMFObject
117 if ( KErrNone == status )
119 object->HandleRequest(message);
127 // ---------------------------------------------------------------------------
128 // Called by framework when plugin is to be deleted
129 // ---------------------------------------------------------------------------
131 void CCIPlatformMsgHndlrPlugin::Close()
133 DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::Close"));
135 iMCustomInterface = NULL;
136 delete iCustomCommandParserManager;
138 iCustomCommandParserManager = NULL;
139 delete iMMFObjectContainer;
140 iMMFObjectContainer = NULL;
142 iCIFWObjectsInitialized = EFalse;
144 REComSession::DestroyedImplementation(iDestructorKey);
149 // ---------------------------------------------------------------------------
150 // Called by framework to get handle to custom interface builder
151 // ---------------------------------------------------------------------------
153 const TMMFMessageDestination& CCIPlatformMsgHndlrPlugin::GetCustomInterfaceBuilderL()
156 return iCustomInterfaceBuilder->Handle();
159 // ---------------------------------------------------------------------------
161 // ---------------------------------------------------------------------------
163 CCIPlatformMsgHndlrPlugin::CCIPlatformMsgHndlrPlugin()
164 :iMCustomInterface(NULL),
165 iCIFWObjectsInitialized(EFalse),
166 iMMFObjectContainer(NULL),
167 iCustomCommandParserManager(NULL),
168 iCustomInterfaceBuilder(NULL)
173 // ---------------------------------------------------------------------------
174 // Second phase constructor
175 // ---------------------------------------------------------------------------
177 void CCIPlatformMsgHndlrPlugin::ConstructL()
182 // ---------------------------------------------------------------------------
183 // Initializes objects required for Custom Interface Framework.
184 // ---------------------------------------------------------------------------
186 void CCIPlatformMsgHndlrPlugin::InitializeCIFWObjectsL()
188 DEB_TRACE0(_L("*CI* CCIPlatformMsgHndlrPlugin::InitializeCIFWObjectsL"));
190 iMMFObjectContainer = new(ELeave) CMMFObjectContainer;
192 iCustomCommandParserManager = CMMFCustomCommandParserManager::NewL();
194 CCustomInterfaceCustomCommandParser* ciccParser = CCustomInterfaceCustomCommandParser::NewL(*this);
195 CleanupStack::PushL( ciccParser );
197 iCustomCommandParserManager->AddCustomCommandParserL(*ciccParser);
198 CleanupStack::Pop( ciccParser );
200 iCustomInterfaceBuilder = CCustomInterfaceBuilder::NewL( *iMMFObjectContainer, *iMCustomInterface);
201 iMMFObjectContainer->AddMMFObject(*iCustomInterfaceBuilder);
203 iCIFWObjectsInitialized = ETrue;