LibreOffice Module connectivity (master) 1
CConnection.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
29namespace com::sun::star {
30 namespace sheet { class XSpreadsheetDocument; }
31}
32
33namespace utl { class CloseVeto; }
34
35
36namespace connectivity::calc
37 {
38 class ODriver;
40 {
41 // the spreadsheet document:
42 css::uno::Reference< css::sheet::XSpreadsheetDocument > m_xDoc;
43 OUString m_sPassword;
44 OUString m_aFileName;
45 oslInterlockedCount m_nDocCount;
46
47 class CloseVetoButTerminateListener : public cppu::WeakComponentImplHelper<css::frame::XTerminateListener>
48 {
49 private:
51 std::unique_ptr<utl::CloseVeto> m_pCloseListener;
54 css::uno::Reference<css::frame::XDesktop2> m_xDesktop;
55 osl::Mutex m_aMutex;
56 public:
58 : cppu::WeakComponentImplHelper<css::frame::XTerminateListener>(m_aMutex)
59 {
60 }
61
62 void start(const css::uno::Reference<css::uno::XInterface>& rCloseable,
63 const css::uno::Reference<css::frame::XDesktop2>& rDesktop)
64 {
65 m_xDesktop = rDesktop;
66 m_xDesktop->addTerminateListener(this);
67 m_pCloseListener.reset(new utl::CloseVeto(rCloseable, true));
68 }
69
70 void stop()
71 {
72 m_pCloseListener.reset();
73 if (!m_xDesktop.is())
74 return;
75 m_xDesktop->removeTerminateListener(this);
76 m_xDesktop.clear();
77 }
78
79 // XTerminateListener
80 virtual void SAL_CALL queryTermination(const css::lang::EventObject& /*rEvent*/) override
81 {
82 }
83
84 virtual void SAL_CALL notifyTermination(const css::lang::EventObject& /*rEvent*/) override
85 {
86 stop();
87 }
88
89 virtual void SAL_CALL disposing() override
90 {
91 stop();
92 cppu::WeakComponentImplHelperBase::disposing();
93 }
94
95 virtual void SAL_CALL disposing(const css::lang::EventObject& rEvent) override
96 {
97 const bool bShutDown = (rEvent.Source == m_xDesktop);
98 if (bShutDown)
99 stop();
100 }
101 };
102
104
105 public:
106 OCalcConnection(ODriver* _pDriver);
107 virtual ~OCalcConnection() override;
108
109 virtual void construct(const OUString& _rUrl,
110 const css::uno::Sequence< css::beans::PropertyValue >& _rInfo ) override;
111
112 // XServiceInfo
114
115 // OComponentHelper
116 virtual void SAL_CALL disposing() override;
117
118 // XConnection
119 virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override;
120 virtual css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog() override;
121 virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override;
122 virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override;
123 virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override;
124
125 // no interface methods
126 css::uno::Reference< css::sheet::XSpreadsheetDocument> const & acquireDoc();
127 void releaseDoc();
128
130 {
132 css::uno::Reference< css::sheet::XSpreadsheetDocument> m_xDoc;
133 public:
134 ODocHolder(OCalcConnection* _pConnection) : m_pConnection(_pConnection)
135 {
137 }
139 {
140 m_xDoc.clear();
142 }
143 const css::uno::Reference< css::sheet::XSpreadsheetDocument>& getDoc() const { return m_xDoc; }
144 };
145 };
146
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL disposing(const css::lang::EventObject &rEvent) override
Definition: CConnection.hxx:95
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: CConnection.hxx:54
std::unique_ptr< utl::CloseVeto > m_pCloseListener
close listener that vetoes so nobody else disposes m_xDoc
Definition: CConnection.hxx:51
void start(const css::uno::Reference< css::uno::XInterface > &rCloseable, const css::uno::Reference< css::frame::XDesktop2 > &rDesktop)
Definition: CConnection.hxx:62
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &) override
Definition: CConnection.hxx:84
virtual void SAL_CALL queryTermination(const css::lang::EventObject &) override
Definition: CConnection.hxx:80
css::uno::Reference< css::sheet::XSpreadsheetDocument > m_xDoc
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDoc() const
ODocHolder(OCalcConnection *_pConnection)
css::uno::Reference< css::sheet::XSpreadsheetDocument > const & acquireDoc()
Definition: CConnection.cxx:99
css::uno::Reference< css::sheet::XSpreadsheetDocument > m_xDoc
Definition: CConnection.hxx:42
virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() override
virtual void construct(const OUString &_rUrl, const css::uno::Sequence< css::beans::PropertyValue > &_rInfo) override
Definition: CConnection.cxx:59
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString &sql) override
rtl::Reference< CloseVetoButTerminateListener > m_xCloseVetoButTerminateListener
virtual css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
virtual void SAL_CALL disposing() override
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override