Other: Event Stream refactor.

Other: GRPCClient keeps track of the event stream status. [skip-ci]
Other: renamed StartEventStream to RunEventStream for clarity. [skip-ci]
This commit is contained in:
Xavier Michelon
2022-08-22 15:46:54 +02:00
committed by Jakub
parent 35d2cc9be7
commit 275a92ae93
13 changed files with 152 additions and 127 deletions

View File

@ -40,8 +40,9 @@ const (
)
//**********************************************************
// Log related message
// Log related message
//**********************************************************
// Note: the enum values are prefixed with 'LOG_' to avoid a clash in C++ on Windows with the ERROR macro defined in wingdi.h
type LogLevel int32
const (
@ -4124,7 +4125,7 @@ var file_bridge_proto_rawDesc = []byte{
0x6f, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x13, 0x0a, 0x0f, 0x49, 0x4d, 0x41, 0x50, 0x5f, 0x50,
0x4f, 0x52, 0x54, 0x5f, 0x49, 0x53, 0x53, 0x55, 0x45, 0x10, 0x00, 0x12, 0x13, 0x0a, 0x0f, 0x53,
0x4d, 0x54, 0x50, 0x5f, 0x50, 0x4f, 0x52, 0x54, 0x5f, 0x49, 0x53, 0x53, 0x55, 0x45, 0x10, 0x01,
0x32, 0xc0, 0x1d, 0x0a, 0x06, 0x42, 0x72, 0x69, 0x64, 0x67, 0x65, 0x12, 0x3f, 0x0a, 0x0b, 0x41,
0x32, 0xbe, 0x1d, 0x0a, 0x06, 0x42, 0x72, 0x69, 0x64, 0x67, 0x65, 0x12, 0x3f, 0x0a, 0x0b, 0x41,
0x64, 0x64, 0x4c, 0x6f, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x18, 0x2e, 0x67, 0x72, 0x70,
0x63, 0x2e, 0x41, 0x64, 0x64, 0x4c, 0x6f, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
@ -4351,20 +4352,20 @@ var file_bridge_proto_rawDesc = []byte{
0x4d, 0x61, 0x69, 0x6c, 0x12, 0x1f, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6f, 0x6e, 0x66,
0x69, 0x67, 0x75, 0x72, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x4d, 0x61, 0x69, 0x6c, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x41, 0x0a,
0x10, 0x53, 0x74, 0x61, 0x72, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61,
0x6d, 0x12, 0x18, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74,
0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x67, 0x72,
0x70, 0x63, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x01,
0x12, 0x41, 0x0a, 0x0f, 0x53, 0x74, 0x6f, 0x70, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72,
0x65, 0x61, 0x6d, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f,
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d,
0x70, 0x74, 0x79, 0x42, 0x36, 0x5a, 0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f,
0x6d, 0x2f, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x6e, 0x4d, 0x61, 0x69, 0x6c, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x6e, 0x2d, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x2f, 0x76, 0x32, 0x2f, 0x69, 0x6e,
0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x3f, 0x0a,
0x0e, 0x52, 0x75, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12,
0x18, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65,
0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x67, 0x72, 0x70, 0x63,
0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x01, 0x12, 0x41,
0x0a, 0x0f, 0x53, 0x74, 0x6f, 0x70, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61,
0x6d, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74,
0x79, 0x42, 0x36, 0x5a, 0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x6e, 0x4d, 0x61, 0x69, 0x6c, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x6e, 0x2d, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x2f, 0x76, 0x32, 0x2f, 0x69, 0x6e, 0x74, 0x65,
0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
}
var (
@ -4554,7 +4555,7 @@ var file_bridge_proto_depIdxs = []int32{
64, // 101: grpc.Bridge.LogoutUser:input_type -> google.protobuf.StringValue
64, // 102: grpc.Bridge.RemoveUser:input_type -> google.protobuf.StringValue
15, // 103: grpc.Bridge.ConfigureUserAppleMail:input_type -> grpc.ConfigureAppleMailRequest
16, // 104: grpc.Bridge.StartEventStream:input_type -> grpc.EventStreamRequest
16, // 104: grpc.Bridge.RunEventStream:input_type -> grpc.EventStreamRequest
62, // 105: grpc.Bridge.StopEventStream:input_type -> google.protobuf.Empty
62, // 106: grpc.Bridge.AddLogEntry:output_type -> google.protobuf.Empty
62, // 107: grpc.Bridge.GuiReady:output_type -> google.protobuf.Empty
@ -4609,7 +4610,7 @@ var file_bridge_proto_depIdxs = []int32{
62, // 156: grpc.Bridge.LogoutUser:output_type -> google.protobuf.Empty
62, // 157: grpc.Bridge.RemoveUser:output_type -> google.protobuf.Empty
62, // 158: grpc.Bridge.ConfigureUserAppleMail:output_type -> google.protobuf.Empty
17, // 159: grpc.Bridge.StartEventStream:output_type -> grpc.StreamEvent
17, // 159: grpc.Bridge.RunEventStream:output_type -> grpc.StreamEvent
62, // 160: grpc.Bridge.StopEventStream:output_type -> google.protobuf.Empty
106, // [106:161] is the sub-list for method output_type
51, // [51:106] is the sub-list for method input_type

View File

@ -97,7 +97,7 @@ service Bridge {
rpc ConfigureUserAppleMail(ConfigureAppleMailRequest) returns (google.protobuf.Empty);
// Server -> Client event stream
rpc StartEventStream(EventStreamRequest) returns (stream StreamEvent); // Keep streaming until StopEventStream is called.
rpc RunEventStream(EventStreamRequest) returns (stream StreamEvent); // Keep streaming until StopEventStream is called.
rpc StopEventStream(google.protobuf.Empty) returns (google.protobuf.Empty);
}

View File

@ -85,7 +85,7 @@ type BridgeClient interface {
RemoveUser(ctx context.Context, in *wrapperspb.StringValue, opts ...grpc.CallOption) (*emptypb.Empty, error)
ConfigureUserAppleMail(ctx context.Context, in *ConfigureAppleMailRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
// Server -> Client event stream
StartEventStream(ctx context.Context, in *EventStreamRequest, opts ...grpc.CallOption) (Bridge_StartEventStreamClient, error)
RunEventStream(ctx context.Context, in *EventStreamRequest, opts ...grpc.CallOption) (Bridge_RunEventStreamClient, error)
StopEventStream(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error)
}
@ -574,12 +574,12 @@ func (c *bridgeClient) ConfigureUserAppleMail(ctx context.Context, in *Configure
return out, nil
}
func (c *bridgeClient) StartEventStream(ctx context.Context, in *EventStreamRequest, opts ...grpc.CallOption) (Bridge_StartEventStreamClient, error) {
stream, err := c.cc.NewStream(ctx, &Bridge_ServiceDesc.Streams[0], "/grpc.Bridge/StartEventStream", opts...)
func (c *bridgeClient) RunEventStream(ctx context.Context, in *EventStreamRequest, opts ...grpc.CallOption) (Bridge_RunEventStreamClient, error) {
stream, err := c.cc.NewStream(ctx, &Bridge_ServiceDesc.Streams[0], "/grpc.Bridge/RunEventStream", opts...)
if err != nil {
return nil, err
}
x := &bridgeStartEventStreamClient{stream}
x := &bridgeRunEventStreamClient{stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
}
@ -589,16 +589,16 @@ func (c *bridgeClient) StartEventStream(ctx context.Context, in *EventStreamRequ
return x, nil
}
type Bridge_StartEventStreamClient interface {
type Bridge_RunEventStreamClient interface {
Recv() (*StreamEvent, error)
grpc.ClientStream
}
type bridgeStartEventStreamClient struct {
type bridgeRunEventStreamClient struct {
grpc.ClientStream
}
func (x *bridgeStartEventStreamClient) Recv() (*StreamEvent, error) {
func (x *bridgeRunEventStreamClient) Recv() (*StreamEvent, error) {
m := new(StreamEvent)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
@ -680,7 +680,7 @@ type BridgeServer interface {
RemoveUser(context.Context, *wrapperspb.StringValue) (*emptypb.Empty, error)
ConfigureUserAppleMail(context.Context, *ConfigureAppleMailRequest) (*emptypb.Empty, error)
// Server -> Client event stream
StartEventStream(*EventStreamRequest, Bridge_StartEventStreamServer) error
RunEventStream(*EventStreamRequest, Bridge_RunEventStreamServer) error
StopEventStream(context.Context, *emptypb.Empty) (*emptypb.Empty, error)
mustEmbedUnimplementedBridgeServer()
}
@ -848,8 +848,8 @@ func (UnimplementedBridgeServer) RemoveUser(context.Context, *wrapperspb.StringV
func (UnimplementedBridgeServer) ConfigureUserAppleMail(context.Context, *ConfigureAppleMailRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method ConfigureUserAppleMail not implemented")
}
func (UnimplementedBridgeServer) StartEventStream(*EventStreamRequest, Bridge_StartEventStreamServer) error {
return status.Errorf(codes.Unimplemented, "method StartEventStream not implemented")
func (UnimplementedBridgeServer) RunEventStream(*EventStreamRequest, Bridge_RunEventStreamServer) error {
return status.Errorf(codes.Unimplemented, "method RunEventStream not implemented")
}
func (UnimplementedBridgeServer) StopEventStream(context.Context, *emptypb.Empty) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method StopEventStream not implemented")
@ -1821,24 +1821,24 @@ func _Bridge_ConfigureUserAppleMail_Handler(srv interface{}, ctx context.Context
return interceptor(ctx, in, info, handler)
}
func _Bridge_StartEventStream_Handler(srv interface{}, stream grpc.ServerStream) error {
func _Bridge_RunEventStream_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(EventStreamRequest)
if err := stream.RecvMsg(m); err != nil {
return err
}
return srv.(BridgeServer).StartEventStream(m, &bridgeStartEventStreamServer{stream})
return srv.(BridgeServer).RunEventStream(m, &bridgeRunEventStreamServer{stream})
}
type Bridge_StartEventStreamServer interface {
type Bridge_RunEventStreamServer interface {
Send(*StreamEvent) error
grpc.ServerStream
}
type bridgeStartEventStreamServer struct {
type bridgeRunEventStreamServer struct {
grpc.ServerStream
}
func (x *bridgeStartEventStreamServer) Send(m *StreamEvent) error {
func (x *bridgeRunEventStreamServer) Send(m *StreamEvent) error {
return x.ServerStream.SendMsg(m)
}
@ -2086,8 +2086,8 @@ var Bridge_ServiceDesc = grpc.ServiceDesc{
},
Streams: []grpc.StreamDesc{
{
StreamName: "StartEventStream",
Handler: _Bridge_StartEventStream_Handler,
StreamName: "RunEventStream",
Handler: _Bridge_RunEventStream_Handler,
ServerStreams: true,
},
},

View File

@ -26,8 +26,8 @@ import (
"google.golang.org/protobuf/types/known/emptypb"
)
// StartEventStream implement the gRPC server->Client event stream.
func (s *Service) StartEventStream(request *EventStreamRequest, server Bridge_StartEventStreamServer) error {
// RunEventStream implement the gRPC server->Client event stream.
func (s *Service) RunEventStream(request *EventStreamRequest, server Bridge_RunEventStreamServer) error {
s.log.Info("Starting Event stream")
if s.eventStreamCh != nil {