예제 #1
0
FREObject messageToFre(midiMessage m)
{
	FREObject fStatus;
	FRENewObjectFromInt32((int)m.status,&fStatus);
	FREObject fD1;
	FRENewObjectFromInt32((int)m.data1,&fD1);
	FREObject fD2;
	FRENewObjectFromInt32((int)m.data2,&fD2);
	FREObject fStamp;
	FRENewObjectFromDouble(m.stamp,&fStamp);
	FREObject fDevice;
	FRENewObjectFromInt32((int)m.device,&fDevice);

	FREObject args[5];
	args[0] = fStatus;
	args[1] = fD1;
	args[2] = fD2;
	args[3] = fStamp;
	args[4] = fDevice;

	FREObject fm = NULL;
	FREResult fre = FRENewObject((const uint8_t *)"benkuper.nativeExtensions.MIDIMessage",5,args,&fm,NULL);
			
	//printf("Message to fre FREResult %i\n",fre);

	return fm;
}
예제 #2
0
 FREObject LNLeapDevice::getClosestScreenHit(int pointableId) {
     ScreenList screenList = controller->calibratedScreens();
     Frame frame = controller->frame();
     PointableList pointables = frame.pointables();
     Pointable pointable;
     
     // TODO: Create a fake pointable width tipPosition and direction instead of looping
     bool didFind = false;
     for (int i = 0; i < pointables.count(); i++) {
         if (pointables[i].id() == pointableId) {
             pointable = pointables[i];
             didFind = true;
             break;
         }
     }
     
     FREObject freScreenId;
     
     if(didFind) {
         Screen screen = screenList.closestScreenHit(pointable);
         FRENewObjectFromInt32(screen.id(), &freScreenId);
     } else {
         FRENewObjectFromInt32(0, &freScreenId);
     }
     return freScreenId;
 }
예제 #3
0
	FREObject getCameraFrameSize(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		int w = gGrabber.getWidth();
		int h = gGrabber.getHeight();

		FREObject fX,fY;

		FRENewObjectFromInt32(w,&fX);
		FRENewObjectFromInt32(h,&fY);

		FREObject value = argv[0];

		FRESetObjectProperty(value,(const uint8_t*)"w",fX,NULL);                
		FRESetObjectProperty(value,(const uint8_t*)"h",fY,NULL);
		return NULL;
	}
예제 #4
0
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;
}
예제 #5
0
	FREObject FlyCapture2_getNumCameras(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]){
		FREObject retObj;
		
		int numCams = fc2Manager.getNumCameras();
		FRENewObjectFromInt32(numCams, &retObj);
		return retObj;
	}
예제 #6
0
	FREObject openInputDevice(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		
		int index = 0;
		FREGetObjectAsInt32(argv[0],&index);

		//printf("Native MIDI :: open input device %i\n",index);
		
		int pointer = -1;
		try {
			RtMidiIn* in = new RtMidiIn();
			in->openPort(index);
			openMidiIn.push_back(in);

			pointer = (int)in;
			printf("Open midi pointer : %i (%s), num open devices :  %i\n",pointer,in->getPortName(index).c_str(),openMidiIn.size());
			// Don't ignore sysex, timing, or active sensing messages.
			midiin->ignoreTypes( false, false, false );

		}
		catch ( RtMidiError &error ) {
			error.printMessage();
		}		
		
		FREObject result;
		FRENewObjectFromInt32(pointer,&result);
		return result;
	}
예제 #7
0
	FREObject openOutputDevice(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		int index = 0;
		FREGetObjectAsInt32(argv[0],&index);

		//printf("Native MIDI :: open output device %i\n",index);

		int pointer = -1;
		
		try {
			RtMidiOut* out = new RtMidiOut();
			out->openPort(index);
			openMidiOut.push_back(out);

			pointer = (int)out;
			//printf("Open midi pointer : %i\n",pointer);
			// Don't ignore sysex, timing, or active sensing messages.

		}
		catch ( RtMidiError &error ) {
			error.printMessage();
		}	

		FREObject result;
		FRENewObjectFromInt32(pointer,&result);
		return result;
	}
