1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::error::{Error, ErrorKind};
use ffi_support::{ErrorCode, ExternError};
pub mod error_codes {
pub const UNEXPECTED: i32 = 1;
pub const UNSUPPORTED_ENGINE: i32 = 2;
pub const ENGINE_NOT_OPEN: i32 = 3;
}
fn get_code(err: &Error) -> ErrorCode {
match err.kind() {
ErrorKind::UnknownEngine(e) => {
log::error!("Unknown engine: {}", e);
ErrorCode::new(error_codes::UNSUPPORTED_ENGINE)
}
ErrorKind::UnsupportedFeature(f) => {
log::error!("Unsupported feature: {}", f);
ErrorCode::new(error_codes::UNSUPPORTED_ENGINE)
}
ErrorKind::ConnectionClosed(e) => {
log::error!("Connection closed: {}", e);
ErrorCode::new(error_codes::ENGINE_NOT_OPEN)
}
err => {
log::error!("Unexpected error: {}", err);
ErrorCode::new(error_codes::UNEXPECTED)
}
}
}
impl From<Error> for ExternError {
fn from(e: Error) -> ExternError {
ExternError::new_error(get_code(&e), e.to_string())
}
}
ffi_support::implement_into_ffi_by_protobuf!(crate::msg_types::SyncResult);
ffi_support::implement_into_ffi_by_protobuf!(crate::msg_types::SyncParams);