Skip to content

Commit

Permalink
Used StyleCop to get rid of tabs in the source code
Browse files Browse the repository at this point in the history
  • Loading branch information
jtattermusch committed Mar 6, 2015
1 parent 49fd7fe commit 13cd125
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 205 deletions.
1 change: 1 addition & 0 deletions src/csharp/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.userprefs
StyleCop.Cache
test-results
packages
Grpc.v12.suo
Expand Down
55 changes: 26 additions & 29 deletions src/csharp/Grpc.Core/Internal/CallSafeHandle.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#region Copyright notice and license

// Copyright 2015, Google Inc.
// All rights reserved.
//
Expand Down Expand Up @@ -30,21 +29,19 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#endregion

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Grpc.Core;

namespace Grpc.Core.Internal
{
internal delegate void CompletionCallbackDelegate(GRPCOpError error, IntPtr batchContextPtr);

internal delegate void CompletionCallbackDelegate(GRPCOpError error,IntPtr batchContextPtr);
/// <summary>
/// grpc_call from <grpc/grpc.h>
/// </summary>
internal class CallSafeHandle : SafeHandleZeroIsInvalid
{
internal class CallSafeHandle : SafeHandleZeroIsInvalid
{
const UInt32 GRPC_WRITE_BUFFER_HINT = 1;

[DllImport("grpc_csharp_ext.dll")]
Expand All @@ -58,51 +55,50 @@ internal class CallSafeHandle : SafeHandleZeroIsInvalid

[DllImport("grpc_csharp_ext.dll")]
static extern GRPCCallError grpcsharp_call_start_unary(CallSafeHandle call,
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback,
byte[] send_buffer, UIntPtr send_buffer_len);
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback,
byte[] send_buffer, UIntPtr send_buffer_len);

[DllImport("grpc_csharp_ext.dll")]
static extern void grpcsharp_call_blocking_unary(CallSafeHandle call, CompletionQueueSafeHandle dedicatedCq,
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback,
byte[] send_buffer, UIntPtr send_buffer_len);
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback,
byte[] send_buffer, UIntPtr send_buffer_len);

[DllImport("grpc_csharp_ext.dll")]
static extern GRPCCallError grpcsharp_call_start_client_streaming(CallSafeHandle call,
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback);
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback);

[DllImport("grpc_csharp_ext.dll")]
static extern GRPCCallError grpcsharp_call_start_server_streaming(CallSafeHandle call,
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback,
byte[] send_buffer, UIntPtr send_buffer_len);
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback,
byte[] send_buffer, UIntPtr send_buffer_len);

[DllImport("grpc_csharp_ext.dll")]
static extern GRPCCallError grpcsharp_call_start_duplex_streaming(CallSafeHandle call,
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback);

[DllImport("grpc_csharp_ext.dll")]
static extern GRPCCallError grpcsharp_call_send_message(CallSafeHandle call,
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback,
byte[] send_buffer, UIntPtr send_buffer_len);
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback,
byte[] send_buffer, UIntPtr send_buffer_len);

[DllImport("grpc_csharp_ext.dll")]
static extern GRPCCallError grpcsharp_call_send_close_from_client(CallSafeHandle call,
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback);
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback);

[DllImport("grpc_csharp_ext.dll")]
static extern GRPCCallError grpcsharp_call_send_status_from_server(CallSafeHandle call, [MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback, StatusCode statusCode, string statusMessage);

[DllImport("grpc_csharp_ext.dll")]
static extern GRPCCallError grpcsharp_call_recv_message(CallSafeHandle call,
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback);
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback);

[DllImport("grpc_csharp_ext.dll")]
static extern GRPCCallError grpcsharp_call_start_serverside(CallSafeHandle call,
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback);
[MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback);

[DllImport("grpc_csharp_ext.dll")]
static extern void grpcsharp_call_destroy(IntPtr call);


private CallSafeHandle()
{
}
Expand All @@ -114,12 +110,12 @@ public static CallSafeHandle Create(ChannelSafeHandle channel, CompletionQueueSa

public void StartUnary(byte[] payload, CompletionCallbackDelegate callback)
{
AssertCallOk(grpcsharp_call_start_unary(this, callback, payload, new UIntPtr((ulong) payload.Length)));
AssertCallOk(grpcsharp_call_start_unary(this, callback, payload, new UIntPtr((ulong)payload.Length)));
}

public void BlockingUnary(CompletionQueueSafeHandle dedicatedCq, byte[] payload, CompletionCallbackDelegate callback)
{
grpcsharp_call_blocking_unary(this, dedicatedCq, callback, payload, new UIntPtr((ulong) payload.Length));
grpcsharp_call_blocking_unary(this, dedicatedCq, callback, payload, new UIntPtr((ulong)payload.Length));
}

public void StartClientStreaming(CompletionCallbackDelegate callback)
Expand All @@ -129,7 +125,7 @@ public void StartClientStreaming(CompletionCallbackDelegate callback)

public void StartServerStreaming(byte[] payload, CompletionCallbackDelegate callback)
{
AssertCallOk(grpcsharp_call_start_server_streaming(this, callback, payload, new UIntPtr((ulong) payload.Length)));
AssertCallOk(grpcsharp_call_start_server_streaming(this, callback, payload, new UIntPtr((ulong)payload.Length)));
}

public void StartDuplexStreaming(CompletionCallbackDelegate callback)
Expand All @@ -139,7 +135,7 @@ public void StartDuplexStreaming(CompletionCallbackDelegate callback)

public void StartSendMessage(byte[] payload, CompletionCallbackDelegate callback)
{
AssertCallOk(grpcsharp_call_send_message(this, callback, payload, new UIntPtr((ulong) payload.Length)));
AssertCallOk(grpcsharp_call_send_message(this, callback, payload, new UIntPtr((ulong)payload.Length)));
}

public void StartSendCloseFromClient(CompletionCallbackDelegate callback)
Expand Down Expand Up @@ -172,19 +168,20 @@ public void CancelWithStatus(Status status)
AssertCallOk(grpcsharp_call_cancel_with_status(this, status.StatusCode, status.Detail));
}

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

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

