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