Browse Source

Simplify "perform" interface of Call class

Tim Burks 9 years ago
parent
commit
10de2b3ce0

+ 18 - 26
Packages/gRPC/Sources/Call.swift

@@ -146,13 +146,11 @@ public class Call {
     }
   }
 
-  /// Initiate performance of a call without waiting for completion
+  /// Initiate performance of a group of operations without waiting for completion
   ///
-  /// - Parameter operations: array of operations to be performed
-  /// - Parameter completionQueue: completion queue used to wait for completion
+  /// - Parameter operations: group of operations to be performed
   /// - Returns: the result of initiating the call
-  func performOperations(operations: OperationGroup,
-                         completionQueue: CompletionQueue)
+  func perform(_ operations: OperationGroup)
     -> CallError {
       completionQueue.operationGroups[operations.tag] = operations
       let mutex = CallLock.sharedInstance.mutex
@@ -180,14 +178,14 @@ public class Call {
     let operation_receiveStatusOnClient = Operation_ReceiveStatusOnClient()
     let operation_receiveMessage = Operation_ReceiveMessage()
 
-    let group = OperationGroup(call:self,
-                               operations:[operation_sendInitialMetadata,
-                                           operation_sendMessage,
-                                           operation_sendCloseFromClient,
-                                           operation_receiveInitialMetadata,
-                                           operation_receiveStatusOnClient,
-                                           operation_receiveMessage],
-                               completion:
+    let operations = OperationGroup(call:self,
+                                    operations:[operation_sendInitialMetadata,
+                                                operation_sendMessage,
+                                                operation_sendCloseFromClient,
+                                                operation_receiveInitialMetadata,
+                                                operation_receiveStatusOnClient,
+                                                operation_receiveMessage],
+                                    completion:
       {(success) in
         if success {
           completion(CallResult(statusCode:operation_receiveStatusOnClient.status(),
@@ -204,13 +202,7 @@ public class Call {
         }
     })
 
-    return self.perform(operations: group)
-  }
-
-  // perform a group of operations (used internally)
-  private func perform(operations: OperationGroup) -> CallError {
-    return performOperations(operations:operations,
-                             completionQueue: self.completionQueue)
+    return self.perform(operations)
   }
 
   // start a streaming connection
@@ -261,7 +253,7 @@ public class Call {
         }
       }
     }
-    return self.perform(operations:operations)
+    return self.perform(operations)
   }
 
 
@@ -274,7 +266,7 @@ public class Call {
         callback(messageBuffer.data())
       }
     }
-    return self.perform(operations:operations)
+    return self.perform(operations)
   }
 
   // send initial metadata over a streaming connection
@@ -288,7 +280,7 @@ public class Call {
         return
       }
     }
-    return self.perform(operations:operations)
+    return self.perform(operations)
   }
 
   // receive initial metadata from a streaming connection
@@ -301,7 +293,7 @@ public class Call {
         print("Received initial metadata -> " + initialMetadata.key(index:j) + " : " + initialMetadata.value(index:j))
       }
     }
-    return self.perform(operations:operations)
+    return self.perform(operations)
   }
 
   // receive status from a streaming connection
@@ -312,7 +304,7 @@ public class Call {
     { (event) in
       print("status = \(operation_receiveStatus.status()), \(operation_receiveStatus.statusDetails())")
     }
-    return self.perform(operations:operations)
+    return self.perform(operations)
   }
 
   // close a streaming connection
@@ -322,6 +314,6 @@ public class Call {
     { (event) in
       completion()
     }
-    return self.perform(operations:operations)
+    return self.perform(operations)
   }
 }

+ 7 - 14
Packages/gRPC/Sources/Handler.swift

@@ -115,8 +115,7 @@ public class Handler {
         completion(nil)
       }
     }
-    _ = call.performOperations(operations:operations,
-                               completionQueue: self.completionQueue)
+    _ = call.perform(operations)
   }
 
   /// Sends the response to a request
