My fun time at MAX

I had a good time at MAX, learned a few new things about some Flash Player 10 internals, learned some new things about performance tuning from Sean Christmann, and found out that there’s a lot of stuff going on with getting the Flash Player to run on ARM, which you should read as “on powerful Mobile phones”, which you can read however you would like.

I’m also going to lay out a quick note of how I solved the “AIR communicate with the System” problem. I wrote a wrapper application that launched the AIR app when it was started up, nothing new or exciting there. Then I just wrote commands that looked like:

“ls -a {0}”

where I would just fill {0} with the value passed from the AIR app. I encrypt those so that the command can’t be tinkered with and unencrypt them at runtime. Then, in a very lightweight (i.e. ~4kb) process I just check the file to see if it exists and whether it’s locked, if it’s not locked, then we read it, fill the command with the parameters, and then pass it to the system to be executed.

The meat of the OSX version of this looks more or less like so:


// this is the threaded method
void *process( void *data )
{
while(run) {
checkFile();
usleep(500000);
}
char buffer[1024];
sprintf(buffer, "rm -f %s", f->cfile);
system(buffer);
return (void*) 1;
}


int main(int argc, char *argv[])
{
char* lockFile;
char* commFile;
char* result;
//
printf(" starting up ");
commFile = (char*) malloc(1024 * sizeof(char));
lockFile = (char*) malloc(1024 * sizeof(char));
result = (char*) calloc(1024, sizeof(char));
//
pthread_t thread;
int threadi;
//
// you'll want to encrypt your system commands just in case
// so you could do
// xorUnencrypt(addToSafe);
// start up the air app, if it works we'll create the thread
if(startAIRApp(commFile, lockFile) == 1)
{
run = true;
// thread identifier
threadi = pthread_create(&thread, NULL, process, NULL);
// go ahead and make the thread
pthread_join(thread, NULL);
//
free(commFile);
free(result);
free(lockFile);
}
}

Is this beautiful C? Nah, not really. But it works. The rest of the OSX version (extremely sanitized for the sake of my future employment) is here.

The hardest part of all of this was finding where the app wasn so that I could launch it. On OSX that requires that you make use of the FSRef object. Essentially, you do the following:

1) create a FSRef object
2) pass is to LSFindApplicationForInfo along with the name of the bundle from the plist file of your app
3) call FSRefMakePath along with a string that the path can written into

that looks pretty much like so:


OSStatus err;
FSRef appRef; // this is the OSX application object that you can get the app path from
char *appPath = (char*)malloc(1024); // just go ahead and do the max
//
err = LSFindApplicationForInfo(0, CFSTR(TARGET_APP_BUNDLE_ID), NULL, &appRef, NULL);
if (err != 0) { return err; }
appPath = NULL;
// note the wierd cast, ick
err = FSRefMakePath(&appRef, (UInt8*) appPath, appPathSize); // now your application path is written to appPath

And that’s really all there is to it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>