[Libreoffice-commits] online.git: loolwsd/Exceptions.hpp loolwsd/TileCache.cpp loolwsd/TileCache.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun May 15 22:57:06 UTC 2016


 loolwsd/Exceptions.hpp |   10 ++++++++
 loolwsd/TileCache.cpp  |   50 ++++++++++++++++++++++++++++++++++++++++++++
 loolwsd/TileCache.hpp  |   55 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+), 1 deletion(-)

New commits:
commit 2b0347e391ecf769f36c3d5f1f586f445f63f10b
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun May 15 17:50:32 2016 -0400

    loolwsd: new tile descriptor class to represent tiles
    
    Change-Id: I680ea2d698a352bf3f99b37713d68c34d9502ea4
    Reviewed-on: https://gerrit.libreoffice.org/25019
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/Exceptions.hpp b/loolwsd/Exceptions.hpp
index 0384bde..eb2b4a6 100644
--- a/loolwsd/Exceptions.hpp
+++ b/loolwsd/Exceptions.hpp
@@ -21,7 +21,7 @@ protected:
     using std::runtime_error::runtime_error;
 };
 
-/// A bad-request exception that is means to signify,
+/// A bad-request exception that is meant to signify,
 /// and translate into, an HTTP bad request.
 class BadRequestException : public LoolException
 {
@@ -29,6 +29,14 @@ public:
     using LoolException::LoolException;
 };
 
+/// A bad-argument exception that is meant to signify,
+/// and translate into, an HTTP bad request.
+class BadArgumentException : public BadRequestException
+{
+public:
+    using BadRequestException::BadRequestException;
+};
+
 /// An authorization exception that is means to signify,
 /// and translate into, an HTTP unauthorized error.
 class UnauthorizedRequestException : public LoolException
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 5cdeeb5..a139490 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -44,6 +44,56 @@ using Poco::Timestamp;
 
 using namespace LOOLProtocol;
 
+std::string TileDesc::serialize(const std::string& prefix) const
+{
+    std::ostringstream oss;
+    oss << prefix
+        << " part=" << _part
+        << " width=" << _width
+        << " height=" << _height
+        << " tileposx=" << _tilePosX
+        << " tileposy=" << _tilePosY
+        << " tilewidth=" << _tileWidth
+        << " tileheight=" << _tileHeight;
+    if (_id >= 0)
+    {
+        oss << " id=" << _id;
+    }
+
+    return oss.str();
+}
+
+TileDesc TileDesc::parse(const Poco::StringTokenizer& tokens)
+{
+    // We don't expect undocument fields and
+    // assume all values to be int.
+    std::map<std::string, int> pairs;
+
+    // id is optional.
+    pairs["id"] = -1;
+
+    for (size_t i = 0; i < tokens.count(); ++i)
+    {
+        std::string name;
+        int value = -1;
+        if (parseNameIntegerPair(tokens[i], name, value))
+        {
+            pairs[name] = value;
+        }
+    }
+
+    return TileDesc(pairs["part"], pairs["width"], pairs["height"],
+                    pairs["tileposx"], pairs["tileposy"],
+                    pairs["tilewidth"], pairs["tileheight"],
+                    pairs["id"]);
+}
+
+TileDesc TileDesc::parse(const std::string& message)
+{
+    StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+    return parse(tokens);
+}
+
 TileCache::TileCache(const std::string& docURL,
                      const Timestamp& modifiedTime,
                      const std::string& cacheDir) :
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index 270d679..9afe4c6 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -18,12 +18,67 @@
 #include <vector>
 
 #include <Poco/Timestamp.h>
+#include <Poco/StringTokenizer.h>
+
+#include "Exceptions.hpp"
 
 /** Handles the cache for tiles of one document.
 */
 
 class MasterProcessSession;
 
+/// Tile Descriptor
+/// Represents a tile's coordinates and dimensions.
+class TileDesc
+{
+public:
+    TileDesc(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, int id = -1) :
+        _part(part),
+        _width(width),
+        _height(height),
+        _tilePosX(tilePosX),
+        _tilePosY(tilePosY),
+        _tileWidth(tileWidth),
+        _tileHeight(tileHeight),
+        _id(id)
+    {
+        if (_part < 0 ||
+            _width <= 0 ||
+            _height <= 0 ||
+            _tilePosX < 0 ||
+            _tilePosY < 0 ||
+            _tileWidth <= 0 ||
+            _tileHeight <= 0)
+        {
+            throw BadArgumentException("Invalid tile descriptor.");
+        }
+    }
+
+    int getPart() const { return _part; }
+    int getWidth() const { return _width; }
+    int getHeight() const { return _height; }
+    int getTilePosX() const { return _tilePosX; }
+    int getTilePosY() const { return _tilePosY; }
+    int getTileWidth() const { return _tileWidth; }
+    int getTileHeight() const { return _tileHeight; }
+
+    std::string serialize(const std::string& prefix = "") const;
+
+    /// Deserialize a TileDesc from a string format.
+    static TileDesc parse(const std::string& message);
+    static TileDesc parse(const Poco::StringTokenizer& tokens);
+
+private:
+    int _part;
+    int _width;
+    int _height;
+    int _tilePosX;
+    int _tilePosY;
+    int _tileWidth;
+    int _tileHeight;
+    int _id;
+};
+
 class TileCache
 {
     struct TileBeingRendered;


More information about the Libreoffice-commits mailing list