rust_libindy_wrapper/
blob_storage.rs

1use {ErrorCode, IndyHandle};
2
3use std::ffi::CString;
4use std::time::Duration;
5
6use native::blob_storage;
7use native::ResponseI32CB;
8
9use utils::results::ResultHandler;
10use utils::callbacks::ClosureHandler;
11
12pub struct Blob {}
13
14impl Blob {
15    pub fn open_reader(xtype: &str, config_json: &str) -> Result<IndyHandle, ErrorCode> {
16        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32();
17
18        let err = Blob::_open_reader(command_handle, xtype, config_json, cb);
19
20        ResultHandler::one(err, receiver)
21    }
22
23    pub fn open_reader_timeout(xtype: &str, config_json: &str, timeout: Duration) -> Result<IndyHandle, ErrorCode> {
24        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32();
25
26        let err = Blob::_open_reader(command_handle, xtype, config_json, cb);
27
28        ResultHandler::one_timeout(err, receiver, timeout)
29    }
30
31    pub fn open_reader_async<F: 'static>(xtype: &str, config_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, IndyHandle) + Send {
32        let (command_handle, cb) = ClosureHandler::convert_cb_ec_i32(Box::new(closure));
33
34        Blob::_open_reader(command_handle, xtype, config_json, cb)
35    }
36
37    fn _open_reader(command_handle: IndyHandle, xtype: &str, config_json: &str, cb: Option<ResponseI32CB>) -> ErrorCode {
38        let xtype = c_str!(xtype);
39        let config_json = c_str!(config_json);
40
41        ErrorCode::from(unsafe { blob_storage::indy_open_blob_storage_reader(command_handle, xtype.as_ptr(), config_json.as_ptr(), cb) })
42    }
43
44    pub fn open_writer(xtype: &str, config_json: &str) -> Result<IndyHandle, ErrorCode> {
45        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32();
46
47        let err = Blob::_open_writer(command_handle, xtype, config_json, cb);
48
49        ResultHandler::one(err, receiver)
50    }
51
52    pub fn open_writer_timeout(xtype: &str, config_json: &str, timeout: Duration) -> Result<IndyHandle, ErrorCode> {
53        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32();
54
55        let err = Blob::_open_writer(command_handle, xtype, config_json, cb);
56
57        ResultHandler::one_timeout(err, receiver, timeout)
58    }
59
60    pub fn open_writer_async<F: 'static>(xtype: &str, config_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, IndyHandle) + Send {
61        let (command_handle, cb) = ClosureHandler::convert_cb_ec_i32(Box::new(closure));
62
63        Blob::_open_writer(command_handle, xtype, config_json, cb)
64    }
65
66    fn _open_writer(command_handle: IndyHandle, xtype: &str, config_json: &str, cb: Option<ResponseI32CB>) -> ErrorCode {
67        let xtype = c_str!(xtype);
68        let config_json = c_str!(config_json);
69
70        ErrorCode::from(unsafe { blob_storage::indy_open_blob_storage_writer(command_handle, xtype.as_ptr(), config_json.as_ptr(), cb) })
71    }
72}