swigutil_java.c
来自「linux subdivision ying gai ke yi le ba」· C语言 代码 · 共 1,257 行 · 第 1/3 页
C
1,257 行
static svn_error_t * close_baton_checksum(void *baton,
const char *text_checksum,
const char *method)
{
item_baton *ib = baton;
jobject result;
JNIEnv *jenv = ib->jenv;
jclass cls = JCALL1(GetObjectClass, jenv, ib->editor);
jmethodID methodID;
methodID = JCALL3(GetMethodID, jenv, cls, method,
"(Ljava/lang/Object;)Ljava/lang/Object;");
result = JCALL4(CallObjectMethod, jenv, ib->editor, methodID, ib->baton,
text_checksum);
if (result == NULL)
return convert_exception(ib->jenv, ib->pool);
/* there is no return value, so just toss this object */
JCALL1(DeleteGlobalRef, ib->jenv, result);
/* We're now done with the baton. Since there isn't really a free, all
we need to do is note that its objects are no longer referenced by
the baton. */
JCALL1(DeleteGlobalRef, ib->jenv, ib->editor);
JCALL1(DeleteGlobalRef, ib->jenv, ib->baton);
#ifdef SVN_DEBUG
ib->editor = ib->baton = NULL;
#endif
return SVN_NO_ERROR;
}
static svn_error_t * thunk_set_target_revision(void *edit_baton,
svn_revnum_t target_revision,
apr_pool_t *pool)
{
item_baton *ib = edit_baton;
jobject result;
jclass cls; /*= JCALL(FindClass, ib->jenv, "FIXME");*/
/* FIXME: Signature wants svn_revnum type instead of java.lang.Object */
jmethodID methodID = JCALL3(GetMethodID, ib->jenv, cls,
"set_target_revision", "(Ljava/lang/Object;)");
/* FIXME: Translate to JNI
if ((result = PyObject_CallMethod(ib->editor, (char *)"set_target_revision",
(char *)"l", target_revision)) == NULL)
{
return convert_exception(ib->jenv, pool);
}
*/
/* there is no return value, so just toss this object */
JCALL1(DeleteGlobalRef, ib->jenv, result);
return SVN_NO_ERROR;
}
static svn_error_t * thunk_open_root(void *edit_baton,
svn_revnum_t base_revision,
apr_pool_t *dir_pool,
void **root_baton)
{
item_baton *ib = edit_baton;
jobject result;
/* FIXME: Translate to JNI
if ((result = PyObject_CallMethod(ib->editor, (char *)"open_root",
(char *)"lO&", base_revision,
make_ob_pool, dir_pool)) == NULL)
{
return convert_exception(ib->jenv, dir_pool);
}
*/
/* make_baton takes our 'result' reference */
*root_baton = make_baton(ib->jenv, dir_pool, ib->editor, result);
return SVN_NO_ERROR;
}
static svn_error_t * thunk_delete_entry(const char *path,
svn_revnum_t revision,
void *parent_baton,
apr_pool_t *pool)
{
item_baton *ib = parent_baton;
jobject result;
/* FIXME: Translate to JNI
if ((result = PyObject_CallMethod(ib->editor, (char *)"delete_entry",
(char *)"slOO&", path, revision, ib->baton,
make_ob_pool, pool)) == NULL)
{
return convert_exception(ib->jenv, pool);
}
*/
/* there is no return value, so just toss this object */
JCALL1(DeleteGlobalRef, ib->jenv, result);
return SVN_NO_ERROR;
}
static svn_error_t * thunk_add_directory(const char *path,
void *parent_baton,
const char *copyfrom_path,
svn_revnum_t copyfrom_revision,
apr_pool_t *dir_pool,
void **child_baton)
{
item_baton *ib = parent_baton;
jobject result;
/* FIXME: Translate to JNI
if ((result = PyObject_CallMethod(ib->editor, (char *)"add_directory",
(char *)"sOslO&", path, ib->baton,
copyfrom_path, copyfrom_revision,
make_ob_pool, dir_pool)) == NULL)
{
return convert_exception(ib->jenv, dir_pool);
}
*/
/* make_baton takes our 'result' reference */
*child_baton = make_baton(ib->jenv, dir_pool, ib->editor, result);
return SVN_NO_ERROR;
}
static svn_error_t * thunk_open_directory(const char *path,
void *parent_baton,
svn_revnum_t base_revision,
apr_pool_t *dir_pool,
void **child_baton)
{
item_baton *ib = parent_baton;
jobject result;
/* FIXME: Translate to JNI
if ((result = PyObject_CallMethod(ib->editor, (char *)"open_directory",
(char *)"sOlO&", path, ib->baton,
base_revision,
make_ob_pool, dir_pool)) == NULL)
{
return convert_exception(ib->jenv, dir_pool);
}
*/
/* make_baton takes our 'result' reference */
*child_baton = make_baton(ib->jenv, dir_pool, ib->editor, result);
return SVN_NO_ERROR;
}
static svn_error_t * thunk_change_dir_prop(void *dir_baton,
const char *name,
const svn_string_t *value,
apr_pool_t *pool)
{
item_baton *ib = dir_baton;
jobject result;
/* FIXME: Translate to JNI
if ((result = PyObject_CallMethod(ib->editor, (char *)"change_dir_prop",
(char *)"Oss#O&", ib->baton, name,
value->data, value->len,
make_ob_pool, pool)) == NULL)
{
return convert_exception(ib->jenv, pool);
}
*/
/* there is no return value, so just toss this object */
JCALL1(DeleteGlobalRef, ib->jenv, result);
return SVN_NO_ERROR;
}
static svn_error_t * thunk_close_directory(void *dir_baton, apr_pool_t *pool)
{
return close_baton(dir_baton, "close_directory");
}
static svn_error_t * thunk_add_file(const char *path,
void *parent_baton,
const char *copyfrom_path,
svn_revnum_t copyfrom_revision,
apr_pool_t *file_pool,
void **file_baton)
{
item_baton *ib = parent_baton;
jobject result;
/* FIXME: Translate to JNI
if ((result = PyObject_CallMethod(ib->editor, (char *)"add_file",
(char *)"sOslO&", path, ib->baton,
copyfrom_path, copyfrom_revision,
make_ob_pool, file_pool)) == NULL)
{
return convert_exception(ib->jenv, file_pool);
}
*/
/* make_baton takes our 'result' reference */
*file_baton = make_baton(ib->jenv, file_pool, ib->editor, result);
return SVN_NO_ERROR;
}
static svn_error_t * thunk_open_file(const char *path,
void *parent_baton,
svn_revnum_t base_revision,
apr_pool_t *file_pool,
void **file_baton)
{
item_baton *ib = parent_baton;
jobject result;
/* FIXME: Translate to JNI
if ((result = PyObject_CallMethod(ib->editor, (char *)"open_file",
(char *)"sOlO&", path, ib->baton,
base_revision,
make_ob_pool, file_pool)) == NULL)
{
return convert_exception(ib->jenv, file_pool);
}
*/
/* make_baton takes our 'result' reference */
*file_baton = make_baton(ib->jenv, file_pool, ib->editor, result);
return SVN_NO_ERROR;
}
static svn_error_t * thunk_window_handler(svn_txdelta_window_t *window,
void *baton)
{
handler_baton *hb = baton;
jobject result;
if (window == NULL)
{
/* the last call; it closes the handler */
/* invoke the handler with None for the window */
/* ### python doesn't have 'const' on the format */
/* FIXME: To JNI
result = PyObject_CallFunction(hb->handler, (char *)"O", Py_None);
*/
/* we no longer need to refer to the handler object */
JCALL1(DeleteGlobalRef, hb->jenv, hb->handler);
}
else
{
/* invoke the handler with the window */
/* FIXME: Translate to JNI
result = PyObject_CallFunction(hb->handler,
(char *)"O&", make_ob_window, window);
*/
}
if (result == NULL)
return convert_exception(hb->jenv, hb->pool);
/* there is no return value, so just toss this object */
JCALL1(DeleteGlobalRef, hb->jenv, result);
return SVN_NO_ERROR;
}
static svn_error_t * thunk_apply_textdelta(
void *file_baton,
const char *base_checksum,
apr_pool_t *pool,
svn_txdelta_window_handler_t *handler,
void **h_baton)
{
item_baton *ib = file_baton;
jobject result;
/* FIXME: Translate to JNI
if ((result = PyObject_CallMethod(ib->editor, (char *)"apply_textdelta",
(char *)"O", ib->baton)) == NULL)
{
return convert_exception(ib->jenv, pool);
}
*/
/* FIXME: To JNI
if (result == Py_None)
{
JCALL1(DeleteGlobalRef, ib->jenv, result);
*handler = NULL;
*h_baton = NULL;
}
else
*/
{
handler_baton *hb = apr_palloc(ib->pool, sizeof(*hb));
/* return the thunk for invoking the handler. the baton takes our
'result' reference. */
hb->handler = result;
hb->pool = ib->pool;
hb->jenv = ib->jenv;
*handler = thunk_window_handler;
*h_baton = hb;
}
return SVN_NO_ERROR;
}
static svn_error_t * thunk_change_file_prop(void *file_baton,
const char *name,
const svn_string_t *value,
apr_pool_t *pool)
{
item_baton *ib = file_baton;
jobject result;
/* FIXME: Translate to JNI
if ((result = PyObject_CallMethod(ib->editor, (char *)"change_file_prop",
(char *)"Oss#O&", ib->baton, name,
value->data, value->len,
make_ob_pool, pool)) == NULL)
{
return convert_exception(ib->jenv, pool);
}
*/
/* there is no return value, so just toss this object */
JCALL1(DeleteGlobalRef, ib->jenv, result);
return SVN_NO_ERROR;
}
static svn_error_t * thunk_close_file(void *file_baton,
const char *text_checksum,
apr_pool_t *pool)
{
return close_baton_checksum(file_baton, text_checksum, "close_file");
}
static svn_error_t * thunk_close_edit(void *edit_baton, apr_pool_t *pool)
{
return close_baton(edit_baton, "close_edit");
}
static svn_error_t * thunk_abort_edit(void *edit_baton, apr_pool_t *pool)
{
return close_baton(edit_baton, "abort_edit");
}
void svn_swig_java_make_editor(JNIEnv *jenv,
const svn_delta_editor_t **editor,
void **edit_baton,
jobject java_editor,
apr_pool_t *pool)
{
svn_delta_editor_t *thunk_editor = svn_delta_default_editor (pool);
thunk_editor->set_target_revision = thunk_set_target_revision;
thunk_editor->open_root = thunk_open_root;
thunk_editor->delete_entry = thunk_delete_entry;
thunk_editor->add_directory = thunk_add_directory;
thunk_editor->open_directory = thunk_open_directory;
thunk_editor->change_dir_prop = thunk_change_dir_prop;
thunk_editor->close_directory = thunk_close_directory;
thunk_editor->add_file = thunk_add_file;
thunk_editor->open_file = thunk_open_file;
thunk_editor->apply_textdelta = thunk_apply_textdelta;
thunk_editor->change_file_prop = thunk_change_file_prop;
thunk_editor->close_file = thunk_close_file;
thunk_editor->close_edit = thunk_close_edit;
thunk_editor->abort_edit = thunk_abort_edit;
*editor = thunk_editor;
*edit_baton = make_baton(jenv, pool, java_editor, NULL);
}
/* This baton type is used for client prompt operations */
typedef struct {
jobject callback; /* Object to call back */
apr_pool_t *pool; /* pool to use for errors */
JNIEnv *jenv; /* Java native interface structure */
} callback_baton_t;
/* Pool cleanup handler. Removes global reference */
static apr_status_t callback_baton_cleanup_handler(void *baton)
{
callback_baton_t *callback_baton = (callback_baton_t *) baton;
JCALL1(DeleteGlobalRef, callback_baton->jenv, callback_baton->callback);
return APR_SUCCESS;
}
/* Create a callback baton */
void *svn_swig_java_make_callback_baton(JNIEnv *jenv,
jobject callback,
apr_pool_t *pool)
{
jobject globalref;
callback_baton_t *callback_baton;
globalref = JCALL1(NewGlobalRef, jenv, callback);
if (globalref == NULL)
{
/* Exception occurred */
return 0;
}
callback_baton = apr_palloc(pool, sizeof(*callback_baton));
callback_baton->callback = globalref;
callback_baton->pool = pool;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?