[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Aug 15 03:06:42 UTC 2016
loolwsd/LOOLKit.cpp | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
New commits:
commit 5a20ae67baaf95d5f63373b4f429fcdb320b9649
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Fri Aug 12 18:42:47 2016 -0400
loolwsd: parse the ViewId of event payloads to dispatch
Change-Id: I70e603c7f9d5d63e6ca0c3fb0364310112bc03c0
Reviewed-on: https://gerrit.libreoffice.org/28121
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index bb0a42a..50f100a 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -26,6 +26,7 @@
#include <cstdlib>
#include <iostream>
#include <memory>
+#include <regex>
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKitInit.h>
@@ -338,6 +339,9 @@ private:
std::atomic<bool> _joined;
};
+/// Regex to parse the ViewId from json.
+static std::regex ViewIdRegex("\"viewId\"\\s*:\\s*\"(\\d*)\"");
+
/// A document container.
/// Owns LOKitDocument instance and connections.
/// Manages the lifetime of a document.
@@ -739,7 +743,18 @@ private:
return;
}
- const auto viewId = self->_loKitDocument->getView();
+ // We can't invoke loKitDocument here as that could deadlock.
+ // We have to parse the message to get the target view.
+ // We can do it here once at the expense of the lok thread, or,
+ // dispatch swiftly and prase multiple times in each session.
+ int viewId = -1;
+ std::smatch match;
+ if (std::regex_search(payload.begin(), payload.end(), match, ViewIdRegex) &&
+ match.length() > 1)
+ {
+ const auto strViewId = match[1].str();
+ viewId = std::stoi(strViewId);
+ }
// Forward to the same view only.
for (auto& it: self->_connections)
@@ -747,9 +762,13 @@ private:
if (it.second->isRunning())
{
auto session = it.second->getSession();
- if (session && session->getViewId() == viewId)
+ if (session)
{
- session->loKitCallback(nType, pPayload);
+ if (viewId < 0 || session->getViewId() == viewId)
+ {
+ // Broadcast if not view-specific.
+ session->loKitCallback(nType, payload);
+ }
}
}
}
More information about the Libreoffice-commits
mailing list