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