layouts/cdl/CdlEngine/src/CdlEngine.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include <e32base.h>
       
    18 #include "CdlEngine.h"
       
    19 #include "CdlServEng.h"
       
    20 #include "CCdlEngine.h"
       
    21 #include <e32uid.h>
       
    22 #include <f32file.h>
       
    23 
       
    24 
       
    25 void Panic(TCdlEngPanic aReason)
       
    26 	{
       
    27 	_LIT(KCat, "CdlEng");
       
    28 	User::Panic(KCat, aReason);
       
    29 	}
       
    30 
       
    31 
       
    32 //
       
    33 // CCdlEngineRef
       
    34 //
       
    35 
       
    36 EXPORT_C CCdlEngineRef::~CCdlEngineRef()
       
    37 	{
       
    38 	__ASSERT_DEBUG(iRefCount==0 || iRefCount==1, Panic(ECdlEngPanic_BadRefCount));
       
    39 	ReleaseRef();
       
    40 	}
       
    41 
       
    42 CCdlEngineRef::CCdlEngineRef(CCdlEngineBase* aEngine)
       
    43 : iEngine(aEngine)
       
    44 	{
       
    45 	AddRef();
       
    46 	}
       
    47 
       
    48 void CCdlEngineRef::AddRef()
       
    49 	{
       
    50 	iEngine->IncRefCount();
       
    51 	iRefCount++;
       
    52 	}
       
    53 
       
    54 void CCdlEngineRef::ReleaseRef()
       
    55 	{
       
    56 	if (iRefCount > 0)
       
    57 		{
       
    58 		iEngine->DecRefCount();
       
    59 		iRefCount--;
       
    60 		}
       
    61 	}
       
    62 
       
    63 CCdlEngineBase* CCdlEngineRef::Engine() const
       
    64 	{
       
    65 	return iEngine;
       
    66 	}
       
    67 
       
    68 
       
    69 //
       
    70 // CdlEngine
       
    71 //
       
    72 
       
    73 EXPORT_C TBool CdlEngine::IsCdlEngineCreated()
       
    74 	{
       
    75 	return CCdlEngine::Static() != NULL;
       
    76 	}
       
    77 
       
    78 EXPORT_C CCdlEngineRef* CdlEngine::CreateCdlEngineL()
       
    79 	{
       
    80 	TBool pushed;
       
    81 	CCdlEngine* eng = CCdlEngine::InstanceLC(pushed);
       
    82 	CCdlEngineRef* ref = new(ELeave) CCdlEngineRef(eng);
       
    83 	if (pushed)
       
    84 		CleanupStack::Pop();
       
    85 	return ref;
       
    86 	}
       
    87 
       
    88 EXPORT_C TAny* CdlEngine::GetData(TUid aCdlUid, TInt aApiId)
       
    89 	{
       
    90 	return CCdlEngine::Instance().GetData(aCdlUid, aApiId);
       
    91 	}
       
    92 
       
    93 EXPORT_C TCdlEngineFunc* CdlEngine::GetFunction(TUid aCdlUid, TInt aApiId)
       
    94 	{
       
    95 	CCdlEngine& eng = CCdlEngine::Instance();
       
    96 	CCdlCustomisationStack** pCust = eng.iCustomisations.Find(aCdlUid.iUid);
       
    97 	if(!pCust)
       
    98 		{
       
    99 		Panic(ECdlEngPanic_CustomisationNotPresent);
       
   100 		return NULL;
       
   101 		}
       
   102 	
       
   103 		CCdlCustomisationStack* stack = *pCust;
       
   104 			const CCdlInstance* inst = stack->iTop;
       
   105 			__ASSERT_ALWAYS(inst, Panic(ECdlEngPanic_NoInstanceLoaded));
       
   106 			inst->iLastApi = aApiId;
       
   107 			eng.SetLastApiId(aApiId);
       
   108 			TCdlEngineFunc* func = 0;
       
   109 			do
       
   110 				{
       
   111 				if (aApiId < inst->Interface().iApiSize)
       
   112 					func = (TCdlEngineFunc*)(inst->Implementation(aApiId));
       
   113 				inst = inst->iSubLayer;
       
   114 				} while (!func && inst);
       
   115 			__ASSERT_ALWAYS(func, Panic(ECdlEngPanic_NoImplementation));
       
   116 			return func;
       
   117 	}
       
   118 
       
   119 
       
   120 //
       
   121 // Note that if this method is called, then GetFunction will naturally be called on the resulting instance
       
   122 // and not on CdlEngine, which means that the stack iteration will not be repeated unnecessarily
       
   123 // 
       
   124 EXPORT_C const CCdlInstance* CdlEngine::Implementor(TUid aCdlUid, TInt aApiId)
       
   125 	{
       
   126 	CCdlEngine& eng = CCdlEngine::Instance();
       
   127 	CCdlCustomisationStack** pCust = eng.iCustomisations.Find(aCdlUid.iUid);
       
   128 	if(!pCust)
       
   129 		{
       
   130 		Panic(ECdlEngPanic_CustomisationNotPresent);
       
   131 		}
       
   132 		CCdlCustomisationStack* stack = *pCust;
       
   133 			const CCdlInstance* inst = stack->iTop;
       
   134 			__ASSERT_ALWAYS(inst, Panic(ECdlEngPanic_NoInstanceLoaded));
       
   135 			return inst->Implementor(aApiId);
       
   136 	}
       
   137 	
       
   138 	
       
   139 EXPORT_C void CdlEngine::RequireCustomisationL(const SCdlInterface* aInterfaceParams)
       
   140 	{
       
   141 	CCdlEngine::Instance().RequireCustomisationL(aInterfaceParams);
       
   142 	}
       
   143 
       
   144 EXPORT_C void CdlEngine::LoadCustomisationL(const TCdlRef& aRef)
       
   145 	{
       
   146 	CCdlEngine::Instance().LoadCustomisationL(aRef);
       
   147 	}
       
   148 
       
   149 EXPORT_C TBool CdlEngine::IsCustomisationStarted(const SCdlInterface* aInterfaceParams)
       
   150 	{
       
   151 	return CCdlEngine::Instance().IsCustomisationStarted(aInterfaceParams);
       
   152 	}
       
   153 
       
   154 EXPORT_C const CCdlInstance& CdlEngine::CustomisationInstance(TUid aCdlUid)
       
   155 	{
       
   156 	return CCdlEngine::Instance().CustomisationInstance(aCdlUid);
       
   157 	}
       
   158 
       
   159 EXPORT_C const TCdlRef& CdlEngine::LastAccessedRef(TUid aCdlUid)
       
   160 	{
       
   161 	return CCdlEngine::Instance().LastAccessedRef(aCdlUid);
       
   162 	}
       
   163 
       
   164 EXPORT_C void CdlEngine::FileNameRelativeToLastAccessedInstance(TUid aCdlUid, TFileName& aFileName)
       
   165 	{
       
   166 	CCdlEngine::Instance().FileNameRelativeToLastAccessedInstance(aCdlUid, aFileName);
       
   167 	}
       
   168 
       
   169 EXPORT_C TInt CdlEngine::LastApiId()
       
   170 	{
       
   171 	return CCdlEngine::Instance().LastApiId();
       
   172 	}
       
   173 
       
   174 EXPORT_C CCdlRefs* CdlEngine::FindInstancesLC(TUid aCdlUid)
       
   175 	{
       
   176 	return CCdlEngine::Instance().FindInstancesLC(aCdlUid);
       
   177 	}
       
   178 
       
   179 EXPORT_C CCdlRefCollection* CdlEngine::FileContentsLC(const TDesC& aFileName)
       
   180 	{
       
   181 	return CCdlEngine::Instance().FileContentsLC(aFileName);
       
   182 	}
       
   183 
       
   184 EXPORT_C CCdlNames* CdlEngine::FindCustomisationFilesLC()
       
   185 	{
       
   186 	return CCdlEngine::Instance().FindCustomisationFilesLC();
       
   187 	}
       
   188 
       
   189 EXPORT_C CCdlRefs* CdlEngine::AllAvailableRefsLC()
       
   190 	{
       
   191 	return CCdlEngine::Instance().AllAvailableRefsLC();
       
   192 	}
       
   193 
       
   194 EXPORT_C void CdlEngine::SetLocalStateL(const CCdlRefs& aState)
       
   195 	{
       
   196 	CCdlEngine::Instance().SetLocalStateL(aState);
       
   197 	}
       
   198 
       
   199 EXPORT_C void CdlEngine::SetGlobalStateL(const CCdlRefs& aState)
       
   200 	{
       
   201 	CCdlEngine::Instance().SetGlobalStateL(aState);
       
   202 	}
       
   203 
       
   204 EXPORT_C CCdlRefs* CdlEngine::LocalStateLC(const CCdlUids& aCdlUids)
       
   205 	{
       
   206 	return CCdlEngine::Instance().LocalStateLC(aCdlUids);
       
   207 	}
       
   208 
       
   209 EXPORT_C CCdlRefs* CdlEngine::GlobalStateLC(const CCdlUids& aCdlUids)
       
   210 	{
       
   211 	return CCdlEngine::Instance().GlobalStateLC(aCdlUids);
       
   212 	}
       
   213 
       
   214 EXPORT_C void CdlEngine::EnableGlobalCustomisationL(const CCdlUids& aCdlUids, TBool aEnabled)
       
   215 	{
       
   216 	CCdlEngine::Instance().EnableGlobalCustomisationL(aCdlUids, aEnabled);
       
   217 	}
       
   218 
       
   219 EXPORT_C void CdlEngine::StartGlobalCustomisationL()
       
   220 	{
       
   221 	CCdlEngine::Instance().StartGlobalCustomisationL();
       
   222 	}
       
   223 
       
   224 EXPORT_C void CdlEngine::SetCustomisationChangeObserverL(MCdlChangeObserver* aObserver, TUid aUid)
       
   225 	{
       
   226 	CCdlEngine::Instance().AddCustomisationChangeObserverL(aObserver, aUid);
       
   227 	}
       
   228 
       
   229 EXPORT_C void CdlEngine::SetAvailableRefsChangeObserverL(MCdlChangeObserver* aObserver)
       
   230 	{
       
   231 	CCdlEngine::Instance().AddGeneralChangeObserverL(aObserver);
       
   232 	}
       
   233 
       
   234 EXPORT_C TInt CdlEngine::CompareNames(const TDesC& aLeft, const TDesC& aRight)
       
   235 	{
       
   236 	TPtrC left(RCdlLibrary::ExtractName(aLeft));
       
   237 	TPtrC right(RCdlLibrary::ExtractName(aRight));
       
   238 	// Call Compare first, because it's much faster if the
       
   239 	// strings match
       
   240 	if (left.Compare(right) == 0)
       
   241 		{
       
   242 		return 0;
       
   243 		}
       
   244 	return left.CompareF(right);
       
   245 	}
       
   246 
       
   247 
       
   248 //
       
   249 // CdlServerEngine
       
   250 //
       
   251 
       
   252 EXPORT_C CCdlEngineRef* CdlServerEngine::CreateCdlEngineL()
       
   253 	{
       
   254 	TBool pushed;
       
   255 	CCdlEngineBase* eng = CCdlEngineBase::InstanceLC(pushed);
       
   256 	CCdlEngineRef* ref = new(ELeave) CCdlEngineRef(static_cast<CCdlEngine*>(eng));
       
   257 	if (pushed)
       
   258 		CleanupStack::Pop();
       
   259 	return ref;
       
   260 	}
       
   261 
       
   262 
       
   263 //
       
   264 // MCdlChangeObserver
       
   265 //
       
   266 
       
   267 EXPORT_C MCdlChangeObserver::~MCdlChangeObserver()
       
   268 	{
       
   269 	// It's unusual for a M-class to have a real implementation of this function.
       
   270 	// This function ensures that an observer will automatically deregister from the
       
   271 	// engine on destruction.
       
   272 	CCdlEngine* eng = CCdlEngine::Static();
       
   273 	if (eng)
       
   274 		eng->RemoveChangeObserver(this);
       
   275 	}
       
   276 
       
   277 EXPORT_C void MCdlChangeObserver::HandleCustomisationChangeL(const CCdlUids& /*aUids*/)
       
   278 	{
       
   279 	}
       
   280 
       
   281 EXPORT_C void MCdlChangeObserver::HandleAvailableRefsChangeL()
       
   282 	{
       
   283 	}
       
   284 
       
   285 #ifndef EKA2
       
   286 GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
       
   287 	{
       
   288 	return(KErrNone);
       
   289 	}
       
   290 #endif