xref: /trunk/main/io/source/connector/connector.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 #include <rtl/unload.h>
28 
29 #include <cppuhelper/implbase1.hxx>
30 #include <cppuhelper/implbase2.hxx>
31 
32 #include <com/sun/star/connection/XConnection.hpp>
33 #include <com/sun/star/connection/XConnectionBroadcaster.hpp>
34 
35 #include <hash_set>
36 #       include <osl/socket.hxx>
37 #       include <osl/pipe.hxx>
38 
39 namespace stoc_connector
40 {
41     extern rtl_StandardModuleCount g_moduleCount;
42 
43     template<class T>
44     struct ReferenceHash
45     {
46         size_t operator () (const ::com::sun::star::uno::Reference<T> & ref) const
47         {
48             return (size_t)ref.get();
49         }
50     };
51 
52     template<class T>
53     struct ReferenceEqual
54     {
55         sal_Bool operator () (const ::com::sun::star::uno::Reference<T> & op1,
56                               const ::com::sun::star::uno::Reference<T> & op2) const
57         {
58             return op1.get() == op2.get();
59         }
60     };
61 
62     typedef ::std::hash_set< ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>,
63                              ReferenceHash< ::com::sun::star::io::XStreamListener>,
64                              ReferenceEqual< ::com::sun::star::io::XStreamListener> >
65             XStreamListener_hash_set;
66 
67     class PipeConnection :
68         public ::cppu::WeakImplHelper1< ::com::sun::star::connection::XConnection >
69 
70     {
71     public:
72         PipeConnection( const ::rtl::OUString &sConnectionDescription );
73         virtual ~PipeConnection();
74 
75         virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes,
76                                          sal_Int32 nBytesToRead )
77             throw(::com::sun::star::io::IOException,
78                   ::com::sun::star::uno::RuntimeException);
79         virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData )
80             throw(::com::sun::star::io::IOException,
81                   ::com::sun::star::uno::RuntimeException);
82         virtual void SAL_CALL flush(  ) throw(
83             ::com::sun::star::io::IOException,
84             ::com::sun::star::uno::RuntimeException);
85         virtual void SAL_CALL close(  )
86             throw(::com::sun::star::io::IOException,
87                   ::com::sun::star::uno::RuntimeException);
88         virtual ::rtl::OUString SAL_CALL getDescription(  )
89             throw(::com::sun::star::uno::RuntimeException);
90     public:
91         ::osl::StreamPipe m_pipe;
92         oslInterlockedCount m_nStatus;
93         ::rtl::OUString m_sDescription;
94     };
95 
96     class SocketConnection :
97         public ::cppu::WeakImplHelper2< ::com::sun::star::connection::XConnection, ::com::sun::star::connection::XConnectionBroadcaster >
98 
99     {
100     public:
101         SocketConnection( const ::rtl::OUString & sConnectionDescription  );
102         virtual ~SocketConnection();
103 
104         virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes,
105                                          sal_Int32 nBytesToRead )
106             throw(::com::sun::star::io::IOException,
107                   ::com::sun::star::uno::RuntimeException);
108         virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData )
109             throw(::com::sun::star::io::IOException,
110                   ::com::sun::star::uno::RuntimeException);
111         virtual void SAL_CALL flush(  ) throw(
112             ::com::sun::star::io::IOException,
113             ::com::sun::star::uno::RuntimeException);
114         virtual void SAL_CALL close(  )
115             throw(::com::sun::star::io::IOException,
116                   ::com::sun::star::uno::RuntimeException);
117         virtual ::rtl::OUString SAL_CALL getDescription(  )
118             throw(::com::sun::star::uno::RuntimeException);
119 
120 
121         // XConnectionBroadcaster
122         virtual void SAL_CALL addStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener)
123             throw(::com::sun::star::uno::RuntimeException);
124         virtual void SAL_CALL removeStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener)
125             throw(::com::sun::star::uno::RuntimeException);
126 
127     public:
128         void completeConnectionString();
129 
130         ::osl::ConnectorSocket m_socket;
131         ::osl::SocketAddr m_addr;
132         oslInterlockedCount m_nStatus;
133         ::rtl::OUString m_sDescription;
134 
135         ::osl::Mutex _mutex;
136         sal_Bool     _started;
137         sal_Bool     _closed;
138         sal_Bool     _error;
139 
140         XStreamListener_hash_set _listeners;
141     };
142 }
143 
144 
145