mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
improve naming
This commit is contained in:
@@ -23,7 +23,7 @@ typedef struct _dc_provider dc_provider_t;
|
||||
typedef struct _dc_event dc_event_t;
|
||||
typedef struct _dc_event_emitter dc_event_emitter_t;
|
||||
typedef struct _dc_accounts_event_emitter dc_accounts_event_emitter_t;
|
||||
typedef struct _dc_json_api_instance dc_json_api_instance_t;
|
||||
typedef struct _dc_jsonrpc_instance dc_jsonrpc_instance_t;
|
||||
|
||||
/**
|
||||
* @mainpage Getting started
|
||||
@@ -5180,7 +5180,7 @@ int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
|
||||
|
||||
|
||||
/**
|
||||
* @class dc_json_api_instance_t
|
||||
* @class dc_jsonrpc_instance_t
|
||||
*
|
||||
* Opaque object for using the json rpc api from the cffi bindings.
|
||||
*/
|
||||
@@ -5191,41 +5191,41 @@ int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
|
||||
* @memberof dc_accounts_t
|
||||
* @param account_manager The accounts object as created by dc_accounts_new().
|
||||
* @return Returns the jsonrpc instance, NULL on errors.
|
||||
* Must be freed using dc_json_api_unref() after usage.
|
||||
* Must be freed using dc_jsonrpc_unref() after usage.
|
||||
*
|
||||
*/
|
||||
dc_json_api_instance_t* dc_get_json_api(dc_accounts_t* account_manager);
|
||||
dc_jsonrpc_instance_t* dc_jsonrpc_init(dc_accounts_t* account_manager);
|
||||
|
||||
/**
|
||||
* Free a jsonrpc instance.
|
||||
*
|
||||
* @memberof dc_json_api_instance_t
|
||||
* @param json_api_instance jsonrpc instance as returned from dc_get_json_api().
|
||||
* @memberof dc_jsonrpc_instance_t
|
||||
* @param jsonrpc_instance jsonrpc instance as returned from dc_jsonrpc_init().
|
||||
* If NULL is given, nothing is done and an error is logged.
|
||||
*/
|
||||
void dc_json_api_unref(dc_json_api_instance_t* json_api_instance);
|
||||
void dc_jsonrpc_unref(dc_jsonrpc_instance_t* jsonrpc_instance);
|
||||
|
||||
/**
|
||||
* Makes an asynchronous jsonrpc request,
|
||||
* returns immediately and once the result is ready it can be retrieved via dc_get_next_json_response()
|
||||
* returns immediately and once the result is ready it can be retrieved via dc_jsonrpc_next_response()
|
||||
* the jsonrpc specification defines an invocation id that can then be used to match request and response.
|
||||
*
|
||||
* @memberof dc_json_api_instance_t
|
||||
* @param json_api_instance jsonrpc instance as returned from dc_get_json_api().
|
||||
* @memberof dc_jsonrpc_instance_t
|
||||
* @param jsonrpc_instance jsonrpc instance as returned from dc_jsonrpc_init().
|
||||
* @param request JSON-RPC request as string
|
||||
*/
|
||||
void dc_json_request(dc_json_api_instance_t* json_api_instance, char* request);
|
||||
void dc_jsonrpc_request(dc_jsonrpc_instance_t* jsonrpc_instance, char* request);
|
||||
|
||||
/**
|
||||
* Get the next json_rpc response, blocks until there is a new event, so call this in a loop from a thread.
|
||||
*
|
||||
* @memberof dc_json_api_instance_t
|
||||
* @param json_api_instance jsonrpc instance as returned from dc_get_json_api().
|
||||
* @memberof dc_jsonrpc_instance_t
|
||||
* @param jsonrpc_instance jsonrpc instance as returned from dc_jsonrpc_init().
|
||||
* @return JSON-RPC response as string
|
||||
* If NULL is returned, the accounts_t belonging to the jsonrpc instance is unref'd and no more events will come;
|
||||
* in this case, free the jsonrpc instance using dc_json_api_unref().
|
||||
* in this case, free the jsonrpc instance using dc_jsonrpc_unref().
|
||||
*/
|
||||
char* dc_get_next_json_response(dc_json_api_instance_t* json_api_instance);
|
||||
char* dc_jsonrpc_next_response(dc_jsonrpc_instance_t* jsonrpc_instance);
|
||||
|
||||
/**
|
||||
* @class dc_event_emitter_t
|
||||
|
||||
@@ -4432,52 +4432,52 @@ mod jsonrpc {
|
||||
use deltachat_jsonrpc::api::CommandApi;
|
||||
use deltachat_jsonrpc::yerpc::{MessageHandle, RpcHandle};
|
||||
|
||||
pub struct dc_json_api_instance_t {
|
||||
pub struct dc_jsonrpc_instance_t {
|
||||
receiver: async_std::channel::Receiver<deltachat_jsonrpc::yerpc::Message>,
|
||||
handle: MessageHandle<CommandApi>,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_json_api(
|
||||
pub unsafe extern "C" fn dc_jsonrpc_init(
|
||||
account_manager: *mut dc_accounts_t,
|
||||
) -> *mut dc_json_api_instance_t {
|
||||
) -> *mut dc_jsonrpc_instance_t {
|
||||
if account_manager.is_null() {
|
||||
eprintln!("ignoring careless call to dc_get_json_api()");
|
||||
eprintln!("ignoring careless call to dc_jsonrpc_init()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
|
||||
let cmd_api =
|
||||
deltachat_jsonrpc::api::CommandApi::new_from_cffi((*account_manager).inner.clone());
|
||||
deltachat_jsonrpc::api::CommandApi::new_from_arc((*account_manager).inner.clone());
|
||||
|
||||
let (request_handle, receiver) = RpcHandle::new();
|
||||
let handle = MessageHandle::new(request_handle, cmd_api);
|
||||
|
||||
let instance = dc_json_api_instance_t { receiver, handle };
|
||||
let instance = dc_jsonrpc_instance_t { receiver, handle };
|
||||
|
||||
Box::into_raw(Box::new(instance))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_json_api_unref(json_api_instance: *mut dc_json_api_instance_t) {
|
||||
if json_api_instance.is_null() {
|
||||
eprintln!("ignoring careless call to dc_json_api_unref()");
|
||||
pub unsafe extern "C" fn dc_jsonrpc_unref(jsonrpc_instance: *mut dc_jsonrpc_instance_t) {
|
||||
if jsonrpc_instance.is_null() {
|
||||
eprintln!("ignoring careless call to dc_jsonrpc_unref()");
|
||||
return;
|
||||
}
|
||||
|
||||
Box::from_raw(json_api_instance);
|
||||
Box::from_raw(jsonrpc_instance);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_json_request(
|
||||
json_api_instance: *mut dc_json_api_instance_t,
|
||||
pub unsafe extern "C" fn dc_jsonrpc_request(
|
||||
jsonrpc_instance: *mut dc_jsonrpc_instance_t,
|
||||
request: *const libc::c_char,
|
||||
) {
|
||||
if json_api_instance.is_null() || request.is_null() {
|
||||
eprintln!("ignoring careless call to dc_json_request()");
|
||||
if jsonrpc_instance.is_null() || request.is_null() {
|
||||
eprintln!("ignoring careless call to dc_jsonrpc_request()");
|
||||
return;
|
||||
}
|
||||
|
||||
let api = &*json_api_instance;
|
||||
let api = &*jsonrpc_instance;
|
||||
let handle = &api.handle;
|
||||
let request = to_string_lossy(request);
|
||||
async_std::task::spawn(async move {
|
||||
@@ -4486,14 +4486,14 @@ mod jsonrpc {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_next_json_response(
|
||||
json_api_instance: *mut dc_json_api_instance_t,
|
||||
pub unsafe extern "C" fn dc_jsonrpc_next_response(
|
||||
jsonrpc_instance: *mut dc_jsonrpc_instance_t,
|
||||
) -> *mut libc::c_char {
|
||||
if json_api_instance.is_null() {
|
||||
eprintln!("ignoring careless call to dc_get_next_json_response()");
|
||||
if jsonrpc_instance.is_null() {
|
||||
eprintln!("ignoring careless call to dc_jsonrpc_next_response()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
let api = &*json_api_instance;
|
||||
let api = &*jsonrpc_instance;
|
||||
async_std::task::block_on(api.receiver.recv())
|
||||
.map(|result| serde_json::to_string(&result).unwrap_or_default().strdup())
|
||||
.unwrap_or(ptr::null_mut())
|
||||
|
||||
@@ -39,7 +39,7 @@ impl CommandApi {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_from_cffi(accounts: Arc<RwLock<Accounts>>) -> Self {
|
||||
pub fn new_from_arc(accounts: Arc<RwLock<Accounts>>) -> Self {
|
||||
CommandApi { accounts }
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ interface NativeAccount {}
|
||||
export class AccountManager extends EventEmitter {
|
||||
dcn_accounts: NativeAccount
|
||||
accountDir: string
|
||||
json_rpc_started = false
|
||||
jsonRpcStarted = false
|
||||
|
||||
constructor(cwd: string, os = 'deltachat-node') {
|
||||
super()
|
||||
@@ -122,17 +122,17 @@ export class AccountManager extends EventEmitter {
|
||||
if (!callback) {
|
||||
throw new Error('no callback set')
|
||||
}
|
||||
if (this.json_rpc_started) {
|
||||
if (this.jsonRpcStarted) {
|
||||
throw new Error('jsonrpc was started already')
|
||||
}
|
||||
|
||||
binding.dcn_accounts_start_jsonrpc(this.dcn_accounts, callback.bind(this))
|
||||
debug('Started jsonrpc handler')
|
||||
this.json_rpc_started = true
|
||||
this.jsonRpcStarted = true
|
||||
}
|
||||
|
||||
jsonRPCRequest(message: string) {
|
||||
if (!this.json_rpc_started) {
|
||||
if (!this.jsonRpcStarted) {
|
||||
throw new Error(
|
||||
'jsonrpc is not active, start it with startJSONRPCHandler first'
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ typedef struct dcn_accounts_t {
|
||||
uv_thread_t event_handler_thread;
|
||||
napi_threadsafe_function threadsafe_jsonrpc_handler;
|
||||
uv_thread_t jsonrpc_thread;
|
||||
dc_json_api_instance_t* jsonrpc_instance;
|
||||
dc_jsonrpc_instance_t* jsonrpc_instance;
|
||||
int gc;
|
||||
} dcn_accounts_t;
|
||||
|
||||
@@ -2936,7 +2936,7 @@ NAPI_METHOD(dcn_accounts_unref) {
|
||||
dcn_accounts->event_handler_thread = 0;
|
||||
}
|
||||
if (dcn_accounts->jsonrpc_instance) {
|
||||
dc_json_request(dcn_accounts->jsonrpc_instance, "{}");
|
||||
dc_jsonrpc_request(dcn_accounts->jsonrpc_instance, "{}");
|
||||
uv_thread_join(&dcn_accounts->jsonrpc_thread);
|
||||
dcn_accounts->jsonrpc_instance = NULL;
|
||||
}
|
||||
@@ -3256,7 +3256,7 @@ static void accounts_jsonrpc_thread_func(void* arg)
|
||||
TRACE("accounts_jsonrpc_thread_func starting");
|
||||
char* response;
|
||||
while (true) {
|
||||
response = dc_get_next_json_response(dcn_accounts->jsonrpc_instance);
|
||||
response = dc_jsonrpc_next_response(dcn_accounts->jsonrpc_instance);
|
||||
if (response == NULL) {
|
||||
// done or broken
|
||||
break;
|
||||
@@ -3279,7 +3279,7 @@ static void accounts_jsonrpc_thread_func(void* arg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
dc_json_api_unref(dcn_accounts->jsonrpc_instance);
|
||||
dc_jsonrpc_unref(dcn_accounts->jsonrpc_instance);
|
||||
dcn_accounts->jsonrpc_instance = NULL;
|
||||
TRACE("accounts_jsonrpc_thread_func ended");
|
||||
napi_release_threadsafe_function(dcn_accounts->threadsafe_jsonrpc_handler, napi_tsfn_release);
|
||||
@@ -3347,7 +3347,7 @@ NAPI_METHOD(dcn_accounts_start_jsonrpc) {
|
||||
TRACE("done");
|
||||
|
||||
dcn_accounts->gc = 0;
|
||||
dcn_accounts->jsonrpc_instance = dc_get_json_api(dcn_accounts->dc_accounts);
|
||||
dcn_accounts->jsonrpc_instance = dc_jsonrpc_init(dcn_accounts->dc_accounts);
|
||||
|
||||
TRACE("creating uv thread..");
|
||||
uv_thread_create(&dcn_accounts->jsonrpc_thread, accounts_jsonrpc_thread_func, dcn_accounts);
|
||||
@@ -3363,7 +3363,7 @@ NAPI_METHOD(dcn_json_rpc_request) {
|
||||
NAPI_STATUS_THROWS(napi_throw_type_error(env, NULL, msg));
|
||||
}
|
||||
NAPI_ARGV_UTF8_MALLOC(request, 1);
|
||||
dc_json_request(dcn_accounts->jsonrpc_instance, request);
|
||||
dc_jsonrpc_request(dcn_accounts->jsonrpc_instance, request);
|
||||
free(request);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user