<commit_before>/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 *
 * Licensed under the GNU Lesser General Public License Version 2.1
 *
 * 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
 */

/**
 * SECTION:asb-package
 * @short_description: Object representing a package file.
 * @stability: Unstable
 *
 * This object represents one package file.
 */

#include "config.h"

#include <limits.h>

#include "as-cleanup.h"
#include "asb-package.h"
#include "asb-plugin.h"

typedef struct _AsbPackagePrivate	AsbPackagePrivate;
struct _AsbPackagePrivate
{
	AsbPackageKind	 kind;
	gboolean	 enabled;
	gchar		**filelist;
	GPtrArray	*deps;
	gchar		*filename;
	gchar		*basename;
	gchar		*name;
	guint		 epoch;
	gchar		*version;
	gchar		*release;
	gchar		*arch;
	gchar		*url;
	gchar		*nevr;
	gchar		*nevra;
	gchar		*evr;
	gchar		*license;
	gchar		*vcs;
	gchar		*source_nevra;
	gchar		*source_pkgname;
	gsize		 log_written_len;
	GString		*log;
	GHashTable	*configs;
	GTimer		*timer;
	gdouble		 last_log;
	GPtrArray	*releases;
	GHashTable	*releases_hash;
	GMutex		 mutex_log;
};

G_DEFINE_TYPE_WITH_PRIVATE (AsbPackage, asb_package, G_TYPE_OBJECT)

#define GET_PRIVATE(o) (asb_package_get_instance_private (o))

/**
 * asb_package_finalize:
 **/
static void
asb_package_finalize (GObject *object)
{
	AsbPackage *pkg = ASB_PACKAGE (object);
	AsbPackagePrivate *priv = GET_PRIVATE (pkg);

	g_mutex_clear (&priv->mutex_log);
	g_strfreev (priv->filelist);
	g_ptr_array_unref (priv->deps);
	g_free (priv->filename);
	g_free (priv->basename);
	g_free (priv->name);
	g_free (priv->version);
	g_free (priv->release);
	g_free (priv->arch);
	g_free (priv->url);
	g_free (priv->nevr);
	g_free (priv->nevra);
	g_free (priv->evr);
	g_free (priv->license);
	g_free (priv->vcs);
	g_free (priv->source_nevra);
	g_free (priv->source_pkgname);
	g_string_free (priv->log, TRUE);
	g_timer_destroy (priv->timer);
	g_hash_table_unref (priv->configs);
	g_ptr_array_unref (priv->releases);
	g_hash_table_unref (priv->releases_hash);

	G_OBJECT_CLASS (asb_package_parent_class)->finalize (object);
}

/**
 * asb_package_init:
 **/
static void
asb_package_init (AsbPackage *pkg)
{
	AsbPackagePrivate *priv = GET_PRIVATE (pkg);
	priv->enabled = TRUE;
	priv->log = g_string_sized_new (1024);
	priv->timer = g_timer_new ();
	priv->deps = g_ptr_array_new_with_free_func (g_free);
	priv->configs = g_hash_table_new_full (g_str_hash, g_str_equal,
					       g_free, g_free);
	priv->releases = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
	priv->releases_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
						     g_free, (GDestroyNotify) g_object_unref);
	g_mutex_init (&priv->mutex_log);
}

/**
 * asb_package_get_enabled:
 * @pkg: A #AsbPackage
 *
 * Gets if the package is enabled.
 *
 * Returns: enabled status
 *
 * Since: 0.1.0
 **/
gboolean
asb_package_get_enabled (AsbPackage *pkg)
{
	AsbPackagePrivate *priv = GET_PRIVATE (pkg);
	return priv->enabled;
}

/**
 * asb_package_set_enabled:
 * @pkg: A #AsbPackage
 * @enabled: boolean<commit_msg>trivial: Do not allocate 1k of log space for each package at startup<commit_after>/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 *
 * Licensed under the GNU Lesser General Public License Version 2.1
 *
 * 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
 */

