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 #ifndef _APPHELPER_SERVICEMACROS_HXX 28 #define _APPHELPER_SERVICEMACROS_HXX 29 30 /* 31 to use these macros the supported services and the implementation name needs to be static 32 especially you need to implement (declaration is contained in macro already): 33 34 static com::sun::star::uno::Sequence< rtl::OUString > 35 Class::getSupportedServiceNames_Static(); 36 */ 37 38 //========================================================================= 39 // 40 // XServiceInfo decl 41 // 42 //========================================================================= 43 namespace apphelper 44 { 45 46 #define APPHELPER_XSERVICEINFO_DECL() \ 47 virtual ::rtl::OUString SAL_CALL \ 48 getImplementationName() \ 49 throw( ::com::sun::star::uno::RuntimeException ); \ 50 virtual sal_Bool SAL_CALL \ 51 supportsService( const ::rtl::OUString& ServiceName ) \ 52 throw( ::com::sun::star::uno::RuntimeException ); \ 53 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL \ 54 getSupportedServiceNames() \ 55 throw( ::com::sun::star::uno::RuntimeException ); \ 56 \ 57 static ::rtl::OUString getImplementationName_Static(); \ 58 static ::com::sun::star::uno::Sequence< ::rtl::OUString > \ 59 getSupportedServiceNames_Static(); 60 61 //========================================================================= 62 // 63 // XServiceInfo impl 64 // 65 //========================================================================= 66 67 #define APPHELPER_XSERVICEINFO_IMPL( Class, ImplName ) \ 68 ::rtl::OUString SAL_CALL Class::getImplementationName() \ 69 throw( ::com::sun::star::uno::RuntimeException ) \ 70 { \ 71 return getImplementationName_Static(); \ 72 } \ 73 \ 74 ::rtl::OUString Class::getImplementationName_Static() \ 75 { \ 76 return ImplName; \ 77 } \ 78 \ 79 sal_Bool SAL_CALL \ 80 Class::supportsService( const ::rtl::OUString& ServiceName ) \ 81 throw( ::com::sun::star::uno::RuntimeException ) \ 82 { \ 83 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = \ 84 getSupportedServiceNames(); \ 85 const ::rtl::OUString* pArray = aSNL.getArray(); \ 86 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) \ 87 { \ 88 if( pArray[ i ] == ServiceName ) \ 89 return sal_True; \ 90 } \ 91 \ 92 return sal_False; \ 93 } \ 94 \ 95 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL \ 96 Class::getSupportedServiceNames() \ 97 throw( ::com::sun::star::uno::RuntimeException ) \ 98 { \ 99 return getSupportedServiceNames_Static(); \ 100 } 101 102 //========================================================================= 103 // 104 // Service factory helper decl+impl 105 // 106 //to use this macro you need to provide a constructor: 107 //class( Reference< XComponentContext > const & xContext ) 108 //and implement OWeakObject 109 //========================================================================= 110 111 #define APPHELPER_SERVICE_FACTORY_HELPER(Class) \ 112 static ::com::sun::star::uno::Reference< \ 113 ::com::sun::star::uno::XInterface > SAL_CALL \ 114 create( ::com::sun::star::uno::Reference< \ 115 ::com::sun::star::uno::XComponentContext > const & xContext) \ 116 throw(::com::sun::star::uno::Exception) \ 117 { \ 118 return (::cppu::OWeakObject *)new Class( xContext ); \ 119 } 120 121 /** This macro contains the default implementation for getImplementationId(). 122 Note, that you have to include the header necessary for rtl_createUuid. 123 Insert the following into your file: 124 125 <code> 126 #include <rtl/uuid.h> 127 </code> 128 129 @param Class the Class-Name for which getImplementationId() should be 130 implemented 131 */ 132 #define APPHELPER_GETIMPLEMENTATIONID_IMPL(Class) \ 133 ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL Class::getImplementationId() \ 134 throw (::com::sun::star::uno::RuntimeException) \ 135 { \ 136 static ::com::sun::star::uno::Sequence< sal_Int8 > aId; \ 137 if( aId.getLength() == 0 ) \ 138 { \ 139 aId.realloc( 16 ); \ 140 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); \ 141 } \ 142 return aId; \ 143 } 144 145 }//end namespace apphelper 146 #endif 147