1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #define CPPUHELPER_TEST_COMPONENT_IMPL
23 #include "TestComponent.hxx"
28 #include "osl/thread.h"
30 #include "cppuhelper/implbase1.hxx"
31 #include "cppuhelper/implementationentry.hxx"
32 #include "cppuhelper/supportsservice.hxx"
34 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
35 #include "com/sun/star/lang/XServiceInfo.hpp"
37 #include "com/sun/star/uno/XComponentContext.hpp"
40 #include "cppu/EnvDcp.hxx"
42 #include <uno/environment.hxx>
43 #include <uno/lbnames.h>
45 using namespace ::com::sun::star
;
48 #define LOG_LIFECYCLE_TestComponent
49 #ifdef LOG_LIFECYCLE_TestComponent
51 # define LOG_LIFECYCLE_TestComponent_emit(x) x
54 # define LOG_LIFECYCLE_TestComponent_emit(x)
59 class TestComponent
: public cppu::WeakImplHelper1
<lang::XServiceInfo
>
61 rtl::OUString m_implName
;
64 static uno::Reference
<uno::XInterface
> create(
65 uno::Reference
<uno::XComponentContext
> const & xCtx
67 SAL_THROW((uno::Exception
));
70 static uno::Sequence
<rtl::OUString
> SAL_CALL
getSupportedServiceNames_Static();
72 explicit TestComponent(uno::Reference
<uno::XComponentContext
> const & xCtx
);
73 virtual ~TestComponent();
75 uno::Any SAL_CALL
queryInterface(uno::Type
const & rType
) throw (::com::sun::star::uno::RuntimeException
);
76 void SAL_CALL
release() throw ();
77 void SAL_CALL
acquire() throw ();
80 virtual rtl::OUString SAL_CALL
getImplementationName() throw (uno::RuntimeException
);
81 virtual sal_Bool SAL_CALL
supportsService(rtl::OUString
const & ServiceName
)
82 throw (uno::RuntimeException
);
83 virtual uno::Sequence
<rtl::OUString
> SAL_CALL
getSupportedServiceNames()
84 throw (uno::RuntimeException
);
87 uno::Reference
<uno::XComponentContext
> m_xComponentContext
;
91 uno::Reference
<uno::XInterface
> SAL_CALL
TestComponent::create(
92 uno::Reference
<uno::XComponentContext
> const & xCtx
94 SAL_THROW((uno::Exception
))
98 return static_cast<cppu::OWeakObject
*>(new TestComponent(xCtx
));
100 catch (std::bad_alloc
&)
102 throw uno::RuntimeException(rtl::OUString("std::bad_alloc"),
103 uno::Reference
<uno::XInterface
>());
107 uno::Sequence
<rtl::OUString
> SAL_CALL
TestComponent::getSupportedServiceNames_Static()
109 uno::Sequence
<rtl::OUString
> serviceNames(1);
110 serviceNames
[0] = rtl::OUString("com.sun.star.lang.ServiceInfo");
116 TestComponent::TestComponent(uno::Reference
<uno::XComponentContext
> const & xCtx
)
117 : m_xComponentContext(xCtx
)
119 LOG_LIFECYCLE_TestComponent_emit(fprintf(stderr
, "LIFE: %s -> %p\n", "TestComponent::TestComponent()", this));
122 TestComponent::~TestComponent()
124 LOG_LIFECYCLE_TestComponent_emit(fprintf(stderr
, "LIFE: %s -> %p\n", "TestComponent::~TestComponent", this));
127 rtl::OUString SAL_CALL
TestComponent::getImplementationName()
128 throw (uno::RuntimeException
)
133 void SAL_CALL
TestComponent::acquire() throw ()
135 cppu::WeakImplHelper1
<lang::XServiceInfo
>::acquire();
138 void SAL_CALL
TestComponent::release() throw ()
140 cppu::WeakImplHelper1
<lang::XServiceInfo
>::release();
143 uno::Any SAL_CALL
TestComponent::queryInterface(uno::Type
const & rType
) throw (::com::sun::star::uno::RuntimeException
)
145 return cppu::WeakImplHelper1
<lang::XServiceInfo
>::queryInterface(rType
);
148 sal_Bool SAL_CALL
TestComponent::supportsService(rtl::OUString
const & ServiceName
)
149 throw (uno::RuntimeException
)
151 return cppu::supportsService(this, ServiceName
);
154 uno::Sequence
<rtl::OUString
> SAL_CALL
TestComponent::getSupportedServiceNames()
155 throw (uno::RuntimeException
)
157 return getSupportedServiceNames_Static();
160 extern "C" sal_Bool SAL_CALL
component_writeInfo(
161 void * /*serviceManager*/,
162 void * /*registryKey*/
165 g_envDcp
= uno::Environment::getCurrent().getTypeName();
170 extern "C" SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
component_getFactory(
171 char const * pImplName
,
172 void * /*serviceManager*/,
173 void * /*registryKey*/
176 g_envDcp
= uno::Environment::getCurrent().getTypeName();
178 uno::Reference
< lang::XSingleComponentFactory
> xFactory
;
180 rtl::OUString
uTmp(pImplName
, rtl_str_getLength(pImplName
), RTL_TEXTENCODING_ASCII_US
);
182 rtl::OUString
uImplName(cppu::EnvDcp::getTypeName(uTmp
));
183 rtl::OUString
cmpName("impl.test.TestComponent");
185 if (uImplName
.equals(cmpName
))
187 xFactory
= cppu::createSingleComponentFactory(
188 TestComponent::create
,
190 TestComponent::getSupportedServiceNames_Static());
195 return xFactory
.get();
198 extern "C" SAL_DLLPUBLIC_EXPORT
void SAL_CALL
component_getImplementationEnvironmentExt(
199 sal_Char
const ** envTypeName
,
200 uno_Environment
** /*ppEnv*/,
201 sal_Char
const * pImplName
,
202 uno_Environment
* /*pSrcEnv*/
205 rtl::OString purpose
;
207 if (pImplName
) // this is the purpose for a specified impl
209 rtl::OUString
uImplName(pImplName
, rtl_str_getLength(pImplName
), RTL_TEXTENCODING_ASCII_US
);
210 purpose
= rtl::OUStringToOString(cppu::EnvDcp::getPurpose(uImplName
), RTL_TEXTENCODING_ASCII_US
);
213 if (!purpose
.getLength())
215 char * pPurpose
= getenv("TestComponent.uno");
217 purpose
= rtl::OString(pPurpose
);
220 if (purpose
.getLength() == 0)
221 *envTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
226 strcpy(buff
, CPPU_CURRENT_LANGUAGE_BINDING_NAME
);
227 strcat(buff
, purpose
.getStr());
229 *envTypeName
= strdup(buff
);
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */