jdk/src/solaris/native/sun/xawt/awt_Desktop.c
author dav
Wed, 16 Feb 2011 01:12:53 +0300
changeset 8369 d835f77a7f86
parent 7668 d4a77089c587
child 9035 1255eb81cc2f
permissions -rw-r--r--
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior. Reviewed-by: art, dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6825
diff changeset
     2
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
typedef int gboolean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    31
typedef gboolean (GNOME_URL_SHOW_TYPE)(const char *, void **);
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    32
typedef gboolean (GNOME_VFS_INIT_TYPE)(void);
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    33
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    34
GNOME_URL_SHOW_TYPE *gnome_url_show;
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    35
GNOME_VFS_INIT_TYPE *gnome_vfs_init;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
int init(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    void *vfs_handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    void *gnome_handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    const char *errmsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    vfs_handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    if (vfs_handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#ifdef INTERNAL_BUILD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        fprintf(stderr, "can not load libgnomevfs-2.so\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    dlerror(); /* Clear errors */
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    50
    gnome_vfs_init = (GNOME_VFS_INIT_TYPE*)dlsym(vfs_handle, "gnome_vfs_init");
8369
d835f77a7f86 6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents: 7668
diff changeset
    51
    if (gnome_vfs_init == NULL){
d835f77a7f86 6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents: 7668
diff changeset
    52
#ifdef INTERNAL_BUILD
d835f77a7f86 6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents: 7668
diff changeset
    53
        fprintf(stderr, "dlsym( gnome_vfs_init) returned NULL\n");
d835f77a7f86 6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents: 7668
diff changeset
    54
#endif
d835f77a7f86 6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents: 7668
diff changeset
    55
        return 0;
d835f77a7f86 6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents: 7668
diff changeset
    56
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    if ((errmsg = dlerror()) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#ifdef INTERNAL_BUILD
8369
d835f77a7f86 6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents: 7668
diff changeset
    59
        fprintf(stderr, "can not find symbol gnome_vfs_init %s \n", errmsg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // call gonme_vfs_init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    (*gnome_vfs_init)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    gnome_handle = dlopen("libgnome-2.so.0", RTLD_LAZY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    if (gnome_handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#ifdef INTERNAL_BUILD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        fprintf(stderr, "can not load libgnome-2.so\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    dlerror(); /* Clear errors */
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    74
    gnome_url_show = (GNOME_URL_SHOW_TYPE*)dlsym(gnome_handle, "gnome_url_show");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    if ((errmsg = dlerror()) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#ifdef INTERNAL_BUILD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        fprintf(stderr, "can not find symble gnome_url_show\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Class:     sun_awt_X11_XDesktopPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Method:    init
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_init
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    int init_ok = init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    return init_ok ? JNI_TRUE : JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * Class:     sun_awt_X11_XDesktopPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * Method:    gnome_url_show
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * Signature: (Ljava/lang/[B;)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_gnome_1url_1show
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  (JNIEnv *env, jobject obj, jbyteArray url_j)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    gboolean success;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   106
    const char* url_c;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   108
    if (gnome_url_show == NULL) {
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   109
        return JNI_FALSE;
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   110
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   112
    url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // call gnome_url_show(const char* , GError**)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    success = (*gnome_url_show)(url_c, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    (*env)->ReleaseByteArrayElements(env, url_j, (signed char*)url_c, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    return success ? JNI_TRUE : JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
}