Exemplo n.º 1
0
static
void
DNSSD_API
OnServiceChanged(DNSServiceRef sdRef, DNSServiceFlags flags, 
        uint32_t interfaceIndex, DNSServiceErrorType errorCode, 
        const char * serviceName, const char * serviceType,
        const char * replyDomain, void * context)
{
    NanScope();
    ServiceRef * serviceRef = static_cast<ServiceRef*>(context);
    Handle<Function> callback = serviceRef->GetCallback();
    Handle<Object> this_ = serviceRef->GetThis();

    const size_t argc(8);
    Local<Value> args[argc];
    args[0] = NanObjectWrapHandle(serviceRef);
    args[1] = NanNew<Integer>(flags);
    args[2] = NanNew<Uint32>(interfaceIndex);
    args[3] = NanNew<Integer>(errorCode);
    args[4] = stringOrUndefined(serviceName);
    args[5] = stringOrUndefined(serviceType);
    args[6] = stringOrUndefined(replyDomain);
    if (serviceRef->GetContext().IsEmpty()) {
        args[7] = NanUndefined();
    } else {
        args[7] = NanNew<Value>(serviceRef->GetContext());
    }
    NanMakeCallback(this_, callback, argc, args);
}
Exemplo n.º 2
0
void
DNSSD_API
OnResolve(DNSServiceRef sdRef, DNSServiceFlags flags,
        uint32_t interfaceIndex, DNSServiceErrorType errorCode,
        const char * fullname, const char * hosttarget, uint16_t port,
        uint16_t txtLen, const unsigned char * txtRecord, void * context)
{

    NanScope();
    ServiceRef * serviceRef = static_cast<ServiceRef*>(context);
    Handle<Function> callback = serviceRef->GetCallback();
    Handle<Object> this_ = serviceRef->GetThis();

    const size_t argc(9);
    Local<Value> args[argc];
    args[0] = NanObjectWrapHandle(serviceRef);
    args[1] = NanNew<Integer>(flags);
    args[2] = NanNew<Uint32>(interfaceIndex);
    args[3] = NanNew<Integer>(errorCode);
    args[4] = stringOrUndefined(fullname);
    args[5] = stringOrUndefined(hosttarget);
    args[6] = NanNew<Integer>( ntohs(port) );
    Local<Object> buffer = NanNewBufferHandle(txtLen);
    memcpy(Buffer::Data(buffer), txtRecord, txtLen);
    args[7] = buffer;
    if (serviceRef->GetContext().IsEmpty()) {
        args[8] = NanUndefined();
    } else {
        args[8] = NanNew<Value>(serviceRef->GetContext());
    }
    NanMakeCallback(this_, callback, argc, args);
}
Exemplo n.º 3
0
static
void
DNSSD_API
OnServiceRegistered(DNSServiceRef sdRef, DNSServiceFlags flags,
        DNSServiceErrorType errorCode, const char * name,
        const char * serviceType, const char * domain, void * context)
{
    if ( ! context) return;

    NanScope();
    ServiceRef * serviceRef = static_cast<ServiceRef*>(context);
    Handle<Function> callback = serviceRef->GetCallback();
    Handle<Object> this_ = serviceRef->GetThis();

    if ( ! callback.IsEmpty() && ! this_.IsEmpty()) {
        const size_t argc(7);
        Local<Value> args[argc];
        args[0] = NanObjectWrapHandle(serviceRef);
        args[1] = NanNew<Integer>(flags);
        args[2] = NanNew<Integer>(errorCode);
        args[3] = stringOrUndefined(name);
        args[4] = stringOrUndefined(serviceType);
        args[5] = stringOrUndefined(domain);
        if (serviceRef->GetContext().IsEmpty()) {
            args[6] = NanUndefined();
        } else {
            args[6] = NanNew<Value>(serviceRef->GetContext());
        }
        NanMakeCallback(this_, callback, argc, args);
    }
}
Exemplo n.º 4
0
Image::~Image() {

  Local<Value> internalField = NanObjectWrapHandle(this)->GetInternalField(0);
  if (internalField->IsNull()) return;

  FIBITMAP *dib = static_cast<FIBITMAP*>(Local<External>::Cast(internalField)->Value());
  FreeImage_Unload(dib);
}
Exemplo n.º 5
0
Local<Function> Cache::exitCallback() {
  NanEscapableScope();

  Local<Function> unboundExitCallback(NanNew<FunctionTemplate>(Cache::Close)->GetFunction());

  static const int argc = 1;
  Handle<Value> argv[argc] = { NanObjectWrapHandle(this) };
  Local<Function> boundExitCallback(
      NanMakeCallback(unboundExitCallback, "bind", argc, argv).As<Function>());

  return NanEscapeScope(boundExitCallback);
}
Exemplo n.º 6
0
 static NAUV_WORK_CB(EmitMessage)
 {
     NanScope();
     NodeMidiInput *input = static_cast<NodeMidiInput*>(async->data);
     uv_mutex_lock(&input->message_mutex);
     v8::Local<v8::Function> emitFunction = NanObjectWrapHandle(input)->Get(NanNew<v8::String>(symbol_emit)).As<v8::Function>();
     while (!input->message_queue.empty())
     {
         MidiMessage* message = input->message_queue.front();
         v8::Local<v8::Value> args[3];
         args[0] = NanNew<v8::String>(symbol_message);
         args[1] = NanNew<v8::Number>(message->deltaTime);
         int32_t count = (int32_t)message->message.size();
         v8::Local<v8::Array> data = NanNew<v8::Array>(count);
         for (int32_t i = 0; i < count; ++i) {
             data->Set(NanNew<v8::Number>(i), NanNew<v8::Integer>(message->message[i]));
         }
         args[2] = data;
         NanMakeCallback(NanObjectWrapHandle(input), emitFunction, 3, args);
         input->message_queue.pop();
         delete message;
     }
     uv_mutex_unlock(&input->message_mutex);
 }
