1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26
27 #include "vcl/svapp.hxx"
28
29 #include "xconnection.hxx"
30 #include "svdata.hxx"
31 #include "salinst.hxx"
32
33 namespace {
34
35 namespace css = com::sun::star;
36
37 }
38
39 namespace vcl
40 {
41 class SolarMutexReleaser
42 {
43 sal_uLong mnReleased;
44 public:
SolarMutexReleaser()45 SolarMutexReleaser()
46 {
47 mnReleased = Application::ReleaseSolarMutex();
48 }
49
~SolarMutexReleaser()50 ~SolarMutexReleaser()
51 {
52 if( mnReleased )
53 Application::AcquireSolarMutex( mnReleased );
54 }
55 };
56 }
57
58 using namespace rtl;
59 using namespace osl;
60 using namespace vcl;
61 using namespace com::sun::star::uno;
62 using namespace com::sun::star::awt;
63
64
DisplayConnection()65 DisplayConnection::DisplayConnection()
66 {
67 SalInstance::ConnectionIdentifierType eType;
68 int nBytes;
69 void* pBytes = ImplGetSVData()->mpDefInst->GetConnectionIdentifier( eType, nBytes );
70 switch( eType )
71 {
72 case SalInstance::AsciiCString:
73 m_aAny <<= OUString::createFromAscii( (sal_Char*)pBytes );
74 break;
75 case SalInstance::Blob:
76 m_aAny <<= Sequence< sal_Int8 >( (sal_Int8*)pBytes, nBytes );
77 break;
78 }
79 }
80
~DisplayConnection()81 DisplayConnection::~DisplayConnection()
82 {}
83
start()84 void DisplayConnection::start()
85 {
86 ImplSVData* pSVData = ImplGetSVData();
87 pSVData->mpDefInst->SetEventCallback( this );
88 }
89
terminate()90 void DisplayConnection::terminate()
91 {
92 ImplSVData* pSVData = ImplGetSVData();
93
94 if( pSVData )
95 {
96 pSVData->mpDefInst->SetEventCallback( NULL );
97 }
98
99 SolarMutexReleaser aRel;
100
101 MutexGuard aGuard( m_aMutex );
102 Any aEvent;
103 std::list< css::uno::Reference< XEventHandler > > aLocalList( m_aHandlers );
104 for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = aLocalList.begin(); it != aLocalList.end(); ++it )
105 (*it)->handleEvent( aEvent );
106 }
107
addEventHandler(const Any &,const css::uno::Reference<XEventHandler> & handler,sal_Int32)108 void SAL_CALL DisplayConnection::addEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler, sal_Int32 /*eventMask*/ ) throw()
109 {
110 MutexGuard aGuard( m_aMutex );
111
112 m_aHandlers.push_back( handler );
113 }
114
removeEventHandler(const Any &,const css::uno::Reference<XEventHandler> & handler)115 void SAL_CALL DisplayConnection::removeEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler ) throw()
116 {
117 MutexGuard aGuard( m_aMutex );
118
119 m_aHandlers.remove( handler );
120 }
121
addErrorHandler(const css::uno::Reference<XEventHandler> & handler)122 void SAL_CALL DisplayConnection::addErrorHandler( const css::uno::Reference< XEventHandler >& handler ) throw()
123 {
124 MutexGuard aGuard( m_aMutex );
125
126 m_aErrorHandlers.push_back( handler );
127 }
128
removeErrorHandler(const css::uno::Reference<XEventHandler> & handler)129 void SAL_CALL DisplayConnection::removeErrorHandler( const css::uno::Reference< XEventHandler >& handler ) throw()
130 {
131 MutexGuard aGuard( m_aMutex );
132
133 m_aErrorHandlers.remove( handler );
134 }
135
getIdentifier()136 Any SAL_CALL DisplayConnection::getIdentifier() throw()
137 {
138 return m_aAny;
139 }
140
dispatchEvent(void * pData,int nBytes)141 bool DisplayConnection::dispatchEvent( void* pData, int nBytes )
142 {
143 SolarMutexReleaser aRel;
144
145 Sequence< sal_Int8 > aSeq( (sal_Int8*)pData, nBytes );
146 Any aEvent;
147 aEvent <<= aSeq;
148 ::std::list< css::uno::Reference< XEventHandler > > handlers;
149 {
150 MutexGuard aGuard( m_aMutex );
151 handlers = m_aHandlers;
152 }
153 for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = handlers.begin(); it != handlers.end(); ++it )
154 if( (*it)->handleEvent( aEvent ) )
155 return true;
156 return false;
157 }
158
dispatchErrorEvent(void * pData,int nBytes)159 bool DisplayConnection::dispatchErrorEvent( void* pData, int nBytes )
160 {
161 SolarMutexReleaser aRel;
162
163 Sequence< sal_Int8 > aSeq( (sal_Int8*)pData, nBytes );
164 Any aEvent;
165 aEvent <<= aSeq;
166 ::std::list< css::uno::Reference< XEventHandler > > handlers;
167 {
168 MutexGuard aGuard( m_aMutex );
169 handlers = m_aErrorHandlers;
170 }
171 for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = handlers.begin(); it != handlers.end(); ++it )
172 if( (*it)->handleEvent( aEvent ) )
173 return true;
174
175 return false;
176 }
177