[Libreoffice-commits] .: Branch 'feature/remote' - sd/source

Andrzej J.R. Hunt ajrhunt at kemper.freedesktop.org
Thu Jul 19 04:05:29 PDT 2012


 sd/source/ui/inc/Server.hxx                |    1 
 sd/source/ui/remotecontrol/Listener.cxx    |   43 ++++++++++-----------
 sd/source/ui/remotecontrol/Listener.hxx    |    7 ++-
 sd/source/ui/remotecontrol/Server.cxx      |   12 +++---
 sd/source/ui/remotecontrol/Transmitter.cxx |   57 ++++++++---------------------
 5 files changed, 50 insertions(+), 70 deletions(-)

New commits:
commit e7a76c4833e10772ff68d7c4370cf117f4219256
Author: Andrzej J. R. Hunt <andrzej at ahunt.org>
Date:   Thu Jul 19 13:02:03 2012 +0200

    Fixed the Listener lifecycle, prevents crash on slideshow exit.
    
    Change-Id: I918754dc7b99cd48bbc012d62b2a8cd0eb0e438e

diff --git a/sd/source/ui/inc/Server.hxx b/sd/source/ui/inc/Server.hxx
index 8447292..b0dcc1c 100644
--- a/sd/source/ui/inc/Server.hxx
+++ b/sd/source/ui/inc/Server.hxx
@@ -42,6 +42,7 @@ namespace sd
             static void setup();
             static void presentationStarted( const css::uno::Reference<
                 css::presentation::XSlideShowController > &rController );
+            void informListenerDestroyed();
         private:
             Server();
             ~Server();
diff --git a/sd/source/ui/remotecontrol/Listener.cxx b/sd/source/ui/remotecontrol/Listener.cxx
index 7b607ab..ed6532c 100644
--- a/sd/source/ui/remotecontrol/Listener.cxx
+++ b/sd/source/ui/remotecontrol/Listener.cxx
@@ -22,13 +22,12 @@ using rtl::OString;
 using rtl::OStringBuffer;
 
 
-Listener::Listener( sd::Transmitter *aTransmitter  )
+Listener::Listener( const ::rtl::Reference<Server>& rServer, sd::Transmitter *aTransmitter  )
     : ::cppu::WeakComponentImplHelper1< XSlideShowListener >( m_aMutex ),
+      mServer( rServer ),
       pTransmitter( NULL )
 {
-    fprintf( stderr, "listener:: address of Transmitter1:%p\n", aTransmitter );
     pTransmitter = aTransmitter;
-    fprintf( stderr, "listener:: address of Transmitter2:%p\n", pTransmitter );
 }
 
 Listener::~Listener()
@@ -83,22 +82,7 @@ void SAL_CALL Listener::resumed (void)
 void SAL_CALL Listener::slideEnded (sal_Bool bReverse)
     throw (css::uno::RuntimeException)
 {
-    fprintf( stderr, "listener:: address of Transmitter__:%p\n", pTransmitter );
-    fprintf( stderr, "slideEnded\n" );
     (void) bReverse;
-    sal_Int32 aSlide = mController->getCurrentSlideIndex();
-
-    OStringBuffer aBuilder( "slide_updated\n" );
-    aBuilder.append( OString::valueOf( aSlide ) );
-    aBuilder.append( "\n\n" );
-
-    if ( pTransmitter )
-    {
-        fprintf( stderr, "Transmitter is, transmitting.\n" );
-        pTransmitter->addMessage( aBuilder.makeStringAndClear(),
-                               Transmitter::Priority::HIGH );
-    }
-    fprintf( stderr, "Transmitted\n" );
 }
 
 void SAL_CALL Listener::hyperLinkClicked (const rtl::OUString &)
