aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpp/client')
-rw-r--r--src/cpp/client/channel.cc212
-rw-r--r--src/cpp/client/channel.h71
-rw-r--r--src/cpp/client/client_context.cc73
-rw-r--r--src/cpp/client/create_channel.cc47
-rw-r--r--src/cpp/client/credentials.cc90
-rw-r--r--src/cpp/client/internal_stub.cc36
-rw-r--r--src/cpp/client/internal_stub.h60
7 files changed, 589 insertions, 0 deletions
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc
new file mode 100644
index 0000000000..7a7529104f
--- /dev/null
+++ b/src/cpp/client/channel.cc
@@ -0,0 +1,212 @@
+/*
+ *
+ * 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 "src/cpp/client/channel.h"
+
+#include <chrono>
+#include <string>
+
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/slice.h>
+#include <grpc/support/time.h>
+
+#include "src/cpp/rpc_method.h"
+#include "src/cpp/proto/proto_utils.h"
+#include "src/cpp/stream/stream_context.h"
+#include "src/cpp/util/time.h"
+#include <grpc++/config.h>
+#include <google/protobuf/message.h>
+#include <grpc++/client_context.h>
+#include <grpc++/status.h>
+
+namespace grpc {
+
+Channel::Channel(const grpc::string& target) : target_(target) {
+ c_channel_ = grpc_channel_create(target_.c_str(), nullptr);
+}
+
+Channel::~Channel() { grpc_channel_destroy(c_channel_); }
+
+namespace {
+// Poll one event from the compeletion queue. Return false when an error
+// occured or the polled type is not expected. If a finished event has been
+// polled, set finished and set status if it has not been set.
+bool NextEvent(grpc_completion_queue* cq, grpc_completion_type expected_type,
+ bool* finished, bool* status_set, Status* status,
+ google::protobuf::Message* result) {
+ // We rely on the c layer to enforce deadline and thus do not use deadline
+ // here.
+ grpc_event* ev = grpc_completion_queue_next(cq, gpr_inf_future);
+ if (!ev) {
+ return false;
+ }
+ bool ret = ev->type == expected_type;
+ switch (ev->type) {
+ case GRPC_INVOKE_ACCEPTED:
+ ret = ret && (ev->data.invoke_accepted == GRPC_OP_OK);
+ break;
+ case GRPC_READ:
+ ret = ret && (ev->data.read != nullptr);
+ if (ret && !DeserializeProto(ev->data.read, result)) {
+ *status_set = true;
+ *status =
+ Status(StatusCode::DATA_LOSS, "Failed to parse response proto.");
+ ret = false;
+ }
+ break;
+ case GRPC_WRITE_ACCEPTED:
+ ret = ret && (ev->data.write_accepted == GRPC_OP_OK);
+ break;
+ case GRPC_FINISH_ACCEPTED:
+ ret = ret && (ev->data.finish_accepted == GRPC_OP_OK);
+ break;
+ case GRPC_CLIENT_METADATA_READ:
+ break;
+ case GRPC_FINISHED:
+ *finished = true;
+ if (!*status_set) {
+ *status_set = true;
+ StatusCode error_code = static_cast<StatusCode>(ev->data.finished.code);
+ grpc::string details(
+ ev->data.finished.details ? ev->data.finished.details : "");
+ *status = Status(error_code, details);
+ }
+ break;
+ default:
+ gpr_log(GPR_ERROR, "Dropping unhandled event with type %d", ev->type);
+ break;
+ }
+ grpc_event_finish(ev);
+ return ret;
+}
+
+// If finished is not true, get final status by polling until a finished
+// event is obtained.
+void GetFinalStatus(grpc_completion_queue* cq, bool status_set, bool finished,
+ Status* status) {
+ while (!finished) {
+ NextEvent(cq, GRPC_FINISHED, &finished, &status_set, status, nullptr);
+ }
+}
+
+} // namespace
+
+// TODO(yangg) more error handling
+Status Channel::StartBlockingRpc(const RpcMethod& method,
+ ClientContext* context,
+ const google::protobuf::Message& request,
+ google::protobuf::Message* result) {
+ Status status;
+ bool status_set = false;
+ bool finished = false;
+ gpr_timespec absolute_deadline;
+ AbsoluteDeadlineTimepoint2Timespec(context->absolute_deadline(),
+ &absolute_deadline);
+ grpc_call* call = grpc_channel_create_call(c_channel_, method.name(),
+ // FIXME(yangg)
+ "localhost", absolute_deadline);
+ context->set_call(call);
+ grpc_completion_queue* cq = grpc_completion_queue_create();
+ context->set_cq(cq);
+ // add_metadata from context
+ //
+ // invoke
+ GPR_ASSERT(grpc_call_start_invoke(call, cq, call, call, call,
+ GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK);
+ if (!NextEvent(cq, GRPC_INVOKE_ACCEPTED, &status_set, &finished, &status,
+ nullptr)) {
+ GetFinalStatus(cq, finished, status_set, &status);
+ return status;
+ }
+ // write request
+ grpc_byte_buffer* write_buffer = nullptr;
+ bool success = SerializeProto(request, &write_buffer);
+ if (!success) {
+ grpc_call_cancel(call);
+ status_set = true;
+ status =
+ Status(StatusCode::DATA_LOSS, "Failed to serialize request proto.");
+ GetFinalStatus(cq, finished, status_set, &status);
+ return status;
+ }
+ GPR_ASSERT(grpc_call_start_write(call, write_buffer, call,
+ GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK);
+ grpc_byte_buffer_destroy(write_buffer);
+ if (!NextEvent(cq, GRPC_WRITE_ACCEPTED, &finished, &status_set, &status,
+ nullptr)) {
+ GetFinalStatus(cq, finished, status_set, &status);
+ return status;
+ }
+ // writes done
+ GPR_ASSERT(grpc_call_writes_done(call, call) == GRPC_CALL_OK);
+ if (!NextEvent(cq, GRPC_FINISH_ACCEPTED, &finished, &status_set, &status,
+ nullptr)) {
+ GetFinalStatus(cq, finished, status_set, &status);
+ return status;
+ }
+ // start read metadata
+ //
+ if (!NextEvent(cq, GRPC_CLIENT_METADATA_READ, &finished, &status_set, &status,
+ nullptr)) {
+ GetFinalStatus(cq, finished, status_set, &status);
+ return status;
+ }
+ // start read
+ GPR_ASSERT(grpc_call_start_read(call, call) == GRPC_CALL_OK);
+ if (!NextEvent(cq, GRPC_READ, &finished, &status_set, &status, result)) {
+ GetFinalStatus(cq, finished, status_set, &status);
+ return status;
+ }
+ // wait status
+ GetFinalStatus(cq, finished, status_set, &status);
+ return status;
+}
+
+StreamContextInterface* Channel::CreateStream(const RpcMethod& method,
+ ClientContext* context,
+ const google::protobuf::Message* request,
+ google::protobuf::Message* result) {
+ gpr_timespec absolute_deadline;
+ AbsoluteDeadlineTimepoint2Timespec(context->absolute_deadline(),
+ &absolute_deadline);
+ grpc_call* call = grpc_channel_create_call(c_channel_, method.name(),
+ // FIXME(yangg)
+ "localhost", absolute_deadline);
+ context->set_call(call);
+ grpc_completion_queue* cq = grpc_completion_queue_create();
+ context->set_cq(cq);
+ return new StreamContext(method, context, request, result);
+}
+
+} // namespace grpc
diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h
new file mode 100644
index 0000000000..a97d35efe8
--- /dev/null
+++ b/src/cpp/client/channel.h
@@ -0,0 +1,71 @@
+/*
+ *
+ * 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 __GRPCPP_INTERNAL_CLIENT_CHANNEL_H__
+#define __GRPCPP_INTERNAL_CLIENT_CHANNEL_H__
+
+#include <grpc++/channel_interface.h>
+#include <grpc++/config.h>
+
+struct grpc_channel;
+
+namespace grpc {
+class StreamContextInterface;
+
+class Channel : public ChannelInterface {
+ public:
+ explicit Channel(const grpc::string& target);
+ ~Channel() override;
+
+ Status StartBlockingRpc(const RpcMethod& method, ClientContext* context,
+ const google::protobuf::Message& request,
+ google::protobuf::Message* result) override;
+
+ StreamContextInterface* CreateStream(const RpcMethod& method,
+ ClientContext* context,
+ const google::protobuf::Message* request,
+ google::protobuf::Message* result) override;
+
+ protected:
+ // TODO(yangg) remove this section when we have the general ssl channel API
+ Channel() {}
+ void set_c_channel(grpc_channel* channel) { c_channel_ = channel; }
+
+ private:
+ const grpc::string target_;
+ grpc_channel* c_channel_; // owned
+};
+
+} // namespace grpc
+
+#endif // __GRPCPP_INTERNAL_CLIENT_CHANNEL_H__
diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc
new file mode 100644
index 0000000000..78774a7f12
--- /dev/null
+++ b/src/cpp/client/client_context.cc
@@ -0,0 +1,73 @@
+/*
+ *
+ * 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 <grpc++/client_context.h>
+
+#include <grpc/grpc.h>
+
+using std::chrono::system_clock;
+
+namespace grpc {
+
+ClientContext::ClientContext()
+ : call_(nullptr),
+ cq_(nullptr),
+ absolute_deadline_(system_clock::time_point::max()) {}
+
+ClientContext::~ClientContext() {
+ if (call_) {
+ grpc_call_destroy(call_);
+ }
+ if (cq_) {
+ grpc_completion_queue_shutdown(cq_);
+ grpc_completion_queue_destroy(cq_);
+ }
+}
+
+void ClientContext::set_absolute_deadline(
+ const system_clock::time_point& deadline) {
+ absolute_deadline_ = deadline;
+}
+
+system_clock::time_point ClientContext::absolute_deadline() {
+ return absolute_deadline_;
+}
+
+void ClientContext::AddMetadata(const grpc::string& meta_key,
+ const grpc::string& meta_value) {
+ return;
+}
+
+void ClientContext::StartCancel() {}
+
+} // namespace grpc
diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc
new file mode 100644
index 0000000000..ea2b6a7ba2
--- /dev/null
+++ b/src/cpp/client/create_channel.cc
@@ -0,0 +1,47 @@
+/*
+ *
+ * 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 <memory>
+#include <string>
+
+#include "src/cpp/client/channel.h"
+#include <grpc++/channel_interface.h>
+#include <grpc++/create_channel.h>
+
+namespace grpc {
+
+std::shared_ptr<ChannelInterface> CreateChannel(const grpc::string& target) {
+ return std::shared_ptr<ChannelInterface>(new Channel(target));
+}
+
+} // namespace grpc
diff --git a/src/cpp/client/credentials.cc b/src/cpp/client/credentials.cc
new file mode 100644
index 0000000000..18fa4fa656
--- /dev/null
+++ b/src/cpp/client/credentials.cc
@@ -0,0 +1,90 @@
+/*
+ *
+ * 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 <string>
+
+#include <grpc/grpc_security.h>
+
+#include <grpc++/credentials.h>
+
+namespace grpc {
+
+Credentials::Credentials(grpc_credentials* c_creds) : creds_(c_creds) {}
+
+Credentials::~Credentials() { grpc_credentials_release(creds_); }
+grpc_credentials* Credentials::GetRawCreds() { return creds_; }
+
+std::unique_ptr<Credentials> CredentialsFactory::DefaultCredentials() {
+ grpc_credentials* c_creds = grpc_default_credentials_create();
+ std::unique_ptr<Credentials> cpp_creds(new Credentials(c_creds));
+ return cpp_creds;
+}
+
+// Builds SSL Credentials given SSL specific options
+std::unique_ptr<Credentials> CredentialsFactory::SslCredentials(
+ const SslCredentialsOptions& options) {
+ grpc_credentials* c_creds = grpc_ssl_credentials_create(
+ reinterpret_cast<const unsigned char*>(options.pem_root_certs.c_str()),
+ options.pem_root_certs.size(),
+ reinterpret_cast<const unsigned char*>(options.pem_private_key.c_str()),
+ options.pem_private_key.size(),
+ reinterpret_cast<const unsigned char*>(options.pem_cert_chain.c_str()),
+ options.pem_cert_chain.size());
+ std::unique_ptr<Credentials> cpp_creds(new Credentials(c_creds));
+ return cpp_creds;
+}
+
+// Builds credentials for use when running in GCE
+std::unique_ptr<Credentials> CredentialsFactory::ComputeEngineCredentials() {
+ grpc_credentials* c_creds = grpc_compute_engine_credentials_create();
+ std::unique_ptr<Credentials> cpp_creds(new Credentials(c_creds));
+ return cpp_creds;
+}
+
+
+// Combines two credentials objects into a composite credentials.
+std::unique_ptr<Credentials> CredentialsFactory::ComposeCredentials(
+ const std::unique_ptr<Credentials>& creds1,
+ const std::unique_ptr<Credentials>& creds2) {
+ // Note that we are not saving unique_ptrs to the two credentials
+ // passed in here. This is OK because the underlying C objects (i.e.,
+ // creds1 and creds2) into grpc_composite_credentials_create will see their
+ // refcounts incremented.
+ grpc_credentials* c_creds = grpc_composite_credentials_create(
+ creds1->GetRawCreds(), creds2->GetRawCreds());
+ std::unique_ptr<Credentials> cpp_creds(new Credentials(c_creds));
+ return cpp_creds;
+}
+
+} // namespace grpc
diff --git a/src/cpp/client/internal_stub.cc b/src/cpp/client/internal_stub.cc
new file mode 100644
index 0000000000..ec88ba5e7e
--- /dev/null
+++ b/src/cpp/client/internal_stub.cc
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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 "src/cpp/client/internal_stub.h"
+
+namespace grpc {} // namespace grpc
diff --git a/src/cpp/client/internal_stub.h b/src/cpp/client/internal_stub.h
new file mode 100644
index 0000000000..0eaa717d0b
--- /dev/null
+++ b/src/cpp/client/internal_stub.h
@@ -0,0 +1,60 @@
+/*
+ *
+ * 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 __GRPCPP_INTERNAL_CLIENT_INTERNAL_STUB_H__
+#define __GRPCPP_INTERNAL_CLIENT_INTERNAL_STUB_H__
+
+#include <memory>
+
+#include <grpc++/channel_interface.h>
+
+namespace grpc {
+
+class InternalStub {
+ public:
+ InternalStub() {}
+ virtual ~InternalStub() {}
+
+ void set_channel(const std::shared_ptr<ChannelInterface>& channel) {
+ channel_ = channel;
+ }
+
+ ChannelInterface* channel() { return channel_.get(); }
+
+ private:
+ std::shared_ptr<ChannelInterface> channel_;
+};
+
+} // namespace grpc
+
+#endif // __GRPCPP_INTERNAL_CLIENT_INTERNAL_STUB_H__