private static UInt32 GetFlags(bool buffered) {
private static UInt32 GetFlags(bool buffered)
{
return buffered ? 0 : GRPC_WRITE_BUFFER_HINT;
}
}
}
}
32 changes: 14 additions & 18 deletions src/csharp/Grpc.Core/Internal/ClientStreamingInputObserver.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#region Copyright notice and license

// Copyright 2015, Google Inc.
// All rights reserved.
//
Expand Down Expand Up @@ -28,43 +27,40 @@
// 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.

#endregion

using System;
using Grpc.Core.Internal;

namespace Grpc.Core.Internal
{
internal class ClientStreamingInputObserver<TWrite, TRead> : IObserver<TWrite>
{
{
readonly AsyncCall<TWrite, TRead> call;

public ClientStreamingInputObserver(AsyncCall<TWrite, TRead> call)
{
{
this.call = call;
}
}

public void OnCompleted()
{
public void OnCompleted()
{
var taskSource = new AsyncCompletionTaskSource();
call.StartSendCloseFromClient(taskSource.CompletionDelegate);
// TODO: how bad is the Wait here?
taskSource.Task.Wait();
}
}

public void OnError(Exception error)
{
throw new InvalidOperationException("This should never be called.");
}
public void OnError(Exception error)
{
throw new InvalidOperationException("This should never be called.");
}

public void OnNext(TWrite value)
{
public void OnNext(TWrite value)
{
var taskSource = new AsyncCompletionTaskSource();
call.StartSendMessage(value, taskSource.CompletionDelegate);
// TODO: how bad is the Wait here?
taskSource.Task.Wait();
}
}
}
}
}

15 changes: 6 additions & 9 deletions src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#region Copyright notice and license

// Copyright 2015, Google Inc.
// All rights reserved.
//
Expand Down Expand Up @@ -28,9 +27,7 @@
// 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.

#endregion

using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
Expand All @@ -40,8 +37,8 @@ namespace Grpc.Core.Internal
/// <summary>
/// grpc_completion_queue from <grpc/grpc.h>
/// </summary>
internal class CompletionQueueSafeHandle : SafeHandleZeroIsInvalid
{
internal class CompletionQueueSafeHandle : SafeHandleZeroIsInvalid
{
[DllImport("grpc_csharp_ext.dll")]
static extern CompletionQueueSafeHandle grpcsharp_completion_queue_create();

Expand Down Expand Up @@ -73,11 +70,11 @@ public void Shutdown()
grpcsharp_completion_queue_shutdown(this);
}

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

31 changes: 14 additions & 17 deletions src/csharp/Grpc.Core/Internal/ServerStreamingOutputObserver.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#region Copyright notice and license

// Copyright 2015, Google Inc.
// All rights reserved.
//
Expand Down Expand Up @@ -28,9 +27,7 @@
// 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.

#endregion

using System;
using Grpc.Core.Internal;

Expand All @@ -41,35 +38,35 @@ namespace Grpc.Core.Internal
/// and then halfcloses the call. Used for server-side call handling.
/// </summary>
internal class ServerStreamingOutputObserver<TRequest, TResponse> : IObserver<TResponse>
{
{
readonly AsyncCallServer<TRequest, TResponse> call;

public ServerStreamingOutputObserver(AsyncCallServer<TRequest, TResponse> call)
{
{
this.call = call;
}
}

public void OnCompleted()
{
public void OnCompleted()
{
var taskSource = new AsyncCompletionTaskSource();
call.StartSendStatusFromServer(new Status(StatusCode.OK, ""), taskSource.CompletionDelegate);
// TODO: how bad is the Wait here?
taskSource.Task.Wait();
}
}

public void OnError(Exception error)
{
public void OnError(Exception error)
{
// TODO: implement this...
throw new InvalidOperationException("This should never be called.");
}
throw new InvalidOperationException("This should never be called.");
}

public void OnNext(TResponse value)
{
public void OnNext(TResponse value)
{
var taskSource = new AsyncCompletionTaskSource();
call.StartSendMessage(value, taskSource.CompletionDelegate);
// TODO: how bad is the Wait here?
taskSource.Task.Wait();
}
}
}
}
}

Loading

0 comments on commit 13cd125

Please sign in to comment.