From 70b91220e29492848c816a7228988ceee39661f6 Mon Sep 17 00:00:00 2001 From: graphemecluster Date: Thu, 25 Jan 2024 11:40:27 +0800 Subject: [PATCH] RIME API - Add APIs for appending remaining data types (bool, double, int) to config list - Include quick start method in `rime_api_t` - Adjust API Order --- src/rime_api.cc | 100 +++++++++++++++++++++++++++++++++++++++--------- src/rime_api.h | 17 ++++++-- 2 files changed, 95 insertions(+), 22 deletions(-) diff --git a/src/rime_api.cc b/src/rime_api.cc index e8e61f7d61..23506f1d9a 100644 --- a/src/rime_api.cc +++ b/src/rime_api.cc @@ -719,24 +719,6 @@ RIME_API Bool RimeConfigBeginList(RimeConfigIterator* iterator, iterator->list = new RimeConfigIteratorImpl(*list, key); return True; } -RIME_API Bool RimeConfigListAppendString(RimeConfig* config, const char* key, const char* value) { - if (!config) { - return False; - } - Config* c = reinterpret_cast(config->ptr); - if (!c) { - return False; - } - an list = c->GetList(key); - if (!list) { - return False; - } - auto val = New(); - val->SetString(value); - if(!list->Append(val)) - return False; - return True; -} RIME_API Bool RimeConfigBeginMap(RimeConfigIterator* iterator, RimeConfig* config, @@ -1008,6 +990,82 @@ RIME_API size_t RimeConfigListSize(RimeConfig* config, const char* key) { return 0; } +RIME_API Bool RimeConfigListAppendBool(RimeConfig* config, + const char* key, + Bool value) { + if (!config) { + return False; + } + Config* c = reinterpret_cast(config->ptr); + if (!c) { + return False; + } + an list = c->GetList(key); + if (!list) { + return False; + } + auto val = New(); + val->SetBool(value != False); + return Bool(list->Append(val)); +} + +RIME_API Bool RimeConfigListAppendDouble(RimeConfig* config, + const char* key, + double value) { + if (!config) { + return False; + } + Config* c = reinterpret_cast(config->ptr); + if (!c) { + return False; + } + an list = c->GetList(key); + if (!list) { + return False; + } + auto val = New(); + val->SetDouble(value); + return Bool(list->Append(val)); +} + +RIME_API Bool RimeConfigListAppendInt(RimeConfig* config, + const char* key, + int value) { + if (!config) { + return False; + } + Config* c = reinterpret_cast(config->ptr); + if (!c) { + return False; + } + an list = c->GetList(key); + if (!list) { + return False; + } + auto val = New(); + val->SetInt(value); + return Bool(list->Append(val)); +} + +RIME_API Bool RimeConfigListAppendString(RimeConfig* config, + const char* key, + const char* value) { + if (!config) { + return False; + } + Config* c = reinterpret_cast(config->ptr); + if (!c) { + return False; + } + an list = c->GetList(key); + if (!list) { + return False; + } + auto val = New(); + val->SetString(value); + return Bool(list->Append(val)); +} + const char* RimeGetInput(RimeSessionId session_id) { an session(Service::instance().GetSession(session_id)); if (!session) @@ -1125,6 +1183,7 @@ RIME_API RimeApi* rime_get_api() { s_api.initialize = &RimeInitialize; s_api.finalize = &RimeFinalize; s_api.start_maintenance = &RimeStartMaintenance; + s_api.start_quick = &RimeStartQuick; s_api.is_maintenance_mode = &RimeIsMaintenancing; s_api.join_maintenance_thread = &RimeJoinMaintenanceThread; s_api.deployer_initialize = &RimeDeployerInitialize; @@ -1165,6 +1224,7 @@ RIME_API RimeApi* rime_get_api() { s_api.config_get_string = &RimeConfigGetString; s_api.config_get_cstring = &RimeConfigGetCString; s_api.config_update_signature = &RimeConfigUpdateSignature; + s_api.config_begin_list = &RimeConfigBeginList; s_api.config_begin_map = &RimeConfigBeginMap; s_api.config_next = &RimeConfigNext; s_api.config_end = &RimeConfigEnd; @@ -1189,7 +1249,9 @@ RIME_API RimeApi* rime_get_api() { s_api.config_create_list = &RimeConfigCreateList; s_api.config_create_map = &RimeConfigCreateMap; s_api.config_list_size = &RimeConfigListSize; - s_api.config_begin_list = &RimeConfigBeginList; + s_api.config_list_append_bool = &RimeConfigListAppendBool; + s_api.config_list_append_int = &RimeConfigListAppendInt; + s_api.config_list_append_double = &RimeConfigListAppendDouble; s_api.config_list_append_string = &RimeConfigListAppendString; s_api.get_input = &RimeGetInput; s_api.get_caret_pos = &RimeGetCaretPos; diff --git a/src/rime_api.h b/src/rime_api.h index 157c7168a1..c3be016b5a 100644 --- a/src/rime_api.h +++ b/src/rime_api.h @@ -456,6 +456,7 @@ typedef struct rime_api_t { void (*finalize)(void); Bool (*start_maintenance)(Bool full_check); + Bool (*start_quick)(void); Bool (*is_maintenance_mode)(void); void (*join_maintenance_thread)(void); @@ -528,6 +529,9 @@ typedef struct rime_api_t { size_t buffer_size); const char* (*config_get_cstring)(RimeConfig* config, const char* key); Bool (*config_update_signature)(RimeConfig* config, const char* signer); + Bool (*config_begin_list)(RimeConfigIterator* iterator, + RimeConfig* config, + const char* key); Bool (*config_begin_map)(RimeConfigIterator* iterator, RimeConfig* config, const char* key); @@ -578,12 +582,19 @@ typedef struct rime_api_t { Bool (*config_create_list)(RimeConfig* config, const char* key); Bool (*config_create_map)(RimeConfig* config, const char* key); size_t (*config_list_size)(RimeConfig* config, const char* key); - Bool (*config_begin_list)(RimeConfigIterator* iterator, - RimeConfig* config, - const char* key); + Bool (*config_list_append_bool)(RimeConfig* config, + const char* key, + Bool value); + Bool (*config_list_append_int)(RimeConfig* config, + const char* key, + int value); + Bool (*config_list_append_double)(RimeConfig* config, + const char* key, + double value); Bool (*config_list_append_string)(RimeConfig* config, const char* key, const char* value); + //! get raw input /*! * NULL is returned if session does not exist.