[Libreoffice-commits] online.git: 2 commits - loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp loolwsd/TileCache.cpp

Tor Lillqvist tml at collabora.com
Thu May 28 22:50:16 PDT 2015


 loolwsd/LOOLSession.cpp |   26 +++++++++---------
 loolwsd/LOOLWSD.cpp     |   18 +++++++-----
 loolwsd/TileCache.cpp   |   67 ++++++++++++++++++++++++++++++------------------
 3 files changed, 66 insertions(+), 45 deletions(-)

New commits:
commit 1b85e8eaaaa6c266f4f918dedfd4ff3bf659c63b
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri May 29 08:49:49 2015 +0300

    Be more consistent in using 'using'

diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index a98a577..3716492 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -28,7 +28,7 @@
 #include <LibreOfficeKit/LibreOfficeKit.h>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
-#include <Poco/Buffer.h>
+#include <Poco/Exception.h>
 #include <Poco/File.h>
 #include <Poco/Net/HTTPStreamFactory.h>
 #include <Poco/Net/WebSocket.h>
@@ -52,8 +52,8 @@
 
 using namespace LOOLProtocol;
 
-using Poco::Buffer;
 using Poco::File;
+using Poco::IOException;
 using Poco::Net::HTTPStreamFactory;
 using Poco::Net::WebSocket;
 using Poco::Path;
@@ -101,7 +101,7 @@ std::set<UInt64> MasterProcessSession::_pendingPreSpawnedChildren;
 std::set<std::shared_ptr<MasterProcessSession>> MasterProcessSession::_availableChildSessions;
 std::mutex MasterProcessSession::_availableChildSessionMutex;
 std::condition_variable MasterProcessSession::_availableChildSessionCV;
-Poco::Random MasterProcessSession::_rng;
+Random MasterProcessSession::_rng;
 std::mutex MasterProcessSession::_rngMutex;
 
 MasterProcessSession::MasterProcessSession(std::shared_ptr<WebSocket> ws, Kind kind) :
@@ -278,7 +278,7 @@ bool MasterProcessSession::haveSeparateProcess()
     return _childId != 0;
 }
 
-Path MasterProcessSession::getJailPath(Poco::UInt64 childId)
+Path MasterProcessSession::getJailPath(UInt64 childId)
 {
     return Path::forDirectory(LOOLWSD::childRoot + Path::separator() + std::to_string(childId));
 }
@@ -592,14 +592,14 @@ void MasterProcessSession::dispatchChild()
             _availableChildSessions.insert(childSession);
             std::cout << Util::logPrefix() << "_availableChildSessions size=" << _availableChildSessions.size() << std::endl;
             lock.unlock();
-            throw Poco::IOException(copy.toString());
+            throw IOException(copy.toString());
         }
         StreamCopier::copyStream(*input, output);
         output.close();
 
         Application::instance().logger().information(Util::logPrefix() + "Copying done");
     }
