xref: /aoo42x/main/io/test/stm/testfactreg.cxx (revision 3716f815)
1*3716f815SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3716f815SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3716f815SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3716f815SAndrew Rist  * distributed with this work for additional information
6*3716f815SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3716f815SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3716f815SAndrew Rist  * "License"); you may not use this file except in compliance
9*3716f815SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3716f815SAndrew Rist  *
11*3716f815SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3716f815SAndrew Rist  *
13*3716f815SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3716f815SAndrew Rist  * software distributed under the License is distributed on an
15*3716f815SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3716f815SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3716f815SAndrew Rist  * specific language governing permissions and limitations
18*3716f815SAndrew Rist  * under the License.
19*3716f815SAndrew Rist  *
20*3716f815SAndrew Rist  *************************************************************/
21*3716f815SAndrew Rist 
22*3716f815SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_io.hxx"
26cdf0e10cSrcweir #include <stdio.h>
27cdf0e10cSrcweir #include <string.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <osl/diagnose.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <cppuhelper/factory.hxx>  // for EXTERN_SERVICE_CALLTYPE
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::rtl;
34cdf0e10cSrcweir using namespace ::cppu;
35cdf0e10cSrcweir using namespace ::com::sun::star::registry;
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir using namespace ::com::sun::star::lang;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "testfactreg.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir extern "C"
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment ** ppEnv)45cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment(
46cdf0e10cSrcweir 	const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
component_writeInfo(void * pServiceManager,void * pRegistryKey)52cdf0e10cSrcweir sal_Bool SAL_CALL component_writeInfo(
53cdf0e10cSrcweir 	void * pServiceManager, void * pRegistryKey )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	if (pRegistryKey)
56cdf0e10cSrcweir 	{
57cdf0e10cSrcweir 		try
58cdf0e10cSrcweir 		{
59cdf0e10cSrcweir 			Reference< XRegistryKey > xKey(
60cdf0e10cSrcweir 				reinterpret_cast< XRegistryKey * >( pRegistryKey ) );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 			OUString str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
63cdf0e10cSrcweir 				OPipeTest_getImplementationName() +
64cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
65cdf0e10cSrcweir 			Reference< XRegistryKey >  xNewKey = xKey->createKey( str );
66cdf0e10cSrcweir 			xNewKey->createKey( OPipeTest_getServiceName() );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
69cdf0e10cSrcweir 				OPumpTest_getImplementationName() +
70cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
71cdf0e10cSrcweir 			xNewKey = xKey->createKey( str );
72cdf0e10cSrcweir 			xNewKey->createKey( OPumpTest_getServiceName() );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
75cdf0e10cSrcweir 				ODataStreamTest_getImplementationName(1) +
76cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
77cdf0e10cSrcweir 			xNewKey = xKey->createKey( str );
78cdf0e10cSrcweir 			xNewKey->createKey( ODataStreamTest_getServiceName(1) );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
81cdf0e10cSrcweir 				ODataStreamTest_getImplementationName(2) +
82cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
83cdf0e10cSrcweir 			xNewKey = xKey->createKey( str );
84cdf0e10cSrcweir 			xNewKey->createKey( ODataStreamTest_getServiceName(2) );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
87cdf0e10cSrcweir 				OObjectStreamTest_getImplementationName(1) +
88cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
89cdf0e10cSrcweir 			xNewKey = xKey->createKey( str );
90cdf0e10cSrcweir 			xNewKey->createKey( OObjectStreamTest_getServiceName(1) );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
93cdf0e10cSrcweir 				OObjectStreamTest_getImplementationName(2) +
94cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
95cdf0e10cSrcweir 			xNewKey = xKey->createKey( str );
96cdf0e10cSrcweir 			xNewKey->createKey( OObjectStreamTest_getServiceName(2) );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
99cdf0e10cSrcweir 				OMarkableOutputStreamTest_getImplementationName() +
100cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
101cdf0e10cSrcweir 			xNewKey = xKey->createKey( str );
102cdf0e10cSrcweir 			xNewKey->createKey( OMarkableOutputStreamTest_getServiceName() );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
105cdf0e10cSrcweir 				OMarkableInputStreamTest_getImplementationName() +
106cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
107cdf0e10cSrcweir 			xNewKey = xKey->createKey( str );
108cdf0e10cSrcweir 			xNewKey->createKey( OMarkableInputStreamTest_getServiceName() );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
111cdf0e10cSrcweir 				OMyPersistObject_getImplementationName() +
112cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
113cdf0e10cSrcweir 			xNewKey = xKey->createKey( str );
114cdf0e10cSrcweir 			xNewKey->createKey( OMyPersistObject_getServiceName() );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 			return sal_True;
117cdf0e10cSrcweir 		}
118cdf0e10cSrcweir 		catch (InvalidRegistryException &)
119cdf0e10cSrcweir 		{
120cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
121cdf0e10cSrcweir 		}
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir 	return sal_False;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey)126cdf0e10cSrcweir void * SAL_CALL component_getFactory(
127cdf0e10cSrcweir 	const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	void * pRet = 0;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	if (pServiceManager )
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		Reference< XSingleServiceFactory > xRet;
134cdf0e10cSrcweir 		Reference< XMultiServiceFactory > xSMgr =
135cdf0e10cSrcweir 			reinterpret_cast< XMultiServiceFactory * > ( pServiceManager );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 		OUString aImplementationName = OUString::createFromAscii( pImplName );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 		if (aImplementationName == OPipeTest_getImplementationName() )
140cdf0e10cSrcweir 		{
141cdf0e10cSrcweir 			xRet = createSingleFactory( xSMgr, aImplementationName,
142cdf0e10cSrcweir 										OPipeTest_CreateInstance,
143cdf0e10cSrcweir 										OPipeTest_getSupportedServiceNames() );
144cdf0e10cSrcweir 		}
145cdf0e10cSrcweir 		else if (aImplementationName == OPumpTest_getImplementationName() )
146cdf0e10cSrcweir 		{
147cdf0e10cSrcweir 			xRet = createSingleFactory( xSMgr, aImplementationName,
148cdf0e10cSrcweir 										OPumpTest_CreateInstance,
149cdf0e10cSrcweir 										OPumpTest_getSupportedServiceNames() );
150cdf0e10cSrcweir 		}
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 		else if( aImplementationName == ODataStreamTest_getImplementationName(1) ) {
153cdf0e10cSrcweir 			xRet = createSingleFactory( xSMgr , aImplementationName,
154cdf0e10cSrcweir 										ODataStreamTest_CreateInstance,
155cdf0e10cSrcweir 										ODataStreamTest_getSupportedServiceNames(1) );
156cdf0e10cSrcweir 		}
157cdf0e10cSrcweir 		else if( aImplementationName == ODataStreamTest_getImplementationName(2) ) {
158cdf0e10cSrcweir 			xRet = createSingleFactory( xSMgr , aImplementationName,
159cdf0e10cSrcweir 										ODataStreamTest_CreateInstance,
160cdf0e10cSrcweir 										ODataStreamTest_getSupportedServiceNames(2) );
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 		else if( aImplementationName == OObjectStreamTest_getImplementationName(1) ) {
163cdf0e10cSrcweir 			xRet = createSingleFactory( xSMgr , aImplementationName,
164cdf0e10cSrcweir 										OObjectStreamTest_CreateInstance,
165cdf0e10cSrcweir 										OObjectStreamTest_getSupportedServiceNames(1) );
166cdf0e10cSrcweir 		}
167cdf0e10cSrcweir 		else if( aImplementationName == OObjectStreamTest_getImplementationName(2) ) {
168cdf0e10cSrcweir 			xRet = createSingleFactory( xSMgr , aImplementationName,
169cdf0e10cSrcweir 										OObjectStreamTest_CreateInstance,
170cdf0e10cSrcweir 										OObjectStreamTest_getSupportedServiceNames(2) );
171cdf0e10cSrcweir 		}
172cdf0e10cSrcweir 		else if( aImplementationName == OMarkableOutputStreamTest_getImplementationName() ) {
173cdf0e10cSrcweir 			xRet = createSingleFactory( xSMgr , aImplementationName,
174cdf0e10cSrcweir 										OMarkableOutputStreamTest_CreateInstance,
175cdf0e10cSrcweir 										OMarkableOutputStreamTest_getSupportedServiceNames() );
176cdf0e10cSrcweir 		}
177cdf0e10cSrcweir 		else if( aImplementationName == OMarkableInputStreamTest_getImplementationName() ) {
178cdf0e10cSrcweir 			xRet = createSingleFactory( xSMgr , aImplementationName,
179cdf0e10cSrcweir 										OMarkableInputStreamTest_CreateInstance,
180cdf0e10cSrcweir 										OMarkableInputStreamTest_getSupportedServiceNames() );
181cdf0e10cSrcweir 		}
182cdf0e10cSrcweir 		else if( aImplementationName == OMyPersistObject_getImplementationName() ) {
183cdf0e10cSrcweir 			xRet = createSingleFactory( xSMgr , aImplementationName,
184cdf0e10cSrcweir 									OMyPersistObject_CreateInstance,
185cdf0e10cSrcweir 										OMyPersistObject_getSupportedServiceNames() );
186cdf0e10cSrcweir 		}
187cdf0e10cSrcweir 		if (xRet.is())
188cdf0e10cSrcweir 		{
189cdf0e10cSrcweir 			xRet->acquire();
190cdf0e10cSrcweir 			pRet = xRet.get();
191cdf0e10cSrcweir 		}
192cdf0e10cSrcweir 	}
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	return pRet;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
createSeq(char * p)199cdf0e10cSrcweir Sequence<sal_Int8 > createSeq( char * p )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	Sequence<sal_Int8> seq( strlen( p )+1 );
202cdf0e10cSrcweir 	strcpy( (char * ) seq.getArray() , p );
203cdf0e10cSrcweir 	return seq;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
createIntSeq(sal_Int32 i)206cdf0e10cSrcweir Sequence<sal_Int8> createIntSeq( sal_Int32 i )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir 	char pcCount[20];
209cdf0e10cSrcweir 	sprintf( pcCount , "%d" , i );
210cdf0e10cSrcweir 	return createSeq( pcCount );
211cdf0e10cSrcweir }
212cdf0e10cSrcweir 
213