summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-02-23 10:31:56 +0100
committerStephan Bergmann <sbergman@redhat.com>2012-02-23 10:47:37 +0100
commit40d21ab3c75a7c18de940162563015ae80136709 (patch)
treed0a3333ba65b560c0cda709e85b03b69fd983dd3 /desktop
parente4c7862ba289cc11b88f6059517fff091ab074f7 (diff)
Adapted OfficeIPCThread to safer-to-use salhelper::Thread
Diffstat (limited to 'desktop')
-rw-r--r--desktop/Library_sofficeapp.mk1
-rw-r--r--desktop/prj/build.lst2
-rw-r--r--desktop/source/app/officeipcthread.cxx49
-rw-r--r--desktop/source/app/officeipcthread.hxx18
4 files changed, 36 insertions, 34 deletions
diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk
index 6880eec81040..15acbb1acad2 100644
--- a/desktop/Library_sofficeapp.mk
+++ b/desktop/Library_sofficeapp.mk
@@ -53,6 +53,7 @@ $(eval $(call gb_Library_add_linked_libs,sofficeapp,\
deploymentmisc \
i18nisolang1 \
sal \
+ salhelper \
sfx \
svl \
svt \
diff --git a/desktop/prj/build.lst b/desktop/prj/build.lst
index 3d8cb8bec9f9..b86555c12df5 100644
--- a/desktop/prj/build.lst
+++ b/desktop/prj/build.lst
@@ -1,3 +1,3 @@
-dt desktop : TRANSLATIONS:translations sfx2 stoc BERKELEYDB:berkeleydb sysui BOOST:boost svx DESKTOP:xmlhelp sal unoil officecfg offapi filter LIBXSLT:libxslt NULL
+dt desktop : TRANSLATIONS:translations sfx2 stoc BERKELEYDB:berkeleydb sysui BOOST:boost svx DESKTOP:xmlhelp sal salhelper unoil officecfg offapi filter LIBXSLT:libxslt NULL
dt desktop usr1 - all dt_mkout NULL
dt desktop\prj nmake - all dt_prj NULL
diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 2cb4e6ccb11e..a0d2f3fe78bb 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -220,7 +220,7 @@ bool addArgument(rtl::OStringBuffer &rArguments, char prefix,
}
-OfficeIPCThread* OfficeIPCThread::pGlobalOfficeIPCThread = 0;
+rtl::Reference< OfficeIPCThread > OfficeIPCThread::pGlobalOfficeIPCThread;
namespace { struct Security : public rtl::Static<osl::Security, Security> {}; }
// Turns a string in aMsg such as file:///home/foo/.libreoffice/3
@@ -376,7 +376,7 @@ void OfficeIPCThread::SetDowning()
// requests are executed anymore.
::osl::MutexGuard aGuard( GetMutex() );
- if ( pGlobalOfficeIPCThread )
+ if ( pGlobalOfficeIPCThread.is() )
pGlobalOfficeIPCThread->mbDowning = true;
}
@@ -387,7 +387,7 @@ void OfficeIPCThread::EnableRequests( bool i_bEnable )
// switch between just queueing the requests and executing them
::osl::MutexGuard aGuard( GetMutex() );
- if ( pGlobalOfficeIPCThread )
+ if ( pGlobalOfficeIPCThread.is() )
{
s_bInEnableRequests = true;
pGlobalOfficeIPCThread->mbRequestsEnabled = i_bEnable;
@@ -406,7 +406,7 @@ sal_Bool OfficeIPCThread::AreRequestsPending()
{
// Give info about pending requests
::osl::MutexGuard aGuard( GetMutex() );
- if ( pGlobalOfficeIPCThread )
+ if ( pGlobalOfficeIPCThread.is() )
return ( pGlobalOfficeIPCThread->mnPendingRequests > 0 );
else
return sal_False;
@@ -416,7 +416,7 @@ void OfficeIPCThread::RequestsCompleted( int nCount )
{
// Remove nCount pending requests from our internal counter
::osl::MutexGuard aGuard( GetMutex() );
- if ( pGlobalOfficeIPCThread )
+ if ( pGlobalOfficeIPCThread.is() )
{
if ( pGlobalOfficeIPCThread->mnPendingRequests > 0 )
pGlobalOfficeIPCThread->mnPendingRequests -= nCount;
@@ -427,13 +427,13 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
{
::osl::MutexGuard aGuard( GetMutex() );
- if( pGlobalOfficeIPCThread )
+ if( pGlobalOfficeIPCThread.is() )
return IPC_STATUS_OK;
::rtl::OUString aUserInstallPath;
::rtl::OUString aDummy;
- OfficeIPCThread* pThread = new OfficeIPCThread;
+ rtl::Reference< OfficeIPCThread > pThread(new OfficeIPCThread);
pThread->maPipeIdent = OUString( RTL_CONSTASCII_USTRINGPARAM( "SingleOfficeIPC_" ) );
@@ -444,7 +444,6 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
aDummy = aUserInstallPath;
else
{
- delete pThread;
return IPC_STATUS_BOOTSTRAP_ERROR;
}
@@ -530,7 +529,7 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
{
// Seems we are the one and only, so start listening thread
pGlobalOfficeIPCThread = pThread;
- pThread->create(); // starts thread
+ pThread->launch();
}
else
{
@@ -562,7 +561,6 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
int n = aStreamPipe.read( aReceiveBuffer, aToken.Len() );
aReceiveBuffer[n]='\0';
- delete pThread;
if (aToken.CompareTo(aReceiveBuffer)!= COMPARE_EQUAL) {
// something went wrong
delete[] aReceiveBuffer;
@@ -580,10 +578,11 @@ void OfficeIPCThread::DisableOfficeIPCThread()
{
osl::ClearableMutexGuard aMutex( GetMutex() );
- if( pGlobalOfficeIPCThread )
+ if( pGlobalOfficeIPCThread.is() )
{
- OfficeIPCThread *pOfficeIPCThread = pGlobalOfficeIPCThread;
- pGlobalOfficeIPCThread = 0;
+ rtl::Reference< OfficeIPCThread > pOfficeIPCThread(
+ pGlobalOfficeIPCThread);
+ pGlobalOfficeIPCThread.clear();
// send thread a termination message
// this is done so the subsequent join will not hang
@@ -605,13 +604,11 @@ void OfficeIPCThread::DisableOfficeIPCThread()
// exit gracefully and join
pOfficeIPCThread->join();
- delete pOfficeIPCThread;
-
-
}
}
OfficeIPCThread::OfficeIPCThread() :
+ Thread( "OfficeIPCThread" ),
mbDowning( false ),
mbRequestsEnabled( false ),
mnPendingRequests( 0 ),
@@ -627,7 +624,7 @@ OfficeIPCThread::~OfficeIPCThread()
mpDispatchWatcher->release();
maPipe.close();
maStreamPipe.close();
- pGlobalOfficeIPCThread = 0;
+ pGlobalOfficeIPCThread.clear();
}
static void AddURLToStringList( const rtl::OUString& aURL, rtl::OUString& aStringList )
@@ -639,16 +636,18 @@ static void AddURLToStringList( const rtl::OUString& aURL, rtl::OUString& aStrin
aStringList = aStringListBuf.makeStringAndClear();
}
-void OfficeIPCThread::SetReady(OfficeIPCThread* pThread)
+void OfficeIPCThread::SetReady(
+ rtl::Reference< OfficeIPCThread > const & pThread)
{
- if (pThread == NULL) pThread = pGlobalOfficeIPCThread;
- if (pThread != NULL)
+ rtl::Reference< OfficeIPCThread > const & t(
+ pThread.is() ? pThread : pGlobalOfficeIPCThread);
+ if (t.is())
{
- pThread->cReady.set();
+ t->cReady.set();
}
}
-void SAL_CALL OfficeIPCThread::run()
+void OfficeIPCThread::execute()
{
do
{
@@ -664,7 +663,7 @@ void SAL_CALL OfficeIPCThread::run()
cReady.wait();
// we might have decided to shutdown while we were sleeping
- if (!pGlobalOfficeIPCThread) return;
+ if (!pGlobalOfficeIPCThread.is()) return;
// only lock the mutex when processing starts, othewise we deadlock when the office goes
// down during wait
@@ -894,7 +893,7 @@ void SAL_CALL OfficeIPCThread::run()
TimeValue tval;
tval.Seconds = 1;
tval.Nanosec = 0;
- wait( tval );
+ osl::Thread::wait( tval );
}
} while( schedule() );
}
@@ -997,7 +996,7 @@ sal_Bool OfficeIPCThread::ExecuteCmdLineRequests( ProcessDocumentsRequest& aRequ
AddConversionsToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aConversionList, aRequest.aConversionParams, aRequest.aPrinterName, aRequest.aModule, aRequest.aConversionOut );
sal_Bool bShutdown( sal_False );
- if ( pGlobalOfficeIPCThread )
+ if ( pGlobalOfficeIPCThread.is() )
{
if( ! pGlobalOfficeIPCThread->AreRequestsEnabled() )
return bShutdown;
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index a1fe4c5f772a..8dfda8303965 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -34,10 +34,11 @@
#include <osl/pipe.hxx>
#include <osl/security.hxx>
#include <osl/signal.h>
+#include <rtl/ref.hxx>
#include <rtl/ustring.hxx>
#include <cppuhelper/implbase2.hxx>
#include <osl/conditn.hxx>
-#include <osl/thread.hxx>
+#include <salhelper/thread.hxx>
#include "boost/optional.hpp"
namespace desktop
@@ -70,10 +71,10 @@ struct ProcessDocumentsRequest
};
class DispatchWatcher;
-class OfficeIPCThread : public osl::Thread
+class OfficeIPCThread : public salhelper::Thread
{
private:
- static OfficeIPCThread* pGlobalOfficeIPCThread;
+ static rtl::Reference< OfficeIPCThread > pGlobalOfficeIPCThread;
osl::Pipe maPipe;
osl::StreamPipe maStreamPipe;
@@ -101,9 +102,10 @@ class OfficeIPCThread : public osl::Thread
OfficeIPCThread();
- protected:
+ virtual ~OfficeIPCThread();
+
/// Working method which should be overridden
- virtual void SAL_CALL run();
+ virtual void execute();
public:
enum Status
@@ -113,8 +115,6 @@ class OfficeIPCThread : public osl::Thread
IPC_STATUS_BOOTSTRAP_ERROR
};
- virtual ~OfficeIPCThread();
-
// controlling pipe communication during shutdown
static void SetDowning();
static void EnableRequests( bool i_bEnable = true );
@@ -126,7 +126,9 @@ class OfficeIPCThread : public osl::Thread
static Status EnableOfficeIPCThread();
static void DisableOfficeIPCThread();
// start dispatching events...
- static void SetReady(OfficeIPCThread* pThread = NULL);
+ static void SetReady(
+ rtl::Reference< OfficeIPCThread > const & pThread =
+ rtl::Reference< OfficeIPCThread >());
bool AreRequestsEnabled() const { return mbRequestsEnabled && ! mbDowning; }
};