Change in core[libreoffice-4-0-0]: fdo#59881 - sdremote: give up on threaded / UNO usage.

Thorsten Behrens (via Code Review) gerrit at gerrit.libreoffice.org
Tue Jan 29 01:04:02 PST 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/1915

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/15/1915/1

fdo#59881 - sdremote: give up on threaded / UNO usage.

Process incoming commands in the main thread in a Timeout, build
thumbnail / previews there too - to avoid the deadlocks mentioned
in the bug.

The following commits got squashed into one:

(cherry picked from commit f07efaa3bbeb6c2160d6ccbe83ea4183df7115a3)
(cherry picked from commit 88cb36db72775c116c4721163763beb1b2ec0ea3)
(cherry picked from commit 9b696a67f92c7206fe947996931995a70229752e)

Change-Id: I7e825228fcc7ba4e1c40a161c29a0f9a371abdfb
Signed-off-by: Thorsten Behrens <tbehrens at suse.com>
---
M sd/source/ui/remotecontrol/Communicator.cxx
M sd/source/ui/remotecontrol/ImagePreparer.cxx
M sd/source/ui/remotecontrol/ImagePreparer.hxx
M sd/source/ui/remotecontrol/Listener.cxx
M sd/source/ui/remotecontrol/Receiver.cxx
M sd/source/ui/remotecontrol/Receiver.hxx
6 files changed, 55 insertions(+), 33 deletions(-)



diff --git a/sd/source/ui/remotecontrol/Communicator.cxx b/sd/source/ui/remotecontrol/Communicator.cxx
index f567b10..3e3e7bc 100644
--- a/sd/source/ui/remotecontrol/Communicator.cxx
+++ b/sd/source/ui/remotecontrol/Communicator.cxx
@@ -81,7 +81,7 @@
         }
         else
         {
-            aReceiver.parseCommand( aCommand );
+            aReceiver.pushCommand( aCommand );
             aCommand.clear();
         }
     }
diff --git a/sd/source/ui/remotecontrol/ImagePreparer.cxx b/sd/source/ui/remotecontrol/ImagePreparer.cxx
index 66b2791..3530a4a 100644
--- a/sd/source/ui/remotecontrol/ImagePreparer.cxx
+++ b/sd/source/ui/remotecontrol/ImagePreparer.cxx
@@ -50,36 +50,29 @@
  :  xController( rxController ),
     pTransmitter( aTransmitter )
 {
+    SetTimeout( 50 );
+    mnSendingSlide = 0;
+    Start();
 }
 
 ImagePreparer::~ImagePreparer()
 {
+    Stop();
 }
 
-void SAL_CALL ImagePreparer::run()
+void ImagePreparer::Timeout()
 {
     sal_uInt32 aSlides = xController->getSlideCount();
-    for ( sal_uInt32 i = 0; i < aSlides; i++ )
+    if ( xController->isRunning() && // not stopped/disposed of.
+         mnSendingSlide < aSlides )
     {
-        if ( !xController->isRunning() ) // stopped/disposed of.
-        {
-            break;
-        }
-        sendPreview( i );
+        sendPreview( mnSendingSlide );
+        sendNotes( mnSendingSlide );
+        mnSendingSlide++;
+        Start();
     }
-    for ( sal_uInt32 i = 0; i < aSlides; i++ )
-    {
-        if ( !xController->isRunning() ) // stopped/disposed of.
-        {
-            break;
-        }
-        sendNotes( i );
-    }
-}
-
-void SAL_CALL ImagePreparer::onTerminated()
-{
-    delete this;
+    else
+        Stop();
 }
 
 void ImagePreparer::sendPreview( sal_uInt32 aSlideNumber )
diff --git a/sd/source/ui/remotecontrol/ImagePreparer.hxx b/sd/source/ui/remotecontrol/ImagePreparer.hxx
index aa013d7..66b30ae 100644
--- a/sd/source/ui/remotecontrol/ImagePreparer.hxx
+++ b/sd/source/ui/remotecontrol/ImagePreparer.hxx
@@ -10,7 +10,7 @@
 #define _SD_IMPRESSREMOTE_IMAGEPREPARER_HXX
 
 #include <osl/thread.hxx>
-
+#include <vcl/timer.hxx>
 #include <com/sun/star/presentation/XSlideShowController.hpp>
 
 #include "Transmitter.hxx"
