diff -r 675a964f4eb5 -r 35751d3474b7 authorisation/userpromptservice/inc_private/pluginmanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/authorisation/userpromptservice/inc_private/pluginmanager.h Thu Sep 10 14:01:51 2009 +0300 @@ -0,0 +1,108 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef PLUGINMANAGER_H +#define PLUGINMANAGER_H + +namespace UserPromptService + { + class CPolicyEvaluator; + class CDialogCreator; + class CPolicyEvaluatorPlugin; + class CDialogCreatorPlugin; + class CPluginManager; + + /** + Container class for a plug-in that notifies a manager object when + it is destroyed. + */ + template + class CPlugin : public CBase + { + public: + CPlugin(CPluginManager* aManager, T* aImp); + T& Imp(); + ~CPlugin(); + private: + CPluginManager* iManager; ///< The plug-in manager that tracks active plug-ins. + T* iImp; ///< The policy evaluator or dialog creator owned by this object. + }; + + /** + Plug-in manager that tracks the number of plug-ins enabling REComSession::FinalClose() + to be deferred (after calling Unload) once all the plug-ins have been unloaded. + + N.B. REComSession::FinalClose CANNOT be called from within an ECOM plug-in. + */ + NONSHARABLE_CLASS(CPluginManager) : public CBase + { + template friend class CPlugin; + public: + IMPORT_C static CPluginManager* NewL(); + IMPORT_C CPlugin* CreateEvaluatorL(const TUid& aEvaluatorId); + IMPORT_C CPlugin* CreateDialogCreatorL(const TUid& aDialogCreatorId); + IMPORT_C void Unload(); + + ~CPluginManager(); + public: + // For testing. Do not modify directly + TInt iPluginCount; ///< The number of active CPlugin objects. (do not modify) + private: + CPluginManager(); + IMPORT_C void ReleasePlugin(); + + TBool iUnload; ///< Indicates that a deferred call to REComSession::FinalClose is required + }; + + template + inline CPlugin::CPlugin(CPluginManager* aManager, T* aImp) : iManager(aManager), iImp(aImp) + /** + Constructor + @param aManager The plug-in manager that tracks the number of plug-ins in existance. + @param aImp The ECOM implementation that this class managers. + */ + { + } + + template + inline T& CPlugin::Imp() + /** + Gets a reference to the plug-in implementation + @return The plug-in implementation. + */ + { + return *iImp; + } + + template + inline CPlugin::~CPlugin() + /** + Destructor + */ + { + delete iImp; + iManager->ReleasePlugin(); + } + } +#endif // PLUGINMANAGER_H