loolwsd/ChildProcessSession.cpp | 24 +++++++++++++----------- loolwsd/ChildProcessSession.hpp | 17 +++++++++-------- loolwsd/LOOLKit.cpp | 17 +++++++++++------ 3 files changed, 33 insertions(+), 25 deletions(-)
New commits: commit f8f7eb9ccc030a9a8dd8e275f9b2db6c822c7021 Author: Ashod Nakashian <[email protected]> Date: Wed Dec 23 21:20:49 2015 -0500 loolwsd: misc cleanups Change-Id: I0e2f497c7527e18ec4524e0f52b920f1e30853fa Reviewed-on: https://gerrit.libreoffice.org/20930 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp index cf75086..f074eb5 100644 --- a/loolwsd/ChildProcessSession.cpp +++ b/loolwsd/ChildProcessSession.cpp @@ -214,8 +214,8 @@ extern "C" /*pid_t tid = syscall(SYS_gettid); std::cout << tid << " callbackWorker : " << priv->m_nViewId << " " << std::string(callbackTypeToString(nType)) << " " << std::string(pPayload ? pPayload : "(nil)") << std::endl;*/ - ChildProcessSession::_callbackQueue.enqueueNotification(new CallBackNotification(nType, pPayload ? pPayload : "(nil)", pData)); - //std::string aPayLoad(pPayload ? pPayload : "(nil)"); + auto pNotif = new CallBackNotification(nType, pPayload ? pPayload : "(nil)", pData); + ChildProcessSession::_callbackQueue.enqueueNotification(pNotif); } } @@ -243,6 +243,7 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok return false; } + Log::info("Loading URI: " + aUri.toString()); if (aUri.empty()) { sendTextFrame("error: cmd=load kind=uriempty"); @@ -259,7 +260,7 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok aUri = URI( URI("file://"), Path(jailDocumentURL + Path::separator() + std::to_string(Process::id()), Path(aUri.getPath()).getFileName()).toString() ); - if ((_loKitDocument = _loKit->pClass->documentLoad(_loKit, aUri.toString().c_str())) == NULL) + if ((_loKitDocument = _loKit->pClass->documentLoad(_loKit, aUri.toString().c_str())) == nullptr) { sendTextFrame("error: cmd=load kind=failed"); Log::error("Failed to load: " + aUri.toString() + ", error is: " + _loKit->pClass->getError(_loKit)); @@ -315,7 +316,8 @@ void ChildProcessSession::sendFontRendering(const char* /*buffer*/, int /*length pixmap = _loKitDocument->pClass->renderFont(_loKitDocument, decodedFont.c_str(), &width, &height); std::cout << Util::logPrefix() << "renderFont called, font[" << font << "] rendered in " << double(timestamp.elapsed())/1000 << "ms" << std::endl; - if (pixmap != nullptr) { + if (pixmap != nullptr) + { if (!Util::encodePNGAndAppendToBuffer(pixmap, width, height, output, LOK_TILEMODE_RGBA)) { sendTextFrame("error: cmd=renderfont kind=failure"); @@ -460,10 +462,10 @@ bool ChildProcessSession::downloadAs(const char* /*buffer*/, int /*length*/, Str } std::string tmpDir, url; - File *file = NULL; + File *file = nullptr; do { - if (file != NULL) + if (file != nullptr) { delete file; } @@ -474,8 +476,8 @@ bool ChildProcessSession::downloadAs(const char* /*buffer*/, int /*length*/, Str delete file; _loKitDocument->pClass->saveAs(_loKitDocument, url.c_str(), - format.size() == 0 ? NULL :format.c_str(), - filterOptions.size() == 0 ? NULL : filterOptions.c_str()); + format.size() == 0 ? nullptr :format.c_str(), + filterOptions.size() == 0 ? nullptr : filterOptions.c_str()); //TODO: handle download portNumber. //sendTextFrame("downloadas: jail=" + _childId + " dir=" + tmpDir + " name=" + name + @@ -500,7 +502,7 @@ bool ChildProcessSession::getTextSelection(const char* /*buffer*/, int /*length* return false; } - char *textSelection = _loKitDocument->pClass->getTextSelection(_loKitDocument, mimeType.c_str(), NULL); + char *textSelection = _loKitDocument->pClass->getTextSelection(_loKitDocument, mimeType.c_str(), nullptr); sendTextFrame("textselectioncontent: " + std::string(textSelection)); return true; @@ -697,8 +699,8 @@ bool ChildProcessSession::saveAs(const char* /*buffer*/, int /*length*/, StringT } bool success = _loKitDocument->pClass->saveAs(_loKitDocument, url.c_str(), - format.size() == 0 ? NULL :format.c_str(), - filterOptions.size() == 0 ? NULL : filterOptions.c_str()); + format.size() == 0 ? nullptr :format.c_str(), + filterOptions.size() == 0 ? nullptr : filterOptions.c_str()); sendTextFrame("saveas: url=" + url); std::string successStr = success ? "true" : "false"; diff --git a/loolwsd/ChildProcessSession.hpp b/loolwsd/ChildProcessSession.hpp index 63a24a3..0c62a39 100644 --- a/loolwsd/ChildProcessSession.hpp +++ b/loolwsd/ChildProcessSession.hpp @@ -20,7 +20,7 @@ class ChildProcessSession final : public LOOLSession { public: /// Create a new ChildProcessSession - /// ws The socket to our counterparty (Child or Master). + /// ws The socket between master and kit (jailed). /// loKit The LOKit instance. /// loKitDocument The instance to an existing document (when opening /// a new view) or nullptr (when first view). @@ -82,14 +82,15 @@ class CallBackNotification: public Poco::Notification public: typedef Poco::AutoPtr<CallBackNotification> Ptr; - CallBackNotification(int nType, const std::string& rPayload, void* pSession) - : m_nType(nType), - m_aPayload(rPayload), - m_pSession(pSession) - {} + CallBackNotification(const int nType, const std::string& rPayload, void* pSession) + : m_nType(nType), + m_aPayload(rPayload), + m_pSession(pSession) + { + } - int m_nType; - std::string m_aPayload; + const int m_nType; + const std::string m_aPayload; void* m_pSession; }; diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index bfd6dd3..0cfeb14 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -60,6 +60,8 @@ const int MASTER_PORT_NUMBER = 9981; const std::string CHILD_URI = "/loolws/child/"; const std::string LOKIT_BROKER = "/tmp/loolbroker.fifo"; +// This thread handles callbacks from the +// lokit instance. class CallBackWorker: public Runnable { public: @@ -68,7 +70,7 @@ public: { } - std::string callbackTypeToString (int nType) + std::string callbackTypeToString (const int nType) { switch (nType) { @@ -106,7 +108,7 @@ public: return std::string(""); } - void callback(int nType, std::string& rPayload, void* pData) + void callback(const int nType, const std::string& rPayload, void* pData) { ChildProcessSession *srv = reinterpret_cast<ChildProcessSession *>(pData); @@ -120,12 +122,14 @@ public: { curPart = 0; } + StringTokenizer tokens(rPayload, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); if (tokens.count() == 4) { int x, y, width, height; - try { + try + { x = std::stoi(tokens[0]); y = std::stoi(tokens[1]); width = std::stoi(tokens[2]); @@ -242,6 +246,8 @@ private: FastMutex CallBackWorker::_mutex; +// This thread handles incoming messages +// on a given kit instance. class QueueHandler: public Runnable { public: @@ -265,7 +271,7 @@ public: { while (true) { - std::string input = _queue.get(); + const std::string input = _queue.get(); if (input == "eof") break; if (!_session->handleInput(input.c_str(), input.size())) @@ -334,12 +340,11 @@ public: std::shared_ptr<WebSocket> ws(new WebSocket(cs, request, response)); _session.reset(new ChildProcessSession(ws, _loKit, _loKitDocument, std::to_string(_childId))); - //std::shared_ptr<ChildProcessSession> session(new ChildProcessSession(ws, _loKit, _loKitDocument)); ws->setReceiveTimeout(0); // child Jail TID PID std::string hello("child " + std::to_string(_childId) + " " + - _threadId + " " + std::to_string(Process::id())); + _threadId + " " + std::to_string(Process::id())); _session->sendTextFrame(hello); TileQueue queue; _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
