<commit_before>/*
 * Java ATK Wrapper for GNOME
 * Copyright (C) 2009 Sun Microsystems Inc.
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <jni.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include <glib/gprintf.h>
#include "jawutil.h"
#include "jawtoplevel.h"
#include "jawobject.h"
#include "jawwindow.h"

#ifdef __cplusplus
extern "C" {
#endif

/* AtkUtil */
static void jaw_util_class_init(JawUtilClass *klass);

static guint jaw_util_add_global_event_listener(GSignalEmissionHook listener,
                                                const gchar *event_type);
static void jaw_util_remove_global_event_listener(guint remove_listener);
static guint jaw_util_add_key_event_listener(AtkKeySnoopFunc listener,
                                             gpointer data);
static void jaw_util_remove_key_event_listener(guint remove_listener);
static AtkObject* jaw_util_get_root(void);
static const gchar* jaw_util_get_toolkit_name(void);
static const gchar* jaw_util_get_toolkit_version(void);

static void _listener_info_destroy(gpointer data);
static guint add_listener(GSignalEmissionHook listener,
                          const gchar         *object_type,
                          const gchar         *signal,
                          const gchar         *hook_data);

static GHashTable *listener_list = NULL;
static gint listener_idx = 1;
static GHashTable *key_listener_list = NULL;

typedef struct _JawUtilListenerInfo JawUtilListenerInfo;

struct _JawUtilListenerInfo
{
  gint key;
  guint signal_id;
  gulong hook_id;
};

JavaVM *cachedJVM;

GType
jaw_util_get_type(void)
{
  static GType type = 0;

  if (!type) {
    static const GTypeInfo tinfo = {
      sizeof(JawUtilClass),
      (GBaseInitFunc) NULL, /*base init*/
      (GBaseFinalizeFunc) NULL, /*base finalize */
      (GClassInitFunc) jaw_util_class_init, /* class init */
      (GClassFinalizeFunc) NULL, /*class finalize */
      NULL, /* class data */
      sizeof(JawUtil), /* instance size */
      0, /* nb preallocs */
      (GInstanceInitFunc) NULL, /* instance init */
      NULL /* value table */
    };

    type = g_type_register_static(ATK_TYPE_UTIL, "JawUtil", &tinfo, 0);
  }

  return type;
}

static void
jaw_util_class_init(JawUtilClass *kclass)
{
  AtkUtilClass *atk_class;
  gpointer data;

  data = g_type_class_peek (ATK_TYPE_UTIL);
  atk_class = ATK_UTIL_CLASS (data);

  atk_class->add_global_event_listener = jaw_util_add_global_event_listener;
  atk_class->remove_global_event_listener = jaw_util_remove_global_event_listener;
  atk_class->add_key_event_listener = jaw_util_add_key_event_listener;
  atk_class->remove_key_event_listener = jaw_util_remove_key_event_listener;
  atk_class->get_root = jaw_util_get_root;
  atk_class->get_toolkit_name = jaw_util_get_toolkit_name;
  atk_class->get_toolkit_version = jaw_util_get_toolkit_version;

  listener_list = g_hash_table_new_full(g_int_hash,
                                        g_int_equal,
                                        NULL,
                                        _listener_info_destroy);
}

static guint
jaw_util_add_global_event_listener(GSignalEmissionHook listener,
                                   const gchar *event_type)
{
  guint rc = 0;
  gchar **split_string;
  guint length;

  split_string = g_strsplit (event_type, ":", 0);
  length = g_strv_length (split_string);

  if ((length == 3) || (length == 4))
    rc = add_listener (listener, split_string[1], split_string[2], event_type);
  g_strfreev (split_string);

  return rc;
}

