xref: /trunk/main/io/source/stm/opipe.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*3716f815SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3716f815SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3716f815SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3716f815SAndrew Rist  * distributed with this work for additional information
6*3716f815SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3716f815SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3716f815SAndrew Rist  * "License"); you may not use this file except in compliance
9*3716f815SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*3716f815SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*3716f815SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3716f815SAndrew Rist  * software distributed under the License is distributed on an
15*3716f815SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3716f815SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3716f815SAndrew Rist  * specific language governing permissions and limitations
18*3716f815SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*3716f815SAndrew Rist  *************************************************************/
21*3716f815SAndrew Rist 
22*3716f815SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_io.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // streams
28cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
29cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
30cdf0e10cSrcweir #include <com/sun/star/io/XConnectable.hpp>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx>      // OWeakObject
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <osl/conditn.hxx>
39cdf0e10cSrcweir #include <osl/mutex.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <limits>
42cdf0e10cSrcweir #include <string.h>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace ::rtl;
45cdf0e10cSrcweir using namespace ::osl;
46cdf0e10cSrcweir using namespace ::cppu;
47cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir using namespace ::com::sun::star::io;
49cdf0e10cSrcweir using namespace ::com::sun::star::lang;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include "factreg.hxx"
52cdf0e10cSrcweir #include "streamhelper.hxx"
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // Implementation and service names
55cdf0e10cSrcweir #define IMPLEMENTATION_NAME "com.sun.star.comp.io.stm.Pipe"
56cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.io.Pipe"
57cdf0e10cSrcweir 
58cdf0e10cSrcweir namespace io_stm{
59cdf0e10cSrcweir 
60cdf0e10cSrcweir class OPipeImpl :
61cdf0e10cSrcweir     public WeakImplHelper4< XInputStream , XOutputStream , XConnectable , XServiceInfo >
62cdf0e10cSrcweir {
63cdf0e10cSrcweir public:
64cdf0e10cSrcweir     OPipeImpl( );
65cdf0e10cSrcweir     ~OPipeImpl();
66cdf0e10cSrcweir 
67cdf0e10cSrcweir public: // XInputStream
68cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead)
69cdf0e10cSrcweir         throw(  NotConnectedException,
70cdf0e10cSrcweir                 BufferSizeExceededException,
71cdf0e10cSrcweir                 RuntimeException );
72cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead)
73cdf0e10cSrcweir         throw( NotConnectedException,
74cdf0e10cSrcweir                BufferSizeExceededException,
75cdf0e10cSrcweir                RuntimeException );
76cdf0e10cSrcweir     virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip)
77cdf0e10cSrcweir         throw( NotConnectedException,
78cdf0e10cSrcweir                BufferSizeExceededException,
79cdf0e10cSrcweir                RuntimeException );
80cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL available(void)
81cdf0e10cSrcweir         throw( NotConnectedException,
82cdf0e10cSrcweir                RuntimeException );
83cdf0e10cSrcweir     virtual void SAL_CALL closeInput(void)
84cdf0e10cSrcweir         throw( NotConnectedException,
85cdf0e10cSrcweir                RuntimeException );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir public: // XOutputStream
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     virtual void SAL_CALL writeBytes(const Sequence< sal_Int8 >& aData)
90cdf0e10cSrcweir         throw( NotConnectedException,
91cdf0e10cSrcweir                BufferSizeExceededException,
92cdf0e10cSrcweir                RuntimeException );
93cdf0e10cSrcweir     virtual void SAL_CALL flush(void)
94cdf0e10cSrcweir         throw( NotConnectedException,
95cdf0e10cSrcweir                BufferSizeExceededException,
96cdf0e10cSrcweir                RuntimeException );
97cdf0e10cSrcweir     virtual void SAL_CALL closeOutput(void)
98cdf0e10cSrcweir         throw( NotConnectedException,
99cdf0e10cSrcweir                BufferSizeExceededException,
100cdf0e10cSrcweir                RuntimeException );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir public: // XConnectable
103cdf0e10cSrcweir     virtual void SAL_CALL setPredecessor(const Reference< XConnectable >& aPredecessor)
104cdf0e10cSrcweir         throw( RuntimeException );
105cdf0e10cSrcweir     virtual Reference< XConnectable > SAL_CALL getPredecessor(void) throw( RuntimeException );
106cdf0e10cSrcweir     virtual void SAL_CALL setSuccessor(const Reference < XConnectable > & aSuccessor)
107cdf0e10cSrcweir         throw( RuntimeException );
108cdf0e10cSrcweir     virtual Reference < XConnectable > SAL_CALL getSuccessor(void) throw( RuntimeException ) ;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir public: // XServiceInfo
112cdf0e10cSrcweir     OUString                    SAL_CALL getImplementationName() throw(  );
113cdf0e10cSrcweir     Sequence< OUString >         SAL_CALL getSupportedServiceNames(void) throw(  );
114cdf0e10cSrcweir     sal_Bool                        SAL_CALL supportsService(const OUString& ServiceName) throw(  );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir private:
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     // DEBUG
119cdf0e10cSrcweir     inline void checkInvariant();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     Reference < XConnectable >  m_succ;
122cdf0e10cSrcweir     Reference < XConnectable >  m_pred;
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     sal_Int32 m_nBytesToSkip;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     sal_Int8  *m_p;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     sal_Bool m_bOutputStreamClosed;
129cdf0e10cSrcweir     sal_Bool m_bInputStreamClosed;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     oslCondition m_conditionBytesAvail;
132cdf0e10cSrcweir     Mutex     m_mutexAccess;
133cdf0e10cSrcweir     IFIFO       *m_pFIFO;
134cdf0e10cSrcweir };
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 
OPipeImpl()138cdf0e10cSrcweir OPipeImpl::OPipeImpl()
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
141cdf0e10cSrcweir     m_nBytesToSkip  = 0;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     m_bOutputStreamClosed   = sal_False;
144cdf0e10cSrcweir     m_bInputStreamClosed    = sal_False;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     m_pFIFO = new MemFIFO;
147cdf0e10cSrcweir     m_conditionBytesAvail = osl_createCondition();
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
~OPipeImpl()150cdf0e10cSrcweir OPipeImpl::~OPipeImpl()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     osl_destroyCondition( m_conditionBytesAvail );
153cdf0e10cSrcweir     delete m_pFIFO;
154cdf0e10cSrcweir     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 
158cdf0e10cSrcweir // These invariants must hold when entering a guarded method or leaving a guarded method.
checkInvariant()159cdf0e10cSrcweir void OPipeImpl::checkInvariant()
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
readBytes(Sequence<sal_Int8> & aData,sal_Int32 nBytesToRead)164cdf0e10cSrcweir sal_Int32 OPipeImpl::readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead)
165cdf0e10cSrcweir     throw( NotConnectedException, BufferSizeExceededException,RuntimeException )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir     while( sal_True )
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         { // start guarded section
170cdf0e10cSrcweir             MutexGuard guard( m_mutexAccess );
171cdf0e10cSrcweir             if( m_bInputStreamClosed )
172cdf0e10cSrcweir             {
173cdf0e10cSrcweir                 throw NotConnectedException(
174cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM( "Pipe::readBytes NotConnectedException" )),
175cdf0e10cSrcweir                     *this );
176cdf0e10cSrcweir             }
177cdf0e10cSrcweir             sal_Int32 nOccupiedBufferLen = m_pFIFO->getSize();
178cdf0e10cSrcweir 
179cdf0e10cSrcweir             if( m_bOutputStreamClosed && nBytesToRead > nOccupiedBufferLen )
180cdf0e10cSrcweir             {
181cdf0e10cSrcweir                 nBytesToRead = nOccupiedBufferLen;
182cdf0e10cSrcweir             }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir             if( nOccupiedBufferLen < nBytesToRead )
185cdf0e10cSrcweir             {
186cdf0e10cSrcweir                 // wait outside guarded section
187cdf0e10cSrcweir                 osl_resetCondition( m_conditionBytesAvail );
188cdf0e10cSrcweir             }
189cdf0e10cSrcweir             else {
190cdf0e10cSrcweir                 // necessary bytes are available
191cdf0e10cSrcweir                 m_pFIFO->read( aData , nBytesToRead );
192cdf0e10cSrcweir                 return nBytesToRead;
193cdf0e10cSrcweir             }
194cdf0e10cSrcweir         } // end guarded section
195cdf0e10cSrcweir 
196cdf0e10cSrcweir         // wait for new data outside guarded section!
197cdf0e10cSrcweir         osl_waitCondition( m_conditionBytesAvail , 0 );
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 
readSomeBytes(Sequence<sal_Int8> & aData,sal_Int32 nMaxBytesToRead)202cdf0e10cSrcweir sal_Int32 OPipeImpl::readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead)
203cdf0e10cSrcweir     throw( NotConnectedException,
204cdf0e10cSrcweir            BufferSizeExceededException,
205cdf0e10cSrcweir            RuntimeException )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     while( sal_True ) {
208cdf0e10cSrcweir         {
209cdf0e10cSrcweir             MutexGuard guard( m_mutexAccess );
210cdf0e10cSrcweir             if( m_bInputStreamClosed )
211cdf0e10cSrcweir             {
212cdf0e10cSrcweir                 throw NotConnectedException(
213cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM( "Pipe::readSomeBytes NotConnectedException" )),
214cdf0e10cSrcweir                     *this );
215cdf0e10cSrcweir             }
216cdf0e10cSrcweir             if( m_pFIFO->getSize() )
217cdf0e10cSrcweir             {
218cdf0e10cSrcweir                 sal_Int32 nSize = Min( nMaxBytesToRead , m_pFIFO->getSize() );
219cdf0e10cSrcweir                 aData.realloc( nSize );
220cdf0e10cSrcweir                 m_pFIFO->read( aData , nSize );
221cdf0e10cSrcweir                 return nSize;
222cdf0e10cSrcweir             }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir             if( m_bOutputStreamClosed )
225cdf0e10cSrcweir             {
226cdf0e10cSrcweir                 // no bytes in buffer anymore
227cdf0e10cSrcweir                 return 0;
228cdf0e10cSrcweir             }
229cdf0e10cSrcweir         }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         osl_waitCondition( m_conditionBytesAvail , 0 );
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 
skipBytes(sal_Int32 nBytesToSkip)236cdf0e10cSrcweir void OPipeImpl::skipBytes(sal_Int32 nBytesToSkip)
237cdf0e10cSrcweir     throw( NotConnectedException,
238cdf0e10cSrcweir            BufferSizeExceededException,
239cdf0e10cSrcweir            RuntimeException )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     MutexGuard guard( m_mutexAccess );
242cdf0e10cSrcweir     if( m_bInputStreamClosed )
243cdf0e10cSrcweir     {
244cdf0e10cSrcweir         throw NotConnectedException(
245cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM( "Pipe::skipBytes NotConnectedException" ) ),
246cdf0e10cSrcweir             *this );
247cdf0e10cSrcweir     }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     if( nBytesToSkip < 0
250cdf0e10cSrcweir         || (nBytesToSkip
251cdf0e10cSrcweir             > std::numeric_limits< sal_Int32 >::max() - m_nBytesToSkip) )
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir         throw BufferSizeExceededException(
254cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM( "Pipe::skipBytes BufferSizeExceededException" )),
255cdf0e10cSrcweir             *this );
256cdf0e10cSrcweir     }
257cdf0e10cSrcweir     m_nBytesToSkip += nBytesToSkip;
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     nBytesToSkip = Min( m_pFIFO->getSize() , m_nBytesToSkip );
260cdf0e10cSrcweir     m_pFIFO->skip( nBytesToSkip );
261cdf0e10cSrcweir     m_nBytesToSkip -= nBytesToSkip;
262cdf0e10cSrcweir }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 
available(void)265cdf0e10cSrcweir sal_Int32 OPipeImpl::available(void)
266cdf0e10cSrcweir     throw( NotConnectedException,
267cdf0e10cSrcweir            RuntimeException )
268cdf0e10cSrcweir  {
269cdf0e10cSrcweir     MutexGuard guard( m_mutexAccess );
270cdf0e10cSrcweir     if( m_bInputStreamClosed )
271cdf0e10cSrcweir     {
272cdf0e10cSrcweir         throw NotConnectedException(
273cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM( "Pipe::available NotConnectedException" ) ),
274cdf0e10cSrcweir             *this );
275cdf0e10cSrcweir     }
276cdf0e10cSrcweir     checkInvariant();
277cdf0e10cSrcweir     return m_pFIFO->getSize();
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
closeInput(void)280cdf0e10cSrcweir void OPipeImpl::closeInput(void)
281cdf0e10cSrcweir     throw( NotConnectedException,
282cdf0e10cSrcweir            RuntimeException)
283cdf0e10cSrcweir {
284cdf0e10cSrcweir     MutexGuard guard( m_mutexAccess );
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     m_bInputStreamClosed = sal_True;
287cdf0e10cSrcweir 
288cdf0e10cSrcweir     delete m_pFIFO;
289cdf0e10cSrcweir     m_pFIFO = 0;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     // readBytes may throw an exception
292cdf0e10cSrcweir     osl_setCondition( m_conditionBytesAvail );
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     setSuccessor( Reference< XConnectable > () );
295cdf0e10cSrcweir     return;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 
writeBytes(const Sequence<sal_Int8> & aData)299cdf0e10cSrcweir void OPipeImpl::writeBytes(const Sequence< sal_Int8 >& aData)
300cdf0e10cSrcweir     throw( NotConnectedException,
301cdf0e10cSrcweir            BufferSizeExceededException,
302cdf0e10cSrcweir            RuntimeException)
303cdf0e10cSrcweir {
304cdf0e10cSrcweir     MutexGuard guard( m_mutexAccess );
305cdf0e10cSrcweir     checkInvariant();
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     if( m_bOutputStreamClosed )
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir         throw NotConnectedException(
310cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM( "Pipe::writeBytes NotConnectedException (outputstream)" )),
311cdf0e10cSrcweir             *this );
312cdf0e10cSrcweir     }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     if( m_bInputStreamClosed )
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         throw NotConnectedException(
317cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM( "Pipe::writeBytes NotConnectedException (inputstream)" )),
318cdf0e10cSrcweir             *this );
319cdf0e10cSrcweir     }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir     // check skipping
322cdf0e10cSrcweir     sal_Int32 nLen = aData.getLength();
323cdf0e10cSrcweir     if( m_nBytesToSkip  && m_nBytesToSkip >= nLen  ) {
324cdf0e10cSrcweir         // all must be skipped - forget whole call
325cdf0e10cSrcweir         m_nBytesToSkip -= nLen;
326cdf0e10cSrcweir         return;
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     // adjust buffersize if necessary
330cdf0e10cSrcweir 
331cdf0e10cSrcweir     try
332cdf0e10cSrcweir     {
333cdf0e10cSrcweir         if( m_nBytesToSkip )
334cdf0e10cSrcweir         {
335cdf0e10cSrcweir             Sequence< sal_Int8 > seqCopy( nLen - m_nBytesToSkip );
336cdf0e10cSrcweir             memcpy( seqCopy.getArray() , &( aData.getConstArray()[m_nBytesToSkip] ) , nLen-m_nBytesToSkip );
337cdf0e10cSrcweir             m_pFIFO->write( seqCopy );
338cdf0e10cSrcweir         }
339cdf0e10cSrcweir         else
340cdf0e10cSrcweir         {
341cdf0e10cSrcweir             m_pFIFO->write( aData );
342cdf0e10cSrcweir         }
343cdf0e10cSrcweir         m_nBytesToSkip = 0;
344cdf0e10cSrcweir     }
345cdf0e10cSrcweir     catch ( IFIFO_OutOfBoundsException & )
346cdf0e10cSrcweir     {
347cdf0e10cSrcweir         throw BufferSizeExceededException(
348cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM( "Pipe::writeBytes BufferSizeExceededException" )),
349cdf0e10cSrcweir             *this );
350cdf0e10cSrcweir     }
351cdf0e10cSrcweir     catch ( IFIFO_OutOfMemoryException & )
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         throw BufferSizeExceededException(
354cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM( "Pipe::writeBytes BufferSizeExceededException" )),
355cdf0e10cSrcweir             *this );
356cdf0e10cSrcweir     }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir     // readBytes may check again if enough bytes are available
359cdf0e10cSrcweir     osl_setCondition( m_conditionBytesAvail );
360cdf0e10cSrcweir 
361cdf0e10cSrcweir     checkInvariant();
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 
flush(void)365cdf0e10cSrcweir void OPipeImpl::flush(void)
366cdf0e10cSrcweir     throw( NotConnectedException,
367cdf0e10cSrcweir            BufferSizeExceededException,
368cdf0e10cSrcweir            RuntimeException)
369cdf0e10cSrcweir {
370cdf0e10cSrcweir     // nothing to do for a pipe
371cdf0e10cSrcweir     return;
372cdf0e10cSrcweir }
373cdf0e10cSrcweir 
closeOutput(void)374cdf0e10cSrcweir void OPipeImpl::closeOutput(void)
375cdf0e10cSrcweir     throw( NotConnectedException,
376cdf0e10cSrcweir            BufferSizeExceededException,
377cdf0e10cSrcweir            RuntimeException)
378cdf0e10cSrcweir {
379cdf0e10cSrcweir     MutexGuard guard( m_mutexAccess );
380cdf0e10cSrcweir 
381cdf0e10cSrcweir     m_bOutputStreamClosed = sal_True;
382cdf0e10cSrcweir     osl_setCondition( m_conditionBytesAvail );
383cdf0e10cSrcweir     setPredecessor( Reference < XConnectable > () );
384cdf0e10cSrcweir     return;
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 
setSuccessor(const Reference<XConnectable> & r)388cdf0e10cSrcweir void OPipeImpl::setSuccessor( const Reference < XConnectable >  &r )
389cdf0e10cSrcweir     throw( RuntimeException )
390cdf0e10cSrcweir {
391cdf0e10cSrcweir      /// if the references match, nothing needs to be done
392cdf0e10cSrcweir      if( m_succ != r ) {
393cdf0e10cSrcweir          /// store the reference for later use
394cdf0e10cSrcweir          m_succ = r;
395cdf0e10cSrcweir 
396cdf0e10cSrcweir          if( m_succ.is() )
397cdf0e10cSrcweir          {
398cdf0e10cSrcweir               m_succ->setPredecessor(
399cdf0e10cSrcweir                   Reference< XConnectable > ( SAL_STATIC_CAST( XConnectable * , this ) ) );
400cdf0e10cSrcweir          }
401cdf0e10cSrcweir      }
402cdf0e10cSrcweir }
403cdf0e10cSrcweir 
getSuccessor()404cdf0e10cSrcweir Reference < XConnectable > OPipeImpl::getSuccessor()    throw( RuntimeException )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir     return m_succ;
407cdf0e10cSrcweir }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 
410cdf0e10cSrcweir // XDataSource
setPredecessor(const Reference<XConnectable> & r)411cdf0e10cSrcweir void OPipeImpl::setPredecessor( const Reference < XConnectable > &r )
412cdf0e10cSrcweir     throw( RuntimeException )
413cdf0e10cSrcweir {
414cdf0e10cSrcweir     if( r != m_pred ) {
415cdf0e10cSrcweir         m_pred = r;
416cdf0e10cSrcweir         if( m_pred.is() ) {
417cdf0e10cSrcweir             m_pred->setSuccessor(
418cdf0e10cSrcweir                 Reference < XConnectable > ( SAL_STATIC_CAST( XConnectable * , this ) ) );
419cdf0e10cSrcweir         }
420cdf0e10cSrcweir     }
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
getPredecessor()423cdf0e10cSrcweir Reference < XConnectable > OPipeImpl::getPredecessor() throw( RuntimeException )
424cdf0e10cSrcweir {
425cdf0e10cSrcweir     return m_pred;
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 
431cdf0e10cSrcweir // XServiceInfo
getImplementationName()432cdf0e10cSrcweir OUString OPipeImpl::getImplementationName() throw(  )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir     return OPipeImpl_getImplementationName();
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir // XServiceInfo
supportsService(const OUString & ServiceName)438cdf0e10cSrcweir sal_Bool OPipeImpl::supportsService(const OUString& ServiceName) throw(  )
439cdf0e10cSrcweir {
440cdf0e10cSrcweir     Sequence< OUString > aSNL = getSupportedServiceNames();
441cdf0e10cSrcweir     const OUString * pArray = aSNL.getConstArray();
442cdf0e10cSrcweir 
443cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
444cdf0e10cSrcweir         if( pArray[i] == ServiceName )
445cdf0e10cSrcweir             return sal_True;
446cdf0e10cSrcweir 
447cdf0e10cSrcweir     return sal_False;
448cdf0e10cSrcweir }
449cdf0e10cSrcweir 
450cdf0e10cSrcweir // XServiceInfo
getSupportedServiceNames(void)451cdf0e10cSrcweir Sequence< OUString > OPipeImpl::getSupportedServiceNames(void) throw(  )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir     return OPipeImpl_getSupportedServiceNames();
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 
460cdf0e10cSrcweir /* implementation functions
461cdf0e10cSrcweir *
462cdf0e10cSrcweir *
463cdf0e10cSrcweir */
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 
OPipeImpl_CreateInstance(const Reference<XComponentContext> &)466cdf0e10cSrcweir Reference < XInterface > SAL_CALL OPipeImpl_CreateInstance(
467cdf0e10cSrcweir     const Reference < XComponentContext > & ) throw(Exception)
468cdf0e10cSrcweir {
469cdf0e10cSrcweir     OPipeImpl *p = new OPipeImpl;
470cdf0e10cSrcweir 
471cdf0e10cSrcweir     return Reference < XInterface > ( SAL_STATIC_CAST( OWeakObject * , p ) );
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 
OPipeImpl_getImplementationName()475cdf0e10cSrcweir OUString    OPipeImpl_getImplementationName()
476cdf0e10cSrcweir {
477cdf0e10cSrcweir     return OUString( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
478cdf0e10cSrcweir }
479cdf0e10cSrcweir 
OPipeImpl_getSupportedServiceNames(void)480cdf0e10cSrcweir Sequence<OUString> OPipeImpl_getSupportedServiceNames(void)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir     Sequence<OUString> aRet(1);
483cdf0e10cSrcweir     aRet.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ));
484cdf0e10cSrcweir     return aRet;
485cdf0e10cSrcweir }
486cdf0e10cSrcweir }
487