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 24 #include "sal/config.h" 25 26 #include <new> 27 28 #include "com/sun/star/uno/Exception.hpp" 29 #include "com/sun/star/uno/Reference.hxx" 30 #include "com/sun/star/uno/RuntimeException.hpp" 31 #include "com/sun/star/uno/Sequence.hxx" 32 #include "com/sun/star/uno/XComponentContext.hpp" 33 #include "com/sun/star/uno/XInterface.hpp" 34 #include "cppuhelper/factory.hxx" 35 #include "cppuhelper/implbase1.hxx" 36 #include "cppuhelper/implementationentry.hxx" 37 #include "cppuhelper/weak.hxx" 38 #include "rtl/ustring.h" 39 #include "rtl/ustring.hxx" 40 #include "sal/types.h" 41 #include "uno/environment.h" 42 #include "uno/lbnames.h" 43 44 #include "test/types/Data.hpp" 45 #include "test/types/XServer.hpp" 46 47 namespace css = ::com::sun::star; 48 49 namespace { 50 51 class Service: public ::cppu::WeakImplHelper1< ::test::types::XServer > { 52 public: 53 Service() {} 54 55 virtual ::test::types::Data SAL_CALL getData() 56 throw (::css::uno::RuntimeException) 57 { 58 return ::test::types::Data( 59 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hello")), 42); 60 } 61 62 private: 63 Service(Service &); // not defined 64 void operator =(Service &); // not defined 65 66 virtual ~Service() {} 67 }; 68 69 namespace CppServer { 70 71 ::css::uno::Reference< ::css::uno::XInterface > create( 72 ::css::uno::Reference< ::css::uno::XComponentContext > const &) 73 SAL_THROW((::css::uno::Exception)) 74 { 75 try { 76 return static_cast< ::cppu::OWeakObject * >(new Service); 77 } catch (::std::bad_alloc &) { 78 throw ::css::uno::RuntimeException( 79 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")), 80 ::css::uno::Reference< ::css::uno::XInterface >()); 81 } 82 } 83 84 ::rtl::OUString getImplementationName() { 85 return ::rtl::OUString( 86 RTL_CONSTASCII_USTRINGPARAM("test.cpp.cppserver.Component")); 87 } 88 89 ::css::uno::Sequence< ::rtl::OUString > getSupportedServiceNames() { 90 return ::css::uno::Sequence< ::rtl::OUString >(); 91 } 92 93 } 94 95 ::cppu::ImplementationEntry entries[] = { 96 { CppServer::create, CppServer::getImplementationName, 97 CppServer::getSupportedServiceNames, ::cppu::createSingleComponentFactory, 98 0, 0 }, 99 { 0, 0, 0, 0, 0, 0 } }; 100 101 } 102 103 extern "C" ::sal_Bool SAL_CALL component_writeInfo( 104 void * serviceManager, void * registryKey) 105 { 106 return ::cppu::component_writeInfoHelper( 107 serviceManager, registryKey, entries); 108 } 109 110 extern "C" void * SAL_CALL component_getFactory( 111 char const * implName, void * serviceManager, void * registryKey) 112 { 113 return ::cppu::component_getFactoryHelper( 114 implName, serviceManager, registryKey, entries); 115 } 116 117 extern "C" void SAL_CALL component_getImplementationEnvironment( 118 char const ** envTypeName, ::uno_Environment **) 119 { 120 *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 121 } 122