Browse Source

Rename internal references to underlying grpc structs to use more explicit names.

Tim Burks 9 years ago
parent
commit
a97aa3c26d

+ 5 - 5
Packages/gRPC/Sources/ByteBuffer.swift

@@ -39,14 +39,14 @@ import Foundation // for String.Encoding
 public class ByteBuffer {
 
   /// Pointer to underlying C representation
-  internal var internalByteBuffer: UnsafeMutableRawPointer!
+  internal var underlyingByteBuffer: UnsafeMutableRawPointer!
 
   /// Creates a ByteBuffer from an underlying C representation.
   /// The ByteBuffer takes ownership of the passed-in representation.
   ///
   /// - Parameter underlyingByteBuffer: the underlying C representation
   internal init(underlyingByteBuffer: UnsafeMutableRawPointer) {
-    self.internalByteBuffer = underlyingByteBuffer
+    self.underlyingByteBuffer = underlyingByteBuffer
   }
 
   /// Creates a byte buffer that contains a copy of the contents of `data`
@@ -54,12 +54,12 @@ public class ByteBuffer {
   /// - Parameter data: the data to store in the buffer
   public init(data: Data) {
     data.withUnsafeBytes { (bytes) in
-      self.internalByteBuffer = cgrpc_byte_buffer_create_by_copying_data(bytes, data.count)
+      self.underlyingByteBuffer = cgrpc_byte_buffer_create_by_copying_data(bytes, data.count)
     }
   }
 
   deinit {
-    cgrpc_byte_buffer_destroy(internalByteBuffer);
+    cgrpc_byte_buffer_destroy(underlyingByteBuffer);
   }
 
   /// Gets data from the contents of the ByteBuffer
@@ -67,7 +67,7 @@ public class ByteBuffer {
   /// - Returns: data formed from the ByteBuffer contents
   public func data() -> Data? {
     var length : Int = 0
-    guard let bytes = cgrpc_byte_buffer_copy_data(internalByteBuffer, &length) else {
+    guard let bytes = cgrpc_byte_buffer_copy_data(underlyingByteBuffer, &length) else {
       return nil
     }
     return Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes),

+ 4 - 4
Packages/gRPC/Sources/Call.swift

@@ -51,7 +51,7 @@ public typealias SendMessageCompletion = (grpc_call_error) -> Void
 public class Call {
 
   /// Pointer to underlying C representation
-  private var call : UnsafeMutableRawPointer!
+  private var underlyingCall : UnsafeMutableRawPointer!
 
   /// Completion queue used for call
   private var completionQueue: CompletionQueue
@@ -70,7 +70,7 @@ public class Call {
   /// - Parameter call: the underlying C representation
   /// - Parameter owned: true if this instance is responsible for deleting the underlying call
   init(call: UnsafeMutableRawPointer, owned: Bool, completionQueue: CompletionQueue) {
-    self.call = call
+    self.underlyingCall = call
     self.owned = owned
     self.completionQueue = completionQueue
     self.pendingMessages = []
@@ -79,7 +79,7 @@ public class Call {
 
   deinit {
     if (owned) {
-      cgrpc_call_destroy(call)
+      cgrpc_call_destroy(underlyingCall)
     }
   }
 
@@ -94,7 +94,7 @@ public class Call {
     -> grpc_call_error {
       let mutex = CallLock.sharedInstance.mutex
       mutex.lock()
-      let error = cgrpc_call_perform(call, operations.operations, tag)
+      let error = cgrpc_call_perform(underlyingCall, operations.operations, tag)
       mutex.unlock()
       return error
   }

+ 8 - 8
Packages/gRPC/Sources/Client.swift

@@ -39,7 +39,7 @@ import Foundation
 public class Client {
 
   /// Pointer to underlying C representation
-  var c: UnsafeMutableRawPointer!
+  var underlyingClient: UnsafeMutableRawPointer!
 
   /// Completion queue for client call operations
   private var completionQueue: CompletionQueue
@@ -48,8 +48,8 @@ public class Client {
   ///
   /// - Parameter address: the address of the server to be called
   public init(address: String) {
-    c = cgrpc_client_create(address)
-    completionQueue = CompletionQueue(cq:cgrpc_client_completion_queue(c))
+    underlyingClient = cgrpc_client_create(address)
+    completionQueue = CompletionQueue(underlyingCompletionQueue:cgrpc_client_completion_queue(underlyingClient))
     completionQueue.name = "Client" // only for debugging
     self.completionQueue.run() {} // start a loop that watches the client's completion queue
   }
@@ -63,17 +63,17 @@ public class Client {
       let url = bundle.url(forResource: "roots", withExtension: "pem")!
       let data = try! Data(contentsOf: url)
       let s = String(data: data, encoding: .ascii)
-      c = cgrpc_client_create_secure(address, s, host)
+      underlyingClient = cgrpc_client_create_secure(address, s, host)
     } else {
-      c = cgrpc_client_create_secure(address, certificates, host)
+      underlyingClient = cgrpc_client_create_secure(address, certificates, host)
     }
-    completionQueue = CompletionQueue(cq:cgrpc_client_completion_queue(c))
+    completionQueue = CompletionQueue(underlyingCompletionQueue:cgrpc_client_completion_queue(underlyingClient))
     completionQueue.name = "Client" // only for debugging
     self.completionQueue.run() {} // start a loop that watches the client's completion queue
   }
 
   deinit {
-    cgrpc_client_destroy(c)
+    cgrpc_client_destroy(underlyingClient)
   }
 
   /// Constructs a Call object to make a gRPC API call
@@ -83,7 +83,7 @@ public class Client {
   /// - Parameter timeout: a timeout value in seconds
   /// - Returns: a Call object that can be used to perform the request
   public func createCall(host:String, method:String, timeout:Double) -> Call {
-    let call = cgrpc_client_create_call(c, method, host, timeout)!
+    let call = cgrpc_client_create_call(underlyingClient, method, host, timeout)!
     return Call(call:call, owned:true, completionQueue:self.completionQueue)
   }
 }

+ 5 - 5
Packages/gRPC/Sources/CompletionQueue.swift

@@ -41,7 +41,7 @@ class CompletionQueue {
   var name : String!
 
   /// Pointer to underlying C representation
-  var cq : UnsafeMutableRawPointer!
+  var underlyingCompletionQueue : UnsafeMutableRawPointer!
 
   /// Operation groups that are awaiting completion, keyed by tag
   var operationGroups : [Int64 : OperationGroup] = [:]
@@ -49,8 +49,8 @@ class CompletionQueue {
   /// Initializes a CompletionQueue
   ///
   /// - Parameter cq: the underlying C representation
-  init(cq: UnsafeMutableRawPointer) {
-    self.cq = cq // NOT OWNED, so we don't dealloc it
+  init(underlyingCompletionQueue: UnsafeMutableRawPointer) {
+    self.underlyingCompletionQueue = underlyingCompletionQueue // NOT OWNED, so we don't dealloc it
   }
 
   /// Waits for an event to complete
@@ -58,7 +58,7 @@ class CompletionQueue {
   /// - Parameter timeout: a timeout value in seconds
   /// - Returns: a grpc_completion_type code indicating the result of waiting
   public func waitForCompletion(timeout: Double) -> grpc_event {
-    return cgrpc_completion_queue_get_next_event(cq, timeout);
+    return cgrpc_completion_queue_get_next_event(underlyingCompletionQueue, timeout);
   }
 
   /// Run a completion queue
@@ -66,7 +66,7 @@ class CompletionQueue {
     DispatchQueue.global().async {
       var running = true
       while (running) {
-        let event = cgrpc_completion_queue_get_next_event(self.cq, -1.0)
+        let event = cgrpc_completion_queue_get_next_event(self.underlyingCompletionQueue, -1.0)
         switch (event.type) {
         case GRPC_OP_COMPLETE:
           let tag = cgrpc_event_tag(event)

+ 11 - 11
Packages/gRPC/Sources/Handler.swift

@@ -38,7 +38,7 @@ import Foundation // for String.Encoding
 /// A gRPC request handler
 public class Handler {
   /// Pointer to underlying C representation
-  var h: UnsafeMutableRawPointer!
+  var underlyingHandler: UnsafeMutableRawPointer!
 
   /// Completion queue for handler response operations
   var completionQueue: CompletionQueue
@@ -49,43 +49,43 @@ public class Handler {
   /// Initializes a Handler
   ///
   /// - Parameter h: the underlying C representation
-  init(h:UnsafeMutableRawPointer!) {
-    self.h = h;
+  init(underlyingHandler:UnsafeMutableRawPointer!) {
+    self.underlyingHandler = underlyingHandler;
     self.requestMetadata = Metadata()
-    self.completionQueue = CompletionQueue(cq:cgrpc_handler_get_completion_queue(h))
+    self.completionQueue = CompletionQueue(underlyingCompletionQueue:cgrpc_handler_get_completion_queue(underlyingHandler))
     self.completionQueue.name = "Handler"
   }
 
   deinit {
-    cgrpc_handler_destroy(self.h)
+    cgrpc_handler_destroy(self.underlyingHandler)
   }
 
   /// Gets the host name sent with the request
   ///
   /// - Returns: the host name sent with the request
   public func host() -> String {
-    return String(cString:cgrpc_handler_host(h), encoding:String.Encoding.utf8)!;
+    return String(cString:cgrpc_handler_host(underlyingHandler), encoding:String.Encoding.utf8)!;
   }
 
   /// Gets the method name sent with the request
   ///
   /// - Returns: the method name sent with the request
   public func method() -> String {
-    return String(cString:cgrpc_handler_method(h), encoding:String.Encoding.utf8)!;
+    return String(cString:cgrpc_handler_method(underlyingHandler), encoding:String.Encoding.utf8)!;
   }
 
   /// Gets the caller identity associated with the request
   ///
   /// - Returns: a string representing the caller address
   public func caller() -> String {
-    return String(cString:cgrpc_handler_call_peer(h), encoding:String.Encoding.utf8)!;
+    return String(cString:cgrpc_handler_call_peer(underlyingHandler), encoding:String.Encoding.utf8)!;
   }
 
   /// Creates a call object associated with the handler
   ///
   /// - Returns: a Call object that can be used to respond to the request
   func call() -> Call {
-    return Call(call: cgrpc_handler_get_call(h),
+    return Call(call: cgrpc_handler_get_call(underlyingHandler),
                 owned: false,
                 completionQueue: self.completionQueue)
   }
@@ -96,7 +96,7 @@ public class Handler {
   ///
   /// - Returns: a grpc_call_error indicating the result of requesting the call
   func requestCall(tag: Int) -> grpc_call_error {
-    return cgrpc_handler_request_call(h, requestMetadata.array, tag)
+    return cgrpc_handler_request_call(underlyingHandler, requestMetadata.array, tag)
   }
 
   /// Receive the message sent with a call
@@ -151,7 +151,7 @@ public class Handler {
 
   /// shutdown the handler's completion queue
   public func shutdown() {
-    cgrpc_completion_queue_shutdown(completionQueue.cq)
+    cgrpc_completion_queue_shutdown(completionQueue.underlyingCompletionQueue)
   }
 
   /// Send initial metadata in response to a connection

+ 5 - 5
Packages/gRPC/Sources/Mutex.swift

@@ -39,15 +39,15 @@
 public class Mutex {
 
   /// Pointer to underlying C representation
-  private var mu: UnsafeMutableRawPointer!
+  private var underlyingMutex: UnsafeMutableRawPointer!
 
   /// Initializes a Mutex
   public init() {
-    mu = cgrpc_mutex_create();
+    underlyingMutex = cgrpc_mutex_create();
   }
 
   deinit {
-    cgrpc_mutex_destroy(mu);
+    cgrpc_mutex_destroy(underlyingMutex);
   }
 
   /// Locks a Mutex
@@ -58,13 +58,13 @@ public class Mutex {
   ///
   /// May block indefinitely or crash if the calling thread has a lock on the Mutex.
   public func lock() {
-    cgrpc_mutex_lock(mu);
+    cgrpc_mutex_lock(underlyingMutex);
   }
 
   /// Unlocks a Mutex
   ///
   /// Releases an exclusive lock on the Mutex held by the calling thread.
   public func unlock() {
-    cgrpc_mutex_unlock(mu);
+    cgrpc_mutex_unlock(underlyingMutex);
   }
 }

+ 1 - 1
Packages/gRPC/Sources/Operation.swift

@@ -72,7 +72,7 @@ class Operation_SendMessage : Operation {
   /// - Parameter message: the message to send
   init(message:ByteBuffer) {
     super.init(observer:cgrpc_observer_create_send_message())
-    cgrpc_observer_send_message_set_message(observer, message.internalByteBuffer);
+    cgrpc_observer_send_message_set_message(observer, message.underlyingByteBuffer);
   }
 }
 

+ 10 - 10
Packages/gRPC/Sources/Server.swift

@@ -39,7 +39,7 @@ import Foundation
 public class Server {
 
   /// Pointer to underlying C representation
-  var s: UnsafeMutableRawPointer!
+  var underlyingServer: UnsafeMutableRawPointer!
 
   /// Completion queue used for server operations
   var completionQueue: CompletionQueue
@@ -54,30 +54,30 @@ public class Server {
   ///
   /// - Parameter address: the address where the server will listen
   public init(address:String) {
-    s = cgrpc_server_create(address)
-    completionQueue = CompletionQueue(cq:cgrpc_server_get_completion_queue(s))
+    underlyingServer = cgrpc_server_create(address)
+    completionQueue = CompletionQueue(underlyingCompletionQueue:cgrpc_server_get_completion_queue(underlyingServer))
     completionQueue.name = "Server " + address
     handlers = NSMutableSet()
   }
 
   public init(address:String, key:String, certs:String) {
-    s = cgrpc_server_create_secure(address, key, certs)
-    completionQueue = CompletionQueue(cq:cgrpc_server_get_completion_queue(s))
+    underlyingServer = cgrpc_server_create_secure(address, key, certs)
+    completionQueue = CompletionQueue(underlyingCompletionQueue:cgrpc_server_get_completion_queue(underlyingServer))
     completionQueue.name = "Server " + address
     handlers = NSMutableSet()
   }
 
   deinit {
-    cgrpc_server_destroy(s)
+    cgrpc_server_destroy(underlyingServer)
   }
 
   /// Run the server
   public func run(handlerFunction: @escaping (Handler) -> Void) {
-    cgrpc_server_start(s);
+    cgrpc_server_start(underlyingServer);
     DispatchQueue.global().async {
       var running = true
       while(running) {
-        let handler = Handler(h:cgrpc_handler_create_with_server(self.s))
+        let handler = Handler(underlyingHandler:cgrpc_handler_create_with_server(self.underlyingServer))
         let call_error = handler.requestCall(tag:101)
         if (call_error != GRPC_CALL_OK) {
           // not good, let's break
@@ -112,7 +112,7 @@ public class Server {
   }
 
   public func stop() {
-    cgrpc_server_stop(s)
+    cgrpc_server_stop(underlyingServer)
   }
 
   public func onCompletion(completion:@escaping (() -> Void)) -> Void {
@@ -123,7 +123,7 @@ public class Server {
   ///
   /// - Returns: a tuple containing the results of waiting and a possible Handler for the request
   private func getNextRequest(timeout: Double) -> (grpc_call_error, grpc_completion_type, Handler?) {
-    let handler = Handler(h:cgrpc_handler_create_with_server(s))
+    let handler = Handler(underlyingHandler:cgrpc_handler_create_with_server(underlyingServer))
     let call_error = handler.requestCall(tag:101)
     if (call_error != GRPC_CALL_OK) {
       return (call_error, GRPC_OP_COMPLETE, nil)