TuttleOFX  1
ofxCorePlugin.h
Go to the documentation of this file.
00001 /*
00002  *  Contains the core architectural structures and function definitions for plug-in mechanism.
00003  *  This code is a subset of ofxCore.h from OpenFX plug-in mechanism ( http://openfx.sourceforge.net/ )
00004  */
00005 
00006 #ifndef _COREPLUGIN_H_
00007 #define _COREPLUGIN_H_
00008 
00009 #include <stddef.h> // for size_t
00010 #include <limits.h>
00011 
00012 #ifdef __cplusplus
00013 extern "C" {
00014 #endif
00015 
00016 /** @brief Platform independent export macro.
00017  *
00018  * This macro is to be used before any symbol that is to be
00019  * exported from a plug-in. This is OS/compiler dependent.
00020  */
00021 #if ( defined( WIN32 ) || defined( WIN64 ) || defined( _WIN32 ) || defined( _WIN64 ) || defined( __WINDOWS__ ) || defined( __TOS_WIN__ ) || defined( __WIN32__ ) )
00022  #define OfxExport extern __declspec( dllexport )
00023 #elif defined( __GNUC__ )     // Add compiler definition here...
00024  #if __GNUC__ - 0 > 3 || ( __GNUC__ - 0 == 3 && __GNUC_MINOR__ - 0 > 2 )
00025   #define OfxExport __attribute__ ( ( visibility( "default" ) ) )
00026  #else
00027   #define OfxExport
00028   #warning "OfxExport not set because of a too old gcc version. The plug-in may not compile with the option -fvisible=hidden."
00029  #endif
00030 #else
00031  #error "OfxExport not defined for this compiler..."
00032 #endif
00033 
00034 /** @brief Blind data structure to manipulate sets of properties through */
00035 typedef struct OfxPropertySetStruct* OfxPropertySetHandle;
00036 
00037 /** @brief OFX status return type */
00038 typedef int OfxStatus;
00039 
00040 /** @brief Generic host structure passed to OfxPlugin::setHost function
00041 
00042     This structure contains what is needed by a plug-in to bootstrap it's connection
00043     to the host.
00044  */
00045 typedef struct OfxHost
00046 {
00047         /** @brief Global handle to the host. Extract relevant host properties from this.
00048             This pointer will be valid while the binary containing the plug-in is loaded.
00049          */
00050         OfxPropertySetHandle host;
00051 
00052         /** @brief The function which the plug-in uses to fetch suites from the host.
00053 
00054             \arg \e host          - the host the suite is being fetched from this \em must be the \e host member of the OfxHost struct containing fetchSuite.
00055             \arg \e suiteName     - ASCII string labelling the host supplied API
00056             \arg \e suiteVersion  - version of that suite to fetch
00057 
00058             Any API fetched will be valid while the binary containing the plug-in is loaded.
00059 
00060             Repeated calls to fetchSuite with the same parameters will return the same pointer.
00061 
00062             returns
00063                - NULL if the API is unknown (either the api or the version requested),
00064            - pointer to the relevant API if it was found
00065          */
00066         void*( *fetchSuite )( OfxPropertySetHandle host, const char* suiteName, int suiteVersion );
00067 } OfxHost;
00068 
00069 /** @brief Entry point for plug-ins
00070 
00071    \arg \e action   - ASCII c string indicating which action to take
00072    \arg \e instance - object to which action should be applied, this will need to be cast to the appropriate blind data type depending on the \e action
00073    \arg \e inData   - handle that contains action specific properties
00074    \arg \e outData  - handle where the plug-in should set various action specific properties
00075 
00076    This is how the host generally communicates with a plug-in. Entry points are used to pass messages
00077    to various objects used within OFX. The main use is within the OfxPlugin struct.
00078 
00079    The exact set of actions is determined by the plug-in API that is being implemented, however all plug-ins
00080    can perform several actions. For the list of actions consult \ref ActionsAll.
00081  */
00082 typedef  OfxStatus ( OfxPluginEntryPoint )( const char* action, const void* handle, OfxPropertySetHandle inArgs, OfxPropertySetHandle outArgs );
00083 
00084 /** @brief The structure that defines a plug-in to a host.
00085  *
00086  * This structure is the first element in any plug-in structure
00087  * using the OFX plug-in architecture. By examining it's members
00088  * a host can determine the API that the plug-in implements,
00089  * the version of that API, it's name and version.
00090  *
00091  * For details see \ref Architecture.
00092  *
00093  */
00094 typedef struct OfxPlugin
00095 {
00096         /** Defines the type of the plug-in, this will tell the host what the plug-in does. e.g.: an image
00097             effects plug-in would be a "OfxImageEffectPlugin"
00098          */
00099         const char* pluginApi;
00100 
00101         /** Defines the version of the pluginApi that this plug-in implements */
00102         int apiVersion;
00103 
00104         /** String that uniquely labels the plug-in among all plug-ins that implement an API.
00105             It need not necessarily be human sensible, however the preference is to use reverse
00106             internet domain name of the developer, followed by a '.' then by a name that represents
00107             the plug-in.. It must be a legal ASCII string and have no whitespace in the
00108             name and no non printing chars.
00109             For example "uk.co.somesoftwarehouse.myPlugin"
00110          */
00111         const char* pluginIdentifier;
00112 
00113         /** Major version of this plug-in, this gets incremented when backwards compatibility is broken. */
00114         unsigned int pluginVersionMajor;
00115 
00116         /**  Major version of this plug-in, this gets incremented when software is changed,
00117              but does not break backwards compatibility. */
00118         unsigned int pluginVersionMinor;
00119 
00120         /** @brief Function the host uses to connect the plug-in to the host's api fetcher
00121 
00122             \arg \e fetchApi - pointer to host's API fetcher
00123 
00124             Mandatory function.
00125 
00126             The very first function called in a plug-in. The plug-in \em must \em not call any OFX functions within this, it must only set it's local copy of the host pointer.
00127 
00128             \pre
00129               - nothing else has been called
00130 
00131             \post
00132               - the pointer suite is valid until the plug-in is unloaded
00133          */
00134         void ( * setHost )( OfxHost* host );
00135 
00136         /** @brief Main entry point for plug-ins
00137 
00138            Mandatory function.
00139 
00140            The exact set of actions is determined by the plug-in API that is being implemented, however all plug-ins
00141            can perform several actions. For the list of actions consult \ref ActionsAll.
00142 
00143            Preconditions
00144             - setHost has been called
00145          */
00146         OfxPluginEntryPoint* mainEntry;
00147 } OfxPlugin;
00148 
00149 /**
00150    \defgroup ActionsAll OFX Actions
00151 
00152    These are the actions passed to a plug-in's 'main' function
00153  */
00154 /*@{*/
00155 
00156 /** @brief Action called just after a plug-in has been loaded, for more details see \ref ArchitectureMainFunction and \ref ActionsGeneralLoad */
00157 #define  kOfxActionLoad "OfxActionLoad"
00158 
00159 /** @brief Action called to have a plug-in describe itself to the host, for more details see \ref ArchitectureMainFunction and \ref ActionsGeneralDescribe */
00160 #define kOfxActionDescribe "OfxActionDescribe"
00161 
00162 /** @brief Action called just before a plug-in is unloaded, for more details see \ref ArchitectureMainFunction and \ref ActionsGeneralUnload */
00163 #define kOfxActionUnload "OfxActionUnload"
00164 
00165 /** @brief Action called just after an instance has been created \ref ArchitectureMainFunction and \ref ActionsGeneralCreateInstance  */
00166 #define kOfxActionCreateInstance        "OfxActionCreateInstance"
00167 
00168 /** @brief Action called just before an instance is destroyed and \ref ActionsGeneralDestroyInstance */
00169 #define kOfxActionDestroyInstance       "OfxActionDestroyInstance"
00170 
00171 /*@}*/
00172 
00173 /** @brief Returns the 'nth' plug-in implemented inside a binary
00174  *
00175  * Returns a pointer to the 'nth' plug-in implemented in the binary. A function of this type
00176  * must be implemented in and exported from each plug-in binary.
00177  */
00178 OfxExport OfxPlugin* OfxGetPlugin( int nth );
00179 
00180 /** @brief Defines the number of plug-ins implemented inside a binary
00181  *
00182  * A host calls this to determine how many plug-ins there are inside
00183  * a binary it has loaded. A function of this type
00184  * must be implemented in and exported from each plug-in binary.
00185  */
00186 OfxExport int OfxGetNumberOfPlugins( void );
00187 
00188 /*@{*/
00189 
00190 /** @brief Status code indicating all was fine */
00191 #define kOfxStatOK 0
00192 
00193 /** @brief Status error code for a failed operation */
00194 #define kOfxStatFailed  ( (int)1 )
00195 
00196 /** @brief Status error code for a fatal error
00197 
00198    Only returned in the case where the plug-in or host cannot continue to function and needs to be restarted.
00199  */
00200 #define kOfxStatErrFatal ( (int)2 )
00201 
00202 /** @brief Status error code for an operation on or request for an unknown object */
00203 #define kOfxStatErrUnknown ( (int)3 )
00204 
00205 /** @brief Status error code returned by plug-ins when they are missing host functionality, either an API or some optional functionality (eg: custom params).
00206 
00207     Plug-Ins returning this should post an appropriate error message stating what they are missing.
00208  */
00209 #define kOfxStatErrMissingHostFeature ( (int) 4 )
00210 
00211 /** @brief Status error code for an unsupported feature/operation */
00212 #define kOfxStatErrUnsupported ( (int) 5 )
00213 
00214 /** @brief Status error code for an operation attempting to create something that exists */
00215 #define kOfxStatErrExists  ( (int) 6 )
00216 
00217 /** @brief Status error code for an incorrect format */
00218 #define kOfxStatErrFormat ( (int) 7 )
00219 
00220 /** @brief Status error code indicating that something failed due to memory shortage */
00221 #define kOfxStatErrMemory  ( (int) 8 )
00222 
00223 /** @brief Status error code for an operation on a bad handle */
00224 #define kOfxStatErrBadHandle ( (int) 9 )
00225 
00226 /** @brief Status error code indicating that a given index was invalid or unavailable */
00227 #define kOfxStatErrBadIndex ( (int)10 )
00228 
00229 /** @brief Status error code indicating that something failed due an illegal value */
00230 #define kOfxStatErrValue ( (int) 11 )
00231 
00232 /** @brief OfxStatus returned indicating a 'yes' */
00233 #define kOfxStatReplyYes ( (int) 12 )
00234 
00235 /** @brief OfxStatus returned indicating a 'no' */
00236 #define kOfxStatReplyNo ( (int) 13 )
00237 
00238 /** @brief OfxStatus returned indicating that a default action should be performed */
00239 #define kOfxStatReplyDefault ( (int) 14 )
00240 
00241 /*@}*/
00242 
00243 #ifdef __cplusplus
00244 }
00245 #endif
00246 
00247 #endif /* CORE_HPP_ */