merge the formfield patch from ooo-build
[ooovba.git] / remotebridges / source / bridge / bridge_connection.cxx
blobadbd57a697fb976578b0dcc7d2768fd3bb3c934e
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: bridge_connection.cxx,v $
10 * $Revision: 1.6 $
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 ************************************************************************/
30 #include "bridge_connection.hxx"
31 #include "remote_bridge.hxx"
32 #include <rtl/byteseq.hxx>
33 #include <string.h>
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::connection;
38 namespace remotebridges_bridge
40 OConnectionWrapper::OConnectionWrapper( const Reference < XConnection > &r ) :
41 m_r( r ),
42 m_nRef( 0 )
44 g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
45 acquire = thisAcquire;
46 release = thisRelease;
47 read = thisRead;
48 write = thisWrite;
49 flush = thisFlush;
50 close = thisClose;
53 OConnectionWrapper::~OConnectionWrapper()
55 g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
58 void OConnectionWrapper::thisAcquire( remote_Connection *p)
60 OConnectionWrapper * m = ( OConnectionWrapper * ) p;
61 osl_incrementInterlockedCount( &(m->m_nRef ) );
64 void OConnectionWrapper::thisRelease( remote_Connection * p)
66 OConnectionWrapper * m = ( OConnectionWrapper * ) p;
67 if( ! osl_decrementInterlockedCount( &( m->m_nRef ) ) )
69 delete m;
73 sal_Int32 OConnectionWrapper::thisRead( remote_Connection *p , sal_Int8 *pDest , sal_Int32 nSize )
75 // guard the C-Code
76 OConnectionWrapper * m = ( OConnectionWrapper * ) p;
77 try
79 // TODO possible optimization : give
80 ::rtl::ByteSequence seq( nSize , ::rtl::BYTESEQ_NODEFAULT );
81 sal_Int32 nRead = m->m_r->read( *(Sequence<sal_Int8>*)&seq , nSize );
82 memcpy( pDest , seq.getConstArray() , nRead );
83 return nRead;
85 catch ( Exception & )
87 return 0;
89 catch (::std::bad_alloc &)
91 return 0;
95 sal_Int32 OConnectionWrapper::thisWrite( remote_Connection *p ,
96 const sal_Int8 *pSource ,
97 sal_Int32 nSize )
99 // guard the C-Code
100 OConnectionWrapper * m = ( OConnectionWrapper * ) p;
103 Sequence< sal_Int8 > seq( pSource , nSize );
104 m->m_r->write( seq );
105 return nSize;
107 catch ( Exception & )
109 return 0;
113 void OConnectionWrapper::thisFlush( remote_Connection *p )
115 // guard the C-Code
118 OConnectionWrapper * m = ( OConnectionWrapper * ) p;
119 m->m_r->flush();
121 catch ( Exception & )
126 void OConnectionWrapper::thisClose( remote_Connection * p)
128 // guard the C-Code
131 OConnectionWrapper * m = ( OConnectionWrapper * ) p;
132 m->m_r->close();
134 catch( Exception & )