1*c142477cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c142477cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c142477cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c142477cSAndrew Rist  * distributed with this work for additional information
6*c142477cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c142477cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c142477cSAndrew Rist  * "License"); you may not use this file except in compliance
9*c142477cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c142477cSAndrew Rist  *
11*c142477cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c142477cSAndrew Rist  *
13*c142477cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c142477cSAndrew Rist  * software distributed under the License is distributed on an
15*c142477cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c142477cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c142477cSAndrew Rist  * specific language governing permissions and limitations
18*c142477cSAndrew Rist  * under the License.
19*c142477cSAndrew Rist  *
20*c142477cSAndrew Rist  *************************************************************/
21*c142477cSAndrew Rist 
22*c142477cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sdext.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir #include <osl/mutex.hxx>
29cdf0e10cSrcweir #include <osl/thread.h>
30cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
31cdf0e10cSrcweir #include <pppoptimizer.hxx>
32cdf0e10cSrcweir #include <pppoptimizerdialog.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace ::rtl;
35cdf0e10cSrcweir using namespace ::cppu;
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir using namespace ::com::sun::star::lang;
38cdf0e10cSrcweir using namespace ::com::sun::star::registry;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir extern "C"
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     void SAL_CALL component_getImplementationEnvironment(
43cdf0e10cSrcweir 	    const sal_Char ** ppEnvTypeName, uno_Environment ** )
44cdf0e10cSrcweir     {
45cdf0e10cSrcweir 	    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
46cdf0e10cSrcweir     }
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     // -------------------------------------------------------------------------
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey )
51cdf0e10cSrcweir     {
52cdf0e10cSrcweir 	    if (pRegistryKey)
53cdf0e10cSrcweir 	    {
54cdf0e10cSrcweir 		    try
55cdf0e10cSrcweir 		    {
56cdf0e10cSrcweir                 Reference< XRegistryKey >   xNewKey;
57cdf0e10cSrcweir                 sal_Int32                   nPos;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir                 xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( PPPOptimizer_getImplementationName() );
60cdf0e10cSrcweir                 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
61cdf0e10cSrcweir                 const Sequence< OUString > & rSNL1 = PPPOptimizer_getSupportedServiceNames();
62cdf0e10cSrcweir 			    const OUString * pArray1 = rSNL1.getConstArray();
63cdf0e10cSrcweir 			    for ( nPos = rSNL1.getLength(); nPos--; )
64cdf0e10cSrcweir 				    xNewKey->createKey( pArray1[nPos] );
65cdf0e10cSrcweir 
66cdf0e10cSrcweir                 xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( PPPOptimizerDialog_getImplementationName() );
67cdf0e10cSrcweir                 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
68cdf0e10cSrcweir 			    const Sequence< OUString > & rSNL2 = PPPOptimizerDialog_getSupportedServiceNames();
69cdf0e10cSrcweir 			    const OUString * pArray2 = rSNL2.getConstArray();
70cdf0e10cSrcweir 			    for ( nPos = rSNL2.getLength(); nPos--; )
71cdf0e10cSrcweir 				    xNewKey->createKey( pArray2[nPos] );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 			    return sal_True;
74cdf0e10cSrcweir 		    }
75cdf0e10cSrcweir 		    catch (InvalidRegistryException &)
76cdf0e10cSrcweir 		    {
77cdf0e10cSrcweir 			    OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
78cdf0e10cSrcweir 		    }
79cdf0e10cSrcweir 	    }
80cdf0e10cSrcweir 	    return sal_False;
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     // -------------------------------------------------------------------------
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     void* SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
86cdf0e10cSrcweir     {
87cdf0e10cSrcweir         OUString    aImplName( OUString::createFromAscii( pImplName ) );
88cdf0e10cSrcweir 	    void*       pRet = 0;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         if( pServiceManager )
91cdf0e10cSrcweir         {
92cdf0e10cSrcweir             Reference< XSingleComponentFactory > xFactory;
93cdf0e10cSrcweir             if( aImplName.equals( PPPOptimizer_getImplementationName() ) )
94cdf0e10cSrcweir 	        {
95cdf0e10cSrcweir 		        xFactory = createSingleComponentFactory(
96cdf0e10cSrcweir 						PPPOptimizer_createInstance,
97cdf0e10cSrcweir 						OUString::createFromAscii( pImplName ),
98cdf0e10cSrcweir 						PPPOptimizer_getSupportedServiceNames() );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	        }
101cdf0e10cSrcweir             else if( aImplName.equals( PPPOptimizerDialog_getImplementationName() ) )
102cdf0e10cSrcweir 	        {
103cdf0e10cSrcweir 				xFactory = createSingleComponentFactory(
104cdf0e10cSrcweir 						PPPOptimizerDialog_createInstance,
105cdf0e10cSrcweir                         OUString::createFromAscii( pImplName ),
106cdf0e10cSrcweir 						PPPOptimizerDialog_getSupportedServiceNames() );
107cdf0e10cSrcweir 	        }
108cdf0e10cSrcweir             if( xFactory.is() )
109cdf0e10cSrcweir             {
110cdf0e10cSrcweir 			    xFactory->acquire();
111cdf0e10cSrcweir                 pRet = xFactory.get();
112cdf0e10cSrcweir             }
113cdf0e10cSrcweir         }
114cdf0e10cSrcweir 	    return pRet;
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir }
117