cid#1607171 Data race condition
[LibreOffice.git] / connectivity / source / inc / hsqldb / HStorageMap.hxx
blob1186c680ac07ff6970095f4e6dadec1f29b4198d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 #include <sal/config.h>
23 #include <map>
24 #include <memory>
26 #include <com/sun/star/embed/XStorage.hpp>
27 #include <com/sun/star/embed/XTransactionListener.hpp>
28 #include <com/sun/star/io/XStream.hpp>
29 #include <com/sun/star/io/XOutputStream.hpp>
30 #include <com/sun/star/io/XInputStream.hpp>
31 #include <com/sun/star/io/XSeekable.hpp>
33 #if defined __clang__
34 #pragma clang diagnostic push
35 #pragma clang diagnostic ignored "-Wunknown-attributes"
36 #endif
37 #include <jni.h>
38 #if defined __clang__
39 #pragma clang diagnostic pop
40 #endif
42 #include <uno/environment.hxx>
44 namespace connectivity::hsqldb
46 class StreamHelper
48 css::uno::Reference< css::io::XStream> m_xStream;
49 css::uno::Reference< css::io::XSeekable> m_xSeek;
50 css::uno::Reference< css::io::XOutputStream> m_xOutputStream;
51 css::uno::Reference< css::io::XInputStream> m_xInputStream;
52 public:
53 StreamHelper(const css::uno::Reference< css::io::XStream>& _xStream);
54 ~StreamHelper();
56 css::uno::Reference< css::io::XInputStream> const & getInputStream();
57 css::uno::Reference< css::io::XOutputStream> const & getOutputStream();
58 css::uno::Reference< css::io::XSeekable> const & getSeek();
62 typedef std::map< OUString, std::shared_ptr<StreamHelper> > TStreamMap;
64 struct StorageData {
65 css::uno::Reference<css::embed::XStorage> storage;
66 css::uno::Environment storageEnvironment;
67 OUString url;
68 TStreamMap streams;
70 css::uno::Reference<css::embed::XStorage> mapStorage() const;
73 typedef std::map<OUString, StorageData> TStorages;
74 /** contains all storages so far accessed.
76 class StorageContainer
78 public:
79 static OUString registerStorage(const css::uno::Reference< css::embed::XStorage>& _xStorage,const OUString& _sURL);
80 static TStorages::mapped_type getRegisteredStorage(const OUString& _sKey);
81 static OUString getRegisteredKey(const css::uno::Reference< css::embed::XStorage>& _xStorage);
82 static void revokeStorage(const OUString& _sKey,const css::uno::Reference< css::embed::XTransactionListener>& _xListener);
84 static TStreamMap::mapped_type registerStream(JNIEnv * env,jstring name, jstring key,sal_Int32 _nMode);
85 static void revokeStream(JNIEnv * env,jstring name, jstring key);
86 static TStreamMap::mapped_type getRegisteredStream( JNIEnv * env, jstring name, jstring key);
88 static OUString jstring2ustring(JNIEnv * env, jstring jstr);
89 static OUString removeURLPrefix(std::u16string_view _sURL, std::u16string_view _sFileURL);
90 static OUString removeOldURLPrefix(const OUString& _sURL);
91 static void throwJavaException(const css::uno::Exception& _aException,JNIEnv * env);
94 } // namespace connectivity::hsqldb
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */