/* * * Copyright 2015, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include #include #include #include "grpc/grpc.h" #include "call.h" #include "channel.h" #include "server.h" #include "completion_queue_async_worker.h" #include "credentials.h" #include "server_credentials.h" using v8::Handle; using v8::Value; using v8::Object; using v8::Uint32; using v8::String; void InitStatusConstants(Handle exports) { NanScope(); Handle status = Object::New(); exports->Set(NanNew("status"), status); Handle OK(NanNew(GRPC_STATUS_OK)); status->Set(NanNew("OK"), OK); Handle CANCELLED(NanNew(GRPC_STATUS_CANCELLED)); status->Set(NanNew("CANCELLED"), CANCELLED); Handle UNKNOWN(NanNew(GRPC_STATUS_UNKNOWN)); status->Set(NanNew("UNKNOWN"), UNKNOWN); Handle INVALID_ARGUMENT( NanNew(GRPC_STATUS_INVALID_ARGUMENT)); status->Set(NanNew("INVALID_ARGUMENT"), INVALID_ARGUMENT); Handle DEADLINE_EXCEEDED( NanNew(GRPC_STATUS_DEADLINE_EXCEEDED)); status->Set(NanNew("DEADLINE_EXCEEDED"), DEADLINE_EXCEEDED); Handle NOT_FOUND(NanNew(GRPC_STATUS_NOT_FOUND)); status->Set(NanNew("NOT_FOUND"), NOT_FOUND); Handle ALREADY_EXISTS( NanNew(GRPC_STATUS_ALREADY_EXISTS)); status->Set(NanNew("ALREADY_EXISTS"), ALREADY_EXISTS); Handle PERMISSION_DENIED( NanNew(GRPC_STATUS_PERMISSION_DENIED)); status->Set(NanNew("PERMISSION_DENIED"), PERMISSION_DENIED); Handle UNAUTHENTICATED( NanNew(GRPC_STATUS_UNAUTHENTICATED)); status->Set(NanNew("UNAUTHENTICATED"), UNAUTHENTICATED); Handle RESOURCE_EXHAUSTED( NanNew(GRPC_STATUS_RESOURCE_EXHAUSTED)); status->Set(NanNew("RESOURCE_EXHAUSTED"), RESOURCE_EXHAUSTED); Handle FAILED_PRECONDITION( NanNew(GRPC_STATUS_FAILED_PRECONDITION)); status->Set(NanNew("FAILED_PRECONDITION"), FAILED_PRECONDITION); Handle ABORTED(NanNew(GRPC_STATUS_ABORTED)); status->Set(NanNew("ABORTED"), ABORTED); Handle OUT_OF_RANGE( NanNew(GRPC_STATUS_OUT_OF_RANGE)); status->Set(NanNew("OUT_OF_RANGE"), OUT_OF_RANGE); Handle UNIMPLEMENTED( NanNew(GRPC_STATUS_UNIMPLEMENTED)); status->Set(NanNew("UNIMPLEMENTED"), UNIMPLEMENTED); Handle INTERNAL(NanNew(GRPC_STATUS_INTERNAL)); status->Set(NanNew("INTERNAL"), INTERNAL); Handle UNAVAILABLE(NanNew(GRPC_STATUS_UNAVAILABLE)); status->Set(NanNew("UNAVAILABLE"), UNAVAILABLE); Handle DATA_LOSS(NanNew(GRPC_STATUS_DATA_LOSS)); status->Set(NanNew("DATA_LOSS"), DATA_LOSS); } void InitCallErrorConstants(Handle exports) { NanScope(); Handle call_error = Object::New(); exports->Set(NanNew("callError"), call_error); Handle OK(NanNew(GRPC_CALL_OK)); call_error->Set(NanNew("OK"), OK); Handle ERROR(NanNew(GRPC_CALL_ERROR)); call_error->Set(NanNew("ERROR"), ERROR); Handle NOT_ON_SERVER( NanNew(GRPC_CALL_ERROR_NOT_ON_SERVER)); call_error->Set(NanNew("NOT_ON_SERVER"), NOT_ON_SERVER); Handle NOT_ON_CLIENT( NanNew(GRPC_CALL_ERROR_NOT_ON_CLIENT)); call_error->Set(NanNew("NOT_ON_CLIENT"), NOT_ON_CLIENT); Handle ALREADY_INVOKED( NanNew(GRPC_CALL_ERROR_ALREADY_INVOKED)); call_error->Set(NanNew("ALREADY_INVOKED"), ALREADY_INVOKED); Handle NOT_INVOKED( NanNew(GRPC_CALL_ERROR_NOT_INVOKED)); call_error->Set(NanNew("NOT_INVOKED"), NOT_INVOKED); Handle ALREADY_FINISHED( NanNew(GRPC_CALL_ERROR_ALREADY_FINISHED)); call_error->Set(NanNew("ALREADY_FINISHED"), ALREADY_FINISHED); Handle TOO_MANY_OPERATIONS( NanNew(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS)); call_error->Set(NanNew("TOO_MANY_OPERATIONS"), TOO_MANY_OPERATIONS); Handle INVALID_FLAGS( NanNew(GRPC_CALL_ERROR_INVALID_FLAGS)); call_error->Set(NanNew("INVALID_FLAGS"), INVALID_FLAGS); } void InitOpTypeConstants(Handle exports) { NanScope(); Handle op_type = Object::New(); exports->Set(NanNew("opType"), op_type); Handle SEND_INITIAL_METADATA( NanNew(GRPC_OP_SEND_INITIAL_METADATA)); op_type->Set(NanNew("SEND_INITIAL_METADATA"), SEND_INITIAL_METADATA); Handle SEND_MESSAGE( NanNew(GRPC_OP_SEND_MESSAGE)); op_type->Set(NanNew("SEND_MESSAGE"), SEND_MESSAGE); Handle SEND_CLOSE_FROM_CLIENT( NanNew(GRPC_OP_SEND_CLOSE_FROM_CLIENT)); op_type->Set(NanNew("SEND_CLOSE_FROM_CLIENT"), SEND_CLOSE_FROM_CLIENT); Handle SEND_STATUS_FROM_SERVER( NanNew(GRPC_OP_SEND_STATUS_FROM_SERVER)); op_type->Set(NanNew("SEND_STATUS_FROM_SERVER"), SEND_STATUS_FROM_SERVER); Handle RECV_INITIAL_METADATA( NanNew(GRPC_OP_RECV_INITIAL_METADATA)); op_type->Set(NanNew("RECV_INITIAL_METADATA"), RECV_INITIAL_METADATA); Handle RECV_MESSAGE( NanNew(GRPC_OP_RECV_MESSAGE)); op_type->Set(NanNew("RECV_MESSAGE"), RECV_MESSAGE); Handle RECV_STATUS_ON_CLIENT( NanNew(GRPC_OP_RECV_STATUS_ON_CLIENT)); op_type->Set(NanNew("RECV_STATUS_ON_CLIENT"), RECV_STATUS_ON_CLIENT); Handle RECV_CLOSE_ON_SERVER( NanNew(GRPC_OP_RECV_CLOSE_ON_SERVER)); op_type->Set(NanNew("RECV_CLOSE_ON_SERVER"), RECV_CLOSE_ON_SERVER); } void init(Handle exports) { NanScope(); grpc_init(); InitStatusConstants(exports); InitCallErrorConstants(exports); InitOpTypeConstants(exports); grpc::node::Call::Init(exports); grpc::node::Channel::Init(exports); grpc::node::Server::Init(exports); grpc::node::CompletionQueueAsyncWorker::Init(exports); grpc::node::Credentials::Init(exports); grpc::node::ServerCredentials::Init(exports); } NODE_MODULE(grpc, init)