|
12 | 12 |
|
13 | 13 | using namespace rime; |
14 | 14 |
|
15 | | -RIME_PROTO_OBJ rime_commit_proto(RimeSessionId session_id) { |
| 15 | +void rime_commit_proto(RimeSessionId session_id, |
| 16 | + RIME_PROTO_BUILDER *commit_builder) { |
16 | 17 | an<Session> session(Service::instance().GetSession(session_id)); |
17 | | - if (!session) return nullptr; |
| 18 | + if (!session) return; |
18 | 19 | auto env = GlobalRef->AttachEnv(); |
19 | 20 | const string &commit_text(session->commit_text()); |
20 | | - RIME_PROTO_OBJ commit = |
21 | | - env->NewObject(GlobalRef->CommitProto, GlobalRef->CommitProtoInit, |
22 | | - *JString(env, commit_text)); |
23 | | - session->ResetCommitText(); |
24 | | - return commit; |
| 21 | + if (!commit_text.empty()) { |
| 22 | + auto *commit = (jobject *)commit_builder; |
| 23 | + *commit = env->NewObject(GlobalRef->CommitProto, GlobalRef->CommitProtoInit, |
| 24 | + *JString(env, commit_text)); |
| 25 | + session->ResetCommitText(); |
| 26 | + } |
25 | 27 | } |
26 | 28 |
|
27 | | -RIME_PROTO_OBJ rime_context_proto(RimeSessionId session_id) { |
| 29 | +void rime_context_proto(RimeSessionId session_id, |
| 30 | + RIME_PROTO_BUILDER *context_builder) { |
28 | 31 | an<Session> session = Service::instance().GetSession(session_id); |
29 | | - if (!session) return nullptr; |
| 32 | + if (!session) return; |
30 | 33 | Context *ctx = session->context(); |
31 | | - if (!ctx) return nullptr; |
| 34 | + if (!ctx) return; |
32 | 35 | auto env = GlobalRef->AttachEnv(); |
| 36 | + auto *context = (jobject *)context_builder; |
33 | 37 | jobject composition = env->NewObject(GlobalRef->CompositionProto, |
34 | 38 | GlobalRef->CompositionProtoDefault); |
35 | 39 | if (ctx->IsComposing()) { |
@@ -94,19 +98,22 @@ RIME_PROTO_OBJ rime_context_proto(RimeSessionId session_id) { |
94 | 98 | *JRef<jobjectArray>(env, dest_labels)); |
95 | 99 | } |
96 | 100 | } |
97 | | - return env->NewObject(GlobalRef->ContextProto, GlobalRef->ContextProtoInit, |
98 | | - *JRef(env, composition), *JRef(env, menu), |
99 | | - *JString(env, ctx->input()), ctx->caret_pos()); |
| 101 | + *context = |
| 102 | + env->NewObject(GlobalRef->ContextProto, GlobalRef->ContextProtoInit, |
| 103 | + *JRef(env, composition), *JRef(env, menu), |
| 104 | + *JString(env, ctx->input()), ctx->caret_pos()); |
100 | 105 | } |
101 | 106 |
|
102 | | -RIME_PROTO_OBJ rime_status_proto(RimeSessionId session_id) { |
| 107 | +void rime_status_proto(RimeSessionId session_id, |
| 108 | + RIME_PROTO_BUILDER *status_builder) { |
103 | 109 | an<Session> session(Service::instance().GetSession(session_id)); |
104 | | - if (!session) return nullptr; |
| 110 | + if (!session) return; |
105 | 111 | Schema *schema = session->schema(); |
106 | 112 | Context *ctx = session->context(); |
107 | | - if (!schema || !ctx) return nullptr; |
| 113 | + if (!schema || !ctx) return; |
108 | 114 | auto env = GlobalRef->AttachEnv(); |
109 | | - return env->NewObject( |
| 115 | + auto *status = (jobject *)status_builder; |
| 116 | + *status = env->NewObject( |
110 | 117 | GlobalRef->StatusProto, GlobalRef->StatusProtoInit, |
111 | 118 | *JString(env, schema->schema_id()), *JString(env, schema->schema_name()), |
112 | 119 | Service::instance().disabled(), ctx->IsComposing(), |
|
0 commit comments