Skip to content

Commit

Permalink
Expose protocol enums in service/ffi
Browse files Browse the repository at this point in the history
This should not be merged until the linked upstream bug is fixed
  • Loading branch information
za-creature committed Jan 14, 2025
1 parent 1e06af8 commit 4165afb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ pub use self::{
network::{
repository_info_hash, DhtContactsStoreTrait, NatBehavior, Network, NetworkEvent,
NetworkEventReceiver, NetworkEventStream, PeerAddr, PeerInfo, PeerInfoCollector,
PeerSource, PeerState, PublicRuntimeId, Registration, SecretRuntimeId, Stats, DHT_ROUTERS,
PeerSource, PeerState, PeerStateKind, PublicRuntimeId, Registration, SecretRuntimeId, Stats,
DHT_ROUTERS,
},
progress::Progress,
protocol::{RepositoryId, StorageSize, BLOCK_SIZE},
Expand Down
2 changes: 1 addition & 1 deletion lib/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub use self::{
peer_addr::PeerAddr,
peer_info::PeerInfo,
peer_source::PeerSource,
peer_state::PeerState,
peer_state::{PeerState, PeerStateKind},
runtime_id::{PublicRuntimeId, SecretRuntimeId},
stats::Stats,
};
Expand Down
4 changes: 4 additions & 0 deletions service/cbindgen.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[parse]
parse_deps = true
include = ['ouisync']

24 changes: 24 additions & 0 deletions service/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ use crate::{
Error, Service,
};

/// Does nothing except accepting arguments for each enum that is exported via the socket interface,
/// thus tricking cbindgen into including them into the generated header.
/// Currently suffers from https://github.com/mozilla/cbindgen/issues/1039
#[no_mangle]
pub unsafe extern "C" fn define_all_enums(
access_mode: AccessMode,
entry_type: EntryType,
network_event: NetworkEvent,
peer_source: PeerSource,
peer_state_kind: PeerStateKind,
) -> u32 {
let _ = access_mode;
let _ = entry_type;
let _ = network_event;
let _ = peer_source;
let _ = peer_state_kind;
0
}
pub type AccessMode = ouisync::AccessMode;
pub type EntryType = ouisync::EntryType;
pub type NetworkEvent = ouisync::NetworkEvent;
pub type PeerSource = ouisync::PeerSource;
pub type PeerStateKind = ouisync::PeerStateKind;

/// Start Ouisync service in a new thread and bind it to the specified local socket.
///
/// Invokes `callback` after the service initialization completes. The first argument is the
Expand Down

0 comments on commit 4165afb

Please sign in to comment.