2015-03-12 09:18:35 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_TILECACHE_HPP
|
|
|
|
#define INCLUDED_TILECACHE_HPP
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <memory>
|
2015-06-24 15:05:49 -05:00
|
|
|
#include <set>
|
2015-05-05 06:57:51 -05:00
|
|
|
#include <string>
|
2015-03-12 09:18:35 -05:00
|
|
|
|
2015-05-29 04:23:57 -05:00
|
|
|
#include <Poco/File.h>
|
2015-03-12 18:34:42 -05:00
|
|
|
#include <Poco/Timestamp.h>
|
2015-08-12 07:31:02 -05:00
|
|
|
#include <Poco/Mutex.h>
|
|
|
|
|
|
|
|
using Poco::FastMutex;
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-06-24 15:05:49 -05:00
|
|
|
/** Handles the cache for tiles of one document.
|
|
|
|
|
|
|
|
The cache consists of 2 cache directories:
|
|
|
|
|
|
|
|
* persistent - that always represents the document as is saved
|
|
|
|
* editing - that represents the document in the current state (with edits)
|
|
|
|
|
|
|
|
The editing cache is cleared on startup, and copied to the persistent on each save.
|
|
|
|
*/
|
2015-03-12 18:34:42 -05:00
|
|
|
class TileCache
|
2015-03-12 09:18:35 -05:00
|
|
|
{
|
2015-03-12 18:34:42 -05:00
|
|
|
public:
|
2015-08-04 13:37:05 -05:00
|
|
|
/// When the docURL is a non-file:// url, the timestamp has to be provided by the caller.
|
|
|
|
/// For file:// url's, it's ignored.
|
|
|
|
/// When it is missing for non-file:// url, it is assumed the document must be read, and no cached value used.
|
|
|
|
TileCache(const std::string& docURL, const std::string& timestamp);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-04-27 13:24:05 -05:00
|
|
|
std::unique_ptr<std::fstream> lookupTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight);
|
|
|
|
void saveTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, const char *data, size_t size);
|
2015-08-18 13:01:05 -05:00
|
|
|
std::string getTextFile(std::string fileName);
|
2015-05-28 04:53:14 -05:00
|
|
|
|
2015-06-24 15:05:49 -05:00
|
|
|
/// Notify the cache that the document was saved - to copy tiles from the Editing cache to Persistent.
|
|
|
|
void documentSaved();
|
|
|
|
|
|
|
|
/// Notify whether we need to use the Editing cache.
|
|
|
|
void setEditing(bool editing = true);
|
|
|
|
|
2015-08-18 13:01:05 -05:00
|
|
|
// The parameter is a message
|
|
|
|
void saveTextFile(const std::string& text, std::string fileName);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-11-27 08:12:44 -06:00
|
|
|
// Saves a font / style / etc rendering
|
|
|
|
// The dir parameter should be the type of rendering, like "font", "style", etc
|
|
|
|
void saveRendering(const std::string& name, const std::string& dir, const char *data, size_t size);
|
|
|
|
|
|
|
|
std::unique_ptr<std::fstream> lookupRendering(const std::string& name, const std::string& dir);
|
|
|
|
|
2015-05-28 10:39:05 -05:00
|
|
|
// The tiles parameter is an invalidatetiles: message as sent by the child process
|
2015-07-21 06:53:53 -05:00
|
|
|
void invalidateTiles(const std::string& tiles);
|
2015-05-28 10:39:05 -05:00
|
|
|
|
|
|
|
void invalidateTiles(int part, int x, int y, int width, int height);
|
|
|
|
|
2015-03-12 18:34:42 -05:00
|
|
|
private:
|
2015-06-24 15:05:49 -05:00
|
|
|
/// Toplevel cache dirname.
|
|
|
|
std::string toplevelCacheDirName();
|
|
|
|
|
|
|
|
/// Path of the (sub-)cache dir, the parameter specifies which (sub-)cache to use.
|
|
|
|
std::string cacheDirName(bool useEditingCache);
|
|
|
|
|
2015-04-27 13:24:05 -05:00
|
|
|
std::string cacheFileName(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight);
|
2015-05-28 10:39:05 -05:00
|
|
|
bool parseCacheFileName(std::string& fileName, int& part, int& width, int& height, int& tilePosX, int& tilePosY, int& tileWidth, int& tileHeight);
|
2015-06-24 15:05:49 -05:00
|
|
|
|
|
|
|
/// Extract location from fileName, and check if it intersects with [x, y, width, height].
|
|
|
|
bool intersectsTile(std::string& fileName, int part, int x, int y, int width, int height);
|
|
|
|
|
2015-08-04 13:37:05 -05:00
|
|
|
/// Load the timestamp from modtime.txt.
|
2015-03-12 18:34:42 -05:00
|
|
|
Poco::Timestamp getLastModified();
|
2015-08-04 13:37:05 -05:00
|
|
|
|
|
|
|
/// Store the timestamp to modtime.txt.
|
|
|
|
void saveLastModified(const Poco::Timestamp& timestamp);
|
|
|
|
|
|
|
|
/// Create or cleanup the cache directory.
|
|
|
|
/// For non-file:// protocols, the timestamp has to be provided externally.
|
|
|
|
void setup(const std::string& timestamp);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
|
|
|
const std::string& _docURL;
|
2015-06-24 15:05:49 -05:00
|
|
|
|
|
|
|
/// The document is being edited.
|
|
|
|
bool _isEditing;
|
|
|
|
|
|
|
|
/// We have some unsaved changes => use the Editing cache.
|
|
|
|
bool _hasUnsavedChanges;
|
|
|
|
|
|
|
|
/// Set of tiles that we want to remove from the Persistent cache on the next save.
|
|
|
|
std::set<std::string> _toBeRemoved;
|
2015-08-12 07:31:02 -05:00
|
|
|
|
|
|
|
Poco::FastMutex _cacheMutex;
|
2015-03-12 09:18:35 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|