LibreOffice Module connectivity (master) 1
WConnection.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <memory>
23#include <file/FConnection.hxx>
24#include <com/sun/star/frame/XDesktop2.hpp>
25#include <com/sun/star/frame/XTerminateListener.hpp>
26#include <rtl/ref.hxx>
28
30{
31class XTextDocument;
32}
33namespace utl
34{
35class CloseVeto;
36}
37
39{
40class ODriver;
42{
43 // the text document:
44 css::uno::Reference<css::text::XTextDocument> m_xDoc;
45 OUString m_sPassword;
46 OUString m_aFileName;
47 oslInterlockedCount m_nDocCount = 0;
48
50 : public cppu::WeakComponentImplHelper<css::frame::XTerminateListener>
51 {
52 private:
54 std::unique_ptr<utl::CloseVeto> m_pCloseListener;
57 css::uno::Reference<css::frame::XDesktop2> m_xDesktop;
58 osl::Mutex m_aMutex;
59
60 public:
62 : cppu::WeakComponentImplHelper<css::frame::XTerminateListener>(m_aMutex)
63 {
64 }
65
66 void start(const css::uno::Reference<css::uno::XInterface>& rCloseable,
67 const css::uno::Reference<css::frame::XDesktop2>& rDesktop)
68 {
69 m_xDesktop = rDesktop;
70 m_xDesktop->addTerminateListener(this);
71 m_pCloseListener = std::make_unique<utl::CloseVeto>(rCloseable, true);
72 }
73
74 void stop()
75 {
76 m_pCloseListener.reset();
77 if (!m_xDesktop.is())
78 return;
79 m_xDesktop->removeTerminateListener(this);
80 m_xDesktop.clear();
81 }
82
83 // XTerminateListener
84 void SAL_CALL queryTermination(const css::lang::EventObject& /*rEvent*/) override {}
85
86 void SAL_CALL notifyTermination(const css::lang::EventObject& /*rEvent*/) override
87 {
88 stop();
89 }
90
91 void SAL_CALL disposing() override
92 {
93 stop();
94 cppu::WeakComponentImplHelperBase::disposing();
95 }
96
97 void SAL_CALL disposing(const css::lang::EventObject& rEvent) override
98 {
99 const bool bShutDown = (rEvent.Source == m_xDesktop);
100 if (bShutDown)
101 stop();
102 }
103 };
104
106
107public:
108 OWriterConnection(ODriver* _pDriver);
110
111 void construct(const OUString& rURL,
112 const css::uno::Sequence<css::beans::PropertyValue>& rInfo) override;
113
114 // XServiceInfo
116
117 // OComponentHelper
118 void SAL_CALL disposing() override;
119
120 // XConnection
121 css::uno::Reference<css::sdbc::XDatabaseMetaData> SAL_CALL getMetaData() override;
122 css::uno::Reference<css::sdbcx::XTablesSupplier> createCatalog() override;
123 css::uno::Reference<css::sdbc::XStatement> SAL_CALL createStatement() override;
124 css::uno::Reference<css::sdbc::XPreparedStatement>
125 SAL_CALL prepareStatement(const OUString& sql) override;
126 css::uno::Reference<css::sdbc::XPreparedStatement>
127 SAL_CALL prepareCall(const OUString& sql) override;
128
129 // no interface methods
130 css::uno::Reference<css::text::XTextDocument> const& acquireDoc();
131 void releaseDoc();
132
134 {
136 css::uno::Reference<css::text::XTextDocument> m_xDoc;
137
138 public:
140 : m_pConnection(_pConnection)
141 {
143 }
145 {
146 m_xDoc.clear();
148 }
149 const css::uno::Reference<css::text::XTextDocument>& getDoc() const { return m_xDoc; }
150 };
151};
152}
153
154/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< utl::CloseVeto > m_pCloseListener
close listener that vetoes so nobody else disposes m_xDoc
Definition: WConnection.hxx:54
void SAL_CALL disposing(const css::lang::EventObject &rEvent) override
Definition: WConnection.hxx:97
css::uno::Reference< css::frame::XDesktop2 > m_xDesktop
but also listen to XDesktop and if app is terminating anyway, dispose m_xDoc while its still possible...
Definition: WConnection.hxx:57
void start(const css::uno::Reference< css::uno::XInterface > &rCloseable, const css::uno::Reference< css::frame::XDesktop2 > &rDesktop)
Definition: WConnection.hxx:66
void SAL_CALL queryTermination(const css::lang::EventObject &) override
Definition: WConnection.hxx:84
void SAL_CALL notifyTermination(const css::lang::EventObject &) override
Definition: WConnection.hxx:86
const css::uno::Reference< css::text::XTextDocument > & getDoc() const
css::uno::Reference< css::text::XTextDocument > m_xDoc
ODocHolder(OWriterConnection *_pConnection)
css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override
css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString &sql) override
rtl::Reference< CloseVetoButTerminateListener > m_xCloseVetoButTerminateListener
css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog() override
css::uno::Reference< css::text::XTextDocument > m_xDoc
Definition: WConnection.hxx:44
void SAL_CALL disposing() override
css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() override
void construct(const OUString &rURL, const css::uno::Sequence< css::beans::PropertyValue > &rInfo) override
Definition: WConnection.cxx:50
css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
css::uno::Reference< css::text::XTextDocument > const & acquireDoc()
Definition: WConnection.cxx:91