22#include <osl/diagnose.h>
23#include <osl/thread.hxx>
27#include <com/sun/star/frame/Desktop.hpp>
28#include <com/sun/star/frame/TerminationVetoException.hpp>
29#include <rtl/ustring.hxx>
42 explicit CancelJobsThread( std::list< css::uno::Reference< css::util::XCancellable > >&& rJobs )
49 void addJobs( std::list< css::uno::Reference< css::util::XCancellable > >& rJobs );
56 css::uno::Reference< css::util::XCancellable >
getNextJob();
59 virtual void SAL_CALL
run()
override;
62 std::list< css::uno::Reference< css::util::XCancellable > >
maJobs;
70 std::scoped_lock aGuard(
maMutex);
72 maJobs.insert(
maJobs.end(), rJobs.begin(), rJobs.end() );
78 std::scoped_lock aGuard(
maMutex);
85 std::scoped_lock aGuard(
maMutex);
92 std::scoped_lock aGuard(
maMutex);
99 css::uno::Reference< css::util::XCancellable > xRet;
102 std::scoped_lock aGuard(
maMutex);
116 std::scoped_lock aGuard(
maMutex);
123 osl_setThreadName(
"sw CancelJobsThread");
129 css::uno::Reference< css::util::XCancellable > aJob(
getNextJob() );
137 std::this_thread::sleep_for(std::chrono::seconds(1));
150 css::uno::Reference< css::uno::XComponentContext > xContext )
160 virtual void SAL_CALL
run()
override;
170 css::uno::Reference< css::uno::XComponentContext >
mxContext;
175 osl::MutexGuard aGuard(
maMutex);
182 osl::MutexGuard aGuard(
maMutex);
189 osl_setThreadName(
"sw TerminateOfficeThread");
193 osl::MutexGuard aGuard(
maMutex);
205 css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create(
mxContext);
207 css::uno::Reference< css::container::XElementAccess > xList = xDesktop->getFrames();
210 OSL_FAIL(
"<TerminateOfficeThread::PerformOfficeTermination()> - no XElementAccess!" );
214 if ( !xList->hasElements() )
217 xDesktop->terminate();
229 mpTerminateOfficeThread( nullptr ),
230 mbRegisteredAtDesktop( false )
237 css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create(
m_xContext);
238 xDesktop->addTerminateListener( css::uno::Reference< css::frame::XTerminateListener >(
this ) );
256 OSL_FAIL(
"<FinalThreadManager::~FinalThreadManager()> - still registered jobs are existing -> perform cancellation" );
263 OSL_FAIL(
"<FinalThreadManager::~FinalThreadManager()> - cancellation of registered jobs not yet finished -> wait for its finish" );
274 return "com.sun.star.util.comp.FinalThreadManager";
284 return {
"com.sun.star.util.JobManager" };
290 osl::MutexGuard aGuard(
maMutex);
303 osl::MutexGuard aGuard(
maMutex);
310 std::list< css::uno::Reference< css::util::XCancellable > > aThreads;
312 osl::MutexGuard aGuard(
maMutex);
318 if ( aThreads.empty() )
321 osl::MutexGuard aGuard(
maMutex);
329 for (
auto const& elem : aThreads)
343 osl::MutexGuard aGuard(
maMutex);
351 std::this_thread::sleep_for(std::chrono::seconds(1));
374 throw css::frame::TerminationVetoException();
408 css::uno::Reference< css::uno::XInterface > aOwnRef(
static_cast< cppu::OWeakObject*
>(
this ));
419extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
421 css::uno::Sequence<css::uno::Any>
const &)
Reference< XComponentContext > m_xContext
thread to cancel a give list of cancellable jobs
void stopWhenAllJobsCancelled()
CancelJobsThread(std::list< css::uno::Reference< css::util::XCancellable > > &&rJobs)
std::list< css::uno::Reference< css::util::XCancellable > > maJobs
css::uno::Reference< css::util::XCancellable > getNextJob()
bool allJobsCancelled() const
virtual void SAL_CALL run() override
void addJobs(std::list< css::uno::Reference< css::util::XCancellable > > &rJobs)
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &Event) override
std::unique_ptr< SwPauseThreadStarting, o3tl::default_delete< SwPauseThreadStarting > > mpPauseThreadStarting
virtual OUString SAL_CALL getImplementationName() override
virtual ~FinalThreadManager() override
void registerAsListenerAtDesktop()
virtual void SAL_CALL releaseJob(const css::uno::Reference< css::util::XCancellable > &Job) override
TerminateOfficeThread * mpTerminateOfficeThread
std::list< css::uno::Reference< css::util::XCancellable > > maThreads
bool mbRegisteredAtDesktop
std::unique_ptr< CancelJobsThread > mpCancelJobsThread
virtual void SAL_CALL registerJob(const css::uno::Reference< css::util::XCancellable > &Job) override
virtual void SAL_CALL cancelAllJobs() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL queryTermination(const css::lang::EventObject &Event) override
FinalThreadManager(css::uno::Reference< css::uno::XComponentContext > context)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL cancelTermination(const css::lang::EventObject &Event) override
Helper class to pause starting of threads during existence of an instance of this class.
thread to terminate office, when all jobs are cancelled.
bool OfficeTerminationStopped()
virtual void SAL_CALL onTerminated() override
void PerformOfficeTermination()
const CancelJobsThread & mrCancelJobsThread
void StopOfficeTermination()
virtual void SAL_CALL run() override
TerminateOfficeThread(CancelJobsThread const &rCancelJobsThread, css::uno::Reference< css::uno::XComponentContext > xContext)
css::uno::Reference< css::uno::XComponentContext > mxContext
bool mbStopOfficeTermination
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_util_comp_FinalThreadManager_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
void ReleaseThreadJoiner()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)