/* * CoCoFacade.cpp * JNADemo * * Created by Eric Sean Conner on 6/30/09. * Copyright 2009 ZTT, FH Worms. All rights reserved. * */ #include #include #include #include "CoCoFacade.h" #include "TPCCommandCoderDB.h" using namespace std; TPCCommandCoderDB coCoInstance; const char* getCoCoInfo() { return coCoInstance.getCoCoInfo().c_str(); } uint32_t getVersion() { return 200; } int32_t createDataBlock(char *target, int tag) { return coCoInstance.createDataBlock(target, tag); } uint32_t* getDataBlock() { return coCoInstance.getDataBlock(); } uint32_t sizeOfLong() { return sizeof(long); } uint32_t errorCount() { return coCoInstance.getError().size(); } int32_t getWatchDogTimeOut() { return coCoInstance.getWatchDogTimeOut(); } string lastError; const char* getError(unsigned int errorId) { // coCoInstance.getError().size() is no problem, // because the method coCoInstance.getError() returns // a Vector and when it is empty the call // coCoInstance.getError().size() returns 0. // The return value from coCoInstance.getError() can't be 0 (null) // because the compiler doesn't allow that. if (errorId < coCoInstance.getError().size()) { lastError = coCoInstance.getError()[errorId]; return lastError.c_str(); } else { // returning of literals is no problem see // http://bytes.com/topic/c/answers/515640-returning-string-literals-function: // "You can see that you're simply returning the address of a global object -- // so no memory is leaked, and no object is accessed after having being // destroyed." return ""; } }