#include "ofxsSupportPrivate.h"
#ifdef DEBUG
#include <iostream>
#if defined(__APPLE__) || defined(linux)
#include <execinfo.h>
#include <stdlib.h>
#endif
#endif
#include "ofxsMemory.h"
namespace OFX {
void throwSuiteStatusException(OfxStatus stat) throw(OFX::Exception::Suite, std::bad_alloc)
{
switch (stat)
{
case kOfxStatOK :
case kOfxStatReplyYes :
case kOfxStatReplyNo :
case kOfxStatReplyDefault :
break;
case kOfxStatErrMemory :
throw std::bad_alloc();
default :
# ifdef DEBUG
std::cout << "Threw suite exception!" << std::endl;
# if defined(__APPLE__) || defined(linux)
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
std::cout << strs[i] << std::endl;
}
free(strs);
# endif
# endif
throw OFX::Exception::Suite(stat);
}
}
void throwHostMissingSuiteException(std::string name) throw(OFX::Exception::Suite)
{
# ifdef DEBUG
std::cout << "Threw suite exception! Host missing '" << name << "' suite." << std::endl;
# if defined(__APPLE__) || defined(linux)
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
std::cout << strs[i] << std::endl;
}
free(strs);
# endif
# endif
throw OFX::Exception::Suite(kOfxStatErrUnsupported);
}
const char* mapStatusToString(OfxStatus stat)
{
switch(stat)
{
case kOfxStatOK : return "kOfxStatOK";
case kOfxStatFailed : return "kOfxStatFailed";
case kOfxStatErrFatal : return "kOfxStatErrFatal";
case kOfxStatErrUnknown : return "kOfxStatErrUnknown";
case kOfxStatErrMissingHostFeature : return "kOfxStatErrMissingHostFeature";
case kOfxStatErrUnsupported : return "kOfxStatErrUnsupported";
case kOfxStatErrExists : return "kOfxStatErrExists";
case kOfxStatErrFormat : return "kOfxStatErrFormat";
case kOfxStatErrMemory : return "kOfxStatErrMemory";
case kOfxStatErrBadHandle : return "kOfxStatErrBadHandle";
case kOfxStatErrBadIndex : return "kOfxStatErrBadIndex";
case kOfxStatErrValue : return "kOfxStatErrValue";
case kOfxStatReplyYes : return "kOfxStatReplyYes";
case kOfxStatReplyNo : return "kOfxStatReplyNo";
case kOfxStatReplyDefault : return "kOfxStatReplyDefault";
case kOfxStatErrImageFormat : return "kOfxStatErrImageFormat";
}
return "UNKNOWN STATUS CODE";
}
namespace Memory {
void *allocate(size_t nBytes, ImageEffect *effect) throw(std::bad_alloc)
{
void *data = 0;
OfxStatus stat = OFX::Private::gMemorySuite->memoryAlloc((void *)(effect ? effect->getHandle() : 0), nBytes, &data);
if(stat != kOfxStatOK)
throw std::bad_alloc();
return data;
}
void free(void *ptr) throw()
{
if(ptr)
OFX::Private::gMemorySuite->memoryFree(ptr);
}
};
};