Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 62 additions & 14 deletions Sources/GRPC/CallHandlers/CallHandlerFactory.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* Copyright 2020, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2020, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import NIO
import SwiftProtobuf

Expand All @@ -34,6 +34,18 @@ public enum CallHandlerFactory {
)
}

public static func makeUnary<Request: GRPCPayload, Response: GRPCPayload>(
callHandlerContext: CallHandlerContext,
eventObserverFactory: @escaping (UnaryContext<Response>) -> UnaryEventObserver<Request, Response>
) -> UnaryCallHandler<Request, Response> {
return UnaryCallHandler(
serializer: GRPCPayloadSerializer(),
deserializer: GRPCPayloadDeserializer(),
callHandlerContext: callHandlerContext,
eventObserverFactory: eventObserverFactory
)
}

public typealias ClientStreamingContext<Response> = UnaryResponseCallContext<Response>
public typealias ClientStreamingEventObserver<Request> = EventLoopFuture<(StreamEvent<Request>) -> Void>

Expand All @@ -49,6 +61,18 @@ public enum CallHandlerFactory {
)
}

public static func makeClientStreaming<Request: GRPCPayload, Response: GRPCPayload>(
callHandlerContext: CallHandlerContext,
eventObserverFactory: @escaping (ClientStreamingContext<Response>) -> ClientStreamingEventObserver<Request>
) -> ClientStreamingCallHandler<Request, Response> {
return ClientStreamingCallHandler(
serializer: GRPCPayloadSerializer(),
deserializer: GRPCPayloadDeserializer(),
callHandlerContext: callHandlerContext,
eventObserverFactory: eventObserverFactory
)
}

public typealias ServerStreamingContext<Response> = StreamingResponseCallContext<Response>
public typealias ServerStreamingEventObserver<Request> = (Request) -> EventLoopFuture<GRPCStatus>

Expand All @@ -64,6 +88,18 @@ public enum CallHandlerFactory {
)
}

public static func makeServerStreaming<Request: GRPCPayload, Response: GRPCPayload>(
callHandlerContext: CallHandlerContext,
eventObserverFactory: @escaping (ServerStreamingContext<Response>) -> ServerStreamingEventObserver<Request>
) -> ServerStreamingCallHandler<Request, Response> {
return ServerStreamingCallHandler(
serializer: GRPCPayloadSerializer(),
deserializer: GRPCPayloadDeserializer(),
callHandlerContext: callHandlerContext,
eventObserverFactory: eventObserverFactory
)
}

public typealias BidirectionalStreamingContext<Response> = StreamingResponseCallContext<Response>
public typealias BidirectionalStreamingEventObserver<Request> = EventLoopFuture<(StreamEvent<Request>) -> Void>

Expand All @@ -78,4 +114,16 @@ public enum CallHandlerFactory {
eventObserverFactory: eventObserverFactory
)
}

public static func makeBidirectionalStreaming<Request: GRPCPayload, Response: GRPCPayload>(
callHandlerContext: CallHandlerContext,
eventObserverFactory: @escaping (BidirectionalStreamingContext<Response>) -> BidirectionalStreamingEventObserver<Request>
) -> BidirectionalStreamingCallHandler<Request, Response> {
return BidirectionalStreamingCallHandler(
serializer: GRPCPayloadSerializer(),
deserializer: GRPCPayloadDeserializer(),
callHandlerContext: callHandlerContext,
eventObserverFactory: eventObserverFactory
)
}
}
Loading