-    catch (Poco::IOException& exc)
+    catch (IOException& exc)
     {
         Application::instance().logger().error(Util::logPrefix() + "Copying failed: " + exc.message());
         sendTextFrame("error: cmd=load kind=failed");
@@ -881,7 +881,7 @@ void ChildProcessSession::sendTile(const char *buffer, int length, StringTokeniz
     sendBinaryFrame(output.data(), output.size());
 }
 
-bool ChildProcessSession::keyEvent(const char *buffer, int length, Poco::StringTokenizer& tokens)
+bool ChildProcessSession::keyEvent(const char *buffer, int length, StringTokenizer& tokens)
 {
     int type, charcode, keycode;
 
@@ -901,7 +901,7 @@ bool ChildProcessSession::keyEvent(const char *buffer, int length, Poco::StringT
     return true;
 }
 
-bool ChildProcessSession::mouseEvent(const char *buffer, int length, Poco::StringTokenizer& tokens)
+bool ChildProcessSession::mouseEvent(const char *buffer, int length, StringTokenizer& tokens)
 {
     int type, x, y, count;
 
@@ -924,7 +924,7 @@ bool ChildProcessSession::mouseEvent(const char *buffer, int length, Poco::Strin
     return true;
 }
 
-bool ChildProcessSession::unoCommand(const char *buffer, int length, Poco::StringTokenizer& tokens)
+bool ChildProcessSession::unoCommand(const char *buffer, int length, StringTokenizer& tokens)
 {
     if (tokens.count() == 1)
     {
@@ -937,7 +937,7 @@ bool ChildProcessSession::unoCommand(const char *buffer, int length, Poco::Strin
     return true;
 }
 
-bool ChildProcessSession::selectText(const char *buffer, int length, Poco::StringTokenizer& tokens)
+bool ChildProcessSession::selectText(const char *buffer, int length, StringTokenizer& tokens)
 {
     int type, x, y;
 
@@ -959,7 +959,7 @@ bool ChildProcessSession::selectText(const char *buffer, int length, Poco::Strin
     return true;
 }
 
-bool ChildProcessSession::selectGraphic(const char *buffer, int length, Poco::StringTokenizer& tokens)
+bool ChildProcessSession::selectGraphic(const char *buffer, int length, StringTokenizer& tokens)
 {
     int type, x, y;
 
@@ -980,7 +980,7 @@ bool ChildProcessSession::selectGraphic(const char *buffer, int length, Poco::St
     return true;
 }
 
-bool ChildProcessSession::resetSelection(const char *buffer, int length, Poco::StringTokenizer& tokens)
+bool ChildProcessSession::resetSelection(const char *buffer, int length, StringTokenizer& tokens)
 {
     if (tokens.count() != 1)
     {
@@ -993,7 +993,7 @@ bool ChildProcessSession::resetSelection(const char *buffer, int length, Poco::S
     return true;
 }
 
-bool ChildProcessSession::saveAs(const char *buffer, int length, Poco::StringTokenizer& tokens)
+bool ChildProcessSession::saveAs(const char *buffer, int length, StringTokenizer& tokens)
 {
     std::string url, format, filterOptions;
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index fa4d386..eb47371 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -76,6 +76,7 @@ DEALINGS IN THE SOFTWARE.
 #include <Poco/Path.h>
 #include <Poco/Process.h>
 #include <Poco/StringTokenizer.h>
+#include <Poco/ThreadPool.h>
 #include <Poco/Util/HelpFormatter.h>
 #include <Poco/Util/Option.h>
 #include <Poco/Util/OptionException.h>
@@ -89,7 +90,9 @@ DEALINGS IN THE SOFTWARE.
 
 using namespace LOOLProtocol;
 
+using Poco::Exception;
 using Poco::File;
+using Poco::IOException;
 using Poco::Net::HTTPClientSession;
 using Poco::Net::HTTPRequest;
 using Poco::Net::HTTPRequestHandler;
@@ -108,6 +111,7 @@ using Poco::Process;
 using Poco::Runnable;
 using Poco::StringTokenizer;
 using Poco::Thread;
+using Poco::ThreadPool;
 using Poco::Util::Application;
 using Poco::Util::HelpFormatter;
 using Poco::Util::IncompatibleOptionsException;
@@ -207,7 +211,7 @@ public:
                 }
             }
         }
-        catch (Poco::IOException& exc)
+        catch (IOException& exc)
         {
             app.logger().error(Util::logPrefix() + "IOException: " + exc.message());
         }
@@ -240,7 +244,7 @@ public:
     }
 };
 
-class TestOutput: public Runnable
+class TestOutput : public Runnable
 {
 public:
     TestOutput(WebSocket& ws) :
@@ -282,7 +286,7 @@ private:
     WebSocket& _ws;
 };
 
-class TestInput: public Runnable
+class TestInput : public Runnable
 {
 public:
     TestInput(ServerApplication& main, ServerSocket& svs, HTTPServer& srv) :
@@ -645,7 +649,7 @@ int LOOLWSD::childMain()
     if (std::getenv("SLEEPFORDEBUGGER"))
     {
         std::cout << "Sleeping " << std::getenv("SLEEPFORDEBUGGER") << " seconds, " <<
-            "attach process " << Poco::Process::id() << " in debugger now." << std::endl;
+            "attach process " << Process::id() << " in debugger now." << std::endl;
         Thread::sleep(std::stoul(std::getenv("SLEEPFORDEBUGGER")) * 1000);
     }
 
@@ -692,7 +696,7 @@ int LOOLWSD::childMain()
         }
         while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
     }
-    catch (Poco::Exception& exc)
+    catch (Exception& exc)
     {
         logger().log(Util::logPrefix() + "Exception: " + exc.what());
     }
@@ -749,7 +753,7 @@ int LOOLWSD::main(const std::vector<std::string>& args)
 
     // Start a server listening on the port for clients
     ServerSocket svs(portNumber, _numPreSpawnedChildren*10);
-    Poco::ThreadPool threadPool(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5);
+    ThreadPool threadPool(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5);
     HTTPServer srv(new RequestHandlerFactory(), threadPool, svs, new HTTPServerParams);
 
     srv.start();
@@ -757,7 +761,7 @@ int LOOLWSD::main(const std::vector<std::string>& args)
     // And one on the port for child processes
     SocketAddress addr2("127.0.0.1", MASTER_PORT_NUMBER);
     ServerSocket svs2(addr2, _numPreSpawnedChildren);
-    Poco::ThreadPool threadPool2(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5);
+    ThreadPool threadPool2(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5);
     HTTPServer srv2(new RequestHandlerFactory(), threadPool2, svs2, new HTTPServerParams);
 
     srv2.start();
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 374c8a0..42b7f61 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -17,24 +17,32 @@
 #include <memory>
 #include <string>
 
+#include <Poco/DigestEngine.h>
 #include <Poco/DirectoryIterator.h>
 #include <Poco/File.h>
 #include <Poco/Path.h>
 #include <Poco/SHA1Engine.h>
 #include <Poco/StringTokenizer.h>
-#include <Poco/Util/Application.h>
+#include <Poco/Timestamp.h>
 
 #include "TileCache.hpp"
 
+using Poco::DigestEngine;
+using Poco::DirectoryIterator;
+using Poco::File;
+using Poco::SHA1Engine;
+using Poco::StringTokenizer;
+using Poco::Timestamp;
+
 TileCache::TileCache(const std::string& docURL) :
     _docURL(docURL)
 {
-    Poco::File dir(cacheDirName());
+    File dir(cacheDirName());
 
     // TODO: Actually handle URLs (file: and http:), not file names.
-    if (dir.exists() && dir.isDirectory() && Poco::File(_docURL).exists() && Poco::File(_docURL).isFile())
+    if (dir.exists() && dir.isDirectory() && File(_docURL).exists() && File(_docURL).isFile())
     {
-        if (getLastModified() != Poco::File(_docURL).getLastModified())
+        if (getLastModified() != File(_docURL).getLastModified())
         {
             dir.remove(true);
        }
@@ -45,7 +53,7 @@ std::unique_ptr<std::fstream> TileCache::lookupTile(int part, int width, int hei
 {
     std::string dirName = cacheDirName();
 
-    if (!Poco::File(dirName).exists() || !Poco::File(dirName).isDirectory())
+    if (!File(dirName).exists() || !File(dirName).isDirectory())
         return nullptr;
 
     std::string fileName = dirName + "/" + cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
@@ -59,7 +67,7 @@ void TileCache::saveTile(int part, int width, int height, int tilePosX, int tile
 {
     std::string dirName = cacheDirName();
 
-    Poco::File(dirName).createDirectories();
+    File(dirName).createDirectories();
 
     std::string fileName = dirName + "/" + cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
 
@@ -68,10 +76,10 @@ void TileCache::saveTile(int part, int width, int height, int tilePosX, int tile
     outStream.close();
 
     // TODO: Actually handle URLs (file: and http:), not file names.
-    if (!Poco::File(_docURL).exists() || !Poco::File(_docURL).isFile())
+    if (!File(_docURL).exists() || !File(_docURL).isFile())
         return;
     std::fstream modTimeFile(dirName + "/modtime.txt", std::ios::out);
-    modTimeFile << Poco::File(_docURL).getLastModified().raw() << std::endl;
+    modTimeFile << File(_docURL).getLastModified().raw() << std::endl;
     modTimeFile.close();
 }
 
@@ -79,7 +87,7 @@ std::string TileCache::getStatus()
 {
     std::string dirName = cacheDirName();
 
-    if (!Poco::File(dirName).exists() || !Poco::File(dirName).isDirectory())
+    if (!File(dirName).exists() || !File(dirName).isDirectory())
         return "";
 
     std::string fileName = dirName + "/status.txt";
@@ -105,9 +113,9 @@ void TileCache::saveStatus(const std::string& status)
 {
     std::string dirName = cacheDirName();
 
-    Poco::File(dirName).createDirectories();
+    File(dirName).createDirectories();
 
-    Poco::StringTokenizer tokens(status, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
+    StringTokenizer tokens(status, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
     assert(tokens[0] == "status:");
 
@@ -127,7 +135,7 @@ void TileCache::invalidateTiles(int part, int x, int y, int width, int height)
 
     std::vector<std::string> toBeRemoved;
 
-    for (auto tileIterator = Poco::DirectoryIterator(dirName); tileIterator != Poco::DirectoryIterator(); ++tileIterator)
+    for (auto tileIterator = DirectoryIterator(dirName); tileIterator != DirectoryIterator(); ++tileIterator)
     {
         std::string baseName = tileIterator.path().getBaseName();
 
@@ -152,7 +160,7 @@ void TileCache::invalidateTiles(int part, int x, int y, int width, int height)
 
 void TileCache::invalidateTiles(int part, const std::string& tiles)
 {
-    Poco::StringTokenizer tokens(tiles, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
+    StringTokenizer tokens(tiles, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
     assert(tokens[0] == "invalidatetiles:");
 
@@ -177,12 +185,12 @@ void TileCache::invalidateTiles(int part, const std::string& tiles)
 
 std::string TileCache::cacheDirName()
 {
-    Poco::SHA1Engine digestEngine;
+    SHA1Engine digestEngine;
 
     digestEngine.update(_docURL.c_str(), _docURL.size());
 
     return (LOOLWSD_CACHEDIR "/" +
-            Poco::DigestEngine::digestToHex(digestEngine.digest()).insert(3, "/").insert(2, "/").insert(1, "/"));
+            DigestEngine::digestToHex(digestEngine.digest()).insert(3, "/").insert(2, "/").insert(1, "/"));
 }
 
 std::string TileCache::cacheFileName(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
@@ -198,14 +206,14 @@ bool TileCache::parseCacheFileName(std::string& fileName, int& part, int& width,
     return (std::sscanf(fileName.c_str(), "%d_%dx%d.%d,%d.%dx%d", &part, &width, &height, &tilePosX, &tilePosY, &tileWidth, &tileHeight) == 7);
 }
 
-Poco::Timestamp TileCache::getLastModified()
+Timestamp TileCache::getLastModified()
 {
     std::fstream modTimeFile(cacheDirName() + "/modtime.txt", std::ios::in);
 
     if (!modTimeFile.is_open())
         return 0;
 
-    Poco::Timestamp::TimeVal result;
+    Timestamp::TimeVal result;
     modTimeFile >> result;
 
     modTimeFile.close();
commit 26161d6063cc7f428521653665d5a48c47e776b7
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri May 29 08:39:21 2015 +0300

    Handle the EMPTY case of LOK_CALLBACK_INVALIDATE_TILES, too

diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index d785404..374c8a0 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -10,6 +10,7 @@
 #include "config.h"
 
 #include <cassert>
+#include <climits>
 #include <cstdio>
 #include <fstream>
 #include <iostream>
@@ -135,7 +136,7 @@ void TileCache::invalidateTiles(int part, int x, int y, int width, int height)
         if (parseCacheFileName(baseName, tilePart, tilePixelWidth, tilePixelHeight, tilePosX, tilePosY, tileWidth, tileHeight))
         {
             std::cout << "Tile " << baseName << " is " << tileWidth << "x" << tileHeight << "@+" << tilePosX << "+" << tilePosY << std::endl;
-            if (tilePart == part &&
+            if ((part == -1 || tilePart == part) &&
                 tilePosX < x + width && tilePosX + tileWidth >= x &&
                 tilePosY < y + height && tilePosY + tileHeight >= y)
             {
@@ -155,15 +156,23 @@ void TileCache::invalidateTiles(int part, const std::string& tiles)
 
     assert(tokens[0] == "invalidatetiles:");
 
-    if (tokens.count() != 5)
+    if (tokens.count() == 2 && tokens[1] == "EMPTY")
+    {
+        invalidateTiles(-1, 0, 0, INT_MAX, INT_MAX);
+    }
+    else if (tokens.count() != 5)
+    {
         return;
+    }
+    else
+    {
+        int width(std::stoi(tokens[1]));
+        int height(std::stoi(tokens[2]));
+        int x(std::stoi(tokens[3]));
+        int y(std::stoi(tokens[4]));
 
-    int width(std::stoi(tokens[1]));
-    int height(std::stoi(tokens[2]));
-    int x(std::stoi(tokens[3]));
-    int y(std::stoi(tokens[4]));
-
-    invalidateTiles(part, x, y, width, height);
+        invalidateTiles(part, x, y, width, height);
+    }
 }
 
 std::string TileCache::cacheDirName()


More information about the Libreoffice-commits mailing list