← XPC

C API Referansı

XPC Dokümantasyonu

C ve Objective-C projeleri için düşük seviyeli XPC dinleyici, oturum ve bağlantı API'leri.


xpc_listener_t

Tip Takma Adı (Type Alias) | XPC

Süreç sınırları boyunca istemciler için görevler gerçekleştiren C tipi.

typealias xpc_listener_t = OS_xpc_listener

xpc_listener_t, Swift XPCListener sınıfının C karşılığıdır. Referans sayımlı ve eşzamanlılık açısından güvenlidir.

Dinleyici Oluşturma

// XPC servisi için dinleyici
xpc_listener_t xpc_listener_create(
    const char *service,
    dispatch_queue_t _Nullable target_queue,
    uint64_t flags,
    xpc_listener_incoming_session_handler_t handler)

// Mach servisi için dinleyici
xpc_listener_t xpc_listener_create_for_mach_service(
    const char *mach_service,
    dispatch_queue_t _Nullable target_queue,
    uint64_t flags,
    xpc_listener_incoming_session_handler_t handler)

// Anonim dinleyici (geçerli süreç)
xpc_listener_t xpc_listener_create_for_current_process(
    dispatch_queue_t _Nullable target_queue,
    uint64_t flags,
    xpc_listener_incoming_session_handler_t handler)

Yaşam Döngüsü

void xpc_listener_activate(xpc_listener_t listener)
void xpc_listener_cancel(xpc_listener_t listener)
xpc_endpoint_t xpc_listener_copy_endpoint(xpc_listener_t listener)

Uyum

  • CVarArg, Equatable, Hashable, NSObjectProtocol, Sendable, SendableMetatype

xpc_session_t

Tip Takma Adı | XPC

Bir sunucu sürecine mesaj gönderen C tipi.

typealias xpc_session_t = OS_xpc_session

xpc_session_t, Swift XPCSession sınıfının C karşılığıdır.

Oturum Oluşturma

// XPC servisiyle oturum
xpc_session_t xpc_session_create_xpc_service(
    const char *name,
    dispatch_queue_t _Nullable target_queue,
    uint64_t flags,
    xpc_session_incoming_message_handler_t _Nullable handler)

// Mach servisiyle oturum
xpc_session_t xpc_session_create_mach_service(
    const char *mach_service,
    dispatch_queue_t _Nullable target_queue,
    uint64_t flags,
    xpc_session_incoming_message_handler_t _Nullable handler)

Oluşturma Bayrakları

| Bayrak | Açıklama | | --- | --- | | XPC_SESSION_CREATE_INACTIVE | Oturum oluşturma sırasında etkinleştirilmez | | XPC_SESSION_CREATE_MACH_PRIVILEGED | Ayrıcalıklı Mach bootstrap'ında | | XPC_SESSION_CREATE_NO_CONFORMANCE_CHECK | Uyum kontrolünü atlar (admin erişimi gerektirir) |

Mesaj Gönderme

// Tek yönlü gönderme
void xpc_session_send_message(
    xpc_session_t session,
    xpc_object_t message)

// Yanıtlı asenkron gönderme
void xpc_session_send_message_with_reply_async(
    xpc_session_t session,
    xpc_object_t message,
    xpc_session_reply_handler_t handler)

// Senkron gönderme (engelleyici)
xpc_object_t xpc_session_send_message_with_reply_sync(
    xpc_session_t session,
    xpc_object_t message,
    xpc_rich_error_t *error)

Yaşam Döngüsü

void xpc_session_activate(xpc_session_t session)
void xpc_session_cancel(xpc_session_t session)
void xpc_session_set_target_queue(xpc_session_t session, dispatch_queue_t queue)
void xpc_session_set_incoming_message_handler(xpc_session_t session, xpc_session_incoming_message_handler_t handler)
void xpc_session_set_cancel_handler(xpc_session_t session, xpc_session_cancel_handler_t handler)
xpc_object_t xpc_session_copy_description(xpc_session_t session)

Hata İşleme

// xpc_rich_error_t — Zengin hata tipi
const char *xpc_rich_error_copy_description(xpc_rich_error_t error)
bool xpc_rich_error_can_retry(xpc_rich_error_t error)

xpc_rich_error_t, xpc_session_t ve xpc_listener_t API'lerinden döndürülen hata nesnesidir. Hata açıklaması ve yeniden denenebilirlik bilgisi içerir.

Uyum

  • CVarArg, Equatable, Hashable, NSObjectProtocol, Sendable, SendableMetatype

XPCEndpoint

Yapı (Struct) | XPC

*Mac Catalyst 18.0+, macOS 15.0+*

Serileştirilmiş biçimdeki bir bağlantı.

struct XPCEndpoint

XPCEndpoint, bir XPC mesajında iletilebilir. Alıcı, XPCSession.init(endpoint:targetQueue:options:cancellationHandler:)) ile istediği kadar farklı oturum oluşturabilir.

Bir bağlantının aksine, uç nokta eylemsiz (inert) bir nesnedir — kendisiyle ilişkili herhangi bir çalışma zamanı etkinliği yoktur.

Başlatıcılar

init(_ endpoint: xpc_endpoint_t)  // C uç nokta nesnesinden kopya-başlatma

Uyum

  • Copyable, CustomDebugStringConvertible, Decodable, Encodable, Equatable, Hashable, Sendable, SendableMetatype

XPCPeerRequirement

Yapı | XPC

*Mac Catalyst 26.0+, macOS 26.0+*

Eş doğrulama gereksinimlerini tanımlayan tip.

struct XPCPeerRequirement

XPC oturumları ve dinleyicileri üzerinde, iletişim kuran eşin belirli gereksinimleri karşılamasını zorunlu kılmak için kullanılır.

