windowing/windowserver/nonnga/SERVER/wspluginmanager.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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 #include "wspluginmanager.h"
       
    17 #include "Graphics/WSPLUGIN.H"
       
    18 #include "inifile.h"
       
    19 
       
    20 GLREF_D CDebugLogBase* wsDebugLog;
       
    21 
       
    22 const TInt KPluginInterfaceId = 0x2001B709;
       
    23 
       
    24 /**********************************************************************
       
    25 Plugin Info
       
    26 **********************************************************************/
       
    27 CWsPluginManager::CPluginInfo::CPluginInfo()
       
    28 	{
       
    29 	}
       
    30 
       
    31 CWsPluginManager::CPluginInfo::~CPluginInfo()
       
    32 	{
       
    33 	delete iPlugin;
       
    34 	}
       
    35 
       
    36 /**********************************************************************
       
    37 Plugin Manager
       
    38 **********************************************************************/
       
    39 CWsPluginManager* CWsPluginManager::NewL(MWsGraphicDrawerEnvironment& aEnvironment)
       
    40 	{
       
    41 	CWsPluginManager* self = new (ELeave) CWsPluginManager(aEnvironment);
       
    42 	CleanupStack::PushL(self);
       
    43 	self->ConstructL();
       
    44 	CleanupStack::Pop(self);
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 CWsPluginManager::CWsPluginManager(MWsGraphicDrawerEnvironment& aEnvironment) :
       
    49 	iEnvironment(aEnvironment)
       
    50 	{
       
    51 	}
       
    52 	
       
    53 CWsPluginManager::~CWsPluginManager()
       
    54 	{
       
    55 	iPlugins.ResetAndDestroy();
       
    56 	}
       
    57 
       
    58 void CWsPluginManager::ConstructL()
       
    59 	{
       
    60 	_LIT(KPlugins,"PLUGINS");
       
    61 	TPtrC pluginString;
       
    62 	TBool havePlugins = WsIniFile->FindVar(KPlugins,pluginString);
       
    63 	const TDesC * plugins;
       
    64 	_LIT(KDefaultPlugins, "FLICKERBUFFER STD DEFAULTFADER");
       
    65 	if (havePlugins)
       
    66 		plugins = &pluginString;
       
    67 	else
       
    68 		plugins = &KDefaultPlugins;
       
    69 	TLex lex(*plugins);
       
    70 	while(true)
       
    71 		{
       
    72 		TPtrC ptr = lex.NextToken();
       
    73 		if (ptr.Length() > 0)
       
    74 			{
       
    75 			CWsPlugin * plugin = 0;
       
    76 			TRAPD(err, plugin = CreatePluginL(ptr));
       
    77 
       
    78 			if (wsDebugLog)
       
    79 				{
       
    80 				TBuf<80> buf;
       
    81 				if (err == KErrNone)
       
    82 					{
       
    83 					_LIT(KLoadedPlugin,"Loaded plugin: ");
       
    84 					_LIT(KPluginName, " calling itself: ");
       
    85 					buf.Append(KLoadedPlugin);
       
    86 					buf.Append(ptr);
       
    87 					buf.Append(KPluginName);
       
    88 					buf.Append(plugin->PluginName());
       
    89 					wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,buf);
       
    90 					}
       
    91 				else
       
    92 					{
       
    93 					_LIT(KMissingPlugin,"Failed to load plugin (%d): ");
       
    94 					buf.Append(KMissingPlugin);
       
    95 					buf.Append(ptr);
       
    96 					wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,buf,err);
       
    97 					}
       
    98 				}
       
    99 			}
       
   100 		else
       
   101 			{
       
   102 			break;
       
   103 			}
       
   104 		}
       
   105 	}
       
   106 
       
   107 CWsPlugin * CWsPluginManager::CreatePluginL(const TDesC& aSection)
       
   108 	{
       
   109 	_LIT(KId, "ID");
       
   110 	_LIT(KData, "DATA");
       
   111 	_LIT(KType, "TYPE");
       
   112 	TInt id;
       
   113 	TPtrC data;
       
   114 	TPtrC type;
       
   115 	TAny * dataPtr;
       
   116 	RBuf8 empty;
       
   117 	CWsPlugin * plugin = 0;
       
   118 	TBool hasId = WsIniFile->FindVar(aSection,KId,id);
       
   119 	TBool hasType = WsIniFile->FindVar(aSection,KType,type);
       
   120 	if ((!hasId) && (!hasType))
       
   121 		{
       
   122 		_LIT(KFlickerBufferStage, "FLICKERBUFFER");
       
   123 		_LIT(KStdStage, "STD");
       
   124 		_LIT(KDefaultFader, "DEFAULTFADER");
       
   125 		if (!aSection.CompareF(KFlickerBufferStage))
       
   126 			{
       
   127 			hasId = ETrue;
       
   128 			id = 0x2001B70C;
       
   129 			}
       
   130 		else if (!aSection.CompareF(KStdStage))
       
   131 			{
       
   132 			hasId = ETrue;
       
   133 			id = 0x2001B70A;
       
   134 			}
       
   135 		else if (!aSection.CompareF(KDefaultFader))
       
   136 			{
       
   137 			hasId = ETrue;
       
   138 			id = 0x2001B70D;
       
   139 			}	
       
   140 		else
       
   141 			{
       
   142 			hasType = ETrue;
       
   143 			type.Set(aSection);
       
   144 			}
       
   145 		}	
       
   146 	TBool hasData = WsIniFile->FindVar(aSection,KData,data);
       
   147 	if (hasData)
       
   148 		dataPtr = &data;
       
   149 	else
       
   150 		dataPtr = NULL;
       
   151 
       
   152 	CPluginInfo* info = new (ELeave) CPluginInfo;
       
   153 	CleanupStack::PushL(info);
       
   154 
       
   155 	if (hasId)
       
   156 		{
       
   157 		TUid uid = TUid::Uid(id);
       
   158 		plugin = reinterpret_cast<CWsPlugin*>(REComSession::CreateImplementationL(uid,CWsPlugin::DtorIDKeyOffset(),dataPtr));
       
   159 		}
       
   160 	else
       
   161 		{
       
   162 		TEComResolverParams params;
       
   163 		RBuf8 buf8;
       
   164 		buf8.CreateL(type.Length());
       
   165 		CleanupClosePushL(buf8);
       
   166 		buf8.Copy(type);
       
   167 		params.SetDataType(buf8);
       
   168 		plugin = reinterpret_cast<CWsPlugin*>(REComSession::CreateImplementationL(TUid::Uid(KPluginInterfaceId),CWsPlugin::DtorIDKeyOffset(),dataPtr,params));
       
   169 		CleanupStack::PopAndDestroy(&buf8);
       
   170 		}
       
   171 	
       
   172 	User::LeaveIfNull(plugin);
       
   173 	info->iPlugin = plugin;
       
   174 	plugin->ConstructL(iEnvironment, empty);
       
   175 	User::LeaveIfError(iPlugins.Append(info));
       
   176 	CleanupStack::Pop(info);
       
   177 	return plugin;
       
   178 	}
       
   179 
       
   180 TAny * CWsPluginManager::ResolveObjectInterface(TUint aId)
       
   181 	{
       
   182 	if (aId == MWsPluginManager::EWsObjectInterfaceId)
       
   183 		return static_cast<MWsPluginManager*>(this);
       
   184 	return NULL;
       
   185 	}
       
   186 
       
   187 TAny * CWsPluginManager::ResolvePluginInterface(TUint aId)
       
   188 	{
       
   189 	for (TInt p = 0; p < iPlugins.Count(); ++p)
       
   190 		{
       
   191 		TAny * interface = iPlugins[p]->iPlugin->ResolveObjectInterface(aId);
       
   192 		if (interface)
       
   193 			return interface;
       
   194 		}
       
   195 	return NULL;
       
   196 	}
       
   197