xref: /aoo41x/main/io/source/connector/ctr_pipe.cxx (revision 3716f815)
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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_io.hxx"
26 
27 #include "connector.hxx"
28 
29 using namespace ::osl;
30 using namespace ::rtl;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::io;
33 using namespace ::com::sun::star::connection;
34 
35 
36 namespace stoc_connector {
37 
PipeConnection(const OUString & sConnectionDescription)38 	PipeConnection::PipeConnection( const OUString & sConnectionDescription ) :
39 		m_nStatus( 0 ),
40 		m_sDescription( sConnectionDescription )
41 	{
42 		g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
43 		// make it unique
44 		m_sDescription += OUString::createFromAscii( ",uniqueValue=" );
45 		m_sDescription += OUString::valueOf(
46             sal::static_int_cast< sal_Int64 >(
47                 reinterpret_cast< sal_IntPtr >(&m_pipe)),
48             10 );
49 	}
50 
~PipeConnection()51 	PipeConnection::~PipeConnection()
52 	{
53 		g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
54 	}
55 
read(Sequence<sal_Int8> & aReadBytes,sal_Int32 nBytesToRead)56 	sal_Int32 PipeConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead )
57 			throw(::com::sun::star::io::IOException,
58 				  ::com::sun::star::uno::RuntimeException)
59 	{
60 		if( ! m_nStatus )
61 		{
62 			if( aReadBytes.getLength() != nBytesToRead )
63 			{
64 				aReadBytes.realloc( nBytesToRead );
65 			}
66 			return m_pipe.read( aReadBytes.getArray()  , aReadBytes.getLength() );
67 		}
68 		else {
69 			throw IOException();
70 		}
71 	}
72 
write(const Sequence<sal_Int8> & seq)73 	void PipeConnection::write( const Sequence < sal_Int8 > &seq )
74 			throw(::com::sun::star::io::IOException,
75 				  ::com::sun::star::uno::RuntimeException)
76 	{
77 		if( ! m_nStatus )
78 		{
79 			if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() )
80 			{
81 				throw IOException();
82 			}
83 		}
84 		else {
85 			throw IOException();
86 		}
87 	}
88 
flush()89 	void PipeConnection::flush( )
90 			throw(::com::sun::star::io::IOException,
91 				  ::com::sun::star::uno::RuntimeException)
92 	{
93 
94 	}
95 
close()96 	void PipeConnection::close()
97 			throw(::com::sun::star::io::IOException,
98 				  ::com::sun::star::uno::RuntimeException)
99 	{
100 		// ensure that close is called only once
101 		if(1 == osl_incrementInterlockedCount( (&m_nStatus) ) )
102 		{
103 			m_pipe.close();
104 		}
105 	}
106 
getDescription()107 	OUString PipeConnection::getDescription()
108 			throw( ::com::sun::star::uno::RuntimeException)
109 	{
110 		return m_sDescription;
111 	}
112 
113 }
114 
115