TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/OfxhHost.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License :
00003  *
00004  * Copyright (c) 2007-2009, The Open Effects Association Ltd. All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * Redistributions of source code must retain the above copyright notice,
00010  *    this list of conditions and the following disclaimer.
00011  * Redistributions in binary form must reproduce the above copyright notice,
00012  *    this list of conditions and the following disclaimer in the documentation
00013  *    and/or other materials provided with the distribution.
00014  * Neither the name The Open Effects Association Ltd, nor the names of its
00015  *    contributors may be used to endorse or promote products derived from this
00016  *    software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00022  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00023  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00024  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00025  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00027  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "OfxhHost.hpp"
00031 
00032 #include "OfxhPropertySuite.hpp"
00033 #include "OfxhMemorySuite.hpp"
00034 
00035 // ofx
00036 #include <ofxCore.h>
00037 #include <ofxProperty.h>
00038 #include <ofxMultiThread.h>
00039 #include <ofxMemory.h>
00040 
00041 #include <climits>
00042 #include <cmath>
00043 #include <cfloat>
00044 #include <cstring>
00045 
00046 
00047 namespace tuttle {
00048 namespace host {
00049 namespace ofx {
00050 /// our own internal property for storing away our private pointer to our host descriptor
00051 #define kOfxHostSupportHostPointer "sf.openfx.net.OfxHostSupportHostPointer"
00052 
00053 static property::OfxhPropSpec hostStuffs[] = {
00054         { kOfxPropType, property::ePropTypeString, 1, false, "Host" },
00055         { kOfxPropName, property::ePropTypeString, 1, false, "UNKNOWN" },
00056         { kOfxPropLabel, property::ePropTypeString, 1, false, "UNKNOWN" },
00057         { kOfxHostSupportHostPointer,    property::ePropTypePointer,    0,    false,    NULL },
00058         { 0 },
00059 };
00060 
00061 static void* fetchSuite( OfxPropertySetHandle hostProps, const char* suiteName, int suiteVersion )
00062 {
00063         property::OfxhSet* properties = reinterpret_cast<property::OfxhSet*>( hostProps );
00064 
00065         OfxhHost* host = (OfxhHost*)properties->getPointerProperty( kOfxHostSupportHostPointer );
00066 
00067         if( host )
00068                 return host->fetchSuite( suiteName, suiteVersion );
00069         else
00070                 return 0;
00071 }
00072 
00073 // Base Host
00074 OfxhHost::OfxhHost() : _properties( hostStuffs )
00075 {
00076         _host.host       = _properties.getHandle();
00077         _host.fetchSuite = tuttle::host::ofx::fetchSuite;
00078 
00079         // record the host descriptor in the propert set
00080         _properties.setPointerProperty( kOfxHostSupportHostPointer, this );
00081 }
00082 
00083 OfxhHost::~OfxhHost() {}
00084 
00085 OfxHost* OfxhHost::getHandle()
00086 {
00087         return &_host;
00088 }
00089 
00090 void* OfxhHost::fetchSuite( const char* suiteName, const int suiteVersion )
00091 {
00092         if( strcmp( suiteName, kOfxPropertySuite ) == 0  && suiteVersion == 1 )
00093         {
00094                 return property::getPropertySuite( suiteVersion );
00095         }
00096         else if( strcmp( suiteName, kOfxMemorySuite ) == 0 && suiteVersion == 1 )
00097         {
00098                 return getMemorySuite( suiteVersion );
00099         }
00100 
00101         TUTTLE_LOG_TRACE("Failed to Fetch Unknown Suite: " << suiteName << " " << suiteVersion << ".");
00102         return NULL;
00103 }
00104 
00105 }
00106 }
00107 }
00108