sd/source/ui/inc/Server.hxx | 4 +++- sd/source/ui/remotecontrol/Listener.cxx | 15 +++++++++++---- sd/source/ui/remotecontrol/Listener.hxx | 3 +-- sd/source/ui/remotecontrol/Receiver.cxx | 10 +++++----- sd/source/ui/remotecontrol/Receiver.hxx | 5 +++-- sd/source/ui/remotecontrol/Server.cxx | 29 +++++++++++++++++------------ sd/source/ui/remotecontrol/Transmitter.cxx | 23 ++++++++++++++++------- sd/source/ui/remotecontrol/Transmitter.hxx | 8 ++++---- 8 files changed, 60 insertions(+), 37 deletions(-)
New commits: commit d891117a921d7dcfbc5c3b24eb34c1e000db8391 Author: Andrzej J. R. Hunt <andr...@ahunt.org> Date: Wed Jul 18 16:14:52 2012 +0200 Fixed segfault on use of transmitter, and transmitter lifecycle. Change-Id: I3983b28443584f33a879ba9fab52f11a0ab7fad5 diff --git a/sd/source/ui/inc/Server.hxx b/sd/source/ui/inc/Server.hxx index ad17054..9abb24e 100644 --- a/sd/source/ui/inc/Server.hxx +++ b/sd/source/ui/inc/Server.hxx @@ -33,6 +33,7 @@ namespace sd { class Transmitter; + class Listener; class Server : public salhelper::Thread { @@ -48,7 +49,8 @@ namespace sd osl::StreamSocket mStreamSocket; void listenThread(); void execute(); - static Transmitter *mTransmitter; + static Transmitter *pTransmitter; + static css::uno::Reference<Listener> mListener; }; } diff --git a/sd/source/ui/remotecontrol/Listener.cxx b/sd/source/ui/remotecontrol/Listener.cxx index 2ab172c..959b076 100644 --- a/sd/source/ui/remotecontrol/Listener.cxx +++ b/sd/source/ui/remotecontrol/Listener.cxx @@ -25,7 +25,7 @@ using rtl::OStringBuffer; Listener::Listener( sd::Transmitter *aTransmitter ) : ::cppu::WeakComponentImplHelper1< XSlideShowListener>( m_aMutex ) { - mTransmitter = aTransmitter; + pTransmitter = aTransmitter; } Listener::~Listener() @@ -37,7 +37,8 @@ void Listener::init( const css::uno::Reference< css::presentation::XSlideShowCon if (aController.is() ) { mController = css::uno::Reference< css::presentation::XSlideShowController >( aController ); - aController->addSlideShowListener(static_cast<XSlideShowListener*>(this)); + aController->addSlideShowListener(this); + fprintf( stderr, "Registered listener.\n" ); } } @@ -87,8 +88,13 @@ void SAL_CALL Listener::slideEnded (sal_Bool bReverse) aBuilder.append( OString::valueOf( aSlide ) ); aBuilder.append( "\n\n" ); - mTransmitter->addMessage( aBuilder.makeStringAndClear() , - Transmitter::Priority::HIGH ); + 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 &) @@ -116,6 +122,7 @@ void SAL_CALL Listener::slideAnimationsEnded (void) void SAL_CALL Listener::disposing (void) { + pTransmitter = NULL; if ( mController.is() ) { mController->removeSlideShowListener( static_cast<XSlideShowListener*>(this) ); diff --git a/sd/source/ui/remotecontrol/Listener.hxx b/sd/source/ui/remotecontrol/Listener.hxx index 456a4ff..9527ed9 100644 --- a/sd/source/ui/remotecontrol/Listener.hxx +++ b/sd/source/ui/remotecontrol/Listener.hxx @@ -58,8 +58,7 @@ public: throw (com::sun::star::uno::RuntimeException); private: - osl::StreamSocket mStreamSocket; - sd::Transmitter *mTransmitter; + sd::Transmitter *pTransmitter; css::uno::Reference< css::presentation::XSlideShowController > mController; }; } diff --git a/sd/source/ui/remotecontrol/Receiver.cxx b/sd/source/ui/remotecontrol/Receiver.cxx index 8ab8e66..f69c98e 100644 --- a/sd/source/ui/remotecontrol/Receiver.cxx +++ b/sd/source/ui/remotecontrol/Receiver.cxx @@ -33,7 +33,7 @@ using namespace std; Receiver::Receiver( Transmitter *aTransmitter ) { - mTransmitter = aTransmitter; + pTransmitter = aTransmitter; } Receiver::~Receiver() @@ -110,12 +110,12 @@ void Receiver::parseCommand( std::vector<OString> aCommand ) } } // FIXME: remove later, this is just to test functionality - sendPreview( 0, xSlideShowController, mTransmitter ); +// sendPreview( 0, xSlideShowController, mTransmitter ); } -void sendPreview(sal_uInt32 aSlideNumber, - uno::Reference<presentation::XSlideShowController> xSlideShowController, Transmitter *aTransmitter ) +void sendPreview( sal_uInt32 aSlideNumber, + const uno::Reference<presentation::XSlideShowController>& xSlideShowController, Transmitter *aTransmitter ) { sal_uInt64 aSize; // Unused @@ -143,7 +143,7 @@ void sendPreview(sal_uInt32 aSlideNumber, uno::Sequence<sal_Int8> preparePreview(sal_uInt32 aSlideNumber, - const uno::Reference<presentation::XSlideShowController> &xSlideShowController, + const uno::Reference<presentation::XSlideShowController>& xSlideShowController, sal_uInt32 aWidth, sal_uInt32 aHeight, sal_uInt64 &rSize ) { (void)aWidth; (void)aHeight; // FIXME: remove me when I'm used diff --git a/sd/source/ui/remotecontrol/Receiver.hxx b/sd/source/ui/remotecontrol/Receiver.hxx index 688c074..99245d8 100644 --- a/sd/source/ui/remotecontrol/Receiver.hxx +++ b/sd/source/ui/remotecontrol/Receiver.hxx @@ -34,14 +34,15 @@ public: void parseCommand( std::vector<rtl::OString> aCommand ); private: - Transmitter *mTransmitter; + Transmitter *pTransmitter; }; } css::uno::Sequence<sal_Int8> preparePreview(sal_uInt32 aSlideNumber, const css::uno::Reference<css::presentation::XSlideShowController>& xSlideShowController, sal_uInt32 aWidth, sal_uInt32 aHeight, sal_uInt64 &aSize ); -void sendPreview(sal_uInt32 aSlideNumber, css::uno::Reference<css::presentation::XSlideShowController> xSlideShowController, sd::Transmitter *aTransmitter ); +void sendPreview(sal_uInt32 aSlideNumber, const css::uno::Reference< + css::presentation::XSlideShowController>& xSlideShowController, sd::Transmitter *aTransmitter ); #endif // _SD_IMPRESSREMOTE_RECEIVER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx index c4f252b..2531047 100644 --- a/sd/source/ui/remotecontrol/Server.cxx +++ b/sd/source/ui/remotecontrol/Server.cxx @@ -35,10 +35,11 @@ Server::~Server() void Server::listenThread() { // Transmitter aTransmitter( mStreamSocket ); - mTransmitter = new Transmitter( mStreamSocket); - Receiver aReceiver( mTransmitter ); - mTransmitter->addMessage( "Hello world\n\n", Transmitter::Priority::HIGH ); - +// Transmitter aTransmitter( mStreamSocket); + pTransmitter = new Transmitter( mStreamSocket ); + pTransmitter->launch(); + Receiver aReceiver( pTransmitter ); +// aTransmitter.addMessage( "Hello world\n\n", Transmitter::Priority::HIGH ); try { fprintf( stderr, "Trying to add a Listener in listenThread\n" ); uno::Reference< lang::XMultiServiceFactory > xServiceManager( @@ -99,8 +100,10 @@ void Server::listenThread() // TODO: deal with transmision errors gracefully. } - delete mTransmitter; - mTransmitter = NULL; + mListener->disposing(); + mListener = NULL; + delete pTransmitter; + pTransmitter = NULL; } @@ -130,17 +133,19 @@ void Server::execute() void Server::presentationStarted( const css::uno::Reference< css::presentation::XSlideShowController > &rController ) { -// if ( mTransmitter ) -// { -// Listener* aListener = new Listener( mTransmitter ); -// aListener->init( rController ); -// } + if ( pTransmitter ) + { + Listener *aListener = new Listener( pTransmitter ); + aListener->init( rController ); + mListener = css::uno::Reference<Listener>( aListener ); + } } Server *sd::Server::spServer = NULL; -Transmitter *sd::Server::mTransmitter = NULL; +Transmitter *sd::Server::pTransmitter = NULL; +css::uno::Reference<Listener> sd::Server::mListener = NULL; void Server::setup() { diff --git a/sd/source/ui/remotecontrol/Transmitter.cxx b/sd/source/ui/remotecontrol/Transmitter.cxx index dbe902b..341438b 100644 --- a/sd/source/ui/remotecontrol/Transmitter.cxx +++ b/sd/source/ui/remotecontrol/Transmitter.cxx @@ -15,9 +15,12 @@ using namespace sd; Transmitter::Transmitter( StreamSocket &aSocket ) : Thread( "TransmitterThread" ), - mStreamSocket( aSocket ) + mStreamSocket( aSocket ), + mQueuesNotEmpty(), + mQueueMutex(), + mLowPriority(), + mHighPriority() { - launch(); } void @@ -29,7 +32,7 @@ Transmitter::execute() fprintf( stderr, "Continuing after condition\n" ); while ( true ) { - osl::MutexGuard aQueueGuard( mQueueMutex ); + ::osl::MutexGuard aQueueGuard( mQueueMutex ); while ( mHighPriority.size() ) { OString aMessage( mHighPriority.front() ); @@ -46,7 +49,7 @@ Transmitter::execute() mStreamSocket.write( aMessage.getStr(), aMessage.getLength() ); } - if ( (mLowPriority.size() == 0) && (mHighPriority.size() == 0) ) + if ( mLowPriority.empty() && mHighPriority.empty() ) { mQueuesNotEmpty.reset(); break; @@ -62,19 +65,25 @@ Transmitter::~Transmitter() } -void Transmitter::addMessage( const OString aMessage, const Priority aPriority ) +void Transmitter::addMessage( const OString& aMessage, const Priority aPriority ) { - osl::MutexGuard aQueueGuard( mQueueMutex ); + fprintf(stderr, "Acquiring\n"); + ::osl::MutexGuard aQueueGuard( mQueueMutex ); + fprintf(stderr, "Acquired\n" ); 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; } - mQueuesNotEmpty.set(); + fprintf( stderr, "Setting\n" ); + if ( !mQueuesNotEmpty.check() ) + mQueuesNotEmpty.set(); fprintf( stderr, "Added\n" ); } diff --git a/sd/source/ui/remotecontrol/Transmitter.hxx b/sd/source/ui/remotecontrol/Transmitter.hxx index 7fbfe73..14da76f 100644 --- a/sd/source/ui/remotecontrol/Transmitter.hxx +++ b/sd/source/ui/remotecontrol/Transmitter.hxx @@ -27,16 +27,16 @@ public: enum Priority { LOW = 1, HIGH }; Transmitter( osl::StreamSocket &aSocket ); ~Transmitter(); - void addMessage( const rtl::OString aMessage, const Priority aPriority ); + void addMessage( const rtl::OString& aMessage, const Priority aPriority ); private: void execute(); - osl::StreamSocket mStreamSocket; + ::osl::StreamSocket mStreamSocket; - osl::Condition mQueuesNotEmpty; + ::osl::Condition mQueuesNotEmpty; - osl::Mutex mQueueMutex; + ::osl::Mutex mQueueMutex; std::queue<rtl::OString> mLowPriority; std::queue<rtl::OString> mHighPriority; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits