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  osl::MutexGuard 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  {
51  snNextKeyValue = 1;
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  osl::MutexGuard 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  osl::MutexGuard 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  LinkedInputStreamReady,
120  void*, p, void )
121 {
123  if ( !pDataKey )
124  {
125  return;
126  }
127 
128  osl::MutexGuard aGuard(maMutex);
129 
130  SwRetrievedInputStreamDataManager& rDataManager =
133  if ( rDataManager.PopData( *pDataKey, aInputStreamData ) )
134  {
135  std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > pThreadConsumer =
136  aInputStreamData.mpThreadConsumer.lock();
137  if ( pThreadConsumer )
138  {
139  pThreadConsumer->ApplyInputStream( aInputStreamData.mxInputStream,
140  aInputStreamData.mbIsStreamReadOnly );
141  }
142  }
143  delete pDataKey;
144 }
145 
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Singleton class to manage retrieved input stream data in Writer.
bool PopData(const tDataKey nDataKey, tData &rData)
IMPL_LINK(SwRetrievedInputStreamDataManager, LinkedInputStreamReady, void *, p, void)
callback function, which is triggered by input stream data manager on filling of the data container t...
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
std::mutex maMutex
void PushData(const tDataKey nDataKey, css::uno::Reference< css::io::XInputStream > const &xInputStream, const bool bIsStreamReadOnly)
std::map< tDataKey, tData > maInputStreamData
std::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer
Application * GetpApp()
css::uno::Reference< css::io::XInputStream > mxInputStream
#define SAL_MAX_UINT64
static SwRetrievedInputStreamDataManager & GetManager()
tDataKey ReserveData(std::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > const &pThreadConsumer)
void * p