1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sdext.hxx"
30 
31 #include <stdio.h>
32 #include <osl/mutex.hxx>
33 #include <osl/thread.h>
34 #include <cppuhelper/factory.hxx>
35 #include <pppoptimizer.hxx>
36 #include <pppoptimizerdialog.hxx>
37 
38 using namespace ::rtl;
39 using namespace ::cppu;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::registry;
43 
44 extern "C"
45 {
46     void SAL_CALL component_getImplementationEnvironment(
47 	    const sal_Char ** ppEnvTypeName, uno_Environment ** )
48     {
49 	    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
50     }
51 
52     // -------------------------------------------------------------------------
53 
54     sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey )
55     {
56 	    if (pRegistryKey)
57 	    {
58 		    try
59 		    {
60                 Reference< XRegistryKey >   xNewKey;
61                 sal_Int32                   nPos;
62 
63                 xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( PPPOptimizer_getImplementationName() );
64                 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
65                 const Sequence< OUString > & rSNL1 = PPPOptimizer_getSupportedServiceNames();
66 			    const OUString * pArray1 = rSNL1.getConstArray();
67 			    for ( nPos = rSNL1.getLength(); nPos--; )
68 				    xNewKey->createKey( pArray1[nPos] );
69 
70                 xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( PPPOptimizerDialog_getImplementationName() );
71                 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
72 			    const Sequence< OUString > & rSNL2 = PPPOptimizerDialog_getSupportedServiceNames();
73 			    const OUString * pArray2 = rSNL2.getConstArray();
74 			    for ( nPos = rSNL2.getLength(); nPos--; )
75 				    xNewKey->createKey( pArray2[nPos] );
76 
77 			    return sal_True;
78 		    }
79 		    catch (InvalidRegistryException &)
80 		    {
81 			    OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
82 		    }
83 	    }
84 	    return sal_False;
85     }
86 
87     // -------------------------------------------------------------------------
88 
89     void* SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
90     {
91         OUString    aImplName( OUString::createFromAscii( pImplName ) );
92 	    void*       pRet = 0;
93 
94         if( pServiceManager )
95         {
96             Reference< XSingleComponentFactory > xFactory;
97             if( aImplName.equals( PPPOptimizer_getImplementationName() ) )
98 	        {
99 		        xFactory = createSingleComponentFactory(
100 						PPPOptimizer_createInstance,
101 						OUString::createFromAscii( pImplName ),
102 						PPPOptimizer_getSupportedServiceNames() );
103 
104 	        }
105             else if( aImplName.equals( PPPOptimizerDialog_getImplementationName() ) )
106 	        {
107 				xFactory = createSingleComponentFactory(
108 						PPPOptimizerDialog_createInstance,
109                         OUString::createFromAscii( pImplName ),
110 						PPPOptimizerDialog_getSupportedServiceNames() );
111 	        }
112             if( xFactory.is() )
113             {
114 			    xFactory->acquire();
115                 pRet = xFactory.get();
116             }
117         }
118 	    return pRet;
119     }
120 }
121