librime: rime_api_impl.h Source File

| librime 1.2 Rime Input Method Engine, the core library

rime_api_impl.h
Go to the documentation of this file.
1// intended to be included multiple times in c++ source files with different
2// RIME_FLAVORED macro definitions
3
4#include "rime_api.h"
5
6#include <rime/common.h>
7#include <rime/composition.h>
8#include <rime/config.h>
9#include <rime/context.h>
10#include <rime/deployer.h>
11#include <rime/key_event.h>
12#include <rime/menu.h>
13#include <rime/module.h>
14#include <rime/registry.h>
15#include <rime/schema.h>
16#include <rime/service.h>
17#include <rime/setup.h>
18#include <rime/signature.h>
19#include <rime/switches.h>
20
21using namespace rime;
22
23void rime_declare_module_dependencies();
24
25 RIME_DEPRECATED void RimeSetup(RimeTraits* traits) {
26 rime_declare_module_dependencies();
27
28 SetupDeployer(traits);
29 if (RIME_PROVIDED(traits, app_name)) {
30 if (RIME_STRUCT_HAS_MEMBER(*traits, traits->min_log_level) &&
31 RIME_STRUCT_HAS_MEMBER(*traits, traits->log_dir)) {
32 SetupLogging(traits->app_name, traits->min_log_level, traits->log_dir);
33 } else {
34 SetupLogging(traits->app_name);
35 }
36 }
37}
38
39 RIME_DEPRECATED void RimeSetNotificationHandler(RimeNotificationHandler handler,
40 void* context_object) {
41 if (handler) {
42 Service::instance().SetNotificationHandler(
43 [context_object, handler](auto id, auto type, auto value) {
44 handler(context_object, id, type, value);
45 });
46 } else {
47 Service::instance().ClearNotificationHandler();
48 }
49}
50
51 RIME_DEPRECATED void RimeInitialize(RimeTraits* traits) {
52 SetupDeployer(traits);
53 LoadModules(RIME_PROVIDED(traits, modules) ? traits->modules
54 : kDefaultModules);
55 Service::instance().StartService();
56}
57
58 RIME_DEPRECATED void RimeFinalize() {
59 Service::instance().deployer().JoinMaintenanceThread();
60 Service::instance().StopService();
61 Registry::instance().Clear();
62 ModuleManager::instance().UnloadModules();
63}
64
65 RIME_DEPRECATED Bool RimeStartMaintenance(Bool full_check) {
66 LoadModules(kDeployerModules);
67 Deployer& deployer(Service::instance().deployer());
68 deployer.RunTask("clean_old_log_files");
69 if (!deployer.RunTask("installation_update")) {
70 return False;
71 }
72 if (!full_check) {
73 TaskInitializer args{
74 vector<path>{
75 deployer.user_data_dir,
76 deployer.shared_data_dir,
77 },
78 };
79 if (!deployer.RunTask("detect_modifications", args)) {
80 return False;
81 }
82 LOG(INFO) << "changes detected; starting maintenance.";
83 }
84 deployer.ScheduleTask("workspace_update");
85 deployer.ScheduleTask("user_dict_upgrade");
86 deployer.ScheduleTask("cleanup_trash");
87 deployer.StartMaintenance();
88 return True;
89}
90
91 RIME_DEPRECATED Bool RimeStartMaintenanceOnWorkspaceChange() {
92 return RimeStartMaintenance(False);
93}
94
95 RIME_DEPRECATED Bool RimeIsMaintenancing() {
96 Deployer& deployer(Service::instance().deployer());
97 return Bool(deployer.IsMaintenanceMode());
98}
99
100 RIME_DEPRECATED void RimeJoinMaintenanceThread() {
101 Deployer& deployer(Service::instance().deployer());
102 deployer.JoinMaintenanceThread();
103}
104
105// deployment
106
107 RIME_DEPRECATED void RimeDeployerInitialize(RimeTraits* traits) {
108 SetupDeployer(traits);
109 LoadModules(RIME_PROVIDED(traits, modules) ? traits->modules
110 : kDeployerModules);
111}
112
113 RIME_DEPRECATED Bool RimePrebuildAllSchemas() {
114 Deployer& deployer(Service::instance().deployer());
115 return Bool(deployer.RunTask("prebuild_all_schemas"));
116}
117
118 RIME_DEPRECATED Bool RimeDeployWorkspace() {
119 Deployer& deployer(Service::instance().deployer());
120 return Bool(deployer.RunTask("installation_update") &&
121 deployer.RunTask("workspace_update") &&
122 deployer.RunTask("user_dict_upgrade") &&
123 deployer.RunTask("cleanup_trash"));
124}
125
126 RIME_DEPRECATED Bool RimeDeploySchema(const char* schema_file) {
127 Deployer& deployer(Service::instance().deployer());
128 return Bool(deployer.RunTask("schema_update", path(schema_file)));
129}
130
131 RIME_DEPRECATED Bool RimeDeployConfigFile(const char* file_name,
132 const char* version_key) {
133 Deployer& deployer(Service::instance().deployer());
134 TaskInitializer args(make_pair<string, string>(file_name, version_key));
135 return Bool(deployer.RunTask("config_file_update", args));
136}
137
138 RIME_DEPRECATED Bool RimeSyncUserData() {
139 Service::instance().CleanupAllSessions();
140 Deployer& deployer(Service::instance().deployer());
141 deployer.ScheduleTask("installation_update");
142 deployer.ScheduleTask("backup_config_files");
143 deployer.ScheduleTask("user_dict_sync");
144 return Bool(deployer.StartMaintenance());
145}
146
147// session management
148
149 RIME_DEPRECATED RimeSessionId RimeCreateSession() {
150 return Service::instance().CreateSession();
151}
152
153 RIME_DEPRECATED Bool RimeFindSession(RimeSessionId session_id) {
154 return Bool(session_id && Service::instance().GetSession(session_id));
155}
156
157 RIME_DEPRECATED Bool RimeDestroySession(RimeSessionId session_id) {
158 return Bool(Service::instance().DestroySession(session_id));
159}
160
161 RIME_DEPRECATED void RimeCleanupStaleSessions() {
162 Service::instance().CleanupStaleSessions();
163}
164
165 RIME_DEPRECATED void RimeCleanupAllSessions() {
166 Service::instance().CleanupAllSessions();
167}
168
169// input
170
171 RIME_DEPRECATED Bool RimeProcessKey(RimeSessionId session_id,
172 int keycode,
173 int mask) {
174 an<Session> session(Service::instance().GetSession(session_id));
175 if (!session)
176 return False;
177 return Bool(session->ProcessKey(KeyEvent(keycode, mask)));
178}
179
180 RIME_DEPRECATED Bool RimeCommitComposition(RimeSessionId session_id) {
181 an<Session> session(Service::instance().GetSession(session_id));
182 if (!session)
183 return False;
184 return Bool(session->CommitComposition());
185}
186
187 RIME_DEPRECATED void RimeClearComposition(RimeSessionId session_id) {
188 an<Session> session(Service::instance().GetSession(session_id));
189 if (!session)
190 return;
191 session->ClearComposition();
192}
193
194// output
195
196static void rime_candidate_copy(RimeCandidate* dest, const an<Candidate>& src) {
197 dest->text = new char[src->text().length() + 1];
198 std::strcpy(dest->text, src->text().c_str());
199 string comment(src->comment());
200 if (!comment.empty()) {
201 dest->comment = new char[comment.length() + 1];
202 std::strcpy(dest->comment, comment.c_str());
203 } else {
204 dest->comment = nullptr;
205 }
206 dest->reserved = nullptr;
207}
208
209 RIME_DEPRECATED Bool RimeGetContext(RimeSessionId session_id,
210 RIME_FLAVORED(RimeContext) * context) {
211 if (!context || context->data_size <= 0)
212 return False;
213 RIME_STRUCT_CLEAR(*context);
214 an<Session> session(Service::instance().GetSession(session_id));
215 if (!session)
216 return False;
217 Context* ctx = session->context();
218 if (!ctx)
219 return False;
220 if (ctx->IsComposing()) {
221 Preedit preedit = ctx->GetPreedit();
222 context->composition.length = preedit.text.length();
223 context->composition.preedit = new char[preedit.text.length() + 1];
224 std::strcpy(context->composition.preedit, preedit.text.c_str());
225 context->composition.cursor_pos = preedit.caret_pos;
226 context->composition.sel_start = preedit.sel_start;
227 context->composition.sel_end = preedit.sel_end;
228 if (RIME_STRUCT_HAS_MEMBER(*context, context->commit_text_preview)) {
229 string commit_text(ctx->GetCommitText());
230 if (!commit_text.empty()) {
231 context->commit_text_preview = new char[commit_text.length() + 1];
232 std::strcpy(context->commit_text_preview, commit_text.c_str());
233 }
234 }
235 }
236 if (ctx->HasMenu()) {
237 Segment& seg(ctx->composition().back());
238 int page_size = 5;
239 Schema* schema = session->schema();
240 if (schema)
241 page_size = schema->page_size();
242 int selected_index = seg.selected_index;
243 int page_no = selected_index / page_size;
244 the<Page> page(seg.menu->CreatePage(page_size, page_no));
245 if (page) {
246 context->menu.page_size = page_size;
247 context->menu.page_no = page_no;
248 context->menu.is_last_page = Bool(page->is_last_page);
249 context->menu.highlighted_candidate_index = selected_index % page_size;
250 int i = 0;
251 context->menu.num_candidates = page->candidates.size();
252 if (ctx->get_option("_hide_candidate")) {
253 context->menu.num_candidates = 0;
254 return True;
255 }
256 context->menu.candidates = new RimeCandidate[page->candidates.size()];
257 for (const an<Candidate>& cand : page->candidates) {
258 RimeCandidate* dest = &context->menu.candidates[i++];
259 rime_candidate_copy(dest, cand);
260 }
261 if (schema) {
262 const string& select_keys(schema->select_keys());
263 if (!select_keys.empty()) {
264 context->menu.select_keys = new char[select_keys.length() + 1];
265 std::strcpy(context->menu.select_keys, select_keys.c_str());
266 }
267 Config* config = schema->config();
268 an<ConfigList> select_labels =
269 config->GetList("menu/alternative_select_labels");
270 if (select_labels && (size_t)page_size <= select_labels->size()) {
271 context->select_labels = new char*[page_size];
272 for (size_t i = 0; i < (size_t)page_size; ++i) {
273 an<ConfigValue> value = select_labels->GetValueAt(i);
274 string label = value->str();
275 context->select_labels[i] = new char[label.length() + 1];
276 std::strcpy(context->select_labels[i], label.c_str());
277 }
278 }
279 }
280 }
281 }
282 return True;
283}
284
285 RIME_DEPRECATED Bool RimeFreeContext(RIME_FLAVORED(RimeContext) * context) {
286 if (!context || context->data_size <= 0)
287 return False;
288 delete[] context->composition.preedit;
289 for (int i = 0; i < context->menu.num_candidates; ++i) {
290 delete[] context->menu.candidates[i].text;
291 delete[] context->menu.candidates[i].comment;
292 }
293 delete[] context->menu.candidates;
294 delete[] context->menu.select_keys;
295 if (RIME_STRUCT_HAS_MEMBER(*context, context->select_labels) &&
296 context->select_labels) {
297 for (int i = 0; i < context->menu.page_size; ++i) {
298 delete[] context->select_labels[i];
299 }
300 delete[] context->select_labels;
301 }
302 if (RIME_STRUCT_HAS_MEMBER(*context, context->commit_text_preview)) {
303 delete[] context->commit_text_preview;
304 }
305 RIME_STRUCT_CLEAR(*context);
306 return True;
307}
308
309 RIME_DEPRECATED Bool RimeGetCommit(RimeSessionId session_id,
310 RimeCommit* commit) {
311 if (!commit)
312 return False;
313 RIME_STRUCT_CLEAR(*commit);
314 an<Session> session(Service::instance().GetSession(session_id));
315 if (!session)
316 return False;
317 const string& commit_text(session->commit_text());
318 if (!commit_text.empty()) {
319 commit->text = new char[commit_text.length() + 1];
320 std::strcpy(commit->text, commit_text.c_str());
321 session->ResetCommitText();
322 return True;
323 }
324 return False;
325}
326
327 RIME_DEPRECATED Bool RimeFreeCommit(RimeCommit* commit) {
328 if (!commit)
329 return False;
330 delete[] commit->text;
331 RIME_STRUCT_CLEAR(*commit);
332 return True;
333}
334
335 RIME_DEPRECATED Bool RimeGetStatus(RimeSessionId session_id,
336 RIME_FLAVORED(RimeStatus) * status) {
337 if (!status || status->data_size <= 0)
338 return False;
339 RIME_STRUCT_CLEAR(*status);
340 an<Session> session(Service::instance().GetSession(session_id));
341 if (!session)
342 return False;
343 Schema* schema = session->schema();
344 Context* ctx = session->context();
345 if (!schema || !ctx)
346 return False;
347 status->schema_id = new char[schema->schema_id().length() + 1];
348 std::strcpy(status->schema_id, schema->schema_id().c_str());
349 status->schema_name = new char[schema->schema_name().length() + 1];
350 std::strcpy(status->schema_name, schema->schema_name().c_str());
351 status->is_disabled = Bool(Service::instance().disabled());
352 status->is_composing = Bool(ctx->IsComposing());
353 status->is_ascii_mode = Bool(ctx->get_option("ascii_mode"));
354 status->is_full_shape = Bool(ctx->get_option("full_shape"));
355 status->is_simplified = Bool(ctx->get_option("simplification"));
356 status->is_traditional = Bool(ctx->get_option("traditional"));
357 status->is_ascii_punct = Bool(ctx->get_option("ascii_punct"));
358 return True;
359}
360
361 RIME_DEPRECATED Bool RimeFreeStatus(RIME_FLAVORED(RimeStatus) * status) {
362 if (!status || status->data_size <= 0)
363 return False;
364 delete[] status->schema_id;
365 delete[] status->schema_name;
366 RIME_STRUCT_CLEAR(*status);
367 return True;
368}
369
370// accessing candidate list
371
372 RIME_DEPRECATED Bool
373RimeCandidateListFromIndex(RimeSessionId session_id,
374 RimeCandidateListIterator* iterator,
375 int index) {
376 if (!iterator)
377 return False;
378 an<Session> session(Service::instance().GetSession(session_id));
379 if (!session)
380 return False;
381 Context* ctx = session->context();
382 if (!ctx || !ctx->HasMenu())
383 return False;
384 memset(iterator, 0, sizeof(RimeCandidateListIterator));
385 iterator->ptr = ctx->composition().back().menu.get();
386 iterator->index = index - 1;
387 return True;
388}
389
390 RIME_DEPRECATED Bool
391RimeCandidateListBegin(RimeSessionId session_id,
392 RimeCandidateListIterator* iterator) {
393 return RimeCandidateListFromIndex(session_id, iterator, 0);
394}
395
396 RIME_DEPRECATED Bool
397RimeCandidateListNext(RimeCandidateListIterator* iterator) {
398 if (!iterator)
399 return False;
400 Menu* menu = reinterpret_cast<Menu*>(iterator->ptr);
401 if (!menu)
402 return False;
403 ++iterator->index;
404 if (auto cand = menu->GetCandidateAt((size_t)iterator->index)) {
405 delete[] iterator->candidate.text;
406 delete[] iterator->candidate.comment;
407 rime_candidate_copy(&iterator->candidate, cand);
408 return True;
409 }
410 return False;
411}
412
413 RIME_DEPRECATED void RimeCandidateListEnd(RimeCandidateListIterator* iterator) {
414 if (!iterator)
415 return;
416 delete[] iterator->candidate.text;
417 delete[] iterator->candidate.comment;
418 memset(iterator, 0, sizeof(RimeCandidateListIterator));
419}
420
421// runtime options
422
423 RIME_DEPRECATED void RimeSetOption(RimeSessionId session_id,
424 const char* option,
425 Bool value) {
426 an<Session> session(Service::instance().GetSession(session_id));
427 if (!session)
428 return;
429 Context* ctx = session->context();
430 if (!ctx)
431 return;
432 ctx->set_option(option, !!value);
433}
434
435 RIME_DEPRECATED Bool RimeGetOption(RimeSessionId session_id,
436 const char* option) {
437 an<Session> session(Service::instance().GetSession(session_id));
438 if (!session)
439 return False;
440 Context* ctx = session->context();
441 if (!ctx)
442 return False;
443 return Bool(ctx->get_option(option));
444}
445
446 RIME_DEPRECATED void RimeSetProperty(RimeSessionId session_id,
447 const char* prop,
448 const char* value) {
449 an<Session> session(Service::instance().GetSession(session_id));
450 if (!session)
451 return;
452 Context* ctx = session->context();
453 if (!ctx)
454 return;
455 ctx->set_property(prop, value);
456}
457
458 RIME_DEPRECATED Bool RimeGetProperty(RimeSessionId session_id,
459 const char* prop,
460 char* value,
461 size_t buffer_size) {
462 an<Session> session(Service::instance().GetSession(session_id));
463 if (!session)
464 return False;
465 Context* ctx = session->context();
466 if (!ctx)
467 return False;
468 string str_value(ctx->get_property(prop));
469 if (str_value.empty())
470 return False;
471 strncpy(value, str_value.c_str(), buffer_size);
472 return True;
473}
474
475 RIME_DEPRECATED Bool RimeGetSchemaList(RimeSchemaList* output) {
476 if (!output)
477 return False;
478 output->size = 0;
479 output->list = NULL;
480 Schema default_schema;
481 Config* config = default_schema.config();
482 if (!config)
483 return False;
484 an<ConfigList> schema_list = config->GetList("schema_list");
485 if (!schema_list || schema_list->size() == 0)
486 return False;
487 output->list = new RimeSchemaListItem[schema_list->size()];
488 for (size_t i = 0; i < schema_list->size(); ++i) {
489 an<ConfigMap> item = As<ConfigMap>(schema_list->GetAt(i));
490 if (!item)
491 continue;
492 an<ConfigValue> schema_property = item->GetValue("schema");
493 if (!schema_property)
494 continue;
495 const string& schema_id(schema_property->str());
496 RimeSchemaListItem& x(output->list[output->size]);
497 x.schema_id = new char[schema_id.length() + 1];
498 strcpy(x.schema_id, schema_id.c_str());
499 Schema schema(schema_id);
500 x.name = new char[schema.schema_name().length() + 1];
501 strcpy(x.name, schema.schema_name().c_str());
502 x.reserved = NULL;
503 ++output->size;
504 }
505 if (output->size == 0) {
506 delete[] output->list;
507 output->list = NULL;
508 return False;
509 }
510 return True;
511}
512
513 RIME_DEPRECATED void RimeFreeSchemaList(RimeSchemaList* schema_list) {
514 if (!schema_list)
515 return;
516 if (schema_list->list) {
517 for (size_t i = 0; i < schema_list->size; ++i) {
518 delete[] schema_list->list[i].schema_id;
519 delete[] schema_list->list[i].name;
520 }
521 delete[] schema_list->list;
522 }
523 schema_list->size = 0;
524 schema_list->list = NULL;
525}
526
527 RIME_DEPRECATED Bool RimeGetCurrentSchema(RimeSessionId session_id,
528 char* schema_id,
529 size_t buffer_size) {
530 an<Session> session(Service::instance().GetSession(session_id));
531 if (!session)
532 return False;
533 Schema* schema = session->schema();
534 if (!schema)
535 return False;
536 strncpy(schema_id, schema->schema_id().c_str(), buffer_size);
537 return True;
538}
539
540 RIME_DEPRECATED Bool RimeSelectSchema(RimeSessionId session_id,
541 const char* schema_id) {
542 if (!schema_id)
543 return False;
544 an<Session> session(Service::instance().GetSession(session_id));
545 if (!session)
546 return False;
547 session->ApplySchema(new Schema(schema_id));
548 return True;
549}
550
551// config
552
553static Bool open_config_in_component(const char* config_component,
554 const char* config_id,
555 RimeConfig* config) {
556 if (!config_id || !config)
557 return False;
558 Config::Component* cc = Config::Require(config_component);
559 if (!cc)
560 return False;
561 Config* c = cc->Create(config_id);
562 if (!c)
563 return False;
564 config->ptr = (void*)c;
565 return True;
566}
567
568 RIME_DEPRECATED Bool RimeSchemaOpen(const char* schema_id, RimeConfig* config) {
569 return open_config_in_component("schema", schema_id, config);
570}
571
572 RIME_DEPRECATED Bool RimeConfigOpen(const char* config_id, RimeConfig* config) {
573 return open_config_in_component("config", config_id, config);
574}
575
576 RIME_DEPRECATED Bool RimeUserConfigOpen(const char* config_id,
577 RimeConfig* config) {
578 return open_config_in_component("user_config", config_id, config);
579}
580
581 RIME_DEPRECATED Bool RimeConfigClose(RimeConfig* config) {
582 if (!config || !config->ptr)
583 return False;
584 Config* c = reinterpret_cast<Config*>(config->ptr);
585 delete c;
586 config->ptr = NULL;
587 return True;
588}
589
590 RIME_DEPRECATED Bool RimeConfigGetBool(RimeConfig* config,
591 const char* key,
592 Bool* value) {
593 if (!config || !key || !value)
594 return False;
595 Config* c = reinterpret_cast<Config*>(config->ptr);
596 bool bool_value = false;
597 if (c->GetBool(key, &bool_value)) {
598 *value = Bool(bool_value);
599 return True;
600 }
601 return False;
602}
603
604 RIME_DEPRECATED Bool RimeConfigGetInt(RimeConfig* config,
605 const char* key,
606 int* value) {
607 if (!config || !key || !value)
608 return False;
609 Config* c = reinterpret_cast<Config*>(config->ptr);
610 return Bool(c->GetInt(key, value));
611}
612
613 RIME_DEPRECATED Bool RimeConfigGetDouble(RimeConfig* config,
614 const char* key,
615 double* value) {
616 if (!config || !key || !value)
617 return False;
618 Config* c = reinterpret_cast<Config*>(config->ptr);
619 return Bool(c->GetDouble(key, value));
620}
621
622 RIME_DEPRECATED Bool RimeConfigGetString(RimeConfig* config,
623 const char* key,
624 char* value,
625 size_t buffer_size) {
626 if (!config || !key || !value)
627 return False;
628 Config* c = reinterpret_cast<Config*>(config->ptr);
629 if (!c)
630 return False;
631 string str_value;
632 if (c->GetString(key, &str_value)) {
633 std::strncpy(value, str_value.c_str(), buffer_size);
634 return True;
635 }
636 return False;
637}
638
639 RIME_DEPRECATED const char* RimeConfigGetCString(RimeConfig* config,
640 const char* key) {
641 if (!config || !key)
642 return NULL;
643 Config* c = reinterpret_cast<Config*>(config->ptr);
644 if (!c)
645 return NULL;
646 if (an<ConfigValue> v = c->GetValue(key)) {
647 return v->str().c_str();
648 }
649 return NULL;
650}
651
652 RIME_DEPRECATED Bool RimeConfigUpdateSignature(RimeConfig* config,
653 const char* signer) {
654 if (!config || !signer)
655 return False;
656 Config* c = reinterpret_cast<Config*>(config->ptr);
657 Deployer& deployer(Service::instance().deployer());
658 Signature sig(signer);
659 return Bool(sig.Sign(c, &deployer));
660}
661
662template <class T>
663 struct RimeConfigIteratorImpl {
664 typename T::Iterator iter;
665 typename T::Iterator end;
666 string prefix;
667 string key;
668 string path;
669 RimeConfigIteratorImpl<T>(T& container, const string& root_path)
670 : iter(container.begin()), end(container.end()) {
671 if (root_path.empty() || root_path == "/") {
672 // prefix is empty
673 } else {
674 prefix = root_path + "/";
675 }
676 }
677};
678
679 RIME_DEPRECATED Bool RimeConfigBeginList(RimeConfigIterator* iterator,
680 RimeConfig* config,
681 const char* key) {
682 if (!iterator || !config || !key)
683 return False;
684 iterator->list = NULL;
685 iterator->map = NULL;
686 iterator->index = -1;
687 iterator->key = NULL;
688 iterator->path = NULL;
689 Config* c = reinterpret_cast<Config*>(config->ptr);
690 if (!c)
691 return False;
692 an<ConfigList> list = c->GetList(key);
693 if (!list)
694 return False;
695 iterator->list = new RimeConfigIteratorImpl<ConfigList>(*list, key);
696 return True;
697}
698
699 RIME_DEPRECATED Bool RimeConfigBeginMap(RimeConfigIterator* iterator,
700 RimeConfig* config,
701 const char* key) {
702 if (!iterator || !config || !key)
703 return False;
704 iterator->list = NULL;
705 iterator->map = NULL;
706 iterator->index = -1;
707 iterator->key = NULL;
708 iterator->path = NULL;
709 Config* c = reinterpret_cast<Config*>(config->ptr);
710 if (!c)
711 return False;
712 an<ConfigMap> m = c->GetMap(key);
713 if (!m)
714 return False;
715 iterator->map = new RimeConfigIteratorImpl<ConfigMap>(*m, key);
716 return True;
717}
718
719 RIME_DEPRECATED Bool RimeConfigNext(RimeConfigIterator* iterator) {
720 if (!iterator->list && !iterator->map)
721 return False;
722 if (iterator->list) {
723 RimeConfigIteratorImpl<ConfigList>* p =
724 reinterpret_cast<RimeConfigIteratorImpl<ConfigList>*>(iterator->list);
725 if (!p)
726 return False;
727 if (++iterator->index > 0)
728 ++p->iter;
729 if (p->iter == p->end)
730 return False;
731 std::ostringstream key;
732 key << "@" << iterator->index;
733 p->key = key.str();
734 p->path = p->prefix + p->key;
735 iterator->key = p->key.c_str();
736 iterator->path = p->path.c_str();
737 return True;
738 }
739 if (iterator->map) {
740 RimeConfigIteratorImpl<ConfigMap>* p =
741 reinterpret_cast<RimeConfigIteratorImpl<ConfigMap>*>(iterator->map);
742 if (!p)
743 return False;
744 if (++iterator->index > 0)
745 ++p->iter;
746 if (p->iter == p->end)
747 return False;
748 p->key = p->iter->first;
749 p->path = p->prefix + p->key;
750 iterator->key = p->key.c_str();
751 iterator->path = p->path.c_str();
752 return True;
753 }
754 return False;
755}
756
757 RIME_DEPRECATED void RimeConfigEnd(RimeConfigIterator* iterator) {
758 if (!iterator)
759 return;
760 if (iterator->list)
761 delete reinterpret_cast<RimeConfigIteratorImpl<ConfigList>*>(
762 iterator->list);
763 if (iterator->map)
764 delete reinterpret_cast<RimeConfigIteratorImpl<ConfigMap>*>(iterator->map);
765 memset(iterator, 0, sizeof(RimeConfigIterator));
766}
767
768 RIME_DEPRECATED Bool RimeSimulateKeySequence(RimeSessionId session_id,
769 const char* key_sequence) {
770 LOG(INFO) << "simulate key sequence: " << key_sequence;
771 an<Session> session(Service::instance().GetSession(session_id));
772 if (!session)
773 return False;
774 KeySequence keys;
775 if (!keys.Parse(key_sequence)) {
776 LOG(ERROR) << "error parsing input: '" << key_sequence << "'";
777 return False;
778 }
779 for (const KeyEvent& key : keys) {
780 session->ProcessKey(key);
781 }
782 return True;
783}
784
785 RIME_DEPRECATED Bool RimeRunTask(const char* task_name) {
786 if (!task_name)
787 return False;
788 Deployer& deployer(Service::instance().deployer());
789 return Bool(deployer.RunTask(task_name));
790}
791
792 RIME_DEPRECATED const char* RimeGetSharedDataDir() {
793 Deployer& deployer(Service::instance().deployer());
794 static string string_path;
795 string_path = deployer.shared_data_dir.string();
796 return string_path.c_str();
797}
798
799 RIME_DEPRECATED const char* RimeGetUserDataDir() {
800 Deployer& deployer(Service::instance().deployer());
801 static string string_path;
802 string_path = deployer.user_data_dir.string();
803 return string_path.c_str();
804}
805
806 RIME_DEPRECATED const char* RimeGetPrebuiltDataDir() {
807 Deployer& deployer(Service::instance().deployer());
808 static string string_path;
809 string_path = deployer.prebuilt_data_dir.string();
810 return string_path.c_str();
811}
812
813 RIME_DEPRECATED const char* RimeGetStagingDir() {
814 Deployer& deployer(Service::instance().deployer());
815 static string string_path;
816 string_path = deployer.staging_dir.string();
817 return string_path.c_str();
818}
819
820 RIME_DEPRECATED const char* RimeGetSyncDir() {
821 Deployer& deployer(Service::instance().deployer());
822 static string string_path;
823 string_path = deployer.sync_dir.string();
824 return string_path.c_str();
825}
826
827 RIME_DEPRECATED const char* RimeGetUserId() {
828 Deployer& deployer(Service::instance().deployer());
829 return deployer.user_id.c_str();
830}
831
832 RIME_DEPRECATED void RimeGetUserDataSyncDir(char* dir, size_t buffer_size) {
833 Deployer& deployer(Service::instance().deployer());
834 string string_path = deployer.user_data_sync_dir().string();
835 strncpy(dir, string_path.c_str(), buffer_size);
836}
837
838 RIME_DEPRECATED Bool RimeConfigInit(RimeConfig* config) {
839 if (!config || config->ptr)
840 return False;
841 config->ptr = (void*)new Config;
842 return True;
843}
844
845 RIME_DEPRECATED Bool RimeConfigLoadString(RimeConfig* config,
846 const char* yaml) {
847 if (!config || !yaml) {
848 return False;
849 }
850 if (!config->ptr) {
851 RimeConfigInit(config);
852 }
853 Config* c = reinterpret_cast<Config*>(config->ptr);
854 std::istringstream iss(yaml);
855 return Bool(c->LoadFromStream(iss));
856}
857
858 RIME_DEPRECATED Bool RimeConfigGetItem(RimeConfig* config,
859 const char* key,
860 RimeConfig* value) {
861 if (!config || !key || !value)
862 return False;
863 Config* c = reinterpret_cast<Config*>(config->ptr);
864 if (!c)
865 return False;
866 if (!value->ptr) {
867 RimeConfigInit(value);
868 }
869 Config* v = reinterpret_cast<Config*>(value->ptr);
870 *v = c->GetItem(key);
871 return True;
872}
873
874 RIME_DEPRECATED Bool RimeConfigSetItem(RimeConfig* config,
875 const char* key,
876 RimeConfig* value) {
877 if (!config || !key)
878 return False;
879 Config* c = reinterpret_cast<Config*>(config->ptr);
880 if (!c)
881 return False;
882 an<ConfigItem> item;
883 if (value) {
884 if (Config* v = reinterpret_cast<Config*>(value->ptr)) {
885 item = v->GetItem("");
886 }
887 }
888 return Bool(c->SetItem(key, item));
889}
890
891 RIME_DEPRECATED Bool RimeConfigSetBool(RimeConfig* config,
892 const char* key,
893 Bool value) {
894 if (!config || !key)
895 return False;
896 Config* c = reinterpret_cast<Config*>(config->ptr);
897 if (!c)
898 return False;
899 return c->SetBool(key, value != False);
900}
901
902 RIME_DEPRECATED Bool RimeConfigSetInt(RimeConfig* config,
903 const char* key,
904 int value) {
905 if (!config || !key)
906 return False;
907 Config* c = reinterpret_cast<Config*>(config->ptr);
908 if (!c)
909 return False;
910 return Bool(c->SetInt(key, value));
911}
912
913 RIME_DEPRECATED Bool RimeConfigSetDouble(RimeConfig* config,
914 const char* key,
915 double value) {
916 if (!config || !key)
917 return False;
918 Config* c = reinterpret_cast<Config*>(config->ptr);
919 if (!c)
920 return False;
921 return Bool(c->SetDouble(key, value));
922}
923
924 RIME_DEPRECATED Bool RimeConfigSetString(RimeConfig* config,
925 const char* key,
926 const char* value) {
927 if (!config || !key || !value)
928 return False;
929 Config* c = reinterpret_cast<Config*>(config->ptr);
930 if (!c)
931 return False;
932 return Bool(c->SetString(key, value));
933}
934
935 RIME_DEPRECATED Bool RimeConfigClear(RimeConfig* config, const char* key) {
936 if (!config || !key)
937 return False;
938 Config* c = reinterpret_cast<Config*>(config->ptr);
939 if (!c)
940 return False;
941 return Bool(c->SetItem(key, nullptr));
942}
943
944 RIME_DEPRECATED Bool RimeConfigCreateList(RimeConfig* config, const char* key) {
945 if (!config || !key)
946 return False;
947 Config* c = reinterpret_cast<Config*>(config->ptr);
948 if (!c)
949 return False;
950 return Bool(c->SetItem(key, New<ConfigList>()));
951}
952
953 RIME_DEPRECATED Bool RimeConfigCreateMap(RimeConfig* config, const char* key) {
954 if (!config || !key)
955 return False;
956 Config* c = reinterpret_cast<Config*>(config->ptr);
957 if (!c)
958 return False;
959 return Bool(c->SetItem(key, New<ConfigMap>()));
960}
961
962 RIME_DEPRECATED size_t RimeConfigListSize(RimeConfig* config, const char* key) {
963 if (!config || !key)
964 return 0;
965 Config* c = reinterpret_cast<Config*>(config->ptr);
966 if (!c)
967 return 0;
968 if (an<ConfigList> list = c->GetList(key)) {
969 return list->size();
970 }
971 return 0;
972}
973
974static bool do_with_candidate(RimeSessionId session_id,
975 size_t index,
976 bool (Context::*verb)(size_t index)) {
977 an<Session> session(Service::instance().GetSession(session_id));
978 if (!session)
979 return false;
980 Context* ctx = session->context();
981 if (!ctx)
982 return false;
983 return (ctx->*verb)(index);
984}
985
986static bool do_with_candidate_on_current_page(
987 RimeSessionId session_id,
988 size_t index,
989 bool (Context::*verb)(size_t index)) {
990 an<Session> session(Service::instance().GetSession(session_id));
991 if (!session)
992 return false;
993 Context* ctx = session->context();
994 if (!ctx || !ctx->HasMenu())
995 return false;
996 Schema* schema = session->schema();
997 if (!schema)
998 return false;
999 size_t page_size = (size_t)schema->page_size();
1000 if (index >= page_size)
1001 return false;
1002 const auto& seg(ctx->composition().back());
1003 size_t page_start = seg.selected_index / page_size * page_size;
1004 return (ctx->*verb)(page_start + index);
1005}
1006
1007static Bool RimeChangePage(RimeSessionId session_id, Bool backward) {
1008 an<Session> session(Service::instance().GetSession(session_id));
1009 if (!session)
1010 return False;
1011 Context* ctx = session->context();
1012 if (!ctx || !ctx->HasMenu())
1013 return False;
1014 Schema* schema = session->schema();
1015 if (!schema)
1016 return False;
1017 size_t page_size = (size_t)schema->page_size();
1018 auto& seg(ctx->composition().back());
1019 size_t current_index = seg.selected_index;
1020 size_t index =
1021 backward ? (current_index <= page_size ? 0 : current_index - page_size)
1022 : (current_index + page_size);
1023 DLOG(INFO) << "current selection: " << current_index << ", flipping "
1024 << (backward ? "backward" : "forward") << ", new selection "
1025 << index;
1026 seg.tags.insert("paging");
1027 return Bool(ctx->Highlight(index));
1028}
1029
1030static Bool RimeHighlightCandidate(RimeSessionId session_id, size_t index) {
1031 return (Bool)do_with_candidate(session_id, index, &Context::Highlight);
1032}
1033
1034static Bool RimeHighlightCandidateOnCurrentPage(RimeSessionId session_id,
1035 size_t index) {
1036 return (Bool)do_with_candidate_on_current_page(session_id, index,
1037 &Context::Highlight);
1038}
1039
1040 RIME_DEPRECATED Bool RimeSelectCandidate(RimeSessionId session_id,
1041 size_t index) {
1042 return (Bool)do_with_candidate(session_id, index, &Context::Select);
1043}
1044
1045 RIME_DEPRECATED Bool RimeSelectCandidateOnCurrentPage(RimeSessionId session_id,
1046 size_t index) {
1047 return (Bool)do_with_candidate_on_current_page(session_id, index,
1048 &Context::Select);
1049}
1050
1051 RIME_DEPRECATED Bool RimeDeleteCandidate(RimeSessionId session_id,
1052 size_t index) {
1053 return (Bool)do_with_candidate(session_id, index, &Context::DeleteCandidate);
1054}
1055
1056 RIME_DEPRECATED Bool RimeDeleteCandidateOnCurrentPage(RimeSessionId session_id,
1057 size_t index) {
1058 return (Bool)do_with_candidate_on_current_page(session_id, index,
1059 &Context::DeleteCandidate);
1060}
1061
1062static const char* RimeGetInput(RimeSessionId session_id) {
1063 an<Session> session(Service::instance().GetSession(session_id));
1064 if (!session)
1065 return NULL;
1066 Context* ctx = session->context();
1067 if (!ctx)
1068 return NULL;
1069 return ctx->input().c_str();
1070}
1071
1072 RIME_DEPRECATED Bool RimeSetInput(RimeSessionId session_id, const char* input) {
1073 an<Session> session(Service::instance().GetSession(session_id));
1074 if (!session)
1075 return False;
1076 Context* ctx = session->context();
1077 if (!ctx)
1078 return False;
1079 ctx->set_input(input);
1080 return True;
1081}
1082
1083static size_t RimeGetCaretPos(RimeSessionId session_id) {
1084 an<Session> session(Service::instance().GetSession(session_id));
1085 if (!session)
1086 return 0;
1087 Context* ctx = session->context();
1088 if (!ctx)
1089 return 0;
1090 return ctx->caret_pos();
1091}
1092
1093static void RimeSetCaretPos(RimeSessionId session_id, size_t caret_pos) {
1094 an<Session> session(Service::instance().GetSession(session_id));
1095 if (!session)
1096 return;
1097 Context* ctx = session->context();
1098 if (!ctx)
1099 return;
1100 return ctx->set_caret_pos(caret_pos);
1101}
1102
1103static RimeStringSlice RimeGetStateLabelAbbreviated(RimeSessionId session_id,
1104 const char* option_name,
1105 Bool state,
1106 Bool abbreviated) {
1107 an<Session> session(Service::instance().GetSession(session_id));
1108 if (!session)
1109 return {nullptr, 0};
1110 Config* config = session->schema()->config();
1111 if (!config)
1112 return {nullptr, 0};
1113 Switches switches(config);
1114 StringSlice label = switches.GetStateLabel(option_name, state, abbreviated);
1115 return {label.str, label.length};
1116}
1117
1118static const char* RimeGetStateLabel(RimeSessionId session_id,
1119 const char* option_name,
1120 Bool state) {
1121 return RimeGetStateLabelAbbreviated(session_id, option_name, state, False)
1122 .str;
1123}
1124
1125void RimeGetSharedDataDirSecure(char* dir, size_t buffer_size);
1126void RimeGetUserDataDirSecure(char* dir, size_t buffer_size);
1127void RimeGetPrebuiltDataDirSecure(char* dir, size_t buffer_size);
1128void RimeGetStagingDirSecure(char* dir, size_t buffer_size);
1129void RimeGetSyncDirSecure(char* dir, size_t buffer_size);
1130const char* RimeGetVersion();
1131
1132 RIME_API RIME_FLAVORED(RimeApi) * RIME_FLAVORED(rime_get_api)() {
1133 static RIME_FLAVORED(RimeApi) s_api = {0};
1134 if (!s_api.data_size) {
1135 RIME_STRUCT_INIT(RIME_FLAVORED(RimeApi), s_api);
1136 s_api.setup = &RimeSetup;
1137 s_api.set_notification_handler = &RimeSetNotificationHandler;
1138 s_api.initialize = &RimeInitialize;
1139 s_api.finalize = &RimeFinalize;
1140 s_api.start_maintenance = &RimeStartMaintenance;
1141 s_api.is_maintenance_mode = &RimeIsMaintenancing;
1142 s_api.join_maintenance_thread = &RimeJoinMaintenanceThread;
1143 s_api.deployer_initialize = &RimeDeployerInitialize;
1144 s_api.prebuild = &RimePrebuildAllSchemas;
1145 s_api.deploy = &RimeDeployWorkspace;
1146 s_api.deploy_schema = &RimeDeploySchema;
1147 s_api.deploy_config_file = &RimeDeployConfigFile;
1148 s_api.sync_user_data = &RimeSyncUserData;
1149 s_api.create_session = &RimeCreateSession;
1150 s_api.find_session = &RimeFindSession;
1151 s_api.destroy_session = &RimeDestroySession;
1152 s_api.cleanup_stale_sessions = &RimeCleanupStaleSessions;
1153 s_api.cleanup_all_sessions = &RimeCleanupAllSessions;
1154 s_api.process_key = &RimeProcessKey;
1155 s_api.commit_composition = &RimeCommitComposition;
1156 s_api.clear_composition = &RimeClearComposition;
1157 s_api.get_commit = &RimeGetCommit;
1158 s_api.free_commit = &RimeFreeCommit;
1159 s_api.get_context = &RimeGetContext;
1160 s_api.free_context = &RimeFreeContext;
1161 s_api.get_status = &RimeGetStatus;
1162 s_api.free_status = &RimeFreeStatus;
1163 s_api.set_option = &RimeSetOption;
1164 s_api.get_option = &RimeGetOption;
1165 s_api.set_property = &RimeSetProperty;
1166 s_api.get_property = &RimeGetProperty;
1167 s_api.get_schema_list = &RimeGetSchemaList;
1168 s_api.free_schema_list = &RimeFreeSchemaList;
1169 s_api.get_current_schema = &RimeGetCurrentSchema;
1170 s_api.select_schema = &RimeSelectSchema;
1171 s_api.schema_open = &RimeSchemaOpen;
1172 s_api.config_open = &RimeConfigOpen;
1173 s_api.user_config_open = &RimeUserConfigOpen;
1174 s_api.config_close = &RimeConfigClose;
1175 s_api.config_get_bool = &RimeConfigGetBool;
1176 s_api.config_get_int = &RimeConfigGetInt;
1177 s_api.config_get_double = &RimeConfigGetDouble;
1178 s_api.config_get_string = &RimeConfigGetString;
1179 s_api.config_get_cstring = &RimeConfigGetCString;
1180 s_api.config_update_signature = &RimeConfigUpdateSignature;
1181 s_api.config_begin_map = &RimeConfigBeginMap;
1182 s_api.config_next = &RimeConfigNext;
1183 s_api.config_end = &RimeConfigEnd;
1184 s_api.simulate_key_sequence = &RimeSimulateKeySequence;
1185 s_api.register_module = &RimeRegisterModule;
1186 s_api.find_module = &RimeFindModule;
1187 s_api.run_task = &RimeRunTask;
1188 s_api.get_shared_data_dir = &RimeGetSharedDataDir;
1189 s_api.get_user_data_dir = &RimeGetUserDataDir;
1190 s_api.get_sync_dir = &RimeGetSyncDir;
1191 s_api.get_user_id = &RimeGetUserId;
1192 s_api.get_user_data_sync_dir = &RimeGetUserDataSyncDir;
1193 s_api.config_init = &RimeConfigInit;
1194 s_api.config_load_string = &RimeConfigLoadString;
1195 s_api.config_set_bool = &RimeConfigSetBool;
1196 s_api.config_set_int = &RimeConfigSetInt;
1197 s_api.config_set_double = &RimeConfigSetDouble;
1198 s_api.config_set_string = &RimeConfigSetString;
1199 s_api.config_get_item = &RimeConfigGetItem;
1200 s_api.config_set_item = &RimeConfigSetItem;
1201 s_api.config_clear = &RimeConfigClear;
1202 s_api.config_create_list = &RimeConfigCreateList;
1203 s_api.config_create_map = &RimeConfigCreateMap;
1204 s_api.config_list_size = &RimeConfigListSize;
1205 s_api.config_begin_list = &RimeConfigBeginList;
1206 s_api.get_input = &RimeGetInput;
1207 s_api.get_caret_pos = &RimeGetCaretPos;
1208 s_api.select_candidate = &RimeSelectCandidate;
1209 s_api.get_version = &RimeGetVersion;
1210 s_api.set_caret_pos = &RimeSetCaretPos;
1211 s_api.select_candidate_on_current_page = &RimeSelectCandidateOnCurrentPage;
1212 s_api.candidate_list_begin = &RimeCandidateListBegin;
1213 s_api.candidate_list_next = &RimeCandidateListNext;
1214 s_api.candidate_list_end = &RimeCandidateListEnd;
1215 s_api.candidate_list_from_index = &RimeCandidateListFromIndex;
1216 s_api.get_prebuilt_data_dir = &RimeGetPrebuiltDataDir;
1217 s_api.get_staging_dir = &RimeGetStagingDir;
1218 s_api.commit_proto = nullptr;
1219 s_api.context_proto = nullptr;
1220 s_api.status_proto = nullptr;
1221 s_api.get_state_label = &RimeGetStateLabel;
1222 s_api.delete_candidate = &RimeDeleteCandidate;
1223 s_api.delete_candidate_on_current_page = &RimeDeleteCandidateOnCurrentPage;
1224 s_api.get_state_label_abbreviated = &RimeGetStateLabelAbbreviated;
1225 s_api.set_input = &RimeSetInput;
1226 s_api.get_shared_data_dir_s = &RimeGetSharedDataDirSecure;
1227 s_api.get_user_data_dir_s = &RimeGetUserDataDirSecure;
1228 s_api.get_prebuilt_data_dir_s = &RimeGetPrebuiltDataDirSecure;
1229 s_api.get_staging_dir_s = &RimeGetStagingDirSecure;
1230 s_api.get_sync_dir_s = &RimeGetSyncDirSecure;
1231 s_api.highlight_candidate = &RimeHighlightCandidate;
1232 s_api.highlight_candidate_on_current_page =
1233 &RimeHighlightCandidateOnCurrentPage;
1234 s_api.change_page = &RimeChangePage;
1235 }
1236 return &s_api;
1237}
rime_api.h
RimeCandidateListIterator
struct rime_candidate_list_iterator_t RimeCandidateListIterator
RIME_PROVIDED
#define RIME_PROVIDED(p, member)
Definition rime_api.h:74
RimeSchemaListItem
struct rime_schema_list_item_t RimeSchemaListItem
False
#define False
Definition rime_api.h:50
RimeSessionId
uintptr_t RimeSessionId
Definition rime_api.h:57
RIME_STRUCT_INIT
#define RIME_STRUCT_INIT(Type, var)
Definition rime_api.h:60
RIME_DEPRECATED
#define RIME_DEPRECATED
Definition rime_api.h:38
RimeStringSlice
struct rime_string_slice_t RimeStringSlice
RimeSchemaList
struct rime_schema_list_t RimeSchemaList
RimeCandidate
struct rime_candidate_t RimeCandidate
RimeConfigIterator
struct rime_config_iterator_t RimeConfigIterator
RimeConfig
struct rime_config_t RimeConfig
RIME_STRUCT_HAS_MEMBER
#define RIME_STRUCT_HAS_MEMBER(var, member)
Definition rime_api.h:62
Bool
#define Bool
Definition rime_api.h:46
RimeNotificationHandler
void(*) RimeNotificationHandler(void *context_object, RimeSessionId session_id, const char *message_type, const char *message_value)
Definition rime_api.h:231
RIME_API
#define RIME_API
Definition rime_api.h:34
RIME_FLAVORED
#define RIME_FLAVORED(name)
Definition rime_api.h:42
RIME_STRUCT_CLEAR
#define RIME_STRUCT_CLEAR(var)
Definition rime_api.h:65
RimeCommit
struct rime_commit_t RimeCommit
Should be initialized by calling RIME_STRUCT_INIT(Type, var);.
True
#define True
Definition rime_api.h:54
RimeTraits
struct rime_traits_t RimeTraits
Rime traits structure.
RimeGetSyncDirSecure
void RimeGetSyncDirSecure(char *dir, size_t buffer_size)
Definition rime_api.cc:70
RimeGetSharedDataDirSecure
void RimeGetSharedDataDirSecure(char *dir, size_t buffer_size)
Definition rime_api.cc:49
rime_declare_module_dependencies
void rime_declare_module_dependencies()
Definition rime_api.cc:30
RimeGetUserDataDirSecure
void RimeGetUserDataDirSecure(char *dir, size_t buffer_size)
Definition rime_api.cc:54
RimeGetVersion
const char * RimeGetVersion()
Definition rime_api.cc:75
RimeGetStagingDirSecure
void RimeGetStagingDirSecure(char *dir, size_t buffer_size)
Definition rime_api.cc:65
RimeFindModule
RIME_API RimeModule * RimeFindModule(const char *module_name)
Definition rime_api.cc:45
RimeGetPrebuiltDataDirSecure
void RimeGetPrebuiltDataDirSecure(char *dir, size_t buffer_size)
Definition rime_api.cc:59
RimeRegisterModule
RIME_API Bool RimeRegisterModule(RimeModule *module)
Definition rime_api.cc:38
RimeGetPrebuiltDataDir
RIME_DEPRECATED const char * RimeGetPrebuiltDataDir()
Definition rime_api_impl.h:806
RimeGetStagingDir
RIME_DEPRECATED const char * RimeGetStagingDir()
Definition rime_api_impl.h:813
RimeGetUserDataSyncDir
RIME_DEPRECATED void RimeGetUserDataSyncDir(char *dir, size_t buffer_size)
Definition rime_api_impl.h:832
schema.h
menu.h
deployer.h
signature.h
common.h
context.h
setup.h
module.h
switches.h
DLOG
#define DLOG(severity)
Definition no_logging.h:53
LOG
#define LOG(severity)
Definition no_logging.h:31
config.h
composition.h
service.h
key_event.h
registry.h
RimeConfigGetDouble
RIME_DEPRECATED Bool RimeConfigGetDouble(RimeConfig *config, const char *key, double *value)
Definition rime_api_impl.h:613
RimeDestroySession
RIME_DEPRECATED Bool RimeDestroySession(RimeSessionId session_id)
Definition rime_api_impl.h:157
RimeFreeContext
RIME_DEPRECATED Bool RimeFreeContext(RIME_FLAVORED(RimeContext) *context)
Definition rime_api_impl.h:285
RimeCommitComposition
RIME_DEPRECATED Bool RimeCommitComposition(RimeSessionId session_id)
return True if there is unread commit text
Definition rime_api_impl.h:180
RimeSelectCandidateOnCurrentPage
RIME_DEPRECATED Bool RimeSelectCandidateOnCurrentPage(RimeSessionId session_id, size_t index)
Definition rime_api_impl.h:1045
RimeGetSyncDir
RIME_DEPRECATED const char * RimeGetSyncDir(void)
Definition rime_api_impl.h:820
RimeSelectSchema
RIME_DEPRECATED Bool RimeSelectSchema(RimeSessionId session_id, const char *schema_id)
Definition rime_api_impl.h:540
RimeSelectCandidate
RIME_DEPRECATED Bool RimeSelectCandidate(RimeSessionId session_id, size_t index)
Definition rime_api_impl.h:1040
RimeCandidateListBegin
RIME_DEPRECATED Bool RimeCandidateListBegin(RimeSessionId session_id, RimeCandidateListIterator *iterator)
Definition rime_api_impl.h:391
RimeGetStatus
RIME_DEPRECATED Bool RimeGetStatus(RimeSessionId session_id, RIME_FLAVORED(RimeStatus) *status)
Definition rime_api_impl.h:335
RimeDeployConfigFile
RIME_DEPRECATED Bool RimeDeployConfigFile(const char *file_name, const char *version_key)
Definition rime_api_impl.h:131
RimeCandidateListNext
RIME_DEPRECATED Bool RimeCandidateListNext(RimeCandidateListIterator *iterator)
Definition rime_api_impl.h:397
RimeSyncUserData
RIME_DEPRECATED Bool RimeSyncUserData(void)
Definition rime_api_impl.h:138
RimeDeployerInitialize
RIME_DEPRECATED void RimeDeployerInitialize(RimeTraits *traits)
Definition rime_api_impl.h:107
RimeSetup
RIME_DEPRECATED void RimeSetup(RimeTraits *traits)
Call this function before accessing any other API.
Definition rime_api_impl.h:25
RimeFreeStatus
RIME_DEPRECATED Bool RimeFreeStatus(RIME_FLAVORED(RimeStatus) *status)
Definition rime_api_impl.h:361
RimeConfigGetItem
RIME_DEPRECATED Bool RimeConfigGetItem(RimeConfig *config, const char *key, RimeConfig *value)
Definition rime_api_impl.h:858
RimeGetUserId
RIME_DEPRECATED const char * RimeGetUserId(void)
Definition rime_api_impl.h:827
RimeConfigCreateMap
RIME_DEPRECATED Bool RimeConfigCreateMap(RimeConfig *config, const char *key)
Definition rime_api_impl.h:953
RimeFreeCommit
RIME_DEPRECATED Bool RimeFreeCommit(RimeCommit *commit)
Definition rime_api_impl.h:327
RimeDeploySchema
RIME_DEPRECATED Bool RimeDeploySchema(const char *schema_file)
Definition rime_api_impl.h:126
RimePrebuildAllSchemas
RIME_DEPRECATED Bool RimePrebuildAllSchemas(void)
Definition rime_api_impl.h:113
RimeDeleteCandidate
RIME_DEPRECATED Bool RimeDeleteCandidate(RimeSessionId session_id, size_t index)
Definition rime_api_impl.h:1051
RimeCleanupAllSessions
RIME_DEPRECATED void RimeCleanupAllSessions(void)
Definition rime_api_impl.h:165
RimeStartMaintenanceOnWorkspaceChange
RIME_DEPRECATED Bool RimeStartMaintenanceOnWorkspaceChange(void)
Definition rime_api_impl.h:91
RimeConfigSetBool
RIME_DEPRECATED Bool RimeConfigSetBool(RimeConfig *config, const char *key, Bool value)
Definition rime_api_impl.h:891
RimeConfigListSize
RIME_DEPRECATED size_t RimeConfigListSize(RimeConfig *config, const char *key)
Definition rime_api_impl.h:962
RimeCandidateListFromIndex
RIME_DEPRECATED Bool RimeCandidateListFromIndex(RimeSessionId session_id, RimeCandidateListIterator *iterator, int index)
Definition rime_api_impl.h:373
RimeConfigBeginList
RIME_DEPRECATED Bool RimeConfigBeginList(RimeConfigIterator *iterator, RimeConfig *config, const char *key)
Definition rime_api_impl.h:679
RimeConfigInit
RIME_DEPRECATED Bool RimeConfigInit(RimeConfig *config)
Definition rime_api_impl.h:838
RimeSetInput
RIME_DEPRECATED Bool RimeSetInput(RimeSessionId session_id, const char *input)
Definition rime_api_impl.h:1072
RimeFinalize
RIME_DEPRECATED void RimeFinalize(void)
Definition rime_api_impl.h:58
RimeSimulateKeySequence
RIME_DEPRECATED Bool RimeSimulateKeySequence(RimeSessionId session_id, const char *key_sequence)
Definition rime_api_impl.h:768
RimeIsMaintenancing
RIME_DEPRECATED Bool RimeIsMaintenancing(void)
Definition rime_api_impl.h:95
RimeProcessKey
RIME_DEPRECATED Bool RimeProcessKey(RimeSessionId session_id, int keycode, int mask)
Definition rime_api_impl.h:171
RimeGetProperty
RIME_DEPRECATED Bool RimeGetProperty(RimeSessionId session_id, const char *prop, char *value, size_t buffer_size)
Definition rime_api_impl.h:458
RimeGetCommit
RIME_DEPRECATED Bool RimeGetCommit(RimeSessionId session_id, RimeCommit *commit)
Definition rime_api_impl.h:309
RimeConfigUpdateSignature
RIME_DEPRECATED Bool RimeConfigUpdateSignature(RimeConfig *config, const char *signer)
Definition rime_api_impl.h:652
RimeDeleteCandidateOnCurrentPage
RIME_DEPRECATED Bool RimeDeleteCandidateOnCurrentPage(RimeSessionId session_id, size_t index)
Definition rime_api_impl.h:1056
RimeSetOption
RIME_DEPRECATED void RimeSetOption(RimeSessionId session_id, const char *option, Bool value)
Definition rime_api_impl.h:423
RimeConfigLoadString
RIME_DEPRECATED Bool RimeConfigLoadString(RimeConfig *config, const char *yaml)
Definition rime_api_impl.h:845
RimeGetContext
RIME_DEPRECATED Bool RimeGetContext(RimeSessionId session_id, RIME_FLAVORED(RimeContext) *context)
Definition rime_api_impl.h:209
RimeGetSchemaList
RIME_DEPRECATED Bool RimeGetSchemaList(RimeSchemaList *schema_list)
Definition rime_api_impl.h:475
RimeConfigBeginMap
RIME_DEPRECATED Bool RimeConfigBeginMap(RimeConfigIterator *iterator, RimeConfig *config, const char *key)
Definition rime_api_impl.h:699
RimeFreeSchemaList
RIME_DEPRECATED void RimeFreeSchemaList(RimeSchemaList *schema_list)
Definition rime_api_impl.h:513
RimeConfigEnd
RIME_DEPRECATED void RimeConfigEnd(RimeConfigIterator *iterator)
Definition rime_api_impl.h:757
RimeDeployWorkspace
RIME_DEPRECATED Bool RimeDeployWorkspace(void)
Definition rime_api_impl.h:118
RimeConfigGetString
RIME_DEPRECATED Bool RimeConfigGetString(RimeConfig *config, const char *key, char *value, size_t buffer_size)
Definition rime_api_impl.h:622
RimeSchemaOpen
RIME_DEPRECATED Bool RimeSchemaOpen(const char *schema_id, RimeConfig *config)
Definition rime_api_impl.h:568
RimeConfigGetBool
RIME_DEPRECATED Bool RimeConfigGetBool(RimeConfig *config, const char *key, Bool *value)
Definition rime_api_impl.h:590
RimeClearComposition
RIME_DEPRECATED void RimeClearComposition(RimeSessionId session_id)
Definition rime_api_impl.h:187
RimeConfigClear
RIME_DEPRECATED Bool RimeConfigClear(RimeConfig *config, const char *key)
Definition rime_api_impl.h:935
RimeInitialize
RIME_DEPRECATED void RimeInitialize(RimeTraits *traits)
Definition rime_api_impl.h:51
RimeCandidateListEnd
RIME_DEPRECATED void RimeCandidateListEnd(RimeCandidateListIterator *iterator)
Definition rime_api_impl.h:413
RimeGetUserDataDir
RIME_DEPRECATED const char * RimeGetUserDataDir(void)
Definition rime_api_impl.h:799
RimeJoinMaintenanceThread
RIME_DEPRECATED void RimeJoinMaintenanceThread(void)
Definition rime_api_impl.h:100
RimeConfigSetInt
RIME_DEPRECATED Bool RimeConfigSetInt(RimeConfig *config, const char *key, int value)
Definition rime_api_impl.h:902
RimeConfigOpen
RIME_DEPRECATED Bool RimeConfigOpen(const char *config_id, RimeConfig *config)
Definition rime_api_impl.h:572
RimeConfigGetInt
RIME_DEPRECATED Bool RimeConfigGetInt(RimeConfig *config, const char *key, int *value)
Definition rime_api_impl.h:604
RimeConfigSetString
RIME_DEPRECATED Bool RimeConfigSetString(RimeConfig *config, const char *key, const char *value)
Definition rime_api_impl.h:924
RimeConfigGetCString
RIME_DEPRECATED const char * RimeConfigGetCString(RimeConfig *config, const char *key)
Definition rime_api_impl.h:639
RimeCreateSession
RIME_DEPRECATED RimeSessionId RimeCreateSession(void)
Definition rime_api_impl.h:149
RimeConfigNext
RIME_DEPRECATED Bool RimeConfigNext(RimeConfigIterator *iterator)
Definition rime_api_impl.h:719
RimeStartMaintenance
RIME_DEPRECATED Bool RimeStartMaintenance(Bool full_check)
Definition rime_api_impl.h:65
RimeConfigCreateList
RIME_DEPRECATED Bool RimeConfigCreateList(RimeConfig *config, const char *key)
Definition rime_api_impl.h:944
RimeCleanupStaleSessions
RIME_DEPRECATED void RimeCleanupStaleSessions(void)
Definition rime_api_impl.h:161
RimeConfigSetDouble
RIME_DEPRECATED Bool RimeConfigSetDouble(RimeConfig *config, const char *key, double value)
Definition rime_api_impl.h:913
RimeFindSession
RIME_DEPRECATED Bool RimeFindSession(RimeSessionId session_id)
Definition rime_api_impl.h:153
RimeGetOption
RIME_DEPRECATED Bool RimeGetOption(RimeSessionId session_id, const char *option)
Definition rime_api_impl.h:435
RimeRunTask
RIME_DEPRECATED Bool RimeRunTask(const char *task_name)
Run a registered task.
Definition rime_api_impl.h:785
RimeUserConfigOpen
RIME_DEPRECATED Bool RimeUserConfigOpen(const char *config_id, RimeConfig *config)
Definition rime_api_impl.h:576
RimeConfigSetItem
RIME_DEPRECATED Bool RimeConfigSetItem(RimeConfig *config, const char *key, RimeConfig *value)
Definition rime_api_impl.h:874
RimeGetSharedDataDir
RIME_DEPRECATED const char * RimeGetSharedDataDir(void)
Definition rime_api_impl.h:792
RimeSetProperty
RIME_DEPRECATED void RimeSetProperty(RimeSessionId session_id, const char *prop, const char *value)
Definition rime_api_impl.h:446
RimeGetCurrentSchema
RIME_DEPRECATED Bool RimeGetCurrentSchema(RimeSessionId session_id, char *schema_id, size_t buffer_size)
Definition rime_api_impl.h:527
RimeSetNotificationHandler
RIME_DEPRECATED void RimeSetNotificationHandler(RimeNotificationHandler handler, void *context_object)
Receive notifications.
Definition rime_api_impl.h:39
RimeConfigClose
RIME_DEPRECATED Bool RimeConfigClose(RimeConfig *config)
Definition rime_api_impl.h:581
rime
Definition algebra.cc:12
rime::LoadModules
RIME_DLL void LoadModules(const char *module_names[])
Definition setup.cc:33
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::kDefaultModules
RIME_DLL const char * kDefaultModules[]
rime::kDeployerModules
RIME_DLL const char * kDeployerModules[]
rime::SetupLogging
RIME_DLL void SetupLogging(const char *app_name, int min_log_level, const char *log_dir)
Definition setup.cc:68
rime::SetupDeployer
RIME_DLL void SetupDeployer(RimeTraits *traits)
Definition setup.cc:42
rime::As
an< X > As(const an< Y > &ptr)
Definition common.h:67
rime::the
std::unique_ptr< T > the
Definition common.h:58
rime::TaskInitializer
std::any TaskInitializer
Definition deployer.h:22
rime::New
an< T > New(Args &&... args)
Definition common.h:77
rime::path
Definition common.h:84
rime::Class< Config, const string & >::Require
static Component * Require(const string &name)
Definition component.h:29
rime::Preedit
Definition composition.h:14
rime::Preedit::caret_pos
size_t caret_pos
Definition composition.h:16
rime::Preedit::sel_start
size_t sel_start
Definition composition.h:17
rime::Preedit::text
string text
Definition composition.h:15
rime::Preedit::sel_end
size_t sel_end
Definition composition.h:18
rime::Config
Definition config_component.h:21
rime::Config::GetString
RIME_DLL bool GetString(const string &path, string *value)
Definition config_component.cc:84
rime::Config::GetBool
RIME_DLL bool GetBool(const string &path, bool *value)
Definition config_component.cc:66
rime::Config::GetList
RIME_DLL an< ConfigList > GetList(const string &path)
Definition config_component.cc:106
rime::Config::SetItem
RIME_DLL bool SetItem(const string &path, an< ConfigItem > item)
Definition config_component.cc:136
rime::Config::SetString
RIME_DLL bool SetString(const string &path, const char *value)
Definition config_component.cc:128
rime::Config::SetBool
bool SetBool(const string &path, bool value)
Definition config_component.cc:116
rime::Config::SetInt
RIME_DLL bool SetInt(const string &path, int value)
Definition config_component.cc:120
rime::Config::GetMap
RIME_DLL an< ConfigMap > GetMap(const string &path)
Definition config_component.cc:111
rime::Config::LoadFromStream
bool LoadFromStream(std::istream &stream)
Definition config_component.cc:30
rime::Config::GetItem
an< ConfigItem > GetItem(const string &path)
Definition config_component.cc:96
rime::Config::GetDouble
RIME_DLL bool GetDouble(const string &path, double *value)
Definition config_component.cc:78
rime::Config::SetDouble
bool SetDouble(const string &path, double value)
Definition config_component.cc:124
rime::Config::GetValue
an< ConfigValue > GetValue(const string &path)
Definition config_component.cc:101
rime::Config::GetInt
RIME_DLL bool GetInt(const string &path, int *value)
Definition config_component.cc:72
rime::Context
Definition context.h:19
rime::Context::caret_pos
size_t caret_pos() const
Definition context.h:67
rime::Context::DeleteCandidate
bool DeleteCandidate(size_t index)
Definition context.cc:151
rime::Context::input
const string & input() const
Definition context.h:64
rime::Context::set_caret_pos
void set_caret_pos(size_t caret_pos)
Definition context.cc:268
rime::Context::GetCommitText
string GetCommitText() const
Definition context.cc:28
rime::Context::set_option
void set_option(const string &name, bool value)
Definition context.cc:286
rime::Context::HasMenu
bool HasMenu() const
Definition context.cc:52
rime::Context::get_property
string get_property(const string &name) const
Definition context.cc:305
rime::Context::Highlight
bool Highlight(size_t index)
Definition context.cc:132
rime::Context::composition
Composition & composition()
Definition context.h:70
rime::Context::GetPreedit
Preedit GetPreedit() const
Definition context.cc:44
rime::Context::set_input
void set_input(const string &value)
Definition context.cc:280
rime::Context::Select
bool Select(size_t index)
Definition context.cc:118
rime::Context::set_property
void set_property(const string &name, const string &value)
Definition context.cc:300
rime::Context::get_option
bool get_option(const string &name) const
Definition context.cc:292
rime::Context::IsComposing
bool IsComposing() const
Definition context.cc:48
rime::Deployer
Definition deployer.h:32
rime::Deployer::shared_data_dir
path shared_data_dir
Definition deployer.h:35
rime::Deployer::user_data_dir
path user_data_dir
Definition deployer.h:36
rime::Deployer::user_id
string user_id
Definition deployer.h:40
rime::Deployer::prebuilt_data_dir
path prebuilt_data_dir
Definition deployer.h:37
rime::Deployer::ScheduleTask
bool ScheduleTask(const string &task_name, TaskInitializer arg=TaskInitializer())
Definition deployer.cc:42
rime::Deployer::StartMaintenance
bool StartMaintenance()
Definition deployer.cc:126
rime::Deployer::user_data_sync_dir
path user_data_sync_dir() const
Definition deployer.cc:150
rime::Deployer::RunTask
bool RunTask(const string &task_name, TaskInitializer arg=TaskInitializer())
Definition deployer.cc:28
rime::Deployer::IsMaintenanceMode
bool IsMaintenanceMode()
Definition deployer.cc:137
rime::Deployer::JoinMaintenanceThread
void JoinMaintenanceThread()
Definition deployer.cc:146
rime::Deployer::staging_dir
path staging_dir
Definition deployer.h:38
rime::Deployer::sync_dir
path sync_dir
Definition deployer.h:39
rime::KeyEvent
Definition key_event.h:17
rime::KeySequence
Definition key_event.h:59
rime::KeySequence::Parse
RIME_DLL bool Parse(const string &repr)
Definition key_event.cc:111
rime::Menu
Definition menu.h:27
rime::Menu::GetCandidateAt
an< Candidate > GetCandidateAt(size_t index)
Definition menu.cc:60
rime::ModuleManager::UnloadModules
void UnloadModules()
Definition module.cc:39
rime::ModuleManager::instance
static ModuleManager & instance()
Definition module.cc:48
rime::Registry::instance
static RIME_DLL Registry & instance()
Definition registry.cc:47
rime::Registry::Clear
void Clear()
Definition registry.cc:31
rime::Schema
Definition schema.h:15
rime::Schema::Schema
Schema()
Definition schema.cc:12
rime::Schema::select_keys
const string & select_keys() const
Definition schema.h:30
rime::Schema::config
Config * config() const
Definition schema.h:25
rime::Schema::schema_id
const string & schema_id() const
Definition schema.h:22
rime::Schema::schema_name
const string & schema_name() const
Definition schema.h:23
rime::Schema::page_size
int page_size() const
Definition schema.h:28
rime::Segment
Definition segmentation.h:18
rime::Segment::menu
an< Menu > menu
Definition segmentation.h:30
rime::Segment::selected_index
size_t selected_index
Definition segmentation.h:31
rime::Service::instance
static Service & instance()
Definition service.cc:196
rime::Service::CreateSession
SessionId CreateSession()
Definition service.cc:85
rime::Service::StopService
void StopService()
Definition service.cc:80
rime::Service::SetNotificationHandler
void SetNotificationHandler(const NotificationHandler &handler)
Definition service.cc:149
rime::Service::StartService
void StartService()
Definition service.cc:76
rime::Service::deployer
Deployer & deployer()
Definition service.h:84
rime::Service::ClearNotificationHandler
void ClearNotificationHandler()
Definition service.cc:153
rime::Service::CleanupAllSessions
void CleanupAllSessions()
Definition service.cc:145
rime::Service::CleanupStaleSessions
void CleanupStaleSessions()
Definition service.cc:128
rime::Signature
Definition signature.h:15
rime::Signature::Sign
bool Sign(Config *config, Deployer *deployer)
Definition signature.cc:15
rime::StringSlice
Definition switches.h:13
rime::StringSlice::length
size_t length
Definition switches.h:15
rime::StringSlice::str
const char * str
Definition switches.h:14
rime::Switches
Definition switches.h:24
rime_traits_t::log_dir
const char * log_dir
Directory of log files.
Definition rime_api.h:112
rime_traits_t::min_log_level
int min_log_level
Minimal level of logged messages.
Definition rime_api.h:107
rime_traits_t::modules
const char ** modules
A list of modules to load before initializing.
Definition rime_api.h:101
rime_traits_t::app_name
const char * app_name
Pass a C-string constant in the format "rime.x" where 'x' is the name of your application.
Definition rime_api.h:98
rime_candidate_t::reserved
void * reserved
Definition rime_api.h:130
rime_candidate_t::comment
char * comment
Definition rime_api.h:129
rime_candidate_t::text
char * text
Definition rime_api.h:128
rime_commit_t::text
char * text
Definition rime_api.h:149
rime_candidate_list_iterator_t::index
int index
Definition rime_api.h:184
rime_candidate_list_iterator_t::candidate
RimeCandidate candidate
Definition rime_api.h:185
rime_candidate_list_iterator_t::ptr
void * ptr
Definition rime_api.h:183
rime_config_t::ptr
void * ptr
Definition rime_api.h:189
rime_config_iterator_t::index
int index
Definition rime_api.h:195
rime_config_iterator_t::list
void * list
Definition rime_api.h:193
rime_config_iterator_t::path
const char * path
Definition rime_api.h:197
rime_config_iterator_t::key
const char * key
Definition rime_api.h:196
rime_config_iterator_t::map
void * map
Definition rime_api.h:194
rime_schema_list_item_t::schema_id
char * schema_id
Definition rime_api.h:201
rime_schema_list_item_t::reserved
void * reserved
Definition rime_api.h:203
rime_schema_list_item_t::name
char * name
Definition rime_api.h:202
rime_schema_list_t::list
RimeSchemaListItem * list
Definition rime_api.h:208
rime_schema_list_t::size
size_t size
Definition rime_api.h:207
RimeConfigIteratorImpl
Definition rime_api_impl.h:663
RimeConfigIteratorImpl::end
T::Iterator end
Definition rime_api_impl.h:665
RimeConfigIteratorImpl::iter
T::Iterator iter
Definition rime_api_impl.h:664
RimeConfigIteratorImpl::RimeConfigIteratorImpl
RimeConfigIteratorImpl(T &container, const string &root_path)
Definition rime_api_impl.h:669
RimeConfigIteratorImpl::path
string path
Definition rime_api_impl.h:668
RimeConfigIteratorImpl::key
string key
Definition rime_api_impl.h:667
RimeConfigIteratorImpl::prefix
string prefix
Definition rime_api_impl.h:666