blob: 9ec28e15af04accf6499c800abd56947a417b513 [file] [log] [blame]
murgatroid99749666e2015-01-12 18:25:58 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
murgatroid99749666e2015-01-12 18:25:58 -08004 * 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
murgatroid99e5061512015-01-12 18:14:35 -080034#ifndef NET_GRPC_NODE_CHANNEL_H_
35#define NET_GRPC_NODE_CHANNEL_H_
36
37#include <node.h>
38#include <nan.h>
39#include "grpc/grpc.h"
40
41namespace grpc {
42namespace node {
43
murgatroid9975a2bba2015-10-12 16:12:04 -070044bool ParseChannelArgs(v8::Local<v8::Value> args_val,
45 grpc_channel_args **channel_args_ptr);
46
47void DeallocateChannelArgs(grpc_channel_args *channel_args);
48
murgatroid99e5061512015-01-12 18:14:35 -080049/* Wrapper class for grpc_channel structs */
murgatroid992b097832015-09-17 13:56:25 -070050class Channel : public Nan::ObjectWrap {
murgatroid99e5061512015-01-12 18:14:35 -080051 public:
murgatroid992b097832015-09-17 13:56:25 -070052 static void Init(v8::Local<v8::Object> exports);
53 static bool HasInstance(v8::Local<v8::Value> val);
murgatroid99e5061512015-01-12 18:14:35 -080054 /* This is used to typecheck javascript objects before converting them to
55 this type */
56 static v8::Persistent<v8::Value> prototype;
57
58 /* Returns the grpc_channel struct that this object wraps */
59 grpc_channel *GetWrappedChannel();
60
murgatroid99e5061512015-01-12 18:14:35 -080061 private:
murgatroid993f507d02015-08-03 15:17:53 -070062 explicit Channel(grpc_channel *channel);
murgatroid99e5061512015-01-12 18:14:35 -080063 ~Channel();
64
65 // Prevent copying
Craig Tillere8e304e2015-01-13 14:41:29 -080066 Channel(const Channel &);
67 Channel &operator=(const Channel &);
murgatroid99e5061512015-01-12 18:14:35 -080068
69 static NAN_METHOD(New);
70 static NAN_METHOD(Close);
murgatroid99ea12b972015-07-24 10:43:27 -070071 static NAN_METHOD(GetTarget);
murgatroid99c7f4d4f2015-07-28 15:18:57 -070072 static NAN_METHOD(GetConnectivityState);
73 static NAN_METHOD(WatchConnectivityState);
murgatroid992b097832015-09-17 13:56:25 -070074 static Nan::Callback *constructor;
75 static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
murgatroid99e5061512015-01-12 18:14:35 -080076
77 grpc_channel *wrapped_channel;
murgatroid99e5061512015-01-12 18:14:35 -080078};
79
80} // namespace node
81} // namespace grpc
82
Craig Tiller190d3602015-02-18 09:23:38 -080083#endif // NET_GRPC_NODE_CHANNEL_H_