Update ooo320-m1
[ooovba.git] / desktop / source / splash / services_spl.cxx
blobd10546d4809c2fa05c114a17438361ff60b1547b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: services_spl.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_desktop.hxx"
33 #include <com/sun/star/beans/NamedValue.hpp>
34 #include <com/sun/star/registry/XRegistryKey.hpp>
35 #include <com/sun/star/util/Date.hpp>
36 #include <uno/environment.h>
37 #include <cppuhelper/factory.hxx>
38 #include <unotools/configmgr.hxx>
40 #include "splash.hxx"
41 #include "firststart.hxx"
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;
51 static const char* pServices[] =
53 SplashScreen::serviceName,
54 FirstStart::serviceName,
55 NULL
58 static const char* pImplementations[] =
60 SplashScreen::implementationName,
61 FirstStart::implementationName,
62 NULL
65 typedef Reference<XInterface>(* fProvider)(const Reference<XMultiServiceFactory>&);
67 static const fProvider pInstanceProviders[] =
69 SplashScreen::getInstance,
70 FirstStart::CreateInstance,
71 NULL
75 static const char** pSupportedServices[] =
77 SplashScreen::interfaces,
78 FirstStart::interfaces,
79 NULL
80 };
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]);
90 return aSeq;
93 extern "C"
95 void SAL_CALL
96 component_getImplementationEnvironment(
97 const sal_Char** ppEnvironmentTypeName,
98 uno_Environment**)
100 *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
103 sal_Bool SAL_CALL
104 component_writeInfo(
105 void* pServiceManager,
106 void* pRegistryKey)
108 Reference<XMultiServiceFactory> xMan(
109 reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
110 Reference<XRegistryKey> xKey(
111 reinterpret_cast< XRegistryKey* >( pRegistryKey ) ) ;
113 // iterate over service names and register them...
114 OUString aImpl;
115 const char* pServiceName = NULL;
116 const char* pImplName = NULL;
117 for (int i = 0; (pServices[i]!=NULL)&&(pImplementations[i]!=NULL); i++) {
118 pServiceName= pServices[i];
119 pImplName = pImplementations[i];
120 aImpl = OUString::createFromAscii("/")
121 + OUString::createFromAscii(pImplName)
122 + OUString::createFromAscii("/UNO/SERVICES");
123 Reference<XRegistryKey> xNewKey = xKey->createKey(aImpl);
124 xNewKey->createKey(OUString::createFromAscii(pServiceName));
126 return sal_True;
129 void* SAL_CALL
130 component_getFactory(
131 const sal_Char* pImplementationName,
132 void* pServiceManager,
133 void*)
135 // Set default return value for this operation - if it failed.
136 if ( pImplementationName && pServiceManager )
138 Reference< XSingleServiceFactory > xFactory;
139 Reference< XMultiServiceFactory > xServiceManager(
140 reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
142 // search implementation
143 for (int i = 0; (pImplementations[i]!=NULL); i++) {
144 if ( strcmp(pImplementations[i], pImplementationName ) == 0 ) {
145 // found implementation
146 xFactory = Reference<XSingleServiceFactory>(cppu::createSingleFactory(
147 xServiceManager, OUString::createFromAscii(pImplementationName),
148 pInstanceProviders[i], getSupportedServiceNames(i)));
149 if ( xFactory.is() ) {
150 // Factory is valid - service was found.
151 xFactory->acquire();
152 return xFactory.get();
155 } // for()
157 // Return with result of this operation.
158 return NULL;
160 } // extern "C"