Update ooo320-m1
[ooovba.git] / io / source / connector / ctr_pipe.cxx
blob28e557cafe11e3e5bfb90fd62aaabab184d4f2e1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ctr_pipe.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_io.hxx"
34 #include "connector.hxx"
36 using namespace ::osl;
37 using namespace ::rtl;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::io;
40 using namespace ::com::sun::star::connection;
43 namespace stoc_connector {
45 PipeConnection::PipeConnection( const OUString & sConnectionDescription ) :
46 m_nStatus( 0 ),
47 m_sDescription( sConnectionDescription )
49 g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
50 // make it unique
51 m_sDescription += OUString::createFromAscii( ",uniqueValue=" );
52 m_sDescription += OUString::valueOf(
53 sal::static_int_cast< sal_Int64 >(
54 reinterpret_cast< sal_IntPtr >(&m_pipe)),
55 10 );
58 PipeConnection::~PipeConnection()
60 g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
63 sal_Int32 PipeConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead )
64 throw(::com::sun::star::io::IOException,
65 ::com::sun::star::uno::RuntimeException)
67 if( ! m_nStatus )
69 if( aReadBytes.getLength() != nBytesToRead )
71 aReadBytes.realloc( nBytesToRead );
73 return m_pipe.read( aReadBytes.getArray() , aReadBytes.getLength() );
75 else {
76 throw IOException();
80 void PipeConnection::write( const Sequence < sal_Int8 > &seq )
81 throw(::com::sun::star::io::IOException,
82 ::com::sun::star::uno::RuntimeException)
84 if( ! m_nStatus )
86 if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() )
88 throw IOException();
91 else {
92 throw IOException();
96 void PipeConnection::flush( )
97 throw(::com::sun::star::io::IOException,
98 ::com::sun::star::uno::RuntimeException)
103 void PipeConnection::close()
104 throw(::com::sun::star::io::IOException,
105 ::com::sun::star::uno::RuntimeException)
107 // ensure that close is called only once
108 if(1 == osl_incrementInterlockedCount( (&m_nStatus) ) )
110 m_pipe.close();
114 OUString PipeConnection::getDescription()
115 throw( ::com::sun::star::uno::RuntimeException)
117 return m_sDescription;