add C# call flags API

pull/8828/head
Jan Tattermusch 8 years ago
parent 8442ebee03
commit 0faf80c348
  1. 4
      src/csharp/Grpc.Core.Tests/CallOptionsTest.cs
  2. 60
      src/csharp/Grpc.Core/CallFlags.cs
  3. 26
      src/csharp/Grpc.Core/CallOptions.cs
  4. 3
      src/csharp/Grpc.Core/Grpc.Core.csproj

@ -67,6 +67,9 @@ namespace Grpc.Core.Tests
var credentials = new FakeCallCredentials();
Assert.AreSame(credentials, options.WithCredentials(credentials).Credentials);
var flags = CallFlags.WaitForReady | CallFlags.CacheableRequest;
Assert.AreEqual(flags, options.WithFlags(flags).Flags);
// Check that the original instance is unchanged.
Assert.IsNull(options.Headers);
Assert.IsNull(options.Deadline);
@ -74,6 +77,7 @@ namespace Grpc.Core.Tests
Assert.IsNull(options.WriteOptions);
Assert.IsNull(options.PropagationToken);
Assert.IsNull(options.Credentials);
Assert.AreEqual(default(CallFlags), options.Flags);
}
[Test]

@ -0,0 +1,60 @@
#region Copyright notice and license
// 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.
#endregion
using System;
namespace Grpc.Core
{
/// <summary>
/// Flags for various call behaviors (client-side only).
/// </summary>
[Flags]
public enum CallFlags
{
/// <summary>
/// The call is idempotent (retrying the call doesn't change the outcome of the operation).
/// </summary>
IdempotentRequest = 0x10,
/// <summary>
/// If channel is in <c>ChannelState.TransientFailure</c>, attempt waiting for the channel to recover
/// instead of failing the call immediately.
/// </summary>
WaitForReady = 0x20,
/// <summary>
/// The call is cacheable. gRPC is free to use GET verb */
/// </summary>
CacheableRequest = 0x40
}
}

@ -50,6 +50,7 @@ namespace Grpc.Core
WriteOptions writeOptions;
ContextPropagationToken propagationToken;
CallCredentials credentials;
CallFlags flags;
/// <summary>
/// Creates a new instance of <c>CallOptions</c> struct.
@ -60,8 +61,10 @@ namespace Grpc.Core
/// <param name="writeOptions">Write options that will be used for this call.</param>
/// <param name="propagationToken">Context propagation token obtained from <see cref="ServerCallContext"/>.</param>
/// <param name="credentials">Credentials to use for this call.</param>
/// <param name="flags">Flags to use for this call.</param>
public CallOptions(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken),
WriteOptions writeOptions = null, ContextPropagationToken propagationToken = null, CallCredentials credentials = null)
WriteOptions writeOptions = null, ContextPropagationToken propagationToken = null, CallCredentials credentials = null,
CallFlags flags = default(CallFlags))
{
this.headers = headers;
this.deadline = deadline;
@ -69,6 +72,7 @@ namespace Grpc.Core
this.writeOptions = writeOptions;
this.propagationToken = propagationToken;
this.credentials = credentials;
this.flags = flags;
}
/// <summary>
@ -125,6 +129,14 @@ namespace Grpc.Core
get { return this.credentials; }
}
/// <summary>
/// Flags to use for this call.
/// </summary>
public CallFlags Flags
{
get { return this.flags; }
}
/// <summary>
/// Returns new instance of <see cref="CallOptions"/> with
/// <c>Headers</c> set to the value provided. Values of all other fields are preserved.
@ -197,6 +209,18 @@ namespace Grpc.Core
return newOptions;
}
/// <summary>
/// Returns new instance of <see cref="CallOptions"/> with
/// <c>Flags</c> set to the value provided. Values of all other fields are preserved.
/// </summary>
/// <param name="flags">The call flags.</param>
public CallOptions WithFlags(CallFlags flags)
{
var newOptions = this;
newOptions.flags = flags;
return newOptions;
}
/// <summary>
/// Returns a new instance of <see cref="CallOptions"/> with
/// all previously unset values set to their defaults and deadline and cancellation

@ -48,6 +48,7 @@
<Compile Include="AsyncServerStreamingCall.cs" />
<Compile Include="AsyncAuthInterceptor.cs" />
<Compile Include="CallCredentials.cs" />
<Compile Include="CallFlags.cs" />
<Compile Include="IClientStreamWriter.cs" />
<Compile Include="Internal\NativeMethods.cs" />
<Compile Include="Internal\PlatformApis.cs" />
@ -153,4 +154,4 @@
<Link>roots.pem</Link>
</EmbeddedResource>
</ItemGroup>
</Project>
</Project>
Loading…
Cancel
Save