Esempio n. 1
0
void		pipe_in_list(char **tmp, t_list *list, int **pipe_fd, int nb_pipe)
{
  t_command	*command;
  int		fd[2];
  int		i;
  int		j;

  i = 0;
  j = 0;
  if ((command = malloc(sizeof(t_command))) == NULL)
    exit (0);
  init_struct(command);
  while (nb_pipe > 0)
    {
      add_pipe(pipe_fd, command, fd, j);
      command->data = my_str_to_wordtab(tmp[i++], ' ');
      my_insert_pushfront(list, command);
      command->input = fd[0];
      j += 2;
      nb_pipe -= 1;
    }
  command->output = -1;
  command->data = my_str_to_wordtab(tmp[i], ' ');
  my_insert_pushfront(list, command);
}
Esempio n. 2
0
void Model::init_pipes(QJsonArray pipes_array){
    QJsonObject pipe_obj;
    for(int i=0; i<pipes_array.size();i++){
        pipe_obj=pipes_array[i].toObject();
        add_pipe(pipe_obj["height"].toInt(),pipe_obj["line"].toInt(),
                pipe_obj["column"].toInt());
    }
}
Esempio n. 3
0
int			add_to_rooms(t_room **rooms, char *str)
{
	if (*str == 'L')
		return (error("A room cannot start with a L"));
	if (*str == '#')
	{
		if (*(str + 1) == '#')
			return (add_command(rooms, str));
		return (COMMENT);
	}
	if (ft_strchr(str, '-'))
		return (add_pipe(rooms, str));
	return (create_and_add_room(rooms, str, ROOM));
}
Esempio n. 4
0
/* creates a process_h struct with defaults */
process_h *initng_process_db_new(ptype_h * type)
{
	process_h *new_p = NULL;
	pipe_h *current_pipe;

	/* allocate a new process entry */
	new_p = (process_h *) initng_toolbox_calloc(1, sizeof(process_h));
	if (!new_p) {
		F_("Unable to allocate process!\n");
		return NULL;
	}

	new_p->pt = type;

	/* null pid */
	new_p->pid = 0;

	/* reset return code */
	new_p->r_code = 0;

	/* Set this to active, so it wont get freed */
	new_p->pst = P_ACTIVE;

	/* initziate list of pipes, so we can run add_pipe below without segfault */
	initng_list_init(&new_p->pipes.list);

	/* create the output pipe */
	current_pipe = initng_process_db_pipe_new(BUFFERED_OUT_PIPE);
	if (!current_pipe) {
		free(new_p);
		return NULL;
	}

	/* we want this pipe to get fd 1 and 2 in the fork */
	current_pipe->targets[0] = STDOUT_FILENO;
	current_pipe->targets[1] = STDERR_FILENO;
	add_pipe(current_pipe, new_p);

	/* return new process_h pointer */
	return new_p;
}
Esempio n. 5
0
void *op_brick_add(t_brick *brick)
{
	t_context *C = ctx_get();
	t_node *node = NULL;
	t_block *block;
	t_set *set;

	// store
	scene_store(C->scene,1);

	char *name=brick->id.name;

	     if(is(name,"frame")) 		node = add_slider_int(C,"frame",&C->app->frame); 
	else if(is(name,"timer"))  		node = add_slider_float(C,"timer",&C->app->timer); 
	else if(is(name,"timer low"))  		node = add_slider_float(C,"timer low",&C->app->timer_add_low); 
	else if(is(name,"=")) 			node = add_operator_double(C,"=");
	else if(is(name,">"))  			node = add_operator_double(C,">"); 
	else if(is(name,"<"))  			node = add_operator_double(C,"<"); 
	else if(is(name,"if")) 			node = add_if(C); 
	else if(is(name,"mod"))  		node = add_operator_double(C,"mod"); 
	else if(is(name,"x")) 			node = add_maths(C,"x");
	else if(is(name,"+"))  			node = add_maths(C,"+"); 
	else if(is(name,"++")) 			node = add_plusplus(C);
	else if(is(name,"switch"))  		node = add_switch(C,"switch",NULL,NULL); 
	else if(is(name,"clone"))  		node = add_clone(C); 
	else if(is(name,"pipe")) 		node = add_pipe(C); 
	else if(is(name,"sec")) 		node = add_slider_int(C,"sec",&C->app->clock->sec);
	else if(is(name,"min")) 		node = add_slider_int(C,"min",&C->app->clock->min);
	else if(is(name,"int")) 		node = add_slider_int(C,"int",NULL);
	else if(is(name,"float")) 		node = add_slider_float(C,"float",NULL);
	else if(is(name,"10")) 			node = add_multiplier(C,"10");
	else if(is(name,"100")) 		node = add_multiplier(C,"100");
	else if(is(name,".1")) 			node = add_multiplier(C,".1");
	else if(is(name,".01")) 		node = add_multiplier(C,".01");
	else if(is(name,".001")) 		node = add_multiplier(C,".001");
	else if(is(name,"msec")) 		node = add_slider_int(C,"msec",&C->app->clock->msec);
	else if(is(name,"cos")) 		node = add_operator_single(C,"cos",op_cos);
	else if(is(name,"sin")) 		node = add_operator_single(C,"sin",op_sin);
	else if(is(name,"cam_eye_x")) 		node = add_slider_camera(C,"eye x");
	else if(is(name,"cam_eye_y")) 		node = add_slider_camera(C,"eye y");
	else if(is(name,"cam_eye_z")) 		node = add_slider_camera(C,"eye z");
	else if(is(name,"cam_pos_x")) 		node = add_slider_camera(C,"pos x");
	else if(is(name,"cam_pos_y")) 		node = add_slider_camera(C,"pos y");
	else if(is(name,"cam_pos_z")) 		node = add_slider_camera(C,"pos z");
	else if(is(name,"cam_rot_xy")) 		node = add_slider_float_custom(C,"cam rot xy",op_camera_rotate_xy); 
	else if(is(name,"cam_rot_z")) 		node = add_slider_float_custom(C,"cam rot z",op_camera_rotate_z); 
	else if(is(name,"pos x")) 		node = add_slider_object(C,"pos x");
	else if(is(name,"pos y")) 		node = add_slider_object(C,"pos y");
	else if(is(name,"pos z")) 		node = add_slider_object(C,"pos z");
	else if(is(name,"rot x")) 		node = add_slider_object(C,"rot x");
	else if(is(name,"rot y")) 		node = add_slider_object(C,"rot y");
	else if(is(name,"rot z")) 		node = add_slider_object(C,"rot z");
	else if(is(name,"scl x")) 		node = add_slider_object(C,"scl x");
	else if(is(name,"scl y")) 		node = add_slider_object(C,"scl y");
	else if(is(name,"scl z")) 		node = add_slider_object(C,"scl z");
	else if(is(name,"red")) 		node = add_slider_object(C,"red");
	else if(is(name,"green")) 		node = add_slider_object(C,"green");
	else if(is(name,"blue")) 		node = add_slider_object(C,"blue");
	else if(is(name,"color")) 		node = add_slider_object(C,"color");
	else if(is(name,"faces")) 		node = add_slider_object(C,"faces");
	else if(is(name,"alpha")) 		node = add_slider_object(C,"alpha");
	else if(is(name,"label")) 		node = add_label(C,"label");
	else if(is(name,"get")) 		node = add_get(C);
	else if(is(name,"rewind")) 		node = add_trigger_always(C,"rewind",op_rewind); 
	else if(is(name,"not")) 		node = add_slider_int_custom(C,"not",NULL,op_not); 
	else if(is(name,"mouse_x")) 		node = add_slider_int(C,"mouse x",&C->app->mouse->x); 
	else if(is(name,"mouse_y")) 		node = add_slider_int(C,"mouse y",&C->app->mouse->y); 
	else if(is(name,"keyboard")) 		node = add_slider_char(C,"keyboard",&C->app->keyboard->key_pressed); 
	else if(is(name,"rnd")) 		node = add_slider_int_custom(C,"rnd",NULL,op_rnd);
	else if(is(name,"neg")) 		node = add_slider_int_custom(C,"neg",NULL,op_neg);
	else if(is(name,"abs")) 		node = add_slider_int_custom( C, "abs", NULL, op_abs); 
	else if(is(name,"last?")) 		node = add_switch(C,"last?",NULL,op_is_last);
	else if(is(name,"for")) 		node = add_for(C);
	else if(is(name,"vector 3d")) 		node = add_vector_3d(C);
	else if(is(name,"vector 2d")) 		node = add_vector_2d(C);
	else if(is(name,"bang")) 		node = add_slider_int_custom(C,"bang",NULL,op_bang); 
	else if(is(name,"quit")) 		node = add_trigger_always(C,"quit",op_do_quit); 
	else if(is(name,"const")) 		node = add_const(C); 
	else if(is(name,"and")) 		node = add_maths(C,"and"); 
	else if(is(name,"stack")) 		node = add_stack(C); 
	else if(is(name,"mesh")) 		node = add_slider_object(C,"mesh"); 
	else if(is(name,"vertex")) 		node = add_brick_mesh(C,"vertex"); 
	else if(is(name,"edges")) 		node = add_brick_mesh(C,"edges"); 
	else if(is(name,"case")) 		node = add_case(C,"switch"); 

	// Store
	scene_store(C->scene,0);

	term_log("+ brick");

	// Switch Desk
	if(!C->ui->show_sets) show_sets(C);

	if( node)
	{
		block = node->data;
		set = block->set;
		set_setup( set);
	}
		
	return NULL;
}
Esempio n. 6
0
static void start_worker_process(struct sandbox *sb, int slot)
{
	pid_t p;
	int filename_pipe[2];
	int result_pipe[2];
	int stream_pipe[2];

	if ( pipe(filename_pipe) == - 1 ) {
		ERROR("pipe() failed!\n");
		return;
	}

	if ( pipe(result_pipe) == - 1 ) {
		ERROR("pipe() failed!\n");
		return;
	}

	if ( pipe(stream_pipe) == - 1 ) {
		ERROR("pipe() failed!\n");
		return;
	}

	p = fork();
	if ( p == -1 ) {
		ERROR("fork() failed!\n");
		return;
	}

	if ( p == 0 ) {

		Stream *st;
		int j;
		struct sigaction sa;
		int r;
		char *tmp;
		struct stat s;
		size_t ll;

		/* First, disconnect the signal handler */
		sa.sa_flags = 0;
		sigemptyset(&sa.sa_mask);
		sa.sa_handler = SIG_DFL;
		r = sigaction(SIGCHLD, &sa, NULL);
		if ( r == -1 ) {
			ERROR("Failed to set signal handler!\n");
			return;
		}

		ll = 64 + strlen(sb->tmpdir);
		tmp = malloc(ll);
		if ( tmp == NULL ) {
			ERROR("Failed to allocate temporary dir\n");
			return;
		}

		snprintf(tmp, 63, "%s/worker.%i", sb->tmpdir, slot);

		if ( stat(tmp, &s) == -1 ) {
			if ( errno != ENOENT ) {
				ERROR("Failed to stat temporary folder.\n");
				return;
			}

			r = mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
			if ( r ) {
				ERROR("Failed to create temporary folder: %s\n",
				strerror(errno));
				return;
			}
		}

		/* Free resources which will not be needed by worker */
		for ( j=0; j<sb->n_proc; j++ ) {
			if ( (j != slot) && (sb->running[j]) ) {
				close(sb->stream_pipe_write[j]);
			}
		}
		for ( j=0; j<sb->n_proc; j++ ) {
			if ( (j != slot) && (sb->running[j]) ) {
				if ( sb->result_fhs[j] != NULL ) {
					fclose(sb->result_fhs[j]);
				}
				close(sb->filename_pipes[j]);
			}
		}
		free(sb->filename_pipes);
		free(sb->result_fhs);
		free(sb->pids);
		/* Also prefix, use_this_one_instead and fh */

		/* Child process gets the 'read' end of the filename
		 * pipe, and the 'write' end of the result pipe. */
		close(filename_pipe[1]);
		close(result_pipe[0]);

		st = open_stream_fd_for_write(stream_pipe[1]);
		run_work(sb->iargs, filename_pipe[0], result_pipe[1],
		         st, slot, tmp);
		close_stream(st);

		//close(filename_pipe[0]);
		close(result_pipe[1]);

		exit(0);

	}

	/* Parent process gets the 'write' end of the filename pipe
	 * and the 'read' end of the result pipe. */
	sb->pids[slot] = p;
	sb->running[slot] = 1;
	add_pipe(sb->reader, stream_pipe[0]);
	close(filename_pipe[0]);
	close(result_pipe[1]);
	close(stream_pipe[1]);
	sb->filename_pipes[slot] = filename_pipe[1];

	sb->result_fhs[slot] = fdopen(result_pipe[0], "r");
	if ( sb->result_fhs[slot] == NULL ) {
		ERROR("fdopen() failed.\n");
		return;
	}
}