<commit_before>/*
 * app_registry.c
 *
 *  Created on: 18.10.2012
 *      Author: alexandr
 */


#include <xwnd/app_registry.h>
#include <kernel/task.h>
#include <stdlib.h>
#include <unistd.h>
#include <xwnd/event.h>

//FIXME: this have to be removed
#include <xwnd/test_app.h>

#define XAPP_REG_DEF_CNT 256

static struct xwnd_app_registry xapp_reg;

int xwnd_app_reg_init (void) {
	xapp_reg.nodes = malloc (XAPP_REG_DEF_CNT * sizeof(struct xwnd_app_registry_node));
	if (!xapp_reg.nodes) {
		return -1;
	}
	xapp_reg.allocated = XAPP_REG_DEF_CNT;
	xapp_reg.used = 0;
	return 0;
}

struct xwnd_application * xwnd_app_create (void) {
	struct xwnd_application * t_xapp;
	struct xwnd_window * t_wnd;
	int req_pipe[2], msg_pipe[2];
	int xapp_id = xapp_reg.used;
	int xapp_tid;

	//Get an entry in registry
	if (xapp_id >= XAPP_REG_DEF_CNT - 1) {
		return NULL;
	}
	xapp_reg.used++;

	//Allocate client-side application structure
	//FIXME: This allocation is freaking bad. Replace it with something better
	t_xapp = malloc(sizeof(struct xwnd_application));
	if (!t_xapp) {
		xapp_reg.used--;
		return NULL;
	}
	xapp_reg.nodes[xapp_id].xapp = t_xapp;
	//Initialize them

	//Init pipe semaphores
	sem_init(&(t_xapp->msg_sem), 1);
	sem_init(&(t_xapp->req_sem), 1);
	//Connect pipes
	pipe(req_pipe);
	pipe(msg_pipe);
	xapp_reg.nodes[xapp_id].pipe_in  = req_pipe[0];
	xapp_reg.nodes[xapp_id].pipe_out = msg_pipe[1];
	t_xapp->pipe_in  = msg_pipe[0];
	t_xapp->pipe_out = req_pipe[1];

	//Create window
	t_wnd = malloc (sizeof(struct xwnd_window));
	if (!t_wnd) {
		free(t_xapp);
		return NULL;
	}
	t_wnd->caption = NULL;<commit_msg>xwnd: Minor event system fixes<commit_after>/*
 * app_registry.c
 *
 *  Created on: 18.10.2012
 *      Author: alexandr
 */


#include <xwnd/app_registry.h>
#include <kernel/task.h>
#include <stdlib.h>
#include <unistd.h>
#include <xwnd/event.h>

//FIXME: this have to be removed
#include <xwnd/test_app.h>

#define XAPP_REG_DEF_CNT 256

static struct xwnd_app_registry xapp_reg;

int xwnd_app_reg_init (void) {
	xapp_reg.nodes = malloc (XAPP_REG_DEF_CNT * sizeof(struct xwnd_app_registry_node));
	if (!xapp_reg.nodes) {
		return -1;
	}
	xapp_reg.allocated = XAPP_REG_DEF_CNT;
	xapp_reg.used = 0;
	return 0;
}

struct xwnd_application * xwnd_app_create (void) {
	struct xwnd_application * t_xapp;
	struct xwnd_window * t_wnd;
	int req_pipe[2], msg_pipe[2];
	int xapp_id = xapp_reg.used;
	int xapp_tid;

	//Get an entry in registry
	if (xapp_id >= XAPP_REG_DEF_CNT - 1) {
		return NULL;
	}
	xapp_reg.used++;

	//Allocate client-side application structure
	//FIXME: This allocation is freaking bad. Replace it with something better
	t_xapp = malloc(sizeof(struct xwnd_application));
	if (!t_xapp) {
		xapp_reg.used--;
		return NULL;
	}
	xapp_reg.nodes[xapp_id].xapp = t_xapp;
	//Initialize them

	//Init pipe semaphores
	sem_init(&(t_xapp->msg_sem), 2);
	sem_init(&(t_xapp->req_sem), 2);
	//Connect pipes
	pipe(req_pipe);
	pipe(msg_pipe);
	xapp_reg.nodes[xapp_id].pipe_in  = req_pipe[0];
	xapp_reg.nodes[xapp_id].pipe_out = msg_pipe[1];
	t_xapp->pipe_in  = msg_pipe[0];
	t_xapp->pipe_out = req_pipe[1];

	//Create window
	t_wnd = malloc (sizeof(struct xwnd_window));
	if (!t_wnd) {
		free(t_xapp);
		return NULL;
	}
	t_wnd->caption = NULL;
{'fraction_non_alphanumeric': 0.1329444273871661, 'fraction_numerical': 0.014123426466073074, 'mean_word_length': 4.385123966942149, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, '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': '2064444', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1404, 'n_words': 281}