aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/channel.h
blob: fbfb83874c2522507f2d41d19c56881ced2cd5c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef NET_GRPC_NODE_CHANNEL_H_
#define NET_GRPC_NODE_CHANNEL_H_

#include <node.h>
#include <nan.h>
#include "grpc/grpc.h"

namespace grpc {
namespace node {

/* Wrapper class for grpc_channel structs */
class Channel : public ::node::ObjectWrap {
 public:
  static void Init(v8::Handle<v8::Object> exports);
  static bool HasInstance(v8::Handle<v8::Value> val);
  /* This is used to typecheck javascript objects before converting them to
     this type */
  static v8::Persistent<v8::Value> prototype;

  /* Returns the grpc_channel struct that this object wraps */
  grpc_channel *GetWrappedChannel();

  /* Return the hostname that this channel connects to */
  char *GetHost();

 private:
  explicit Channel(grpc_channel *channel, NanUtf8String *host);
  ~Channel();

  // Prevent copying
  Channel(const Channel&);
  Channel& operator=(const Channel&);

  static NAN_METHOD(New);
  static NAN_METHOD(Close);
  static v8::Persistent<v8::Function> constructor;
  static v8::Persistent<v8::FunctionTemplate> fun_tpl;

  grpc_channel *wrapped_channel;
  NanUtf8String *host;
};

}  // namespace node
}  // namespace grpc

#endif  // NET_GRPC_NODE_CHANNEL_H_