os/persistentdata/traceservices/tracefw/ulogger/src/pluginframework/pluginallocator.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/traceservices/tracefw/ulogger/src/pluginframework/pluginallocator.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,137 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +
    1.20 +#include "pluginallocator.h"
    1.21 +#include "uloggeroutputplugin.h"
    1.22 +#include <e32cmn.h>
    1.23 +#include <ecom/ecom.h>
    1.24 +
    1.25 +namespace Ulogger
    1.26 +{
    1.27 +
    1.28 +/*!Default constructor.
    1.29 +*/
    1.30 +CPluginAllocator::CPluginAllocator()
    1.31 +	{
    1.32 +	iOutputPluginBase = NULL;
    1.33 +	iInputPluginBase = NULL;
    1.34 +	}
    1.35 +
    1.36 +
    1.37 +/*!Destructor.
    1.38 +*/
    1.39 +EXPORT_C CPluginAllocator::~CPluginAllocator()
    1.40 +	{	
    1.41 +	if(iOutputPluginBase)
    1.42 +		{		
    1.43 +		delete iOutputPluginBase;
    1.44 +		iOutputPluginBase = NULL;
    1.45 +		}
    1.46 +	iOutputLib.Close();
    1.47 +		
    1.48 +	if((iOutputLibName.Compare(iInputLibName)!=0) && iInputPluginBase)
    1.49 +		{		
    1.50 +		delete iInputPluginBase;
    1.51 +		iInputPluginBase = NULL;
    1.52 +		}
    1.53 +	iInputLib.Close();
    1.54 +
    1.55 +	REComSession::FinalClose();
    1.56 +	}
    1.57 +
    1.58 +
    1.59 +/*!Standard Symbian OS construction method which leaves object on CleanupStack.
    1.60 +*/
    1.61 +EXPORT_C CPluginAllocator* CPluginAllocator::NewLC(const TPtrC8& aOutputPluginName, const TPtrC8& aInputPluginName)
    1.62 +	{
    1.63 +	CPluginAllocator* obj = new (ELeave) CPluginAllocator();
    1.64 +	CleanupStack::PushL(obj);
    1.65 +	obj->ConstructL(aOutputPluginName, aInputPluginName);
    1.66 +	return obj;
    1.67 +	}
    1.68 +
    1.69 +
    1.70 +/*!Standard Symbian OS construction method which does not leaves object on CleanupStack.
    1.71 +*/
    1.72 +EXPORT_C CPluginAllocator* CPluginAllocator::NewL(const TPtrC8& aOutputPluginName, const TPtrC8& aInputPluginName)
    1.73 +	{
    1.74 +	CPluginAllocator* obj = CPluginAllocator::NewLC(aOutputPluginName, aInputPluginName);
    1.75 +	CleanupStack::Pop(); //obj
    1.76 +	return obj;
    1.77 +	}
    1.78 +
    1.79 +
    1.80 +/*!Standard Symbian OS construction method.
    1.81 +*/
    1.82 +EXPORT_C void CPluginAllocator::ConstructL(const TPtrC8& aOutputPluginName, const TPtrC8& aInputPluginName)
    1.83 +	{	
    1.84 +	//create output and control channels
    1.85 +	User::LeaveIfError(this->CreateChannelsL(aOutputPluginName, aInputPluginName));
    1.86 +	}
    1.87 +
    1.88 +/*!This function create Output channel according to aOutputSettings.
    1.89 +*/
    1.90 +TInt CPluginAllocator::CreateChannelsL(const TPtrC8& aOutputPluginName, const TPtrC8& aInputPluginName)
    1.91 +	{
    1.92 +	TInt retVal = KErrNone;
    1.93 +	
    1.94 +	iOutputLibName.Copy(aOutputPluginName);
    1.95 +	iInputLibName.Copy(aInputPluginName);
    1.96 +
    1.97 +	//create output plugin
    1.98 +	iOutputPluginBase = (CPlugin*)(CPlugin::NewL(aOutputPluginName));
    1.99 +	
   1.100 +	//create control plugin
   1.101 +	if(iOutputLibName.Compare(iInputLibName) == 0)
   1.102 +		{
   1.103 +		//share implementation
   1.104 +		if(aInputPluginName.Length()>0)
   1.105 +			iInputPluginBase = iOutputPluginBase;
   1.106 +		}
   1.107 +	else
   1.108 +		{
   1.109 +		//create new instance of control plugin
   1.110 +		//ulogger can work without control plugin as this is optional functionality
   1.111 +		if(aInputPluginName.Length()>0)
   1.112 +			iInputPluginBase = (CPlugin*)(CPlugin::NewL(aInputPluginName));
   1.113 +		}
   1.114 +	
   1.115 +	return retVal;
   1.116 +	}
   1.117 +
   1.118 +
   1.119 +EXPORT_C MOutputPlugin* CPluginAllocator::GetOutputPlugin()
   1.120 +	{
   1.121 +	if(iOutputPluginBase)
   1.122 +		return (MOutputPlugin*)iOutputPluginBase->GetInterfaceL(MOutputPlugin::iInterfaceId);
   1.123 +	else
   1.124 +		return NULL;
   1.125 +	}
   1.126 +
   1.127 +EXPORT_C MInputPlugin* CPluginAllocator::GetInputPlugin()
   1.128 +	{
   1.129 +	if(iInputPluginBase)
   1.130 +		return (MInputPlugin*)iInputPluginBase->GetInterfaceL(MInputPlugin::iInterfaceId);
   1.131 +	else
   1.132 +		return NULL;
   1.133 +	}
   1.134 +
   1.135 +EXPORT_C void CPluginAllocator::ListAllImplementationsL(RImplInfoPtrArray& aImplInfoArray)
   1.136 +	{
   1.137 +	REComSession::ListImplementationsL(KCPluginUid, aImplInfoArray);
   1.138 +	}
   1.139 +
   1.140 +} //</namespace Ulogger>