static int _init_button_processor(button_processor_t *button_processor, int node_count) { int *dim_size = NULL; if (node_count == 0) { g_print("_init_button_processor: no nodes selected\n"); return SLURM_ERROR; } memset(button_processor, 0, sizeof(button_processor_t)); if (cluster_dims > 1) { dim_size = _get_cluster_dims(); if (dim_size == NULL) { g_error("could not read dim_size\n"); return SLURM_ERROR; } } if (cluster_dims == 4) { button_processor->default_y_offset = (dim_size[3] * dim_size[2]) + (dim_size[2] - dim_size[3]); working_sview_config.grid_x_width = (dim_size[1] + dim_size[3]) * dim_size[0]; button_processor->table_y = (dim_size[3] * dim_size[2]) + dim_size[2]; } else if (cluster_dims == 3) { button_processor->default_y_offset = (dim_size[2] * dim_size[1]) + (dim_size[1] - dim_size[2]); working_sview_config.grid_x_width = dim_size[0] + dim_size[2]; button_processor->table_y = (dim_size[2] * dim_size[1]) + dim_size[1]; } else { if (!working_sview_config.grid_x_width) { if (node_count < 50) { working_sview_config.grid_x_width = 1; } else if (node_count < 500) { working_sview_config.grid_x_width = 10; } else { working_sview_config.grid_x_width = 20; } } button_processor->table_y = (node_count / working_sview_config.grid_x_width) + 1; } button_processor->force_row_break = FALSE; return SLURM_SUCCESS; }
/* Add a button for a given node. If node_ptr == NULL then fill in any gaps * in the grid just for a clean look. Always call with node_ptr == NULL for * the last call in the sequence. */ static int _add_button_to_list(node_info_t *node_ptr, button_processor_t *button_processor) { static bool *node_exists = NULL; static int node_exists_cnt = 1; grid_button_t *grid_button = button_processor->grid_button; int *dim_size = NULL, i, coord_x = 0, coord_y = 0; int len = 0, len_a = 0; if (cluster_dims > 1) { dim_size = _get_cluster_dims(); if (dim_size == NULL) { g_error("Could not read dim_size\n"); return SLURM_ERROR; } if ((dim_size[0] < 1) || (cluster_dims < 1)) { g_error("Invalid dim_size %d or cluster_dims %d\n", dim_size[0], cluster_dims); return SLURM_ERROR; } /* Translate a 3D or 4D space into a 2D space to the extent * possible. */ if (node_exists == NULL) { node_exists_cnt = 1; for (i = 0; i < cluster_dims; i++) node_exists_cnt *= dim_size[i]; node_exists = xmalloc(sizeof(bool) * node_exists_cnt); } if (node_ptr) { len = strlen(node_ptr->name); if (len < cluster_dims) { g_error("bad node name %s\n", node_ptr->name); return SLURM_ERROR; } if (cluster_flags & CLUSTER_FLAG_CRAY_A) { len_a = strlen(node_ptr->node_addr); if (len_a < cluster_dims) { g_error("bad node addr %s\n", node_ptr->node_addr); return SLURM_ERROR; } } } } if (cluster_dims == 3) { int x, y, z; if (node_ptr) { if (cluster_flags & CLUSTER_FLAG_CRAY_A) { x = select_char2coord( node_ptr->node_addr[len_a-3]); y = select_char2coord( node_ptr->node_addr[len_a-2]); z = select_char2coord( node_ptr->node_addr[len_a-1]); } else { x = select_char2coord(node_ptr->name[len-3]); y = select_char2coord(node_ptr->name[len-2]); z = select_char2coord(node_ptr->name[len-1]); } i = (x * dim_size[1] + y) * dim_size[2] + z; node_exists[i] = true; _calc_coord_3d(x, y, z, button_processor->default_y_offset, &coord_x, &coord_y, dim_size); } else { for (x = 0; x < dim_size[0]; x++) { for (y = 0; y < dim_size[1]; y++) { for (z = 0; z < dim_size[2]; z++) { i = (x * dim_size[1] + y) * dim_size[2] + z; if (node_exists[i]) continue; _calc_coord_3d(x, y, z, button_processor-> default_y_offset, &coord_x, &coord_y, dim_size); _build_empty_node( coord_x, coord_y, button_processor); } } } xfree(node_exists); return SLURM_SUCCESS; } } if (node_ptr == NULL) return SLURM_SUCCESS; if (cluster_dims > 1) { (*button_processor->coord_x) = coord_x; (*button_processor->coord_y) = coord_y; #if 0 g_print("%s %d:%d\n", node_ptr->name, coord_x, coord_y); #endif } if (!grid_button) { grid_button = xmalloc(sizeof(grid_button_t)); grid_button->color_inx = MAKE_INIT; grid_button->inx = (*button_processor->inx); grid_button->table = button_processor->table; grid_button->table_x = (*button_processor->coord_x); grid_button->table_y = (*button_processor->coord_y); grid_button->button = gtk_button_new(); grid_button->node_name = xstrdup(node_ptr->name); gtk_widget_set_size_request(grid_button->button, working_sview_config.button_size, working_sview_config.button_size); _add_button_signals(grid_button); list_append(button_processor->button_list, grid_button); gtk_table_attach(button_processor->table, grid_button->button, (*button_processor->coord_x), ((*button_processor->coord_x)+1), (*button_processor->coord_y), ((*button_processor->coord_y)+1), GTK_SHRINK, GTK_SHRINK, 1, 1); } else { grid_button->table_x = (*button_processor->coord_x); grid_button->table_y = (*button_processor->coord_y); gtk_container_child_set( GTK_CONTAINER(button_processor->table), grid_button->button, "left-attach", (*button_processor->coord_x), "right-attach", ((*button_processor->coord_x)+1), "top-attach", (*button_processor->coord_y), "bottom-attach", ((*button_processor->coord_y)+1), NULL); } /* gtk_container_add(GTK_CONTAINER(grid_button->frame), */ /* grid_button->button); */ /* gtk_frame_set_shadow_type(GTK_FRAME(grid_button->frame), */ /* GTK_SHADOW_ETCHED_OUT); */ if (cluster_dims < 3) { /* On linear systems we just up the x_coord until we hit the * side of the table and then increment the coord_y. We add * space between each tenth row. */ (*button_processor->coord_x)++; if (button_processor->force_row_break) { (*button_processor->coord_x) = 0; (*button_processor->coord_y)++; gtk_table_set_row_spacing( button_processor->table, (*button_processor->coord_y)-1, working_sview_config.gap_size); return SLURM_SUCCESS; } if ((*button_processor->coord_x) == working_sview_config.grid_x_width) { (*button_processor->coord_x) = 0; (*button_processor->coord_y)++; if (!((*button_processor->coord_y) % working_sview_config.grid_vert)) gtk_table_set_row_spacing( button_processor->table, (*button_processor->coord_y)-1, working_sview_config.gap_size); } if ((*button_processor->coord_y) == button_processor->table_y) return SLURM_SUCCESS; if ((*button_processor->coord_x) && !((*button_processor->coord_x) % working_sview_config.grid_hori)) gtk_table_set_col_spacing( button_processor->table, (*button_processor->coord_x)-1, working_sview_config.gap_size); } return SLURM_SUCCESS; }