Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

feat!: Some non-blocking, callback-based C FFI #322

Merged
merged 6 commits into from
Apr 19, 2023

Conversation

cdata
Copy link
Collaborator

@cdata cdata commented Apr 17, 2023

This change proposes a model for Swift-friendly, C-compatible, non-blocking, callback-based FFI. Non-blocking FFI calls are executed by the Tokio runtime, and will be scheduled according to the runtime's internal semantics.

The new FFI style entails two conventional trailing parameters in each callback-based function:

  1. An opaque "context"
  2. A function pointer that can be called with the provided context, a conditionally initialized error and the result of the FFI call

These trailing parameters enable a closure to be created by setting the captured closure state to the context; when the function is called, the captured state is then passed back into it. Importantly, this enables us to write idiomatic-ish closures in Swift as well.

Callback APIs added for:

  • Reading sphere content
  • Syncing with gateway
  • Traversing spheres by petname

The older, blocking forms of the FFI have been renamed (e.g., ns_sphere_sync is now ns_sphere_sync_blocking) and have been marked as deprecated.

@cdata cdata requested a review from jsantell April 17, 2023 23:34
cdata added 2 commits April 17, 2023 16:50
Callback APIs added for:

 - Reading sphere content
 - Syncing with gateway
 - Traversing by petname
@cdata cdata force-pushed the feat/async-read-and-sync-ffi branch from d7b74a1 to 71199ee Compare April 17, 2023 23:51
Base automatically changed from feat/no-lock-sphere-read to main April 18, 2023 16:31
bfollington
bfollington previously approved these changes Apr 18, 2023
Copy link
Contributor

@bfollington bfollington left a comment

Choose a reason for hiding this comment

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

LGTM, couple questions on my end. Excited to start using this in the app!

rust/noosphere/src/ffi/context.rs Show resolved Hide resolved
rust/noosphere/src/ffi/sphere.rs Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants