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_desktop.hxx"
26 
27 #include "evaluation.hxx"
28 #include <com/sun/star/beans/NamedValue.hpp>
29 #include <com/sun/star/registry/XRegistryKey.hpp>
30 #include <com/sun/star/util/Date.hpp>
31 #include <uno/environment.h>
32 #include <cppuhelper/factory.hxx>
33 #include <unotools/configmgr.hxx>
34 
35 #include "oemjob.hxx"
36 #include "evaluation.hxx"
37 
38 #include <string.h>
39 
40 using namespace rtl;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::registry;
45 using namespace ::desktop;
46 
47 static const char* pServices[] =
48 {
49     SOEvaluation::serviceName,
50     OEMPreloadJob::serviceName,
51     NULL
52 };
53 
54 static const char* pImplementations[] =
55 {
56     SOEvaluation::implementationName,
57     OEMPreloadJob::implementationName,
58     NULL
59 };
60 
61 typedef Reference<XInterface>(* fProvider)(const Reference<XMultiServiceFactory>&);
62 
63 static const fProvider pInstanceProviders[] =
64 {
65     SOEvaluation::CreateInstance,
66     OEMPreloadJob::CreateInstance,
67     NULL
68 };
69 
70 
71 static const char** pSupportedServices[] =
72 {
73     SOEvaluation::interfaces,
74     OEMPreloadJob::interfaces,
75     NULL
76 };
77 
78 static Sequence<OUString>
getSupportedServiceNames(int p)79 getSupportedServiceNames(int p) {
80     const char **names = pSupportedServices[p];
81     Sequence<OUString> aSeq;
82     for(int i = 0; names[i] != NULL; i++) {
83         aSeq.realloc(i+1);
84         aSeq[i] = OUString::createFromAscii(names[i]);
85     }
86     return aSeq;
87 }
88 
89 extern "C"
90 {
91 void SAL_CALL
component_getImplementationEnvironment(const sal_Char ** ppEnvironmentTypeName,uno_Environment **)92 component_getImplementationEnvironment(
93     const sal_Char** ppEnvironmentTypeName,
94     uno_Environment**)
95 {
96 	*ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
97 }
98 
99 void* SAL_CALL
component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void *)100 component_getFactory(
101     const sal_Char* pImplementationName,
102     void* pServiceManager,
103     void*)
104 {
105 	// Set default return value for this operation - if it failed.
106     if  ( pImplementationName && pServiceManager )
107 	{
108         Reference< XSingleServiceFactory > xFactory;
109         Reference< XMultiServiceFactory > xServiceManager(
110             reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
111 
112         // search implementation
113         for (int i = 0; (pImplementations[i]!=NULL); i++) {
114             if ( strcmp(pImplementations[i], pImplementationName ) == 0 ) {
115                 // found implementation
116 			    xFactory = Reference<XSingleServiceFactory>(cppu::createSingleFactory(
117                     xServiceManager, OUString::createFromAscii(pImplementationName),
118                     pInstanceProviders[i], getSupportedServiceNames(i)));
119                 if ( xFactory.is() ) {
120                     // Factory is valid - service was found.
121 			        xFactory->acquire();
122 			        return xFactory.get();
123 		        }
124             }
125         } // for()
126 	}
127 	// Return with result of this operation.
128 	return NULL;
129 }
130 } // extern "C"
131