On Wed, Jul 10, 2013 at 12:25 PM, Luís Miranda <[email protected]> wrote:
> So, what you are telling me is something like this will work:
Basically - but I have a few comments that I'll post inline.
> #include <uv.h>
> #include <node.h>
>
> #include "hardware.h"
>
> using namespace v8;
>
> uv_loop_t *loop;
> uv_async_t async;
>
> void Interruption_handler(*data){
>
> async.data = data;
If you use the .data field, you need to protect access with e.g. a
mutex. See uv_mutex_t in uv.h.
> uv_async_send(&async);
>
> }
>
> Handle<Value> RunCallback(const Arguments& args) {
Wrong function prototype, it should be `void RunCallback(uv_async_t*
handle, int status)`. The status field is unused, it's always zero.
> HandleScope scope;
>
> Local<Function> cb = Local<Function>::Cast(args[0]);
> const unsigned argc = 1;
> Local<Value> argv[argc] = { Local<Value>::New(String::New("hello world"))
> };
> cb->Call(Context::GetCurrent()->Global(), argc, argv);
>
> return scope.Close(Undefined());
> }
>
> Handle<Value> Start(const Arguments& args){
> HandleScope scope;
> feedback = Hardware_Setup(Interruption_handler);
> return scope.Close(Integer::New(feedback));
> }
>
> void Init(Handle<Object> exports){
> node::SetMethod(exports, "RunCallback", RunCallBack)
> node::SetMethod(exports, "Start", Start);
>
> loop = uv_default_loop();
> uv_async_init(loop, &async, RunCallBack);
> uv_run(loop, UV_RUN_DEFAULT);
You don't call uv_run(), node.js does that for you when it's time.
> }
>
> NODE_MODULE(addon, Init)
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.