aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/ext
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-07-24 10:43:27 -0700
committerGravatar murgatroid99 <mlumish@google.com>2015-07-24 10:43:27 -0700
commitea12b97243f95d1830a9f70c3c176b82ef37cb04 (patch)
tree53e4b2cfc5efed35772ae31f288f939aea90449a /src/node/ext
parent2e7ce156354f77bcbdfe0c096b6fa29ebe320200 (diff)
Exposed channel target and call peer in Node wrapper
Diffstat (limited to 'src/node/ext')
-rw-r--r--src/node/ext/call.cc14
-rw-r--r--src/node/ext/call.h1
-rw-r--r--src/node/ext/channel.cc11
-rw-r--r--src/node/ext/channel.h1
4 files changed, 27 insertions, 0 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc
index 15c9b2d97d..b647735ead 100644
--- a/src/node/ext/call.cc
+++ b/src/node/ext/call.cc
@@ -453,6 +453,8 @@ void Call::Init(Handle<Object> exports) {
NanNew<FunctionTemplate>(StartBatch)->GetFunction());
NanSetPrototypeTemplate(tpl, "cancel",
NanNew<FunctionTemplate>(Cancel)->GetFunction());
+ NanSetPrototypeTemplate(tpl, "getPeer",
+ NanNew<FunctionTemplate>(GetPeer)->GetFunction());
NanAssignPersistent(fun_tpl, tpl);
Handle<Function> ctr = tpl->GetFunction();
ctr->Set(NanNew("WRITE_BUFFER_HINT"),
@@ -608,5 +610,17 @@ NAN_METHOD(Call::Cancel) {
NanReturnUndefined();
}
+NAN_METHOD(Call::GetPeer) {
+ NanScope();
+ if (!HasInstance(args.This())) {
+ return NanThrowTypeError("getPeer can only be called on Call objects");
+ }
+ Call *call = ObjectWrap::Unwrap<Call>(args.This());
+ char *peer = grpc_call_get_peer(call->wrapped_call);
+ Handle<Value> peer_value = NanNew(peer);
+ gpr_free(peer);
+ NanReturnValue(peer_value);
+}
+
} // namespace node
} // namespace grpc
diff --git a/src/node/ext/call.h b/src/node/ext/call.h
index 43142c7091..6acda76197 100644
--- a/src/node/ext/call.h
+++ b/src/node/ext/call.h
@@ -120,6 +120,7 @@ class Call : public ::node::ObjectWrap {
static NAN_METHOD(New);
static NAN_METHOD(StartBatch);
static NAN_METHOD(Cancel);
+ static NAN_METHOD(GetPeer);
static NanCallback *constructor;
// Used for typechecking instances of this javascript class
static v8::Persistent<v8::FunctionTemplate> fun_tpl;
diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc
index d37bf763dd..0b7333e450 100644
--- a/src/node/ext/channel.cc
+++ b/src/node/ext/channel.cc
@@ -76,6 +76,8 @@ void Channel::Init(Handle<Object> exports) {
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NanSetPrototypeTemplate(tpl, "close",
NanNew<FunctionTemplate>(Close)->GetFunction());
+ NanSetPrototypeTemplate(tpl, "getTarget",
+ NanNew<FunctionTemplate>(GetTarget)->GetFunction());
NanAssignPersistent(fun_tpl, tpl);
Handle<Function> ctr = tpl->GetFunction();
constructor = new NanCallback(ctr);
@@ -185,5 +187,14 @@ NAN_METHOD(Channel::Close) {
NanReturnUndefined();
}
+NAN_METHOD(Channel::GetTarget) {
+ NanScope();
+ if (!HasInstance(args.This())) {
+ return NanThrowTypeError("getTarget can only be called on Channel objects");
+ }
+ Channel *channel = ObjectWrap::Unwrap<Channel>(args.This());
+ NanReturnValue(NanNew(grpc_channel_get_target(channel->wrapped_channel)));
+}
+
} // namespace node
} // namespace grpc
diff --git a/src/node/ext/channel.h b/src/node/ext/channel.h
index b3aa0f700f..6725ebb03f 100644
--- a/src/node/ext/channel.h
+++ b/src/node/ext/channel.h
@@ -66,6 +66,7 @@ class Channel : public ::node::ObjectWrap {
static NAN_METHOD(New);
static NAN_METHOD(Close);
+ static NAN_METHOD(GetTarget);
static NanCallback *constructor;
static v8::Persistent<v8::FunctionTemplate> fun_tpl;