mssf_core/runtime/
store.rs

1// ------------------------------------------------------------
2// Copyright (c) Microsoft Corporation.  All rights reserved.
3// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4// ------------------------------------------------------------
5
6use std::ffi::c_void;
7
8use crate::{PCWSTR, WString};
9use mssf_com::{
10    FabricRuntime::{
11        IFabricKeyValueStoreReplica2, IFabricStoreEventHandler, IFabricStoreEventHandler_Impl,
12    },
13    FabricTypes::{FABRIC_ESE_LOCAL_STORE_SETTINGS, FABRIC_LOCAL_STORE_KIND},
14};
15use windows_core::implement;
16
17use crate::types::{EseLocalStoreSettings, LocalStoreKind, ReplicatorSettings};
18
19#[implement(IFabricStoreEventHandler)]
20pub struct DummyStoreEventHandler {}
21
22impl IFabricStoreEventHandler_Impl for DummyStoreEventHandler_Impl {
23    #[cfg_attr(
24        feature = "tracing",
25        tracing::instrument(skip_all, level = "debug", ret)
26    )]
27    fn OnDataLoss(&self) {}
28}
29
30pub fn create_com_key_value_store_replica(
31    storename: &WString,
32    partitionid: crate::GUID,
33    replicaid: i64,
34    replicatorsettings: &ReplicatorSettings,
35    localstorekind: LocalStoreKind,
36    localstoresettings: Option<&EseLocalStoreSettings>,
37    storeeventhandler: &IFabricStoreEventHandler,
38) -> crate::Result<IFabricKeyValueStoreReplica2> {
39    let kind: FABRIC_LOCAL_STORE_KIND = localstorekind.into();
40    let local_settings: Option<FABRIC_ESE_LOCAL_STORE_SETTINGS> =
41        localstoresettings.map(|x| x.get_raw());
42
43    let local_settings_ptr = match local_settings {
44        Some(x) => &x,
45        None => std::ptr::null(),
46    };
47    crate::API_TABLE
48        .fabric_create_key_value_store_replica::<IFabricKeyValueStoreReplica2>(
49            PCWSTR::from_raw(storename.as_ptr()),
50            partitionid,
51            replicaid,
52            &replicatorsettings.get_raw(),
53            kind,
54            local_settings_ptr as *const c_void,
55            Some(storeeventhandler),
56        )
57        .map_err(crate::Error::from)
58}