eww
eww

Reputation: 300

Reset / Re-initialize NSXPCConnection?

Sorry in advance if this is an obvious question or I demonstrate a total lack of knowledge here (which would be accurate).

We're interacting with a C API. That API stores all sorts of session/environment information under the hood. There are specific API calls that require a total restart of the API, but the only way to accomplish that is fully shutting down the client application that invokes it (the API acts like a Singleton with no way to reinitialize itself).

My hope is that potentially wrapping the C API in an XPC Service would let me more gracefully shut down the service and restart it so I can avoid restarting the entire client application.

  1. Is that even remotely the right way of thinking about this need in Cocoa?
  2. If (if) it is, how would I go about doing that? I added a simple XPC Service to the existing app using File -> Add Target -> XPC Service. I can call into the C API and that all works using NSXPCConnection and hitting the appropriate service method from the app. I'm stumped on how I would potentially kill/reinitialize the XPC Service, though.
  3. Is there a different / better way to look at this?

Any direction / ideas / critiques most welcome

Thank you!

Upvotes: 0

Views: 283

Answers (1)

eww
eww

Reputation: 300

I think I got this to work with NSXPCConnection.

Following up on Kill XPC when parent app is still running I called what I could of the API's dispose-ish methods and then called exit(0) inside of a method in the the XPC connection.

So far, so good!

Upvotes: 0

Related Questions