FREObject getRange(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
    FREObject returnObject;
    FREObject* argV=(FREObject*)malloc(sizeof(FREObject)*2);
#if defined(BB10)
	SC_Range_t aRange = SC_ScoresController_GetRange(scores_controller);
    FRENewObjectFromInt32(SC_Score_GetMode(aRange.offset), &argV[0]);
    FRENewObjectFromInt32(SC_Score_GetLevel(aRange.length), &argV[1]);
#else
    argV[0] = SC_ScoresController_GetRangeOffset(scores_controller);
    argV[1] = SC_ScoresController_GetRangeLength(scores_controller);
#endif

    FRENewObject("com.wallwizz.scoreloop.Range",2,argV,&returnObject,NULL);
    return returnObject;
}
FREObject getMode(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{

    FREObject returnObject;
    FRENewObjectFromInt32(SC_ScoresController_GetMode(scores_controller), &returnObject);
    return returnObject;
}
예제 #10
0
/**
 * Called by ActionScript after it receives an event when a contact has been updated.
 * This method returns an array of the properties that have been updated for each contact.
 */
FREObject getUpdatedContactProperties(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
	pthread_mutex_lock(&amutex);
	FREObject result = NULL;
	FRENewObject((const uint8_t*) "Array", 0, NULL, &result, NULL);

	trace( "getUpdatedContactProperties" );

	int i = 0;

	for( i = 0; i<update_size; i++ )
	{
		ContactUpdate contactUpdate = contact_updates[ i ];

		FREObject update;
		FRENewObject((const uint8_t*) "Object", 0, NULL, &update, NULL);

		if( contactUpdate.value != NULL )
		{
			FREObject value;
			FRENewObjectFromUTF8( (uint32_t)(strlen(contactUpdate.value) + 1), (const uint8_t*)contactUpdate.value, &value );
			FRESetObjectProperty( update, (const uint8_t*) "value", value, NULL );
		}

		FREObject ppid;
		FRENewObjectFromUTF8( (uint32_t)(strlen(contactUpdate.ppid) + 1), (const uint8_t*)contactUpdate.ppid, &ppid );
		FRESetObjectProperty( update, (const uint8_t*) "ppid", ppid, NULL );

		FREObject property;
		FRENewObjectFromInt32( (int32_t)contactUpdate.property, &property );
		FRESetObjectProperty( update, (const uint8_t*) "property", property, NULL );

		FREObject status;
		FRENewObjectFromInt32( (int32_t)contactUpdate.status, &status );
		FRESetObjectProperty( update, (const uint8_t*) "status", status, NULL );

		FRESetArrayElementAt( result, i, update );

		free( contactUpdate.value );
		free( contactUpdate.ppid );

	}

	update_size = 0;
	pthread_mutex_unlock(&amutex);
	return result;
}
예제 #11
0
    FREObject LNLeapDevice::getConfigInt32(uint32_t len, const uint8_t* key) {
        std::string keyString( key, key+len );
        
        FREObject freReturnValue;
        FRENewObjectFromInt32(controller->config().getInt32(keyString), &freReturnValue);

        return freReturnValue;
    }
예제 #12
0
//缓存区数据量_wh
FREObject getAvailableBytes(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
	FREObject result;
	pthread_mutex_lock(&safety);//开启线程互斥锁_wh
	FRENewObjectFromInt32(bufferSize, &result);//赋予result为as实例_wh
	pthread_mutex_unlock(&safety);//关闭线程互斥锁_wh
	return result;
}
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;
}
예제 #14
0
 FREObject LNLeapDevice::getScreenWidthPixels(int screenId) {
     ScreenList screenList = controller->calibratedScreens();
     Screen screen = screenList[screenId];
     
     FREObject freReturnValue;
     FRENewObjectFromInt32((int32_t) screen.widthPixels(), &freReturnValue);
     
     return freReturnValue;
 }
예제 #15
0
FREObject supportsSaveToCameraRoll(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    FREObject res_obj;

    int32_t res = captureSupportsSaveToCameraRoll();
    FRENewObjectFromInt32(res, &res_obj);
    
    return res_obj;
}
예제 #16
0
FREObject getMouseInfo(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
	FREObject result = argv[0];

	POINT mouse;

	GetCursorPos(&mouse);

	int32_t x = (int32_t) mouse.x;
	int32_t y = (int32_t) mouse.y;

	FREObject mouseX;
	FREObject mouseY;

	FRENewObjectFromInt32(x, &mouseX);
	FRENewObjectFromInt32(y, &mouseY);

	FRESetObjectProperty(result, (const uint8_t*) "mouseX", mouseX, NULL);
	FRESetObjectProperty(result, (const uint8_t*) "mouseY", mouseY, NULL);

	return NULL;
}
FREObject __cdecl AmbireCaptureGetScreenSize(FREContext ctx, void * functionData, uint32_t argc, FREObject argv[]) {
	POINT pt = { 0 };
	HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
	MONITORINFO mi = { 0 };
	mi.cbSize = sizeof(mi);
	GetMonitorInfo(hMonitor, &mi);
	int W = mi.rcMonitor.right - mi.rcMonitor.left;
	int H = mi.rcMonitor.bottom - mi.rcMonitor.top;
	int N = W | (H << 16);
	FREObject rv = 0;
	FRENewObjectFromInt32(N, &rv);
	return rv;
}
예제 #18
0
	FREObject getMouseXY(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		POINT cursorPos;
		GetCursorPos(&cursorPos);

		FREObject value = argv[0];

		int x = (int) cursorPos.x;
		int y = (int) cursorPos.y;


		FREObject fX,fY;


		FRENewObjectFromInt32(x,&fX);
		FRENewObjectFromInt32(y,&fY);

		FRESetObjectProperty(value,(const uint8_t*)"x",fX,NULL);                
		FRESetObjectProperty(value,(const uint8_t*)"y",fY,NULL);        

		return NULL;
	}
