loolwsd/TileCache.cpp          |    2 +
 loolwsd/Unit.cpp               |   15 ++++++++++++
 loolwsd/Unit.hpp               |   16 +++++++++++++
 loolwsd/test/Makefile.am       |    5 ++--
 loolwsd/test/UnitTileCache.cpp |   49 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 85 insertions(+), 2 deletions(-)

New commits:
commit d16f44d7a223841a2db9929a8245fd97851502bb
Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
Date:   Sun May 1 10:24:31 2016 -0400

    loolwsd: TileCache unittest, hooks, and events
    
    Change-Id: Id9e0539d2f920f15b0d0cb8e5924e480ed6d1e87
    Reviewed-on: https://gerrit.libreoffice.org/24570
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>

diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index c02eb7e..39bc587 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -34,6 +34,7 @@
 #include "TileCache.hpp"
 #include "Util.hpp"
 #include "MasterProcessSession.hpp"
+#include "Unit.hpp"
 
 using Poco::DirectoryIterator;
 using Poco::File;
@@ -107,6 +108,7 @@ std::unique_ptr<std::fstream> TileCache::lookupTile(int 
part, int width, int hei
     const std::string fileName = _cacheDir + "/" + cacheFileName(part, width, 
height, tilePosX, tilePosY, tileWidth, tileHeight);
 
     std::unique_ptr<std::fstream> result(new std::fstream(fileName, 
std::ios::in));
+    UnitWSD::get().lookupTile(part, width, height, tilePosX, tilePosY, 
tileWidth, tileHeight, result);
     if (result && result->is_open())
     {
         Log::trace("Found cache tile: " + fileName);
diff --git a/loolwsd/Unit.cpp b/loolwsd/Unit.cpp
index 1c4f5fa..b8661a4 100644
--- a/loolwsd/Unit.cpp
+++ b/loolwsd/Unit.cpp
@@ -10,6 +10,8 @@
 #include <dlfcn.h>
 #include <ftw.h>
 #include <cassert>
+#include <fstream>
+
 #include "Util.hpp"
 #include "Unit.hpp"
 
@@ -126,6 +128,19 @@ UnitWSD::~UnitWSD()
 {
 }
 
+void UnitWSD::lookupTile(int part, int width, int height, int tilePosX, int 
tilePosY,
+                         int tileWidth, int tileHeight, 
std::unique_ptr<std::fstream>& cacheFile)
+{
+    if (cacheFile && cacheFile->is_open())
+    {
+        onTileCacheHit(part, width, height, tilePosX, tilePosY, tileWidth, 
tileHeight);
+    }
+    else
+    {
+        onTileCacheMiss(part, width, height, tilePosX, tilePosY, tileWidth, 
tileHeight);
+    }
+}
+
 UnitKit::UnitKit()
 {
 }
diff --git a/loolwsd/Unit.hpp b/loolwsd/Unit.hpp
index 05d5696..6dc3045 100644
--- a/loolwsd/Unit.hpp
+++ b/loolwsd/Unit.hpp
@@ -133,12 +133,28 @@ public:
                      Poco::Net::HTTPServerResponse& /* response */)
         { return false; }
 
+    // ---------------- TileCache hooks ----------------
+    /// Called before the lookupTile call returns. Should always be called to 
fire events.
+    virtual void lookupTile(int part, int width, int height, int tilePosX, int 
tilePosY,
+                            int tileWidth, int tileHeight, 
std::unique_ptr<std::fstream>& cacheFile);
+
     // ---------------- WSD events ----------------
     virtual void onChildConnected(const int /* pid */, const std::string& /* 
sessionId */) {}
     /// When admin notify message is sent
     virtual void onAdminNotifyMessage(const std::string& /* message */) {}
     /// When admin message is sent in response to a query
     virtual void onAdminQueryMessage(const std::string& /* message */) {}
+
+    // ---------------- TileCache events ----------------
+    virtual void onTileCacheHit(int /*part*/, int /*width*/, int /*height*/,
+                                int /*tilePosX*/, int /*tilePosY*/,
+                                int /*tileWidth*/, int /*tileHeight*/) {}
+    virtual void onTileCacheMiss(int /*part*/, int /*width*/, int /*height*/,
+                                 int /*tilePosX*/, int /*tilePosY*/,
+                                 int /*tileWidth*/, int /*tileHeight*/) {}
+    virtual void onTileCacheSubscribe(int /*part*/, int /*width*/, int 
/*height*/,
+                                      int /*tilePosX*/, int /*tilePosY*/,
+                                      int /*tileWidth*/, int /*tileHeight*/) {}
 };
 
 /// Derive your Kit unit test / hooks from me.
diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am
index 7b64b9d..5ec0722 100644
--- a/loolwsd/test/Makefile.am
+++ b/loolwsd/test/Makefile.am
@@ -7,7 +7,7 @@ AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
 noinst_LTLIBRARIES = \
         unit-timeout.la unit-prefork.la \
         unit-storage.la unit-fonts.la \
-        unit-admin.la
+        unit-admin.la unit-tilecache.la
 
 MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy
 AM_LDFLAGS = -pthread -module $(MAGIC_TO_FORCE_SHLIB_CREATION)
@@ -24,6 +24,7 @@ unit_fonts_la_SOURCES = UnitFonts.cpp
 unit_timeout_la_SOURCES = UnitTimeout.cpp
 unit_prefork_la_SOURCES = UnitPrefork.cpp
 unit_storage_la_SOURCES = UnitStorage.cpp
+unit_tilecache_la_SOURCES = UnitTileCache.cpp
 
 if HAVE_LO_PATH
 SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp
@@ -34,7 +35,7 @@ endif
 if HAVE_LO_PATH
 check-local:
        ./run_unit.sh --log-file test.log --trs-file test.trs
-TESTS = unit-admin.la unit-timeout.la unit-fonts.la unit-storage.la 
unit-prefork.la
+TESTS = unit-tilecache.la unit-admin.la unit-timeout.la unit-fonts.la 
unit-storage.la unit-prefork.la
 else
 TESTS = ${top_builddir}/test/test
 endif
diff --git a/loolwsd/test/UnitTileCache.cpp b/loolwsd/test/UnitTileCache.cpp
new file mode 100644
index 0000000..6ebf377
--- /dev/null
+++ b/loolwsd/test/UnitTileCache.cpp
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#include <dlfcn.h>
+#include <ftw.h>
+#include <cassert>
+#include <iostream>
+#include <fstream>
+
+#include "Util.hpp"
+#include "Unit.hpp"
+#include "UnitHTTP.hpp"
+
+class UnitTileCache: public UnitWSD
+{
+public:
+    virtual void lookupTile(int part, int width, int height, int tilePosX, int 
tilePosY,
+                            int tileWidth, int tileHeight, 
std::unique_ptr<std::fstream>& cacheFile)
+    {
+        // Call base to fire events.
+        UnitWSD::lookupTile(part, width, height, tilePosX, tilePosY, 
tileWidth, tileHeight, cacheFile);
+
+        // Fail the lookup to force subscription and rendering.
+        cacheFile.reset();
+    }
+
+    virtual void invokeTest()
+    {
+        // FIXME: push through to the right place to exercise this.
+        exitTest(TestResult::TEST_OK);
+        UnitHTTPServerResponse response;
+        UnitHTTPServerRequest request(response, std::string(CHILD_URI));
+        UnitWSD::testHandleRequest(TestRequest::TEST_REQ_PRISONER,
+                                   request, response);
+    }
+};
+
+UnitBase *unit_create_wsd(void)
+{
+    return new UnitTileCache();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to