Fabrika Metotları

// Kod gereksiniminden oluştur
static func codeRequirement(_ requirement: ProcessCodeRequirement) -> XPCPeerRequirement

// Yetkilendirme (entitlement) kontrolü
static func hasEntitlement(_ entitlement: String) -> XPCPeerRequirement
static func entitlement(_ entitlement: String, matches value: String) -> XPCPeerRequirement
static func entitlement(_ entitlement: String, matches value: Int) -> XPCPeerRequirement
static func entitlement(_ entitlement: String, matches value: Bool) -> XPCPeerRequirement

// Kimlik kontrolü
static func isFromSameTeam(andMatchesSigningIdentifier: String? = nil) -> XPCPeerRequirement
static func isPlatformCode(andMatchesSigningIdentifier: String? = nil) -> XPCPeerRequirement

Başlatıcılar

init(lightweightCodeRequirements dictionary: XPCDictionary)

Uyum

  • Sendable, SendableMetatype

xpc_peer_requirement_t

Tip Takma Adı | XPC

typealias xpc_peer_requirement_t = OS_xpc_peer_requirement

Eşler üzerinde doğrulanmış gereksinimleri temsil eden soyut C tipi. xpc_peer_requirement_create_* API'leri ile oluşturulur. Referans sayımlıdır ve eşzamanlılık güvenlidir; tek bir xpc_peer_requirement_t nesnesi birden fazla bağlantı, oturum veya dinleyici arasında paylaşılabilir.


XPC Bağlantıları

API Koleksiyonu | XPC

Bağlantı tabanlı API'lerle servis bağlantıları oluşturma ve yönetme.

Bu API'ler, bir çerçeve fonksiyonunun xpc_connection_t döndürdüğü durumlar gibi, XPC bağlantılarıyla çalışmanız gerektiğinde kullanılır.

Bağlantı Oluşturma

xpc_connection_t xpc_connection_create(const char *name, dispatch_queue_t queue)
xpc_connection_t xpc_connection_create_mach_service(const char *name, dispatch_queue_t queue, uint64_t flags)
xpc_connection_t xpc_connection_create_from_endpoint(xpc_endpoint_t endpoint)

Bağlantı Yapılandırma

void xpc_connection_set_target_queue(xpc_connection_t conn, dispatch_queue_t queue)
void xpc_connection_set_event_handler(xpc_connection_t conn, xpc_handler_t handler)
void xpc_connection_set_peer_code_signing_requirement(xpc_connection_t conn, const char *req)

Yaşam Döngüsü

void xpc_connection_activate(xpc_connection_t conn)
void xpc_connection_resume(xpc_connection_t conn)
void xpc_connection_suspend(xpc_connection_t conn)
void xpc_connection_cancel(xpc_connection_t conn)

Mesajlaşma

void xpc_connection_send_message(xpc_connection_t conn, xpc_object_t msg)
void xpc_connection_send_message_with_reply(xpc_connection_t conn, xpc_object_t msg,
    dispatch_queue_t queue, xpc_handler_t handler)
xpc_object_t xpc_connection_send_message_with_reply_sync(xpc_connection_t conn, xpc_object_t msg)
void xpc_connection_send_barrier(xpc_connection_t conn, dispatch_block_t barrier)
void xpc_connection_send_notification(xpc_connection_t conn, xpc_object_t msg)

Bağlantı Bilgileri

pid_t xpc_connection_get_pid(xpc_connection_t conn)
uid_t xpc_connection_get_euid(xpc_connection_t conn)
gid_t xpc_connection_get_egid(xpc_connection_t conn)
au_asid_t xpc_connection_get_asid(xpc_connection_t conn)
audit_token_t xpc_connection_get_audit_token(xpc_connection_t conn)
xpc_object_t xpc_connection_copy_description(xpc_connection_t conn)
xpc_endpoint_t xpc_connection_copy_endpoint(xpc_connection_t conn)

Eş Kimlik Doğrulama (macOS 26+)

// Yetkilendirme kontrolü
int xpc_connection_set_peer_entitlement_exists_requirement(
    xpc_connection_t conn, const char *entitlement)
int xpc_connection_set_peer_entitlement_matches_value_requirement(
    xpc_connection_t conn, const char *entitlement, xpc_object_t value)

// Platform ve takım kimliği kontrolü
int xpc_connection_set_peer_platform_identity_requirement(
    xpc_connection_t conn, const char *_Nullable signing_identifier)
int xpc_connection_set_peer_team_identity_requirement(
    xpc_connection_t conn, const char *_Nullable signing_identifier)

// Hafif kod gereksinimi
int xpc_connection_set_peer_lightweight_code_requirement(
    xpc_connection_t conn, xpc_object_t requirement)

Sabitler

| Sabit | Açıklama | | --- | --- | | XPC_CONNECTION_MACH_SERVICE_LISTENER | Mach servisine bir dinleyici olarak bağlanır | | XPC_CONNECTION_MACH_SERVICE_PRIVILEGED | Ayrıcalıklı Mach bootstrap'ında olan servise bağlanır | | XPC_ERROR_CONNECTION_INTERRUPTED | Bağlantı kesintiye uğradı | | XPC_ERROR_CONNECTION_INVALID | Bağlantı geçersiz | | XPC_ERROR_TERMINATION_IMMINENT | Süreç yakında sonlanacak | | XPC_ERROR_PEER_CODE_SIGNING_REQUIREMENT | Eş kod imzalama gereksinimi karşılanmadı |

OS_xpc_session

Sınıf | XPC

class OS_xpc_session

OS_object'ten miras alır. xpc_session_t tip takma adının temel sınıfıdır.