I've been waiting like fifteen years for something like nacl to
happen. I really hope that the project will not be canned ;-)
Question about fileloading via SRPC. From the examples I have gathered
the following picture. All file loads are basically initiated by
JavaScript...
1) JS: Get a reference to the NaCl plugin like this:
plugin = document.getElementById('my-nacl-embed');
2) JS => C++: Invoke a method called __urlAsNaClDesc on the plugin,
which checks the url, and opens a file descriptor to it. Funny enough,
this method seems to be only reachable from Javascript, not from the
plugin itself?!
plugin.__urlAsNaClDesc(url, new MyHandler("media/something.jpg"));
3) C++ => JS: One of the parameters to __urlAsNaClDesc is a reference
to a JS object which must have two methods: onload(filedesc) and onfail
(object). Either one or the other is invoked depending on the legality
of the url given to __urlAsNaClDesc...
var MyHandler = function (theFileName) {
this.fileName = theFileName
this.onload = function (theFileDescriptor) { }
this.onfail = function (object) { }
}
4) JS => C++: Via the SRPC interface, JavaScript hands over the file
descriptor to C++ through some function that the C++ plugin must
export...
...
this.onload = function (theFileDescriptor) {
// Invoke the SRPC handler that ends up using the file
descriptor for loading
plugin.myHandler (theFileDescriptor, this.fileName)
}
5) C++: Load and cache the file through an implementation of the
handler mentioned above.
int myHandler (NaClAppArg **in_args, NaClAppArg **out_args);
NACL_SRPC_METHOD("myHandler:hs", myHandler);
int myHandler (NaClAppArg **in_args, NaClAppArg **out_args) {
int filedesc = in_args[0]->u.hval;
char* filename = in_args[1]->u.sval;
FILE* file = fdopen (filedesc, "r");
// ... Check for errors, read from the file, cache the data.
fclose(file);
// Or to put it into the framework below... call
myRetreiveFileDescFromJS (filename, fd)
return RPC_OK;
}
I'd like to have a "step 0" in the above scheme, where I can call out
from C++ to JS and start the (probably highly asynchronous) process of
retrieving a file descriptor and putting it back to C++. So basically
we replace this simple C operation:
file = fopen("media/something.jpg", "r");
with all the JS above plus this C++:
map<string, int> globalFileDescriptors;
pthread_cond_t globalFDCond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t globalFDMutex = PTHREAD_MUTEX_INITIALIZER;
void loadSomeTexture()
{
askJStoLoadFile("media/something.jpg");
// Sleep until JS has reported back via the SRPC function
below.
pthread_mutex_lock( &globalFDMutex );
while (globalFileDescriptors.find)"media/something.jpg") ==
globalFileDescriptors.end())
pthread_cond_wait( &globalFDCond, &globalFDMutex );
pthread_mutex_unlock( &globalFDMutex );
}
void myRetreiveFileDescFromJS (filename, fd)
{
globalFileDescriptors[filename] = fd;
pthread_mutex_lock( &globalFDMutex );
pthread_cond_signal( &globalFDCond, &globalFDMutex );
pthread_mutex_unlock( &globalFDMutex );
}
It all seems a bit elaborate :)
Now for the questions: First, before I go on, I would like to hear
that this is the simplest way of doing things.
Second, assuming that it is, I'd be happy if somebody could point me
to a code example where invocation from C++ => JS takes place. I would
much prefer to use SRPC alone to keep dependencies to a minimum.
Cheers
P.S. gtardini... Don't give up on Ogre yet. I'd be happy to cooperate
on that one once Irrlicht is running steady and I've had some fun with
it. After Irrlicht, I'd probably mess with a sound library next
though.
> > wgethttp://
atomicmonstergirls.net/work/nacl/my-irrlicht-0.1.tar.gz