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 
28 namespace
29 {
30  class theSwRetrievedInputStreamDataManager :
31  public rtl::Static< SwRetrievedInputStreamDataManager, theSwRetrievedInputStreamDataManager>
32  {
33  };
34 }
35 
37 {
39 }
40 
42  std::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > const & pThreadConsumer )
43 {
44  osl::MutexGuard aGuard(maMutex);
45 
46  // create empty data container for given thread Consumer
47  tDataKey nDataKey( mnNextKeyValue );
48  tData aNewEntry( pThreadConsumer );
49  maInputStreamData[ nDataKey ] = aNewEntry;
50 
51  // prepare next data key value
53  {
55  }
56  else
57  {
58  mnNextKeyValue = 1;
59  }
60 
61  return nDataKey;
62 }
63 
65  const tDataKey nDataKey,
66  css::uno::Reference<css::io::XInputStream> const & xInputStream,
67  const bool bIsStreamReadOnly )
68 {
69  osl::MutexGuard aGuard(maMutex);
70 
71  std::map< tDataKey, tData >::iterator aIter = maInputStreamData.find( nDataKey );
72 
73  if ( aIter != maInputStreamData.end() )
74  {
75  // Fill data container.
76  (*aIter).second.mxInputStream = xInputStream;
77  (*aIter).second.mbIsStreamReadOnly = bIsStreamReadOnly;
78 
79  // post user event to process the retrieved input stream data
80  if ( GetpApp() )
81  {
82 
83  tDataKey* pDataKey = new tDataKey;
84  *pDataKey = nDataKey;
85  Application::PostUserEvent( LINK( this, SwRetrievedInputStreamDataManager, LinkedInputStreamReady ), pDataKey );
86  }
87  else
88  {
89  // no application available -> discard data
90  maInputStreamData.erase( aIter );
91  }
92  }
93 }
94 
96  tData& rData )
97 {
98  osl::MutexGuard aGuard(maMutex);
99 
100  bool bDataProvided( false );
101 
102  std::map< tDataKey, tData >::iterator aIter = maInputStreamData.find( nDataKey );
103 
104  if ( aIter != maInputStreamData.end() )
105  {
106  rData.mpThreadConsumer = (*aIter).second.mpThreadConsumer;
107  rData.mxInputStream = (*aIter).second.mxInputStream;
108  rData.mbIsStreamReadOnly = (*aIter).second.mbIsStreamReadOnly;
109 
110  maInputStreamData.erase( aIter );
111 
112  bDataProvided = true;
113  }
114 
115  return bDataProvided;
116 }
117 
126  LinkedInputStreamReady,
127  void*, p, void )
128 {
130  if ( !pDataKey )
131  {
132  return;
133  }
134 
135  osl::MutexGuard aGuard(maMutex);
136 
137  SwRetrievedInputStreamDataManager& rDataManager =
140  if ( rDataManager.PopData( *pDataKey, aInputStreamData ) )
141  {
142  std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > pThreadConsumer =
143  aInputStreamData.mpThreadConsumer.lock();
144  if ( pThreadConsumer )
145  {
146  pThreadConsumer->ApplyInputStream( aInputStreamData.mxInputStream,
147  aInputStreamData.mbIsStreamReadOnly );
148  }
149  }
150  delete pDataKey;
151 }
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Singleton class to manage retrieved input stream data in Writer.
bool PopData(const tDataKey nDataKey, tData &rData)
::osl::Mutex maMutex
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)
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)