예제 #19
0
FREObject getFlashMode(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    int32_t id;
    FREGetObjectAsInt32(argv[0], &id);
    
    CCapture *cap;
    cap = active_cams[id];
    
    if (cap)
    {
        int32_t mode = (int32_t)captureGetFlashMode(cap);
        FREObject ret;
        FRENewObjectFromInt32(mode, &ret);
        return ret;
    }
    return NULL;
}
예제 #20
0
FREObject getBytesAsByteArray(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
	FREObject result;
	FREByteArray incomingBytes;

	FREAcquireByteArray(argv[0], &incomingBytes);

	pthread_mutex_lock(&safety);
	memcpy(incomingBytes.bytes, buffer, bufferSize);
	FRENewObjectFromInt32(bufferSize, &result);
	bufferSize = 0;
	sentEvent = 0;
	pthread_mutex_unlock(&safety);

	FREReleaseByteArray(&incomingBytes);

	return result;
}
예제 #21
0
 FREObject LNLeapDevice::getConfigType(uint32_t len, const uint8_t* key) {
     std::string keyString( key, key+len );
     
     int type;
     
     switch (controller->config().type(keyString)) {
         case Config::TYPE_UNKNOWN:
         {
             type = 0;
             break;
         }
         case Config::TYPE_BOOLEAN:
         {
             type = 1;
             break;
         }
         case Config::TYPE_INT32:
         {
             type = 2;
             break;
         }
         case Config::TYPE_FLOAT:
         {
             type = 6;
             break;
         }
         case Config::TYPE_STRING:
         {
             type = 8;
             break;
         }
         default:
         {
             type = 0;
             break;
         }
     }
     
     FREObject freReturnValue;
     FRENewObjectFromInt32(type, &freReturnValue);
     
     return freReturnValue;
 }
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;
}
예제 #23
0
    FREObject LNLeapDevice::getFrame() {
        
        Frame frame = controller->frame();
        
        // TODO: Only continue with valid Frame?
        
        FREObject freCurrentFrame;
        FRENewObject( (const uint8_t*) "com.leapmotion.leap.Frame", 0, NULL, &freCurrentFrame, NULL);
        
        FREObject freFrameId;
        FRENewObjectFromInt32((int32_t) frame.id(), &freFrameId);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "id", freFrameId, NULL);
        
        const Vector frameTranslation = frame.translation(lastFrame);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "translationVector", createVector3(frameTranslation.x, frameTranslation.y, frameTranslation.z), NULL);
        
        const Matrix frameRotation = frame.rotationMatrix(lastFrame);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "rotation", createMatrix(
                     createVector3(frameRotation.xBasis[0], frameRotation.xBasis[1], frameRotation.xBasis[2]),
                     createVector3(frameRotation.yBasis[0], frameRotation.yBasis[1], frameRotation.yBasis[2]),
                     createVector3(frameRotation.zBasis[0], frameRotation.zBasis[1], frameRotation.zBasis[2]),
                     createVector3(frameRotation.origin[0], frameRotation.origin[1], frameRotation.origin[2])
        ), NULL);
        
        FREObject freFrameScaleFactor;
        FRENewObjectFromDouble(frame.scaleFactor(lastFrame), &freFrameScaleFactor);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "scaleFactorNumber", freFrameScaleFactor, NULL);
        
        FREObject freTimestamp;
        FRENewObjectFromInt32((int32_t) frame.timestamp(), &freTimestamp);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "timestamp", freTimestamp, NULL);
        
        std::map<int, FREObject> freHandsMap;
        if (!frame.hands().empty()) {
            
            FREObject freHands;
            FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "hands", &freHands, NULL);
            
            for(int i = 0; i < frame.hands().count(); i++) {
                const Hand hand = frame.hands()[i];
                
                FREObject freHand;
                FRENewObject( (const uint8_t*) "com.leapmotion.leap.Hand", 0, NULL, &freHand, NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "frame", freCurrentFrame, NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "direction", createVector3(hand.direction()[0], hand.direction()[1], hand.direction()[2]), NULL);
                
                FREObject freHandId;
                FRENewObjectFromInt32(hand.id(), &freHandId);
                FRESetObjectProperty(freHand, (const uint8_t*) "id", freHandId, NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "palmNormal", createVector3(hand.palmNormal()[0], hand.palmNormal()[1], hand.palmNormal()[2]), NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "palmPosition", createVector3(hand.palmPosition()[0], hand.palmPosition()[1], hand.palmPosition()[2]), NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "palmVelocity", createVector3(hand.palmVelocity()[0], hand.palmVelocity()[1], hand.palmVelocity()[2]), NULL);
                
                const Matrix rotation = hand.rotationMatrix(lastFrame);
                FRESetObjectProperty(freHand, (const uint8_t*) "rotation", createMatrix(
                                     createVector3(rotation.xBasis[0], rotation.xBasis[1], rotation.xBasis[2]),
                                     createVector3(rotation.yBasis[0], rotation.yBasis[1], rotation.yBasis[2]),
                                     createVector3(rotation.zBasis[0], rotation.zBasis[1], rotation.zBasis[2]),
                                     createVector3(rotation.origin[0], rotation.origin[1], rotation.origin[2])
                ), NULL);
                
                FREObject freScaleFactor;
                FRENewObjectFromDouble(hand.scaleFactor(lastFrame), &freScaleFactor);
                FRESetObjectProperty(freHand, (const uint8_t*) "scaleFactorNumber", freScaleFactor, NULL);
                
                FRESetObjectProperty(freHand, (const uint8_t*) "sphereCenter", createVector3(hand.sphereCenter()[0], hand.sphereCenter()[1], hand.sphereCenter()[2]), NULL);
                
                FREObject freSphereRadius;
                FRENewObjectFromDouble(hand.sphereRadius(), &freSphereRadius);
                FRESetObjectProperty(freHand, (const uint8_t*) "sphereRadius", freSphereRadius, NULL);
                
                const Vector translation = hand.translation(lastFrame);
                FRESetObjectProperty(freHand, (const uint8_t*) "translationVector", createVector3(translation.x, translation.y, translation.z), NULL);
                
                FRESetArrayElementAt(freHands, i, freHand);
                
                freHandsMap[hand.id()] = freHand;
            }
        }
        
        std::map<int, FREObject> frePointablesMap;
        if(!frame.pointables().empty()) {
            
            FREObject frePointables;
            FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "pointables", &frePointables, NULL);
            
            for(int i = 0; i < frame.pointables().count(); i++) {
                const Pointable pointable = frame.pointables()[i];
                
                FREObject frePointable;
                if(pointable.isTool()) {
                    FRENewObject( (const uint8_t*) "com.leapmotion.leap.Tool", 0, NULL, &frePointable, NULL);
                } else {
                    FRENewObject( (const uint8_t*) "com.leapmotion.leap.Finger", 0, NULL, &frePointable, NULL);
                }
                
                FRESetObjectProperty(frePointable, (const uint8_t*) "frame", freCurrentFrame, NULL);
                
                FREObject frePointableId;
                FRENewObjectFromInt32(pointable.id(), &frePointableId);
                FRESetObjectProperty(frePointable, (const uint8_t*) "id", frePointableId, NULL);
                
                FREObject frePointableLength;
                FRENewObjectFromDouble(pointable.length(), &frePointableLength);
                FRESetObjectProperty(frePointable, (const uint8_t*) "length", frePointableLength, NULL);

                FREObject frePointableWidth;
                FRENewObjectFromDouble(pointable.width(), &frePointableWidth);
                FRESetObjectProperty(frePointable, (const uint8_t*) "width", frePointableWidth, NULL);

                FRESetObjectProperty(frePointable, (const uint8_t*) "direction", createVector3(pointable.direction().x, pointable.direction().y, pointable.direction().z), NULL);
                FRESetObjectProperty(frePointable, (const uint8_t*) "tipPosition", createVector3(pointable.tipPosition().x, pointable.tipPosition().y, pointable.tipPosition().z), NULL);
                FRESetObjectProperty(frePointable, (const uint8_t*) "tipVelocity", createVector3(pointable.tipVelocity().x, pointable.tipVelocity().y, pointable.tipVelocity().z), NULL);
                
                //map to hand & back
                if(pointable.hand().isValid()) {
                    FREObject freHand = freHandsMap[pointable.hand().id()];
                    FRESetObjectProperty(frePointable, (const uint8_t*) "hand", freHand, NULL);
                    
                    FREObject frePointables;
                    FREGetObjectProperty(freHand, (const uint8_t*) "pointables", &frePointables, NULL);
                    
                    uint32_t numPointables;
                    FREGetArrayLength(frePointables, &numPointables);
                    FRESetArrayElementAt(frePointables, numPointables, frePointable);
                    
                    FREObject freSpecificHandPointables;
                    if(pointable.isTool()) {
                        FREGetObjectProperty(freHand, (const uint8_t*) "tools", &freSpecificHandPointables, NULL);
                    } else {
                        FREGetObjectProperty(freHand, (const uint8_t*) "fingers", &freSpecificHandPointables, NULL);
                    }
                    uint32_t numSpecificHandTools;
                    FREGetArrayLength(freSpecificHandPointables, &numSpecificHandTools);
                    FRESetArrayElementAt(freSpecificHandPointables, numSpecificHandTools, frePointable);
                }
                
                //push it in current frame
                FRESetArrayElementAt(frePointables, i, frePointable);
                
                //specific
                FREObject freSpecificPointables;
                if(pointable.isTool()) {
                    FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "tools", &freSpecificPointables, NULL);
                } else {
                    FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "fingers", &freSpecificPointables, NULL);
                }
                uint32_t numSpecificTools;
                FREGetArrayLength(freSpecificPointables, &numSpecificTools);
                FRESetArrayElementAt(freSpecificPointables, numSpecificTools, frePointable);
                frePointablesMap[pointable.id()] = frePointable;
            }
        }
        
        if(!frame.gestures().empty()) {
            
            FREObject freGestures;
            FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "gesturesVector", &freGestures, NULL);
            
            for(int i = 0; i < frame.gestures().count(); i++) {
                const Gesture gesture = frame.gestures()[i];
                
                int state;
                switch (gesture.state()) {
                    case Gesture::STATE_INVALID:
                        state = 0;
                        break;
                    case Gesture::STATE_START:
                        state = 1;
                        break;
                    case Gesture::STATE_UPDATE:
                        state = 2;
                        break;
                    case Gesture::STATE_STOP:
                        state = 3;
                        break;
                        
                    default:
                        break;
                }
                
                int type;
                FREObject freGesture;
                switch (gesture.type()) {
                    case Gesture::TYPE_SWIPE:
                    {
                        type = 5;
                        SwipeGesture swipe = gesture;
                        
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.SwipeGesture", 0, NULL, &freGesture, NULL);
                        
                        FRESetObjectProperty(freGesture, (const uint8_t*) "direction", createVector3(swipe.direction().x, swipe.direction().y, swipe.direction().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "position", createVector3(swipe.position().x, swipe.position().y, swipe.position().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "startPosition", createVector3(swipe.startPosition().x, swipe.startPosition().y, swipe.startPosition().z), NULL);
                        
                        FREObject freSwipeGestureSpeed;
                        FRENewObjectFromDouble(swipe.speed(), &freSwipeGestureSpeed);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "speed", freSwipeGestureSpeed, NULL);

                        break;
                    }
                    case Gesture::TYPE_CIRCLE:
                    {
                        type = 6;
                        CircleGesture circle = gesture;

                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.CircleGesture", 0, NULL, &freGesture, NULL);
                        
                        FRESetObjectProperty(freGesture, (const uint8_t*) "center", createVector3(circle.center().x, circle.center().y, circle.center().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "normal", createVector3(circle.normal().x, circle.normal().y, circle.normal().z), NULL);
                        
                        FREObject freCircleGestureProgress;
                        FRENewObjectFromDouble(circle.progress(), &freCircleGestureProgress);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "progress", freCircleGestureProgress, NULL);
                        
                        FREObject freCircleGestureRadius;
                        FRENewObjectFromDouble(circle.radius(), &freCircleGestureRadius);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "radius", freCircleGestureRadius, NULL);
                    
                        FREObject frePointable = frePointablesMap[circle.pointable().id()];
                        if(frePointable != NULL)
                        {
                            FRESetObjectProperty(freGesture, (const uint8_t*) "pointable", frePointable, NULL);
                        }

                        break;
                    }
                    case Gesture::TYPE_SCREEN_TAP:
                    {
                        type = 7;
                        ScreenTapGesture screentap = gesture;
                        
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.ScreenTapGesture", 0, NULL, &freGesture, NULL);

                        FRESetObjectProperty(freGesture, (const uint8_t*) "direction", createVector3(screentap.direction().x, screentap.direction().y, screentap.direction().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "position", createVector3(screentap.position().x, screentap.position().y, screentap.position().z), NULL);

                        break;
                    }
                    case Gesture::TYPE_KEY_TAP:
                    {
                        type = 8;
                        KeyTapGesture tap = gesture;
                        
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.KeyTapGesture", 0, NULL, &freGesture, NULL);

                        FRESetObjectProperty(freGesture, (const uint8_t*) "direction", createVector3(tap.direction().x, tap.direction().y, tap.direction().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "position", createVector3(tap.position().x, tap.position().y, tap.position().z), NULL);
                        
                        break;
                    }
                    default:
                    {
                        type = 4;
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.Gesture", 0, NULL, &freGesture, NULL);
                        break;
                    }
                }
                
                FREObject freGestureState;
                FRENewObjectFromInt32(state, &freGestureState);
                FRESetObjectProperty(freGesture, (const uint8_t*) "state", freGestureState, NULL);
                
                FREObject freGestureType;
                FRENewObjectFromInt32(type, &freGestureType);
                FRESetObjectProperty(freGesture, (const uint8_t*) "type", freGestureType, NULL);

                FREObject freGestureDuration;
                FRENewObjectFromInt32((int32_t) gesture.duration(), &freGestureDuration);
                FRESetObjectProperty(freGesture, (const uint8_t*) "duration", freGestureDuration, NULL);
                
                FREObject freGestureDurationSeconds;
                FRENewObjectFromDouble(gesture.durationSeconds(), &freGestureDurationSeconds);
                FRESetObjectProperty(freGesture, (const uint8_t*) "durationSeconds", freGestureDurationSeconds, NULL);
                
                FRESetObjectProperty(freGesture, (const uint8_t*) "frame", freCurrentFrame, NULL);
                
                FREObject freGestureId;
                FRENewObjectFromInt32(gesture.id(), &freGestureId);
                FRESetObjectProperty(freGesture, (const uint8_t*) "id", freGestureId, NULL);
                
                if (!gesture.hands().empty()) {
                    
                    FREObject freGestureHands;
                    FREGetObjectProperty(freGesture, (const uint8_t*) "hands", &freGestureHands, NULL);
                    
                    for(int i = 0; i < gesture.hands().count(); i++) {
                        const Hand hand = gesture.hands()[i];
                        
                        FREObject freHand = freHandsMap[hand.id()];
                        FRESetArrayElementAt(freGestureHands, i, freHand);
                    }
                }
                
                if (!gesture.pointables().empty()) {
                    
                    FREObject freGesturePointables;
                    FREGetObjectProperty(freGesture, (const uint8_t*) "pointables", &freGesturePointables, NULL);
                    
                    for(int i = 0; i < gesture.pointables().count(); i++) {
                        const Pointable pointable = gesture.pointables()[i];
                        
                        FREObject frePointable = frePointablesMap[pointable.id()];
                        FRESetArrayElementAt(freGesturePointables, i, frePointable);
                    }
                }
                
                //push it in current gesture vector
                FRESetArrayElementAt(freGestures, i, freGesture);
            }
        }
        
        lastFrame = frame;
        
        return freCurrentFrame;
    }
