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