Skip to content

Commit

Permalink
RIME API
Browse files Browse the repository at this point in the history
- Add APIs for appending remaining data types (bool, double, int) to config list
- Include quick start method in `rime_api_t`
- Adjust API Order
  • Loading branch information
graphemecluster committed Jan 25, 2024
1 parent 3a75234 commit 70b9122
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 22 deletions.
100 changes: 81 additions & 19 deletions src/rime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -719,24 +719,6 @@ RIME_API Bool RimeConfigBeginList(RimeConfigIterator* iterator,
iterator->list = new RimeConfigIteratorImpl<ConfigList>(*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*>(config->ptr);
if (!c) {
return False;
}
an<ConfigList> list = c->GetList(key);
if (!list) {
return False;
}
auto val = New<ConfigValue>();
val->SetString(value);
if(!list->Append(val))
return False;
return True;
}

RIME_API Bool RimeConfigBeginMap(RimeConfigIterator* iterator,
RimeConfig* config,
Expand Down Expand Up @@ -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*>(config->ptr);
if (!c) {
return False;
}
an<ConfigList> list = c->GetList(key);
if (!list) {
return False;
}
auto val = New<ConfigValue>();
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*>(config->ptr);
if (!c) {
return False;
}
an<ConfigList> list = c->GetList(key);
if (!list) {
return False;
}
auto val = New<ConfigValue>();
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*>(config->ptr);
if (!c) {
return False;
}
an<ConfigList> list = c->GetList(key);
if (!list) {
return False;
}
auto val = New<ConfigValue>();
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*>(config->ptr);
if (!c) {
return False;
}
an<ConfigList> list = c->GetList(key);
if (!list) {
return False;
}
auto val = New<ConfigValue>();
val->SetString(value);
return Bool(list->Append(val));
}

const char* RimeGetInput(RimeSessionId session_id) {
an<Session> session(Service::instance().GetSession(session_id));
if (!session)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
17 changes: 14 additions & 3 deletions src/rime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 70b9122

Please sign in to comment.