void* TypedArray::Validate(Handle<Object> obj, GDALDataType type, int min_length){ //validate array NanEscapableScope(); if(!obj->HasIndexedPropertiesInExternalArrayData()) { NanThrowError("Object has no external array data"); return NULL; } GDALDataType src_type = TypedArray::Identify(obj); if(type == GDT_Unknown) { NanThrowTypeError("Unable to identify GDAL datatype of passed array object"); return NULL; } if(src_type != type) { std::ostringstream ss; ss << "Array type does not match band data type (" << "array: " << GDALGetDataTypeName(src_type) << " band: " << GDALGetDataTypeName(type) << ")"; NanThrowTypeError(ss.str().c_str()); return NULL; } if(TypedArray::Length(obj) < min_length) { std::ostringstream ss; ss << "Array length must be greater than or equal to " << min_length; NanThrowError(ss.str().c_str()); return NULL; } return TypedArray::Data(obj); }
static inline NAN_METHOD(register_fonts) { NanScope(); try { if (args.Length() == 0 || !args[0]->IsString()) { NanThrowTypeError("first argument must be a path to a directory of fonts"); NanReturnUndefined(); } bool found = false; std::vector<std::string> const names_before = mapnik::freetype_engine::face_names(); // option hash if (args.Length() == 2){ if (!args[1]->IsObject()) { NanThrowTypeError("second argument is optional, but if provided must be an object, eg. { recurse:Boolean }"); NanReturnUndefined(); } Local<Object> options = args[1].As<Object>(); if (options->Has(NanNew("recurse"))) { Local<Value> recurse_opt = options->Get(NanNew("recurse")); if (!recurse_opt->IsBoolean()) { NanThrowTypeError("'recurse' must be a Boolean"); NanReturnUndefined(); } bool recurse = recurse_opt->BooleanValue(); std::string path = TOSTR(args[0]); found = mapnik::freetype_engine::register_fonts(path,recurse); } } else { std::string path = TOSTR(args[0]); found = mapnik::freetype_engine::register_fonts(path); } std::vector<std::string> const& names_after = mapnik::freetype_engine::face_names(); if (names_after.size() == names_before.size()) found = false; NanReturnValue(NanNew(found)); } catch (std::exception const& ex) { NanThrowError(ex.what()); NanReturnUndefined(); } }
static NAN_METHOD(GetPortName) { NanScope(); NodeMidiOutput* output = node::ObjectWrap::Unwrap<NodeMidiOutput>(args.This()); if (args.Length() == 0 || !args[0]->IsUint32()) { return NanThrowTypeError("First argument must be an integer"); } unsigned int portNumber = args[0]->Uint32Value(); v8::Local<v8::String> result = NanNew<v8::String>(output->out->getPortName(portNumber).c_str()); NanReturnValue(result); }
static NAN_METHOD(New) { NanScope(); if (!args.IsConstructCall()) { return NanThrowTypeError("Use the new operator to create instances of this object."); } NodeMidiOutput* output = new NodeMidiOutput(); output->Wrap(args.This()); NanReturnValue(args.This()); }
static NAN_METHOD(OpenVirtualPort) { NanScope(); NodeMidiOutput* output = node::ObjectWrap::Unwrap<NodeMidiOutput>(args.This()); if (args.Length() == 0 || !args[0]->IsString()) { return NanThrowTypeError("First argument must be a string"); } std::string name(*NanAsciiString(args[0])); output->out->openVirtualPort(name); NanReturnUndefined(); }
void EIO_AfterWrite(uv_work_t* req) { NanScope(); QueuedWrite* queuedWrite = static_cast<QueuedWrite*>(req->data); WriteBaton* data = static_cast<WriteBaton*>(queuedWrite->baton); v8::Handle<v8::Value> argv[2]; if(data->errorString[0]) { argv[0] = v8::Exception::Error(NanNew<v8::String>(data->errorString)); argv[1] = NanUndefined(); } else { argv[0] = NanUndefined(); argv[1] = NanNew<v8::Int32>(data->result); } data->callback->Call(2, argv); if (data->offset < data->bufferLength && !data->errorString[0]) { // We're not done with this baton, so throw it right back onto the queue. // Don't re-push the write in the event loop if there was an error; because same error could occur again! // TODO: Add a uv_poll here for unix... //fprintf(stderr, "Write again...\n"); uv_queue_work(uv_default_loop(), req, EIO_Write, (uv_after_work_cb)EIO_AfterWrite); return; } int fd = data->fd; _WriteQueue *q = qForFD(fd); if(!q) { NanThrowTypeError("There's no write queue for that file descriptor (after write)!"); return; } q->lock(); QueuedWrite &write_queue = q->get(); // remove this one from the list queuedWrite->remove(); // If there are any left, start a new thread to write the next one. if (!write_queue.empty()) { // Always pull the next work item from the head of the queue QueuedWrite* nextQueuedWrite = write_queue.next; uv_queue_work(uv_default_loop(), &nextQueuedWrite->req, EIO_Write, (uv_after_work_cb)EIO_AfterWrite); } q->unlock(); NanDisposePersistent(data->buffer); delete data->callback; delete data; delete queuedWrite; }
static NAN_METHOD(IgnoreTypes) { NanScope(); NodeMidiInput* input = node::ObjectWrap::Unwrap<NodeMidiInput>(args.This()); if (args.Length() != 3 || !args[0]->IsBoolean() || !args[1]->IsBoolean() || !args[2]->IsBoolean()) { return NanThrowTypeError("Arguments must be boolean"); } bool filter_sysex = args[0]->BooleanValue(); bool filter_timing = args[1]->BooleanValue(); bool filter_sensing = args[2]->BooleanValue(); input->in->ignoreTypes(filter_sysex, filter_timing, filter_sensing); NanReturnUndefined(); }
static NAN_METHOD(OpenPort) { NanScope(); NodeMidiOutput* output = node::ObjectWrap::Unwrap<NodeMidiOutput>(args.This()); if (args.Length() == 0 || !args[0]->IsUint32()) { return NanThrowTypeError("First argument must be an integer"); } unsigned int portNumber = args[0]->Uint32Value(); if (portNumber >= output->out->getPortCount()) { return NanThrowRangeError("Invalid MIDI port number"); } output->out->openPort(portNumber); NanReturnUndefined(); }
static NAN_METHOD(New) { NanScope(); if (!args.IsConstructCall()) { return NanThrowTypeError("Use the new operator to create instances of this object."); } NodeMidiInput* input = new NodeMidiInput(); input->message_async.data = input; uv_async_init(uv_default_loop(), &input->message_async, NodeMidiInput::EmitMessage); input->Wrap(args.This()); NanReturnValue(args.This()); }
static inline NAN_METHOD(register_datasource) { NanScope(); if (args.Length() != 1 || !args[0]->IsString()) { NanThrowTypeError("first argument must be a path to a mapnik input plugin (.input)"); NanReturnUndefined(); } std::vector<std::string> names_before = mapnik::datasource_cache::instance().plugin_names(); std::string path = TOSTR(args[0]); mapnik::datasource_cache::instance().register_datasource(path); std::vector<std::string> names_after = mapnik::datasource_cache::instance().plugin_names(); if (names_after.size() > names_before.size()) NanReturnValue(NanTrue()); NanReturnValue(NanFalse()); }
static NAN_METHOD(SendMessage) { NanScope(); NodeMidiOutput* output = node::ObjectWrap::Unwrap<NodeMidiOutput>(args.This()); if (args.Length() == 0 || !args[0]->IsArray()) { return NanThrowTypeError("First argument must be an array"); } v8::Local<v8::Object> message = args[0]->ToObject(); int32_t messageLength = message->Get(NanNew<v8::String>("length"))->Int32Value(); std::vector<unsigned char> messageOutput; for (int32_t i = 0; i != messageLength; ++i) { messageOutput.push_back(message->Get(NanNew<v8::Integer>(i))->Int32Value()); } output->out->sendMessage(&messageOutput); NanReturnUndefined(); }