LCOV - code coverage report
Current view: top level - node/ext - node_grpc.cc (source / functions) Hit Total Coverage
Test: tmp.CaZ6RjdVn2 Lines: 110 110 100.0 %
Date: 2015-12-10 22:15:08 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2015, Google Inc.
       4             :  * All rights reserved.
       5             :  *
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions are
       8             :  * met:
       9             :  *
      10             :  *     * Redistributions of source code must retain the above copyright
      11             :  * notice, this list of conditions and the following disclaimer.
      12             :  *     * Redistributions in binary form must reproduce the above
      13             :  * copyright notice, this list of conditions and the following disclaimer
      14             :  * in the documentation and/or other materials provided with the
      15             :  * distribution.
      16             :  *     * Neither the name of Google Inc. nor the names of its
      17             :  * contributors may be used to endorse or promote products derived from
      18             :  * this software without specific prior written permission.
      19             :  *
      20             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      21             :  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      22             :  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      23             :  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      24             :  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      25             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      26             :  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      27             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      28             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      29             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      30             :  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      31             :  *
      32             :  */
      33             : 
      34             : #include <node.h>
      35             : #include <nan.h>
      36             : #include <v8.h>
      37             : #include "grpc/grpc.h"
      38             : 
      39             : #include "call.h"
      40             : #include "call_credentials.h"
      41             : #include "channel.h"
      42             : #include "channel_credentials.h"
      43             : #include "server.h"
      44             : #include "completion_queue_async_worker.h"
      45             : #include "server_credentials.h"
      46             : 
      47             : using v8::Local;
      48             : using v8::Value;
      49             : using v8::Object;
      50             : using v8::Uint32;
      51             : using v8::String;
      52             : 
      53           1 : void InitStatusConstants(Local<Object> exports) {
      54             :   Nan::HandleScope scope;
      55           1 :   Local<Object> status = Nan::New<Object>();
      56           2 :   Nan::Set(exports, Nan::New("status").ToLocalChecked(), status);
      57             :   Local<Value> OK(Nan::New<Uint32, uint32_t>(GRPC_STATUS_OK));
      58           2 :   Nan::Set(status, Nan::New("OK").ToLocalChecked(), OK);
      59             :   Local<Value> CANCELLED(Nan::New<Uint32, uint32_t>(GRPC_STATUS_CANCELLED));
      60           2 :   Nan::Set(status, Nan::New("CANCELLED").ToLocalChecked(), CANCELLED);
      61             :   Local<Value> UNKNOWN(Nan::New<Uint32, uint32_t>(GRPC_STATUS_UNKNOWN));
      62           2 :   Nan::Set(status, Nan::New("UNKNOWN").ToLocalChecked(), UNKNOWN);
      63             :   Local<Value> INVALID_ARGUMENT(
      64             :       Nan::New<Uint32, uint32_t>(GRPC_STATUS_INVALID_ARGUMENT));
      65           2 :   Nan::Set(status, Nan::New("INVALID_ARGUMENT").ToLocalChecked(),
      66           1 :            INVALID_ARGUMENT);
      67             :   Local<Value> DEADLINE_EXCEEDED(
      68             :       Nan::New<Uint32, uint32_t>(GRPC_STATUS_DEADLINE_EXCEEDED));
      69           2 :   Nan::Set(status, Nan::New("DEADLINE_EXCEEDED").ToLocalChecked(),
      70           1 :            DEADLINE_EXCEEDED);
      71             :   Local<Value> NOT_FOUND(Nan::New<Uint32, uint32_t>(GRPC_STATUS_NOT_FOUND));
      72           2 :   Nan::Set(status, Nan::New("NOT_FOUND").ToLocalChecked(), NOT_FOUND);
      73             :   Local<Value> ALREADY_EXISTS(
      74             :       Nan::New<Uint32, uint32_t>(GRPC_STATUS_ALREADY_EXISTS));
      75           2 :   Nan::Set(status, Nan::New("ALREADY_EXISTS").ToLocalChecked(), ALREADY_EXISTS);
      76             :   Local<Value> PERMISSION_DENIED(
      77             :       Nan::New<Uint32, uint32_t>(GRPC_STATUS_PERMISSION_DENIED));
      78           2 :   Nan::Set(status, Nan::New("PERMISSION_DENIED").ToLocalChecked(),
      79           1 :            PERMISSION_DENIED);
      80             :   Local<Value> UNAUTHENTICATED(
      81             :       Nan::New<Uint32, uint32_t>(GRPC_STATUS_UNAUTHENTICATED));
      82           2 :   Nan::Set(status, Nan::New("UNAUTHENTICATED").ToLocalChecked(),
      83           1 :            UNAUTHENTICATED);
      84             :   Local<Value> RESOURCE_EXHAUSTED(
      85             :       Nan::New<Uint32, uint32_t>(GRPC_STATUS_RESOURCE_EXHAUSTED));
      86           2 :   Nan::Set(status, Nan::New("RESOURCE_EXHAUSTED").ToLocalChecked(),
      87           1 :            RESOURCE_EXHAUSTED);
      88             :   Local<Value> FAILED_PRECONDITION(
      89             :       Nan::New<Uint32, uint32_t>(GRPC_STATUS_FAILED_PRECONDITION));
      90           2 :   Nan::Set(status, Nan::New("FAILED_PRECONDITION").ToLocalChecked(),
      91           1 :            FAILED_PRECONDITION);
      92             :   Local<Value> ABORTED(Nan::New<Uint32, uint32_t>(GRPC_STATUS_ABORTED));
      93           2 :   Nan::Set(status, Nan::New("ABORTED").ToLocalChecked(), ABORTED);
      94             :   Local<Value> OUT_OF_RANGE(
      95             :       Nan::New<Uint32, uint32_t>(GRPC_STATUS_OUT_OF_RANGE));
      96           2 :   Nan::Set(status, Nan::New("OUT_OF_RANGE").ToLocalChecked(), OUT_OF_RANGE);
      97             :   Local<Value> UNIMPLEMENTED(
      98             :       Nan::New<Uint32, uint32_t>(GRPC_STATUS_UNIMPLEMENTED));
      99           2 :   Nan::Set(status, Nan::New("UNIMPLEMENTED").ToLocalChecked(), UNIMPLEMENTED);
     100             :   Local<Value> INTERNAL(Nan::New<Uint32, uint32_t>(GRPC_STATUS_INTERNAL));
     101           2 :   Nan::Set(status, Nan::New("INTERNAL").ToLocalChecked(), INTERNAL);
     102             :   Local<Value> UNAVAILABLE(Nan::New<Uint32, uint32_t>(GRPC_STATUS_UNAVAILABLE));
     103           2 :   Nan::Set(status, Nan::New("UNAVAILABLE").ToLocalChecked(), UNAVAILABLE);
     104             :   Local<Value> DATA_LOSS(Nan::New<Uint32, uint32_t>(GRPC_STATUS_DATA_LOSS));
     105           2 :   Nan::Set(status, Nan::New("DATA_LOSS").ToLocalChecked(), DATA_LOSS);
     106           1 : }
     107             : 
     108           1 : void InitCallErrorConstants(Local<Object> exports) {
     109             :   Nan::HandleScope scope;
     110           1 :   Local<Object> call_error = Nan::New<Object>();
     111           2 :   Nan::Set(exports, Nan::New("callError").ToLocalChecked(), call_error);
     112             :   Local<Value> OK(Nan::New<Uint32, uint32_t>(GRPC_CALL_OK));
     113           2 :   Nan::Set(call_error, Nan::New("OK").ToLocalChecked(), OK);
     114             :   Local<Value> ERROR(Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR));
     115           2 :   Nan::Set(call_error, Nan::New("ERROR").ToLocalChecked(), ERROR);
     116             :   Local<Value> NOT_ON_SERVER(
     117             :       Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_NOT_ON_SERVER));
     118           2 :   Nan::Set(call_error, Nan::New("NOT_ON_SERVER").ToLocalChecked(),
     119           1 :            NOT_ON_SERVER);
     120             :   Local<Value> NOT_ON_CLIENT(
     121             :       Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_NOT_ON_CLIENT));
     122           2 :   Nan::Set(call_error, Nan::New("NOT_ON_CLIENT").ToLocalChecked(),
     123           1 :            NOT_ON_CLIENT);
     124             :   Local<Value> ALREADY_INVOKED(
     125             :       Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_ALREADY_INVOKED));
     126           2 :   Nan::Set(call_error, Nan::New("ALREADY_INVOKED").ToLocalChecked(),
     127           1 :            ALREADY_INVOKED);
     128             :   Local<Value> NOT_INVOKED(
     129             :       Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_NOT_INVOKED));
     130           2 :   Nan::Set(call_error, Nan::New("NOT_INVOKED").ToLocalChecked(), NOT_INVOKED);
     131             :   Local<Value> ALREADY_FINISHED(
     132             :       Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_ALREADY_FINISHED));
     133           2 :   Nan::Set(call_error, Nan::New("ALREADY_FINISHED").ToLocalChecked(),
     134           1 :            ALREADY_FINISHED);
     135             :   Local<Value> TOO_MANY_OPERATIONS(
     136             :       Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS));
     137           2 :   Nan::Set(call_error, Nan::New("TOO_MANY_OPERATIONS").ToLocalChecked(),
     138           1 :            TOO_MANY_OPERATIONS);
     139             :   Local<Value> INVALID_FLAGS(
     140             :       Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_INVALID_FLAGS));
     141           2 :   Nan::Set(call_error, Nan::New("INVALID_FLAGS").ToLocalChecked(),
     142           1 :            INVALID_FLAGS);
     143           1 : }
     144             : 
     145           1 : void InitOpTypeConstants(Local<Object> exports) {
     146             :   Nan::HandleScope scope;
     147           1 :   Local<Object> op_type = Nan::New<Object>();
     148           2 :   Nan::Set(exports, Nan::New("opType").ToLocalChecked(), op_type);
     149             :   Local<Value> SEND_INITIAL_METADATA(
     150             :       Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_INITIAL_METADATA));
     151           2 :   Nan::Set(op_type, Nan::New("SEND_INITIAL_METADATA").ToLocalChecked(),
     152           1 :            SEND_INITIAL_METADATA);
     153             :   Local<Value> SEND_MESSAGE(
     154             :       Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_MESSAGE));
     155           2 :   Nan::Set(op_type, Nan::New("SEND_MESSAGE").ToLocalChecked(), SEND_MESSAGE);
     156             :   Local<Value> SEND_CLOSE_FROM_CLIENT(
     157             :       Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_CLOSE_FROM_CLIENT));
     158           2 :   Nan::Set(op_type, Nan::New("SEND_CLOSE_FROM_CLIENT").ToLocalChecked(),
     159           1 :            SEND_CLOSE_FROM_CLIENT);
     160             :   Local<Value> SEND_STATUS_FROM_SERVER(
     161             :       Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_STATUS_FROM_SERVER));
     162           2 :   Nan::Set(op_type, Nan::New("SEND_STATUS_FROM_SERVER").ToLocalChecked(),
     163           1 :            SEND_STATUS_FROM_SERVER);
     164             :   Local<Value> RECV_INITIAL_METADATA(
     165             :       Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_INITIAL_METADATA));
     166           2 :   Nan::Set(op_type, Nan::New("RECV_INITIAL_METADATA").ToLocalChecked(),
     167           1 :            RECV_INITIAL_METADATA);
     168             :   Local<Value> RECV_MESSAGE(
     169             :       Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_MESSAGE));
     170           2 :   Nan::Set(op_type, Nan::New("RECV_MESSAGE").ToLocalChecked(), RECV_MESSAGE);
     171             :   Local<Value> RECV_STATUS_ON_CLIENT(
     172             :       Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_STATUS_ON_CLIENT));
     173           2 :   Nan::Set(op_type, Nan::New("RECV_STATUS_ON_CLIENT").ToLocalChecked(),
     174           1 :            RECV_STATUS_ON_CLIENT);
     175             :   Local<Value> RECV_CLOSE_ON_SERVER(
     176             :       Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_CLOSE_ON_SERVER));
     177           2 :   Nan::Set(op_type, Nan::New("RECV_CLOSE_ON_SERVER").ToLocalChecked(),
     178           1 :            RECV_CLOSE_ON_SERVER);
     179           1 : }
     180             : 
     181           1 : void InitPropagateConstants(Local<Object> exports) {
     182             :   Nan::HandleScope scope;
     183           1 :   Local<Object> propagate = Nan::New<Object>();
     184           2 :   Nan::Set(exports, Nan::New("propagate").ToLocalChecked(), propagate);
     185             :   Local<Value> DEADLINE(Nan::New<Uint32, uint32_t>(GRPC_PROPAGATE_DEADLINE));
     186           2 :   Nan::Set(propagate, Nan::New("DEADLINE").ToLocalChecked(), DEADLINE);
     187             :   Local<Value> CENSUS_STATS_CONTEXT(
     188             :       Nan::New<Uint32, uint32_t>(GRPC_PROPAGATE_CENSUS_STATS_CONTEXT));
     189           2 :   Nan::Set(propagate, Nan::New("CENSUS_STATS_CONTEXT").ToLocalChecked(),
     190           1 :            CENSUS_STATS_CONTEXT);
     191             :   Local<Value> CENSUS_TRACING_CONTEXT(
     192             :       Nan::New<Uint32, uint32_t>(GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT));
     193           2 :   Nan::Set(propagate, Nan::New("CENSUS_TRACING_CONTEXT").ToLocalChecked(),
     194           1 :            CENSUS_TRACING_CONTEXT);
     195             :   Local<Value> CANCELLATION(
     196             :       Nan::New<Uint32, uint32_t>(GRPC_PROPAGATE_CANCELLATION));
     197           2 :   Nan::Set(propagate, Nan::New("CANCELLATION").ToLocalChecked(), CANCELLATION);
     198             :   Local<Value> DEFAULTS(Nan::New<Uint32, uint32_t>(GRPC_PROPAGATE_DEFAULTS));
     199           2 :   Nan::Set(propagate, Nan::New("DEFAULTS").ToLocalChecked(), DEFAULTS);
     200           1 : }
     201             : 
     202           1 : void InitConnectivityStateConstants(Local<Object> exports) {
     203             :   Nan::HandleScope scope;
     204           1 :   Local<Object> channel_state = Nan::New<Object>();
     205           1 :   Nan::Set(exports, Nan::New("connectivityState").ToLocalChecked(),
     206           2 :            channel_state);
     207             :   Local<Value> IDLE(Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_IDLE));
     208           2 :   Nan::Set(channel_state, Nan::New("IDLE").ToLocalChecked(), IDLE);
     209             :   Local<Value> CONNECTING(Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_CONNECTING));
     210           2 :   Nan::Set(channel_state, Nan::New("CONNECTING").ToLocalChecked(), CONNECTING);
     211             :   Local<Value> READY(Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_READY));
     212           2 :   Nan::Set(channel_state, Nan::New("READY").ToLocalChecked(), READY);
     213             :   Local<Value> TRANSIENT_FAILURE(
     214             :       Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_TRANSIENT_FAILURE));
     215           2 :   Nan::Set(channel_state, Nan::New("TRANSIENT_FAILURE").ToLocalChecked(),
     216           1 :            TRANSIENT_FAILURE);
     217             :   Local<Value> FATAL_FAILURE(
     218             :       Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_FATAL_FAILURE));
     219           2 :   Nan::Set(channel_state, Nan::New("FATAL_FAILURE").ToLocalChecked(),
     220           1 :            FATAL_FAILURE);
     221           1 : }
     222             : 
     223           1 : void InitWriteFlags(Local<Object> exports) {
     224             :   Nan::HandleScope scope;
     225           1 :   Local<Object> write_flags = Nan::New<Object>();
     226           2 :   Nan::Set(exports, Nan::New("writeFlags").ToLocalChecked(), write_flags);
     227             :   Local<Value> BUFFER_HINT(Nan::New<Uint32, uint32_t>(GRPC_WRITE_BUFFER_HINT));
     228           2 :   Nan::Set(write_flags, Nan::New("BUFFER_HINT").ToLocalChecked(), BUFFER_HINT);
     229             :   Local<Value> NO_COMPRESS(Nan::New<Uint32, uint32_t>(GRPC_WRITE_NO_COMPRESS));
     230           2 :   Nan::Set(write_flags, Nan::New("NO_COMPRESS").ToLocalChecked(), NO_COMPRESS);
     231           1 : }
     232             : 
     233           1 : void init(Local<Object> exports) {
     234             :   Nan::HandleScope scope;
     235           1 :   grpc_init();
     236           1 :   InitStatusConstants(exports);
     237           1 :   InitCallErrorConstants(exports);
     238           1 :   InitOpTypeConstants(exports);
     239           1 :   InitPropagateConstants(exports);
     240           1 :   InitConnectivityStateConstants(exports);
     241           1 :   InitWriteFlags(exports);
     242             : 
     243           1 :   grpc::node::Call::Init(exports);
     244           1 :   grpc::node::CallCredentials::Init(exports);
     245           1 :   grpc::node::Channel::Init(exports);
     246           1 :   grpc::node::ChannelCredentials::Init(exports);
     247           1 :   grpc::node::Server::Init(exports);
     248           1 :   grpc::node::CompletionQueueAsyncWorker::Init(exports);
     249           1 :   grpc::node::ServerCredentials::Init(exports);
     250           1 : }
     251             : 
     252           1 : NODE_MODULE(grpc_node, init)

Generated by: LCOV version 1.11