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 throw( ::com::sun::star::uno::RuntimeException ); \ 46 virtual sal_Bool SAL_CALL \ 47 supportsService( const ::rtl::OUString& ServiceName ) \ 48 throw( ::com::sun::star::uno::RuntimeException ); \ 49 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL \ 50 getSupportedServiceNames() \ 51 throw( ::com::sun::star::uno::RuntimeException ); \ 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 throw( ::com::sun::star::uno::RuntimeException ) \ 66 { \ 67 return getImplementationName_Static(); \ 68 } \ 69 \ 70 ::rtl::OUString Class::getImplementationName_Static() \ 71 { \ 72 return ImplName; \ 73 } \ 74 \ 75 sal_Bool SAL_CALL \ 76 Class::supportsService( const ::rtl::OUString& ServiceName ) \ 77 throw( ::com::sun::star::uno::RuntimeException ) \ 78 { \ 79 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = \ 80 getSupportedServiceNames(); \ 81 const ::rtl::OUString* pArray = aSNL.getArray(); \ 82 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) \ 83 { \ 84 if( pArray[ i ] == ServiceName ) \ 85 return sal_True; \ 86 } \ 87 \ 88 return sal_False; \ 89 } \ 90 \ 91 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL \ 92 Class::getSupportedServiceNames() \ 93 throw( ::com::sun::star::uno::RuntimeException ) \ 94 { \ 95 return getSupportedServiceNames_Static(); \ 96 } 97 98 //========================================================================= 99 // 100 // Service factory helper decl+impl 101 // 102 //to use this macro you need to provide a constructor: 103 //class( Reference< XComponentContext > const & xContext ) 104 //and implement OWeakObject 105 //========================================================================= 106 107 #define APPHELPER_SERVICE_FACTORY_HELPER(Class) \ 108 static ::com::sun::star::uno::Reference< \ 109 ::com::sun::star::uno::XInterface > SAL_CALL \ 110 create( ::com::sun::star::uno::Reference< \ 111 ::com::sun::star::uno::XComponentContext > const & xContext) \ 112 throw(::com::sun::star::uno::Exception) \ 113 { \ 114 return (::cppu::OWeakObject *)new Class( xContext ); \ 115 } 116 117 /** This macro contains the default implementation for getImplementationId(). 118 Note, that you have to include the header necessary for rtl_createUuid. 119 Insert the following into your file: 120 121 <code> 122 #include <rtl/uuid.h> 123 </code> 124 125 @param Class the Class-Name for which getImplementationId() should be 126 implemented 127 */ 128 #define APPHELPER_GETIMPLEMENTATIONID_IMPL(Class) \ 129 ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL Class::getImplementationId() \ 130 throw (::com::sun::star::uno::RuntimeException) \ 131 { \ 132 static ::com::sun::star::uno::Sequence< sal_Int8 > aId; \ 133 if( aId.getLength() == 0 ) \ 134 { \ 135 aId.realloc( 16 ); \ 136 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); \ 137 } \ 138 return aId; \ 139 } 140 141 }//end namespace apphelper 142 #endif 143