update dev300-m58
[ooovba.git] / io / source / connector / connector.hxx
blob09e844d0faef7b3ce81038a443362983f58e67ee
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: connector.hxx,v $
10 * $Revision: 1.11 $
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 <rtl/unload.h>
32 #include <cppuhelper/implbase1.hxx>
33 #include <cppuhelper/implbase2.hxx>
35 #include <com/sun/star/connection/XConnection.hpp>
36 #include <com/sun/star/connection/XConnectionBroadcaster.hpp>
38 #include <hash_set>
39 # include <osl/socket.hxx>
40 # include <osl/pipe.hxx>
42 namespace stoc_connector
44 extern rtl_StandardModuleCount g_moduleCount;
46 template<class T>
47 struct ReferenceHash
49 size_t operator () (const ::com::sun::star::uno::Reference<T> & ref) const
51 return (size_t)ref.get();
55 template<class T>
56 struct ReferenceEqual
58 sal_Bool operator () (const ::com::sun::star::uno::Reference<T> & op1,
59 const ::com::sun::star::uno::Reference<T> & op2) const
61 return op1.get() == op2.get();
65 typedef ::std::hash_set< ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>,
66 ReferenceHash< ::com::sun::star::io::XStreamListener>,
67 ReferenceEqual< ::com::sun::star::io::XStreamListener> >
68 XStreamListener_hash_set;
70 class PipeConnection :
71 public ::cppu::WeakImplHelper1< ::com::sun::star::connection::XConnection >
74 public:
75 PipeConnection( const ::rtl::OUString &sConnectionDescription );
76 virtual ~PipeConnection();
78 virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes,
79 sal_Int32 nBytesToRead )
80 throw(::com::sun::star::io::IOException,
81 ::com::sun::star::uno::RuntimeException);
82 virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData )
83 throw(::com::sun::star::io::IOException,
84 ::com::sun::star::uno::RuntimeException);
85 virtual void SAL_CALL flush( ) throw(
86 ::com::sun::star::io::IOException,
87 ::com::sun::star::uno::RuntimeException);
88 virtual void SAL_CALL close( )
89 throw(::com::sun::star::io::IOException,
90 ::com::sun::star::uno::RuntimeException);
91 virtual ::rtl::OUString SAL_CALL getDescription( )
92 throw(::com::sun::star::uno::RuntimeException);
93 public:
94 ::osl::StreamPipe m_pipe;
95 oslInterlockedCount m_nStatus;
96 ::rtl::OUString m_sDescription;
99 class SocketConnection :
100 public ::cppu::WeakImplHelper2< ::com::sun::star::connection::XConnection, ::com::sun::star::connection::XConnectionBroadcaster >
103 public:
104 SocketConnection( const ::rtl::OUString & sConnectionDescription );
105 virtual ~SocketConnection();
107 virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes,
108 sal_Int32 nBytesToRead )
109 throw(::com::sun::star::io::IOException,
110 ::com::sun::star::uno::RuntimeException);
111 virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData )
112 throw(::com::sun::star::io::IOException,
113 ::com::sun::star::uno::RuntimeException);
114 virtual void SAL_CALL flush( ) throw(
115 ::com::sun::star::io::IOException,
116 ::com::sun::star::uno::RuntimeException);
117 virtual void SAL_CALL close( )
118 throw(::com::sun::star::io::IOException,
119 ::com::sun::star::uno::RuntimeException);
120 virtual ::rtl::OUString SAL_CALL getDescription( )
121 throw(::com::sun::star::uno::RuntimeException);
124 // XConnectionBroadcaster
125 virtual void SAL_CALL addStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener)
126 throw(::com::sun::star::uno::RuntimeException);
127 virtual void SAL_CALL removeStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener)
128 throw(::com::sun::star::uno::RuntimeException);
130 public:
131 void completeConnectionString();
133 ::osl::ConnectorSocket m_socket;
134 ::osl::SocketAddr m_addr;
135 oslInterlockedCount m_nStatus;
136 ::rtl::OUString m_sDescription;
138 ::osl::Mutex _mutex;
139 sal_Bool _started;
140 sal_Bool _closed;
141 sal_Bool _error;
143 XStreamListener_hash_set _listeners;