1*5f94a14cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5f94a14cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5f94a14cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5f94a14cSAndrew Rist * distributed with this work for additional information
6*5f94a14cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5f94a14cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5f94a14cSAndrew Rist * "License"); you may not use this file except in compliance
9*5f94a14cSAndrew Rist * with the License. You may obtain a copy of the License at
10*5f94a14cSAndrew Rist *
11*5f94a14cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*5f94a14cSAndrew Rist *
13*5f94a14cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5f94a14cSAndrew Rist * software distributed under the License is distributed on an
15*5f94a14cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5f94a14cSAndrew Rist * KIND, either express or implied. See the License for the
17*5f94a14cSAndrew Rist * specific language governing permissions and limitations
18*5f94a14cSAndrew Rist * under the License.
19*5f94a14cSAndrew Rist *
20*5f94a14cSAndrew Rist *************************************************************/
21*5f94a14cSAndrew Rist
22*5f94a14cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "sal/config.h"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
27cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
28cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
29cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
30cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
31cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
32cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
33cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
34cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx"
35cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
36cdf0e10cSrcweir #include "rtl/ustring.h"
37cdf0e10cSrcweir #include "rtl/ustring.hxx"
38cdf0e10cSrcweir #include "sal/types.h"
39cdf0e10cSrcweir #include "uno/environment.h"
40cdf0e10cSrcweir #include "uno/lbnames.h"
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include "test/types/TestException.hpp"
43cdf0e10cSrcweir #include "test/types/XTest.hpp"
44cdf0e10cSrcweir
45cdf0e10cSrcweir namespace css = com::sun::star;
46cdf0e10cSrcweir
47cdf0e10cSrcweir namespace {
48cdf0e10cSrcweir
49cdf0e10cSrcweir class Service: public cppu::WeakImplHelper1< test::types::XTest > {
50cdf0e10cSrcweir public:
Service()51cdf0e10cSrcweir Service() {}
52cdf0e10cSrcweir
throwException()53cdf0e10cSrcweir virtual void SAL_CALL throwException()
54cdf0e10cSrcweir throw (test::types::TestException, css::uno::RuntimeException)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir throw test::types::TestException(
57cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test")),
58cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this));
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
61cdf0e10cSrcweir private:
62cdf0e10cSrcweir Service(Service &); // not defined
63cdf0e10cSrcweir void operator =(Service &); // not defined
64cdf0e10cSrcweir
~Service()65cdf0e10cSrcweir virtual ~Service() {}
66cdf0e10cSrcweir };
67cdf0e10cSrcweir
68cdf0e10cSrcweir namespace CppTest {
69cdf0e10cSrcweir
create(css::uno::Reference<css::uno::XComponentContext> const &)70cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > create(
71cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const &)
72cdf0e10cSrcweir SAL_THROW((css::uno::Exception))
73cdf0e10cSrcweir {
74cdf0e10cSrcweir try {
75cdf0e10cSrcweir return static_cast< cppu::OWeakObject * >(new Service);
76cdf0e10cSrcweir } catch (std::bad_alloc &) {
77cdf0e10cSrcweir throw css::uno::RuntimeException(
78cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")),
79cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >());
80cdf0e10cSrcweir }
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
getImplementationName()83cdf0e10cSrcweir rtl::OUString getImplementationName() {
84cdf0e10cSrcweir return rtl::OUString(
85cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("test.cpp.cpptest.Component"));
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
getSupportedServiceNames()88cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
89cdf0e10cSrcweir rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("test.types.CppTest"));
90cdf0e10cSrcweir return css::uno::Sequence< rtl::OUString >(&s, 1);
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir cppu::ImplementationEntry entries[] = {
96cdf0e10cSrcweir { CppTest::create, CppTest::getImplementationName,
97cdf0e10cSrcweir CppTest::getSupportedServiceNames, cppu::createSingleComponentFactory, 0,
98cdf0e10cSrcweir 0 },
99cdf0e10cSrcweir { 0, 0, 0, 0, 0, 0 } };
100cdf0e10cSrcweir
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
component_writeInfo(void * serviceManager,void * registryKey)103cdf0e10cSrcweir extern "C" sal_Bool SAL_CALL component_writeInfo(
104cdf0e10cSrcweir void * serviceManager, void * registryKey)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir return cppu::component_writeInfoHelper(
107cdf0e10cSrcweir serviceManager, registryKey, entries);
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
component_getFactory(char const * implName,void * serviceManager,void * registryKey)110cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory(
111cdf0e10cSrcweir char const * implName, void * serviceManager, void * registryKey)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir return cppu::component_getFactoryHelper(
114cdf0e10cSrcweir implName, serviceManager, registryKey, entries);
115cdf0e10cSrcweir }
116cdf0e10cSrcweir
component_getImplementationEnvironment(char const ** envTypeName,uno_Environment **)117cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment(
118cdf0e10cSrcweir char const ** envTypeName, uno_Environment **)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
121cdf0e10cSrcweir }
122