os/persistentdata/traceservices/tracefw/ulogger/src/pluginframework/pluginallocator.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 
    17 #include "pluginallocator.h"
    18 #include "uloggeroutputplugin.h"
    19 #include <e32cmn.h>
    20 #include <ecom/ecom.h>
    21 
    22 namespace Ulogger
    23 {
    24 
    25 /*!Default constructor.
    26 */
    27 CPluginAllocator::CPluginAllocator()
    28 	{
    29 	iOutputPluginBase = NULL;
    30 	iInputPluginBase = NULL;
    31 	}
    32 
    33 
    34 /*!Destructor.
    35 */
    36 EXPORT_C CPluginAllocator::~CPluginAllocator()
    37 	{	
    38 	if(iOutputPluginBase)
    39 		{		
    40 		delete iOutputPluginBase;
    41 		iOutputPluginBase = NULL;
    42 		}
    43 	iOutputLib.Close();
    44 		
    45 	if((iOutputLibName.Compare(iInputLibName)!=0) && iInputPluginBase)
    46 		{		
    47 		delete iInputPluginBase;
    48 		iInputPluginBase = NULL;
    49 		}
    50 	iInputLib.Close();
    51 
    52 	REComSession::FinalClose();
    53 	}
    54 
    55 
    56 /*!Standard Symbian OS construction method which leaves object on CleanupStack.
    57 */
    58 EXPORT_C CPluginAllocator* CPluginAllocator::NewLC(const TPtrC8& aOutputPluginName, const TPtrC8& aInputPluginName)
    59 	{
    60 	CPluginAllocator* obj = new (ELeave) CPluginAllocator();
    61 	CleanupStack::PushL(obj);
    62 	obj->ConstructL(aOutputPluginName, aInputPluginName);
    63 	return obj;
    64 	}
    65 
    66 
    67 /*!Standard Symbian OS construction method which does not leaves object on CleanupStack.
    68 */
    69 EXPORT_C CPluginAllocator* CPluginAllocator::NewL(const TPtrC8& aOutputPluginName, const TPtrC8& aInputPluginName)
    70 	{
    71 	CPluginAllocator* obj = CPluginAllocator::NewLC(aOutputPluginName, aInputPluginName);
    72 	CleanupStack::Pop(); //obj
    73 	return obj;
    74 	}
    75 
    76 
    77 /*!Standard Symbian OS construction method.
    78 */
    79 EXPORT_C void CPluginAllocator::ConstructL(const TPtrC8& aOutputPluginName, const TPtrC8& aInputPluginName)
    80 	{	
    81 	//create output and control channels
    82 	User::LeaveIfError(this->CreateChannelsL(aOutputPluginName, aInputPluginName));
    83 	}
    84 
    85 /*!This function create Output channel according to aOutputSettings.
    86 */
    87 TInt CPluginAllocator::CreateChannelsL(const TPtrC8& aOutputPluginName, const TPtrC8& aInputPluginName)
    88 	{
    89 	TInt retVal = KErrNone;
    90 	
    91 	iOutputLibName.Copy(aOutputPluginName);
    92 	iInputLibName.Copy(aInputPluginName);
    93 
    94 	//create output plugin
    95 	iOutputPluginBase = (CPlugin*)(CPlugin::NewL(aOutputPluginName));
    96 	
    97 	//create control plugin
    98 	if(iOutputLibName.Compare(iInputLibName) == 0)
    99 		{
   100 		//share implementation
   101 		if(aInputPluginName.Length()>0)
   102 			iInputPluginBase = iOutputPluginBase;
   103 		}
   104 	else
   105 		{
   106 		//create new instance of control plugin
   107 		//ulogger can work without control plugin as this is optional functionality
   108 		if(aInputPluginName.Length()>0)
   109 			iInputPluginBase = (CPlugin*)(CPlugin::NewL(aInputPluginName));
   110 		}
   111 	
   112 	return retVal;
   113 	}
   114 
   115 
   116 EXPORT_C MOutputPlugin* CPluginAllocator::GetOutputPlugin()
   117 	{
   118 	if(iOutputPluginBase)
   119 		return (MOutputPlugin*)iOutputPluginBase->GetInterfaceL(MOutputPlugin::iInterfaceId);
   120 	else
   121 		return NULL;
   122 	}
   123 
   124 EXPORT_C MInputPlugin* CPluginAllocator::GetInputPlugin()
   125 	{
   126 	if(iInputPluginBase)
   127 		return (MInputPlugin*)iInputPluginBase->GetInterfaceL(MInputPlugin::iInterfaceId);
   128 	else
   129 		return NULL;
   130 	}
   131 
   132 EXPORT_C void CPluginAllocator::ListAllImplementationsL(RImplInfoPtrArray& aImplInfoArray)
   133 	{
   134 	REComSession::ListImplementationsL(KCPluginUid, aImplInfoArray);
   135 	}
   136 
   137 } //</namespace Ulogger>