[flexcoders] C Native Extension: Need to replace time structure into millisecond output

Tuesday, December 27, 2011

 

I'm taking time to experiment how I can track the MIDI timing in milliseconds. In this code below contain date and time format and wish to replace with time function that is capable of milliseconds precision without huge jump in accuracy. This will be run on Window 7 using GCC or MingGW compilers.
Any advice is appreciate!

#include "FlashRuntimeExtensions.h"
#include "Stdlib.h"
#include "SampleANE.h"
#include "String.h"
#include "time.h"

//If AIR can access this function, return 1, ANE is avail
FREObject isSupported(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
FREObject result;

uint32_t isSupportedInThisOS = 1;
FRENewObjectFromBool(isSupportedInThisOS, &result); //Boolean to object and return, FRE_OK

return result;
}

FREObject getTestString(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
FREObject result = 0;

//Temporary values to hold our actionscript code.
uint32_t len = -1;
const uint8_t *str = 0;
char *temp;
uint8_t *strAll;

time_t curtime;
struct tm *loctime;

curtime = time(NULL);

loctime = malloc(sizeof(curtime));

loctime = localtime(&curtime);

char *asc = asctime(loctime);

//Turn our actionscrpt code into native code.
if(FREGetObjectAsUTF8(argv[0], &len, &str) == FRE_OK) {
temp = "Hello World! This is ";

strAll = (char *)malloc(strlen(temp) + strlen(str) + strlen(asc) + 1);
strcpy(strAll,temp);
strcat(strAll,str);
strcat(strAll,asctime(loctime));
}

FRENewObjectFromUTF8(strlen((const char *)strAll)+1, (const uint8_t *)strAll, &result); //UTF8 to object and return
free(strAll);
free(temp);

return result;
}

FREObject getHelloWorld(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
FREObject result;

const char *str = "Hello World! This is a String";
FRENewObjectFromUTF8(strlen(str)+1, (const uint8_t *)str, &result);

return result;
}

void contextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t* numFunctions, const FRENamedFunction** functions)
{
// setup the number of functions in this extension
*numFunctions = 3;

// create an array to store all the functions we will use.
FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * (*numFunctions));

// create an array entry for each function
func[0].name = (const uint8_t*) "getTestString";
func[0].functionData = NULL; //data type from ctxType?
func[0].function = &getTestString;

func[1].name = (const uint8_t*) "isSupported";
func[1].functionData = NULL; //data type from ctxType?
func[1].function = &isSupported;

func[2].name = (const uint8_t*) "getHelloWorld";
func[2].functionData = NULL; //data type from ctxType?
func[2].function = &getHelloWorld;

// create an array to store all the functions we will use.
*functions = func;
}

// A native context instance is disposed
void contextFinalizer(FREContext ctx) {
return;
}

void initializer(void** extData, FREContextInitializer* ctxInitializer, FREContextFinalizer* ctxFinalizer) {
*ctxInitializer = &contextInitializer;
*ctxFinalizer = &contextFinalizer;
}

void finalizer(void* extData) {
return;
}

__._,_.___
Recent Activity:
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

0 comments:

Post a Comment