So, what you are telling me is something like this will work:

#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;
*uv_async_send*(&async); 

}

Handle<Value> *RunCallback*(const Arguments& args) {
  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);   
}

NODE_MODULE(addon, Init)




On Wednesday, July 10, 2013 10:48:24 AM UTC+1, Ben Noordhuis wrote:
>
> On Wed, Jul 10, 2013 at 11:25 AM, Luís Miranda 
> <[email protected]<javascript:>> 
> wrote: 
> > Hi. 
> > 
> > I'm working in a project where the goal is to provide in JavaScript some 
> > functions to access to an hardware platform. The hardware platform 
> provides 
> > a library and a header with the functions available. We are building 
> some 
> > nodeJS addons on the top of these functions.  The problem is , answers 
> given 
> > by the hardware are event based, and function to deal with those events 
> must 
> > be passed to the hardware during the start up an then the hardware will 
> call 
> > that function in another thread. This prevents me from using a callback 
> > inside of the Interruption_handler function. 
> > 
> > Interruption_handler(*data){ 
> > 
> >     // if data == 1; 
> >     //     do something(); 
> >     //     curl -> Make request to the server 
> > } 
> > 
> > 
> > Handle<Value> Start(const Arguments& args){ 
> >      Hardware_Setup(Interruption_handler) 
> > } 
> > 
> > 
> > void Init(...){ 
> >     node::SetMethod(exports, "Start", Start); 
> > } 
> > 
> > NODE_MODULE(addon, Init) 
> > 
> > So, i tried to solve the problem by using curl to make a request to a 
> nodeJS 
> > server from inside the Interruption_handler().  This server is running 
> in 
> > the same nodejs instance where the the JavaScript functions to access 
> the 
> > hardware are called. I thought this was a good idea, but curl just 
> hangs. If 
> > i put the server in another node instance, everything works OK. 
> > 
> > I've already tried to use libuv, but curl still hangs. Any ideas on why 
> curl 
> > is hanging or how to solve this problem? 
> > 
> > Thanks in advance. 
> > 
> > PS: Not a native English speaker :) 
>
> You get notifications in a different thread?  You can use a uv_async_t 
> handle for that. 
>
> First uv_async_init() it in the main thread.  Then, when you receive a 
> notification, call uv_async_send() and libuv will wake up the main 
> thread for you and invoke your C/C++ callback.  From there on, you can 
> call into V8 using MakeCallback() or what have you. 
>
> You will probably need some kind of synchronization around shared data 
> structures.  Libuv provides the full gamut of mutexes, read/write 
> locks, barriers, etc. 
>

-- 
-- 
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.


Reply via email to