diff options
author | Andrzej J. R. Hunt <andrzej@ahunt.org> | 2012-07-18 16:14:52 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2012-08-06 10:22:58 +0100 |
commit | 6d6b6ee2750aa181c37464d9253b01509036b2ba (patch) | |
tree | edb66c4ed4e10e9ca5021f6daa557e6c0e2b2eac /sd | |
parent | 38b4c55546dc91e6f90f24b6e8b30530a3093fcf (diff) |
Fixed segfault on use of transmitter, and transmitter lifecycle.
Change-Id: I3983b28443584f33a879ba9fab52f11a0ab7fad5
Diffstat (limited to 'sd')
-rw-r--r-- | sd/source/ui/inc/Server.hxx | 4 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Listener.cxx | 15 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Listener.hxx | 3 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Receiver.cxx | 10 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Receiver.hxx | 5 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Server.cxx | 29 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Transmitter.cxx | 23 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Transmitter.hxx | 8 |
8 files changed, 60 insertions, 37 deletions
diff --git a/sd/source/ui/inc/Server.hxx b/sd/source/ui/inc/Server.hxx index ad1705447b6d..9abb24e0afd5 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 2ab172c62e55..959b07663c5e 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 456a4ff55269..9527ed998a58 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 8ab8e666aef4..f69c98ec4b4e 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 688c0742db83..99245d83525b 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 c4f252b847b4..2531047d7e48 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 dbe902b8bd98..341438b5dcfd 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 7fbfe736e9a6..14da76f76f3f 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; |