Skip to content

Commit

Permalink
Expose function to init db (and possible future bootstrapping)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivnsch authored May 26, 2020
1 parent cd7975b commit 2a1b70c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/ios/c_headers/coepicore.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <CoreFoundation/CoreFoundation.h>

CFStringRef bootstrap_core(const char *to);

CFStringRef fetch_new_reports();
CFStringRef get_reports(int32_t interval_number, int32_t interval_length);
CFStringRef post_report(const char *to);
Expand Down
14 changes: 13 additions & 1 deletion src/ios/ios_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core_foundation::base::TCFType;
use serde::Serialize;

use crate::{composition_root::COMP_ROOT, networking, reporting::symptom_inputs::{SymptomInputsSubmitter, SymptomInputs}, errors::ServicesError::{Networking, Error, self}};
use crate::reporting::symptom_inputs_manager::SymptomInputsProcessor;
use crate::{init_db, reporting::symptom_inputs_manager::SymptomInputsProcessor};
use networking::TcnApi;

// Generic struct to return results to app
Expand All @@ -17,6 +17,18 @@ struct LibResult<T> {
error_message: Option<String>
}

#[no_mangle]
pub unsafe extern "C" fn bootstrap_core(db_path: *const c_char) -> CFStringRef {

let db_path_str = cstring_to_str(&db_path).unwrap();

println!("RUST: bootstrapping with db path: {:?}", db_path_str);

let result = init_db(db_path_str).map_err(ServicesError::from);
println!("RUST: bootstrapping result: {:?}", result);
return to_result_str(result);
}

#[no_mangle]
pub unsafe extern "C" fn fetch_new_reports() -> CFStringRef {
println!("RUST: updating reports");
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub type Res<T> = Result<T, Error>;

const CENS_BY_TS: &str = "cens by ts";

pub fn init<P: AsRef<Path>>(p: P) -> Res<()> {
pub fn init_db<P: AsRef<Path>>(p: P) -> Res<()> {
let db = Persy::open_or_create_with(p, Config::new(), |db| {
let mut tx = db.begin()?;
tx.create_segment("tcn")?;
Expand Down
2 changes: 1 addition & 1 deletion src/reports_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<'a,
.and_then(|tcns| self.tcn_matcher.match_reports(tcns, reports));

let time = matching_start_time.elapsed().as_secs();
println!("Took ${:?}s to match reports", time);
println!("Took {:?}s to match reports", time);

if let Ok(reports) = &matched_reports {
if !reports.is_empty() {
Expand Down

0 comments on commit 2a1b70c

Please sign in to comment.