Skip to content

Commit

Permalink
Adopt SpellbookFoundation 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkenso committed Jun 5, 2024
1 parent abb4629 commit a485bd8
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public final class ESXPCClient: ESClientProtocol {
}

try connectionLock.withLock {
try syncExecutor { callback in
try syncExecutor.sync { callback in
let proxy = try connection.remoteObjectProxy { callback($0) }
.get(name: "ESXPCConnection", description: "ES XPC client is not connected")
try body(proxy, callback)
Expand All @@ -314,7 +314,7 @@ public final class ESXPCClient: ESClientProtocol {
body: @escaping (ESClientXPCProtocol, @escaping (Result<T, Error>) -> Void) throws -> Void
) throws -> T {
try connectionLock.withLock {
try syncExecutor { (callback: @escaping (Result<T, Error>) -> Void) in
try syncExecutor.sync { (callback: @escaping (Result<T, Error>) -> Void) in
let proxy = try connection.remoteObjectProxy { callback(.failure($0)) }
.get(name: "ESXPCConnection", description: "ES XPC client is not connected")
try body(proxy, callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private final class ESXPCExportedObject: NSObject, ESClientXPCProtocol {
do {
let encoded = try xpcEncoder.encode(process)
let executor = SynchronousExecutor("HandlePathInterest", timeout: 5.0)
guard let interest = try executor({ reply in
guard let interest = try executor.sync({ reply in
DispatchQueue.global().async { self.delegate.handlePathInterest(encoded, reply: reply) }
}) else {
return .listen()
Expand Down
6 changes: 3 additions & 3 deletions Mac/Tests/SpellbookMacTests/Users & Groups/ACLTests.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import SpellbookMac

import SpellbookTestUtils
import SpellbookFoundation
import XCTest

private let fm = FileManager.default

class ACLTests: XCTestCase {
let tmpRoot = TestTemporaryDirectory(prefix: "ACLTests")
let tmpRoot = TemporaryDirectory.bundle.directory(prefix: "ACLTests")

override func setUpWithError() throws {
try super.setUpWithError()
Expand All @@ -19,7 +19,7 @@ class ACLTests: XCTestCase {
}

func test() throws {
let path = tmpRoot.url.path
let path = tmpRoot.location.path
XCTAssertThrowsError(try FileManager.default.acl(atPath: path))
XCTAssertThrowsError(try fm.acl(atPath: "/foo/nonexistent"))

Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
.library(name: "SpellbookXPC", targets: ["SpellbookXPC"]),
],
dependencies: [
.package(url: "https://github.com/Alkenso/SwiftSpellbook.git", from: "0.4.2"),
.package(url: "https://github.com/Alkenso/SwiftSpellbook.git", from: "1.0.0"),
],
targets: [
// MacShims.
Expand Down Expand Up @@ -113,6 +113,7 @@ let package = Package(
dependencies: [
"SpellbookMac",
.product(name: "SpellbookFoundation", package: "SwiftSpellbook"),
.product(name: "SpellbookBinaryParsing", package: "SwiftSpellbook"),
],
path: "XPC/Sources/SpellbookXPC"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import Foundation
import SpellbookFoundation
import SpellbookBinaryParsing

private let clientHello = Data(UUID(staticString: "fef88fd3-9f29-4632-8827-0b417472c8f2").uuidString.utf8)
private let serverHello = Data(UUID(staticString: "071e1957-bf27-4669-961a-7e707b980740").uuidString.utf8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public class XPCTransportServer {
self.connectionOpened?(transport.peerInfo)
case .invalidated:
self.connectionClosed?(transport.peerInfo)
self.connections.writeAsync { $0.removeValue(forKey: id) }
self.connections.write { _ = $0.removeValue(forKey: id) }
case .connecting:
break
}
}
prepareNewConnectionReceive?(transport)

connections.writeAsync { $0[id] = transport }
connections.write { $0[id] = transport }
transport.activate()
}
}
Expand Down
4 changes: 2 additions & 2 deletions XPC/Sources/SpellbookXPC/XPCConnection/XPCClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class XPCClient<RemoteInterface, ExportedInterface, ConnectedState> {

/// Observalbe state of the connection. The value is present when connection is alive.
/// Can be used to monitor connection state (connected/not connected).
public let connectedState: Observable<ConnectedState?>
public let connectedState: ValueObservable<ConnectedState?>

// Get a proxy for the remote object (that is, the object exported from the other side of this connection).
public func remoteObjectProxy(synchronous: Bool = false, errorHandler: ((Error) -> Void)? = nil) -> RemoteInterface {
Expand Down Expand Up @@ -113,7 +113,7 @@ public class XPCClient<RemoteInterface, ExportedInterface, ConnectedState> {

self.queue = DispatchQueue(label: "\(Self.self).queue")
self.connectedStateStore = infoStore
self.connectedState = infoStore.asObservable
self.connectedState = infoStore.observable
self.connection = createConnection(.connection(.init(serviceName: "not activated connection")))
self.createConnection = createConnection
}
Expand Down
4 changes: 2 additions & 2 deletions XPC/Sources/SpellbookXPC/XPCConnection/XPCConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ extension XPCConnection {
}

private func registerInStorage() {
_currentConnectionStorage.writeAsync { $0[ObjectIdentifier(self.native)] = Weak(self) }
_currentConnectionStorage.write { $0[ObjectIdentifier(self.native)] = Weak(self) }
}

private func unregisterFromStorage() {
_currentConnectionStorage.writeAsync { [id = ObjectIdentifier(native)] in $0.removeValue(forKey: id) }
_currentConnectionStorage.write { [id = ObjectIdentifier(native)] in _ = $0.removeValue(forKey: id) }
}
}

Expand Down
46 changes: 0 additions & 46 deletions XPC/Sources/SpellbookXPC/XPCConnection/XPCListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,49 +140,3 @@ extension XPCListenerInit {
}
}
}

// MARK: - AnyXPCListener

public extension XPCListenerProtocol {
func eraseToAnyXPCListener() -> AnyXPCListener<Self.ExportedInterface, Self.RemoteInterface> {
AnyXPCListener(self)
}
}

public class AnyXPCListener<ExportedInterface, RemoteInterface>: XPCListenerProtocol {
private let _newConnectionHandler: GetSet<((XPCConnection<ExportedInterface, RemoteInterface>) -> Bool)?>
private let _verifyConnectionHandler: GetSet<((audit_token_t) -> Bool)?>
private let _resume: () -> Void
private let _suspend: () -> Void
private let _invalidate: () -> Void

public init<Listener: XPCListenerProtocol>(_ listener: Listener) where Listener.ExportedInterface == ExportedInterface, Listener.RemoteInterface == RemoteInterface {
self._newConnectionHandler = GetSet(listener, \.newConnectionHandler)
self._verifyConnectionHandler = GetSet(listener, \.verifyConnectionHandler)
self._resume = listener.resume
self._suspend = listener.suspend
self._invalidate = listener.invalidate
}

public var newConnectionHandler: ((XPCConnection<ExportedInterface, RemoteInterface>) -> Bool)? {
get { _newConnectionHandler.get() }
set { _newConnectionHandler.set(newValue) }
}

public var verifyConnectionHandler: ((audit_token_t) -> Bool)? {
get { _verifyConnectionHandler.get() }
set { _verifyConnectionHandler.set(newValue) }
}

public func resume() {
_resume()
}

public func suspend() {
_suspend()
}

public func invalidate() {
_invalidate()
}
}

0 comments on commit a485bd8

Please sign in to comment.