Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CtrlCHandler helper class (Swift) #3469

Merged
merged 13 commits into from
Feb 1, 2025

Conversation

bernardnormier
Copy link
Member

This PR adds the CtrlCHandler helper class to Swift.

It's a thin wrapper over the Ice::CtrlCHandler class provided by Ice C++. It's main consumer is our Swift demos for macOS.

/// @param cb The callback function to invoke when a signal is received.
explicit CtrlCHandler(CtrlCHandlerCallback cb);

CtrlCHandler(const CtrlCHandler&) = delete;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having these made the class rather bug-prone.


@interface ICECtrlCHandler ()
{
Ice::CtrlCHandler cppObject;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's essential to use a field and not a property here, since a property wants to return a copy of the C++ object (which is not copyable).

@bernardnormier
Copy link
Member Author

bernardnormier commented Feb 1, 2025

Although not tested yet, I believe this helper class can also be used when waiting for either Ctrl+C or a shutdown request, with something like:

Task {
    await ctrlCHandler.catchSignal()
    communicator.shutdown() // initiate shutdown after receiving signal
}

and the "main" thread blocks on communicator.waitForShutdown()

cpp/src/Ice/CtrlCHandler.cpp Outdated Show resolved Hide resolved
cpp/src/Ice/CtrlCHandler.cpp Outdated Show resolved Hide resolved
Copy link
Member

@externl externl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@bernardnormier bernardnormier merged commit a378e1f into zeroc-ice:main Feb 1, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants