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 { 57 return ::test::types::Data( 58 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hello")), 42); 59 } 60 61 private: 62 Service(Service &); // not defined 63 void operator =(Service &); // not defined 64 65 virtual ~Service() {} 66 }; 67 68 namespace CppServer { 69 70 ::css::uno::Reference< ::css::uno::XInterface > create( 71 ::css::uno::Reference< ::css::uno::XComponentContext > const &) 72 { 73 try { 74 return static_cast< ::cppu::OWeakObject * >(new Service); 75 } catch (::std::bad_alloc &) { 76 throw ::css::uno::RuntimeException( 77 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")), 78 ::css::uno::Reference< ::css::uno::XInterface >()); 79 } 80 } 81 82 ::rtl::OUString getImplementationName() { 83 return ::rtl::OUString( 84 RTL_CONSTASCII_USTRINGPARAM("test.cpp.cppserver.Component")); 85 } 86 87 ::css::uno::Sequence< ::rtl::OUString > getSupportedServiceNames() { 88 return ::css::uno::Sequence< ::rtl::OUString >(); 89 } 90 91 } 92 93 ::cppu::ImplementationEntry entries[] = { 94 { CppServer::create, CppServer::getImplementationName, 95 CppServer::getSupportedServiceNames, ::cppu::createSingleComponentFactory, 96 0, 0 }, 97 { 0, 0, 0, 0, 0, 0 } }; 98 99 } 100 101 extern "C" ::sal_Bool SAL_CALL component_writeInfo( 102 void * serviceManager, void * registryKey) 103 { 104 return ::cppu::component_writeInfoHelper( 105 serviceManager, registryKey, entries); 106 } 107 108 extern "C" void * SAL_CALL component_getFactory( 109 char const * implName, void * serviceManager, void * registryKey) 110 { 111 return ::cppu::component_getFactoryHelper( 112 implName, serviceManager, registryKey, entries); 113 } 114 115 extern "C" void SAL_CALL component_getImplementationEnvironment( 116 char const ** envTypeName, ::uno_Environment **) 117 { 118 *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 119 } 120