예제 #24
0
/**
 * Creates a ActionScript net.rim.bbm.BBMContact instance from the supplied native contact.
 */
FREObject createActionScriptContact( const bbmsp_contact_t* contact )
{
	FREObject contact_AS = NULL;

	const int cNumAttributes = 7;
	FREObject resultAttributes[cNumAttributes];

	bbmsp_result_t result;

	char ppid[BBMSP_CONTACT_PPID_MAX];
	result = bbmsp_contact_get_ppid( contact, ppid, BBMSP_CONTACT_PPID_MAX );

	if( result == BBMSP_SUCCESS )
	{
		FRENewObjectFromUTF8((uint32_t)(strlen(ppid) + 1), (uint8_t*)ppid, &resultAttributes[0]);
	}
	else
	{
		trace( "createActionScriptContact ppid %i", result );
	}


	char displayName[BBMSP_CONTACT_DISPLAY_NAME_MAX];
	result = bbmsp_contact_get_display_name( contact, displayName, BBMSP_CONTACT_DISPLAY_NAME_MAX );
	if( result == BBMSP_SUCCESS )
	{
		FRENewObjectFromUTF8((uint32_t)(strlen(displayName) + 1), (uint8_t*)displayName, &resultAttributes[1]);
	}
	else
	{
		trace( "createActionScriptContact displayName %i", result );
	}


	char personalMessage[BBMSP_CONTACT_PERSONAL_MSG_MAX];
	result = bbmsp_contact_get_personal_message( contact, personalMessage, BBMSP_CONTACT_PERSONAL_MSG_MAX );
	if( result == BBMSP_SUCCESS )
	{
		FRENewObjectFromUTF8((uint32_t)(strlen(personalMessage) + 1), (uint8_t*)personalMessage, &resultAttributes[2]);
	}
	else
	{
		trace( "createActionScriptContact personalMessage %i", result );
	}

	char statusMessage[BBMSP_CONTACT_STATUS_MSG_MAX];
	result = bbmsp_contact_get_status_message( contact, statusMessage, BBMSP_CONTACT_STATUS_MSG_MAX );
	if( result == BBMSP_SUCCESS )
	{
		FRENewObjectFromUTF8((uint32_t)(strlen(statusMessage) + 1), (uint8_t*)statusMessage, &resultAttributes[3]);
	}
	else
	{
		trace( "createActionScriptContact statusMessage %i", result );
	}

	char appVersion[BBMSP_CONTACT_APP_VERSION_MAX];
	result = bbmsp_contact_get_app_version( contact, appVersion, BBMSP_CONTACT_APP_VERSION_MAX );
	if( result == BBMSP_SUCCESS )
	{
		FRENewObjectFromUTF8((uint32_t)(strlen(appVersion) + 1), (uint8_t*)appVersion, &resultAttributes[4]);
	}
	else
	{
		trace( "createActionScriptContact appVersion %i", result );
	}

	bbmsp_presence_status_t status;
	result = bbmsp_contact_get_status( contact, &status );
	if( result == BBMSP_SUCCESS )
	{
		FRENewObjectFromInt32( (int32_t)status, &resultAttributes[5]);
	}
	else
	{
		trace( "createActionScriptContact status %i", result );
	}


	bbmsp_image_t* m_contact_avatar;
	bbmsp_image_create_empty(&m_contact_avatar);

	result = bbmsp_contact_get_display_picture( contact, m_contact_avatar );
	trace( "%i picture", result );

	if( result == BBMSP_SUCCESS )
	{
		char path[PATH_MAX];
		getAvatarPath( m_contact_avatar, ppid, path );
		FRENewObjectFromUTF8((uint32_t)(strlen(path) + 1), (uint8_t*)path, &resultAttributes[6]);
	}
	else
	{
		resultAttributes[5] = NULL;
	}

	bbmsp_image_destroy( &m_contact_avatar );

	FRENewObject((const uint8_t*) "Array", cNumAttributes, resultAttributes, &contact_AS, NULL);

	return( contact_AS );
}
예제 #25
0
FREObject FREInt(int32 value) {
	FREObject result;
	FRENewObjectFromInt32(value, &result);
	return result;
}
예제 #26
0
FREObject getCaptureFrame(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    int32_t _id, _opt;
    FREGetObjectAsInt32(argv[0], &_id);

    FREObject res_obj;
    FRENewObjectFromInt32(0, &res_obj);

    FREObject objectBA;
    FREByteArray baData;
    FREBitmapData2 bitmapData;
    uint8_t *ba;
    const uint8_t* frame_0;
    const uint8_t* frame;

    int32_t w, h, w2, h2, widthInBytes, i, j;
    uint32_t fstride;
    CCapture* cap;
    cap = active_cams[_id];
    
    uint32_t flipped = 0;
    uint32_t isWin = 1;
    #if defined(ANE_MAC)
        isWin = 0;
    #endif

    objectBA = argv[1];
    FREAcquireByteArray(objectBA, &baData);
    ba = baData.bytes;

    ba += ba_read_int(ba, &_opt);
    ba += ba_read_int(ba, &w2);
    ba += ba_read_int(ba, &h2);

    FREReleaseByteArray(objectBA);

    if(cap && captureCheckNewFrame(cap))
    {
        frame_0 = (const uint8_t*)captureGetFrame(cap, &w, &h, &widthInBytes);

        // here is some conversion we need cause in Flash BitmapData bytes
        // represented differently :(
        if((_opt & FRAME_BITMAP))
        {
            objectBA = argv[2];
            FREAcquireBitmapData2(objectBA, &bitmapData);

            uint32_t* input = bitmapData.bits32;
            fstride = bitmapData.lineStride32 * sizeof(uint32_t); // for some reasons not always == width
            flipped = bitmapData.isInvertedY;

            frame = frame_0;
            ba = (uint8_t*)input;
            
            #if defined (__ANDROID__) || defined (ANE_IOS)

                for(i=0; i<h; i++){
                    memcpy(ba+i*fstride, frame+i*widthInBytes, fstride);
                }

            #else

            // most likely wont happen / but who knows? ;)
            if(flipped && !isWin)
            {
                const uint8_t* a_ptr = (const uint8_t*)frame;
                const uint8_t* a_ptr2 = (const uint8_t*)(frame + (h - 1) * widthInBytes);
                uint8_t* b_ptr = ba + (h - 1) * fstride;
                uint8_t* b_ptr2 = ba;
                for(i = 0; i < h / 2; i++)
                {
                    uint8_t *ba_ln = b_ptr;
                    uint8_t *ba_ln2 = b_ptr2;
                    const uint8_t *a_ln = a_ptr;
                    const uint8_t *a_ln2 = a_ptr2;
                    #if defined(ANE_MSW)
                    for(j = 0; j < w; j++, ba_ln += 4, ba_ln2 += 4, a_ln += 3, a_ln2 += 3)
                    {
                            *ba_ln = *(a_ln);
                            ba_ln[1] = *(a_ln+1);
                            ba_ln[2] = *(a_ln+2);
                            //
                            *ba_ln2 = *(a_ln2);
                            ba_ln2[1] = *(a_ln2+1);
                            ba_ln2[2] = *(a_ln2+2);
                    }
                    #elif defined(ANE_MAC)
                    memcpy(ba_ln, a_ln, widthInBytes);
                    memcpy(ba_ln2, a_ln2, widthInBytes);
                    #endif
                    
                    a_ptr += widthInBytes;
                    a_ptr2 -= widthInBytes;
                    b_ptr -= fstride;
                    b_ptr2 += fstride;
                }
                if(h&1)
                {
                    #if defined(ANE_MSW)
                        for(j = 0; j < w; j++, b_ptr += 4, a_ptr+=3)
                        {
                            *b_ptr = *(a_ptr);
                            b_ptr[1] = *(a_ptr+1);
                            b_ptr[2] = *(a_ptr+2);
                        }
                    #elif defined(ANE_MAC)
                        memcpy(b_ptr, a_ptr, widthInBytes);
                    #endif
                }
            }
            else
            {
                for(i = 0; i < h; i++)
                {
                    uint8_t *ba_ln = ba;
                    const uint8_t *fr_ln = frame;
                    #if defined(ANE_MSW)
                        for(j = 0; j < w; j++, ba_ln += 4, fr_ln += 3)
                        {                        
                            *ba_ln = *(fr_ln);
                            ba_ln[1] = *(fr_ln+1);
                            ba_ln[2] = *(fr_ln+2);
                        }
                    #elif defined(ANE_MAC) 
                        memcpy(ba_ln, fr_ln, widthInBytes);
                    #endif
                    ba += fstride;
                    frame += widthInBytes;
                }
            }

            #endif


            FREReleaseBitmapData(objectBA);
        } 

        if((_opt & FRAME_RAW))
        {
            objectBA = argv[3];
            FREAcquireByteArray(objectBA, &baData);
            ba = baData.bytes;

            memcpy(ba, frame_0, widthInBytes * h);

            FREReleaseByteArray(objectBA);
        }

        // power of 2 output for stage3d
        if((_opt & FRAME_P2_BGRA))
        {
            objectBA = argv[4];
            FREAcquireByteArray(objectBA, &baData);
            ba = baData.bytes;

            frame = frame_0;

            // resize
            /*
            if(w > w2 || h > h2)
            {
                float scx = (float)w2 / (float)w;
                float scy = (float)h2 / (float)h;
                if(scy < scx) scx = scy;
                int32_t wr = w * scx;
                int32_t hr = h * scx;
                uint8_t *frame_rs = allocResizeBuf(wr, hr, 4);
                //resample_area_8u(frame, w, h, frame_rs, wr, hr, 4);

                // update values
                w = wr;
                h = hr;
                frame = frame_rs;
                widthInBytes = wr * sizeof(uint32_t);
            }
            */

            int32_t p2w = (w2);
            int32_t p2h = (h2);
            int32_t off_x = (p2w - w) / 2; // -64
            int32_t off_y = (p2h - h) / 2;
            size_t p2stride = p2w * sizeof(uint32_t);

            int32_t b_off_x, b_off_y, a_off_x, a_off_y;

            if(off_x < 0)
            {
                b_off_x = 0;
                a_off_x = -off_x;
            } else {
                b_off_x = off_x;
                a_off_x = 0;
            }

            if(off_y < 0)
            {
                b_off_y = 0;
                a_off_y = -off_y;
            } else {
                b_off_y = off_y;
                a_off_y = 0;
            }

            uint8_t* b_ptr0 = ba + b_off_y * p2stride + b_off_x*4;

            int32_t nw = w - a_off_x*2;
            int32_t nh = h - a_off_y*2;

            #if defined (ANE_MSW) // we need flip Y

                const uint8_t* a_ptr0 = (const uint8_t*)(frame + a_off_y * widthInBytes + a_off_x*3);
                const uint8_t* a_ptr = a_ptr0;
                const uint8_t* a_ptr2 = a_ptr0 + (nh - 1) * widthInBytes;
                uint8_t* b_ptr = b_ptr0 + (h - 1) * p2stride;
                uint8_t* b_ptr2 = b_ptr0;
                const uint8_t alpha = 0xFF;
                for(i = 0; i < nh / 2; i++)
                {
                    uint8_t *ba_ln = b_ptr;
                    uint8_t *ba_ln2 = b_ptr2;
                    const uint8_t *a_ln = a_ptr;
                    const uint8_t *a_ln2 = a_ptr2;
                    for(j = 0; j < nw; j++, ba_ln += 4, ba_ln2 += 4, a_ln += 3, a_ln2 += 3)
                    {

                        *ba_ln = *(a_ln+0);
                        ba_ln[1] = *(a_ln+1);
                        ba_ln[2] = *(a_ln+2);
                        ba_ln[3] = alpha;
                        //
                        *ba_ln2 = *(a_ln2+0);
                        ba_ln2[1] = *(a_ln2+1);
                        ba_ln2[2] = *(a_ln2+2);
                        ba_ln2[3] = alpha;
                    }
                    
                    a_ptr += widthInBytes;
                    a_ptr2 -= widthInBytes;
                    b_ptr -= p2stride;
                    b_ptr2 += p2stride;
                }
                if(nh&1)
                {
                    for(j = 0; j < nw; j++, b_ptr += 4, a_ptr+=3)
                    {
                        *b_ptr = *(a_ptr+0);
                        b_ptr[1] = *(a_ptr+1);
                        b_ptr[2] = *(a_ptr+2);
                        b_ptr[3] = alpha;
                    }
                }

            #elif defined(ANE_MAC) || defined (ANE_IOS) || defined (__ANDROID__) 

                const uint8_t* a_ptr0 = (const uint8_t*)(frame + a_off_y * widthInBytes + a_off_x*4);

                for(i = 0; i < nh; i++)
                {
                    memcpy(b_ptr0, a_ptr0, nw*4);
                    a_ptr0 += widthInBytes;
                    b_ptr0 += p2stride;
                }

            #endif
            
            FREReleaseByteArray(objectBA);
        }

        FRENewObjectFromInt32(1, &res_obj);
    } 
    else if(cap)
    {
        // lets see if device is available it may be freezed
        if( captureCheckResponse(cap) == 0 )
        {
            FRENewObjectFromInt32(-1, &res_obj);
        }
    }

    return res_obj;
}
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;
}
예제 #28
0
FREObject getFREObjectFromInt32(int32_t arg) {
	FREObject result;
	FRENewObjectFromInt32(arg, &result);
	return result;
}