I do not know js-ctypes enough to be of any help, but I know that you are
unlikely to find any help about that on the dev.b2g news group.
On 07/29/2013 11:30 PM, Kilcheon Kim wrote:
Hi, All,
Actually, I am studying how to port native application(made by C and C++) into
B2G.
Then you should probably look into using emscripten than js-ctypes. Unless
you want to flash the phone your self, I hardly think you can have access to
js-ctypes from any pages. js-ctypes were made for embedding the JS engine
in other program while providing a layer of interoperability.
If you are worried about the performance of your code, I think emscripten
might be faster in the end, as you never leave the JS Engine and avoid all
the boxing/unboxing mechanism of the native types.
I added my test library in root directory such as "/b2g/libTEST". And I used
js-ctypes to load native library(libTEST.so).
Now library was ran properly by js-ctypes. My library should use some thread.
As my testing, thread and timer work well.
But I have a problem about js-ctypes callback.
I am defining my callback in gecko layer such as:
myCallback = function(arg) {
debug("myCallback : arg = " + arg);
}
......
SetMy_CB = library.declare("SetMyCallback",
ctypes.default_abi,
ctypes.void_t,
ctypes.voidptr_t);
My_CB = ctypes.FunctionType(
ctypes.default_abi,
ctypes.void_t,
[ctypes.voidptr_t]
).ptr;
SetMy_CB(My_CB(myCallback));
and I add some code in my library for callback such as :
**** in header file
typedef void MyCallback_forGecko(void* in_bitmap);
extern void SetMyCallback(MyCallback_forGecko* callback);
......
**** in source file
static MyCallback_forGecko* gMyCallback_forGecko;
void SetMyCallback(Callback_MyCallback_forGecko* callback)
{
gMyCallback_forGecko = callback;
}
......
gMyCallback_forGecko(arg) //call callback function
In this case, I got crash because thread is not main thread, when gMyCallback
called.
My library should be use two gThreads to run.
Of course, I know that thread is same to use js-ctypes callback. But I don't
know how to use same thread in gecko and my library.
Would please let me know how to implement js-ctypes callback?
Any help would be greatly appreciated.
Thanks,
--
Nicolas B. Pierron
_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g