@@ -18,9 +18,9 @@
 namespace sd
 {
 
-class ImagePreparer:
-    public osl::Thread
+class ImagePreparer : Timer
 {
+    sal_uInt32 mnSendingSlide;
 public:
     ImagePreparer( const
         css::uno::Reference<css::presentation::XSlideShowController>&
@@ -31,9 +31,7 @@
     css::uno::Reference<css::presentation::XSlideShowController> xController;
     Transmitter *pTransmitter;
 
-    // Thread method
-    virtual void SAL_CALL run();
-    virtual void SAL_CALL onTerminated();
+    virtual void Timeout();
 
     void sendPreview( sal_uInt32 aSlideNumber );
     css::uno::Sequence<sal_Int8> preparePreview( sal_uInt32 aSlideNumber,
diff --git a/sd/source/ui/remotecontrol/Listener.cxx b/sd/source/ui/remotecontrol/Listener.cxx
index 30b29a9..2052fbf 100644
--- a/sd/source/ui/remotecontrol/Listener.cxx
+++ b/sd/source/ui/remotecontrol/Listener.cxx
@@ -10,11 +10,12 @@
 #include <comphelper/processfactory.hxx>
 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
 #include <com/sun/star/presentation/XPresentation2.hpp>
-
 #include <rtl/strbuf.hxx>
+#include <vcl/svapp.hxx>
 
 #include "Listener.hxx"
 #include "ImagePreparer.hxx"
+
 
 using namespace sd;
 using namespace ::com::sun::star::presentation;
@@ -53,8 +54,10 @@
         pTransmitter->addMessage( aBuffer.makeStringAndClear(),
                                   Transmitter::PRIORITY_HIGH );
 
-        ImagePreparer* pPreparer = new ImagePreparer( aController, pTransmitter );
-        pPreparer->create();
+        {
+            SolarMutexGuard aGuard;
+            /* ImagePreparer* pPreparer = */ new ImagePreparer( aController, pTransmitter );
+        }
     }
     else
     {
diff --git a/sd/source/ui/remotecontrol/Receiver.cxx b/sd/source/ui/remotecontrol/Receiver.cxx
index 968fbb4..c3e7d8a 100644
--- a/sd/source/ui/remotecontrol/Receiver.cxx
+++ b/sd/source/ui/remotecontrol/Receiver.cxx
@@ -30,13 +30,35 @@
 Receiver::Receiver( Transmitter *aTransmitter )
 {
     pTransmitter = aTransmitter;
+    SetTimeout( 0 );
 }
 
 Receiver::~Receiver()
 {
 }
 
-void Receiver::parseCommand( std::vector<OString> aCommand )
+// Bounce the commands to the main thread to avoid threading woes
+void Receiver::pushCommand( const std::vector<OString> &rCommand )
+{
+    SolarMutexGuard aGuard;
+    maExecQueue.push_back( rCommand );
+    Start();
+}
+
+void Receiver::Timeout()
+{
+    if( maExecQueue.size() )
+    {
+        std::vector< rtl::OString > aCommands( maExecQueue.front() );
+        maExecQueue.pop_front();
+        executeCommand( aCommands );
+        Start();
+    }
+    else
+        Stop();
+}
+
+void Receiver::executeCommand( const std::vector<OString> &aCommand )
 {
     uno::Reference<presentation::XSlideShowController> xSlideShowController;
     uno::Reference<presentation::XPresentation2> xPresentation;
diff --git a/sd/source/ui/remotecontrol/Receiver.hxx b/sd/source/ui/remotecontrol/Receiver.hxx
index 0bee508..a4a915c 100644
--- a/sd/source/ui/remotecontrol/Receiver.hxx
+++ b/sd/source/ui/remotecontrol/Receiver.hxx
@@ -16,6 +16,8 @@
 #include <com/sun/star/presentation/XPresentation2.hpp>
 #include <osl/socket.hxx>
 #include <stdlib.h>
+#include <vcl/timer.hxx>
+#include <vcl/svapp.hxx>
 
 #include <vector>
 
@@ -24,12 +26,16 @@
 namespace sd
 {
 
-class Receiver
+// Timer is protected by the solar mutex => so are we.
+class Receiver : Timer
 {
+    std::deque< std::vector< rtl::OString > > maExecQueue;
 public:
     Receiver( Transmitter *aTransmitter );
     ~Receiver();
-    void parseCommand( std::vector<rtl::OString> aCommand );
+    virtual void Timeout();
+    void pushCommand( const std::vector<rtl::OString> &rCommand );
+    void executeCommand( const std::vector<rtl::OString> &aCommand );
 
 private:
     Transmitter *pTransmitter;

-- 
To view, visit https://gerrit.libreoffice.org/1915
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7e825228fcc7ba4e1c40a161c29a0f9a371abdfb
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0-0
Gerrit-Owner: Thorsten Behrens <tbehrens at suse.com>
Gerrit-Reviewer: Michael Meeks <michael.meeks at suse.com>


More information about the LibreOffice mailing list