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 #ifndef INCLUDED_SOT_SOURCE_UNOOLESTORAGE_XOLESIMPLESTORAGE_HXX
21 #define INCLUDED_SOT_SOURCE_UNOOLESTORAGE_XOLESIMPLESTORAGE_HXX
22 
23 #include <sal/config.h>
24 
25 #include <memory>
26 
27 #include <com/sun/star/embed/XOLESimpleStorage.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <cppuhelper/implbase.hxx>
30 
31 #include <osl/mutex.hxx>
32 
33 namespace com::sun::star::container { class XNameAccess; }
34 namespace com::sun::star::io { class XInputStream; }
35 namespace com::sun::star::io { class XStream; }
36 namespace com::sun::star::lang { class XEventListener; }
37 namespace com::sun::star::uno { class XComponentContext; }
38 namespace comphelper { class OInterfaceContainerHelper2; }
39 
40 class BaseStorage;
41 class SvStream;
42 
43 class OLESimpleStorage : public cppu::WeakImplHelper<css::embed::XOLESimpleStorage, css::lang::XServiceInfo>
44 {
45     ::osl::Mutex m_aMutex;
46 
47     bool m_bDisposed;
48 
49     css::uno::Reference< css::io::XStream > m_xStream;
50     css::uno::Reference< css::io::XStream > m_xTempStream;
51     std::unique_ptr<SvStream> m_pStream;
52     std::unique_ptr<BaseStorage> m_pStorage;
53 
54     ::comphelper::OInterfaceContainerHelper2* m_pListenersContainer; // list of listeners
55     css::uno::Reference<css::uno::XComponentContext> m_xContext;
56 
57     bool m_bNoTemporaryCopy;
58 
59     void UpdateOriginal_Impl();
60 
61     /// @throws css::uno::Exception
62     static void InsertInputStreamToStorage_Impl( BaseStorage* pStorage, const OUString & aName, const css::uno::Reference< css::io::XInputStream >& xInputStream );
63 
64     /// @throws css::uno::Exception
65     static void InsertNameAccessToStorage_Impl( BaseStorage* pStorage, const OUString & aName, const css::uno::Reference< css::container::XNameAccess >& xNameAccess );
66 
67 public:
68 
69     OLESimpleStorage(css::uno::Reference<css::uno::XComponentContext> const & xContext,
70             css::uno::Sequence<css::uno::Any> const &arguments);
71 
72     virtual ~OLESimpleStorage() override;
73 
74     //  XNameContainer
75 
76     virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override;
77 
78     virtual void SAL_CALL removeByName( const OUString& Name ) override;
79 
80     virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;
81 
82     virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
83 
84     virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
85 
86     virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
87 
88     virtual css::uno::Type SAL_CALL getElementType() override;
89 
90     virtual sal_Bool SAL_CALL hasElements() override;
91 
92     //  XComponent
93 
94     virtual void SAL_CALL dispose() final override;
95 
96     virtual void SAL_CALL addEventListener(
97             const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
98 
99     virtual void SAL_CALL removeEventListener(
100             const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
101 
102     //  XTransactedObject
103 
104     virtual void SAL_CALL commit() override;
105 
106     virtual void SAL_CALL revert() override;
107 
108     //  XClassifiedObject
109 
110     virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL getClassID() override;
111 
112     virtual OUString SAL_CALL getClassName() override;
113 
114     virtual void SAL_CALL setClassInfo( const css::uno::Sequence< ::sal_Int8 >& aClassID,
115                                         const OUString& sClassName ) override;
116 
117     //  XServiceInfo
118 
119     virtual OUString SAL_CALL getImplementationName() override;
120 
121     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
122 
123     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
124 };
125 
126 #endif
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
129