android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / docnode / retrievedinputstreamdata.cxx
blob311be07ca7190b7a95ac9b2bb29c668bf54197f3
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 .
20 #include <retrievedinputstreamdata.hxx>
21 #include <retrieveinputstreamconsumer.hxx>
22 #include <vcl/svapp.hxx>
24 // #i73788#
26 SwRetrievedInputStreamDataManager::tDataKey SwRetrievedInputStreamDataManager::snNextKeyValue = 1;
28 SwRetrievedInputStreamDataManager& SwRetrievedInputStreamDataManager::GetManager()
30 static SwRetrievedInputStreamDataManager theSwRetrievedInputStreamDataManager;
31 return theSwRetrievedInputStreamDataManager;
34 SwRetrievedInputStreamDataManager::tDataKey SwRetrievedInputStreamDataManager::ReserveData(
35 std::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > const & pThreadConsumer )
37 std::unique_lock aGuard(maMutex);
39 // create empty data container for given thread Consumer
40 tDataKey nDataKey( snNextKeyValue );
41 tData aNewEntry( pThreadConsumer );
42 maInputStreamData[ nDataKey ] = aNewEntry;
44 // prepare next data key value
45 if ( snNextKeyValue < SAL_MAX_UINT64 )
47 ++snNextKeyValue;
49 else
51 snNextKeyValue = 1;
54 return nDataKey;
57 void SwRetrievedInputStreamDataManager::PushData(
58 const tDataKey nDataKey,
59 css::uno::Reference<css::io::XInputStream> const & xInputStream,
60 const bool bIsStreamReadOnly )
62 std::unique_lock aGuard(maMutex);
64 std::map< tDataKey, tData >::iterator aIter = maInputStreamData.find( nDataKey );
66 if ( aIter == maInputStreamData.end() )
67 return;
69 // Fill data container.
70 (*aIter).second.mxInputStream = xInputStream;
71 (*aIter).second.mbIsStreamReadOnly = bIsStreamReadOnly;
73 // post user event to process the retrieved input stream data
74 if ( GetpApp() )
77 tDataKey* pDataKey = new tDataKey;
78 *pDataKey = nDataKey;
79 Application::PostUserEvent( LINK( this, SwRetrievedInputStreamDataManager, LinkedInputStreamReady ), pDataKey );
81 else
83 // no application available -> discard data
84 maInputStreamData.erase( aIter );
88 bool SwRetrievedInputStreamDataManager::PopData( const tDataKey nDataKey,
89 tData& rData )
91 std::unique_lock aGuard(maMutex);
93 bool bDataProvided( false );
95 std::map< tDataKey, tData >::iterator aIter = maInputStreamData.find( nDataKey );
97 if ( aIter != maInputStreamData.end() )
99 rData.mpThreadConsumer = (*aIter).second.mpThreadConsumer;
100 rData.mxInputStream = (*aIter).second.mxInputStream;
101 rData.mbIsStreamReadOnly = (*aIter).second.mbIsStreamReadOnly;
103 maInputStreamData.erase( aIter );
105 bDataProvided = true;
108 return bDataProvided;
111 /** callback function, which is triggered by input stream data manager on
112 filling of the data container to provide retrieved input stream to the
113 thread Consumer using <Application::PostUserEvent(..)>
115 #i73788#
116 Note: This method has to be run in the main thread.
118 IMPL_STATIC_LINK( SwRetrievedInputStreamDataManager, LinkedInputStreamReady,
119 void*, p, void )
121 SwRetrievedInputStreamDataManager::tDataKey* pDataKey = static_cast<SwRetrievedInputStreamDataManager::tDataKey*>(p);
122 if ( !pDataKey )
124 return;
127 SwRetrievedInputStreamDataManager& rDataManager =
128 SwRetrievedInputStreamDataManager::GetManager();
129 SwRetrievedInputStreamDataManager::tData aInputStreamData;
130 if ( rDataManager.PopData( *pDataKey, aInputStreamData ) )
132 std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > pThreadConsumer =
133 aInputStreamData.mpThreadConsumer.lock();
134 if ( pThreadConsumer )
136 pThreadConsumer->ApplyInputStream( aInputStreamData.mxInputStream,
137 aInputStreamData.mbIsStreamReadOnly );
140 delete pDataKey;
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */