Rename OfficeIPCThread to RequestHandler

Change-Id: I2076d903e83a0b8eb3aa0ce2413630e2c5415b15
This commit is contained in:
Stephan Bergmann 2016-03-29 14:54:20 +02:00
parent a91272a6a4
commit dde79dd504
7 changed files with 126 additions and 127 deletions

View File

@ -112,8 +112,8 @@ bool DeletedSpecial::VisitCXXMethodDecl(CXXMethodDecl const * decl) {
|| whitelist(decl, "SwLineInfo", "sw/source/core/text/inftxt.hxx") || whitelist(decl, "SwLineInfo", "sw/source/core/text/inftxt.hxx")
|| whitelist(decl, "XRenderPeer", "vcl/unx/generic/gdi/xrender_peer.hxx") || whitelist(decl, "XRenderPeer", "vcl/unx/generic/gdi/xrender_peer.hxx")
|| whitelist(decl, "desktop::DispatchWatcher", "desktop/source/app/dispatchwatcher.hxx") || whitelist(decl, "desktop::DispatchWatcher", "desktop/source/app/dispatchwatcher.hxx")
|| whitelist(decl, "desktop::OfficeIPCThread", "desktop/source/app/officeipcthread.hxx") || whitelist(decl, "desktop::RequestHandler", "desktop/source/app/officeipcthread.hxx")
|| whitelist(decl, "desktop::OfficeIPCThread", "desktop/source/lib/../app/officeipcthread.hxx") || whitelist(decl, "desktop::RequestHandler", "desktop/source/lib/../app/officeipcthread.hxx")
|| whitelist(decl, "sd::DiscoveryService", "sd/source/ui/remotecontrol/DiscoveryService.hxx") || whitelist(decl, "sd::DiscoveryService", "sd/source/ui/remotecontrol/DiscoveryService.hxx")
|| whitelist(decl, "sd::IconCache", "sd/source/ui/inc/tools/IconCache.hxx") || whitelist(decl, "sd::IconCache", "sd/source/ui/inc/tools/IconCache.hxx")
|| whitelist(decl, "sd::RemoteServer", "sd/source/ui/inc/RemoteServer.hxx") || whitelist(decl, "sd::RemoteServer", "sd/source/ui/inc/RemoteServer.hxx")

View File

@ -199,7 +199,7 @@ namespace {
// removed cache data is recreated. // removed cache data is recreated.
// //
// Multiple instances of soffice.bin can execute this code in parallel for a // Multiple instances of soffice.bin can execute this code in parallel for a
// single UserInstallation, as it is called before OfficeIPCThread is set up. // single UserInstallation, as it is called before RequestHandler is set up.
// Therefore, any errors here only lead to SAL_WARNs. // Therefore, any errors here only lead to SAL_WARNs.
// //
// At least in theory, this function could be removed again once no // At least in theory, this function could be removed again once no
@ -576,8 +576,8 @@ void Desktop::Init()
const CommandLineArgs& rCmdLineArgs = GetCommandLineArgs(); const CommandLineArgs& rCmdLineArgs = GetCommandLineArgs();
// start ipc thread only for non-remote offices // start ipc thread only for non-remote offices
OfficeIPCThread::Status aStatus = OfficeIPCThread::EnableOfficeIPCThread(); RequestHandler::Status aStatus = RequestHandler::Enable();
if ( aStatus == OfficeIPCThread::IPC_STATUS_PIPE_ERROR ) if ( aStatus == RequestHandler::IPC_STATUS_PIPE_ERROR )
{ {
#if HAVE_FEATURE_MACOSX_SANDBOX #if HAVE_FEATURE_MACOSX_SANDBOX
// In a sandboxed LO, on 10.8.2 at least, creating the // In a sandboxed LO, on 10.8.2 at least, creating the
@ -599,11 +599,11 @@ void Desktop::Init()
SetBootstrapError( BE_PATHINFO_MISSING, OUString() ); SetBootstrapError( BE_PATHINFO_MISSING, OUString() );
#endif #endif
} }
else if ( aStatus == OfficeIPCThread::IPC_STATUS_BOOTSTRAP_ERROR ) else if ( aStatus == RequestHandler::IPC_STATUS_BOOTSTRAP_ERROR )
{ {
SetBootstrapError( BE_PATHINFO_MISSING, OUString() ); SetBootstrapError( BE_PATHINFO_MISSING, OUString() );
} }
else if ( aStatus == OfficeIPCThread::IPC_STATUS_2ND_OFFICE ) else if ( aStatus == RequestHandler::IPC_STATUS_2ND_OFFICE )
{ {
// 2nd office startup should terminate after sending cmdlineargs through pipe // 2nd office startup should terminate after sending cmdlineargs through pipe
SetBootstrapStatus(BS_TERMINATE); SetBootstrapStatus(BS_TERMINATE);
@ -612,7 +612,7 @@ void Desktop::Init()
|| rCmdLineArgs.IsHelp() || rCmdLineArgs.IsVersion() ) || rCmdLineArgs.IsHelp() || rCmdLineArgs.IsVersion() )
{ {
// disable IPC thread in an instance that is just showing a help message // disable IPC thread in an instance that is just showing a help message
OfficeIPCThread::DisableOfficeIPCThread(); RequestHandler::Disable();
} }
pSignalHandler = osl_addSignalHandler(SalMainPipeExchangeSignal_impl, nullptr); pSignalHandler = osl_addSignalHandler(SalMainPipeExchangeSignal_impl, nullptr);
} }
@ -641,7 +641,7 @@ void Desktop::DeInit()
// clear lockfile // clear lockfile
m_xLockfile.reset(); m_xLockfile.reset();
OfficeIPCThread::DisableOfficeIPCThread(); RequestHandler::Disable();
if( pSignalHandler ) if( pSignalHandler )
osl_removeSignalHandler( pSignalHandler ); osl_removeSignalHandler( pSignalHandler );
} catch (const RuntimeException&) { } catch (const RuntimeException&) {
@ -677,9 +677,9 @@ bool Desktop::QueryExit()
FlushConfiguration(); FlushConfiguration();
try try
{ {
// it is no problem to call DisableOfficeIPCThread() more than once // it is no problem to call RequestHandler::Disable() more than once
// it also looks to be threadsafe // it also looks to be threadsafe
OfficeIPCThread::DisableOfficeIPCThread(); RequestHandler::Disable();
} }
catch ( const RuntimeException& ) catch ( const RuntimeException& )
{ {
@ -1154,7 +1154,7 @@ namespace {
void restartOnMac(bool passArguments) { void restartOnMac(bool passArguments) {
#if defined MACOSX #if defined MACOSX
OfficeIPCThread::DisableOfficeIPCThread(); RequestHandler::Disable();
#if HAVE_FEATURE_MACOSX_SANDBOX #if HAVE_FEATURE_MACOSX_SANDBOX
(void) passArguments; // avoid warnings (void) passArguments; // avoid warnings
ResMgr *resMgr = Desktop::GetDesktopResManager(); ResMgr *resMgr = Desktop::GetDesktopResManager();
@ -1279,7 +1279,7 @@ void Desktop::Exception(sal_uInt16 nError)
if( bRestart ) if( bRestart )
{ {
OfficeIPCThread::DisableOfficeIPCThread(); RequestHandler::Disable();
if( pSignalHandler ) if( pSignalHandler )
osl_removeSignalHandler( pSignalHandler ); osl_removeSignalHandler( pSignalHandler );
@ -1613,7 +1613,7 @@ int Desktop::Main()
try try
{ {
if ( xDesktop.is() ) if ( xDesktop.is() )
xDesktop->addTerminateListener( new OfficeIPCThreadController ); xDesktop->addTerminateListener( new RequestHandlerController );
SetSplashScreenProgress(100); SetSplashScreenProgress(100);
} }
catch ( const css::uno::Exception& e ) catch ( const css::uno::Exception& e )
@ -1659,27 +1659,27 @@ int Desktop::Main()
} }
catch(const css::document::CorruptedFilterConfigurationException& exFilterCfg) catch(const css::document::CorruptedFilterConfigurationException& exFilterCfg)
{ {
OfficeIPCThread::SetDowning(); RequestHandler::SetDowning();
FatalError( MakeStartupErrorMessage(exFilterCfg.Message) ); FatalError( MakeStartupErrorMessage(exFilterCfg.Message) );
} }
catch(const css::configuration::CorruptedConfigurationException& exAnyCfg) catch(const css::configuration::CorruptedConfigurationException& exAnyCfg)
{ {
OfficeIPCThread::SetDowning(); RequestHandler::SetDowning();
FatalError( MakeStartupErrorMessage(exAnyCfg.Message) ); FatalError( MakeStartupErrorMessage(exAnyCfg.Message) );
} }
catch( const css::uno::Exception& exUNO) catch( const css::uno::Exception& exUNO)
{ {
OfficeIPCThread::SetDowning(); RequestHandler::SetDowning();
FatalError( exUNO.Message); FatalError( exUNO.Message);
} }
catch( const std::exception& exSTD) catch( const std::exception& exSTD)
{ {
OfficeIPCThread::SetDowning(); RequestHandler::SetDowning();
FatalError( OUString::createFromAscii( exSTD.what())); FatalError( OUString::createFromAscii( exSTD.what()));
} }
catch( ...) catch( ...)
{ {
OfficeIPCThread::SetDowning(); RequestHandler::SetDowning();
FatalError( "Caught Unknown Exception: Aborting!"); FatalError( "Caught Unknown Exception: Aborting!");
} }
} }
@ -1943,7 +1943,7 @@ IMPL_LINK_NOARG_TYPED(Desktop, OpenClients_Impl, void*, void)
try { try {
OpenClients(); OpenClients();
OfficeIPCThread::SetReady(); RequestHandler::SetReady();
CloseSplashScreen(); CloseSplashScreen();
CheckFirstRun( ); CheckFirstRun( );
@ -2351,7 +2351,7 @@ void Desktop::OpenClients()
CrashReporter::writeCommonInfo(); CrashReporter::writeCommonInfo();
#endif #endif
OfficeIPCThread::EnableRequests(); RequestHandler::EnableRequests();
ProcessDocumentsRequest aRequest(rArgs.getCwdUrl()); ProcessDocumentsRequest aRequest(rArgs.getCwdUrl());
aRequest.aOpenList = rArgs.GetOpenList(); aRequest.aOpenList = rArgs.GetOpenList();
@ -2407,7 +2407,7 @@ void Desktop::OpenClients()
} }
// Process request // Process request
if ( OfficeIPCThread::ExecuteCmdLineRequests(aRequest, false) ) if ( RequestHandler::ExecuteCmdLineRequests(aRequest, false) )
{ {
// Don't do anything if we have successfully called terminate at desktop: // Don't do anything if we have successfully called terminate at desktop:
return; return;
@ -2481,7 +2481,7 @@ void Desktop::OpenDefault()
ProcessDocumentsRequest aRequest(rArgs.getCwdUrl()); ProcessDocumentsRequest aRequest(rArgs.getCwdUrl());
aRequest.aOpenList.push_back(aName); aRequest.aOpenList.push_back(aName);
OfficeIPCThread::ExecuteCmdLineRequests(aRequest, false); RequestHandler::ExecuteCmdLineRequests(aRequest, false);
} }
@ -2604,7 +2604,7 @@ void Desktop::HandleAppEvent( const ApplicationEvent& rAppEvent )
std::vector<OUString> const & data(rAppEvent.GetStringsData()); std::vector<OUString> const & data(rAppEvent.GetStringsData());
docsRequest.aOpenList.insert( docsRequest.aOpenList.insert(
docsRequest.aOpenList.end(), data.begin(), data.end()); docsRequest.aOpenList.end(), data.begin(), data.end());
OfficeIPCThread::ExecuteCmdLineRequests(docsRequest, false); RequestHandler::ExecuteCmdLineRequests(docsRequest, false);
} }
} }
break; break;
@ -2621,7 +2621,7 @@ void Desktop::HandleAppEvent( const ApplicationEvent& rAppEvent )
std::vector<OUString> const & data(rAppEvent.GetStringsData()); std::vector<OUString> const & data(rAppEvent.GetStringsData());
docsRequest.aPrintList.insert( docsRequest.aPrintList.insert(
docsRequest.aPrintList.end(), data.begin(), data.end()); docsRequest.aPrintList.end(), data.begin(), data.end());
OfficeIPCThread::ExecuteCmdLineRequests(docsRequest, false); RequestHandler::ExecuteCmdLineRequests(docsRequest, false);
} }
} }
break; break;

