LibreOffice Module dbaccess (master) 1
connectiondependent.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 <com/sun/star/sdbc/XConnection.hpp>
23#include <com/sun/star/lang/DisposedException.hpp>
24#include <com/sun/star/uno/XComponentContext.hpp>
25
27#include <osl/mutex.hxx>
28#include <utility>
29
30namespace sdbtools
31{
32
33 // ConnectionDependentComponent
35 {
36 private:
37 mutable ::osl::Mutex m_aMutex;
38 css::uno::WeakReference< css::sdbc::XConnection >
40 css::uno::Reference< css::uno::XComponentContext >
42
49 css::uno::Reference< css::sdbc::XConnection >
51
52 protected:
53 ::osl::Mutex& getMutex() const { return m_aMutex; }
54
55 const css::uno::Reference< css::uno::XComponentContext >&
56 getContext() const { return m_aContext; }
57
58 protected:
59 class EntryGuard;
60
61 protected:
62 explicit ConnectionDependentComponent( css::uno::Reference< css::uno::XComponentContext > _xContext )
63 :m_aContext(std::move( _xContext ))
64 {
65 }
66
74 void setWeakConnection( const css::uno::Reference< css::sdbc::XConnection >& _rxConnection )
75 {
76 m_aConnection = _rxConnection;
77 }
78
79 const css::uno::Reference< css::sdbc::XConnection >&
80 getConnection() const { return m_xConnection; }
81
82 public:
83 struct GuardAccess;
84 friend struct GuardAccess;
87 struct GuardAccess { friend class EntryGuard; private: GuardAccess() { } };
88
89 ::osl::Mutex& getMutex( GuardAccess ) const { return m_aMutex; }
90
92 {
94 return m_xConnection.is();
95 }
97 {
98 m_xConnection.clear();
99 }
100 };
101
102 // ConnectionDependentComponent::EntryGuard
114 {
115 private:
116 ::osl::MutexGuard m_aMutexGuard;
118
119 public:
122 ,m_rComponent( _rComponent )
123 {
125 throw css::lang::DisposedException();
126 }
127
129 {
131 }
132 };
133
134} // namespace sdbtools
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
a class for guarding methods of a connection-dependent component
EntryGuard(ConnectionDependentComponent &_rComponent)
css::uno::WeakReference< css::sdbc::XConnection > m_aConnection
ConnectionDependentComponent(css::uno::Reference< css::uno::XComponentContext > _xContext)
const css::uno::Reference< css::uno::XComponentContext > & getContext() const
const css::uno::Reference< css::sdbc::XConnection > & getConnection() const
css::uno::Reference< css::uno::XComponentContext > m_aContext
void setWeakConnection(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection)
sets the connection we depend on.
css::uno::Reference< css::sdbc::XConnection > m_xConnection
a hard reference to the connection we're working for
::osl::Mutex & getMutex(GuardAccess) const
helper for granting exclusive access to various other methods
Reference< XComponentContext > _xContext