static void
jaw_util_remove_global_event_listener (guint remove_listener)
{
  if (remove_listener > 0) {
    JawUtilListenerInfo *listener_info;<commit_msg>JNI: Fix JRE error when running java apps<commit_after>/*
 * Java ATK Wrapper for GNOME
 * Copyright (C) 2009 Sun Microsystems Inc.
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <jni.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include <glib/gprintf.h>
#include "jawutil.h"
#include "jawtoplevel.h"
#include "jawobject.h"
#include "jawwindow.h"

#ifdef __cplusplus
extern "C" {
#endif

/* AtkUtil */
static void jaw_util_class_init(JawUtilClass *klass);

static guint jaw_util_add_global_event_listener(GSignalEmissionHook listener,
                                                const gchar *event_type);
static void jaw_util_remove_global_event_listener(guint remove_listener);
static guint jaw_util_add_key_event_listener(AtkKeySnoopFunc listener,
                                             gpointer data);
static void jaw_util_remove_key_event_listener(guint remove_listener);
static AtkObject* jaw_util_get_root(void);
static const gchar* jaw_util_get_toolkit_name(void);
static const gchar* jaw_util_get_toolkit_version(void);

static void _listener_info_destroy(gpointer data);
static guint add_listener(GSignalEmissionHook listener,
                          const gchar         *object_type,
                          const gchar         *signal,
                          const gchar         *hook_data);

static GHashTable *listener_list = NULL;
static gint listener_idx = 1;
static GHashTable *key_listener_list = NULL;

typedef struct _JawUtilListenerInfo JawUtilListenerInfo;

struct _JawUtilListenerInfo
{
  gint key;
  guint signal_id;
  gulong hook_id;
};

JavaVM *cachedJVM;

GType
jaw_util_get_type(void)
{
  static GType type = 0;

  if (!type) {
    static const GTypeInfo tinfo = {
      sizeof(JawUtilClass),
      (GBaseInitFunc) NULL, /*base init*/
      (GBaseFinalizeFunc) NULL, /*base finalize */
      (GClassInitFunc) jaw_util_class_init, /* class init */
      (GClassFinalizeFunc) NULL, /*class finalize */
      NULL, /* class data */
      sizeof(JawUtil), /* instance size */
      0, /* nb preallocs */
      (GInstanceInitFunc) NULL, /* instance init */
      NULL /* value table */
    };

    type = g_type_register_static(ATK_TYPE_UTIL, "JawUtil", &tinfo, 0);
  }

  return type;
}

static void
jaw_util_class_init(JawUtilClass *kclass)
{
  AtkUtilClass *atk_class;
  gpointer data;

  data = g_type_class_peek (ATK_TYPE_UTIL);
  atk_class = ATK_UTIL_CLASS (data);

  atk_class->add_global_event_listener = jaw_util_add_global_event_listener;
  atk_class->remove_global_event_listener = jaw_util_remove_global_event_listener;
  atk_class->add_key_event_listener = jaw_util_add_key_event_listener;
  atk_class->remove_key_event_listener = jaw_util_remove_key_event_listener;
  atk_class->get_root = jaw_util_get_root;
  atk_class->get_toolkit_name = jaw_util_get_toolkit_name;
  atk_class->get_toolkit_version = jaw_util_get_toolkit_version;

  listener_list = g_hash_table_new_full(g_int_hash,
                                        g_int_equal,
                                        NULL,
                                        _listener_info_destroy);
}

static guint
jaw_util_add_global_event_listener(GSignalEmissionHook listener,
                                   const gchar *event_type)
{
  guint rc = 0;
  gchar **split_string;
  guint length;

  g_type_class_unref( g_type_class_ref(JAW_TYPE_WINDOW));
  split_string = g_strsplit (event_type, ":", 3);

  if (split_string) {
    if (!strcmp ("window", split_string[0])) {
      rc = add_listener (listener, "JawWindow", split_string[1], event_type);
    } else {
      rc = add_listener (listener, split_string[1], split_string[2], event_type);
    }

    g_strfreev (split_string);
  }


  return rc;
}

static void
jaw_util_remove_global_event_listener (guint remove_listener)
{
  if (remove_listener > 0) {
    JawUtilListenerInfo *listener_info;
{'fraction_non_alphanumeric': 0.08184115126881247, 'fraction_numerical': 0.007030649236515435, 'mean_word_length': 3.372718539865514, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5728222', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2866, 'n_words': 751}