void
DNSSD_API
OnEnumeration(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
        DNSServiceErrorType errorCode, const char * replyDomain, void * context)
{
    Nan::HandleScope scope;
    ServiceRef * serviceRef = static_cast<ServiceRef*>(context);
    Handle<Function> callback = serviceRef->GetCallback();
    Handle<Object> this_ = serviceRef->GetThis();

    const size_t argc(6);
    Local<Value> args[argc];
    args[0] = NanObjectWrapHandle(serviceRef);
    args[1] = NanNew<Integer>(flags);
    args[2] = NanNew<Uint32>(interfaceIndex);
    args[3] = NanNew<Integer>(errorCode);
    args[4] = stringOrUndefined(replyDomain);
    args[5] = NanNew<Value>(serviceRef->GetContext());
    NanMakeCallback(this_, callback, argc, args);
}
void NodeFileSource::processAdd(mbgl::Request *req) {
    NanScope();

    // Make sure the loop stays alive as long as request is pending.
    if (pending.empty()) {
        queue->ref();
    }

    auto handle = NanObjectWrapHandle(this);
    auto requestHandle = NanNew<v8::Object>(NodeRequest::Create(handle, req));
#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
    const v8::UniquePersistent<v8::Object> requestPersistent(v8::Isolate::GetCurrent(), requestHandle);
#else
    v8::Persistent<v8::Object> requestPersistent;
    NanAssignPersistent(requestPersistent, requestHandle);
#endif
    pending.emplace(req, std::move(requestPersistent));

    v8::Local<v8::Value> argv[] = { requestHandle };
    NanMakeCallback(handle, NanNew("request"), 1, argv);
}
void NodeFileSource::processCancel(mbgl::Request *req) {
    NanScope();

    auto it = pending.find(req);
    if (it == pending.end()) {
        // The response callback was already fired. There is no point in calling the cancelation
        // callback because the request is already completed.
    } else {
#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
        auto requestHandle = v8::Local<v8::Object>::New(v8::Isolate::GetCurrent(), it->second);
#else
        auto requestHandle = NanNew<v8::Object>(it->second);
#endif

        // Dispose and remove the persistent handle
#if (NODE_MODULE_VERSION <= NODE_0_10_MODULE_VERSION)
        NanDisposePersistent(it->second);
#endif
        pending.erase(it);

        // Make sure the the loop can exit when there are no pending requests.
        if (pending.empty()) {
            queue->unref();
        }

        auto handle = NanObjectWrapHandle(this);
        if (handle->Has(NanNew("cancel"))) {
            v8::Local<v8::Value> argv[] = { requestHandle };
            NanMakeCallback(handle, NanNew("cancel"), 1, argv);
        }

        // Set the request handle in the request wrapper handle to null
        ObjectWrap::Unwrap<NodeRequest>(requestHandle)->cancel();
    }

    // Finally, destruct the request object
    req->destruct();
}
Exemplo n.º 10
0
void Grid::EIO_AfterClear(uv_work_t* req)
{
    NanScope();
    clear_grid_baton_t *closure = static_cast<clear_grid_baton_t *>(req->data);
    if (closure->error)
    {
        // There seems to be no possible way for the exception to be thrown in the previous 
        // process and therefore not possible to have an error here so removing it from code
        // coverage
        /* LCOV_EXCL_START */
        Local<Value> argv[1] = { NanError(closure->error_name.c_str()) };
        NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv);
        /* LCOV_EXCL_END */
    }
    else
    {
        Local<Value> argv[2] = { NanNull(), NanObjectWrapHandle(closure->g) };
        NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv);
    }
    closure->g->Unref();
    NanDisposePersistent(closure->cb);
    delete closure;
}
Exemplo n.º 11
0
 static NAN_METHOD(GetHandle) {
   NanScope();
   MyObject* obj = node::ObjectWrap::Unwrap<MyObject>(args.This());
   NanReturnValue(NanObjectWrapHandle(obj));
 }