imageeditor/ImageEditorManager/src/Pluginloader.cpp
changeset 1 edfc90759b9f
equal deleted inserted replaced
0:57d4cdd99204 1:edfc90759b9f
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <eikenv.h>
       
    23 
       
    24 #include "PluginLoader.h"
       
    25 #include "ImageEditorError.h"
       
    26 
       
    27 #include "../../ImageEditor/inc/plugintypedef.h"
       
    28 
       
    29 //=============================================================================
       
    30 CPluginLoader * CPluginLoader::NewL (
       
    31 	const TDesC	&	aFileName,
       
    32 	const TUid *	aUID2,
       
    33 	const TUid *	aUID3
       
    34 	)
       
    35 {
       
    36 	CPluginLoader * self = CPluginLoader::NewLC (aFileName, aUID2, aUID3);
       
    37 	CleanupStack::Pop (); // self
       
    38 	return self;
       
    39 }
       
    40 
       
    41 //=============================================================================
       
    42 CPluginLoader * CPluginLoader::NewLC (
       
    43 	const TDesC	&	aFileName,
       
    44 	const TUid *	aUID2,
       
    45 	const TUid *	aUID3
       
    46 	)
       
    47 {
       
    48 	CPluginLoader * self = new (ELeave) CPluginLoader;
       
    49 	CleanupStack::PushL (self);
       
    50 	self->ConstructL (aFileName, aUID2, aUID3);
       
    51 	return self;
       
    52 }
       
    53 
       
    54 //=============================================================================
       
    55 CPluginLoader::~CPluginLoader ()
       
    56 {
       
    57 	delete iPlugin;
       
    58 	iLibrary.Close();
       
    59 }
       
    60 
       
    61 //=============================================================================
       
    62 CPluginLoader::CPluginLoader ()
       
    63 {
       
    64 
       
    65 }
       
    66 
       
    67 //=============================================================================
       
    68 void CPluginLoader::ConstructL (
       
    69 	const TDesC	&	aFileName,
       
    70 	const TUid *	aUID2,
       
    71 	const TUid *	aUID3
       
    72 	)
       
    73 {
       
    74     LOGFMT(KImageEditorLogFile, "CPluginLoader: Loading plugin %S", &aFileName);
       
    75     
       
    76     //	Dynamically load DLL
       
    77 	TInt err = iLibrary.Load (aFileName);
       
    78     if (err != KErrNone)
       
    79         {
       
    80         LOGFMT(KImageEditorLogFile,"CPluginLoader: Failed to load file: %S", &aFileName);
       
    81         User::Leave (KSIEEInternal);
       
    82         }
       
    83 
       
    84 	//	Check UID2
       
    85 	if (aUID2)
       
    86 	{
       
    87 		if ( iLibrary.Type()[1] != *aUID2 )
       
    88 		{
       
    89             LOG(KImageEditorLogFile, "CPluginLoader: Invalid plugin UID");
       
    90 			User::Leave (KSIEEInternal);
       
    91 		}
       
    92 		
       
    93 	}
       
    94 
       
    95     //	Check UID3
       
    96 	if (aUID3)
       
    97 	{
       
    98         if ( iLibrary.Type()[2] != *aUID3 )
       
    99 		{
       
   100             LOG(KImageEditorLogFile, "CPluginLoader: Invalid plugin UID");
       
   101 			User::Leave (KSIEEInternal);
       
   102 		}
       
   103 	}
       
   104 
       
   105     //	Create a plugin by calling ordinal 1 factory method
       
   106     TLibraryFunction entrypoint = iLibrary.Lookup (1);
       
   107     iPlugin = (CPluginType *) entrypoint();
       
   108 
       
   109 }
       
   110 
       
   111 //=============================================================================
       
   112 CPluginType * CPluginLoader::GetPlugin () const
       
   113 {
       
   114 	return iPlugin;
       
   115 }
       
   116 
       
   117 //=============================================================================
       
   118 const RLibrary & CPluginLoader::GetPluginDll () const
       
   119 {
       
   120 	return iLibrary;
       
   121 }
       
   122 
       
   123 
       
   124 // End of File