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