fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / stoc / source / registry_tdprovider / tdservice.cxx
blob190ad7af4d6e886ea2c9a0db71dccfbcf995edc6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <osl/diagnose.h>
21 #include <rtl/ustrbuf.hxx>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include "com/sun/star/uno/RuntimeException.hpp"
25 #include "registry/reader.hxx"
26 #include "registry/version.h"
27 #include "base.hxx"
28 #include "methoddescription.hxx"
30 #include <memory>
32 using namespace com::sun::star;
34 namespace {
36 class Constructor:
37 public cppu::WeakImplHelper1< XServiceConstructorDescription >
39 public:
40 Constructor(
41 Reference< XHierarchicalNameAccess > const & manager,
42 OUString const & name, Sequence< sal_Int8 > const & bytes,
43 sal_uInt16 index):
44 m_desc(manager, name, bytes, index) {}
46 virtual ~Constructor() {}
48 virtual sal_Bool SAL_CALL isDefaultConstructor() throw (RuntimeException)
49 { return m_desc.getName().isEmpty(); }
51 virtual OUString SAL_CALL getName() throw (RuntimeException)
52 { return m_desc.getName(); }
54 virtual Sequence< Reference< XParameter > > SAL_CALL getParameters()
55 throw (RuntimeException)
56 { return m_desc.getParameters(); }
58 virtual Sequence< Reference<XCompoundTypeDescription > > SAL_CALL
59 getExceptions() throw (RuntimeException)
60 { return m_desc.getExceptions(); }
62 private:
63 Constructor(Constructor &); // not implemented
64 void operator =(Constructor); // not implemented
66 stoc::registry_tdprovider::MethodDescription m_desc;
71 namespace stoc_rdbtdp
74 // PropertyTypeDescriptionImpl
76 class PropertyTypeDescriptionImpl : public WeakImplHelper1< XPropertyTypeDescription >
78 OUString _aName;
79 Reference< XTypeDescription > _xTD;
80 sal_Int16 _nFlags;
82 public:
83 PropertyTypeDescriptionImpl( const OUString & rName,
84 const Reference< XTypeDescription > & xTD,
85 sal_Int16 nFlags )
86 : _aName( rName ), _xTD( xTD ), _nFlags( nFlags )
88 virtual ~PropertyTypeDescriptionImpl();
90 // XTypeDescription
91 virtual TypeClass SAL_CALL getTypeClass()
92 throw( RuntimeException );
93 virtual OUString SAL_CALL getName()
94 throw( RuntimeException );
96 // XPropertyTypeDescription
97 virtual sal_Int16 SAL_CALL getPropertyFlags()
98 throw ( RuntimeException );
99 virtual Reference< XTypeDescription > SAL_CALL getPropertyTypeDescription()
100 throw ( RuntimeException );
103 // virtual
104 PropertyTypeDescriptionImpl::~PropertyTypeDescriptionImpl() {}
106 // XTypeDescription
108 // virtual
109 TypeClass PropertyTypeDescriptionImpl::getTypeClass()
110 throw ( RuntimeException )
112 return TypeClass_PROPERTY;
115 // virtual
116 OUString PropertyTypeDescriptionImpl::getName()
117 throw ( RuntimeException )
119 return _aName;
122 // XPropertyTypeDescription
124 // virtual
125 sal_Int16 SAL_CALL PropertyTypeDescriptionImpl::getPropertyFlags()
126 throw ( RuntimeException )
128 return _nFlags;
131 // virtual
132 Reference< XTypeDescription > SAL_CALL
133 PropertyTypeDescriptionImpl::getPropertyTypeDescription()
134 throw ( RuntimeException )
136 return _xTD;
139 // ServiceTypeDescriptionImpl
141 // virtual
142 ServiceTypeDescriptionImpl::~ServiceTypeDescriptionImpl() {}
144 // XTypeDescription
146 // virtual
147 TypeClass ServiceTypeDescriptionImpl::getTypeClass()
148 throw(::com::sun::star::uno::RuntimeException)
150 return TypeClass_SERVICE;
153 // virtual
154 OUString ServiceTypeDescriptionImpl::getName()
155 throw(::com::sun::star::uno::RuntimeException)
157 return _aName;
160 // XServiceTypeDescription
162 // virtual
163 Sequence< Reference< XServiceTypeDescription > > SAL_CALL
164 ServiceTypeDescriptionImpl::getMandatoryServices()
165 throw ( RuntimeException )
167 getReferences();
168 return _aMandatoryServices;
171 // virtual
172 Sequence< Reference< XServiceTypeDescription > > SAL_CALL
173 ServiceTypeDescriptionImpl::getOptionalServices()
174 throw ( RuntimeException )
176 getReferences();
177 return _aOptionalServices;
180 // virtual
181 Sequence< Reference< XInterfaceTypeDescription > > SAL_CALL
182 ServiceTypeDescriptionImpl::getMandatoryInterfaces()
183 throw ( RuntimeException )
185 getReferences();
186 return _aMandatoryInterfaces;
189 // virtual
190 Sequence< Reference< XInterfaceTypeDescription > > SAL_CALL
191 ServiceTypeDescriptionImpl::getOptionalInterfaces()
192 throw ( RuntimeException )
194 getReferences();
195 return _aOptionalInterfaces;
198 // virtual
199 Sequence< Reference< XPropertyTypeDescription > > SAL_CALL
200 ServiceTypeDescriptionImpl::getProperties()
201 throw ( RuntimeException )
204 MutexGuard guard(getMutex());
205 if (_pProps.get() != 0) {
206 return *_pProps;
210 typereg::Reader aReader(
211 _aBytes.getConstArray(), _aBytes.getLength(), false, TYPEREG_VERSION_1);
213 sal_uInt16 nFields = (sal_uInt16)aReader.getFieldCount();
214 SAL_WNODEPRECATED_DECLARATIONS_PUSH
215 std::auto_ptr< Sequence< Reference< XPropertyTypeDescription > > >
216 pTempProps(
217 new Sequence< Reference< XPropertyTypeDescription > >(nFields));
218 SAL_WNODEPRECATED_DECLARATIONS_POP
219 Reference< XPropertyTypeDescription > * pProps = pTempProps->getArray();
221 while ( nFields-- )
223 // name
224 OUStringBuffer aName( _aName );
225 aName.appendAscii( "." );
226 aName.append( aReader.getFieldName( nFields ) );
228 // type description
229 Reference< XTypeDescription > xTD;
232 _xTDMgr->getByHierarchicalName(
233 aReader.getFieldTypeName( nFields ).replace( '/', '.' ) )
234 >>= xTD;
236 catch ( NoSuchElementException const & )
239 OSL_ENSURE( xTD.is(), "### no type description for property!" );
241 // flags
242 RTFieldAccess nFlags = aReader.getFieldFlags( nFields );
244 sal_Int16 nAttribs = 0;
245 if ( nFlags & RT_ACCESS_READONLY )
246 nAttribs |= beans::PropertyAttribute::READONLY;
247 if ( nFlags & RT_ACCESS_OPTIONAL )
248 nAttribs |= beans::PropertyAttribute::OPTIONAL;
249 if ( nFlags & RT_ACCESS_MAYBEVOID )
250 nAttribs |= beans::PropertyAttribute::MAYBEVOID;
251 if ( nFlags & RT_ACCESS_BOUND )
252 nAttribs |= beans::PropertyAttribute::BOUND;
253 if ( nFlags & RT_ACCESS_CONSTRAINED )
254 nAttribs |= beans::PropertyAttribute::CONSTRAINED;
255 if ( nFlags & RT_ACCESS_TRANSIENT )
256 nAttribs |= beans::PropertyAttribute::TRANSIENT;
257 if ( nFlags & RT_ACCESS_MAYBEAMBIGUOUS )
258 nAttribs |= beans::PropertyAttribute::MAYBEAMBIGUOUS;
259 if ( nFlags & RT_ACCESS_MAYBEDEFAULT )
260 nAttribs |= beans::PropertyAttribute::MAYBEDEFAULT;
261 if ( nFlags & RT_ACCESS_REMOVEABLE )
262 nAttribs |= beans::PropertyAttribute::REMOVABLE;
264 OSL_ENSURE( !(nFlags & RT_ACCESS_PROPERTY),
265 "### RT_ACCESS_PROPERTY is unexpected here!" );
266 OSL_ENSURE( !(nFlags & RT_ACCESS_ATTRIBUTE),
267 "### RT_ACCESS_ATTRIBUTE is unexpected here!" );
268 OSL_ENSURE( !(nFlags & RT_ACCESS_CONST),
269 "### RT_ACCESS_CONST is unexpected here!" );
270 // always set, unless RT_ACCESS_READONLY is set.
271 //OSL_ENSURE( !(nFlags & RT_ACCESS_READWRITE),
272 // "### RT_ACCESS_READWRITE is unexpected here" );
273 OSL_ENSURE( !(nFlags & RT_ACCESS_DEFAULT),
274 "### RT_ACCESS_DEAFAULT is unexpected here" );
276 pProps[ nFields ]
277 = new PropertyTypeDescriptionImpl( aName.makeStringAndClear(),
278 xTD,
279 nAttribs );
282 MutexGuard guard(getMutex());
283 if (_pProps.get() == 0) {
284 _pProps = pTempProps;
286 return *_pProps;
289 sal_Bool ServiceTypeDescriptionImpl::isSingleInterfaceBased()
290 throw (RuntimeException)
292 getReferences();
293 return _xInterfaceTD.is();
296 Reference< XTypeDescription > ServiceTypeDescriptionImpl::getInterface()
297 throw (RuntimeException)
299 getReferences();
300 return _xInterfaceTD;
303 Sequence< Reference< XServiceConstructorDescription > >
304 ServiceTypeDescriptionImpl::getConstructors() throw (RuntimeException) {
305 MutexGuard guard(getMutex());
306 if (_pCtors.get() == 0) {
307 typereg::Reader reader(
308 _aBytes.getConstArray(), _aBytes.getLength(), false,
309 TYPEREG_VERSION_1);
310 sal_uInt16 ctorCount = reader.getMethodCount();
311 SAL_WNODEPRECATED_DECLARATIONS_PUSH
312 std::auto_ptr< Sequence< Reference< XServiceConstructorDescription > > >
313 ctors(
314 new Sequence< Reference< XServiceConstructorDescription > >(
315 ctorCount));
316 SAL_WNODEPRECATED_DECLARATIONS_POP
317 for (sal_uInt16 i = 0; i < ctorCount; ++i) {
318 OUString name(reader.getMethodName(i));
319 if (reader.getMethodFlags(i) != RT_MODE_TWOWAY
320 || (reader.getMethodReturnTypeName(i) != "void")
321 || (name.isEmpty()
322 && (ctorCount != 1 || reader.getMethodParameterCount(i) != 0
323 || reader.getMethodExceptionCount(i) != 0)))
325 throw RuntimeException(
326 OUString("Service has bad constructors"),
327 static_cast< OWeakObject * >(this));
329 (*ctors)[i] = new Constructor(
330 _xTDMgr, reader.getMethodName(i), _aBytes, i);
332 _pCtors = ctors;
334 return *_pCtors;
337 void ServiceTypeDescriptionImpl::getReferences()
338 throw ( RuntimeException )
341 MutexGuard guard(getMutex());
342 if (_bInitReferences) {
343 return;
346 typereg::Reader aReader(
347 _aBytes.getConstArray(), _aBytes.getLength(), false, TYPEREG_VERSION_1);
348 sal_uInt16 superTypes = aReader.getSuperTypeCount();
349 if (superTypes > 1) {
350 throw RuntimeException(
351 OUString("Service has more than one supertype"),
352 static_cast< OWeakObject * >(this));
354 if (superTypes == 1) {
355 OUString aBaseName( aReader.getSuperTypeName(0).replace( '/', '.' ) );
356 if ( aReader.getReferenceCount() != 0
357 || aReader.getFieldCount() != 0 )
358 throw RuntimeException(
359 OUString("Service is single-interface--based but also has"
360 " references and/or properties" ),
361 static_cast< OWeakObject * >( this ) );
362 Reference< XTypeDescription > ifc;
365 _xTDMgr->getByHierarchicalName( aBaseName ) >>= ifc;
367 catch ( NoSuchElementException const & e )
369 throw RuntimeException(
370 OUString("com.sun.star.container.NoSuchElementException: " )
371 + e.Message,
372 static_cast< OWeakObject * >( this ) );
374 OSL_ASSERT(ifc.is());
375 if (resolveTypedefs(ifc)->getTypeClass() != TypeClass_INTERFACE) {
376 throw RuntimeException(
377 OUString("Single-interface--based service is not based on"
378 " interface type" ),
379 static_cast< OWeakObject * >( this ) );
381 MutexGuard guard(getMutex());
382 if (!_bInitReferences) {
383 _xInterfaceTD = ifc;
384 _bInitReferences = true;
387 else
389 sal_uInt16 nRefs = aReader.getReferenceCount();
390 Sequence< Reference< XServiceTypeDescription > > aMandatoryServices(
391 nRefs);
392 Sequence< Reference< XServiceTypeDescription > > aOptionalServices(
393 nRefs);
394 Sequence< Reference< XInterfaceTypeDescription > > aMandatoryInterfaces(
395 nRefs);
396 Sequence< Reference< XInterfaceTypeDescription > > aOptionalInterfaces(
397 nRefs);
398 sal_uInt32 nMS = 0;
399 sal_uInt32 nOS = 0;
400 sal_uInt32 nMI = 0;
401 sal_uInt32 nOI = 0;
403 for ( sal_uInt16 nPos = 0; nPos < nRefs; ++nPos )
405 RTReferenceType eType = aReader.getReferenceSort( nPos );
406 switch ( eType )
408 case RT_REF_EXPORTS: // service
410 uno::Any aTypeDesc;
413 aTypeDesc = _xTDMgr->getByHierarchicalName(
414 aReader.getReferenceTypeName( nPos ).replace(
415 '/', '.' ) );
417 catch ( NoSuchElementException const & e )
419 throw RuntimeException(
420 OUString("com.sun.star.container.NoSuchElementException: " )
421 + e.Message,
422 static_cast< OWeakObject * >( this ) );
425 RTFieldAccess nAccess = aReader.getReferenceFlags( nPos );
426 if ( nAccess & RT_ACCESS_OPTIONAL )
428 // optional service
429 if ( !( aTypeDesc >>= aOptionalServices[ nOS ] ) )
430 throw RuntimeException(
431 OUString("Service 'export' is not a service" ),
432 static_cast< OWeakObject * >( this ) );
433 nOS++;
435 else
437 // mandatory service
438 if ( !( aTypeDesc >>= aMandatoryServices[ nMS ] ) )
439 throw RuntimeException(
440 OUString("Service 'export' is not a service" ),
441 static_cast< OWeakObject * >( this ) );
442 nMS++;
444 break;
446 case RT_REF_SUPPORTS: // interface
448 uno::Any aTypeDesc;
451 aTypeDesc = _xTDMgr->getByHierarchicalName(
452 aReader.getReferenceTypeName( nPos ).replace(
453 '/', '.' ) );
455 catch ( NoSuchElementException const & e )
457 throw RuntimeException(
458 OUString("com.sun.star.container.NoSuchElementException: " )
459 + e.Message,
460 static_cast< OWeakObject * >( this ) );
463 RTFieldAccess nAccess = aReader.getReferenceFlags( nPos );
464 if ( nAccess & RT_ACCESS_OPTIONAL )
466 // optional interface
467 if ( !( aTypeDesc >>= aOptionalInterfaces[ nOI ] ) )
468 throw RuntimeException(
469 OUString("Service 'supports' is not an"
470 " interface" ),
471 static_cast< OWeakObject * >( this ) );
472 nOI++;
474 else
476 // mandatory interface
477 if ( !( aTypeDesc >>= aMandatoryInterfaces[ nMI ] ) )
478 throw RuntimeException(
479 OUString("Service 'supports' is not an"
480 " interface" ),
481 static_cast< OWeakObject * >( this ) );
482 nMI++;
484 break;
486 case RT_REF_OBSERVES:
487 case RT_REF_NEEDS:
488 break;
489 default:
490 OSL_FAIL( "### unsupported reference type!" );
491 break;
494 aMandatoryServices.realloc( nMS );
495 aOptionalServices.realloc( nOS );
496 aMandatoryInterfaces.realloc( nMI );
497 aOptionalInterfaces.realloc( nOI );
499 MutexGuard guard(getMutex());
500 if (!_bInitReferences) {
501 _aMandatoryServices = aMandatoryServices;
502 _aOptionalServices = aOptionalServices;
503 _aMandatoryInterfaces = aMandatoryInterfaces;
504 _aOptionalInterfaces = aOptionalInterfaces;
505 _bInitReferences = true;
513 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */