static void show_color(MBLOCK *mblk, int col_id) { int save_win_id; char *label; int colornamecount; char **arraydata; int win_id = mblk->info->colorwin_id; int block_id = mblk->info->colorblock_id; int array_id = mblk->info->colorarray_id; g_push_gc(); save_win_id=g_get_windownr(); g_select_window(win_id); g_delete_object(mblk->spar[S_COLORMAP].obj_id+1); g_open_object(mblk->spar[S_COLORMAP].obj_id+1); g_select_viewport(mblk->spar[S_COLORMAP].vp_id); g_set_foreground(col_id); g_fillrectangle(0,MAXROW,MAXCOLUMN,MAXROW+1); g_moveto(0.2,MAXROW+0.2); if (col_id == G_WHITE ) g_set_foreground(G_BLACK); else g_set_foreground(G_WHITE); g_set_font(G_FONT_HELVETICA_BOLD,G_RELATIVE_FONTSCALING); g_set_charsize(1.0); arraydata = psnd_get_colornames(&colornamecount); label = psnd_sprintf_temp("Block%d:%s:Color=%d", block_id+1, arraydata[array_id], col_id); g_label(label); g_close_object(mblk->spar[S_COLORMAP].obj_id+1); g_call_object(mblk->spar[S_COLORMAP].obj_id+1); g_flush(); g_pop_gc(); g_select_window(save_win_id); }
/* * Thread reads from or writes to local component and also handles DELETE and * FLUSH requests. */ static void * disk_thread(void *arg) { struct hast_resource *res = arg; struct hio *hio; ssize_t ret; bool clear_activemap, logerror; clear_activemap = true; for (;;) { pjdlog_debug(2, "disk: Taking request."); QUEUE_TAKE(disk, hio); while (clear_activemap) { unsigned char *map; size_t mapsize; /* * When first request is received, it means that primary * already received our activemap, merged it and stored * locally. We can now safely clear our activemap. */ mapsize = activemap_calc_ondisk_size(res->hr_local_mediasize - METADATA_SIZE, res->hr_extentsize, res->hr_local_sectorsize); map = calloc(1, mapsize); if (map == NULL) { pjdlog_warning("Unable to allocate memory to clear local activemap."); break; } if (pwrite(res->hr_localfd, map, mapsize, METADATA_SIZE) != (ssize_t)mapsize) { pjdlog_errno(LOG_WARNING, "Unable to store cleared activemap"); free(map); break; } free(map); clear_activemap = false; pjdlog_debug(1, "Local activemap cleared."); break; } reqlog(LOG_DEBUG, 2, -1, hio, "disk: (%p) Got request: ", hio); logerror = true; /* Handle the actual request. */ switch (hio->hio_cmd) { case HIO_READ: ret = pread(res->hr_localfd, hio->hio_data, hio->hio_length, hio->hio_offset + res->hr_localoff); if (ret < 0) hio->hio_error = errno; else if (ret != (int64_t)hio->hio_length) hio->hio_error = EIO; else hio->hio_error = 0; break; case HIO_WRITE: ret = pwrite(res->hr_localfd, hio->hio_data, hio->hio_length, hio->hio_offset + res->hr_localoff); if (ret < 0) hio->hio_error = errno; else if (ret != (int64_t)hio->hio_length) hio->hio_error = EIO; else hio->hio_error = 0; break; case HIO_DELETE: ret = g_delete(res->hr_localfd, hio->hio_offset + res->hr_localoff, hio->hio_length); if (ret < 0) hio->hio_error = errno; else hio->hio_error = 0; break; case HIO_FLUSH: if (!res->hr_localflush) { ret = -1; hio->hio_error = EOPNOTSUPP; logerror = false; break; } ret = g_flush(res->hr_localfd); if (ret < 0) { if (errno == EOPNOTSUPP) res->hr_localflush = false; hio->hio_error = errno; } else { hio->hio_error = 0; } break; default: PJDLOG_ABORT("Unexpected command (cmd=%hhu).", hio->hio_cmd); } if (logerror && hio->hio_error != 0) { reqlog(LOG_ERR, 0, hio->hio_error, hio, "Request failed: "); } pjdlog_debug(2, "disk: (%p) Moving request to the send queue.", hio); QUEUE_INSERT(send, hio); } /* NOTREACHED */ return (NULL); }
/* * Display the color map in a window */ void psnd_show_colormap(MBLOCK *mblk, int numcol) { float x0,y0,dx,dy,box_height,box_width; int nx,ny,win_id, save_win_id,bar_id; char string[5]; int i,ix,iy,color=0; int colornamecount; char **arraydata; if (mblk->info->colorwin_id) { g_raise_window(mblk->info->colorwin_id); return; } arraydata = psnd_get_colornames(&colornamecount); box_width = 60.0; box_height = 30.0; nx = sqrt(numcol); if (nx>MAXCOLUMN) nx=MAXCOLUMN; ny = numcol/nx; if (nx*ny < numcol) ny++; x0 = 0.0; y0 = 0.0; dx = box_width*(nx); dy = box_height*(ny); g_push_gc(); save_win_id=g_get_windownr(); mblk->info->colorwin_id = g_open_window(G_SCREEN, x0, y0, dx, dy, "Colormap", G_WIN_BUFFER| G_WIN_BUTTONBAR2); /* g_popup_follow_cursor(TRUE); */ g_delete_object(mblk->spar[S_COLORMAP].obj_id); g_open_object(mblk->spar[S_COLORMAP].obj_id); g_set_viewport(mblk->spar[S_COLORMAP].vp_id, 0, 0, 1, 1); g_set_world(mblk->spar[S_COLORMAP].vp_id, 0, 0, nx+0.01, 1+ny+0.01); g_select_viewport(mblk->spar[S_COLORMAP].vp_id); g_set_clipping(FALSE); g_set_font(G_FONT_HELVETICA_BOLD,G_RELATIVE_FONTSCALING); g_set_charsize(1.0); for (iy=0;iy<ny;iy++) { for(ix=0;ix<nx;ix++) { g_set_foreground(color); g_fillrectangle(ix,ny-iy-1,ix+1,ny-iy); g_moveto((float)ix+0.25,(float)(ny-iy-1)+0.25); if ((color%(numcol)) == G_WHITE ) g_set_foreground(G_BLACK); else g_set_foreground(G_WHITE); sprintf(string,"%d",color); g_label(string); color++; } } g_close_object(mblk->spar[S_COLORMAP].obj_id); g_call_object(mblk->spar[S_COLORMAP].obj_id); bar_id = g_menu_create_buttonbox2(mblk->info->colorwin_id, 1); mblk->info->colorbar_id = bar_id; g_menu_append_button(bar_id, "Quit", COL_QUIT); g_menu_append_button(bar_id, "Reset", COL_DEF); g_menu_append_button(bar_id, "Save", COL_WRITE); g_menu_append_button(bar_id, "Retrieve", COL_READ); #ifdef _WIN32 g_menu_append_button(bar_id, "Item", COL_ITEM); #else { char *data[MAX_BLOCK] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }; assert(mblk->info->colorblock_id <= 12); g_menu_append_optionmenu(bar_id, "Block", COL_BLOCK, MAXBLK, mblk->info->colorblock_id, data); } g_menu_append_optionmenu(bar_id, "Item", COL_ARRAY, colornamecount, mblk->info->colorarray_id, arraydata); #endif g_menu_create_buttonbox2(mblk->info->colorwin_id, -1); g_flush(); g_pop_gc(); g_select_window(save_win_id); color = psnd_get_colorvalue(mblk,mblk->info->colorarray_id, mblk->info->colorblock_id); show_color(mblk, color); }