@@ -109,35 +93,50 @@ void SAL_CALL Listener::hyperLinkClicked (const rtl::OUString &)
 void SAL_CALL Listener::slideTransitionStarted (void)
     throw (css::uno::RuntimeException)
 {
-        fprintf( stderr, "slideTransitionStarted\n" );
+    sal_Int32 aSlide = mController->getCurrentSlideIndex();
+
+    OStringBuffer aBuilder( "slide_updated\n" );
+    aBuilder.append( OString::valueOf( aSlide + 1 ) ); // Slides are numbered from 0
+    aBuilder.append( "\n\n" );
+
+    if ( pTransmitter )
+    {
+        pTransmitter->addMessage( aBuilder.makeStringAndClear(),
+                               Transmitter::Priority::HIGH );
+    }
 }
 
 void SAL_CALL Listener::slideTransitionEnded (void)
     throw (css::uno::RuntimeException)
 {
-    fprintf( stderr, "slideTransitionEnded\n" );
 }
 
 void SAL_CALL Listener::slideAnimationsEnded (void)
     throw (css::uno::RuntimeException)
 {
-    fprintf( stderr, "slideAnimationsEnded\n" );
 }
 
 void SAL_CALL Listener::disposing (void)
 {
+    fprintf( stderr, "In disposing\n" );
     pTransmitter = NULL;
+    fprintf( stderr, "Nulled transmitter\n" );
     if ( mController.is() )
     {
+        fprintf( stderr, "mController was\n" );
         mController->removeSlideShowListener( this );
+        mController = NULL;
     }
+    mServer->informListenerDestroyed();
+    fprintf( stderr, "finished disposing\n" );
 }
 
 void SAL_CALL Listener::disposing (
     const css::lang::EventObject& rEvent)
     throw (::com::sun::star::uno::RuntimeException)
 {
+    fprintf( stderr, "disposing\n");
     (void) rEvent;
-    dispose();
+     dispose();
 }
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/sd/source/ui/remotecontrol/Listener.hxx b/sd/source/ui/remotecontrol/Listener.hxx
index 9527ed9..09c04ea 100644
--- a/sd/source/ui/remotecontrol/Listener.hxx
+++ b/sd/source/ui/remotecontrol/Listener.hxx
@@ -17,7 +17,9 @@
 #include <cppuhelper/compbase1.hxx>
 #include <cppuhelper/basemutex.hxx>
 #include <osl/socket.hxx>
+#include <rtl/ref.hxx>
 
+#include "Server.hxx"
 #include "Transmitter.hxx"
 
 namespace css = ::com::sun::star;
@@ -28,9 +30,9 @@ class Listener
       public ::cppu::WeakComponentImplHelper1< css::presentation::XSlideShowListener >
 {
 public:
-    Listener( sd::Transmitter *aTransmitter );
+    Listener( const ::rtl::Reference<Server>& rServer, sd::Transmitter *aTransmitter );
     ~Listener();
-    void init( const css::uno::Reference< css::presentation::XSlideShowController >& aController);
+    void init( const css::uno::Reference< css::presentation::XSlideShowController >& aController );
 
     // XAnimationListener
     virtual void SAL_CALL beginEvent(const css::uno::Reference<
@@ -58,6 +60,7 @@ public:
     throw (com::sun::star::uno::RuntimeException);
 
 private:
+    rtl::Reference<Server> mServer;
     sd::Transmitter *pTransmitter;
     css::uno::Reference< css::presentation::XSlideShowController > mController;
 };
diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx
index 2906f6c..919d471 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -129,17 +129,19 @@ void Server::execute()
 
 }
 
+void Server::informListenerDestroyed()
+{
+    mListener.clear();
+}
 
 void Server::presentationStarted( const css::uno::Reference<
      css::presentation::XSlideShowController > &rController )
 {
     if ( pTransmitter )
     {
-        Listener *aListener = new Listener( pTransmitter );
-        aListener->init( rController );
-        fprintf( stderr, "presentationStarted:init--done\n");
-        mListener = rtl::Reference<Listener>( aListener );
-        fprintf( stderr, "presentationStarted:mListener--done\n");
+        mListener = rtl::Reference<Listener>( new Listener( spServer, pTransmitter ) );
+        mListener->init( rController );
+
     }
 }
 