@@ -140,8 +139,7 @@ public class Handler {
     {(call_error) in
       self.shutdown()
     }
-    _ = call.performOperations(operations:operations,
-                               completionQueue: self.completionQueue)
+    _ = call.perform(operations)
   }
 
   /// shutdown the handler's completion queue
@@ -161,8 +159,7 @@ public class Handler {
         completion()
       }
     }
-    _ = call.performOperations(operations:operations,
-                               completionQueue: self.completionQueue)
+    _ = call.perform(operations)
   }
 
   /// Receive the message sent with a call
@@ -184,8 +181,7 @@ public class Handler {
       }
     }
 
-    let call_error = call.performOperations(operations:operations,
-                                            completionQueue: self.completionQueue)
+    let call_error = call.perform(operations)
     print("perform receiveMessage \(call_error)")
   }
 
@@ -201,8 +197,7 @@ public class Handler {
       print("server sendResponse complete")
       completion()
     }
-    _ = call.performOperations(operations:operations,
-                               completionQueue: self.completionQueue)
+    _ = call.perform(operations)
   }
 
   /// Recognize when the client has closed a request
@@ -213,8 +208,7 @@ public class Handler {
       print("server receiveClose complete")
       completion()
     }
-    let call_error = call.performOperations(operations:operations,
-                                            completionQueue: self.completionQueue)
+    let call_error = call.perform(operations)
     print("perform receiveClose \(call_error)")
   }
 
@@ -229,7 +223,6 @@ public class Handler {
       print("server sendStatus complete")
       completion()
     }
-    _ = call.performOperations(operations:operations,
-                               completionQueue: self.completionQueue)
+    _ = call.perform(operations)
   }
 }

+ 2 - 2
gRPC.xcodeproj/project.pbxproj

@@ -55,11 +55,11 @@
 		D3AC86AC1D5BEBBE0042B341 /* server.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = server.c; path = Packages/CgRPC/Sources/server.c; sourceTree = "<group>"; };
 		D3AC86AD1D5BEBBE0042B341 /* cgrpc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cgrpc.h; path = Packages/CgRPC/Sources/cgrpc.h; sourceTree = "<group>"; };
 		D3AC86BB1D5BEBE00042B341 /* ByteBuffer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ByteBuffer.swift; path = Packages/gRPC/Sources/ByteBuffer.swift; sourceTree = "<group>"; };
-		D3AC86BC1D5BEBE00042B341 /* Call.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Call.swift; path = Packages/gRPC/Sources/Call.swift; sourceTree = "<group>"; };
+		D3AC86BC1D5BEBE00042B341 /* Call.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = Call.swift; path = Packages/gRPC/Sources/Call.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
 		D3AC86BD1D5BEBE00042B341 /* Client.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Client.swift; path = Packages/gRPC/Sources/Client.swift; sourceTree = "<group>"; };
 		D3AC86BE1D5BEBE00042B341 /* CompletionQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CompletionQueue.swift; path = Packages/gRPC/Sources/CompletionQueue.swift; sourceTree = "<group>"; };
 		D3AC86BF1D5BEBE00042B341 /* gRPC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = gRPC.swift; path = Packages/gRPC/Sources/gRPC.swift; sourceTree = "<group>"; };
-		D3AC86C01D5BEBE00042B341 /* Handler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Handler.swift; path = Packages/gRPC/Sources/Handler.swift; sourceTree = "<group>"; };
+		D3AC86C01D5BEBE00042B341 /* Handler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = Handler.swift; path = Packages/gRPC/Sources/Handler.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
 		D3AC86C11D5BEBE00042B341 /* Metadata.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Metadata.swift; path = Packages/gRPC/Sources/Metadata.swift; sourceTree = "<group>"; };
 		D3AC86C21D5BEBE00042B341 /* Mutex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Mutex.swift; path = Packages/gRPC/Sources/Mutex.swift; sourceTree = "<group>"; };
 		D3AC86C31D5BEBE00042B341 /* Operation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Operation.swift; path = Packages/gRPC/Sources/Operation.swift; sourceTree = "<group>"; };