Skip to content

Commit

Permalink
Merge pull request #794 from Cysharp/feature/UpdateDiagnosticHandlerApi
Browse files Browse the repository at this point in the history
Update IStreamingHubDiagnosticHandler API
  • Loading branch information
mayuki authored Jun 21, 2024
2 parents 1a04afd + dbdc9dc commit b0dee9d
Show file tree
Hide file tree
Showing 58 changed files with 213 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ static void EmitOnBroadcastEvent(StreamingHubClientBuildContext ctx)
ctx.Writer.AppendLine("""
protected override void OnBroadcastEvent(global::System.Int32 methodId, global::System.ReadOnlyMemory<global::System.Byte> data)
{
""");
if (ctx.EnableStreamingHubDiagnosticHandler)
{
ctx.Writer.AppendLine("""
diagnosticHandler?.OnBroadcastEventRaw(this, methodId, data);
""");
}
ctx.Writer.AppendLine("""
switch (methodId)
{
""");
Expand Down Expand Up @@ -356,18 +364,31 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
static void EmitOnResponseEvent(StreamingHubClientBuildContext ctx)
{
ctx.Writer.AppendLine("""
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
""");
foreach (var method in ctx.Hub.Methods)
{
ctx.Writer.AppendLineWithFormat($$"""
if (ctx.EnableStreamingHubDiagnosticHandler)
{
ctx.Writer.AppendLineWithFormat($$"""
case {{method.HubId}}: // {{method.MethodReturnType.ToDisplayName()}} {{method.MethodName}}({{method.Parameters.ToMethodSignaturize()}})
diagnosticHandler?.OnResponseEvent<{{ctx.Hub.GetClientFullName()}}, {{method.ResponseType.FullName}}>(this, "{{method.MethodName}}", data);
base.SetResultForResponse<{{method.ResponseType.FullName}}>(taskSource, data);
break;
""");
}
else
{
ctx.Writer.AppendLineWithFormat($$"""
case {{method.HubId}}: // {{method.MethodReturnType.ToDisplayName()}} {{method.MethodName}}({{method.Parameters.ToMethodSignaturize()}})
base.SetResultForResponse<{{method.ResponseType.FullName}}>(taskCompletionSource, data);
base.SetResultForResponse<{{method.ResponseType.FullName}}>(taskSource, data);
break;
""");

}
}
ctx.Writer.AppendLine("""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public interface IStreamingHubDiagnosticHandler
/// <param name="invokeMethod"></param>
ValueTask<TResponse> OnMethodInvoke<THub, TRequest, TResponse>(THub hubInstance, int methodId, string methodName, TRequest request, bool isFireAndForget, InvokeMethodDelegate<TRequest, TResponse> invokeMethod);

/// <summary>
/// [Preview] The callback method when a method of HubReceiver is invoked. This API may change in the future.
/// </summary>
/// <typeparam name="THub"></typeparam>
/// <param name="hubInstance"></param>
/// <param name="methodId"></param>
/// <param name="data"></param>
void OnBroadcastEventRaw<THub>(THub hubInstance, int methodId, ReadOnlyMemory<byte> data);

/// <summary>
/// [Preview] The callback method when a method of HubReceiver is invoked. This API may change in the future.
/// </summary>
Expand All @@ -33,5 +42,15 @@ public interface IStreamingHubDiagnosticHandler
/// <param name="methodName"></param>
/// <param name="value"></param>
void OnBroadcastEvent<THub, T>(THub hubInstance, string methodName, T value);

/// <summary>
/// [Preview] The callback method when the return value of a hub method call is received. This API may change in the future.
/// </summary>
/// <typeparam name="THub"></typeparam>
/// <typeparam name="T"></typeparam>
/// <param name="hubInstance"></param>
/// <param name="methodName"></param>
/// <param name="data"></param>
void OnResponseEvent<THub, T>(THub hubInstance, string methodName, ReadOnlyMemory<byte> data);
}
}
19 changes: 19 additions & 0 deletions src/MagicOnion.Client/IStreamingHubDiagnosticHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public interface IStreamingHubDiagnosticHandler
/// <param name="invokeMethod"></param>
ValueTask<TResponse> OnMethodInvoke<THub, TRequest, TResponse>(THub hubInstance, int methodId, string methodName, TRequest request, bool isFireAndForget, InvokeMethodDelegate<TRequest, TResponse> invokeMethod);

/// <summary>
/// [Preview] The callback method when a method of HubReceiver is invoked. This API may change in the future.
/// </summary>
/// <typeparam name="THub"></typeparam>
/// <param name="hubInstance"></param>
/// <param name="methodId"></param>
/// <param name="data"></param>
void OnBroadcastEventRaw<THub>(THub hubInstance, int methodId, ReadOnlyMemory<byte> data);

/// <summary>
/// [Preview] The callback method when a method of HubReceiver is invoked. This API may change in the future.
/// </summary>
Expand All @@ -33,5 +42,15 @@ public interface IStreamingHubDiagnosticHandler
/// <param name="methodName"></param>
/// <param name="value"></param>
void OnBroadcastEvent<THub, T>(THub hubInstance, string methodName, T value);

/// <summary>
/// [Preview] The callback method when the return value of a hub method call is received. This API may change in the future.
/// </summary>
/// <typeparam name="THub"></typeparam>
/// <typeparam name="T"></typeparam>
/// <param name="hubInstance"></param>
/// <param name="methodName"></param>
/// <param name="data"></param>
void OnResponseEvent<THub, T>(THub hubInstance, string methodName, ReadOnlyMemory<byte> data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
case -1005848884: // Task A(global::TempProject.MyGenericObject<global::System.Int32> a)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
case -955516027: // Task B(global::TempProject.MyGenericObject<global::TempProject.MyObject> a)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,24 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
case 1774317884: // Task<Nil> GetStringValuesAsync(global::System.String[] arg0)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
case -400881550: // Task<Nil> GetIntValuesAsync(global::System.Int32[] arg0)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
case 309063297: // Task<Nil> GetInt32ValuesAsync(global::System.Int32[] arg0)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
case 702446639: // Task<Nil> GetSingleValuesAsync(global::System.Single[] arg0)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
case 2082077357: // Task<Nil> GetBooleanValuesAsync(global::System.Boolean[] arg0)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
case -209315513: // Task<Nil> GetValuesAsync(global::TempProject.MyResponse[] arg0)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
case 1774317884: // Task<Nil> GetStringValuesAsync(global::System.Collections.Generic.List<global::System.String> arg0)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
case -400881550: // Task<Nil> GetIntValuesAsync(global::System.Collections.Generic.List<global::System.Int32> arg0)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ protected override void OnBroadcastEvent(global::System.Int32 methodId, global::
}
}

protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskCompletionSource, global::System.ReadOnlyMemory<global::System.Byte> data)
protected override void OnResponseEvent(global::System.Int32 methodId, global::System.Object taskSource, global::System.ReadOnlyMemory<global::System.Byte> data)
{
switch (methodId)
{
case -209315513: // Task<Nil> GetValuesAsync(global::System.Collections.Generic.List<global::TempProject.MyResponse> arg0)
base.SetResultForResponse<global::MessagePack.Nil>(taskCompletionSource, data);
base.SetResultForResponse<global::MessagePack.Nil>(taskSource, data);
break;
}
}
Expand Down
Loading

0 comments on commit b0dee9d

Please sign in to comment.