View File

@ -201,7 +201,7 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest
{ {
bSetInputFilter = true; bSetInputFilter = true;
aForcedInputFilter = aDispatchRequest.aURL; aForcedInputFilter = aDispatchRequest.aURL;
OfficeIPCThread::RequestsCompleted(); RequestHandler::RequestsCompleted();
continue; continue;
} }
@ -438,7 +438,7 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest
aDispatchRequest.aRequestType == REQUEST_FORCENEW ) aDispatchRequest.aRequestType == REQUEST_FORCENEW )
{ {
// request is completed // request is completed
OfficeIPCThread::RequestsCompleted(); RequestHandler::RequestsCompleted();
} }
else if ( aDispatchRequest.aRequestType == REQUEST_PRINT || else if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
aDispatchRequest.aRequestType == REQUEST_PRINTTO || aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
@ -662,7 +662,7 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest
} }
// request is completed // request is completed
OfficeIPCThread::RequestsCompleted(); RequestHandler::RequestsCompleted();
} }
} }
} }
@ -727,8 +727,8 @@ void SAL_CALL DispatchWatcher::dispatchFinished( const DispatchResultEvent& ) th
osl::ClearableMutexGuard aGuard(m_mutex); osl::ClearableMutexGuard aGuard(m_mutex);
sal_Int16 nCount = --m_nRequestCount; sal_Int16 nCount = --m_nRequestCount;
aGuard.clear(); aGuard.clear();
OfficeIPCThread::RequestsCompleted(); RequestHandler::RequestsCompleted();
if ( !nCount && !OfficeIPCThread::AreRequestsPending() ) if ( !nCount && !RequestHandler::AreRequestsPending() )
{ {
// We have to check if we have an open task otherwise we have to shutdown the office. // We have to check if we have an open task otherwise we have to shutdown the office.
Reference< XDesktop2 > xDesktop = css::frame::Desktop::create( ::comphelper::getProcessComponentContext() ); Reference< XDesktop2 > xDesktop = css::frame::Desktop::create( ::comphelper::getProcessComponentContext() );

View File

@ -242,7 +242,7 @@ bool addArgument(OStringBuffer &rArguments, char prefix,
} }
rtl::Reference< OfficeIPCThread > OfficeIPCThread::pGlobalOfficeIPCThread; rtl::Reference< RequestHandler > RequestHandler::pGlobal;
// Turns a string in aMsg such as file:///home/foo/.libreoffice/3 // Turns a string in aMsg such as file:///home/foo/.libreoffice/3
// Into a hex string of well known length ff132a86... // Into a hex string of well known length ff132a86...
@ -290,9 +290,9 @@ IMPL_STATIC_LINK_TYPED( ProcessEventsClass_Impl, CallEvent, void*, pEvent, void
IMPL_STATIC_LINK_TYPED( ProcessEventsClass_Impl, ProcessDocumentsEvent, void*, pEvent, void ) IMPL_STATIC_LINK_TYPED( ProcessEventsClass_Impl, ProcessDocumentsEvent, void*, pEvent, void )
{ {
// Documents requests are processed by the OfficeIPCThread implementation // Documents requests are processed by the RequestHandler implementation
ProcessDocumentsRequest* pDocsRequest = static_cast<ProcessDocumentsRequest*>(pEvent); ProcessDocumentsRequest* pDocsRequest = static_cast<ProcessDocumentsRequest*>(pEvent);
OfficeIPCThread::ExecuteCmdLineRequests(*pDocsRequest, false); RequestHandler::ExecuteCmdLineRequests(*pDocsRequest, false);
delete pDocsRequest; delete pDocsRequest;
} }
@ -309,34 +309,34 @@ void ImplPostProcessDocumentsEvent( ProcessDocumentsRequest* pEvent )
oslSignalAction SAL_CALL SalMainPipeExchangeSignal_impl(void* /*pData*/, oslSignalInfo* pInfo) oslSignalAction SAL_CALL SalMainPipeExchangeSignal_impl(void* /*pData*/, oslSignalInfo* pInfo)
{ {
if( pInfo->Signal == osl_Signal_Terminate ) if( pInfo->Signal == osl_Signal_Terminate )
OfficeIPCThread::DisableOfficeIPCThread(false); RequestHandler::Disable(false);
return osl_Signal_ActCallNextHdl; return osl_Signal_ActCallNextHdl;
} }
// The OfficeIPCThreadController implementation is a bookkeeper for all pending requests // The RequestHandlerController implementation is a bookkeeper for all pending requests
// that were created by the OfficeIPCThread. The requests are waiting to be processed by // that were created by the RequestHandler. The requests are waiting to be processed by
// our framework loadComponentFromURL function (e.g. open/print request). // our framework loadComponentFromURL function (e.g. open/print request).
// During shutdown the framework is asking OfficeIPCThreadController about pending requests. // During shutdown the framework is asking RequestHandlerController about pending requests.
// If there are pending requests framework has to stop the shutdown process. It is waiting // If there are pending requests framework has to stop the shutdown process. It is waiting
// for these requests because framework is not able to handle shutdown and open a document // for these requests because framework is not able to handle shutdown and open a document
// concurrently. // concurrently.
// XServiceInfo // XServiceInfo
OUString SAL_CALL OfficeIPCThreadController::getImplementationName() OUString SAL_CALL RequestHandlerController::getImplementationName()
throw ( RuntimeException, std::exception ) throw ( RuntimeException, std::exception )
{ {
return OUString( "com.sun.star.comp.OfficeIPCThreadController" ); return OUString( "com.sun.star.comp.RequestHandlerController" );
} }
sal_Bool OfficeIPCThreadController::supportsService( sal_Bool RequestHandlerController::supportsService(
OUString const & ServiceName) throw (css::uno::RuntimeException, std::exception) OUString const & ServiceName) throw (css::uno::RuntimeException, std::exception)
{ {
return cppu::supportsService(this, ServiceName); return cppu::supportsService(this, ServiceName);
} }
Sequence< OUString > SAL_CALL OfficeIPCThreadController::getSupportedServiceNames() Sequence< OUString > SAL_CALL RequestHandlerController::getSupportedServiceNames()
throw ( RuntimeException, std::exception ) throw ( RuntimeException, std::exception )
{ {
Sequence< OUString > aSeq( 0 ); Sequence< OUString > aSeq( 0 );
@ -344,33 +344,33 @@ throw ( RuntimeException, std::exception )
} }
// XEventListener // XEventListener
void SAL_CALL OfficeIPCThreadController::disposing( const EventObject& ) void SAL_CALL RequestHandlerController::disposing( const EventObject& )
throw( RuntimeException, std::exception ) throw( RuntimeException, std::exception )
{ {
} }
// XTerminateListener // XTerminateListener
void SAL_CALL OfficeIPCThreadController::queryTermination( const EventObject& ) void SAL_CALL RequestHandlerController::queryTermination( const EventObject& )
throw( TerminationVetoException, RuntimeException, std::exception ) throw( TerminationVetoException, RuntimeException, std::exception )
{ {
// Desktop ask about pending request through our office ipc pipe. We have to // Desktop ask about pending request through our office ipc pipe. We have to
// be sure that no pending request is waiting because framework is not able to // be sure that no pending request is waiting because framework is not able to
// handle shutdown and open a document concurrently. // handle shutdown and open a document concurrently.
if ( OfficeIPCThread::AreRequestsPending() ) if ( RequestHandler::AreRequestsPending() )
throw TerminationVetoException(); throw TerminationVetoException();
else else
OfficeIPCThread::SetDowning(); RequestHandler::SetDowning();
} }
void SAL_CALL OfficeIPCThreadController::notifyTermination( const EventObject& ) void SAL_CALL RequestHandlerController::notifyTermination( const EventObject& )
throw( RuntimeException, std::exception ) throw( RuntimeException, std::exception )
{ {
} }
class PipeReaderThread: public salhelper::Thread { class PipeReaderThread: public salhelper::Thread {
public: public:
PipeReaderThread(OfficeIPCThread & ipc, osl::Pipe const & pipe): PipeReaderThread(RequestHandler & ipc, osl::Pipe const & pipe):
Thread("PipeReader"), ipc_(ipc), pipe_(pipe) Thread("PipeReader"), ipc_(ipc), pipe_(pipe)
{} {}
@ -381,75 +381,75 @@ private:
void execute() override; void execute() override;
OfficeIPCThread & ipc_; RequestHandler & ipc_;
osl::Pipe pipe_; osl::Pipe pipe_;
}; };
namespace namespace
{ {
class theOfficeIPCThreadMutex class theRequestHandlerMutex
: public rtl::Static<osl::Mutex, theOfficeIPCThreadMutex> {}; : public rtl::Static<osl::Mutex, theRequestHandlerMutex> {};
} }
::osl::Mutex& OfficeIPCThread::GetMutex() ::osl::Mutex& RequestHandler::GetMutex()
{ {
return theOfficeIPCThreadMutex::get(); return theRequestHandlerMutex::get();
} }
void OfficeIPCThread::SetDowning() void RequestHandler::SetDowning()
{ {
// We have the order to block all incoming requests. Framework // We have the order to block all incoming requests. Framework
// wants to shutdown and we have to make sure that no loading/printing // wants to shutdown and we have to make sure that no loading/printing
// requests are executed anymore. // requests are executed anymore.
::osl::MutexGuard aGuard( GetMutex() ); ::osl::MutexGuard aGuard( GetMutex() );
if ( pGlobalOfficeIPCThread.is() ) if ( pGlobal.is() )
pGlobalOfficeIPCThread->mState = State::Downing; pGlobal->mState = State::Downing;
} }
void OfficeIPCThread::EnableRequests() void RequestHandler::EnableRequests()
{ {
// switch between just queueing the requests and executing them // switch between just queueing the requests and executing them
::osl::MutexGuard aGuard( GetMutex() ); ::osl::MutexGuard aGuard( GetMutex() );
if ( pGlobalOfficeIPCThread.is() ) if ( pGlobal.is() )
{ {
if (pGlobalOfficeIPCThread->mState != State::Downing) { if (pGlobal->mState != State::Downing) {
pGlobalOfficeIPCThread->mState = State::RequestsEnabled; pGlobal->mState = State::RequestsEnabled;
} }
// hit the compiler over the head // hit the compiler over the head
ProcessDocumentsRequest aEmptyReq = ProcessDocumentsRequest( boost::optional< OUString >() ); ProcessDocumentsRequest aEmptyReq = ProcessDocumentsRequest( boost::optional< OUString >() );
// trigger already queued requests // trigger already queued requests
OfficeIPCThread::ExecuteCmdLineRequests(aEmptyReq, true); RequestHandler::ExecuteCmdLineRequests(aEmptyReq, true);
} }
} }
bool OfficeIPCThread::AreRequestsPending() bool RequestHandler::AreRequestsPending()
{ {
// Give info about pending requests // Give info about pending requests
::osl::MutexGuard aGuard( GetMutex() ); ::osl::MutexGuard aGuard( GetMutex() );
if ( pGlobalOfficeIPCThread.is() ) if ( pGlobal.is() )
return ( pGlobalOfficeIPCThread->mnPendingRequests > 0 ); return ( pGlobal->mnPendingRequests > 0 );
else else
return false; return false;
} }
void OfficeIPCThread::RequestsCompleted() void RequestHandler::RequestsCompleted()
{ {
// Remove nCount pending requests from our internal counter // Remove nCount pending requests from our internal counter
::osl::MutexGuard aGuard( GetMutex() ); ::osl::MutexGuard aGuard( GetMutex() );
if ( pGlobalOfficeIPCThread.is() ) if ( pGlobal.is() )
{ {
if ( pGlobalOfficeIPCThread->mnPendingRequests > 0 ) if ( pGlobal->mnPendingRequests > 0 )
pGlobalOfficeIPCThread->mnPendingRequests --; pGlobal->mnPendingRequests --;
} }
} }
OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread() RequestHandler::Status RequestHandler::Enable()
{ {
::osl::MutexGuard aGuard( GetMutex() ); ::osl::MutexGuard aGuard( GetMutex() );
if( pGlobalOfficeIPCThread.is() ) if( pGlobal.is() )
return IPC_STATUS_OK; return IPC_STATUS_OK;
#if HAVE_FEATURE_DESKTOP #if HAVE_FEATURE_DESKTOP
@ -462,7 +462,7 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
// In LibreOfficeKit-based programs we want to be totally independent from any other LibreOffice // In LibreOfficeKit-based programs we want to be totally independent from any other LibreOffice
// instance or LOKit-using program. Certainly no need for any IPC pipes by definition, as we // instance or LOKit-using program. Certainly no need for any IPC pipes by definition, as we
// don't have any reason to do any IPC. Why we even call this EnableOfficeIPCThread function // don't have any reason to do any IPC. Why we even call this Enable function
// from LibreOfficeKit's lo_initialize() I am not completely sure, but that code, and this, is // from LibreOfficeKit's lo_initialize() I am not completely sure, but that code, and this, is
// such horrible crack that I don't want to change it too much. // such horrible crack that I don't want to change it too much.
@ -584,9 +584,9 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
if ( nPipeMode == PIPEMODE_CREATED ) if ( nPipeMode == PIPEMODE_CREATED )
{ {
// Seems we are the one and only, so start listening thread // Seems we are the one and only, so start listening thread
rtl::Reference< OfficeIPCThread > pThread(new OfficeIPCThread); rtl::Reference< RequestHandler > pThread(new RequestHandler);
pThread->mPipeReaderThread = new PipeReaderThread(*pThread, pipe); pThread->mPipeReaderThread = new PipeReaderThread(*pThread, pipe);
pGlobalOfficeIPCThread = pThread; pGlobal = pThread;
pThread->mPipeReaderThread->launch(); pThread->mPipeReaderThread->launch();
} }
else else
@ -627,67 +627,66 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
return IPC_STATUS_2ND_OFFICE; return IPC_STATUS_2ND_OFFICE;
} }
#else #else
rtl::Reference< OfficeIPCThread > pThread(new OfficeIPCThread); rtl::Reference< RequestHandler > pThread(new RequestHandler);
pGlobalOfficeIPCThread = pThread; pGlobal = pThread;
#endif #endif
return IPC_STATUS_OK; return IPC_STATUS_OK;
} }
void OfficeIPCThread::DisableOfficeIPCThread(bool join) void RequestHandler::Disable(bool join)
{ {
osl::ClearableMutexGuard aMutex( GetMutex() ); osl::ClearableMutexGuard aMutex( GetMutex() );
if( pGlobalOfficeIPCThread.is() ) if( pGlobal.is() )
{ {
rtl::Reference< OfficeIPCThread > pOfficeIPCThread( rtl::Reference< RequestHandler > handler(pGlobal);
pGlobalOfficeIPCThread); pGlobal.clear();
pGlobalOfficeIPCThread.clear();
pOfficeIPCThread->mState = State::Downing; handler->mState = State::Downing;
if (pOfficeIPCThread->mPipeReaderThread.is()) { if (handler->mPipeReaderThread.is()) {
pOfficeIPCThread->mPipeReaderThread->close(); handler->mPipeReaderThread->close();
} }
// release mutex to avoid deadlocks // release mutex to avoid deadlocks
aMutex.clear(); aMutex.clear();
pOfficeIPCThread->cReady.set(); handler->cReady.set();
// exit gracefully and join // exit gracefully and join
if (join && pOfficeIPCThread->mPipeReaderThread.is()) if (join && handler->mPipeReaderThread.is())
{ {
pOfficeIPCThread->mPipeReaderThread->join(); handler->mPipeReaderThread->join();
pOfficeIPCThread->mPipeReaderThread.clear(); handler->mPipeReaderThread.clear();
} }
} }
} }
OfficeIPCThread::OfficeIPCThread() : RequestHandler::RequestHandler() :
mState( State::Starting ), mState( State::Starting ),
mnPendingRequests( 0 ) mnPendingRequests( 0 )
{ {
} }
OfficeIPCThread::~OfficeIPCThread() RequestHandler::~RequestHandler()
{ {
assert(!mPipeReaderThread.is()); assert(!mPipeReaderThread.is());
} }
void OfficeIPCThread::SetReady() void RequestHandler::SetReady()
{ {
osl::MutexGuard g(GetMutex()); osl::MutexGuard g(GetMutex());
if (pGlobalOfficeIPCThread.is()) if (pGlobal.is())
{ {
pGlobalOfficeIPCThread->cReady.set(); pGlobal->cReady.set();
} }
} }
void OfficeIPCThread::WaitForReady() void RequestHandler::WaitForReady()
{ {
rtl::Reference<OfficeIPCThread> t; rtl::Reference<RequestHandler> t;
{ {
osl::MutexGuard g(GetMutex()); osl::MutexGuard g(GetMutex());
t = pGlobalOfficeIPCThread; t = pGlobal;
} }
if (t.is()) if (t.is())
{ {
@ -695,10 +694,10 @@ void OfficeIPCThread::WaitForReady()
} }
} }
bool OfficeIPCThread::IsEnabled() bool RequestHandler::IsEnabled()
{ {
osl::MutexGuard g(GetMutex()); osl::MutexGuard g(GetMutex());
return pGlobalOfficeIPCThread.is(); return pGlobal.is();
} }
void PipeReaderThread::execute() void PipeReaderThread::execute()
@ -723,13 +722,13 @@ void PipeReaderThread::execute()
ipc_.cReady.wait(); ipc_.cReady.wait();
// we might have decided to shutdown while we were sleeping // we might have decided to shutdown while we were sleeping
if (!ipc_.pGlobalOfficeIPCThread.is()) return; if (!ipc_.pGlobal.is()) return;
// only lock the mutex when processing starts, othewise we deadlock when the office goes // only lock the mutex when processing starts, othewise we deadlock when the office goes
// down during wait // down during wait
osl::ClearableMutexGuard aGuard( OfficeIPCThread::GetMutex() ); osl::ClearableMutexGuard aGuard( RequestHandler::GetMutex() );
if ( ipc_.mState == OfficeIPCThread::State::Downing ) if ( ipc_.mState == RequestHandler::State::Downing )
{ {
break; break;
} }
@ -967,8 +966,8 @@ void PipeReaderThread::execute()
else else
{ {
{ {
osl::MutexGuard aGuard( OfficeIPCThread::GetMutex() ); osl::MutexGuard aGuard( RequestHandler::GetMutex() );
if ( ipc_.mState == OfficeIPCThread::State::Downing ) if ( ipc_.mState == RequestHandler::State::Downing )
{ {
break; break;
} }
@ -1049,7 +1048,7 @@ static void AddConversionsToDispatchList(
} }
bool OfficeIPCThread::ExecuteCmdLineRequests( bool RequestHandler::ExecuteCmdLineRequests(
ProcessDocumentsRequest& aRequest, bool noTerminate) ProcessDocumentsRequest& aRequest, bool noTerminate)
{ {
// protect the dispatch list // protect the dispatch list
@ -1069,18 +1068,18 @@ bool OfficeIPCThread::ExecuteCmdLineRequests(
AddConversionsToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aConversionList, aRequest.aConversionParams, aRequest.aPrinterName, aRequest.aModule, aRequest.aConversionOut, aRequest.bTextCat ); AddConversionsToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aConversionList, aRequest.aConversionParams, aRequest.aPrinterName, aRequest.aModule, aRequest.aConversionOut, aRequest.bTextCat );
bool bShutdown( false ); bool bShutdown( false );
if ( pGlobalOfficeIPCThread.is() ) if ( pGlobal.is() )
{ {
if( ! pGlobalOfficeIPCThread->AreRequestsEnabled() ) if( ! pGlobal->AreRequestsEnabled() )
return bShutdown; return bShutdown;
pGlobalOfficeIPCThread->mnPendingRequests += aDispatchList.size(); pGlobal->mnPendingRequests += aDispatchList.size();
if ( !pGlobalOfficeIPCThread->mpDispatchWatcher.is() ) if ( !pGlobal->mpDispatchWatcher.is() )
{ {
pGlobalOfficeIPCThread->mpDispatchWatcher = new DispatchWatcher; pGlobal->mpDispatchWatcher = new DispatchWatcher;
} }
rtl::Reference<DispatchWatcher> dispatchWatcher( rtl::Reference<DispatchWatcher> dispatchWatcher(
pGlobalOfficeIPCThread->mpDispatchWatcher); pGlobal->mpDispatchWatcher);
// copy for execute // copy for execute
std::vector<DispatchWatcher::DispatchRequest> aTempList( aDispatchList ); std::vector<DispatchWatcher::DispatchRequest> aTempList( aDispatchList );

View File

@ -69,12 +69,12 @@ struct ProcessDocumentsRequest
class DispatchWatcher; class DispatchWatcher;
class PipeReaderThread; class PipeReaderThread;
class OfficeIPCThread: public salhelper::SimpleReferenceObject class RequestHandler: public salhelper::SimpleReferenceObject
{ {
friend PipeReaderThread; friend PipeReaderThread;
private: private:
static rtl::Reference< OfficeIPCThread > pGlobalOfficeIPCThread; static rtl::Reference< RequestHandler > pGlobal;
enum class State { Starting, RequestsEnabled, Downing }; enum class State { Starting, RequestsEnabled, Downing };
@ -93,9 +93,9 @@ class OfficeIPCThread: public salhelper::SimpleReferenceObject
static ::osl::Mutex& GetMutex(); static ::osl::Mutex& GetMutex();
OfficeIPCThread(); RequestHandler();
virtual ~OfficeIPCThread(); virtual ~RequestHandler();
public: public:
enum Status enum Status
@ -115,8 +115,8 @@ class OfficeIPCThread: public salhelper::SimpleReferenceObject
ProcessDocumentsRequest&, bool noTerminate); ProcessDocumentsRequest&, bool noTerminate);
// return sal_False if second office // return sal_False if second office
static Status EnableOfficeIPCThread(); static Status Enable();
static void DisableOfficeIPCThread(bool join = true); static void Disable(bool join = true);
// start dispatching events... // start dispatching events...
static void SetReady(); static void SetReady();
static void WaitForReady(); static void WaitForReady();
@ -126,13 +126,13 @@ class OfficeIPCThread: public salhelper::SimpleReferenceObject
}; };
class OfficeIPCThreadController : public ::cppu::WeakImplHelper< class RequestHandlerController : public ::cppu::WeakImplHelper<
css::lang::XServiceInfo, css::lang::XServiceInfo,
css::frame::XTerminateListener > css::frame::XTerminateListener >
{ {
public: public:
OfficeIPCThreadController() {} RequestHandlerController() {}
virtual ~OfficeIPCThreadController() {} virtual ~RequestHandlerController() {}
// XServiceInfo // XServiceInfo
virtual OUString SAL_CALL getImplementationName() virtual OUString SAL_CALL getImplementationName()

View File

@ -1921,7 +1921,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
} }
// This is horrible crack. I really would want to go back to simply just call // This is horrible crack. I really would want to go back to simply just call
// InitVCL() here. The OfficeIPCThread thing is just horrible. // InitVCL() here. The RequestHandler thing is just horrible.
// We could use InitVCL() here -- and used to before using soffice_main, // We could use InitVCL() here -- and used to before using soffice_main,
// however that now deals with the initialisation for us (and it's not // however that now deals with the initialisation for us (and it's not
@ -1934,25 +1934,25 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
// functions depend on VCL being ready -- the deadlocks would happen // functions depend on VCL being ready -- the deadlocks would happen
// if you try to use loadDocument too early. // if you try to use loadDocument too early.
// The OfficeIPCThread is specifically set to be ready when all the other // The RequestHandler is specifically set to be ready when all the other
// init in Desktop::Main (run from soffice_main) is done. We can "enable" // init in Desktop::Main (run from soffice_main) is done. We can "enable"
// the Thread from wherever (it's done again in Desktop::Main), and can // the Thread from wherever (it's done again in Desktop::Main), and can
// then use it to wait until we're definitely ready to continue. // then use it to wait until we're definitely ready to continue.
if (eStage != PRE_INIT) if (eStage != PRE_INIT)
{ {
SAL_INFO("lok", "Enabling OfficeIPCThread"); SAL_INFO("lok", "Enabling RequestHandler");
OfficeIPCThread::EnableOfficeIPCThread(); RequestHandler::Enable();
SAL_INFO("lok", "Starting soffice_main"); SAL_INFO("lok", "Starting soffice_main");
pLib->maThread = osl_createThread(lo_startmain, nullptr); pLib->maThread = osl_createThread(lo_startmain, nullptr);
SAL_INFO("lok", "Waiting for OfficeIPCThread"); SAL_INFO("lok", "Waiting for RequestHandler");
OfficeIPCThread::WaitForReady(); RequestHandler::WaitForReady();
SAL_INFO("lok", "OfficeIPCThread ready -- continuing"); SAL_INFO("lok", "RequestHandler ready -- continuing");
// If the Thread has been disabled again that indicates that a // If the Thread has been disabled again that indicates that a
// restart is required (or in any case we don't have a useable // restart is required (or in any case we don't have a useable
// process around). // process around).
if (!OfficeIPCThread::IsEnabled()) if (!RequestHandler::IsEnabled())
{ {
fprintf(stderr, "LOK init failed -- restart required\n"); fprintf(stderr, "LOK init failed -- restart required\n");
return false; return false;

View File

@ -385,7 +385,7 @@ void SAL_CALL Desktop::addTerminateListener( const css::uno::Reference< css::fra
m_xSfxTerminator = xListener; m_xSfxTerminator = xListener;
return; return;
} }
if( sImplementationName == "com.sun.star.comp.OfficeIPCThreadController" ) if( sImplementationName == "com.sun.star.comp.RequestHandlerController" )
{ {
m_xPipeTerminator = xListener; m_xPipeTerminator = xListener;
return; return;
@ -424,7 +424,7 @@ void SAL_CALL Desktop::removeTerminateListener( const css::uno::Reference< css::
return; return;
} }
if( sImplementationName == "com.sun.star.comp.OfficeIPCThreadController" ) if( sImplementationName == "com.sun.star.comp.RequestHandlerController" )
{ {
m_xPipeTerminator.clear(); m_xPipeTerminator.clear();
return; return;