mirror of https://github.com/grpc/grpc.git
parent
1578c6a4ab
commit
63056a694d
4 changed files with 0 additions and 618 deletions
@ -1,173 +0,0 @@ |
||||
/*
|
||||
* |
||||
* 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 <map> |
||||
|
||||
#include <node.h> |
||||
#include <nan.h> |
||||
#include "grpc/grpc.h" |
||||
#include "byte_buffer.h" |
||||
#include "call.h" |
||||
#include "event.h" |
||||
#include "tag.h" |
||||
#include "timeval.h" |
||||
|
||||
namespace grpc { |
||||
namespace node { |
||||
|
||||
using ::node::Buffer; |
||||
using v8::Array; |
||||
using v8::Date; |
||||
using v8::Handle; |
||||
using v8::HandleScope; |
||||
using v8::Number; |
||||
using v8::Object; |
||||
using v8::Persistent; |
||||
using v8::String; |
||||
using v8::Value; |
||||
|
||||
Handle<Value> ParseMetadata(grpc_metadata *metadata_elements, size_t length) { |
||||
NanEscapableScope(); |
||||
std::map<const char*, size_t> size_map; |
||||
std::map<const char*, size_t> index_map; |
||||
|
||||
for (unsigned int i = 0; i < length; i++) { |
||||
const char *key = metadata_elements[i].key; |
||||
if (size_map.count(key)) { |
||||
size_map[key] += 1; |
||||
} |
||||
index_map[key] = 0; |
||||
} |
||||
Handle<Object> metadata_object = NanNew<Object>(); |
||||
for (unsigned int i = 0; i < length; i++) { |
||||
grpc_metadata* elem = &metadata_elements[i]; |
||||
Handle<String> key_string = String::New(elem->key); |
||||
Handle<Array> array; |
||||
if (metadata_object->Has(key_string)) { |
||||
array = Handle<Array>::Cast(metadata_object->Get(key_string)); |
||||
} else { |
||||
array = NanNew<Array>(size_map[elem->key]); |
||||
metadata_object->Set(key_string, array); |
||||
} |
||||
array->Set(index_map[elem->key], |
||||
MakeFastBuffer( |
||||
NanNewBufferHandle(elem->value, elem->value_length))); |
||||
index_map[elem->key] += 1; |
||||
} |
||||
return NanEscapeScope(metadata_object); |
||||
} |
||||
|
||||
Handle<Value> GetEventData(grpc_event *event) { |
||||
NanEscapableScope(); |
||||
size_t count; |
||||
grpc_metadata *items; |
||||
Handle<Array> metadata; |
||||
Handle<Object> status; |
||||
Handle<Object> rpc_new; |
||||
switch (event->type) { |
||||
case GRPC_READ: |
||||
return NanEscapeScope(ByteBufferToBuffer(event->data.read)); |
||||
case GRPC_WRITE_ACCEPTED: |
||||
return NanEscapeScope(NanNew<Number>(event->data.write_accepted)); |
||||
case GRPC_FINISH_ACCEPTED: |
||||
return NanEscapeScope(NanNew<Number>(event->data.finish_accepted)); |
||||
case GRPC_CLIENT_METADATA_READ: |
||||
count = event->data.client_metadata_read.count; |
||||
items = event->data.client_metadata_read.elements; |
||||
return NanEscapeScope(ParseMetadata(items, count)); |
||||
case GRPC_FINISHED: |
||||
status = NanNew<Object>(); |
||||
status->Set(NanNew("code"), NanNew<Number>(event->data.finished.status)); |
||||
if (event->data.finished.details != NULL) { |
||||
status->Set(NanNew("details"), |
||||
String::New(event->data.finished.details)); |
||||
} |
||||
count = event->data.finished.metadata_count; |
||||
items = event->data.finished.metadata_elements; |
||||
status->Set(NanNew("metadata"), ParseMetadata(items, count)); |
||||
return NanEscapeScope(status); |
||||
case GRPC_SERVER_RPC_NEW: |
||||
rpc_new = NanNew<Object>(); |
||||
if (event->data.server_rpc_new.method == NULL) { |
||||
return NanEscapeScope(NanNull()); |
||||
} |
||||
rpc_new->Set( |
||||
NanNew("method"), |
||||
NanNew(event->data.server_rpc_new.method)); |
||||
rpc_new->Set( |
||||
NanNew("host"), |
||||
NanNew(event->data.server_rpc_new.host)); |
||||
rpc_new->Set(NanNew("absolute_deadline"), |
||||
NanNew<Date>(TimespecToMilliseconds( |
||||
event->data.server_rpc_new.deadline))); |
||||
count = event->data.server_rpc_new.metadata_count; |
||||
items = event->data.server_rpc_new.metadata_elements; |
||||
metadata = NanNew<Array>(static_cast<int>(count)); |
||||
for (unsigned int i = 0; i < count; i++) { |
||||
Handle<Object> item_obj = Object::New(); |
||||
item_obj->Set(NanNew("key"), |
||||
NanNew(items[i].key)); |
||||
item_obj->Set( |
||||
NanNew("value"), |
||||
NanNew(items[i].value, static_cast<int>(items[i].value_length))); |
||||
metadata->Set(i, item_obj); |
||||
} |
||||
rpc_new->Set(NanNew("metadata"), ParseMetadata(items, count)); |
||||
return NanEscapeScope(rpc_new); |
||||
default: |
||||
return NanEscapeScope(NanNull()); |
||||
} |
||||
} |
||||
|
||||
Handle<Value> CreateEventObject(grpc_event *event) { |
||||
NanEscapableScope(); |
||||
if (event == NULL) { |
||||
return NanEscapeScope(NanNull()); |
||||
} |
||||
Handle<Object> event_obj = NanNew<Object>(); |
||||
Handle<Value> call; |
||||
if (TagHasCall(event->tag)) { |
||||
call = TagGetCall(event->tag); |
||||
} else { |
||||
call = Call::WrapStruct(event->call); |
||||
} |
||||
event_obj->Set(NanNew<String, const char *>("call"), call); |
||||
event_obj->Set(NanNew<String, const char *>("type"), |
||||
NanNew<Number>(event->type)); |
||||
event_obj->Set(NanNew<String, const char *>("data"), GetEventData(event)); |
||||
|
||||
return NanEscapeScope(event_obj); |
||||
} |
||||
|
||||
} // namespace node
|
||||
} // namespace grpc
|
@ -1,48 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef NET_GRPC_NODE_EVENT_H_ |
||||
#define NET_GRPC_NODE_EVENT_H_ |
||||
|
||||
#include <node.h> |
||||
#include "grpc/grpc.h" |
||||
|
||||
namespace grpc { |
||||
namespace node { |
||||
|
||||
v8::Handle<v8::Value> CreateEventObject(grpc_event *event); |
||||
|
||||
} // namespace node
|
||||
} // namespace grpc
|
||||
|
||||
#endif // NET_GRPC_NODE_EVENT_H_
|
@ -1,325 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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 <map> |
||||
#include <vector> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <stdlib.h> |
||||
#include <node.h> |
||||
#include <nan.h> |
||||
#include "tag.h" |
||||
#include "call.h" |
||||
|
||||
namespace grpc { |
||||
namespace node { |
||||
|
||||
using v8::Boolean; |
||||
using v8::Function; |
||||
using v8::Handle; |
||||
using v8::HandleScope; |
||||
using v8::Persistent; |
||||
using v8::Value; |
||||
|
||||
Handle<Value> ParseMetadata(grpc_metadata_array *metadata_array) { |
||||
NanEscapableScope(); |
||||
grpc_metadata *metadata_elements = metadata_array->metadata; |
||||
size_t length = metadata_array->count; |
||||
std::map<char*, size_t> size_map; |
||||
std::map<char*, size_t> index_map; |
||||
|
||||
for (unsigned int i = 0; i < length; i++) { |
||||
char *key = metadata_elements[i].key; |
||||
if (size_map.count(key)) { |
||||
size_map[key] += 1; |
||||
} |
||||
index_map[key] = 0; |
||||
} |
||||
Handle<Object> metadata_object = NanNew<Object>(); |
||||
for (unsigned int i = 0; i < length; i++) { |
||||
grpc_metadata* elem = &metadata_elements[i]; |
||||
Handle<String> key_string = String::New(elem->key); |
||||
Handle<Array> array; |
||||
if (metadata_object->Has(key_string)) { |
||||
array = Handle<Array>::Cast(metadata_object->Get(key_string)); |
||||
} else { |
||||
array = NanNew<Array>(size_map[elem->key]); |
||||
metadata_object->Set(key_string, array); |
||||
} |
||||
array->Set(index_map[elem->key], |
||||
MakeFastBuffer( |
||||
NanNewBufferHandle(elem->value, elem->value_length))); |
||||
index_map[elem->key] += 1; |
||||
} |
||||
return NanEscapeScope(metadata_object); |
||||
} |
||||
|
||||
class OpResponse { |
||||
public: |
||||
explicit OpResponse(char *name): name(name) { |
||||
} |
||||
virtual Handle<Value> GetNodeValue() const = 0; |
||||
virtual bool ParseOp() = 0; |
||||
Handle<Value> GetOpType() const { |
||||
NanEscapableScope(); |
||||
return NanEscapeScope(NanNew(name)); |
||||
} |
||||
|
||||
private: |
||||
char *name; |
||||
}; |
||||
|
||||
class SendResponse : public OpResponse { |
||||
public: |
||||
explicit SendResponse(char *name): OpResponse(name) { |
||||
} |
||||
|
||||
Handle<Value> GetNodeValue() { |
||||
NanEscapableScope(); |
||||
return NanEscapeScope(NanTrue()); |
||||
} |
||||
} |
||||
|
||||
class MetadataResponse : public OpResponse { |
||||
public: |
||||
explicit MetadataResponse(grpc_metadata_array *recv_metadata): |
||||
recv_metadata(recv_metadata), OpResponse("metadata") { |
||||
} |
||||
|
||||
Handle<Value> GetNodeValue() const { |
||||
NanEscapableScope(); |
||||
return NanEscapeScope(ParseMetadata(recv_metadata)); |
||||
} |
||||
|
||||
private: |
||||
grpc_metadata_array *recv_metadata; |
||||
}; |
||||
|
||||
class MessageResponse : public OpResponse { |
||||
public: |
||||
explicit MessageResponse(grpc_byte_buffer **recv_message): |
||||
recv_message(recv_message), OpResponse("read") { |
||||
} |
||||
|
||||
Handle<Value> GetNodeValue() const { |
||||
NanEscapableScope(); |
||||
return NanEscapeScope(ByteBufferToBuffer(*recv_message)); |
||||
} |
||||
|
||||
private: |
||||
grpc_byte_buffer **recv_message; |
||||
}; |
||||
|
||||
switch () { |
||||
case GRPC_RECV_CLIENT_STATUS: |
||||
op = new ClientStatusResponse; |
||||
break; |
||||
} |
||||
|
||||
|
||||
class ClientStatusResponse : public OpResponse { |
||||
public: |
||||
explicit ClientStatusResponse(): |
||||
OpResponse("status") { |
||||
} |
||||
|
||||
bool ParseOp(Handle<Value> obj, grpc_op *out) { |
||||
} |
||||
|
||||
Handle<Value> GetNodeValue() const { |
||||
NanEscapableScope(); |
||||
Handle<Object> status_obj = NanNew<Object>(); |
||||
status_obj->Set(NanNew("code"), NanNew<Number>(*status)); |
||||
if (event->data.finished.details != NULL) { |
||||
status_obj->Set(NanNew("details"), String::New(*status_details)); |
||||
} |
||||
status_obj->Set(NanNew("metadata"), ParseMetadata(metadata_array)); |
||||
return NanEscapeScope(status_obj); |
||||
} |
||||
private: |
||||
grpc_metadata_array metadata_array; |
||||
grpc_status_code status; |
||||
char *status_details; |
||||
}; |
||||
|
||||
class ServerCloseResponse : public OpResponse { |
||||
public: |
||||
explicit ServerCloseResponse(int *cancelled): cancelled(cancelled), |
||||
OpResponse("cancelled") { |
||||
} |
||||
|
||||
Handle<Value> GetNodeValue() const { |
||||
NanEscapableScope(); |
||||
NanEscapeScope(NanNew<Boolean>(*cancelled)); |
||||
} |
||||
|
||||
private: |
||||
int *cancelled; |
||||
}; |
||||
|
||||
class NewCallResponse : public OpResponse { |
||||
public: |
||||
explicit NewCallResponse(grpc_call **call, grpc_call_details *details, |
||||
grpc_metadata_array *request_metadata) : |
||||
call(call), details(details), request_metadata(request_metadata), |
||||
OpResponse("call"){ |
||||
} |
||||
|
||||
Handle<Value> GetNodeValue() const { |
||||
NanEscapableScope(); |
||||
if (*call == NULL) { |
||||
return NanEscapeScope(NanNull()); |
||||
} |
||||
Handle<Object> obj = NanNew<Object>(); |
||||
obj->Set(NanNew("call"), Call::WrapStruct(*call)); |
||||
obj->Set(NanNew("method"), NanNew(details->method)); |
||||
obj->Set(NanNew("host"), NanNew(details->host)); |
||||
obj->Set(NanNew("deadline"), |
||||
NanNew<Date>(TimespecToMilliseconds(details->deadline))); |
||||
obj->Set(NanNew("metadata"), ParseMetadata(request_metadata)); |
||||
return NanEscapeScope(obj); |
||||
} |
||||
private: |
||||
grpc_call **call; |
||||
grpc_call_details *details; |
||||
grpc_metadata_array *request_metadata; |
||||
} |
||||
|
||||
struct tag { |
||||
tag(NanCallback *callback, std::vector<OpResponse*> *responses, |
||||
std::vector<Persistent<Value>> *handles, |
||||
std::vector<NanUtf8String *> *strings) : |
||||
callback(callback), repsonses(responses), handles(handles), |
||||
strings(strings){ |
||||
} |
||||
~tag() { |
||||
for (std::vector<OpResponse *>::iterator it = responses->begin(); |
||||
it != responses->end(); ++it) { |
||||
delete *it; |
||||
} |
||||
for (std::vector<NanUtf8String *>::iterator it = responses->begin(); |
||||
it != responses->end(); ++it) { |
||||
delete *it; |
||||
} |
||||
delete callback; |
||||
delete responses; |
||||
delete handles; |
||||
delete strings; |
||||
} |
||||
NanCallback *callback; |
||||
std::vector<OpResponse*> *responses; |
||||
std::vector<Persistent<Value>> *handles; |
||||
std::vector<NanUtf8String *> *strings; |
||||
}; |
||||
|
||||
void *CreateTag(Handle<Function> callback, grpc_op *ops, size_t nops, |
||||
std::vector<Persistent<Value>> *handles, |
||||
std::vector<NanUtf8String *> *strings) { |
||||
NanScope(); |
||||
NanCallback *cb = new NanCallback(callback); |
||||
vector<OpResponse*> *responses = new vector<OpResponse*>(); |
||||
for (size_t i = 0; i < nops; i++) { |
||||
grpc_op *op = &ops[i]; |
||||
OpResponse *resp; |
||||
// Switching on the TYPE of the op
|
||||
switch (op->op) { |
||||
case GRPC_OP_SEND_INITIAL_METADATA: |
||||
resp = new SendResponse("send metadata"); |
||||
break; |
||||
case GRPC_OP_SEND_MESSAGE: |
||||
resp = new SendResponse("write"); |
||||
break; |
||||
case GRPC_OP_SEND_CLOSE_FROM_CLIENT: |
||||
resp = new SendResponse("client close"); |
||||
break; |
||||
case GRPC_OP_SEND_STATUS_FROM_SERVER: |
||||
resp = new SendResponse("server close"); |
||||
break; |
||||
case GRPC_OP_RECV_INITIAL_METADATA: |
||||
resp = new MetadataResponse(op->data.recv_initial_metadata); |
||||
break; |
||||
case GRPC_OP_RECV_MESSAGE: |
||||
resp = new MessageResponse(op->data.recv_message); |
||||
break; |
||||
case GRPC_OP_RECV_STATUS_ON_CLIENT: |
||||
resp = new ClientStatusResponse( |
||||
op->data.recv_status_on_client.trailing_metadata, |
||||
op->data.recv_status_on_client.status, |
||||
op->data.recv_status_on_client.status_details); |
||||
break; |
||||
case GRPC_RECV_CLOSE_ON_SERVER: |
||||
resp = new ServerCloseResponse(op->data.recv_close_on_server.cancelled); |
||||
break; |
||||
default: |
||||
continue; |
||||
} |
||||
responses->push_back(resp); |
||||
} |
||||
struct tag *tag_struct = new struct tag(cb, responses, handles, strings); |
||||
return reinterpret_cast<void *>(tag_struct); |
||||
} |
||||
|
||||
void *CreateTag(Handle<Function> callback, grpc_call **call, |
||||
grpc_call_details *details, |
||||
grpc_metadata_array *request_metadata) { |
||||
NanEscapableScope(); |
||||
NanCallback *cb = new NanCallback(callback); |
||||
vector<OpResponse*> *responses = new vector<OpResponse*>(); |
||||
OpResponse *resp = new NewCallResponse(call, details, request_metadata); |
||||
responses->push_back(resp); |
||||
struct tag *tag_struct = new struct tag(cb, responses); |
||||
return reinterpret_cast<void *>(tag_struct); |
||||
} |
||||
|
||||
NanCallback GetTagCallback(void *tag) { |
||||
NanEscapableScope(); |
||||
struct tag *tag_struct = reinterpret_cast<struct tag *>(tag); |
||||
return NanEscapeScope(*tag_struct->callback); |
||||
} |
||||
|
||||
Handle<Value> GetNodeValue(void *tag) { |
||||
NanEscapableScope(); |
||||
struct tag *tag_struct = reinterpret_cast<struct tag *>(tag); |
||||
Handle<Object> obj = NanNew<Object>(); |
||||
for (std::vector<OpResponse *>::iterator it = tag_struct->responses->begin(); |
||||
it != tag_struct->responses->end(); ++it) { |
||||
OpResponse *resp = *it; |
||||
obj->Set(resp->GetOpType(), resp->GetNodeValue()); |
||||
} |
||||
return NanEscapeScope(obj); |
||||
} |
||||
|
||||
void DestroyTag(void *tag) { delete reinterpret_cast<struct tag *>(tag); } |
||||
|
||||
} // namespace node
|
||||
} // namespace grpc
|
@ -1,72 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef NET_GRPC_NODE_TAG_H_ |
||||
#define NET_GRPC_NODE_TAG_H_ |
||||
|
||||
#include <vector> |
||||
|
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <node.h> |
||||
#include <nan.h> |
||||
|
||||
namespace grpc { |
||||
namespace node { |
||||
|
||||
/* Create a void* tag that can be passed to grpc_call_start_batch from a
|
||||
callback function and an ops array */ |
||||
void *CreateTag(v8::Handle<v8::Function> callback, grpc_op *ops, size_t nops, |
||||
std::vector<v8::Persistent<v8::Value> > *handles, |
||||
std::vector<NanUtf8String *> *strings); |
||||
|
||||
/* Create a void* tag that can be passed to grpc_server_request_call from a
|
||||
callback and the various out parameters to that function */ |
||||
void *CreateTag(v8::Handle<v8::Function> callback, grpc_call **call, |
||||
grpc_call_details *details, |
||||
grpc_metadata_array *request_metadata); |
||||
|
||||
/* Get the callback from the tag */ |
||||
NanCallback GetCallback(void *tag); |
||||
|
||||
/* Get the combined output value from the tag */ |
||||
v8::Handle<v8::Value> GetNodeValue(void *tag); |
||||
|
||||
/* Destroy the tag and all resources it is holding. It is illegal to call any
|
||||
of these other functions on a tag after it has been destroyed. */ |
||||
void DestroyTag(void *tag); |
||||
|
||||
} // namespace node
|
||||
} // namespace grpc
|
||||
|
||||
#endif // NET_GRPC_NODE_TAG_H_
|
Loading…
Reference in new issue