/**
 * SECTION:asb-package
 * @short_description: Object representing a package file.
 * @stability: Unstable
 *
 * This object represents one package file.
 */

#include "config.h"

#include <limits.h>

#include "as-cleanup.h"
#include "asb-package.h"
#include "asb-plugin.h"

typedef struct _AsbPackagePrivate	AsbPackagePrivate;
struct _AsbPackagePrivate
{
	AsbPackageKind	 kind;
	gboolean	 enabled;
	gchar		**filelist;
	GPtrArray	*deps;
	gchar		*filename;
	gchar		*basename;
	gchar		*name;
	guint		 epoch;
	gchar		*version;
	gchar		*release;
	gchar		*arch;
	gchar		*url;
	gchar		*nevr;
	gchar		*nevra;
	gchar		*evr;
	gchar		*license;
	gchar		*vcs;
	gchar		*source_nevra;
	gchar		*source_pkgname;
	gsize		 log_written_len;
	GString		*log;
	GHashTable	*configs;
	GTimer		*timer;
	gdouble		 last_log;
	GPtrArray	*releases;
	GHashTable	*releases_hash;
	GMutex		 mutex_log;
};

G_DEFINE_TYPE_WITH_PRIVATE (AsbPackage, asb_package, G_TYPE_OBJECT)

#define GET_PRIVATE(o) (asb_package_get_instance_private (o))

/**
 * asb_package_finalize:
 **/
static void
asb_package_finalize (GObject *object)
{
	AsbPackage *pkg = ASB_PACKAGE (object);
	AsbPackagePrivate *priv = GET_PRIVATE (pkg);

	g_mutex_clear (&priv->mutex_log);
	g_strfreev (priv->filelist);
	g_ptr_array_unref (priv->deps);
	g_free (priv->filename);
	g_free (priv->basename);
	g_free (priv->name);
	g_free (priv->version);
	g_free (priv->release);
	g_free (priv->arch);
	g_free (priv->url);
	g_free (priv->nevr);
	g_free (priv->nevra);
	g_free (priv->evr);
	g_free (priv->license);
	g_free (priv->vcs);
	g_free (priv->source_nevra);
	g_free (priv->source_pkgname);
	g_string_free (priv->log, TRUE);
	g_timer_destroy (priv->timer);
	g_hash_table_unref (priv->configs);
	g_ptr_array_unref (priv->releases);
	g_hash_table_unref (priv->releases_hash);

	G_OBJECT_CLASS (asb_package_parent_class)->finalize (object);
}

/**
 * asb_package_init:
 **/
static void
asb_package_init (AsbPackage *pkg)
{
	AsbPackagePrivate *priv = GET_PRIVATE (pkg);
	priv->enabled = TRUE;
	priv->log = g_string_new (NULL);
	priv->timer = g_timer_new ();
	priv->deps = g_ptr_array_new_with_free_func (g_free);
	priv->configs = g_hash_table_new_full (g_str_hash, g_str_equal,
					       g_free, g_free);
	priv->releases = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
	priv->releases_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
						     g_free, (GDestroyNotify) g_object_unref);
	g_mutex_init (&priv->mutex_log);
}

/**
 * asb_package_get_enabled:
 * @pkg: A #AsbPackage
 *
 * Gets if the package is enabled.
 *
 * Returns: enabled status
 *
 * Since: 0.1.0
 **/
gboolean
asb_package_get_enabled (AsbPackage *pkg)
{
	AsbPackagePrivate *priv = GET_PRIVATE (pkg);
	return priv->enabled;
}

/**
 * asb_package_set_enabled:
 * @pkg: A #AsbPackage
 * @enabled: boolean
{'fraction_non_alphanumeric': 0.11594392768243154, 'fraction_numerical': 0.006943534652168217, 'mean_word_length': 4.609110947832476, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4649810', 'n_tokens_mistral': 2946, 'n_tokens_neox': 2846, 'n_words': 741}