@@ -11,6 +11,7 @@ import (
1111 "runtime/cgo"
1212 "unsafe"
1313
14+ "github.com/Code-Hex/vz/v3/internal/cgohandler"
1415 "github.com/Code-Hex/vz/v3/internal/objc"
1516)
1617
@@ -20,8 +21,8 @@ import (
2021type Session struct {
2122 // Exported for use in other packages since unimplemented XPC API may require direct access to xpc_session_t.
2223 * xpcObject
23- cancellationHandler * cgoHandler
24- incomingMessageHandler * cgoHandler
24+ cancellationHandler * cgohandler. Handler
25+ incomingMessageHandler * cgohandler. Handler
2526}
2627
2728var _ Object = & Session {}
@@ -128,16 +129,16 @@ func (s *Session) activate() error {
128129//
129130//export callMessageHandler
130131func callMessageHandler (cgoMessageHandler , cgoMessage uintptr ) (reply unsafe.Pointer ) {
131- handler := unwrapHandler [MessageHandler ](cgoMessageHandler )
132+ handler := cgohandler. Unwrap [MessageHandler ](cgoMessageHandler )
132133 message := unwrapObject [* Dictionary ](cgoMessage )
133134 return objc .Ptr (handler (message ))
134135}
135136
136137// setIncomingMessageHandler sets the [MessageHandler] for the inactive [Session]. (macOS 13.0+)
137138// - https://developer.apple.com/documentation/xpc/xpc_session_set_incoming_message_handler
138139func (s * Session ) setIncomingMessageHandler (handler MessageHandler ) {
139- cgoHandler , p := newCgoHandler (handler )
140- C .xpcSessionSetIncomingMessageHandler (objc .Ptr (s ), p )
140+ cgoHandler , p := cgohandler . New (handler )
141+ C .xpcSessionSetIncomingMessageHandler (objc .Ptr (s ), C . uintptr_t ( p ) )
141142 // Store the handler after setting it to avoid premature garbage collection of the previous handler.
142143 s .incomingMessageHandler = cgoHandler
143144}
@@ -152,7 +153,7 @@ func (s *Session) Cancel() {
152153//
153154//export callCancelHandler
154155func callCancelHandler (cgoCancelHandler , cgoErr uintptr ) {
155- handler := unwrapHandler [CancellationHandler ](cgoCancelHandler )
156+ handler := cgohandler. Unwrap [CancellationHandler ](cgoCancelHandler )
156157 err := unwrapObject [* RichError ](cgoErr )
157158 handler (err )
158159}
@@ -161,13 +162,13 @@ func callCancelHandler(cgoCancelHandler, cgoErr uintptr) {
161162// The handler will call [Session.handleCancellation] after executing the provided handler.
162163// - https://developer.apple.com/documentation/xpc/xpc_session_set_cancel_handler
163164func (s * Session ) setCancellationHandler (handler CancellationHandler ) {
164- cgoHandler , p := newCgoHandler ((CancellationHandler )(func (err * RichError ) {
165+ cgoHandler , p := cgohandler . New ((CancellationHandler )(func (err * RichError ) {
165166 if handler != nil {
166167 handler (err )
167168 }
168169 s .handleCancellation (err )
169170 }))
170- C .xpcSessionSetCancelHandler (objc .Ptr (s ), p )
171+ C .xpcSessionSetCancelHandler (objc .Ptr (s ), C . uintptr_t ( p ) )
171172 // Store the handler after setting it to avoid premature garbage collection of the previous handler.
172173 s .cancellationHandler = cgoHandler
173174}
@@ -182,7 +183,7 @@ type ReplyHandler func(*Dictionary, *RichError)
182183//
183184//export callReplyHandler
184185func callReplyHandler (cgoReplyHandler uintptr , cgoReply , cgoError uintptr ) {
185- handler := unwrapHandler [ReplyHandler ](cgoReplyHandler )
186+ handler := cgohandler. Unwrap [ReplyHandler ](cgoReplyHandler )
186187 reply := unwrapObject [* Dictionary ](uintptr (cgoReply ))
187188 err := unwrapObject [* RichError ](cgoError )
188189 handler (reply , err )
0 commit comments