summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2019-04-17 16:23:39 +0100
committerAshod Nakashian <ashnakash@gmail.com>2019-04-23 02:59:45 +0200
commitb34786d2774b261be48de92f65a5d0aa3c32b289 (patch)
tree0acaf342c3e93465777a0aeca0568bdaec3c1bc7 /vcl
parent9f32d341b80e1f1ffe28542f33003bfe5750639b (diff)
Unipoll: add LibreOfficeKit API for polling, and an option to use it.
Change-Id: Iee7556ee52541ddbf1ef8f31e1ed4697f805a2ac Reviewed-on: https://gerrit.libreoffice.org/70898 Tested-by: Jenkins Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/headless/svpinst.cxx32
-rw-r--r--vcl/inc/headless/svpinst.hxx3
-rw-r--r--vcl/inc/svdata.hxx6
-rw-r--r--vcl/source/app/svapp.cxx19
4 files changed, 49 insertions, 11 deletions
diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx
index 324d976cb95e..69353b104fc3 100644
--- a/vcl/headless/svpinst.cxx
+++ b/vcl/headless/svpinst.cxx
@@ -51,6 +51,7 @@
#include <unx/gendata.hxx>
// FIXME: remove when we re-work the svp mainloop
#include <unx/salunxtime.h>
+#include <comphelper/lok.hxx>
SvpSalInstance* SvpSalInstance::s_pDefaultInstance = nullptr;
@@ -175,12 +176,15 @@ void SvpSalInstance::Wakeup(SvpRequest const request)
#ifdef IOS
(void)request;
#else
+ ImplSVData* pSVData = ImplGetSVData();
+
+ if (pSVData->mpWakeCallback)
+ pSVData->mpWakeCallback(pSVData->mpPollClosure);
+
SvpSalYieldMutex *const pMutex(static_cast<SvpSalYieldMutex*>(GetYieldMutex()));
std::unique_lock<std::mutex> g(pMutex->m_WakeUpMainMutex);
if (request != SvpRequest::NONE)
- {
pMutex->m_Request = request;
- }
pMutex->m_wakeUpMain = true;
pMutex->m_WakeUpMainCond.notify_one();
#endif
@@ -373,11 +377,8 @@ sal_uInt32 SvpSalYieldMutex::doRelease(bool const bUnlockAll)
// read m_nCount before doRelease
bool const isReleased(bUnlockAll || m_nCount == 1);
nCount = comphelper::SolarMutex::doRelease( bUnlockAll );
- if (isReleased) {
- std::unique_lock<std::mutex> g(m_WakeUpMainMutex);
- m_wakeUpMain = true;
- m_WakeUpMainCond.notify_one();
- }
+ if (isReleased && pInst)
+ pInst->Wakeup(SvpRequest::NONE);
}
return nCount;
}
@@ -420,8 +421,8 @@ bool SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents)
#endif
// first, process current user events
- bool bEvent = DispatchUserEvents( bHandleAllCurrentEvents );
- if ( !bHandleAllCurrentEvents && bEvent )
+ bool bEvent = DispatchUserEvents(bHandleAllCurrentEvents);
+ if (!bHandleAllCurrentEvents && bEvent)
return true;
bEvent = CheckTimeout() || bEvent;
@@ -450,7 +451,20 @@ bool SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents)
else
nTimeoutMS = -1; // wait until something happens
+ ImplSVData* pSVData = ImplGetSVData();
sal_uInt32 nAcquireCount = ReleaseYieldMutexAll();
+
+ if (pSVData->mpPollCallback)
+ {
+ // Poll for events from the LOK client.
+ if (nTimeoutMS < 0)
+ nTimeoutMS = 5000;
+
+ // External poll.
+ if (pSVData->mpPollCallback(pSVData->mpPollClosure, nTimeoutMS * 1000 /* us */) < 0)
+ pSVData->maAppData.mbAppQuit = true;
+ }
+ else
{
std::unique_lock<std::mutex> g(pMutex->m_WakeUpMainMutex);
// wait for doRelease() or Wakeup() to set the condition
diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx
index dcdd29fc8f07..b552dd9a59bf 100644
--- a/vcl/inc/headless/svpinst.hxx
+++ b/vcl/inc/headless/svpinst.hxx
@@ -93,7 +93,6 @@ public:
virtual ~SvpSalYieldMutex() override;
virtual bool IsCurrentThread() const override;
-
};
SalInstance* svp_create_SalInstance();
@@ -109,7 +108,6 @@ class VCL_DLLPUBLIC SvpSalInstance : public SalGenericInstance, public SalUserEv
virtual void TriggerUserEventProcessing() override;
virtual void ProcessEvent( SalUserEvent aEvent ) override;
- void Wakeup(SvpRequest request = SvpRequest::NONE);
public:
static SvpSalInstance* s_pDefaultInstance;
@@ -119,6 +117,7 @@ public:
void CloseWakeupPipe(bool log);
void CreateWakeupPipe(bool log);
+ void Wakeup(SvpRequest request = SvpRequest::NONE);
void StartTimer( sal_uInt64 nMS );
void StopTimer();
diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
index 714c7c5a36e7..6a98ff4e3185 100644
--- a/vcl/inc/svdata.hxx
+++ b/vcl/inc/svdata.hxx
@@ -29,6 +29,7 @@
#include <vcl/svapp.hxx>
#include <vcl/window.hxx>
#include <vcl/task.hxx>
+#include <LibreOfficeKit/LibreOfficeKitTypes.h>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/i18n/XCharacterClassification.hpp>
@@ -385,6 +386,11 @@ struct ImplSVData
css::uno::Reference<css::i18n::XCharacterClassification> m_xCharClass;
Link<LinkParamNone*,void> maDeInitHook;
+
+ // LOK & headless backend specific hooks
+ LibreOfficeKitPollCallback mpPollCallback = nullptr;
+ LibreOfficeKitWakeCallback mpWakeCallback = nullptr;
+ void *mpPollClosure = nullptr;
};
css::uno::Reference<css::i18n::XCharacterClassification> const& ImplGetCharClass();
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index ca29108bc37e..0037d35443f9 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -38,6 +38,7 @@
#include <unotools/syslocaleoptions.hxx>
#include <vcl/dialog.hxx>
+#include <vcl/lok.hxx>
#include <vcl/floatwin.hxx>
#include <vcl/settings.hxx>
#include <vcl/keycod.hxx>
@@ -1658,4 +1659,22 @@ void Application::setDeInitHook(Link<LinkParamNone*,void> const & hook) {
pSVData->maAppData.mbInAppMain = true;
}
+namespace vcl { namespace lok {
+
+void registerPollCallbacks(
+ LibreOfficeKitPollCallback pPollCallback,
+ LibreOfficeKitWakeCallback pWakeCallback,
+ void *pData) {
+
+ ImplSVData * pSVData = ImplGetSVData();
+ if (pSVData)
+ {
+ pSVData->mpPollCallback = pPollCallback;
+ pSVData->mpWakeCallback = pWakeCallback;
+ pSVData->mpPollClosure = pData;
+ }
+}
+
+} } // namespace lok, namespace vcl
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */