Skip to content

Commit

Permalink
Merge branch 'master' of github.com:grpc/grpc into the-purge-2
Browse files Browse the repository at this point in the history
Conflicts:
	include/grpc++/completion_queue.h
  • Loading branch information
nicolasnoble committed Apr 24, 2015
2 parents 76e49fd + 4107ba2 commit fd2bf67
Show file tree
Hide file tree
Showing 37 changed files with 265 additions and 187 deletions.
2 changes: 2 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ cc_library(
"include/grpc++/generic_stub.h",
"include/grpc++/impl/call.h",
"include/grpc++/impl/client_unary_call.h",
"include/grpc++/impl/grpc_library.h",
"include/grpc++/impl/internal_stub.h",
"include/grpc++/impl/rpc_method.h",
"include/grpc++/impl/rpc_service_method.h",
Expand Down Expand Up @@ -698,6 +699,7 @@ cc_library(
"include/grpc++/generic_stub.h",
"include/grpc++/impl/call.h",
"include/grpc++/impl/client_unary_call.h",
"include/grpc++/impl/grpc_library.h",
"include/grpc++/impl/internal_stub.h",
"include/grpc++/impl/rpc_method.h",
"include/grpc++/impl/rpc_service_method.h",
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3854,6 +3854,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc++/generic_stub.h \
include/grpc++/impl/call.h \
include/grpc++/impl/client_unary_call.h \
include/grpc++/impl/grpc_library.h \
include/grpc++/impl/internal_stub.h \
include/grpc++/impl/rpc_method.h \
include/grpc++/impl/rpc_service_method.h \
Expand Down Expand Up @@ -4118,6 +4119,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc++/generic_stub.h \
include/grpc++/impl/call.h \
include/grpc++/impl/client_unary_call.h \
include/grpc++/impl/grpc_library.h \
include/grpc++/impl/internal_stub.h \
include/grpc++/impl/rpc_method.h \
include/grpc++/impl/rpc_service_method.h \
Expand Down
1 change: 1 addition & 0 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"include/grpc++/generic_stub.h",
"include/grpc++/impl/call.h",
"include/grpc++/impl/client_unary_call.h",
"include/grpc++/impl/grpc_library.h",
"include/grpc++/impl/internal_stub.h",
"include/grpc++/impl/rpc_method.h",
"include/grpc++/impl/rpc_service_method.h",
Expand Down
3 changes: 0 additions & 3 deletions examples/pubsub/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const char kMessageData[] = "Test Data";
} // namespace

int main(int argc, char** argv) {
grpc_init();
grpc::testing::InitTest(&argc, &argv, true);
gpr_log(GPR_INFO, "Start PUBSUB client");

Expand Down Expand Up @@ -145,7 +144,5 @@ int main(int argc, char** argv) {

subscriber.Shutdown();
publisher.Shutdown();
channel.reset();
grpc_shutdown();
return 0;
}
2 changes: 0 additions & 2 deletions examples/pubsub/publisher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,8 @@ TEST_F(PublisherTest, TestPublisher) {

int main(int argc, char** argv) {
grpc_test_init(argc, argv);
grpc_init();
::testing::InitGoogleTest(&argc, argv);
gpr_log(GPR_INFO, "Start test ...");
int result = RUN_ALL_TESTS();
grpc_shutdown();
return result;
}
2 changes: 0 additions & 2 deletions examples/pubsub/subscriber_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ TEST_F(SubscriberTest, TestSubscriber) {

int main(int argc, char** argv) {
grpc_test_init(argc, argv);
grpc_init();
::testing::InitGoogleTest(&argc, argv);
gpr_log(GPR_INFO, "Start test ...");
int result = RUN_ALL_TESTS();
grpc_shutdown();
return result;
}
5 changes: 3 additions & 2 deletions include/grpc++/completion_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <grpc/support/time.h>
#include <grpc++/impl/client_unary_call.h>
#include <grpc++/impl/grpc_library.h>
#include <grpc++/time.h>

struct grpc_completion_queue;
Expand Down Expand Up @@ -71,11 +72,11 @@ class CompletionQueueTag {
};

// grpc_completion_queue wrapper class
class CompletionQueue {
class CompletionQueue : public GrpcLibrary {
public:
CompletionQueue();
explicit CompletionQueue(grpc_completion_queue* take);
~CompletionQueue();
~CompletionQueue() GRPC_OVERRIDE;

// Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT
enum NextStatus { SHUTDOWN, GOT_EVENT, TIMEOUT };
Expand Down
5 changes: 3 additions & 2 deletions include/grpc++/credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@
#include <memory>

#include <grpc++/config.h>
#include <grpc++/impl/grpc_library.h>

namespace grpc {
class ChannelArguments;
class ChannelInterface;
class SecureCredentials;

class Credentials {
class Credentials : public GrpcLibrary {
public:
virtual ~Credentials();
~Credentials() GRPC_OVERRIDE;

protected:
friend std::unique_ptr<Credentials> CompositeCredentials(
Expand Down
50 changes: 50 additions & 0 deletions include/grpc++/impl/grpc_library.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
*
* 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.
*
*/

#ifndef GRPCXX_IMPL_GRPC_LIBRARY_H
#define GRPCXX_IMPL_GRPC_LIBRARY_H

#include <grpc/grpc.h>

namespace grpc {

class GrpcLibrary {
public:
GrpcLibrary() { grpc_init(); }
virtual ~GrpcLibrary() { grpc_shutdown(); }
};

} // namespace grpc


#endif // GRPCXX_IMPL_GRPC_LIBRARY_H
4 changes: 3 additions & 1 deletion include/grpc++/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <grpc++/completion_queue.h>
#include <grpc++/config.h>
#include <grpc++/impl/call.h>
#include <grpc++/impl/grpc_library.h>
#include <grpc++/impl/service_type.h>
#include <grpc++/impl/sync.h>
#include <grpc++/status.h>
Expand All @@ -56,7 +57,8 @@ class ServerCredentials;
class ThreadPoolInterface;

// Currently it only supports handling rpcs in a single thread.
class Server GRPC_FINAL : private CallHook,
class Server GRPC_FINAL : public GrpcLibrary,
private CallHook,
private AsynchronousService::DispatchImpl {
public:
~Server();
Expand Down
4 changes: 3 additions & 1 deletion src/cpp/client/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include <grpc++/channel_interface.h>
#include <grpc++/config.h>
#include <grpc++/impl/grpc_library.h>

struct grpc_channel;

Expand All @@ -49,7 +50,8 @@ class CompletionQueue;
class Credentials;
class StreamContextInterface;

class Channel GRPC_FINAL : public ChannelInterface {
class Channel GRPC_FINAL : public GrpcLibrary,
public ChannelInterface {
public:
Channel(const grpc::string& target, grpc_channel* c_channel);
~Channel() GRPC_OVERRIDE;
Expand Down
3 changes: 2 additions & 1 deletion src/csharp/Grpc.Core/Internal/CallSafeHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using Grpc.Core;
using Grpc.Core.Utils;

namespace Grpc.Core.Internal
{
Expand Down Expand Up @@ -180,7 +181,7 @@ protected override bool ReleaseHandle()

private static void AssertCallOk(GRPCCallError callError)
{
Trace.Assert(callError == GRPCCallError.GRPC_CALL_OK, "Status not GRPC_CALL_OK");
Preconditions.CheckState(callError == GRPCCallError.GRPC_CALL_OK, "Status not GRPC_CALL_OK");
}

private static uint GetFlags(bool buffered)
Expand Down
10 changes: 8 additions & 2 deletions src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Grpc.Core.Utils;

namespace Grpc.Core.Internal
{
Expand Down Expand Up @@ -105,15 +106,20 @@ public void ShutdownAndNotify(ServerShutdownCallbackDelegate callback)
grpcsharp_server_shutdown_and_notify_CALLBACK(this, callback);
}

public GRPCCallError RequestCall(CompletionQueueSafeHandle cq, CompletionCallbackDelegate callback)
public void RequestCall(CompletionQueueSafeHandle cq, CompletionCallbackDelegate callback)
{
return grpcsharp_server_request_call(this, cq, callback);
AssertCallOk(grpcsharp_server_request_call(this, cq, callback));
}

protected override bool ReleaseHandle()
{
grpcsharp_server_destroy(handle);
return true;
}

private static void AssertCallOk(GRPCCallError callError)
{
Preconditions.CheckState(callError == GRPCCallError.GRPC_CALL_OK, "Status not GRPC_CALL_OK");
}
}
}
Loading

0 comments on commit fd2bf67

Please sign in to comment.