Skip to content
Snippets Groups Projects
Commit 0faf80c3 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

add C# call flags API

parent 8442ebee
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,9 @@ namespace Grpc.Core.Tests ...@@ -67,6 +67,9 @@ namespace Grpc.Core.Tests
var credentials = new FakeCallCredentials(); var credentials = new FakeCallCredentials();
Assert.AreSame(credentials, options.WithCredentials(credentials).Credentials); 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. // Check that the original instance is unchanged.
Assert.IsNull(options.Headers); Assert.IsNull(options.Headers);
Assert.IsNull(options.Deadline); Assert.IsNull(options.Deadline);
...@@ -74,6 +77,7 @@ namespace Grpc.Core.Tests ...@@ -74,6 +77,7 @@ namespace Grpc.Core.Tests
Assert.IsNull(options.WriteOptions); Assert.IsNull(options.WriteOptions);
Assert.IsNull(options.PropagationToken); Assert.IsNull(options.PropagationToken);
Assert.IsNull(options.Credentials); Assert.IsNull(options.Credentials);
Assert.AreEqual(default(CallFlags), options.Flags);
} }
[Test] [Test]
......
#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 ...@@ -50,6 +50,7 @@ namespace Grpc.Core
WriteOptions writeOptions; WriteOptions writeOptions;
ContextPropagationToken propagationToken; ContextPropagationToken propagationToken;
CallCredentials credentials; CallCredentials credentials;
CallFlags flags;
/// <summary> /// <summary>
/// Creates a new instance of <c>CallOptions</c> struct. /// Creates a new instance of <c>CallOptions</c> struct.
...@@ -60,8 +61,10 @@ namespace Grpc.Core ...@@ -60,8 +61,10 @@ namespace Grpc.Core
/// <param name="writeOptions">Write options that will be used for this call.</param> /// <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="propagationToken">Context propagation token obtained from <see cref="ServerCallContext"/>.</param>
/// <param name="credentials">Credentials to use for this call.</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), 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.headers = headers;
this.deadline = deadline; this.deadline = deadline;
...@@ -69,6 +72,7 @@ namespace Grpc.Core ...@@ -69,6 +72,7 @@ namespace Grpc.Core
this.writeOptions = writeOptions; this.writeOptions = writeOptions;
this.propagationToken = propagationToken; this.propagationToken = propagationToken;
this.credentials = credentials; this.credentials = credentials;
this.flags = flags;
} }
/// <summary> /// <summary>
...@@ -125,6 +129,14 @@ namespace Grpc.Core ...@@ -125,6 +129,14 @@ namespace Grpc.Core
get { return this.credentials; } get { return this.credentials; }
} }
/// <summary>
/// Flags to use for this call.
/// </summary>
public CallFlags Flags
{
get { return this.flags; }
}
/// <summary> /// <summary>
/// Returns new instance of <see cref="CallOptions"/> with /// Returns new instance of <see cref="CallOptions"/> with
/// <c>Headers</c> set to the value provided. Values of all other fields are preserved. /// <c>Headers</c> set to the value provided. Values of all other fields are preserved.
...@@ -197,6 +209,18 @@ namespace Grpc.Core ...@@ -197,6 +209,18 @@ namespace Grpc.Core
return newOptions; 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> /// <summary>
/// Returns a new instance of <see cref="CallOptions"/> with /// Returns a new instance of <see cref="CallOptions"/> with
/// all previously unset values set to their defaults and deadline and cancellation /// all previously unset values set to their defaults and deadline and cancellation
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
<Compile Include="AsyncServerStreamingCall.cs" /> <Compile Include="AsyncServerStreamingCall.cs" />
<Compile Include="AsyncAuthInterceptor.cs" /> <Compile Include="AsyncAuthInterceptor.cs" />
<Compile Include="CallCredentials.cs" /> <Compile Include="CallCredentials.cs" />
<Compile Include="CallFlags.cs" />
<Compile Include="IClientStreamWriter.cs" /> <Compile Include="IClientStreamWriter.cs" />
<Compile Include="Internal\NativeMethods.cs" /> <Compile Include="Internal\NativeMethods.cs" />
<Compile Include="Internal\PlatformApis.cs" /> <Compile Include="Internal\PlatformApis.cs" />
...@@ -153,4 +154,4 @@ ...@@ -153,4 +154,4 @@
<Link>roots.pem</Link> <Link>roots.pem</Link>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment