Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_COMPHELPER_SERVICEHELPER_HXX
21 : #define INCLUDED_COMPHELPER_SERVICEHELPER_HXX
22 :
23 : #include <rtl/uuid.h>
24 : #include <rtl/instance.hxx>
25 : #include <com/sun/star/uno/Sequence.hxx>
26 :
27 2476 : class UnoTunnelIdInit
28 : {
29 : private:
30 : ::com::sun::star::uno::Sequence< sal_Int8 > m_aSeq;
31 : public:
32 2476 : UnoTunnelIdInit() : m_aSeq(16)
33 : {
34 2476 : rtl_createUuid( reinterpret_cast<sal_uInt8*>(m_aSeq.getArray()), 0, sal_True );
35 2476 : }
36 6160025 : const ::com::sun::star::uno::Sequence< sal_Int8 >& getSeq() const { return m_aSeq; }
37 : };
38 :
39 : /** the UNO3_GETIMPLEMENTATION_* macros implement a static helper function
40 : that gives access to your implementation for a given interface reference,
41 : if possible.
42 :
43 : Example:
44 : MyClass* pClass = MyClass::getImplementation( xRef );
45 :
46 : Usage:
47 : Put a UNO3_GETIMPLEMENTATION_DECL( classname ) inside your class
48 : definitian and UNO3_GETIMPLEMENTATION_IMPL( classname ) inside
49 : your cxx file. Your class must inherit ::com::sun::star::lang::XUnoTunnel
50 : and export it with queryInterface. Implementation of XUnoTunnel is
51 : done by this macro.
52 : */
53 : #define UNO3_GETIMPLEMENTATION_DECL( classname ) \
54 : static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId() throw(); \
55 : static classname* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xInt ); \
56 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
57 :
58 : #define UNO3_GETIMPLEMENTATION_BASE_IMPL( classname ) \
59 : namespace \
60 : { \
61 : class the##classname##UnoTunnelId : public rtl::Static< UnoTunnelIdInit, the##classname##UnoTunnelId> {}; \
62 : } \
63 : const ::com::sun::star::uno::Sequence< sal_Int8 > & classname::getUnoTunnelId() throw() \
64 : { \
65 : return the##classname##UnoTunnelId::get().getSeq(); \
66 : } \
67 : \
68 : classname* classname::getImplementation( const uno::Reference< uno::XInterface >& xInt ) \
69 : { \
70 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xInt, ::com::sun::star::uno::UNO_QUERY ); \
71 : if( xUT.is() ) \
72 : return reinterpret_cast<classname*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( classname::getUnoTunnelId() ))); \
73 : else \
74 : return NULL; \
75 : }
76 :
77 : #define UNO3_GETIMPLEMENTATION_IMPL( classname )\
78 : UNO3_GETIMPLEMENTATION_BASE_IMPL(classname)\
79 : sal_Int64 SAL_CALL classname::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
80 : { \
81 : if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(), \
82 : rId.getConstArray(), 16 ) ) \
83 : { \
84 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); \
85 : } \
86 : return 0; \
87 : }
88 :
89 : #define UNO3_GETIMPLEMENTATION2_IMPL( classname, baseclass )\
90 : UNO3_GETIMPLEMENTATION_BASE_IMPL(classname)\
91 : sal_Int64 SAL_CALL classname::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
92 : { \
93 : if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(), \
94 : rId.getConstArray(), 16 ) ) \
95 : { \
96 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); \
97 : } \
98 : else \
99 : { \
100 : return baseclass::getSomething( rId ); \
101 : } \
102 : }
103 :
104 :
105 : #endif // INCLUDED_COMPHELPER_SERVICEHELPER_HXX
106 :
107 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|