diff --git a/sd/source/ui/remotecontrol/Transmitter.cxx b/sd/source/ui/remotecontrol/Transmitter.cxx
index efece0f..ba432c1 100644
--- a/sd/source/ui/remotecontrol/Transmitter.cxx
+++ b/sd/source/ui/remotecontrol/Transmitter.cxx
@@ -21,44 +21,32 @@ Transmitter::Transmitter( StreamSocket &aSocket )
     mLowPriority(),
     mHighPriority()
 {
-    fprintf( stderr, "Address of low queue in constructor:%p\n", &mLowPriority );
 }
 
 void Transmitter::execute()
 {
-    fprintf( stderr, "Waiting\n" );
     while ( true )
     {
         mQueuesNotEmpty.wait();
-        fprintf( stderr, "Continuing after condition\n" );
-        while ( true )
-        {
-            fprintf( stderr, "Trying to acquire mutex in Transmitter Thread\n" );
-            ::osl::MutexGuard aQueueGuard( mQueueMutex );
-            fprintf( stderr, "Acquired mutex in Transmitter Thread\n" );
-            while ( mHighPriority.size() )
-            {
-                OString aMessage( mHighPriority.front() );
-                mHighPriority.pop();
-                fprintf(stderr , " Writing HIGHP:\n%s<<END>>", aMessage.getStr() );
-                mStreamSocket.write( aMessage.getStr(), aMessage.getLength() );
-            }
-
-            if( mLowPriority.size() )
-            {
-                OString aMessage( mLowPriority.front() );
-                mLowPriority.pop();
-                fprintf(stderr , " Writing LOWP:\n%s<<END>>", aMessage.getStr() );
-                mStreamSocket.write( aMessage.getStr(), aMessage.getLength() );
-            }
 
-            if ( mLowPriority.empty() && mHighPriority.empty() )
-            {
-                mQueuesNotEmpty.reset();
-                break;
-            }
+        ::osl::MutexGuard aQueueGuard( mQueueMutex );
+        if ( !mHighPriority.empty() )
+        {
+            OString aMessage( mHighPriority.front() );
+            mHighPriority.pop();
+            mStreamSocket.write( aMessage.getStr(), aMessage.getLength() );
+        }
+        else if ( !mLowPriority.empty() )
+        {
+            OString aMessage( mLowPriority.front() );
+            mLowPriority.pop();
+            mStreamSocket.write( aMessage.getStr(), aMessage.getLength() );
         }
 
+        if ( mLowPriority.empty() && mHighPriority.empty() )
+        {
+            mQueuesNotEmpty.reset();
+        }
     }
 
 }
@@ -70,33 +58,20 @@ Transmitter::~Transmitter()
 
 void Transmitter::addMessage( const OString& aMessage, const Priority aPriority )
 {
-    fprintf(stderr, "Acquiring\n");
     ::osl::MutexGuard aQueueGuard( mQueueMutex );
-    fprintf(stderr, "Acquired\n" );
-    fprintf( stderr, "Address of low queue in addMessge:%p\n", &mLowPriority );
     switch ( aPriority )
     {
         case Priority::LOW:
-            fprintf(stderr, "PushingLow\n");
             mLowPriority.push( aMessage );
             break;
         case Priority::HIGH:
-            fprintf(stderr, "PushingHigh\n<<<%s>>>\n", aMessage.getStr() );
             mHighPriority.push( aMessage );
             break;
     }
-    fprintf( stderr, "Setting\n" );
     if ( !mQueuesNotEmpty.check() )
     {
         mQueuesNotEmpty.set();
-        fprintf( stderr, "Condition has now been set\n" );
-    }
-    else
-    {
-        fprintf( stderr, "Condition was already set\n" );
     }
-    fprintf( stderr, "Added\n" );
-    fprintf( stderr, "Front:\n<<<%s>>>\n", mHighPriority.front().getStr() );
 }
 
 


More information about the Libreoffice-commits mailing list