xref: /trunk/main/io/source/connector/ctr_pipe.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_io.hxx"
30 
31 #include "connector.hxx"
32 
33 using namespace ::osl;
34 using namespace ::rtl;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::io;
37 using namespace ::com::sun::star::connection;
38 
39 
40 namespace stoc_connector {
41 
42     PipeConnection::PipeConnection( const OUString & sConnectionDescription ) :
43         m_nStatus( 0 ),
44         m_sDescription( sConnectionDescription )
45     {
46         g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
47         // make it unique
48         m_sDescription += OUString::createFromAscii( ",uniqueValue=" );
49         m_sDescription += OUString::valueOf(
50             sal::static_int_cast< sal_Int64 >(
51                 reinterpret_cast< sal_IntPtr >(&m_pipe)),
52             10 );
53     }
54 
55     PipeConnection::~PipeConnection()
56     {
57         g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
58     }
59 
60     sal_Int32 PipeConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead )
61             throw(::com::sun::star::io::IOException,
62                   ::com::sun::star::uno::RuntimeException)
63     {
64         if( ! m_nStatus )
65         {
66             if( aReadBytes.getLength() != nBytesToRead )
67             {
68                 aReadBytes.realloc( nBytesToRead );
69             }
70             return m_pipe.read( aReadBytes.getArray()  , aReadBytes.getLength() );
71         }
72         else {
73             throw IOException();
74         }
75     }
76 
77     void PipeConnection::write( const Sequence < sal_Int8 > &seq )
78             throw(::com::sun::star::io::IOException,
79                   ::com::sun::star::uno::RuntimeException)
80     {
81         if( ! m_nStatus )
82         {
83             if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() )
84             {
85                 throw IOException();
86             }
87         }
88         else {
89             throw IOException();
90         }
91     }
92 
93     void PipeConnection::flush( )
94             throw(::com::sun::star::io::IOException,
95                   ::com::sun::star::uno::RuntimeException)
96     {
97 
98     }
99 
100     void PipeConnection::close()
101             throw(::com::sun::star::io::IOException,
102                   ::com::sun::star::uno::RuntimeException)
103     {
104         // ensure that close is called only once
105         if(1 == osl_incrementInterlockedCount( (&m_nStatus) ) )
106         {
107             m_pipe.close();
108         }
109     }
110 
111     OUString PipeConnection::getDescription()
112             throw( ::com::sun::star::uno::RuntimeException)
113     {
114         return m_sDescription;
115     }
116 
117 }
118 
119