<commit_before>/*  XMMS2 - X Music Multiplexer System
 *  Copyright (C) 2003, 2004 <NAME>, <NAME>, <NAME>
 *
 *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
 *
 *  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.
 */

#include <xmms/xmmsclient.h>

#include <ruby.h>

#include "rb_xmmsclient_main.h"
#include "rb_result.h"

typedef struct {
	xmmsc_result_t *real;
	VALUE parent;
	VALUE callback;
} RbResult;

static VALUE cResult;

static void c_mark (RbResult *res)
{
	if (!NIL_P (res->parent))
		rb_gc_mark (res->parent);

	if (!NIL_P (res->callback))
		rb_gc_mark (res->callback);
}

static void c_free (RbResult *res)
{
	if (res->real)
		xmmsc_result_unref (res->real);

	free (res);
}

VALUE TO_XMMS_CLIENT_RESULT (VALUE parent, xmmsc_result_t *res)
{
	VALUE self;
	RbResult *rbres = NULL;

	if (!res)
		return Qnil;

	self = Data_Make_Struct (cResult, RbResult, c_mark, c_free, rbres);

	rbres->real = res;
	rbres->parent = parent;
	rbres->callback = Qnil;

	rb_obj_call_init (self, 0, NULL);

	return self;
}

static void on_signal (xmmsc_result_t *res2, void *data)
{
	VALUE self = (VALUE) data;

	GET_OBJ (self, RbResult, res);

	rb_funcall (res->callback, rb_intern ("call"), 1,
	            TO_XMMS_CLIENT_RESULT (self, res2));
}

static VALUE c_notifier_set (VALUE self)
{
	GET_OBJ (self, RbResult, res);

	if (!rb_block_given_p ())
		return Qnil;

	res->callback = rb_block_proc ();

	xmmsc_result_notifier_set (res->real, on_signal, (void *) self);

	return Qnil;
}

static VALUE c_wait (VALUE self)
{
	GET_OBJ (self, RbResult, res);

	xmmsc_result_wait (res->real);

	return Qnil;
}

static VALUE c_restart (VALUE self)
{
	xmmsc_result_t *res2;

	GET_OBJ (self, RbResult, res);

	if ((res2 = xmmsc_result_restart (res->real)))
		xmmsc_result_unref (res2);

	return Qnil;
}

static VALUE c_int_get (VALUE self)
{
	int id = 0;

	GET_OBJ (self, RbResult, res);

	if (!xmmsc_result_get_int (res->real, &id)) {
		rb_raise (rb_eRuntimeError, "xmmsc_result_get_int() failed");
		return Qnil;
	}

	return INT2FIX (id);
}

static VALUE c_uint_get (VALUE self)
{
	unsigned int id = 0;

	GET_OBJ (self, RbResult, res);

	if (!xmmsc_result_get_uint (res->real, &id)) {
		rb_raise (rb_eRuntimeError, "xmmsc_result_get_uint() failed");
		return Qnil;
	}

	return UINT2NUM (id);
}

static VALUE c_string_get (VALUE self)<commit_msg>Result#wait and Result#restart return self now.<commit_after>/*  XMMS2 - X Music Multiplexer System
 *  Copyright (C) 2003, 2004 <NAME>, <NAME>, <NAME>
 *
 *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
 *
 *  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.
 */

#include <xmms/xmmsclient.h>

#include <ruby.h>

#include "rb_xmmsclient_main.h"
#include "rb_result.h"

typedef struct {
	xmmsc_result_t *real;
	VALUE parent;
	VALUE callback;
} RbResult;

static VALUE cResult;

static void c_mark (RbResult *res)
{
	if (!NIL_P (res->parent))
		rb_gc_mark (res->parent);

	if (!NIL_P (res->callback))
		rb_gc_mark (res->callback);
}

static void c_free (RbResult *res)
{
	if (res->real)
		xmmsc_result_unref (res->real);

	free (res);
}

VALUE TO_XMMS_CLIENT_RESULT (VALUE parent, xmmsc_result_t *res)
{
	VALUE self;
	RbResult *rbres = NULL;

	if (!res)
		return Qnil;

	self = Data_Make_Struct (cResult, RbResult, c_mark, c_free, rbres);

	rbres->real = res;
	rbres->parent = parent;
	rbres->callback = Qnil;

	rb_obj_call_init (self, 0, NULL);

	return self;
}

static void on_signal (xmmsc_result_t *res2, void *data)
{
	VALUE self = (VALUE) data;

	GET_OBJ (self, RbResult, res);

	rb_funcall (res->callback, rb_intern ("call"), 1,
	            TO_XMMS_CLIENT_RESULT (self, res2));
}

static VALUE c_notifier_set (VALUE self)
{
	GET_OBJ (self, RbResult, res);

	if (!rb_block_given_p ())
		return Qnil;

	res->callback = rb_block_proc ();

	xmmsc_result_notifier_set (res->real, on_signal, (void *) self);

	return Qnil;
}

static VALUE c_wait (VALUE self)
{
	GET_OBJ (self, RbResult, res);

	xmmsc_result_wait (res->real);

	return self;
}

static VALUE c_restart (VALUE self)
{
	xmmsc_result_t *res2;

	GET_OBJ (self, RbResult, res);

	if ((res2 = xmmsc_result_restart (res->real)))
		xmmsc_result_unref (res2);

	return self;
}

static VALUE c_int_get (VALUE self)
{
	int id = 0;

	GET_OBJ (self, RbResult, res);

	if (!xmmsc_result_get_int (res->real, &id)) {
		rb_raise (rb_eRuntimeError, "xmmsc_result_get_int() failed");
		return Qnil;
	}

	return INT2FIX (id);
}

static VALUE c_uint_get (VALUE self)
{
	unsigned int id = 0;

	GET_OBJ (self, RbResult, res);

	if (!xmmsc_result_get_uint (res->real, &id)) {
		rb_raise (rb_eRuntimeError, "xmmsc_result_get_uint() failed");
		return Qnil;
	}

	return UINT2NUM (id);
}

static VALUE c_string_get (VALUE self)
{'fraction_non_alphanumeric': 0.1173036093418259, 'fraction_numerical': 0.00778485491861288, 'mean_word_length': 4.248839368616528, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 45, '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': '3930414', 'n_tokens_mistral': 2273, 'n_tokens_neox': 2173, 'n_words': 634}