Ejemplo n.º 1
0
	/*
	 * Recursive foreach on nodes.
	 */
	int
	foreach_node(const nvobj::persistent_ptr<entry> e, callback clb,
		     void *arg)
	{
		int ret = 0;

		if (e->inode != nullptr) {
			auto n = e->inode;
			if (foreach_node(n->entries[0], clb, arg) == 0)
				foreach_node(n->entries[1], clb, arg);
		} else {
			ret = clb(e->key, e->value, arg);
		}

		return ret;
	}
Ejemplo n.º 2
0
	/**
	 * Call clb for each element in the tree.
	 *
	 * @param clb The callback to be called.
	 * @param args The arguments forwarded to the callback.
	 *
	 * @return 0 if tree empty, clb return value otherwise.
	 */
	int foreach (callback clb, void *args)
	{
		if (is_empty())
			return 0;

		return foreach_node(root, clb, args);
	}
Ejemplo n.º 3
0
static void ascii_draw(void)
{
	foreach_node(ascii_draw_node, NULL);

	if (c_quit_after > 0)
		if (--c_quit_after == 0)
			exit(0);
}
Ejemplo n.º 4
0
Archivo: raft.c Proyecto: jnpkrn/booth
inline static void clear_election(struct ticket_config *tk)
{
	int i;
	struct booth_site *site;

	tk_log_debug("clear election");
	tk->votes_received = 0;
	foreach_node(i, site)
		tk->votes_for[site->index] = NULL;
}
Ejemplo n.º 5
0
static void
print_content(void)
{
	int required_lines = 0, disable_detailed = 0, disabled_graphical = 0;

	if (NULL == get_current_node())
		return;

	if (c_list_in_list) {
		NEXT_ROW;
		putl("");

		if (c_use_colors)
			attrset(COLOR_PAIR(LAYOUT_HEADER) | layout[LAYOUT_HEADER].attr);
	
		NEXT_ROW;
		putl("  #   Tarjeta                RX Tasa         RX #   " \
			"  TX Tasa         TX #");
	
		NEXT_ROW;
		hline(ACS_HLINE, cols);

		if (c_combined_node_list)
			foreach_node(draw_node, NULL);
		else
			draw_node(get_current_node(), NULL);
	} else {
		NEXT_ROW;
		hline(ACS_HLINE, cols);
		move(row, 24);
		addstr(" Press l to enable list view ");
		move(row, 0);
	}

	/*
	 * calculate lines required for graphical and detailed stats unfolded
	 */
	if (c_graphical_in_list)
		required_lines += lines_required_for_graphical();
	else
		required_lines++;

	if (c_detailed_in_list)
		required_lines += lines_required_for_detailed();
	else
		required_lines++;

	if ((rows - row) <= (required_lines + 1)) {
		/*
		 * not enough lines, start over with detailed stats disabled
		 */
		required_lines = 0;
		disable_detailed = 1;

		/*
		 * 1 line for folded detailed stats display
		 */
		required_lines++;

		if (c_graphical_in_list)
			required_lines += lines_required_for_graphical();
		else
			required_lines++;

		if ((rows - row) <= (required_lines + 1)) {
			/*
			 * bad luck, not even enough space for graphical stats
			 * reserve 2 lines for displaying folded detailed and
			 * graphical stats
			 */
			required_lines = 2;
			disabled_graphical = 1;
		}
	}

	/*
	 * Clear out spare space
	 */
	while (row < (rows - (required_lines + 2))) {
		NEXT_ROW; putl("");
	}

	NEXT_ROW;
	hline(ACS_HLINE, cols);

	if (c_graphical_in_list) {
		if (disabled_graphical) {
			move(row, 15);
			addstr(" Increase screen size to see graphical statistics ");
			move(row, 0);
		} else
			draw_graphic();
	} else {
		move(row, 20);
		addstr(" Press g to enable graphical statistics ");
		move(row, 0);
	}

	NEXT_ROW;
	hline(ACS_HLINE, cols);

	if (c_detailed_in_list) {
		if (disable_detailed) {
			move(row, 15);
			addstr(" Increase screen size to see detailed statistics ");
			move(row, 0);
		} else
			draw_detailed();
	} else {
		move(row, 20);
		addstr(" Press d to enable detailed statistics ");
		move(row, 0);
	}
}