1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_stoc.hxx"
26*b1cdbd2cSJim Jagielski #include <osl/diagnose.h>
27*b1cdbd2cSJim Jagielski #include <osl/mutex.hxx>
28*b1cdbd2cSJim Jagielski #include <rtl/alloc.h>
29*b1cdbd2cSJim Jagielski #include <cppuhelper/factory.hxx>
30*b1cdbd2cSJim Jagielski #include <cppuhelper/implbase2.hxx>
31*b1cdbd2cSJim Jagielski
32*b1cdbd2cSJim Jagielski #include <example/XTest.hpp>
33*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XServiceInfo.hpp>
35*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36*b1cdbd2cSJim Jagielski #include <com/sun/star/registry/XRegistryKey.hpp>
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski using namespace example;
39*b1cdbd2cSJim Jagielski using namespace com::sun::star::uno;
40*b1cdbd2cSJim Jagielski using namespace com::sun::star::lang;
41*b1cdbd2cSJim Jagielski using namespace com::sun::star::registry;
42*b1cdbd2cSJim Jagielski using namespace cppu;
43*b1cdbd2cSJim Jagielski using namespace osl;
44*b1cdbd2cSJim Jagielski using namespace rtl;
45*b1cdbd2cSJim Jagielski
46*b1cdbd2cSJim Jagielski #define SERVICENAME1 "example.ExampleComponent1"
47*b1cdbd2cSJim Jagielski #define IMPLNAME1 "example.ExampleComponent1.Impl"
48*b1cdbd2cSJim Jagielski
49*b1cdbd2cSJim Jagielski namespace excomp_impl {
50*b1cdbd2cSJim Jagielski
51*b1cdbd2cSJim Jagielski //*************************************************************************
52*b1cdbd2cSJim Jagielski // ExampleComponent1Impl
53*b1cdbd2cSJim Jagielski //*************************************************************************
54*b1cdbd2cSJim Jagielski class ExampleComponent1Impl : public WeakImplHelper2< XTest, XServiceInfo >
55*b1cdbd2cSJim Jagielski {
56*b1cdbd2cSJim Jagielski public:
57*b1cdbd2cSJim Jagielski ExampleComponent1Impl( const Reference<XMultiServiceFactory> & rXSMgr );
58*b1cdbd2cSJim Jagielski
59*b1cdbd2cSJim Jagielski ~ExampleComponent1Impl();
60*b1cdbd2cSJim Jagielski
61*b1cdbd2cSJim Jagielski // XServiceInfo
62*b1cdbd2cSJim Jagielski virtual OUString SAL_CALL getImplementationName( ) throw(RuntimeException);
63*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
64*b1cdbd2cSJim Jagielski virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(RuntimeException);
65*b1cdbd2cSJim Jagielski static Sequence< OUString > SAL_CALL getSupportedServiceNames_Static( );
66*b1cdbd2cSJim Jagielski
67*b1cdbd2cSJim Jagielski // XSimpleRegistry
68*b1cdbd2cSJim Jagielski virtual OUString SAL_CALL getMessage() throw(RuntimeException);
69*b1cdbd2cSJim Jagielski
70*b1cdbd2cSJim Jagielski protected:
71*b1cdbd2cSJim Jagielski Mutex m_mutex;
72*b1cdbd2cSJim Jagielski
73*b1cdbd2cSJim Jagielski Reference<XMultiServiceFactory> m_xSMgr;
74*b1cdbd2cSJim Jagielski };
75*b1cdbd2cSJim Jagielski
76*b1cdbd2cSJim Jagielski //*************************************************************************
ExampleComponent1Impl(const Reference<XMultiServiceFactory> & rXSMgr)77*b1cdbd2cSJim Jagielski ExampleComponent1Impl::ExampleComponent1Impl( const Reference<XMultiServiceFactory> & rXSMgr )
78*b1cdbd2cSJim Jagielski : m_xSMgr(rXSMgr)
79*b1cdbd2cSJim Jagielski {
80*b1cdbd2cSJim Jagielski }
81*b1cdbd2cSJim Jagielski
82*b1cdbd2cSJim Jagielski //*************************************************************************
~ExampleComponent1Impl()83*b1cdbd2cSJim Jagielski ExampleComponent1Impl::~ExampleComponent1Impl()
84*b1cdbd2cSJim Jagielski {
85*b1cdbd2cSJim Jagielski }
86*b1cdbd2cSJim Jagielski
87*b1cdbd2cSJim Jagielski //*************************************************************************
getImplementationName()88*b1cdbd2cSJim Jagielski OUString SAL_CALL ExampleComponent1Impl::getImplementationName( )
89*b1cdbd2cSJim Jagielski throw(RuntimeException)
90*b1cdbd2cSJim Jagielski {
91*b1cdbd2cSJim Jagielski Guard< Mutex > aGuard( m_mutex );
92*b1cdbd2cSJim Jagielski return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME1) );
93*b1cdbd2cSJim Jagielski }
94*b1cdbd2cSJim Jagielski
95*b1cdbd2cSJim Jagielski //*************************************************************************
supportsService(const OUString & ServiceName)96*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL ExampleComponent1Impl::supportsService( const OUString& ServiceName )
97*b1cdbd2cSJim Jagielski throw(RuntimeException)
98*b1cdbd2cSJim Jagielski {
99*b1cdbd2cSJim Jagielski Guard< Mutex > aGuard( m_mutex );
100*b1cdbd2cSJim Jagielski Sequence< OUString > aSNL = getSupportedServiceNames();
101*b1cdbd2cSJim Jagielski const OUString * pArray = aSNL.getArray();
102*b1cdbd2cSJim Jagielski for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
103*b1cdbd2cSJim Jagielski if( pArray[i] == ServiceName )
104*b1cdbd2cSJim Jagielski return sal_True;
105*b1cdbd2cSJim Jagielski return sal_False;
106*b1cdbd2cSJim Jagielski }
107*b1cdbd2cSJim Jagielski
108*b1cdbd2cSJim Jagielski //*************************************************************************
getSupportedServiceNames()109*b1cdbd2cSJim Jagielski Sequence<OUString> SAL_CALL ExampleComponent1Impl::getSupportedServiceNames( )
110*b1cdbd2cSJim Jagielski throw(RuntimeException)
111*b1cdbd2cSJim Jagielski {
112*b1cdbd2cSJim Jagielski Guard< Mutex > aGuard( m_mutex );
113*b1cdbd2cSJim Jagielski return getSupportedServiceNames_Static();
114*b1cdbd2cSJim Jagielski }
115*b1cdbd2cSJim Jagielski
116*b1cdbd2cSJim Jagielski //*************************************************************************
getSupportedServiceNames_Static()117*b1cdbd2cSJim Jagielski Sequence<OUString> SAL_CALL ExampleComponent1Impl::getSupportedServiceNames_Static( )
118*b1cdbd2cSJim Jagielski {
119*b1cdbd2cSJim Jagielski OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME1) );
120*b1cdbd2cSJim Jagielski return Sequence< OUString >( &aName, 1 );
121*b1cdbd2cSJim Jagielski }
122*b1cdbd2cSJim Jagielski
123*b1cdbd2cSJim Jagielski //*************************************************************************
getMessage()124*b1cdbd2cSJim Jagielski OUString SAL_CALL ExampleComponent1Impl::getMessage() throw(RuntimeException)
125*b1cdbd2cSJim Jagielski {
126*b1cdbd2cSJim Jagielski Guard< Mutex > aGuard( m_mutex );
127*b1cdbd2cSJim Jagielski return OUString::createFromAscii("Lalelu nur der Mann im Mond schaut zu ...");
128*b1cdbd2cSJim Jagielski }
129*b1cdbd2cSJim Jagielski
130*b1cdbd2cSJim Jagielski
131*b1cdbd2cSJim Jagielski //*************************************************************************
ExampleComponent1_CreateInstance(const Reference<XMultiServiceFactory> & rSMgr)132*b1cdbd2cSJim Jagielski Reference<XInterface> SAL_CALL ExampleComponent1_CreateInstance( const Reference<XMultiServiceFactory>& rSMgr )
133*b1cdbd2cSJim Jagielski {
134*b1cdbd2cSJim Jagielski Reference<XInterface> xRet;
135*b1cdbd2cSJim Jagielski
136*b1cdbd2cSJim Jagielski XTest *pXTest = (XTest*) new ExampleComponent1Impl(rSMgr);
137*b1cdbd2cSJim Jagielski
138*b1cdbd2cSJim Jagielski if (pXTest)
139*b1cdbd2cSJim Jagielski {
140*b1cdbd2cSJim Jagielski xRet = Reference< XInterface >::query(pXTest);
141*b1cdbd2cSJim Jagielski }
142*b1cdbd2cSJim Jagielski
143*b1cdbd2cSJim Jagielski return xRet;
144*b1cdbd2cSJim Jagielski }
145*b1cdbd2cSJim Jagielski
146*b1cdbd2cSJim Jagielski } // excomp_impl
147*b1cdbd2cSJim Jagielski
148*b1cdbd2cSJim Jagielski
149*b1cdbd2cSJim Jagielski extern "C"
150*b1cdbd2cSJim Jagielski {
151*b1cdbd2cSJim Jagielski //==================================================================================================
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)152*b1cdbd2cSJim Jagielski void SAL_CALL component_getImplementationEnvironment(
153*b1cdbd2cSJim Jagielski const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ )
154*b1cdbd2cSJim Jagielski {
155*b1cdbd2cSJim Jagielski *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
156*b1cdbd2cSJim Jagielski }
157*b1cdbd2cSJim Jagielski //==================================================================================================
component_writeInfo(void *,void * pRegistryKey)158*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL component_writeInfo(
159*b1cdbd2cSJim Jagielski void * /* pServiceManager */ , void * pRegistryKey )
160*b1cdbd2cSJim Jagielski {
161*b1cdbd2cSJim Jagielski if (pRegistryKey)
162*b1cdbd2cSJim Jagielski {
163*b1cdbd2cSJim Jagielski try
164*b1cdbd2cSJim Jagielski {
165*b1cdbd2cSJim Jagielski // ExampleComponent1
166*b1cdbd2cSJim Jagielski Reference< XRegistryKey > xNewKey(
167*b1cdbd2cSJim Jagielski reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
168*b1cdbd2cSJim Jagielski OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME1 "/UNO/SERVICES") ) ) );
169*b1cdbd2cSJim Jagielski
170*b1cdbd2cSJim Jagielski const Sequence< OUString > & rSNL =
171*b1cdbd2cSJim Jagielski ::excomp_impl::ExampleComponent1Impl::getSupportedServiceNames_Static();
172*b1cdbd2cSJim Jagielski const OUString * pArray = rSNL.getConstArray();
173*b1cdbd2cSJim Jagielski for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
174*b1cdbd2cSJim Jagielski xNewKey->createKey( pArray[nPos] );
175*b1cdbd2cSJim Jagielski
176*b1cdbd2cSJim Jagielski return sal_True;
177*b1cdbd2cSJim Jagielski }
178*b1cdbd2cSJim Jagielski catch (InvalidRegistryException &)
179*b1cdbd2cSJim Jagielski {
180*b1cdbd2cSJim Jagielski OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
181*b1cdbd2cSJim Jagielski }
182*b1cdbd2cSJim Jagielski }
183*b1cdbd2cSJim Jagielski return sal_False;
184*b1cdbd2cSJim Jagielski }
185*b1cdbd2cSJim Jagielski //==================================================================================================
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void *)186*b1cdbd2cSJim Jagielski void * SAL_CALL component_getFactory(
187*b1cdbd2cSJim Jagielski const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ )
188*b1cdbd2cSJim Jagielski {
189*b1cdbd2cSJim Jagielski void * pRet = 0;
190*b1cdbd2cSJim Jagielski
191*b1cdbd2cSJim Jagielski if (rtl_str_compare( pImplName, IMPLNAME1 ) == 0)
192*b1cdbd2cSJim Jagielski {
193*b1cdbd2cSJim Jagielski Reference< XSingleServiceFactory > xFactory( createSingleFactory(
194*b1cdbd2cSJim Jagielski reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
195*b1cdbd2cSJim Jagielski OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME1) ),
196*b1cdbd2cSJim Jagielski ::excomp_impl::ExampleComponent1_CreateInstance,
197*b1cdbd2cSJim Jagielski ::excomp_impl::ExampleComponent1Impl::getSupportedServiceNames_Static() ) );
198*b1cdbd2cSJim Jagielski
199*b1cdbd2cSJim Jagielski if (xFactory.is())
200*b1cdbd2cSJim Jagielski {
201*b1cdbd2cSJim Jagielski xFactory->acquire();
202*b1cdbd2cSJim Jagielski pRet = xFactory.get();
203*b1cdbd2cSJim Jagielski }
204*b1cdbd2cSJim Jagielski }
205*b1cdbd2cSJim Jagielski
206*b1cdbd2cSJim Jagielski return pRet;
207*b1cdbd2cSJim Jagielski }
208*b1cdbd2cSJim Jagielski }
209*b1cdbd2cSJim Jagielski
210*b1cdbd2cSJim Jagielski
211*b1cdbd2cSJim Jagielski
212