1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
// =================================================================================================
// Copyright Adobe
// Copyright 2011 Adobe
// All Rights Reserved
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it.
// =================================================================================================
#ifndef PLUGINMANAGER_H
#define PLUGINMANAGER_H
#include "PluginHandler.h"
#include "ModuleUtils.h"
#include "XMPCommon/XMPCommonDefines.h"
#if SUPPORT_SHARED_POINTERS_IN_STD
#include <memory>
#include <functional>
#elif SUPPORT_SHARED_POINTERS_IN_TR1
#if XMP_WinBuild
#include <memory>
#include <functional>
#else
#include <tr1/memory>
#include <tr1/functional>
#endif
#else
#error "location of shared pointer stuff is unknown"
#endif
namespace XMP_PLUGIN
{
#if SUPPORT_SHARED_POINTERS_IN_STD
using std::shared_ptr;
#elif SUPPORT_SHARED_POINTERS_IN_TR1
using std::tr1::shared_ptr;
#endif
typedef XMP_Uns32 XMPAtom;
typedef XMPAtom FileHandlerType;
typedef shared_ptr<class Module> ModuleSharedPtr;
typedef shared_ptr<class FileHandler> FileHandlerSharedPtr;
class FileHandlerInstance;
typedef FileHandlerInstance* FileHandlerInstancePtr;
typedef std::vector<std::string> StringVec;
typedef std::vector<ModuleSharedPtr> ModuleVec;
typedef std::vector<XMP_FileFormat> XMP_FileFormatVec;
struct FileHandlerPair;
inline void CheckError( WXMP_Error & error )
{
if( error.mErrorID != kXMPErr_NoError )
{
if( error.mErrorID >= kXMPErr_PluginInternal &&
error.mErrorID <= kXMPErr_PluginLastError )
{
throw XMP_Error( kXMPErr_InternalFailure, error.mErrorMsg );
}
else
{
throw XMP_Error( error.mErrorID, error.mErrorMsg );
}
}
}
/** @class PluginManager
* @brief Register all file handlers from all the plugins available in Plugin directory.
*
* At the initialization time of XMPFiles, PluginManager loads all the available plugins
*/
class PluginManager
{
public:
enum HandlerPriority
{
kStandardHandler,
kReplacementHandler,
kUnknown
};
/**
* Initialize the plugin manager. It's a singleton class which manages the plugins.
* @param pluginDir The directory where to search for the plugins.
* @param plugins Comma separated list of the plugins which should be loaded from the plugin directory.
* By default, all plug-ins available in the pluginDir will be loaded.
*/
static void initialize( const std::string& pluginDir, const std::string& plugins = std::string() );
/**
* Terminate the plugin manager.
*/
static void terminate();
/**
* Add file handler corresponding to the given format
* @param format FileFormat supported by the file handler
* @param handler shared pointer to the file handler which is to be added.
* @return Void.
*/
static void addFileHandler( XMP_FileFormat format, FileHandlerSharedPtr handler );
/**
* Returns file handler corresponding to the given format and priority
*
* @param format FileFormat supported by the file handler
* @param priority The priority of the handler (there could be one standard and
* one replacing handler, use the enums kStandardHandler or kReplacementHandler)
* @return shared pointer to the file handler. It does not need to be freed.
*/
static FileHandlerSharedPtr getFileHandler( XMP_FileFormat format, HandlerPriority priority = kStandardHandler );
/**
* Store mapping between session reference (comes from plugin) and
* FileHandlerInstance.
* @param session Session reference from plugin
* @param handler FileHandlerInstance related to the session
*/
static void addHandlerInstance( SessionRef session, FileHandlerInstancePtr handler );
/**
* Remove mapping between session reference (comes from plugin) and
* FilehandlerInstance
* @param session Session reference from plugin
*/
static void removeHandlerInstance( SessionRef session );
/**
* Return FileHandlerInstance that is associated to the session reference
* @param session Session reference from plugin
* @return FileHandlerInstance
*/
static FileHandlerInstancePtr getHandlerInstance( SessionRef session );
/**
* Return the priority of the handler
* @param handler Instance of file handler
* @return Return kStandardHandler or kReplacementHandler
*/
static HandlerPriority getHandlerPriority( FileHandlerInstancePtr handler );
/**
* Return Host API
*/
static HostAPIRef getHostAPI( XMP_Uns32 version );
private:
PluginManager( const std::string& pluginDir, const std::string& plugins );
~PluginManager();
/**
* Terminate host API
*/
void initializeHostAPI();
void terminateHostAPI();
/**
* Load resource file of the given module.
* @param module
* @return Void.
*/
void loadResourceFile( ModuleSharedPtr module );
/**
* Scan mPluginDir for the plugins. It also scans nested folder upto level inMaxNumOfNestedFolder.
* @param inMaxNumOfNestedFolder Nested level where to scan.
* @return Void.
*/
void doScan( const XMP_Int32 inMaxNumOfNestedFolder = 1 );
/**
* Scan recursively the directory /a inPath and insert the found plug-in in ioFoundLibs.
* @param inPath Full path of the directory name to be scanned.
* @param ioFoundLibs Vector of string. Found plug-in will be inserted in this vector.
* @param inLevel The current level
* @param inMaxNumOfNestedFolder Nested level where to scan upto.
* @return Void.
*/
void scanRecursive(
const std::string& inPath,
std::vector<std::string>& ioFoundLibs,
XMP_Int32 inLevel,
XMP_Int32 inMaxNestingLevel );
/**
* Setup passed in HostAPI structure for the host API v1
*/
static void SetupHostAPI_V1( HostAPIRef hostAPI );
/**
* Setup passed in HostAPI structure for the host API v2
*/
static void SetupHostAPI_V2( HostAPIRef hostAPI );
/**
* Setup passed in HostAPI structure for the host API v3
*/
static void SetupHostAPI_V3( HostAPIRef hostAPI );
/**
* Setup passed in HostAPI structure for the host API v4
*/
static void SetupHostAPI_V4( HostAPIRef hostAPI );
typedef std::map<XMP_FileFormat, FileHandlerPair> PluginHandlerMap;
typedef std::map<XMP_Uns32, HostAPIRef> HostAPIMap;
typedef std::map<SessionRef, FileHandlerInstancePtr> SessionMap;
std::string mPluginDir;
StringVec mExtensions;
StringVec mPluginsNeeded;
PluginHandlerMap mHandlers;
SessionMap mSessions;
HostAPIMap mHostAPIs;
static PluginManager* msPluginManager;
};
} //namespace XMP_PLUGIN
#endif //PLUGINMANAGER_H
|