FREObject checkWord(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { const uint8_t *locale = 0; const uint8_t *inpWord = 0; uint32_t len = -1; FREObject retObj=0; int rv=0; U16Char_t* inpWordU16 = NULL; std::string inpWordDictEncoded; bool isConversionUnSuccesful=false; //get first argument if(FREGetObjectAsUTF8(argv[1], &len, &locale) != FRE_OK) return retObj; len = 0; //get second argument if(FREGetObjectAsUTF8(argv[0], &len, &inpWord) != FRE_OK) return retObj; //get the hunspell object from cache Hunspell * hunspellObject=getHunspellObject(std::string((char *)locale)); if(!hunspellObject) return retObj; //convert input utf8 to u16 string inpWordU16 = EncConv::convCharStrToU16Str((char *)inpWord, "UTF-8"); //get dictionary encoding HUNSPELL_GET_ENCODING getEncAdd=(HUNSPELL_GET_ENCODING) GetProcAddress(hinstLib, "hunspell_get_dic_encoding"); char * m_MainEncoding= (getEncAdd)(hunspellObject); //convert u16 to dictionary encoding inpWordDictEncoded=EncConv::convU16StrToCharStr(inpWordU16,m_MainEncoding); if(inpWordDictEncoded.length()==0) { isConversionUnSuccesful = true; } //Get spellAddress HUNSPELL_SPELL spellAdd= (HUNSPELL_SPELL) GetProcAddress(hinstLib, "hunspell_spell"); //Do spell check with converted word else try with UTF-8 if((!isConversionUnSuccesful) ) { rv= (spellAdd)(hunspellObject, (char * )inpWordDictEncoded.c_str()); } else { rv= (spellAdd)(hunspellObject, (char * )inpWord); } //return results FRENewObjectFromInt32(rv, &retObj); EncConv::releaseU16Str(inpWordU16); return retObj; }
FREObject LeapNative_setConfigString(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { leapnative::LNLeapDevice* device; FREGetContextNativeData(ctx, (void **) &device); uint32_t len; const uint8_t* key = 0; FREGetObjectAsUTF8(argv[0], &len, &key); uint32_t valueLen; const uint8_t* valueArray = 0; FREGetObjectAsUTF8(argv[1], &valueLen, &valueArray); return device->setConfigString(len, key, valueLen, valueArray); }
FREObject saveToCameraRoll(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { uint32_t name_size = 0; const uint8_t* name_val = NULL; FREGetObjectAsUTF8(argv[0], &name_size, &name_val); FREObject objectBA = argv[1]; FREByteArray baData; FREAcquireByteArray(objectBA, &baData); uint8_t *ba = baData.bytes; int32_t _size; FREGetObjectAsInt32(argv[2], &_size); int32_t _orientation; FREGetObjectAsInt32(argv[3], &_orientation); int32_t res = captureSaveToCameraRoll( (const char *)name_val, (const uint8_t*)ba, _size, _orientation); FREReleaseByteArray(objectBA); FREObject res_obj; FRENewObjectFromInt32(res, &res_obj); return res_obj; }
std::string getStringFromFREObject(FREObject arg) { uint32_t string1Length; const uint8_t *val; FREGetObjectAsUTF8(arg, &string1Length, &val); std::string s(val, val + string1Length); return s; }
bool FREGetString(FREObject object, std::string& str) { uint32_t len; const uint8_t* data; FREResult res = FREGetObjectAsUTF8(object, &len, &data); if(res != FRE_OK) return false; str = std::string((const char*)data, len); return true; }
FREObject LeapNative_getConfigType(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { leapnative::LNLeapDevice* device; FREGetContextNativeData(ctx, (void **) &device); uint32_t len; const uint8_t* key = 0; FREGetObjectAsUTF8(argv[0], &len, &key); return device->getConfigType(len, key); }
FREObject LeapNative_setConfigFloat(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { leapnative::LNLeapDevice* device; FREGetContextNativeData(ctx, (void **) &device); uint32_t len; const uint8_t* key = 0; FREGetObjectAsUTF8(argv[0], &len, &key); double value; FREGetObjectAsDouble(argv[1], &value); return device->setConfigFloat(len, key, (float)value); }
FREObject talkBack(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { const uint8_t *locale = 0; const uint8_t *inpWord = 0; uint32_t len = 0; FREObject retObj=0; //get first argument if(FREGetObjectAsUTF8(argv[0], &len, &inpWord) != FRE_OK) return retObj; FRENewObjectFromUTF8((uint32_t)(strlen((char *)inpWord)),(const uint8_t*)(inpWord), &retObj); return retObj; }
FREObject sendString(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { FREObject result; uint32_t lengthToSend; const uint8_t *dataToSend; int sendResult = 0; FREGetObjectAsUTF8(argv[0], &lengthToSend, &dataToSend); sendResult = SendBuf(comPort, (unsigned char *)dataToSend, lengthToSend); if (sendResult == -1) { FRENewObjectFromBool(0, &result); } else { FRENewObjectFromBool(1, &result); } return result; }
FREObject initHunspellObject(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]){ const uint8_t *locale = 0; const uint8_t *dictionaryPath = 0; uint32_t len = -1; FREObject retObj=0; Hunspell * hunspellObject; BOOL fRunTimeLinkSuccess = FALSE; //get first argument if(FREGetObjectAsUTF8(argv[1], &len, &dictionaryPath) != FRE_OK) return retObj; len = 0; //get second argument if(FREGetObjectAsUTF8(argv[0], &len, &locale) != FRE_OK) return retObj; //check in cache and return if already present if(!(Hunspell_cache.find(std::string((char *)locale))==Hunspell_cache.end())) { FRENewObjectFromInt32(HUNSPELL_INIT_SUCCESS, &retObj); return retObj; } U16Char_t * dic_path_U16= EncConv::convCharStrToU16Str((char *)dictionaryPath, "UTF-8"); U16Char_t *locale_U16= EncConv::convCharStrToU16Str((char *)locale, "UTF-8"); std::wstring aff_file= std::wstring((wchar_t *)dic_path_U16)+std::wstring(L"\\Dictionaries\\")+std::wstring((wchar_t *)locale_U16)+std::wstring(L"\\")+std::wstring((wchar_t *)locale_U16)+std::wstring(L".aff"); std::wstring dic_file= std::wstring((wchar_t *)dic_path_U16)+std::wstring(L"\\Dictionaries\\")+std::wstring((wchar_t *)locale_U16)+std::wstring(L"\\")+std::wstring((wchar_t *)locale_U16)+std::wstring(L".dic"); std::wstring lib_file= std::wstring((wchar_t *)dic_path_U16)+std::wstring(L"\\libhunspell.dll"); EncConv::releaseU16Str(dic_path_U16); EncConv::releaseU16Str(locale_U16); //creating OS specific aff,dic file paths refer: DanishOS Issue of CS6 AHP std::string aff_file_U8= makeString(aff_file.c_str()); std::string dic_file_U8= makeString(dic_file.c_str()); //make the file url's std::string lib_file_U8= std::string((char *)dictionaryPath)+std::string("\\libhunspell.dll"); //check for file is present if( (FileExists(aff_file) && FileExists(dic_file) && FileExists(lib_file)) == false ) { FRENewObjectFromInt32(RESOURCE_FILES_MISSING, &retObj); return retObj; } LPCTSTR lib_file_lpstring= (wchar_t *)lib_file.c_str(); //make a new hunspell object hinstLib = LoadLibrary(lib_file_lpstring); if (hinstLib != NULL) { HUNSPELL_INIT initAdd = (HUNSPELL_INIT) GetProcAddress(hinstLib, "hunspell_initialize"); // If the function address is valid, call the function. if (NULL != initAdd) { fRunTimeLinkSuccess = TRUE; hunspellObject = (initAdd) ((char *)aff_file_U8.c_str(), (char *)dic_file_U8.c_str()); } } //add to hunspell cache if(Hunspell_cache.find(std::string((char *)locale))==Hunspell_cache.end()) Hunspell_cache[std::string((char *)locale)]= hunspellObject; if(hunspellObject) { FRENewObjectFromInt32(HUNSPELL_INIT_SUCCESS, &retObj); } else { FRENewObjectFromInt32(HUNSPELL_INIT_FAIL, &retObj); } return retObj; }
FREObject getSuggestions(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { const uint8_t *locale = 0; const uint8_t *inpWord = 0; uint32_t len = -1; FREObject retObj=0; FREObject oneSuggestion=0; U16Char_t* inpWordU16 = NULL; std::string inpWordDictEncoded; bool isConversionUnSuccesful=false; char * oneSuggestionEncoded=NULL; U16Char_t * oneSuggestionU16=NULL; std::string oneSuggestionU8; //assign memory to retobj FRENewObject((const uint8_t*)"Array", 0, NULL, &retObj, 0); //get first argument if(FREGetObjectAsUTF8(argv[1], &len, &locale) != FRE_OK) return retObj; len = 0; //get second argument if(FREGetObjectAsUTF8(argv[0], &len, &inpWord) != FRE_OK) return retObj; //get the hunspell object from cache Hunspell * hunspellObject=getHunspellObject(std::string((char *)locale)); if(!hunspellObject) return retObj; //convert input utf8 to u16 string inpWordU16 = EncConv::convCharStrToU16Str((char *)inpWord, "UTF-8"); //get dictionary encoding HUNSPELL_GET_ENCODING getEncAdd=(HUNSPELL_GET_ENCODING) GetProcAddress(hinstLib, "hunspell_get_dic_encoding"); char * m_MainEncoding= (getEncAdd)(hunspellObject); //convert u16 to dictionary encoding inpWordDictEncoded=EncConv::convU16StrToCharStr(inpWordU16,m_MainEncoding); if(inpWordDictEncoded.length()==0) { isConversionUnSuccesful = true; } //get suggestAddress &freelistAddress HUNSPELL_SUGGEST suggestAdd= (HUNSPELL_SUGGEST) GetProcAddress(hinstLib, "hunspell_suggest"); HUNSPELL_FREE_LIST freeListAdd= (HUNSPELL_FREE_LIST) GetProcAddress(hinstLib, "hunspell_free_list"); char** suggList = NULL; int numSugg = 0; //Try getting suggestions with encoded word else try with UTF8 if(suggestAdd && !isConversionUnSuccesful) { numSugg = (suggestAdd)(hunspellObject,(char *) (inpWordDictEncoded.c_str()),&suggList); } else { numSugg = (suggestAdd)(hunspellObject,(char *) (inpWord),&suggList); } if(numSugg) { FRESetArrayLength( retObj, numSugg ); for(int iCount=0; iCount <numSugg; iCount++) { oneSuggestionEncoded=suggList[iCount]; oneSuggestionU16=EncConv::convCharStrToU16Str(oneSuggestionEncoded, m_MainEncoding); oneSuggestionU8= EncConv::convU16StrToCharStr(oneSuggestionU16, "UTF-8"); FRENewObjectFromUTF8((uint32_t)(oneSuggestionU8.length()),(const uint8_t*)(oneSuggestionU8.c_str()), &oneSuggestion); FRESetArrayElementAt(retObj, iCount, oneSuggestion); EncConv::releaseU16Str(oneSuggestionU16); } (freeListAdd)(hunspellObject, &suggList,numSugg); } EncConv::releaseU16Str(inpWordU16); return retObj; }
FREObject getCapture(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { int32_t w, h; int32_t frameRate = 0; uint32_t name_size = 0; const uint8_t* name_val = NULL; FREGetObjectAsUTF8(argv[0], &name_size, &name_val); FREGetObjectAsInt32(argv[1], &w); FREGetObjectAsInt32(argv[2], &h); FREGetObjectAsInt32(argv[3], &frameRate); FREObject objectBA = argv[4]; FREByteArray baData; FREAcquireByteArray(objectBA, &baData); uint8_t *ba = baData.bytes; int32_t emptySlot = -1; size_t i; // search empty slot for(i = 0; i < MAX_ACTIVE_CAMS; i++) { if(!active_cams[i]) { emptySlot = i; break; } } if(emptySlot == -1) { ba += ba_write_int(ba, -1); FREReleaseByteArray(objectBA); return NULL; } CCapture* cap = NULL; cap = createCameraCapture(w, h, (char *)name_val, frameRate ); if(!cap) { ba += ba_write_int(ba, -1); FREReleaseByteArray(objectBA); return NULL; } // start if not running if( captureIsCapturing(cap) == 0 ) { captureStart(cap); } active_cams[emptySlot] = cap; active_cams_count++; captureGetSize( cap, &w, &h ); // write result ba += ba_write_int(ba, emptySlot); ba += ba_write_int(ba, w); ba += ba_write_int(ba, h); FREReleaseByteArray(objectBA); return NULL; }
FREObject getScores(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[]) { SC_ScoreList_h score_list; SC_Score_h aScore; FREObject returnObject; int i,j; unsigned int contextArrayLength = 0; FREGetArrayLength(argv[0],&contextArrayLength); score_list = SC_ScoresController_GetScores(scores_controller); // arrayArgs has the Array arguments. #if defined(BB10) unsigned int scoreListSize = SC_ScoreList_GetCount(score_list); #else unsigned int scoreListSize = SC_ScoreList_GetScoresCount(score_list); #endif FREObject* arrayArgs = (FREObject*)malloc(sizeof(FREObject)*scoreListSize); for(i = 0 ; i < scoreListSize ; i++) { #if defined(BB10) aScore = SC_ScoreList_GetAt(score_list,i); #else aScore = SC_ScoreList_GetScore(score_list,i); #endif FREObject* argV=(FREObject*)malloc(sizeof(FREObject)*6); FRENewObjectFromInt32(SC_Score_GetMode(aScore), &argV[0]); FRENewObjectFromInt32(SC_Score_GetLevel(aScore), &argV[1]); FRENewObjectFromDouble(SC_Score_GetResult(aScore), &argV[2]); FRENewObjectFromDouble(SC_Score_GetMinorResult(aScore), &argV[3]); // Create the 5th argument(User) SC_User_h aUser = SC_Score_GetUser(aScore); SC_String_h scLogin = SC_User_GetLogin(aUser); SC_String_h scEmail = SC_User_GetEmail(aUser); const char * login = ""; const char * email = ""; if(scLogin != NULL) login= SC_String_GetData(scLogin); if(scEmail != NULL) email = SC_String_GetData(scEmail); FREObject* userArgV=(FREObject*)malloc(sizeof(FREObject)*2); FRENewObjectFromUTF8(strlen(login)+1,(const uint8_t*)login, &userArgV[0]); FRENewObjectFromUTF8(strlen(email)+1,(const uint8_t*)email, &userArgV[1]); fprintf(stderr, "username: %s\n", login); FRENewObject((const uint8_t*)"com.wallwizz.scoreloop.User",2,userArgV,&argV[4],NULL); // Create the 6th argument(Context) FREObject* contextArray = (FREObject*)malloc(sizeof(FREObject)*contextArrayLength); for(j = 0; j < contextArrayLength; j++) { FREObject context; FREObject freContextKey; const char * aKey = "test"; SC_String_h scValue = NULL; const char* aValue = NULL; unsigned int length; FREGetArrayElementAt(argv[0], j, &freContextKey); if(FREGetObjectAsUTF8(freContextKey,&length,(const uint8_t**)&aKey) != FRE_OK) fprintf(stderr, "FREGetArrayElementAt Error\n"); fprintf(stderr, "retrieved aKey: %s\n", aKey); SC_Context_h aContext = SC_Score_GetContext(aScore); SC_Context_Get(aContext, aKey, &scValue); if(scValue != NULL) { aValue= SC_String_GetData(scValue); }else{ fprintf(stderr, "scValue NULL\n"); aValue = "not found"; } fprintf(stderr, "retrieved aValue: %s\n", aValue); FREObject* contextArgv=(FREObject*)malloc(sizeof(FREObject)*2); FRENewObjectFromUTF8(strlen(aKey)+1,(const uint8_t*)aKey, &contextArgv[0]); FRENewObjectFromUTF8(strlen(aValue)+1,(const uint8_t*)aValue, &contextArgv[1]); FRENewObject((const uint8_t*)"com.wallwizz.scoreloop.Context",2,contextArgv,&contextArray[j],NULL); free(contextArgv); } FRENewObject((const uint8_t*)"Array",contextArrayLength,contextArray,&argV[5],NULL); FRENewObject((const uint8_t*)"com.wallwizz.scoreloop.Score",6,argV,&arrayArgs[i],NULL); free(contextArray); } FRENewObject((const uint8_t*)"Array",scoreListSize,arrayArgs,&returnObject,NULL); free(arrayArgs); return returnObject; }