1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bridge_connection.cxx,v $
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>
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
) :
44 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
45 acquire
= thisAcquire
;
46 release
= thisRelease
;
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
) ) )
73 sal_Int32
OConnectionWrapper::thisRead( remote_Connection
*p
, sal_Int8
*pDest
, sal_Int32 nSize
)
76 OConnectionWrapper
* m
= ( OConnectionWrapper
* ) p
;
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
);
89 catch (::std::bad_alloc
&)
95 sal_Int32
OConnectionWrapper::thisWrite( remote_Connection
*p
,
96 const sal_Int8
*pSource
,
100 OConnectionWrapper
* m
= ( OConnectionWrapper
* ) p
;
103 Sequence
< sal_Int8
> seq( pSource
, nSize
);
104 m
->m_r
->write( seq
);
107 catch ( Exception
& )
113 void OConnectionWrapper::thisFlush( remote_Connection
*p
)
118 OConnectionWrapper
* m
= ( OConnectionWrapper
* ) p
;
121 catch ( Exception
& )
126 void OConnectionWrapper::thisClose( remote_Connection
* p
)
131 OConnectionWrapper
* m
= ( OConnectionWrapper
* ) p
;