LibreOffice Module sw (master) 1
retrievedinputstreamdata.cxx
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
22#include <vcl/svapp.hxx>
23
24// #i73788#
25
27
29{
30 static SwRetrievedInputStreamDataManager theSwRetrievedInputStreamDataManager;
31 return theSwRetrievedInputStreamDataManager;
32}
33
35 std::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > const & pThreadConsumer )
36{
37 std::unique_lock aGuard(maMutex);
38
39 // create empty data container for given thread Consumer
40 tDataKey nDataKey( snNextKeyValue );
41 tData aNewEntry( pThreadConsumer );
42 maInputStreamData[ nDataKey ] = aNewEntry;
43
44 // prepare next data key value
46 {
48 }
49 else
50 {
52 }
53
54 return nDataKey;
55}
56
58 const tDataKey nDataKey,
59 css::uno::Reference<css::io::XInputStream> const & xInputStream,
60 const bool bIsStreamReadOnly )
61{
62 std::unique_lock aGuard(maMutex);
63
64 std::map< tDataKey, tData >::iterator aIter = maInputStreamData.find( nDataKey );
65
66 if ( aIter == maInputStreamData.end() )
67 return;
68
69 // Fill data container.
70 (*aIter).second.mxInputStream = xInputStream;
71 (*aIter).second.mbIsStreamReadOnly = bIsStreamReadOnly;
72
73 // post user event to process the retrieved input stream data
74 if ( GetpApp() )
75 {
76
77 tDataKey* pDataKey = new tDataKey;
78 *pDataKey = nDataKey;
79 Application::PostUserEvent( LINK( this, SwRetrievedInputStreamDataManager, LinkedInputStreamReady ), pDataKey );
80 }
81 else
82 {
83 // no application available -> discard data
84 maInputStreamData.erase( aIter );
85 }
86}
87
89 tData& rData )
90{
91 std::unique_lock aGuard(maMutex);
92
93 bool bDataProvided( false );
94
95 std::map< tDataKey, tData >::iterator aIter = maInputStreamData.find( nDataKey );
96
97 if ( aIter != maInputStreamData.end() )
98 {
99 rData.mpThreadConsumer = (*aIter).second.mpThreadConsumer;
100 rData.mxInputStream = (*aIter).second.mxInputStream;
101 rData.mbIsStreamReadOnly = (*aIter).second.mbIsStreamReadOnly;
102
103 maInputStreamData.erase( aIter );
104
105 bDataProvided = true;
106 }
107
108 return bDataProvided;
109}
110
119 void*, p, void )
120{
122 if ( !pDataKey )
123 {
124 return;
125 }
126
130 if ( rDataManager.PopData( *pDataKey, aInputStreamData ) )
131 {
132 std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > pThreadConsumer =
133 aInputStreamData.mpThreadConsumer.lock();
134 if ( pThreadConsumer )
135 {
136 pThreadConsumer->ApplyInputStream( aInputStreamData.mxInputStream,
137 aInputStreamData.mbIsStreamReadOnly );
138 }
139 }
140 delete pDataKey;
141}
142
143/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
Singleton class to manage retrieved input stream data in Writer.
tDataKey ReserveData(std::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > const &pThreadConsumer)
static SwRetrievedInputStreamDataManager & GetManager()
bool PopData(const tDataKey nDataKey, tData &rData)
std::map< tDataKey, tData > maInputStreamData
void PushData(const tDataKey nDataKey, css::uno::Reference< css::io::XInputStream > const &xInputStream, const bool bIsStreamReadOnly)
void * p
IMPL_STATIC_LINK(SwRetrievedInputStreamDataManager, LinkedInputStreamReady, void *, p, void)
callback function, which is triggered by input stream data manager on filling of the data container t...
std::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer
css::uno::Reference< css::io::XInputStream > mxInputStream
VCL_DLLPUBLIC Application * GetpApp()
#define SAL_MAX_UINT64