use std::ffi::c_void;
use super::types::{
AsyncExecutorFn, FfiChangeOp, FfiComponentStatus, FfiCreateResult, FfiDispatchMode,
FfiGetResult, FfiOwnedStr, FfiResult, FfiStr, FfiStringArray,
};
#[repr(C)]
pub struct FfiSourceEvent {
pub opaque: *mut c_void,
pub source_id: FfiStr,
pub timestamp_us: i64,
pub op: FfiChangeOp,
pub label: FfiStr,
pub entity_id: FfiStr,
pub drop_fn: extern "C" fn(*mut c_void),
}
#[repr(C)]
pub struct FfiBootstrapEvent {
pub opaque: *mut c_void,
pub source_id: FfiStr,
pub timestamp_us: i64,
pub sequence: u64,
pub label: FfiStr,
pub entity_id: FfiStr,
pub drop_fn: extern "C" fn(*mut c_void),
}
pub type FfiChangePushCallbackFn =
extern "C" fn(ctx: *mut c_void, event: *mut FfiSourceEvent) -> bool;
#[repr(C)]
pub struct FfiChangeReceiver {
pub state: *mut c_void,
pub executor: AsyncExecutorFn,
pub start_push_fn: extern "C" fn(
state: *mut c_void,
callback: FfiChangePushCallbackFn,
callback_ctx: *mut c_void,
),
pub drop_fn: extern "C" fn(state: *mut c_void),
}
unsafe impl Send for FfiChangeReceiver {}
unsafe impl Sync for FfiChangeReceiver {}
pub type FfiBootstrapPushCallbackFn =
extern "C" fn(ctx: *mut c_void, event: *mut FfiBootstrapEvent) -> bool;
#[repr(C)]
pub struct FfiBootstrapReceiver {
pub state: *mut c_void,
pub start_push_fn: extern "C" fn(
state: *mut c_void,
callback: FfiBootstrapPushCallbackFn,
callback_ctx: *mut c_void,
),
pub drop_fn: extern "C" fn(state: *mut c_void),
}
unsafe impl Send for FfiBootstrapReceiver {}
unsafe impl Sync for FfiBootstrapReceiver {}
#[repr(C)]
pub struct FfiSubscriptionResponse {
pub query_id: FfiOwnedStr,
pub source_id: FfiOwnedStr,
pub receiver: *mut FfiChangeReceiver,
pub bootstrap_receiver: *mut FfiBootstrapReceiver,
pub position_handle_ptr: *const std::ffi::c_void,
pub bootstrap_result_receiver: *mut FfiBootstrapResultReceiver,
}
pub type FfiBootstrapResultCallbackFn =
extern "C" fn(ctx: *mut std::ffi::c_void, result: *mut FfiBootstrapResult);
#[repr(C)]
pub struct FfiBootstrapResultReceiver {
pub state: *mut std::ffi::c_void,
pub start_fn: extern "C" fn(
state: *mut std::ffi::c_void,
callback: FfiBootstrapResultCallbackFn,
ctx: *mut std::ffi::c_void,
),
pub drop_fn: extern "C" fn(state: *mut std::ffi::c_void),
}
unsafe impl Send for FfiBootstrapResultReceiver {}
unsafe impl Sync for FfiBootstrapResultReceiver {}
pub type FfiResultPushCallbackFn =
extern "C" fn(ctx: *mut c_void, result: *mut c_void) -> *mut c_void;
#[repr(C)]
pub struct FfiBootstrapSender {
pub state: *mut c_void,
pub send_fn: extern "C" fn(state: *mut c_void, event: *mut FfiBootstrapEvent) -> i32,
pub drop_fn: extern "C" fn(state: *mut c_void),
}
unsafe impl Send for FfiBootstrapSender {}
unsafe impl Sync for FfiBootstrapSender {}
#[repr(C)]
pub struct FfiBootstrapResult {
pub event_count: i64,
pub last_sequence: i64,
pub sequences_aligned: bool,
pub source_position_ptr: *const u8,
pub source_position_len: usize,
pub source_position_drop_fn: Option<extern "C" fn(*mut u8, usize)>,
}
unsafe impl Send for FfiBootstrapResult {}
unsafe impl Sync for FfiBootstrapResult {}
#[repr(C)]
pub struct FfiRuntimeContext {
pub instance_id: FfiStr,
pub component_id: FfiStr,
pub state_store: *const StateStoreVtable,
pub log_callback: Option<super::callbacks::LogCallbackFn>,
pub log_ctx: *mut c_void,
pub lifecycle_callback: Option<super::callbacks::LifecycleCallbackFn>,
pub lifecycle_ctx: *mut c_void,
pub identity_provider: *const super::identity::IdentityProviderVtable,
pub snapshot_fetcher: *const SnapshotFetcherVtable,
}
unsafe impl Send for FfiRuntimeContext {}
unsafe impl Sync for FfiRuntimeContext {}
drasi_ffi_primitives::ffi_vtable! {
pub struct SourceVtable {
fn id_fn(state: *const) -> FfiStr,
fn type_name_fn(state: *const) -> FfiStr,
fn auto_start_fn(state: *const) -> bool,
fn dispatch_mode_fn(state: *const) -> FfiDispatchMode,
fn properties_fn(state: *const) -> FfiOwnedStr,
fn describe_schema_fn(state: *const) -> FfiOwnedStr,
fn start_fn(state: *mut) -> FfiResult,
fn stop_fn(state: *mut) -> FfiResult,
fn status_fn(state: *const) -> FfiComponentStatus,
fn deprovision_fn(state: *mut) -> FfiResult,
fn initialize_fn(state: *mut, ctx: *const FfiRuntimeContext),
fn subscribe_fn(state: *mut, source_id: FfiStr, enable_bootstrap: bool, query_id: FfiStr, nodes_json: FfiStr, relations_json: FfiStr, resume_from_ptr: *const u8, resume_from_len: u32, has_last_sequence: bool, last_sequence: u64, request_position_handle: bool) -> *mut FfiSubscriptionResponse,
fn set_bootstrap_provider_fn(state: *mut, provider: *mut BootstrapProviderVtable),
fn supports_replay_fn(state: *const) -> bool,
fn remove_position_handle_fn(state: *mut, query_id: FfiStr) -> FfiResult,
}
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct FfiCheckpoint {
pub sequence: u64,
pub config_hash: u64,
}
#[repr(C)]
pub struct FfiCheckpointResult {
pub found: bool,
pub checkpoint: FfiCheckpoint,
pub error: FfiOwnedStr,
}
#[repr(C)]
pub struct FfiSnapshotIterator {
pub iter_ctx: *mut c_void,
pub next_fn: extern "C" fn(*mut c_void) -> FfiOwnedStr,
pub drop_fn: extern "C" fn(*mut c_void),
}
#[repr(C)]
pub struct FfiSnapshotIteratorResponse {
pub iterator: FfiSnapshotIterator,
pub as_of_sequence: u64,
pub config_hash: u64,
pub error: FfiOwnedStr,
}
#[repr(C)]
pub struct FfiOutboxIterator {
pub iter_ctx: *mut c_void,
pub next_fn: extern "C" fn(*mut c_void) -> FfiOwnedStr,
pub drop_fn: extern "C" fn(*mut c_void),
}
#[repr(C)]
pub struct FfiOutboxIteratorResponse {
pub iterator: FfiOutboxIterator,
pub latest_sequence: u64,
pub config_hash: u64,
pub error: FfiOwnedStr,
}
pub type FfiBootstrapFetchSnapshotFn = extern "C" fn(*mut c_void) -> FfiSnapshotIteratorResponse;
pub type FfiBootstrapFetchOutboxFn = extern "C" fn(*mut c_void, u64) -> FfiOutboxIteratorResponse;
pub type FfiBootstrapReadCheckpointFn = extern "C" fn(*mut c_void) -> FfiCheckpointResult;
pub type FfiBootstrapWriteCheckpointFn = extern "C" fn(*mut c_void, FfiCheckpoint) -> FfiResult;
#[repr(C)]
pub struct FfiBootstrapContext {
pub query_id: FfiStr,
pub is_reset: bool,
pub callback_ctx: *mut c_void,
pub fetch_snapshot_fn: FfiBootstrapFetchSnapshotFn,
pub fetch_outbox_fn: FfiBootstrapFetchOutboxFn,
pub read_checkpoint_fn: FfiBootstrapReadCheckpointFn,
pub write_checkpoint_fn: FfiBootstrapWriteCheckpointFn,
}
drasi_ffi_primitives::ffi_vtable! {
pub struct ReactionVtable {
fn id_fn(state: *const) -> FfiStr,
fn type_name_fn(state: *const) -> FfiStr,
fn auto_start_fn(state: *const) -> bool,
fn query_ids_fn(state: *const) -> FfiStringArray,
fn properties_fn(state: *const) -> FfiOwnedStr,
fn start_fn(state: *mut) -> FfiResult,
fn stop_fn(state: *mut) -> FfiResult,
fn status_fn(state: *const) -> FfiComponentStatus,
fn deprovision_fn(state: *mut) -> FfiResult,
fn initialize_fn(state: *mut, ctx: *const FfiRuntimeContext),
fn start_result_push_fn(state: *mut, callback: FfiResultPushCallbackFn, callback_ctx: *mut c_void),
fn is_durable_fn(state: *const) -> bool,
fn needs_snapshot_on_fresh_start_fn(state: *const) -> bool,
fn default_recovery_policy_fn(state: *const) -> u8,
fn bootstrap_fn(state: *mut, ctx: *const FfiBootstrapContext) -> FfiResult,
}
}
drasi_ffi_primitives::ffi_vtable! {
pub struct BootstrapProviderVtable {
fn bootstrap_fn(state: *mut, query_id: FfiStr, node_labels: *const FfiStr, node_labels_count: usize, relation_labels: *const FfiStr, relation_labels_count: usize, request_id: FfiStr, server_id: FfiStr, source_id: FfiStr, sender: *mut FfiBootstrapSender) -> *mut FfiBootstrapResult,
}
}
drasi_ffi_primitives::ffi_vtable! {
pub struct SourcePluginVtable {
fn kind_fn(state: *const) -> FfiStr,
fn config_version_fn(state: *const) -> FfiStr,
fn config_schema_json_fn(state: *const) -> FfiOwnedStr,
fn config_schema_name_fn(state: *const) -> FfiStr,
fn create_source_fn(state: *mut, id: FfiStr, config_json: FfiStr, auto_start: bool) -> FfiCreateResult,
}
}
drasi_ffi_primitives::ffi_vtable! {
pub struct ReactionPluginVtable {
fn kind_fn(state: *const) -> FfiStr,
fn config_version_fn(state: *const) -> FfiStr,
fn config_schema_json_fn(state: *const) -> FfiOwnedStr,
fn config_schema_name_fn(state: *const) -> FfiStr,
fn create_reaction_fn(state: *mut, id: FfiStr, query_ids_json: FfiStr, config_json: FfiStr, auto_start: bool) -> FfiCreateResult,
}
}
drasi_ffi_primitives::ffi_vtable! {
pub struct BootstrapPluginVtable {
fn kind_fn(state: *const) -> FfiStr,
fn config_version_fn(state: *const) -> FfiStr,
fn config_schema_json_fn(state: *const) -> FfiOwnedStr,
fn config_schema_name_fn(state: *const) -> FfiStr,
fn create_bootstrap_provider_fn(state: *mut, config_json: FfiStr, source_config_json: FfiStr) -> FfiCreateResult,
}
}
drasi_ffi_primitives::ffi_vtable! {
pub struct IdentityProviderPluginVtable {
fn kind_fn(state: *const) -> FfiStr,
fn config_version_fn(state: *const) -> FfiStr,
fn config_schema_json_fn(state: *const) -> FfiOwnedStr,
fn config_schema_name_fn(state: *const) -> FfiStr,
fn create_identity_provider_fn(state: *mut, config_json: FfiStr) -> *mut super::identity::IdentityProviderVtable,
}
}
drasi_ffi_primitives::ffi_vtable! {
pub struct SecretStorePluginVtable {
fn kind_fn(state: *const) -> FfiStr,
fn config_version_fn(state: *const) -> FfiStr,
fn config_schema_json_fn(state: *const) -> FfiOwnedStr,
fn config_schema_name_fn(state: *const) -> FfiStr,
fn create_secret_store_fn(state: *mut, config_json: FfiStr) -> *mut super::secret_store::SecretStoreProviderVtable,
}
}
#[repr(C)]
pub struct StateStoreVtable {
pub state: *mut c_void,
pub get_fn: extern "C" fn(state: *mut c_void, store_id: FfiStr, key: FfiStr) -> FfiGetResult,
pub set_fn: extern "C" fn(
state: *mut c_void,
store_id: FfiStr,
key: FfiStr,
value: *const u8,
value_len: usize,
) -> FfiResult,
pub delete_fn: extern "C" fn(state: *mut c_void, store_id: FfiStr, key: FfiStr) -> FfiResult,
pub contains_key_fn:
extern "C" fn(state: *mut c_void, store_id: FfiStr, key: FfiStr) -> FfiResult,
pub get_many_fn: extern "C" fn(
state: *mut c_void,
store_id: FfiStr,
keys: *const FfiStr,
keys_count: usize,
out_values: *mut FfiGetResult,
) -> FfiResult,
pub set_many_fn: extern "C" fn(
state: *mut c_void,
store_id: FfiStr,
keys: *const FfiStr,
values: *const *const u8,
value_lens: *const usize,
count: usize,
) -> FfiResult,
pub delete_many_fn: extern "C" fn(
state: *mut c_void,
store_id: FfiStr,
keys: *const FfiStr,
keys_count: usize,
) -> i64,
pub clear_store_fn: extern "C" fn(state: *mut c_void, store_id: FfiStr) -> i64,
pub list_keys_fn: extern "C" fn(state: *mut c_void, store_id: FfiStr) -> FfiStringArray,
pub store_exists_fn: extern "C" fn(state: *mut c_void, store_id: FfiStr) -> FfiResult,
pub key_count_fn: extern "C" fn(state: *mut c_void, store_id: FfiStr) -> i64,
pub sync_fn: extern "C" fn(state: *mut c_void) -> FfiResult,
pub drop_fn: extern "C" fn(state: *mut c_void),
}
unsafe impl Send for StateStoreVtable {}
unsafe impl Sync for StateStoreVtable {}
#[repr(C)]
pub struct SnapshotFetcherVtable {
pub state: *mut c_void,
pub fetch_snapshot_fn:
extern "C" fn(state: *mut c_void, query_id: FfiStr) -> FfiSnapshotIteratorResponse,
pub drop_fn: extern "C" fn(state: *mut c_void),
}
unsafe impl Send for SnapshotFetcherVtable {}
unsafe impl Sync for SnapshotFetcherVtable {}
#[repr(C)]
pub struct FfiPluginRegistration {
pub source_plugins: *mut SourcePluginVtable,
pub source_plugin_count: usize,
pub reaction_plugins: *mut ReactionPluginVtable,
pub reaction_plugin_count: usize,
pub bootstrap_plugins: *mut BootstrapPluginVtable,
pub bootstrap_plugin_count: usize,
pub set_log_callback:
extern "C" fn(ctx: *mut ::std::ffi::c_void, callback: super::callbacks::LogCallbackFn),
pub set_lifecycle_callback: extern "C" fn(
ctx: *mut ::std::ffi::c_void,
callback: super::callbacks::LifecycleCallbackFn,
),
pub identity_provider_plugins: *mut IdentityProviderPluginVtable,
pub identity_provider_plugin_count: usize,
pub secret_store_plugins: *mut SecretStorePluginVtable,
pub secret_store_plugin_count: usize,
pub set_config_resolver:
extern "C" fn(ctx: *mut ::std::ffi::c_void, callback: super::callbacks::ConfigResolverFn),
}