Пример #1
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Oget_comment
 * Signature: (J)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL
Java_hdf_hdf5lib_H5_H5Oget_1comment
    (JNIEnv *env, jclass clss, jlong loc_id)
{
    jstring  str = NULL;
    ssize_t  buf_size;
    ssize_t  status = -1;
    char    *oComment = NULL;

    UNUSED(clss);

    /* Get the length of the comment */
    if ((buf_size = H5Oget_comment((hid_t)loc_id, NULL, 0)) < 0)
        H5_LIBRARY_ERROR(ENVONLY);

    if (buf_size) {
        if (NULL == (oComment = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1)))
            H5_JNI_FATAL_ERROR(ENVONLY, "H5Oget_comment: failed to allocate object comment buffer");

        if ((status = H5Oget_comment((hid_t)loc_id, oComment, (size_t)buf_size + 1)) < 0)
            H5_LIBRARY_ERROR(ENVONLY);
        oComment[buf_size] = '\0';

        if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, oComment)))
            CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
    }

done:
    if (oComment)
        HDfree(oComment);

    return (jstring)str;
} /* end Java_hdf_hdf5lib_H5_H5Oget_1comment */
static void im_preedit_done(XIM im_xim, XPointer client, XPointer call) {
    (void)im_xim;
    (void)call;

    mainEnv->CallVoidMethod((jobject) client, jViewNotifyPreeditMode, JNI_FALSE);
    CHECK_JNI_EXCEPTION(mainEnv);
}
Пример #3
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Ovisit_by_name
 * Signature: (JLjava/lang/String;IILjava/lang/Object;Ljava/lang/Object;IJ)I
 */
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Ovisit_1by_1name
    (JNIEnv *env, jclass clss, jlong grp_id, jstring name, jint idx_type, jint order,
        jobject callback_op, jobject op_data, jint fields, jlong access_id)
{
    cb_wrapper  wrapper = { callback_op, op_data };
    const char *objName = NULL;
    herr_t      status = FAIL;

    UNUSED(clss);

    ENVPTR->GetJavaVM(ENVONLY, &jvm);
    CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);

    if (NULL == op_data)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ovisit_by_name: op_data is NULL");
    if (NULL == callback_op)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ovisit_by_name: callback_op is NULL");
    if (NULL == name)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ovisit_by_name: object name is NULL");

    PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Ovisit_by_name: object name not pinned");

    if ((status = H5Ovisit_by_name2((hid_t)grp_id, objName, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5O_iterate_t)H5O_iterate_cb, (void *)&wrapper, (unsigned)fields, (hid_t)access_id)) < 0)
        H5_LIBRARY_ERROR(ENVONLY);

