xref: /aoo42x/main/ure/source/uretest/cppserver.cc (revision 5f94a14c)
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 <new>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
29cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
30cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
31cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
32cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
33cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
34cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
35cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
36cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx"
37cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
38cdf0e10cSrcweir #include "rtl/ustring.h"
39cdf0e10cSrcweir #include "rtl/ustring.hxx"
40cdf0e10cSrcweir #include "sal/types.h"
41cdf0e10cSrcweir #include "uno/environment.h"
42cdf0e10cSrcweir #include "uno/lbnames.h"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include "test/types/Data.hpp"
45cdf0e10cSrcweir #include "test/types/XServer.hpp"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace css = ::com::sun::star;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace {
50cdf0e10cSrcweir 
51cdf0e10cSrcweir class Service: public ::cppu::WeakImplHelper1< ::test::types::XServer > {
52cdf0e10cSrcweir public:
Service()53cdf0e10cSrcweir     Service() {}
54cdf0e10cSrcweir 
getData()55cdf0e10cSrcweir     virtual ::test::types::Data SAL_CALL getData()
56cdf0e10cSrcweir         throw (::css::uno::RuntimeException)
57cdf0e10cSrcweir     {
58cdf0e10cSrcweir         return ::test::types::Data(
59cdf0e10cSrcweir             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hello")), 42);
60cdf0e10cSrcweir     }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir private:
63cdf0e10cSrcweir     Service(Service &); // not defined
64cdf0e10cSrcweir     void operator =(Service &); // not defined
65cdf0e10cSrcweir 
~Service()66cdf0e10cSrcweir     virtual ~Service() {}
67cdf0e10cSrcweir };
68cdf0e10cSrcweir 
69cdf0e10cSrcweir namespace CppServer {
70cdf0e10cSrcweir 
create(::css::uno::Reference<::css::uno::XComponentContext> const &)71cdf0e10cSrcweir ::css::uno::Reference< ::css::uno::XInterface > create(
72cdf0e10cSrcweir     ::css::uno::Reference< ::css::uno::XComponentContext > const &)
73cdf0e10cSrcweir     SAL_THROW((::css::uno::Exception))
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     try {
76cdf0e10cSrcweir         return static_cast< ::cppu::OWeakObject * >(new Service);
77cdf0e10cSrcweir     } catch (::std::bad_alloc &) {
78cdf0e10cSrcweir         throw ::css::uno::RuntimeException(
79cdf0e10cSrcweir             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")),
80cdf0e10cSrcweir             ::css::uno::Reference< ::css::uno::XInterface >());
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
getImplementationName()84cdf0e10cSrcweir ::rtl::OUString getImplementationName() {
85cdf0e10cSrcweir     return ::rtl::OUString(
86cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("test.cpp.cppserver.Component"));
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
getSupportedServiceNames()89cdf0e10cSrcweir ::css::uno::Sequence< ::rtl::OUString > getSupportedServiceNames() {
90cdf0e10cSrcweir     return ::css::uno::Sequence< ::rtl::OUString >();
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir ::cppu::ImplementationEntry entries[] = {
96cdf0e10cSrcweir     { CppServer::create, CppServer::getImplementationName,
97cdf0e10cSrcweir       CppServer::getSupportedServiceNames, ::cppu::createSingleComponentFactory,
98cdf0e10cSrcweir       0, 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