1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _RETRIEVEDINPUTSTREAMDATA_HXX 24 #define _RETRIEVEDINPUTSTREAMDATA_HXX 25 26 #include <tools/link.hxx> 27 #include <sal/types.h> 28 #include <osl/mutex.hxx> 29 #include <com/sun/star/uno/Reference.hxx> 30 #ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HXX_ 31 #include <com/sun/star/io/XInputStream.hpp> 32 #endif 33 34 #include <map> 35 36 #include <boost/weak_ptr.hpp> 37 class SwAsyncRetrieveInputStreamThreadConsumer; 38 //#ifndef _RETRIEVEINPUTSTREAMCONSUMER_HXX 39 //#include <retrieveinputstreamconsumer.hxx> 40 //#endif 41 42 /** Singleton class to manage retrieved input stream data in Writer 43 44 OD 2007-01-29 #i73788# 45 The instance of this class provides data container for retrieved input 46 stream data. The data container is accessed via a key, which the data 47 manager provides on creation of the data container. 48 When a certain data container is filled with data, an user event is submitted 49 to trigger the processing of with data. 50 51 @author OD 52 */ 53 class SwRetrievedInputStreamDataManager 54 { 55 public: 56 57 typedef sal_uInt64 tDataKey; 58 59 struct tData 60 { 61 boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer; 62 com::sun::star::uno::Reference<com::sun::star::io::XInputStream> mxInputStream; 63 sal_Bool mbIsStreamReadOnly; 64 tDataSwRetrievedInputStreamDataManager::tData65 tData() 66 : mpThreadConsumer(), 67 mbIsStreamReadOnly( sal_False ) 68 {}; 69 tDataSwRetrievedInputStreamDataManager::tData70 tData( boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > pThreadConsumer ) 71 : mpThreadConsumer( pThreadConsumer ), 72 mbIsStreamReadOnly( sal_False ) 73 {}; 74 }; 75 76 static SwRetrievedInputStreamDataManager& GetManager(); 77 ~SwRetrievedInputStreamDataManager()78 ~SwRetrievedInputStreamDataManager() 79 { 80 }; 81 82 tDataKey ReserveData( boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > pThreadConsumer ); 83 84 void PushData( const tDataKey nDataKey, 85 com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream, 86 const sal_Bool bIsStreamReadOnly ); 87 88 bool PopData( const tDataKey nDataKey, 89 tData& rData ); 90 91 DECL_LINK( LinkedInputStreamReady, SwRetrievedInputStreamDataManager::tDataKey* ); 92 93 private: 94 95 static SwRetrievedInputStreamDataManager* mpManager; 96 static tDataKey mnNextKeyValue; 97 static osl::Mutex maGetManagerMutex; 98 99 osl::Mutex maMutex; 100 101 std::map< tDataKey, tData > maInputStreamData; 102 SwRetrievedInputStreamDataManager()103 SwRetrievedInputStreamDataManager() 104 { 105 }; 106 }; 107 #endif 108