done:
    if (objName)
        UNPIN_JAVA_STRING(ENVONLY, name, objName);

    return status;
} /* end Java_hdf_hdf5lib_H5_H5Ovisit_1by_1name */
static void set_data_func(GtkClipboard *clipboard, GtkSelectionData *selection_data,
        guint info, gpointer user_data)
{
    jobject data = (jobject) user_data; //HashMap
    GdkAtom target;
    target = gtk_selection_data_get_target(selection_data);

    set_data(target, selection_data, data);
    CHECK_JNI_EXCEPTION(mainEnv);
}
static void im_preedit_draw(XIM im_xim, XPointer client, XPointer call) {
    (void)im_xim;
    (void)call;

    XIMPreeditDrawCallbackStruct *data = (XIMPreeditDrawCallbackStruct*) call;
    jstring text = NULL;
    jbyteArray attr = NULL;

    if (data->text != NULL) {
        if (data->text->string.multi_byte) {
            if (data->text->encoding_is_wchar) {
                size_t csize = wcstombs(NULL, data->text->string.wide_char, 0);
                char *ctext = new char[csize + 1];
                wcstombs(ctext, data->text->string.wide_char, csize + 1);
                text = mainEnv->NewStringUTF(ctext);
                delete[] ctext;
                CHECK_JNI_EXCEPTION(mainEnv);
            } else {
                text = mainEnv->NewStringUTF(data->text->string.multi_byte);
                CHECK_JNI_EXCEPTION(mainEnv);
            }
        }

        if (XIMFeedback* fb = data->text->feedback) {
            attr = mainEnv->NewByteArray(data->text->length);
            CHECK_JNI_EXCEPTION(mainEnv)
            jbyte v[data->text->length];
            for (int i = 0; i < data->text->length; i++) {
                if (fb[i] & XIMReverse) {
                    v[i] = com_sun_glass_ui_View_IME_ATTR_TARGET_NOTCONVERTED;
                } else if (fb[i] & XIMHighlight) {
                    v[i] = com_sun_glass_ui_View_IME_ATTR_TARGET_CONVERTED;
                } else if (fb[i] & XIMUnderline) {
                    v[i] = com_sun_glass_ui_View_IME_ATTR_CONVERTED;
                } else {
                    v[i] = com_sun_glass_ui_View_IME_ATTR_INPUT;
                }
            }
            mainEnv->SetByteArrayRegion(attr, 0, data->text->length, v);
            CHECK_JNI_EXCEPTION(mainEnv)
        }
    }
static void set_bytebuffer_data(GtkSelectionData *selection_data, GdkAtom target, jobject data)
{
    jbyteArray byteArray = (jbyteArray) mainEnv->CallObjectMethod(data, jByteBufferArray);
    CHECK_JNI_EXCEPTION(mainEnv)
    jbyte* raw = mainEnv->GetByteArrayElements(byteArray, NULL);
    jsize nraw = mainEnv->GetArrayLength(byteArray);

    //XXX is target == type ??
    gtk_selection_data_set(selection_data, target, 8, (guchar *)raw, (gint)nraw);

    mainEnv->ReleaseByteArrayElements(byteArray, raw, JNI_ABORT);
}
Пример #7
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Pget_elink_prefix
 * Signature: (J[Ljava/lang/String;)J
 */
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix
    (JNIEnv *env, jclass clss, jlong lapl_id, jobjectArray prefix)
{
    ssize_t  prefix_size = -1;
    size_t   size = 0;
    char    *pre = NULL;
    jstring  str = NULL;

    UNUSED(clss);

    if (NULL == prefix)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_elink_prefix: prefix is NULL");

    if ((prefix_size = H5Pget_elink_prefix((hid_t)lapl_id, (char *)NULL, size)) < 0)
        H5_LIBRARY_ERROR(ENVONLY);

    if (NULL == (pre = (char *) HDmalloc(sizeof(char) * (size_t) prefix_size + 1)))
        H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_elink_prefix: memory allocation failed");

    if (H5Pget_elink_prefix((hid_t)lapl_id, (char *)pre, (size_t) prefix_size + 1) < 0)
        H5_LIBRARY_ERROR(ENVONLY);
    pre[prefix_size] = '\0';

    if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, pre))) {
        CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
        H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_elink_prefix: out of memory - unable to construct string from UTF characters");
    }

    ENVPTR->SetObjectArrayElement(ENVONLY, prefix, 0, str);
    CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);

done:
    if (pre)
        HDfree(pre);

    return (jlong)prefix_size;
} /* end Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix */
Пример #8
0
/*
 * Class:     com_sun_glass_ui_gtk_GtkView
 * Method:    _setParent
 * Signature: (JJ)V
 */
JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkView__1setParent
  (JNIEnv * env, jobject obj, jlong ptr, jlong parent)
{
    GlassView* view = JLONG_TO_GLASSVIEW(ptr);
    bool is_removing = view->current_window && !parent;

    view->current_window = (WindowContext*)JLONG_TO_PTR(parent);

    if (is_removing) {
        env->CallVoidMethod(obj, jViewNotifyView, com_sun_glass_events_ViewEvent_REMOVE);
    } else {
        env->CallVoidMethod(obj, jViewNotifyView, com_sun_glass_events_ViewEvent_ADD);
    }
    CHECK_JNI_EXCEPTION(env);
}
Пример #9
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Oget_comment_by_name
 * Signature: (JLjava/lang/String;J)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL
Java_hdf_hdf5lib_H5_H5Oget_1comment_1by_1name
    (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_id)
{
    const char *objName = NULL;
    jstring     str = NULL;
    ssize_t     buf_size;
    ssize_t     status;
    char       *objComment = NULL;

    UNUSED(clss);

    if (NULL == name)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Oget_comment_by_name: object name is NULL");

    PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Oget_comment_by_name: object name not pinned");

    /* Get the length of the comment */
    if ((buf_size = H5Oget_comment_by_name((hid_t)loc_id, objName, NULL, 0, (hid_t)access_id)) < 0)
        H5_LIBRARY_ERROR(ENVONLY);

    if (buf_size) {
        if (NULL == (objComment = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1)))
            H5_JNI_FATAL_ERROR(ENVONLY, "H5Oget_comment_by_name: failed to allocate buffer for object comment");

        if ((status = H5Oget_comment_by_name((hid_t)loc_id, objName, objComment, (size_t)buf_size + 1, (hid_t)access_id)) < 0)
            H5_LIBRARY_ERROR(ENVONLY);
        objComment[buf_size] = '\0';

        if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, objComment)))
            CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
    }

done:
    if (objComment)
        HDfree(objComment);
    if (objName)
        UNPIN_JAVA_STRING(ENVONLY, name, objName);

    return (jstring)str;
} /* end Java_hdf_hdf5lib_H5_H5Oget_1comment_1by_1name */
static void data_to_targets(JNIEnv *env, jobject data, GtkTargetEntry **targets, gint *ntargets)
{
    jobject keys;
    jobject keysIterator;
    jstring next;

    GtkTargetList *list = gtk_target_list_new(NULL, 0);

    keys = env->CallObjectMethod(data, jMapKeySet, NULL);
    CHECK_JNI_EXCEPTION(env)
    keysIterator = env->CallObjectMethod(keys, jIterableIterator, NULL);
    CHECK_JNI_EXCEPTION(env)

    while (env->CallBooleanMethod(keysIterator, jIteratorHasNext) == JNI_TRUE) {
        next = (jstring) env->CallObjectMethod(keysIterator, jIteratorNext, NULL);
        add_target_from_jstring(env, list, next);
    }
    *targets = gtk_target_table_new_from_list(list, ntargets);
    gtk_target_list_unref(list);

}
Пример #11
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Ovisit
 * Signature: (JIILjava/lang/Object;Ljava/lang/Object;I)I
 */
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Ovisit
    (JNIEnv *env, jclass clss, jlong grp_id, jint idx_type, jint order,
        jobject callback_op, jobject op_data, jint fields)
{
    cb_wrapper wrapper = { callback_op, op_data };
    herr_t     status = FAIL;

    UNUSED(clss);

    ENVPTR->GetJavaVM(ENVONLY, &jvm);
    CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);

    if (NULL == op_data)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ovisit: op_data is NULL");
    if (NULL == callback_op)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ovisit: callback_op is NULL");

    if ((status = H5Ovisit2((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5O_iterate_t)H5O_iterate_cb, (void *)&wrapper, (unsigned)fields)) < 0)
        H5_LIBRARY_ERROR(ENVONLY);

