diff --git a/HostSupport/HostSupport.sln b/HostSupport/HostSupport.sln index d1d942b6f..80562501c 100644 --- a/HostSupport/HostSupport.sln +++ b/HostSupport/HostSupport.sln @@ -1,44 +1,62 @@  Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual C++ Express 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HostSupport", "HostSupport.vcproj", "{AC66D35B-4E03-44F2-8510-F3DC4C1E4383}" +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HostSupport", "HostSupport.vcproj", "{A7C4BC47-C2BD-402A-B830-04CC45F6AB55}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CacheDemo", "examples\CacheDemo.vcproj", "{35D15EBD-F0D0-4DDF-ABEF-36B8E0F4BCAC}" ProjectSection(ProjectDependencies) = postProject - {AC66D35B-4E03-44F2-8510-F3DC4C1E4383} = {AC66D35B-4E03-44F2-8510-F3DC4C1E4383} - {3C318B12-4004-412D-A37B-DC5D6347E380} = {3C318B12-4004-412D-A37B-DC5D6347E380} + {A7C4BC47-C2BD-402A-B830-04CC45F6AB55} = {A7C4BC47-C2BD-402A-B830-04CC45F6AB55} + {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED} = {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "expat_static", "expat-2.0.1\lib\expat_static.vcproj", "{3C318B12-4004-412D-A37B-DC5D6347E380}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "expat_static", "expat-2.0.1\lib\expat_static.vcproj", "{BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HostDemo", "examples\hostDemo.vcproj", "{33D15EBD-FAD0-4DDF-ABEF-36BBE0F4BCAC}" ProjectSection(ProjectDependencies) = postProject - {3C318B12-4004-412D-A37B-DC5D6347E380} = {3C318B12-4004-412D-A37B-DC5D6347E380} - {AC66D35B-4E03-44F2-8510-F3DC4C1E4383} = {AC66D35B-4E03-44F2-8510-F3DC4C1E4383} + {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED} = {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED} + {A7C4BC47-C2BD-402A-B830-04CC45F6AB55} = {A7C4BC47-C2BD-402A-B830-04CC45F6AB55} EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AC66D35B-4E03-44F2-8510-F3DC4C1E4383}.Debug|Win32.ActiveCfg = Debug-Static|Win32 - {AC66D35B-4E03-44F2-8510-F3DC4C1E4383}.Debug|Win32.Build.0 = Debug-Static|Win32 - {AC66D35B-4E03-44F2-8510-F3DC4C1E4383}.Release|Win32.ActiveCfg = Release|Win32 - {AC66D35B-4E03-44F2-8510-F3DC4C1E4383}.Release|Win32.Build.0 = Release|Win32 + {A7C4BC47-C2BD-402A-B830-04CC45F6AB55}.Debug|Win32.ActiveCfg = Debug-Static|Win32 + {A7C4BC47-C2BD-402A-B830-04CC45F6AB55}.Debug|Win32.Build.0 = Debug-Static|Win32 + {A7C4BC47-C2BD-402A-B830-04CC45F6AB55}.Debug|x64.ActiveCfg = Debug-Static|x64 + {A7C4BC47-C2BD-402A-B830-04CC45F6AB55}.Debug|x64.Build.0 = Debug-Static|x64 + {A7C4BC47-C2BD-402A-B830-04CC45F6AB55}.Release|Win32.ActiveCfg = Release-Static|Win32 + {A7C4BC47-C2BD-402A-B830-04CC45F6AB55}.Release|Win32.Build.0 = Release-Static|Win32 + {A7C4BC47-C2BD-402A-B830-04CC45F6AB55}.Release|x64.ActiveCfg = Release-Static|x64 + {A7C4BC47-C2BD-402A-B830-04CC45F6AB55}.Release|x64.Build.0 = Release-Static|x64 {35D15EBD-F0D0-4DDF-ABEF-36B8E0F4BCAC}.Debug|Win32.ActiveCfg = Debug|Win32 {35D15EBD-F0D0-4DDF-ABEF-36B8E0F4BCAC}.Debug|Win32.Build.0 = Debug|Win32 + {35D15EBD-F0D0-4DDF-ABEF-36B8E0F4BCAC}.Debug|x64.ActiveCfg = Debug|x64 + {35D15EBD-F0D0-4DDF-ABEF-36B8E0F4BCAC}.Debug|x64.Build.0 = Debug|x64 {35D15EBD-F0D0-4DDF-ABEF-36B8E0F4BCAC}.Release|Win32.ActiveCfg = Release|Win32 {35D15EBD-F0D0-4DDF-ABEF-36B8E0F4BCAC}.Release|Win32.Build.0 = Release|Win32 - {3C318B12-4004-412D-A37B-DC5D6347E380}.Debug|Win32.ActiveCfg = Debug|Win32 - {3C318B12-4004-412D-A37B-DC5D6347E380}.Debug|Win32.Build.0 = Debug|Win32 - {3C318B12-4004-412D-A37B-DC5D6347E380}.Release|Win32.ActiveCfg = Release|Win32 - {3C318B12-4004-412D-A37B-DC5D6347E380}.Release|Win32.Build.0 = Release|Win32 + {35D15EBD-F0D0-4DDF-ABEF-36B8E0F4BCAC}.Release|x64.ActiveCfg = Release|x64 + {35D15EBD-F0D0-4DDF-ABEF-36B8E0F4BCAC}.Release|x64.Build.0 = Release|x64 + {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED}.Debug|Win32.ActiveCfg = Debug|Win32 + {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED}.Debug|Win32.Build.0 = Debug|Win32 + {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED}.Debug|x64.ActiveCfg = Debug|x64 + {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED}.Debug|x64.Build.0 = Debug|x64 + {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED}.Release|Win32.ActiveCfg = Release|Win32 + {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED}.Release|Win32.Build.0 = Release|Win32 + {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED}.Release|x64.ActiveCfg = Release|x64 + {BA70A56B-0F9A-4B63-9A1D-A5E4BAB95DED}.Release|x64.Build.0 = Release|x64 {33D15EBD-FAD0-4DDF-ABEF-36BBE0F4BCAC}.Debug|Win32.ActiveCfg = Debug|Win32 {33D15EBD-FAD0-4DDF-ABEF-36BBE0F4BCAC}.Debug|Win32.Build.0 = Debug|Win32 + {33D15EBD-FAD0-4DDF-ABEF-36BBE0F4BCAC}.Debug|x64.ActiveCfg = Debug|x64 + {33D15EBD-FAD0-4DDF-ABEF-36BBE0F4BCAC}.Debug|x64.Build.0 = Debug|x64 {33D15EBD-FAD0-4DDF-ABEF-36BBE0F4BCAC}.Release|Win32.ActiveCfg = Release|Win32 {33D15EBD-FAD0-4DDF-ABEF-36BBE0F4BCAC}.Release|Win32.Build.0 = Release|Win32 + {33D15EBD-FAD0-4DDF-ABEF-36BBE0F4BCAC}.Release|x64.ActiveCfg = Release|x64 + {33D15EBD-FAD0-4DDF-ABEF-36BBE0F4BCAC}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/HostSupport/HostSupport.vcproj b/HostSupport/HostSupport.vcproj index 74ab97c25..618ad270f 100644 --- a/HostSupport/HostSupport.vcproj +++ b/HostSupport/HostSupport.vcproj @@ -43,7 +43,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="..\include;include;expat-2.0.1\lib" - PreprocessorDefinitions="WIN32;WINDOWS;COMPILED_FROM_DSP;XML_STATIC" + PreprocessorDefinitions="_CRTDBG_MAP_ALLOC;WIN32;WINDOWS;COMPILED_FROM_DSP;XML_STATIC" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -81,12 +81,11 @@ /> @@ -289,16 +294,15 @@ /> + @@ -91,8 +94,8 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HostSupport/examples/cacheDemo.cpp b/HostSupport/examples/cacheDemo.cpp index 32ca749b4..cc7cd5b38 100644 --- a/HostSupport/examples/cacheDemo.cpp +++ b/HostSupport/examples/cacheDemo.cpp @@ -59,8 +59,12 @@ public : int main(int argc, char **argv) { +#ifdef _WIN32 + _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); +#endif + /// set the version label in the global cache - OFX::Host::gPluginCache.setCacheVersion("cacheDemoV1"); + OFX::Host::PluginCache::getPluginCache()->setCacheVersion("cacheDemoV1"); /// create our derived image effect host CacheHost myHost; @@ -69,18 +73,20 @@ int main(int argc, char **argv) OFX::Host::ImageEffect::PluginCache imageEffectPluginCache(myHost); /// register the image effect cache with the global plugin cache - imageEffectPluginCache.registerInCache(OFX::Host::gPluginCache); + imageEffectPluginCache.registerInCache(*OFX::Host::PluginCache::getPluginCache()); /// now read an old cache cache std::ifstream ifs("oldcache.xml"); - OFX::Host::gPluginCache.readCache(ifs); - OFX::Host::gPluginCache.scanPluginFiles(); + OFX::Host::PluginCache::getPluginCache()->readCache(ifs); + OFX::Host::PluginCache::getPluginCache()->scanPluginFiles(); ifs.close(); /// and write a new cache, long version with everything in there std::ofstream of("newCache.xml"); - OFX::Host::gPluginCache.writePluginCache(of); + OFX::Host::PluginCache::getPluginCache()->writePluginCache(of); of.close(); imageEffectPluginCache.dumpToStdOut(); + //Clean up, to be polite. + OFX::Host::PluginCache::clearPluginCache(); } diff --git a/HostSupport/examples/hostDemo.cpp b/HostSupport/examples/hostDemo.cpp index 0a6a6ebf3..c3cdd8517 100755 --- a/HostSupport/examples/hostDemo.cpp +++ b/HostSupport/examples/hostDemo.cpp @@ -94,8 +94,12 @@ void exportToPGM(const std::string& fname, MyHost::MyImage* im) int main(int argc, char **argv) { + //_CrtSetBreakAlloc(3168); +#ifdef _WIN32 + _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); +#endif // set the version label in the global cache - OFX::Host::gPluginCache.setCacheVersion("hostDemoV1"); + OFX::Host::PluginCache::getPluginCache()->setCacheVersion("hostDemoV1"); // create our derived image effect host which provides // a factory to make plugin instances and acts @@ -107,17 +111,17 @@ int main(int argc, char **argv) OFX::Host::ImageEffect::PluginCache imageEffectPluginCache(myHost); // register the image effect cache with the global plugin cache - imageEffectPluginCache.registerInCache(OFX::Host::gPluginCache); + imageEffectPluginCache.registerInCache(*OFX::Host::PluginCache::getPluginCache()); // try to read an old cache std::ifstream ifs("hostDemoPluginCache.xml"); - OFX::Host::gPluginCache.readCache(ifs); - OFX::Host::gPluginCache.scanPluginFiles(); + OFX::Host::PluginCache::getPluginCache()->readCache(ifs); + OFX::Host::PluginCache::getPluginCache()->scanPluginFiles(); ifs.close(); /// flush out the current cache std::ofstream of("hostDemoPluginCache.xml"); - OFX::Host::gPluginCache.writePluginCache(of); + OFX::Host::PluginCache::getPluginCache()->writePluginCache(of); of.close(); // get the invert example plugin which uses the OFX C++ support code @@ -195,6 +199,6 @@ int main(int argc, char **argv) instance->endRenderAction(0, numFramesToRender, 1.0, false, renderScale); } } - + OFX::Host::PluginCache::clearPluginCache(); return 0; } diff --git a/HostSupport/examples/hostDemo.vcproj b/HostSupport/examples/hostDemo.vcproj index 36b3b9559..40131894b 100755 --- a/HostSupport/examples/hostDemo.vcproj +++ b/HostSupport/examples/hostDemo.vcproj @@ -10,6 +10,9 @@ + @@ -40,7 +43,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="..\include;..\..\include;..\expat-2.0.1\lib" - PreprocessorDefinitions="WIN32;WINDOWS;COMPILED_FROM_DSP;XML_STATIC" + PreprocessorDefinitions="_CRTDBG_MAP_ALLOC;WIN32;WINDOWS;COMPILED_FROM_DSP;XML_STATIC" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="1" @@ -167,6 +170,161 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HostSupport/examples/hostDemoClipInstance.cpp b/HostSupport/examples/hostDemoClipInstance.cpp index 1fe8f3da1..27a8dfb41 100755 --- a/HostSupport/examples/hostDemoClipInstance.cpp +++ b/HostSupport/examples/hostDemoClipInstance.cpp @@ -129,6 +129,12 @@ namespace MyHost { { } + MyClipInstance::~MyClipInstance() + { + if(_outputImage) + _outputImage->releaseReference(); + } + /// Get the Raw Unmapped Pixel Depth from the host. We are always 8 bits in our example const std::string &MyClipInstance::getUnmappedBitDepth() const { diff --git a/HostSupport/examples/hostDemoClipInstance.h b/HostSupport/examples/hostDemoClipInstance.h index 66138e317..dff3a057c 100755 --- a/HostSupport/examples/hostDemoClipInstance.h +++ b/HostSupport/examples/hostDemoClipInstance.h @@ -30,7 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef HOST_DEMO_CLIP_INSTANCE_H #define HOST_DEMO_CLIP_INSTANCE_H -#define OFXHOSTDEMOCLIPLENGTH 25.0 +#define OFXHOSTDEMOCLIPLENGTH 1.0 namespace MyHost { @@ -57,6 +57,7 @@ namespace MyHost { public: MyClipInstance(MyEffectInstance* effect, OFX::Host::ImageEffect::ClipDescriptor* desc); + virtual ~MyClipInstance(); MyImage* getOutputImage() { return _outputImage; } /// Get the Raw Unmapped Pixel Depth from the host diff --git a/HostSupport/examples/hostDemoEffectInstance.cpp b/HostSupport/examples/hostDemoEffectInstance.cpp index 2393a7d38..d02f10e31 100755 --- a/HostSupport/examples/hostDemoEffectInstance.cpp +++ b/HostSupport/examples/hostDemoEffectInstance.cpp @@ -66,7 +66,8 @@ namespace MyHost { // get a new clip instance OFX::Host::ImageEffect::ClipInstance* MyEffectInstance::newClipInstance(OFX::Host::ImageEffect::Instance* plugin, - OFX::Host::ImageEffect::ClipDescriptor* descriptor) + OFX::Host::ImageEffect::ClipDescriptor* descriptor, + int index) { return new MyClipInstance(this,descriptor); } diff --git a/HostSupport/examples/hostDemoEffectInstance.h b/HostSupport/examples/hostDemoEffectInstance.h index 8f4a4180d..1beee58a8 100755 --- a/HostSupport/examples/hostDemoEffectInstance.h +++ b/HostSupport/examples/hostDemoEffectInstance.h @@ -52,7 +52,8 @@ namespace MyHost { /// make a clip OFX::Host::ImageEffect::ClipInstance* newClipInstance(OFX::Host::ImageEffect::Instance* plugin, - OFX::Host::ImageEffect::ClipDescriptor* descriptor); + OFX::Host::ImageEffect::ClipDescriptor* descriptor, + int index); /// vmessage diff --git a/HostSupport/expat-2.0.1/lib/expat_static.vcproj b/HostSupport/expat-2.0.1/lib/expat_static.vcproj index ecf41b3df..24b921542 100644 --- a/HostSupport/expat-2.0.1/lib/expat_static.vcproj +++ b/HostSupport/expat-2.0.1/lib/expat_static.vcproj @@ -91,9 +91,9 @@ /> @@ -293,7 +293,7 @@ /> _knownContexts; mutable bool _madeKnownContexts; - PluginHandle* _pluginHandle; + std::auto_ptr _pluginHandle; void addContextInternal(const std::string &context) const; public: + virtual ~ImageEffectPlugin(); ImageEffectPlugin(PluginCache &pc, PluginBinary *pb, int pi, OfxPlugin *pl); ImageEffectPlugin(PluginCache &pc, @@ -79,7 +80,7 @@ namespace OFX { const std::string &pluginId, int pluginMajorVersion, int pluginMinorVersion); - + /// return the API handler this plugin was constructed by APICache::PluginAPICacheI& getApiHandler(); diff --git a/HostSupport/include/ofxhInteract.h b/HostSupport/include/ofxhInteract.h index 06b38833f..448b26a3a 100755 --- a/HostSupport/include/ofxhInteract.h +++ b/HostSupport/include/ofxhInteract.h @@ -70,6 +70,8 @@ namespace OFX { /// CTOR Descriptor(); + virtual ~Descriptor() {} + /// set the main entry points void setEntryPoint(OfxPluginEntryPoint *entryPoint) {_entryPoint = entryPoint;} @@ -133,13 +135,13 @@ namespace OFX { /// hooks to kOfxInteractPropViewportSize in the property set /// this is actually redundant and is to be deprecated - virtual void getViewportSize(double &width, double &height) = 0; + virtual void getViewportSize(double &width, double &height) const = 0; // hooks to live kOfxInteractPropPixelScale in the property set - virtual void getPixelScale(double& xScale, double& yScale) = 0; + virtual void getPixelScale(double& xScale, double& yScale) const = 0; // hooks to kOfxInteractPropBackgroundColour in the property set - virtual void getBackgroundColour(double &r, double &g, double &b) = 0; + virtual void getBackgroundColour(double &r, double &g, double &b) const = 0; /// implement virtual OfxStatus swapBuffers() = 0; @@ -157,10 +159,10 @@ namespace OFX { virtual void reset(const std::string &name) OFX_EXCEPTION_SPEC; /// the gethook virutals for pixel scale, background colour - virtual double getDoubleProperty(const std::string &name, int index) OFX_EXCEPTION_SPEC; + virtual double getDoubleProperty(const std::string &name, int index) const OFX_EXCEPTION_SPEC; /// for pixel scale and background colour - virtual void getDoublePropertyN(const std::string &name, double *first, int n) OFX_EXCEPTION_SPEC; + virtual void getDoublePropertyN(const std::string &name, double *first, int n) const OFX_EXCEPTION_SPEC; /// call create instance virtual OfxStatus createInstanceAction(); diff --git a/HostSupport/include/ofxhMemory.h b/HostSupport/include/ofxhMemory.h index 8744f789c..26c62ad2a 100755 --- a/HostSupport/include/ofxhMemory.h +++ b/HostSupport/include/ofxhMemory.h @@ -44,7 +44,7 @@ namespace OFX { virtual ~Instance(); virtual bool alloc(size_t nBytes); virtual OfxImageMemoryHandle getHandle(); - virtual void free(); + virtual void freeMem(); virtual void* getPtr(); virtual void lock(); virtual void unlock(); diff --git a/HostSupport/include/ofxhParam.h b/HostSupport/include/ofxhParam.h index f2df3be15..5a9108f47 100755 --- a/HostSupport/include/ofxhParam.h +++ b/HostSupport/include/ofxhParam.h @@ -132,7 +132,7 @@ namespace OFX { public: SetDescriptor(); - ~SetDescriptor(); + virtual ~SetDescriptor(); const std::map& getParams() const; diff --git a/HostSupport/include/ofxhPluginCache.h b/HostSupport/include/ofxhPluginCache.h index 88ee85a11..ab1ef0990 100644 --- a/HostSupport/include/ofxhPluginCache.h +++ b/HostSupport/include/ofxhPluginCache.h @@ -249,7 +249,7 @@ namespace OFX { public: PluginHandle(Plugin *p, OFX::Host::Host *_host); - ~PluginHandle(); + virtual ~PluginHandle(); OfxPlugin *getOfxPlugin() { return _op; } @@ -298,11 +298,15 @@ namespace OFX { bool _ignoreCache; std::string _cacheVersion; - + static PluginCache* gPluginCachePtr; public: /// ctor, which inits _pluginPath to default locations and not much else PluginCache(); + virtual ~PluginCache(); + static PluginCache* getPluginCache(); + static void clearPluginCache(); + /// get the list in which plugins are sought const std::list &getPluginPath() const { return _pluginPath; @@ -349,10 +353,6 @@ namespace OFX { return _plugins; } }; - - /// the global plugin cache - extern PluginCache gPluginCache; - } } diff --git a/HostSupport/include/ofxhPropertySuite.h b/HostSupport/include/ofxhPropertySuite.h index c79a25e23..e16543431 100644 --- a/HostSupport/include/ofxhPropertySuite.h +++ b/HostSupport/include/ofxhPropertySuite.h @@ -341,7 +341,7 @@ namespace OFX { return new PropertyTemplate(*this); } - ~PropertyTemplate() + virtual ~PropertyTemplate() { } diff --git a/HostSupport/src/ofxhBinary.cpp b/HostSupport/src/ofxhBinary.cpp index f7c9e26d5..c8554ef44 100755 --- a/HostSupport/src/ofxhBinary.cpp +++ b/HostSupport/src/ofxhBinary.cpp @@ -45,7 +45,11 @@ Binary::Binary(const std::string &binaryPath): _binaryPath(binaryPath), _invalid // actually open the binary. -void Binary::load() { +void Binary::load() +{ + if(_invalid) + return; + #if defined (UNIX) _dlHandle = dlopen(_binaryPath.c_str(), RTLD_LAZY); #else diff --git a/HostSupport/src/ofxhImageEffect.cpp b/HostSupport/src/ofxhImageEffect.cpp index 742707ee0..6f318e4d3 100755 --- a/HostSupport/src/ofxhImageEffect.cpp +++ b/HostSupport/src/ofxhImageEffect.cpp @@ -266,6 +266,13 @@ namespace OFX { gImageEffectHost->initDescriptor(this); } + Descriptor::~Descriptor() + { + for(std::map::iterator it = _clips.begin(); it != _clips.end(); ++it) + delete it->second; + _clips.clear(); + } + /// create a new clip and add this to the clip map ClipDescriptor *Descriptor::defineClip(const std::string &name) { ClipDescriptor *c = new ClipDescriptor(name); @@ -380,12 +387,12 @@ namespace OFX { OfxStatus Instance::populate() { const std::vector& clips = _descriptor->getClipsByOrder(); - - for(std::vector::const_iterator it=clips.begin(); it!=clips.end(); it++) + int counter = 0; + for(std::vector::const_iterator it=clips.begin(); it!=clips.end(); it++, counter++) { const std::string& name = (*it)->getName(); // foreach clip descriptor make a clip instance - ClipInstance* instance = newClipInstance(this, *it); + ClipInstance* instance = newClipInstance(this, *it, counter); if(!instance) return kOfxStatFailed; @@ -1648,7 +1655,7 @@ namespace OFX { Memory::Instance *memoryInstance = reinterpret_cast(memoryHandle); if(memoryInstance && memoryInstance->verifyMagic()) { - memoryInstance->free(); + memoryInstance->freeMem(); delete memoryInstance; return kOfxStatOK; } @@ -1952,10 +1959,14 @@ namespace OFX { return 0; } else if (strcmp(suiteName, kOfxTimeLineSuite)==0) { - if(suiteVersion==1) - return (void*)&gTimelineSuite; - else - return 0; + // Temporary change to disable timeline suite function calls + return 0; + /* + if(suiteVersion==1) + return (void*)&gTimelineSuite; + else + return 0; + */ } else if (strcmp(suiteName, kOfxMultiThreadSuite)==0) { if(suiteVersion == 1) diff --git a/HostSupport/src/ofxhImageEffectAPI.cpp b/HostSupport/src/ofxhImageEffectAPI.cpp index dd6832071..a228387ad 100755 --- a/HostSupport/src/ofxhImageEffectAPI.cpp +++ b/HostSupport/src/ofxhImageEffectAPI.cpp @@ -65,7 +65,6 @@ namespace OFX { , _pc(pc) , _baseDescriptor(this) , _madeKnownContexts(false) - , _pluginHandle(0) {} ImageEffectPlugin::ImageEffectPlugin(PluginCache &pc, @@ -80,7 +79,6 @@ namespace OFX { , _pc(pc) , _baseDescriptor(this) , _madeKnownContexts(false) - , _pluginHandle(0) {} #ifdef WINDOWS @@ -140,36 +138,33 @@ namespace OFX { PluginHandle *ImageEffectPlugin::getPluginHandle() { - if(!_pluginHandle) + if(!_pluginHandle.get()) { - _pluginHandle = new OFX::Host::PluginHandle(this, _pc.getHost()); + _pluginHandle.reset(new OFX::Host::PluginHandle(this, _pc.getHost())); OfxPlugin *op = _pluginHandle->getOfxPlugin(); if (!op) { - delete _pluginHandle; - _pluginHandle = 0; + _pluginHandle.reset(0); return 0; } int rval = op->mainEntry(kOfxActionLoad, 0, 0, 0); if (rval != kOfxStatOK && rval != kOfxStatReplyDefault) { - delete _pluginHandle; - _pluginHandle = 0; + _pluginHandle.reset(0); return 0; } rval = op->mainEntry(kOfxActionDescribe, getDescriptor().getHandle(), 0, 0); if (rval != kOfxStatOK && rval != kOfxStatReplyDefault) { - delete _pluginHandle; - _pluginHandle = 0; + _pluginHandle.reset(0); return 0; } } - return _pluginHandle; + return _pluginHandle.get(); } Descriptor *ImageEffectPlugin::getContext(const std::string &context) @@ -191,20 +186,32 @@ namespace OFX { OFX::Host::Property::Set inarg(inargspec); PluginHandle *ph = getPluginHandle(); - ImageEffect::Descriptor *newContext = new ImageEffect::Descriptor(getDescriptor(), this); + std::auto_ptr newContext(new ImageEffect::Descriptor(getDescriptor(), this)); int rval = ph->getOfxPlugin()->mainEntry(kOfxImageEffectActionDescribeInContext, newContext->getHandle(), inarg.getHandle(), 0); if (rval == kOfxStatOK || rval == kOfxStatReplyDefault) { - _contexts[context] = newContext; - return newContext; + _contexts[context] = newContext.release(); + return _contexts[context]; } - - delete newContext; return 0; } + ImageEffectPlugin::~ImageEffectPlugin() + { + for(std::map::iterator it = _contexts.begin(); it != _contexts.end(); ++it) + { + delete it->second; + } + _contexts.clear(); + if(_pluginHandle.get()) + { + OfxPlugin *op = _pluginHandle->getOfxPlugin(); + op->mainEntry(kOfxActionUnload, 0, 0, 0); + } + } + ImageEffect::Instance* ImageEffectPlugin::createInstance(const std::string &context, void *clientData) { diff --git a/HostSupport/src/ofxhInteract.cpp b/HostSupport/src/ofxhInteract.cpp index 208a151cf..1bfac3444 100755 --- a/HostSupport/src/ofxhInteract.cpp +++ b/HostSupport/src/ofxhInteract.cpp @@ -181,7 +181,7 @@ namespace OFX { // no-op } - double Instance::getDoubleProperty(const std::string &name, int index) OFX_EXCEPTION_SPEC + double Instance::getDoubleProperty(const std::string &name, int index) const OFX_EXCEPTION_SPEC { if(name == kOfxInteractPropPixelScale){ if(index>=2) throw Property::Exception(kOfxStatErrBadIndex); @@ -205,7 +205,7 @@ namespace OFX { throw Property::Exception(kOfxStatErrUnknown); } - void Instance::getDoublePropertyN(const std::string &name, double *first, int n) OFX_EXCEPTION_SPEC + void Instance::getDoublePropertyN(const std::string &name, double *first, int n) const OFX_EXCEPTION_SPEC { if(name == kOfxInteractPropPixelScale){ if(n>2) throw Property::Exception(kOfxStatErrBadIndex); @@ -237,6 +237,8 @@ namespace OFX { void Instance::initArgProp(OfxTime time, const OfxPointD &renderScale) { + double vals[2]; + _argProperties.getDoublePropertyN(kOfxInteractPropPixelScale, vals, 2); _argProperties.setPointerProperty(kOfxPropEffectInstance, _effectInstance); _argProperties.setPointerProperty(kOfxPropInstanceData, _properties.getPointerProperty(kOfxPropInstanceData)); _argProperties.setDoubleProperty(kOfxPropTime,time); diff --git a/HostSupport/src/ofxhMemory.cpp b/HostSupport/src/ofxhMemory.cpp index 94cff0ad0..86eadcd16 100755 --- a/HostSupport/src/ofxhMemory.cpp +++ b/HostSupport/src/ofxhMemory.cpp @@ -51,7 +51,7 @@ namespace OFX { bool Instance::alloc(size_t nBytes) { if(!_locked){ if(_ptr) - free(); + freeMem(); _ptr = new char[nBytes]; return true; } @@ -63,7 +63,7 @@ namespace OFX { return (OfxImageMemoryHandle)this; } - void Instance::free(){ + void Instance::freeMem(){ delete [] _ptr; _ptr = 0; } diff --git a/HostSupport/src/ofxhParam.cpp b/HostSupport/src/ofxhParam.cpp index 753bce595..60eb38be2 100755 --- a/HostSupport/src/ofxhParam.cpp +++ b/HostSupport/src/ofxhParam.cpp @@ -356,6 +356,9 @@ namespace OFX { SetDescriptor::~SetDescriptor() { + for(std::list::iterator it = _paramList.begin(); it != _paramList.end(); ++it) + delete (*it); + _paramList.clear(); } const std::map& SetDescriptor::getParams() const diff --git a/HostSupport/src/ofxhPluginAPICache.cpp b/HostSupport/src/ofxhPluginAPICache.cpp index 05dca7949..ddf814ff9 100644 --- a/HostSupport/src/ofxhPluginAPICache.cpp +++ b/HostSupport/src/ofxhPluginAPICache.cpp @@ -60,10 +60,10 @@ namespace OFX } void propertySetXMLRead(const std::string &el, - std::map map, + std::map map, Property::Set &set, - Property::Property *&_currentProp) { + Property::Property *&_currentProp) + { if (el == "property") { std::string propName = map["name"]; std::string propType = map["type"]; diff --git a/HostSupport/src/ofxhPluginCache.cpp b/HostSupport/src/ofxhPluginCache.cpp index db6f089b5..6372ddf93 100644 --- a/HostSupport/src/ofxhPluginCache.cpp +++ b/HostSupport/src/ofxhPluginCache.cpp @@ -68,7 +68,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #elif defined (WINDOWS) #define DIRLIST_SEP_CHAR ";" -#ifdef WIN64 +#ifdef _WIN64 #define ARCHSTR "win64" #else #define ARCHSTR "win32" @@ -79,487 +79,508 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "tchar.h" #endif -namespace OFX { +OFX::Host::PluginCache* OFX::Host::PluginCache::gPluginCachePtr = 0; - namespace Host { +using namespace OFX::Host; - /// try to open the plugin bundle object and query it for plugins - void PluginBinary::loadPluginInfo(PluginCache *cache) { - _fileModificationTime = _binary.getTime(); - _fileSize = _binary.getSize(); - _binaryChanged = false; +/// try to open the plugin bundle object and query it for plugins +void PluginBinary::loadPluginInfo(PluginCache *cache) { + _fileModificationTime = _binary.getTime(); + _fileSize = _binary.getSize(); + _binaryChanged = false; - _binary.load(); + _binary.load(); - int (*getNo)(void) = (int(*)()) _binary.findSymbol("OfxGetNumberOfPlugins"); - OfxPlugin* (*getPlug)(int) = (OfxPlugin*(*)(int)) _binary.findSymbol("OfxGetPlugin"); + int (*getNo)(void) = (int(*)()) _binary.findSymbol("OfxGetNumberOfPlugins"); + OfxPlugin* (*getPlug)(int) = (OfxPlugin*(*)(int)) _binary.findSymbol("OfxGetPlugin"); - if (getNo == 0 || getPlug == 0) { + if (getNo == 0 || getPlug == 0) { - _binary.setInvalid(true); + _binary.setInvalid(true); - } else { - int pluginCount = (*getNo)(); + } else { + int pluginCount = (*getNo)(); - _plugins.reserve(pluginCount); + _plugins.reserve(pluginCount); - for (int i=0;ifindApiHandler(plug->pluginApi, plug->apiVersion); - assert(api); + APICache::PluginAPICacheI *api = cache->findApiHandler(plug->pluginApi, plug->apiVersion); + assert(api); - _plugins.push_back(api->newPlugin(this, i, plug)); - } - } - - _binary.unload(); + _plugins.push_back(api->newPlugin(this, i, plug)); } + } - PluginBinary::~PluginBinary() { - std::vector::iterator i = _plugins.begin(); - while (i != _plugins.end()) { - delete *i; - i++; - } - } + _binary.unload(); +} - PluginHandle::PluginHandle(Plugin *p, OFX::Host::Host *host) : _p(p) - { - _b = p->getBinary(); - _b->_binary.ref(); - _op = 0; - OfxPlugin* (*getPlug)(int) = (OfxPlugin*(*)(int)) _b->_binary.findSymbol("OfxGetPlugin"); - if (getPlug) { - _op = getPlug(p->getIndex()); - if (_op) { - _op->setHost(host->getHandle()); - } - } - } +PluginBinary::~PluginBinary() { + std::vector::iterator i = _plugins.begin(); + while (i != _plugins.end()) { + delete *i; + i++; + } +} - PluginHandle::~PluginHandle() { - _b->_binary.unref(); +PluginHandle::PluginHandle(Plugin *p, OFX::Host::Host *host) : _p(p) +{ + _b = p->getBinary(); + _b->_binary.ref(); + _op = 0; + OfxPlugin* (*getPlug)(int) = (OfxPlugin*(*)(int)) _b->_binary.findSymbol("OfxGetPlugin"); + if (getPlug) { + _op = getPlug(p->getIndex()); + if (_op) { + _op->setHost(host->getHandle()); } + } +} - PluginCache gPluginCache; +PluginHandle::~PluginHandle() { + _b->_binary.unref(); +} #if defined (WINDOWS) - const TCHAR *getStdOFXPluginPath(void) - { - static TCHAR buffer[MAX_PATH]; - static int gotIt = 0; - if(!gotIt) { - gotIt = 1; - SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, SHGFP_TYPE_CURRENT, buffer); - strcat_s(buffer, MAX_PATH, __T("\\OFX\\Plugins")); - } - return buffer; - } +const TCHAR *getStdOFXPluginPath(void) +{ + static TCHAR buffer[MAX_PATH]; + static int gotIt = 0; + if(!gotIt) { + gotIt = 1; + SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, SHGFP_TYPE_CURRENT, buffer); + strcat_s(buffer, MAX_PATH, __T("\\OFX\\Plugins")); + } + return buffer; +} #endif - std::string OFXGetEnv(const char* e) - { +std::string OFXGetEnv(const char* e) +{ #ifdef WINDOWS - size_t requiredSize; - getenv_s(&requiredSize, 0, 0, e); - std::vector buffer(requiredSize); - if(requiredSize >0) - { - getenv_s(&requiredSize, &buffer.front(), requiredSize, e); - return &buffer.front(); - } - return ""; + size_t requiredSize; + getenv_s(&requiredSize, 0, 0, e); + std::vector buffer(requiredSize); + if(requiredSize >0) + { + getenv_s(&requiredSize, &buffer.front(), requiredSize, e); + return &buffer.front(); + } + return ""; #else - if(getenv(e)) - return getenv(e); + if(getenv(e)) + return getenv(e); #endif - return ""; - } + return ""; +} + +PluginCache* PluginCache::getPluginCache() +{ + if(!gPluginCachePtr) + gPluginCachePtr = new PluginCache(); + return gPluginCachePtr; +} - PluginCache::PluginCache() : _xmlCurrentBinary(0), _xmlCurrentPlugin(0) { +void PluginCache::clearPluginCache() +{ + delete gPluginCachePtr; + gPluginCachePtr = 0; +} - _cacheVersion = ""; - _ignoreCache = false; +PluginCache::~PluginCache() +{ + for(std::list::iterator it=_binaries.begin(); it != _binaries.end(); ++it) + { + PluginBinary* p = *it; + delete (*it); + } + _binaries.clear(); +} - std::string s = OFXGetEnv("OFX_PLUGIN_PATH"); +PluginCache::PluginCache() : _xmlCurrentBinary(0), _xmlCurrentPlugin(0) { - while (s.length()) - { + _cacheVersion = ""; + _ignoreCache = false; - int spos = (int)s.find(DIRLIST_SEP_CHAR); + std::string s = OFXGetEnv("OFX_PLUGIN_PATH"); - std::string path; + while (s.length()) + { - if (spos != -1) { - path = s.substr(0, spos); - s = s.substr(spos+1); - } - else { - path = s; - s = ""; - } + int spos = (int)s.find(DIRLIST_SEP_CHAR); - _pluginPath.push_back(path); - } + std::string path; + + if (spos != -1) { + path = s.substr(0, spos); + s = s.substr(spos+1); + } + else { + path = s; + s = ""; + } + + _pluginPath.push_back(path); + } #if defined(WINDOWS) - _pluginPath.push_back(getStdOFXPluginPath()); - _pluginPath.push_back("C:\\Program Files\\Common Files\\OFX\\Plugins"); + _pluginPath.push_back(getStdOFXPluginPath()); + _pluginPath.push_back("C:\\Program Files\\Common Files\\OFX\\Plugins"); #endif #if defined(__linux__) - _pluginPath.push_back("/usr/OFX/Plugins"); + _pluginPath.push_back("/usr/OFX/Plugins"); #endif #if defined(__APPLE__) - _pluginPath.push_back("/Library/OFX/Plugins"); + _pluginPath.push_back("/Library/OFX/Plugins"); #endif - } +} - void PluginCache::scanDirectory(std::set &foundBinFiles, const std::string &dir, bool recurse) - { +void PluginCache::scanDirectory(std::set &foundBinFiles, const std::string &dir, bool recurse) +{ #if defined (WINDOWS) - WIN32_FIND_DATA findData; - HANDLE findHandle; + WIN32_FIND_DATA findData; + HANDLE findHandle; #else - DIR *d = opendir(dir.c_str()); - if (!d) { - return; - } + DIR *d = opendir(dir.c_str()); + if (!d) { + return; + } #endif #if defined (UNIX) - while (dirent *de = readdir(d)) + while (dirent *de = readdir(d)) #elif defined (WINDOWS) - findHandle = FindFirstFile((dir + "\\*").c_str(), &findData); + findHandle = FindFirstFile((dir + "\\*").c_str(), &findData); - if (findHandle == INVALID_HANDLE_VALUE) - { - return; - } + if (findHandle == INVALID_HANDLE_VALUE) + { + return; + } - while (1) + while (1) #endif - { + { #if defined (UNIX) - std::string name = de->d_name; + std::string name = de->d_name; #else - std::string name = findData.cFileName; + std::string name = findData.cFileName; #endif - if (recurse && name[0] != '@' && name != "." && name != "..") { - scanDirectory(foundBinFiles, dir + DIRSEP + name, recurse); - } + if (recurse && name[0] != '@' && name != "." && name != "..") { + scanDirectory(foundBinFiles, dir + DIRSEP + name, recurse); + } - if (name.find(".ofx.bundle") != std::string::npos) { - std::string barename = name.substr(0, name.length() - strlen(".bundle")); - std::string bundlename = dir + DIRSEP + name; - std::string binpath = dir + DIRSEP + name + DIRSEP "Contents" DIRSEP ARCHSTR DIRSEP + barename; + if (name.find(".ofx.bundle") != std::string::npos) { + std::string barename = name.substr(0, name.length() - strlen(".bundle")); + std::string bundlename = dir + DIRSEP + name; + std::string binpath = dir + DIRSEP + name + DIRSEP "Contents" DIRSEP ARCHSTR DIRSEP + barename; - foundBinFiles.insert(binpath); + foundBinFiles.insert(binpath); - if (_knownBinFiles.find(binpath) == _knownBinFiles.end()) { + if (_knownBinFiles.find(binpath) == _knownBinFiles.end()) { - // the binary was not in the cache + // the binary was not in the cache - PluginBinary *pb = new PluginBinary(binpath, bundlename, this); - _binaries.push_back(pb); - _knownBinFiles.insert(binpath); + PluginBinary *pb = new PluginBinary(binpath, bundlename, this); + _binaries.push_back(pb); + _knownBinFiles.insert(binpath); - for (int j=0;jgetNPlugins();j++) { - Plugin *plug = &pb->getPlugin(j); - const APICache::PluginAPICacheI &api = plug->getApiHandler(); - api.loadFromPlugin(plug); - } - } + for (int j=0;jgetNPlugins();j++) { + Plugin *plug = &pb->getPlugin(j); + const APICache::PluginAPICacheI &api = plug->getApiHandler(); + api.loadFromPlugin(plug); } + } + } #if defined(WINDOWS) - int rval = FindNextFile(findHandle, &findData); + int rval = FindNextFile(findHandle, &findData); - if (rval == 0) { - break; - } + if (rval == 0) { + break; + } #endif - } + } #if defined(UNIX) - closedir(d); + closedir(d); #else - FindClose(findHandle); + FindClose(findHandle); #endif - } - - void PluginCache::scanPluginFiles() - { - std::set foundBinFiles; +} - for (std::list::iterator paths= _pluginPath.begin(); - paths != _pluginPath.end(); - paths++) { - scanDirectory(foundBinFiles, *paths, _nonrecursePath.find(*paths) == _nonrecursePath.end()); - } +void PluginCache::scanPluginFiles() +{ + std::set foundBinFiles; - std::list::iterator i=_binaries.begin(); - while (i!=_binaries.end()) { - PluginBinary *pb = *i; + for (std::list::iterator paths= _pluginPath.begin(); + paths != _pluginPath.end(); + paths++) { + scanDirectory(foundBinFiles, *paths, _nonrecursePath.find(*paths) == _nonrecursePath.end()); + } - if (foundBinFiles.find(pb->getFilePath()) == foundBinFiles.end()) { + std::list::iterator i=_binaries.begin(); + while (i!=_binaries.end()) { + PluginBinary *pb = *i; - // the binary was in the cache, but was not on the path + if (foundBinFiles.find(pb->getFilePath()) == foundBinFiles.end()) { - i = _binaries.erase(i); - delete pb; + // the binary was in the cache, but was not on the path - } else { + i = _binaries.erase(i); + delete pb; - bool binChanged = pb->hasBinaryChanged(); + } + else { - // the binary was in the cache, but the binary has changed and thus we need to reload - if (binChanged) { - pb->loadPluginInfo(this); - } + bool binChanged = pb->hasBinaryChanged(); - for (int j=0;jgetNPlugins();j++) { - Plugin *plug = &pb->getPlugin(j); - APICache::PluginAPICacheI &api = plug->getApiHandler(); + // the binary was in the cache, but the binary has changed and thus we need to reload + if (binChanged) { + pb->loadPluginInfo(this); + } - if (binChanged) { - api.loadFromPlugin(plug); - } + for (int j=0;jgetNPlugins();j++) { + Plugin *plug = &pb->getPlugin(j); + APICache::PluginAPICacheI &api = plug->getApiHandler(); - std::string reason; + if (binChanged) { + api.loadFromPlugin(plug); + } - if (api.pluginSupported(plug, reason)) { - _plugins.push_back(plug); - api.confirmPlugin(plug); - } - else { - std::cerr << "ignoring plugin " << plug->getIdentifier() << - " as unsupported (" << reason << ")" << std::endl; - } - } + std::string reason; - i++; + if (api.pluginSupported(plug, reason)) { + _plugins.push_back(plug); + api.confirmPlugin(plug); + } + else { + std::cerr << "ignoring plugin " << plug->getIdentifier() << + " as unsupported (" << reason << ")" << std::endl; } } - } - - /// callback for XML parser - static void elementBeginHandler(void *userData, const XML_Char *name, const XML_Char **atts) { - gPluginCache.elementBeginCallback(userData, name, atts); - } - - /// callback for XML parser - static void elementCharHandler(void *userData, const XML_Char *data, int len) { - gPluginCache.elementCharCallback(userData, data, len); + i++; } + } +} - /// callback for XML parser - static void elementEndHandler(void *userData, const XML_Char *name) { - gPluginCache.elementEndCallback(userData, name); - } - static bool mapHasAll(const std::map &attmap, const char **atts) { - while (*atts) { - if (attmap.find(*atts) == attmap.end()) { - return false; - } - atts++; - } - return true; - } +/// callback for XML parser +static void elementBeginHandler(void *userData, const XML_Char *name, const XML_Char **atts) { + OFX::Host::PluginCache::getPluginCache()->elementBeginCallback(userData, name, atts); +} - void PluginCache::elementBeginCallback(void *userData, const XML_Char *name, const XML_Char **atts) { - if (_ignoreCache) { - return; - } +/// callback for XML parser +static void elementCharHandler(void *userData, const XML_Char *data, int len) { + OFX::Host::PluginCache::getPluginCache()->elementCharCallback(userData, data, len); +} - std::string ename = name; - std::map attmap; +/// callback for XML parser +static void elementEndHandler(void *userData, const XML_Char *name) { + OFX::Host::PluginCache::getPluginCache()->elementEndCallback(userData, name); +} - while (*atts) { - attmap[atts[0]] = atts[1]; - atts += 2; - } +static bool mapHasAll(const std::map &attmap, const char **atts) { + while (*atts) { + if (attmap.find(*atts) == attmap.end()) { + return false; + } + atts++; + } + return true; +} - /// XXX: validate in general +void PluginCache::elementBeginCallback(void *userData, const XML_Char *name, const XML_Char **atts) { + if (_ignoreCache) { + return; + } - if (ename == "cache") { - std::string cacheversion = attmap["version"]; - if (cacheversion != _cacheVersion) { - _ignoreCache = true; - } - } + std::string ename = name; + std::map attmap; - if (ename == "binary") { - const char *binAtts[] = {"path", "bundlepath", "mtime", "size", NULL}; + while (*atts) { + attmap[atts[0]] = atts[1]; + atts += 2; + } - if (!mapHasAll(attmap, binAtts)) { - // no path: bad XML - } + /// XXX: validate in general - std::string fname = attmap["path"]; - std::string bname = attmap["bundle_path"]; - time_t mtime = OFX::Host::Property::stringToInt(attmap["mtime"]); - size_t size = OFX::Host::Property::stringToInt(attmap["size"]); + if (ename == "cache") { + std::string cacheversion = attmap["version"]; + if (cacheversion != _cacheVersion) { + _ignoreCache = true; + } + } - _xmlCurrentBinary = new PluginBinary(fname, bname, mtime, size); - _binaries.push_back(_xmlCurrentBinary); - _knownBinFiles.insert(fname); - return; - } + if (ename == "binary") { + const char *binAtts[] = {"path", "bundlepath", "mtime", "size", NULL}; - if (ename == "plugin" && _xmlCurrentBinary && !_xmlCurrentBinary->hasBinaryChanged()) { - const char *plugAtts[] = {"api", "name", "index", "api_version", "major_version", "minor_version", NULL}; + if (!mapHasAll(attmap, binAtts)) { + // no path: bad XML + } - if (!mapHasAll(attmap, plugAtts)) { - // no path: bad XML - } + std::string fname = attmap["path"]; + std::string bname = attmap["bundle_path"]; + time_t mtime = OFX::Host::Property::stringToInt(attmap["mtime"]); + size_t size = OFX::Host::Property::stringToInt(attmap["size"]); - std::string api = attmap["api"]; - std::string identifier = attmap["name"]; - int idx = OFX::Host::Property::stringToInt(attmap["index"]); - int api_version = OFX::Host::Property::stringToInt(attmap["api_version"]); - int major_version = OFX::Host::Property::stringToInt(attmap["major_version"]); - int minor_version = OFX::Host::Property::stringToInt(attmap["minor_version"]); + _xmlCurrentBinary = new PluginBinary(fname, bname, mtime, size); + _binaries.push_back(_xmlCurrentBinary); + _knownBinFiles.insert(fname); + return; + } - APICache::PluginAPICacheI *apiCache = findApiHandler(api, api_version); - if (apiCache) { + if (ename == "plugin" && _xmlCurrentBinary && !_xmlCurrentBinary->hasBinaryChanged()) { + const char *plugAtts[] = {"api", "name", "index", "api_version", "major_version", "minor_version", NULL}; - Plugin *pe = apiCache->newPlugin(_xmlCurrentBinary, idx, api, api_version, identifier, major_version, minor_version); - _xmlCurrentBinary->addPlugin(pe); - _xmlCurrentPlugin = pe; - apiCache->beginXmlParsing(pe); - } + if (!mapHasAll(attmap, plugAtts)) { + // no path: bad XML + } - return; - } + std::string api = attmap["api"]; + std::string identifier = attmap["name"]; + int idx = OFX::Host::Property::stringToInt(attmap["index"]); + int api_version = OFX::Host::Property::stringToInt(attmap["api_version"]); + int major_version = OFX::Host::Property::stringToInt(attmap["major_version"]); + int minor_version = OFX::Host::Property::stringToInt(attmap["minor_version"]); - if (_xmlCurrentPlugin) { - APICache::PluginAPICacheI &api = _xmlCurrentPlugin->getApiHandler(); - api.xmlElementBegin(name, attmap); - } + APICache::PluginAPICacheI *apiCache = findApiHandler(api, api_version); + if (apiCache) { + Plugin *pe = apiCache->newPlugin(_xmlCurrentBinary, idx, api, api_version, identifier, major_version, minor_version); + _xmlCurrentBinary->addPlugin(pe); + _xmlCurrentPlugin = pe; + apiCache->beginXmlParsing(pe); } - void PluginCache::elementCharCallback(void *userData, const XML_Char *data, int size) - { - if (_ignoreCache) { - return; - } + return; + } - std::string s(data, size); - if (_xmlCurrentPlugin) { - APICache::PluginAPICacheI &api = _xmlCurrentPlugin->getApiHandler(); - api.xmlCharacterHandler(s); - } - else { - /// XXX: we only want whitespace - } - } + if (_xmlCurrentPlugin) { + APICache::PluginAPICacheI &api = _xmlCurrentPlugin->getApiHandler(); + api.xmlElementBegin(name, attmap); + } - void PluginCache::elementEndCallback(void *userData, const XML_Char *name) { - if (_ignoreCache) { - return; - } +} - std::string ename = name; +void PluginCache::elementCharCallback(void *userData, const XML_Char *data, int size) +{ + if (_ignoreCache) { + return; + } - /// XXX: validation? + std::string s(data, size); + if (_xmlCurrentPlugin) { + APICache::PluginAPICacheI &api = _xmlCurrentPlugin->getApiHandler(); + api.xmlCharacterHandler(s); + } + else { + /// XXX: we only want whitespace + } +} - if (ename == "plugin") { - if (_xmlCurrentPlugin) { - APICache::PluginAPICacheI &api = _xmlCurrentPlugin->getApiHandler(); - api.endXmlParsing(); - } - _xmlCurrentPlugin = 0; - return; - } +void PluginCache::elementEndCallback(void *userData, const XML_Char *name) { + if (_ignoreCache) { + return; + } - if (ename == "bundle") { - _xmlCurrentBinary = 0; - return; - } + std::string ename = name; - if (_xmlCurrentPlugin) { - APICache::PluginAPICacheI &api = _xmlCurrentPlugin->getApiHandler(); - api.xmlElementEnd(name); - } + /// XXX: validation? + + if (ename == "plugin") { + if (_xmlCurrentPlugin) { + APICache::PluginAPICacheI &api = _xmlCurrentPlugin->getApiHandler(); + api.endXmlParsing(); } + _xmlCurrentPlugin = 0; + return; + } - void PluginCache::readCache(std::istream &ifs) { - XML_Parser xP = XML_ParserCreate(NULL); - XML_SetElementHandler(xP, elementBeginHandler, elementEndHandler); - XML_SetCharacterDataHandler(xP, elementCharHandler); + if (ename == "bundle") { + _xmlCurrentBinary = 0; + return; + } - while (ifs.good()) { - char buf[1001] = {0}; - ifs.read(buf, 1000); + if (_xmlCurrentPlugin) { + APICache::PluginAPICacheI &api = _xmlCurrentPlugin->getApiHandler(); + api.xmlElementEnd(name); + } +} - if (buf[0] == 0) { - XML_Parse(xP, "", 0, XML_TRUE); - break; - } +void PluginCache::readCache(std::istream &ifs) { + XML_Parser xP = XML_ParserCreate(NULL); + XML_SetElementHandler(xP, elementBeginHandler, elementEndHandler); + XML_SetCharacterDataHandler(xP, elementCharHandler); - XML_Status p = XML_Parse(xP, buf, (int)strlen(buf), XML_FALSE); + while (ifs.good()) { + char buf[1001] = {0}; + ifs.read(buf, 1000); - if (p == XML_STATUS_ERROR) { - std::cout << "xml error : " << XML_GetErrorCode(xP) << std::endl; - /// XXX: do something here - break; - } - } + if (buf[0] == 0) { + XML_Parse(xP, "", 0, XML_TRUE); + break; + } - XML_ParserFree(xP); + XML_Status p = XML_Parse(xP, buf, (int)strlen(buf), XML_FALSE); + + if (p == XML_STATUS_ERROR) { + std::cout << "xml error : " << XML_GetErrorCode(xP) << std::endl; + /// XXX: do something here + break; } + } - void PluginCache::writePluginCache(std::ostream &os) const - { - os << "\n"; - for (std::list::const_iterator i=_binaries.begin();i!=_binaries.end();i++) { - PluginBinary *b = *i; - os << "\n"; - os << " getBundlePath()) - << XML::attribute("path", b->getFilePath()) - << XML::attribute("mtime", (int)b->getFileModificationTime()) - << XML::attribute("size", (int)b->getFileSize()) << "/>\n"; - - for (int j=0;jgetNPlugins();j++) { - Plugin *p = &b->getPlugin(j); - - - os << " getIdentifier()) - << XML::attribute("index", p->getIndex()) - << XML::attribute("api", p->getPluginApi()) - << XML::attribute("api_version", p->getApiVersion()) - << XML::attribute("major_version", p->getVersionMajor()) - << XML::attribute("minor_version", p->getVersionMinor()) - << ">\n"; - - const APICache::PluginAPICacheI &api = p->getApiHandler(); - os << " \n"; - api.saveXML(p, os); - os << " \n"; - - os << " \n"; - } - os << "\n"; - } - os << "\n"; + XML_ParserFree(xP); +} + +void PluginCache::writePluginCache(std::ostream &os) const +{ + os << "\n"; + for (std::list::const_iterator i=_binaries.begin();i!=_binaries.end();i++) { + PluginBinary *b = *i; + os << "\n"; + os << " getBundlePath()) + << XML::attribute("path", b->getFilePath()) + << XML::attribute("mtime", (int)b->getFileModificationTime()) + << XML::attribute("size", (int)b->getFileSize()) << "/>\n"; + + for (int j=0;jgetNPlugins();j++) { + Plugin *p = &b->getPlugin(j); + + + os << " getIdentifier()) + << XML::attribute("index", p->getIndex()) + << XML::attribute("api", p->getPluginApi()) + << XML::attribute("api_version", p->getApiVersion()) + << XML::attribute("major_version", p->getVersionMajor()) + << XML::attribute("minor_version", p->getVersionMinor()) + << ">\n"; + + const APICache::PluginAPICacheI &api = p->getApiHandler(); + os << " \n"; + api.saveXML(p, os); + os << " \n"; + + os << " \n"; } + os << "\n"; + } + os << "\n"; +} - APICache::PluginAPICacheI *PluginCache::findApiHandler(const std::string &api, int version) { - std::list::iterator i = _apiHandlers.begin(); - while (i != _apiHandlers.end()) { - if (i->matches(api, version)) { - return i->handler; - } - i++; - } - return 0; +APICache::PluginAPICacheI *PluginCache::findApiHandler(const std::string &api, int version) { + std::list::iterator i = _apiHandlers.begin(); + while (i != _apiHandlers.end()) { + if (i->matches(api, version)) { + return i->handler; } + i++; } + return 0; } + diff --git a/HostSupport/src/ofxhPropertySuite.cpp b/HostSupport/src/ofxhPropertySuite.cpp index 2350b4634..a2398adfa 100644 --- a/HostSupport/src/ofxhPropertySuite.cpp +++ b/HostSupport/src/ofxhPropertySuite.cpp @@ -497,6 +497,9 @@ namespace OFX { /// add one new property void Set::addProperty(Property *prop) { + PropertyMap::iterator t = _props.find(prop->getName()); + if(t != _props.end()) + delete t->second; _props[prop->getName()] = prop; }