pstcache.c revision a180a41bba1d50822df23fff0099e90b86638b89
a180a41bba1d50822df23fff0099e90b86638b89vboxsync/* -*- c-basic-offset: 8 -*-
a180a41bba1d50822df23fff0099e90b86638b89vboxsync rdesktop: A Remote Desktop Protocol client.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync Persistent Bitmap Cache routines
a180a41bba1d50822df23fff0099e90b86638b89vboxsync Copyright (C) Jeroen Meijer <jeroen@oldambt7.com> 2004-2008
a180a41bba1d50822df23fff0099e90b86638b89vboxsync This program is free software: you can redistribute it and/or modify
a180a41bba1d50822df23fff0099e90b86638b89vboxsync it under the terms of the GNU General Public License as published by
a180a41bba1d50822df23fff0099e90b86638b89vboxsync the Free Software Foundation, either version 3 of the License, or
a180a41bba1d50822df23fff0099e90b86638b89vboxsync (at your option) any later version.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync This program is distributed in the hope that it will be useful,
a180a41bba1d50822df23fff0099e90b86638b89vboxsync but WITHOUT ANY WARRANTY; without even the implied warranty of
a180a41bba1d50822df23fff0099e90b86638b89vboxsync MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a180a41bba1d50822df23fff0099e90b86638b89vboxsync GNU General Public License for more details.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync You should have received a copy of the GNU General Public License
a180a41bba1d50822df23fff0099e90b86638b89vboxsync along with this program. If not, see <http://www.gnu.org/licenses/>.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#define IS_PERSISTENT(id) (id < 8 && g_pstcache_fd[id] > 0)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync/* Update mru stamp/index for a bitmap */
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncpstcache_touch_bitmap(uint8 cache_id, uint16 cache_idx, uint32 stamp)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync rd_lseek_file(fd, 12 + cache_idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync/* Load a bitmap from the persistent cache */
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncpstcache_load_bitmap(uint8 cache_id, uint16 cache_idx)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync rd_lseek_file(fd, cache_idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync bitmap = ui_create_bitmap(cellhdr.width, cellhdr.height, celldata);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync DEBUG(("Load bitmap from disk: id=%d, idx=%d, bmp=%p)\n", cache_id, cache_idx, bitmap));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync/* Store a bitmap in the persistent cache */
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncpstcache_save_bitmap(uint8 cache_id, uint16 cache_idx, uint8 * key,
a180a41bba1d50822df23fff0099e90b86638b89vboxsync uint8 width, uint8 height, uint16 length, uint8 * data)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync rd_lseek_file(fd, cache_idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync/* List the bitmap keys from the persistent cache file */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (!(g_bitmap_cache && g_bitmap_cache_persist_enable && IS_PERSISTENT(id)))
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* The server disconnects if the bitmap cache content is sent more than once */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync DEBUG_RDP5(("Persistent bitmap cache enumeration... "));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync rd_lseek_file(fd, idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (rd_read_file(fd, &cellhdr, sizeof(CELLHEADER)) <= 0)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (memcmp(cellhdr.key, zero_key, sizeof(HASH_KEY)) != 0)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync memcpy(keylist[idx], cellhdr.key, sizeof(HASH_KEY));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Pre-cache (not possible for 8 bit colour depth cause it needs a colourmap) */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (g_bitmap_cache_precache && cellhdr.stamp && g_server_depth > 8)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Sort by stamp */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync for (n = idx; n > 0 && cellhdr.stamp < mru_stamp[n - 1]; n--)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync cache_rebuild_bmpcache_linked_list(id, mru_idx, idx);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync/* initialise the persistent bitmap cache */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (!(g_bitmap_cache && g_bitmap_cache_persist_enable))
a180a41bba1d50822df23fff0099e90b86638b89vboxsync sprintf(filename, "cache/pstcache_%d_%d", cache_id, g_pstcache_Bpp);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync DEBUG(("persistent bitmap cache file: %s\n", filename));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync warning("Persistent bitmap caching is disabled. (The file is already in use)\n");