1
1
#include <node_api.h>
2
- #if RIME_API_VERSION >= 1120
3
- #include <rime_api_deprecated.h>
4
- #else
5
2
#include <rime_api.h>
6
- #endif
7
3
#include <stdio.h>
8
4
9
5
#define DEFAULT_BUFFER_SIZE 1024
74
70
} \
75
71
} while (0);
76
72
73
+ static RimeApi * rime ;
74
+
77
75
static napi_value init (napi_env env , napi_callback_info info ) {
78
76
napi_value argv [1 ];
79
77
SET_ARGV (env , argv );
@@ -102,14 +100,14 @@ static napi_value init(napi_env env, napi_callback_info info) {
102
100
NODE_API_CALL (
103
101
env , napi_get_value_int32 (env , result , & rime_traits .min_log_level ));
104
102
}
105
- RimeSetup (& rime_traits );
106
- RimeInitialize (& rime_traits );
103
+ rime -> setup (& rime_traits );
104
+ rime -> initialize (& rime_traits );
107
105
return NULL ;
108
106
}
109
107
110
108
static napi_value createSession (napi_env env , napi_callback_info info ) {
111
109
napi_value result ;
112
- RimeSessionId session_id = RimeCreateSession ();
110
+ RimeSessionId session_id = rime -> create_session ();
113
111
if (session_id == 0 ) {
114
112
napi_throw_error (env , NULL , "rime cannot create session" );
115
113
return NULL ;
@@ -123,12 +121,12 @@ static napi_value destroySession(napi_env env, napi_callback_info info) {
123
121
RimeSessionId session_id ;
124
122
SET_ARGV (env , argv );
125
123
SET_SESSION_ID (env , argv [0 ], session_id );
126
- if (!RimeDestroySession (session_id )) {
124
+ if (!rime -> destroy_session (session_id )) {
127
125
char str [DEFAULT_BUFFER_SIZE ];
128
126
sprintf (str , "cannot destroy session %ld" , session_id );
129
127
napi_throw_error (env , NULL , str );
130
128
}
131
- RimeFinalize ();
129
+ rime -> finalize ();
132
130
return NULL ;
133
131
}
134
132
@@ -138,7 +136,7 @@ static napi_value getCurrentSchema(napi_env env, napi_callback_info info) {
138
136
char buffer [DEFAULT_BUFFER_SIZE ];
139
137
SET_ARGV (env , argv );
140
138
SET_SESSION_ID (env , argv [0 ], session_id );
141
- if (!RimeGetCurrentSchema (session_id , buffer , DEFAULT_BUFFER_SIZE )) {
139
+ if (!rime -> get_current_schema (session_id , buffer , DEFAULT_BUFFER_SIZE )) {
142
140
napi_throw_error (env , NULL , "cannot get current schema" );
143
141
return NULL ;
144
142
}
@@ -150,7 +148,7 @@ static napi_value getCurrentSchema(napi_env env, napi_callback_info info) {
150
148
static napi_value getSchemaList (napi_env env , napi_callback_info info ) {
151
149
napi_value result ;
152
150
RimeSchemaList schema_list ;
153
- if (!RimeGetSchemaList (& schema_list )) {
151
+ if (!rime -> get_schema_list (& schema_list )) {
154
152
napi_throw_error (env , NULL , "cannot get schema list" );
155
153
return NULL ;
156
154
}
@@ -169,7 +167,7 @@ static napi_value getSchemaList(napi_env env, napi_callback_info info) {
169
167
NODE_API_CALL (env , napi_set_named_property (env , element , "name" , name ));
170
168
NODE_API_CALL (env , napi_set_element (env , result , i , element ));
171
169
}
172
- RimeFreeSchemaList (& schema_list );
170
+ rime -> free_schema_list (& schema_list );
173
171
return result ;
174
172
}
175
173
@@ -180,7 +178,7 @@ static napi_value selectSchema(napi_env env, napi_callback_info info) {
180
178
SET_ARGV (env , argv );
181
179
SET_SESSION_ID (env , argv [0 ], session_id );
182
180
SET_STRING (env , argv [1 ], schema_id );
183
- if (!RimeSelectSchema (session_id , schema_id )) {
181
+ if (!rime -> select_schema (session_id , schema_id )) {
184
182
char str [DEFAULT_BUFFER_SIZE + sizeof ("cannot select schema " )];
185
183
sprintf (str , "cannot select schema %s" , schema_id );
186
184
napi_throw_error (env , NULL , str );
@@ -196,7 +194,7 @@ static napi_value processKey(napi_env env, napi_callback_info info) {
196
194
SET_SESSION_ID (env , argv [0 ], session_id );
197
195
NODE_API_CALL (env , napi_get_value_int32 (env , argv [1 ], & keycode ));
198
196
NODE_API_CALL (env , napi_get_value_int32 (env , argv [2 ], & mask ));
199
- if (!RimeProcessKey (session_id , keycode , mask )) {
197
+ if (!rime -> process_key (session_id , keycode , mask )) {
200
198
char str [DEFAULT_BUFFER_SIZE ];
201
199
sprintf (str , "cannot process key %d" , keycode );
202
200
napi_throw_error (env , NULL , str );
@@ -210,7 +208,7 @@ static napi_value getContext(napi_env env, napi_callback_info info) {
210
208
SET_ARGV (env , argv );
211
209
SET_SESSION_ID (env , argv [0 ], session_id );
212
210
RIME_STRUCT (RimeContext , context );
213
- if (!RimeGetContext (session_id , & context )) {
211
+ if (!rime -> get_context (session_id , & context )) {
214
212
napi_throw_error (env , NULL , "cannot get context" );
215
213
return NULL ;
216
214
}
@@ -308,7 +306,7 @@ static napi_value getContext(napi_env env, napi_callback_info info) {
308
306
NODE_API_CALL (env , napi_set_element (env , select_keys , i , select_key ));
309
307
}
310
308
}
311
- if (!RimeFreeContext (& context ))
309
+ if (!rime -> free_context (& context ))
312
310
napi_throw_error (env , NULL , "cannot free context" );
313
311
return result ;
314
312
}
@@ -319,13 +317,13 @@ static napi_value getCommit(napi_env env, napi_callback_info info) {
319
317
SET_ARGV (env , argv );
320
318
SET_SESSION_ID (env , argv [0 ], session_id );
321
319
RIME_STRUCT (RimeCommit , commit );
322
- if (!RimeGetCommit (session_id , & commit ))
320
+ if (!rime -> get_commit (session_id , & commit ))
323
321
napi_throw_error (env , NULL , "cannot get commit" );
324
322
NODE_API_CALL (env , napi_create_object (env , & result ));
325
323
NODE_API_CALL (
326
324
env , napi_create_string_utf8 (env , commit .text , NAPI_AUTO_LENGTH , & text ));
327
325
NODE_API_CALL (env , napi_set_named_property (env , result , "text" , text ));
328
- if (!RimeFreeCommit (& commit ))
326
+ if (!rime -> free_commit (& commit ))
329
327
napi_throw_error (env , NULL , "cannot free commit" );
330
328
return result ;
331
329
}
@@ -336,7 +334,7 @@ static napi_value commitComposition(napi_env env, napi_callback_info info) {
336
334
SET_ARGV (env , argv );
337
335
SET_SESSION_ID (env , argv [0 ], session_id );
338
336
NODE_API_CALL (
339
- env , napi_create_int32 (env , RimeCommitComposition (session_id ), & result ));
337
+ env , napi_create_int32 (env , rime -> commit_composition (session_id ), & result ));
340
338
return result ;
341
339
}
342
340
@@ -345,11 +343,12 @@ static napi_value clearComposition(napi_env env, napi_callback_info info) {
345
343
RimeSessionId session_id ;
346
344
SET_ARGV (env , argv );
347
345
SET_SESSION_ID (env , argv [0 ], session_id );
348
- RimeClearComposition (session_id );
346
+ rime -> clear_composition (session_id );
349
347
return NULL ;
350
348
}
351
349
352
350
NAPI_MODULE_INIT (/* napi_env env, napi_value exports */ ) {
351
+ rime = rime_get_api ();
353
352
char * names [] = {"init" ,
354
353
"createSession" ,
355
354
"destroySession" ,
0 commit comments