From: Pekka Riikonen Date: Sat, 6 Mar 2004 15:44:12 +0000 (+0000) Subject: Load the bitmap file only after connections has been X-Git-Tag: 1.2.beta1~800 X-Git-Url: http://git.silc.fi/gitweb/?a=commitdiff_plain;h=7916abc933cf6441904ef66425dcc42bb791503f;p=crypto.git Load the bitmap file only after connections has been processed. --- diff --git a/apps/silcmap/silcmap.h b/apps/silcmap/silcmap.h index b5fe8dd5..80b6140b 100644 --- a/apps/silcmap/silcmap.h +++ b/apps/silcmap/silcmap.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2003 Pekka Riikonen + Copyright (C) 2003 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -53,6 +53,7 @@ typedef struct { unsigned int lcolor_set : 1; /* Command */ + unsigned int loadmap : 1; unsigned int writemap : 1; unsigned int writehtml : 1; unsigned int writemaphtml : 1; @@ -75,13 +76,14 @@ typedef struct { /* Bitmap data */ unsigned char *bitmap; /* Loaded bitmap image */ - SilcUInt32 bitsilc_map_size; /* Size of bitmap */ + SilcUInt32 bitmap_size; /* Size of bitmap */ SilcUInt32 width; /* Bitmap width in pixels */ SilcUInt32 height; /* Bitmap height in pixels */ SilcUInt32 maxcolor; /* Max color value in bitmap */ MapFonts font; /* Current font */ /* Output methods */ + SilcMapCommandStruct loadmap; SilcMapCommandStruct writemap; SilcMapCommandStruct writehtml; SilcMapCommandStruct writerel; diff --git a/apps/silcmap/silcmap_bitmap.c b/apps/silcmap/silcmap_bitmap.c index 5f67b388..b05082c2 100644 --- a/apps/silcmap/silcmap_bitmap.c +++ b/apps/silcmap/silcmap_bitmap.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2003 Pekka Riikonen + Copyright (C) 2003 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -43,8 +43,10 @@ bool silc_map_load_ppm(SilcMap map, const char *filename) } /* Read width and height */ - ret = fscanf(fp, "%s %ld %ld %ld ", - type, &map->width, &map->height, &map->maxcolor); + ret = fscanf(fp, "%s %ld %ld %ld ", type, + (unsigned long *)&map->width, + (unsigned long *)&map->height, + (unsigned long *)&map->maxcolor); if (ret < 4) { fprintf(stderr, "Invalid PPM file"); retval = FALSE; @@ -52,9 +54,9 @@ bool silc_map_load_ppm(SilcMap map, const char *filename) } /* Read the picture */ - map->bitsilc_map_size = map->width * 3 * map->height; - map->bitmap = silc_malloc(map->bitsilc_map_size); - ret = fread(map->bitmap, map->bitsilc_map_size, 1, fp); + map->bitmap_size = map->width * 3 * map->height; + map->bitmap = silc_malloc(map->bitmap_size); + ret = fread(map->bitmap, map->bitmap_size, 1, fp); if (ret < 0) { fprintf(stderr, "fread: %s\n", strerror(errno)); retval = FALSE; @@ -72,7 +74,6 @@ bool silc_map_write_ppm(SilcMap map, const char *filename) { FILE *fp; int retval = TRUE; - int i, k; SILC_LOG_DEBUG(("Write PPM '%s'", filename)); @@ -83,10 +84,13 @@ bool silc_map_write_ppm(SilcMap map, const char *filename) } /* Write the header */ - fprintf(fp, "P6 %ld %ld %ld\n", map->width, map->height, map->maxcolor); + fprintf(fp, "P6 %ld %ld %ld\n", + (unsigned long)map->width, + (unsigned long)map->height, + (unsigned long)map->maxcolor); /* Write the bitmap */ - fwrite(map->bitmap, map->bitsilc_map_size, 1, fp); + fwrite(map->bitmap, map->bitmap_size, 1, fp); fclose(fp); return retval; @@ -106,11 +110,13 @@ bool silc_map_cut(SilcMap map, SilcInt32 x, SilcInt32 y, /* Sanity checks */ if (height > map->height - y) { - fprintf(stderr, "Requesting too much height: %ld\n", height); + fprintf(stderr, "Requesting too much height: %ld\n", + (unsigned long)height); return FALSE; } if (width > map->width - x) { - fprintf(stderr, "Requesting too much width: %ld\n", width); + fprintf(stderr, "Requesting too much width: %ld\n", + (unsigned long)width); return FALSE; } @@ -123,8 +129,8 @@ bool silc_map_cut(SilcMap map, SilcInt32 x, SilcInt32 y, (*ret_map)->width = width; (*ret_map)->height = height; (*ret_map)->maxcolor = map->maxcolor; - (*ret_map)->bitsilc_map_size = (width * 3) * height; - (*ret_map)->bitmap = silc_malloc((*ret_map)->bitsilc_map_size); + (*ret_map)->bitmap_size = (width * 3) * height; + (*ret_map)->bitmap = silc_malloc((*ret_map)->bitmap_size); /* Copy the requested area */ for (i = 0; i < height; i++) { diff --git a/apps/silcmap/silcmap_client.c b/apps/silcmap/silcmap_client.c index 86974f93..c605763c 100644 --- a/apps/silcmap/silcmap_client.c +++ b/apps/silcmap/silcmap_client.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2003 Pekka Riikonen + Copyright (C) 2003 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -41,125 +41,146 @@ void silc_map_process_data(SilcMap map, SilcMapConnection mapconn) SilcInt16 r, g, b, lr, lg, lb; int i; - map->conn_num++; SILC_LOG_DEBUG(("Processing the data from server (%d/%d)", map->conn_num, map->conns_num)); - /* Change colors according to server status */ - silc_map_parse_color(mapconn->up_color, &r, &g, &b); - silc_map_parse_color(mapconn->up_text_color, &lr, &lg, &lb); - if (mapconn->down) { - silc_map_parse_color(mapconn->down_color, &r, &g, &b); - silc_map_parse_color(mapconn->down_text_color, &lr, &lg, &lb); - } + map->conn_num++; + if (map->conn_num != map->conns_num) + return; - /* Execute the map commands */ - silc_dlist_start(mapconn->commands); - while ((cmd = silc_dlist_get(mapconn->commands)) != SILC_LIST_END) { - if (cmd->cut) { - if (silc_map_cut(map, cmd->x, cmd->y, cmd->width, - cmd->height, &ret_map)) { - silc_map_write_ppm(ret_map, cmd->filename); - silc_map_free(ret_map); - } - continue; + /* Load the map image to be processed */ + if (!map->bitmap) { + if (!map->loadmap.loadmap || !map->loadmap.filename) { + silc_schedule_task_add(map->client->schedule, 0, + silc_map_process_done, map, 0, 1, + SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); + return; } - if (cmd->draw_line) { - if (cmd->color_set) { - r = cmd->r; - g = cmd->g; - b = cmd->b; - } - silc_map_draw_line(map, cmd->width, cmd->x, cmd->y, cmd->x2, cmd->y2, - r, g, b); - continue; + if (!silc_map_load_ppm(map, map->loadmap.filename)) { + silc_schedule_task_add(map->client->schedule, 0, + silc_map_process_done, map, 0, 1, + SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); + return; } + } - if (cmd->draw_text) { - if (cmd->color_set) { - lr = cmd->r; - lg = cmd->g; - lb = cmd->b; - } - silc_map_draw_text(map, cmd->text, cmd->x, cmd->y, lr, lg, lb); + /* Now process all received data one by one */ + silc_dlist_start(map->conns); + while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) { - continue; + /* Change colors according to server status */ + silc_map_parse_color(mapconn->up_color, &r, &g, &b); + silc_map_parse_color(mapconn->up_text_color, &lr, &lg, &lb); + if (mapconn->down) { + silc_map_parse_color(mapconn->down_color, &r, &g, &b); + silc_map_parse_color(mapconn->down_text_color, &lr, &lg, &lb); } - if (cmd->draw_circle) { - if (cmd->color_set) { - r = cmd->r; - g = cmd->g; - b = cmd->b; + /* Execute the map commands */ + silc_dlist_start(mapconn->commands); + while ((cmd = silc_dlist_get(mapconn->commands)) != SILC_LIST_END) { + if (cmd->cut) { + if (silc_map_cut(map, cmd->x, cmd->y, cmd->width, + cmd->height, &ret_map)) { + silc_map_write_ppm(ret_map, cmd->filename); + silc_map_free(ret_map); + } + continue; } - if (cmd->lcolor_set) { - lr = cmd->lr; - lg = cmd->lg; - lb = cmd->lb; + + if (cmd->draw_line) { + if (cmd->color_set) { + r = cmd->r; + g = cmd->g; + b = cmd->b; + } + silc_map_draw_line(map, cmd->width, cmd->x, cmd->y, cmd->x2, cmd->y2, + r, g, b); + continue; + } + + if (cmd->draw_text) { + if (cmd->color_set) { + lr = cmd->r; + lg = cmd->g; + lb = cmd->b; + } + silc_map_draw_text(map, cmd->text, cmd->x, cmd->y, lr, lg, lb); + continue; } - silc_map_draw_circle(map, cmd->x, cmd->y, r, g, b, - cmd->text, cmd->lposx, cmd->lposy, lr, lg, lb); - continue; - } - if (cmd->draw_rectangle) { - if (cmd->color_set) { - r = cmd->r; - g = cmd->g; - b = cmd->b; + if (cmd->draw_circle) { + if (cmd->color_set) { + r = cmd->r; + g = cmd->g; + b = cmd->b; + } + if (cmd->lcolor_set) { + lr = cmd->lr; + lg = cmd->lg; + lb = cmd->lb; + } + silc_map_draw_circle(map, cmd->x, cmd->y, r, g, b, + cmd->text, cmd->lposx, cmd->lposy, lr, lg, lb); + continue; } - if (cmd->lcolor_set) { - lr = cmd->lr; - lg = cmd->lg; - lb = cmd->lb; + + if (cmd->draw_rectangle) { + if (cmd->color_set) { + r = cmd->r; + g = cmd->g; + b = cmd->b; + } + if (cmd->lcolor_set) { + lr = cmd->lr; + lg = cmd->lg; + lb = cmd->lb; + } + silc_map_draw_rectangle(map, cmd->x, cmd->y, r, g, b, + cmd->text, cmd->lposx, cmd->lposy, lr, lg, lb); + continue; } - silc_map_draw_rectangle(map, cmd->x, cmd->y, r, g, b, - cmd->text, cmd->lposx, cmd->lposy, lr, lg, lb); - continue; } + /* Write the html data file */ + if (map->writehtml.writehtml) + silc_map_writehtml(map, mapconn); + + /* Write uptime reliability data */ + if (map->writerel.writerel) + silc_map_writerel(map, mapconn); + } - /* Write the html data file */ - if (map->writehtml.writehtml) - silc_map_writehtml(map, mapconn); + SILC_LOG_DEBUG(("All connections processed")); - /* Write uptime reliability data */ - if (map->writerel.writerel) - silc_map_writerel(map, mapconn); - - /* If this was last connection, we are done and ready to quit. */ - if (map->conn_num == map->conns_num) { - SILC_LOG_DEBUG(("All connections processed")); - - /* Produce output */ - if (map->writemap.writemap) - silc_map_write_ppm(map, map->writemap.filename); - for (i = 0; i < map->cut_count; i++) { - if (silc_map_cut(map, map->cut[i].x, map->cut[i].y, map->cut[i].width, - map->cut[i].height, &ret_map)) { - silc_map_write_ppm(ret_map, map->cut[i].filename); - silc_map_free(ret_map); - } + /* Produce output */ + if (map->writemap.writemap) + silc_map_write_ppm(map, map->writemap.filename); + for (i = 0; i < map->cut_count; i++) { + if (silc_map_cut(map, map->cut[i].x, map->cut[i].y, map->cut[i].width, + map->cut[i].height, &ret_map)) { + silc_map_write_ppm(ret_map, map->cut[i].filename); + silc_map_free(ret_map); } + } - /* Write the HTML index file */ - if (map->writehtml.writehtml) - silc_map_writehtml_index(map); + /* Write the HTML index file */ + if (map->writehtml.writehtml) + silc_map_writehtml_index(map); - /* Write the HTML map file(s) */ - silc_map_writemaphtml(map); + /* Write the HTML map file(s) */ + silc_map_writemaphtml(map); - /* Write uptime reliability graph */ - if (map->writerel.writerel) - silc_map_writerelhtml(map); + /* Write uptime reliability graph */ + if (map->writerel.writerel) + silc_map_writerelhtml(map); - /* Schedule to stop */ - silc_schedule_task_add(map->client->schedule, 0, - silc_map_process_done, map, 0, 1, - SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); - } + /* Schedule to stop */ + silc_schedule_task_add(map->client->schedule, 0, + silc_map_process_done, map, 0, 1, + SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); } /* Timeout callback to detect if server is down. */ diff --git a/apps/silcmap/silcmap_command.c b/apps/silcmap/silcmap_command.c index 2fcecaee..ef548a4d 100644 --- a/apps/silcmap/silcmap_command.c +++ b/apps/silcmap/silcmap_command.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2003 Pekka Riikonen + Copyright (C) 2003 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -368,10 +368,17 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_loadmap) /* Destroy old bitmap if loadmaped */ silc_free(map->bitmap); + map->bitmap = NULL; - /* Loadmap the bitmap image */ - if (!silc_map_load_ppm(map, filename)) - retval = SILC_CONFIG_ESILENT; + /* Execute directly if there are no connections */ + if (map->conns_num == 0) { + /* Load the bitmap image */ + if (!silc_map_load_ppm(map, filename)) + retval = SILC_CONFIG_ESILENT; + } else { + map->loadmap.filename = strdup(filename); + map->loadmap.writemap = TRUE; + } /* Cleanup */ silc_free(filename); @@ -650,7 +657,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_rectangle) } /* Execute directly if not for connection */ - if (!curr_conn) { + if (!curr_conn && map->bitmap) { /* Draw the rectangle */ ret = silc_map_draw_rectangle(map, silc_map_lon2x(map, lon), silc_map_lat2y(map, lat), @@ -740,7 +747,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_circle) } /* Execute directly if not for connection */ - if (!curr_conn) { + if (!curr_conn && map->bitmap) { /* Draw the circle */ ret = silc_map_draw_circle(map, silc_map_lon2x(map, lon), silc_map_lat2y(map, lat), @@ -828,7 +835,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_line) width = 1; /* Execute directly if not for connection */ - if (!curr_conn) { + if (!curr_conn && map->bitmap) { /* Draw the line */ ret = silc_map_draw_line(map, width, silc_map_lon2x(map, lon), @@ -907,7 +914,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_text) lat, lon, r, g, b, text)); /* Execute directly if not for connection */ - if (!curr_conn) { + if (!curr_conn && map->bitmap) { /* Print the text */ ret = silc_map_draw_text(map, text, silc_map_lon2x(map, lon), @@ -985,7 +992,7 @@ bool silc_map_commands_parse(SilcMap map, const char *filename) SILC_LOG_DEBUG(("Parsing status: %s", silc_config_strerror(ret))); if (ret && ret != SILC_CONFIG_ESILENT) { - fprintf(stderr, "Error parsing commands: %s, line %ld\n", + fprintf(stderr, "Error parsing commands: %s, line %d\n", silc_config_strerror(ret), silc_config_get_line(file)); retval = FALSE; } diff --git a/apps/silcmap/silcmap_html.c b/apps/silcmap/silcmap_html.c index f6c56aef..f565fcaa 100644 --- a/apps/silcmap/silcmap_html.c +++ b/apps/silcmap/silcmap_html.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2003 Pekka Riikonen + Copyright (C) 2003 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -215,67 +215,67 @@ bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn) if (mapconn->clients) { fprintf(fp, "  "); fprintf(fp, "Local clients : %ld\n", - mapconn->data.clients); + (unsigned long)mapconn->data.clients); } if (mapconn->channels) { fprintf(fp, "  "); fprintf(fp, "Local channels : %ld\n", - mapconn->data.channels); + (unsigned long)mapconn->data.channels); } if (mapconn->server_ops) { fprintf(fp, "  "); fprintf(fp, "Local server operators : %ld\n", - mapconn->data.server_ops); + (unsigned long)mapconn->data.server_ops); } if (mapconn->router_ops) { fprintf(fp, "  "); fprintf(fp, "Local router operators : %ld\n", - mapconn->data.router_ops); + (unsigned long)mapconn->data.router_ops); } if (mapconn->cell_clients) { fprintf(fp, "  "); fprintf(fp, "Cell clients : %ld\n", - mapconn->data.cell_clients); + (unsigned long)mapconn->data.cell_clients); } if (mapconn->cell_channels) { fprintf(fp, "  "); fprintf(fp, "Cell channels : %ld\n", - mapconn->data.cell_channels); + (unsigned long)mapconn->data.cell_channels); } if (mapconn->cell_servers) { fprintf(fp, "  "); fprintf(fp, "Cell servers : %ld\n", - mapconn->data.cell_servers); + (unsigned long)mapconn->data.cell_servers); } if (mapconn->all_clients) { fprintf(fp, "  "); fprintf(fp, "All SILC clients : %ld\n", - mapconn->data.all_clients); + (unsigned long)mapconn->data.all_clients); } if (mapconn->all_channels) { fprintf(fp, "  "); fprintf(fp, "All SILC channels : %ld\n", - mapconn->data.all_channels); + (unsigned long)mapconn->data.all_channels); } if (mapconn->all_servers) { fprintf(fp, "  "); fprintf(fp, "All SILC servers : %ld\n", - mapconn->data.all_servers); + (unsigned long)mapconn->data.all_servers); } if (mapconn->all_routers) { fprintf(fp, "  "); fprintf(fp, "All SILC routers : %ld\n", - mapconn->data.all_routers); + (unsigned long)mapconn->data.all_routers); } if (mapconn->all_server_ops) { fprintf(fp, "  "); fprintf(fp, "All SILC server operators : %ld\n", - mapconn->data.all_server_ops); + (unsigned long)mapconn->data.all_server_ops); } if (mapconn->all_router_ops) { fprintf(fp, "  "); fprintf(fp, "All SILC router operators : %ld\n", - mapconn->data.all_router_ops); + (unsigned long)mapconn->data.all_router_ops); } fprintf(fp, "\n"); }