done:
    return status;
} /* end Java_hdf_hdf5lib_H5_H5Ovisit */
static void set_uri_data(GtkSelectionData *selection_data, jobject data) {
    const gchar* url = NULL;
    jstring jurl = NULL;

    jobjectArray files_array = NULL;
    gsize files_cnt = 0;
    
    jstring typeString;

    typeString = mainEnv->NewStringUTF("text/uri-list");
    if (mainEnv->CallBooleanMethod(data, jMapContainsKey, typeString, NULL)) {
        jurl = (jstring) mainEnv->CallObjectMethod(data, jMapGet, typeString, NULL);
        CHECK_JNI_EXCEPTION(mainEnv);
        url = mainEnv->GetStringUTFChars(jurl, NULL);
    }
    
    typeString = mainEnv->NewStringUTF("application/x-java-file-list");
    if (mainEnv->CallBooleanMethod(data, jMapContainsKey, typeString, NULL)) {
        files_array = (jobjectArray) mainEnv->CallObjectMethod(data, jMapGet, typeString, NULL);
        CHECK_JNI_EXCEPTION(mainEnv);
        if (files_array) {
            files_cnt = mainEnv->GetArrayLength(files_array);
        }
    }

    if (!url && !files_cnt) {
        return;
    }

    gsize uri_cnt = files_cnt + (url ? 1 : 0);

    gchar **uris = 
            (gchar**) glass_try_malloc0_n(uri_cnt + 1, // uris must be a NULL-terminated array of strings
                                            sizeof(gchar*));
    if (!uris) {
        if (url) {
            mainEnv->ReleaseStringUTFChars(jurl, url);
        }
        glass_throw_oom(mainEnv, "Failed to allocate uri data");
        return;
    }

    gsize i = 0;
    if (files_cnt > 0) {
        for (; i < files_cnt; ++i) {
            jstring string = (jstring) mainEnv->GetObjectArrayElement(files_array, i);
            const gchar* file = mainEnv->GetStringUTFChars(string, NULL);
            uris[i] = g_filename_to_uri(file, NULL, NULL);
            mainEnv->ReleaseStringUTFChars(string, file);
        }
    }

    if (url) {
        uris[i] = (gchar*) url;
    }
    //http://www.ietf.org/rfc/rfc2483.txt
    gtk_selection_data_set_uris(selection_data, uris);

    for (i = 0; i < uri_cnt; ++i) {
        if (uris[i] != url) {
            g_free(uris[i]);
        }
    }

    if (url) {
        mainEnv->ReleaseStringUTFChars(jurl, url);
    }
    g_free(uris);
}
Пример #13
0
static herr_t
H5O_iterate_cb
    (hid_t g_id, const char *name, const H5O_info_t *info, void *cb_data)
{
    cb_wrapper *wrapper = (cb_wrapper *)cb_data;
    jmethodID   constructor, mid;
    jobject     cb_info_t = NULL;
    jobject     visit_callback = wrapper->visit_callback;
    jobject     hdrinfobuf;
    jobject     ihinfobuf1;
    jobject     ihinfobuf2;
    jstring     str;
    JNIEnv     *cbenv = NULL;
    jclass      cls;
    jvalue      args[12];
    void       *op_data = (void *)wrapper->op_data;
    jint        status = FAIL;

    if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) {
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE);
        H5_JNI_FATAL_ERROR(CBENVONLY, "H5O_iterate_cb: failed to attach current thread to JVM");
    }

    if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, visit_callback)))
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);

    if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5O_info_t;Lhdf/hdf5lib/callbacks/H5O_iterate_t;)I")))
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);

    if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name)))
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);

    args[0].i = (jint)info->hdr.version;
    args[1].i = (jint)info->hdr.nmesgs;
    args[2].i = (jint)info->hdr.nchunks;
    args[3].i = (jint)info->hdr.flags;
    args[4].j = (jlong)info->hdr.space.total;
    args[5].j = (jlong)info->hdr.space.meta;
    args[6].j = (jlong)info->hdr.space.mesg;
    args[7].j = (jlong)info->hdr.space.free;
    args[8].j = (jlong)info->hdr.mesg.present;
    args[9].j = (jlong)info->hdr.mesg.shared;

    /* Get a reference to the H5_hdr_info_t class */
    if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5O_hdr_info_t")))
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);

    /* Get a reference to the constructor; the name is <init> */
    if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "<init>", "(IIIIJJJJJJ)V")))
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);

    if (NULL == (hdrinfobuf = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) {
        HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5O_hdr_info_t: Creation failed\n");
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
    }

    args[0].j = (jlong)info->meta_size.obj.index_size;
    args[1].j = (jlong)info->meta_size.obj.heap_size;

    /* Get a reference to the H5_ih_info_t class */
    if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5_ih_info_t")))
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);

    /* Get a reference to the constructor; the name is <init> */
    if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "<init>", "(JJ)V")))
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);

    if (NULL == (ihinfobuf1 = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) {
        HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5_ih_info_t: Creation failed\n");
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
    }

    args[0].j = (jlong)info->meta_size.attr.index_size;
    args[1].j = (jlong)info->meta_size.attr.heap_size;

    if (NULL == (ihinfobuf2 = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) {
        HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5_ih_info_t: Creation failed\n");
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
    }

    args[0].j = (jlong)info->fileno;
    args[1].j = (jlong)info->addr;
    args[2].i = info->type;
    args[3].i = (jint)info->rc;
    args[4].j = (jlong)info->num_attrs;
    args[5].j = info->atime;
    args[6].j = info->mtime;
    args[7].j = info->ctime;
    args[8].j = info->btime;
    args[9].l = hdrinfobuf;
    args[10].l = ihinfobuf1;
    args[11].l = ihinfobuf2;

    /* Get a reference to the H5O_info_t class */
    if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5O_info_t")))
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);

    /* Get a reference to the constructor; the name is <init> */
    if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "<init>", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V")))
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);

    if (NULL == (cb_info_t = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) {
        HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5O_info_t: Creation failed\n");
        CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
    }

    status = CBENVPTR->CallIntMethod(CBENVONLY, visit_callback, mid, g_id, str, cb_info_t, op_data);
    CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);

done:
    if (cbenv)
        JVMPTR->DetachCurrentThread(JVMPAR);

    return (herr_t)status;
} /* end H5O_iterate_cb */