xref: /AOO41X/main/io/test/stm/testfactreg.cxx (revision 3716f815df2d68347af345f8524e39097ef453f6)
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_io.hxx"
26 #include <stdio.h>
27 #include <string.h>
28 
29 #include <osl/diagnose.h>
30 
31 #include <cppuhelper/factory.hxx>  // for EXTERN_SERVICE_CALLTYPE
32 
33 using namespace ::rtl;
34 using namespace ::cppu;
35 using namespace ::com::sun::star::registry;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 
39 #include "testfactreg.hxx"
40 
41 
42 extern "C"
43 {
44 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment ** ppEnv)45 void SAL_CALL component_getImplementationEnvironment(
46     const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
47 {
48     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
49 }
50 
51 
component_writeInfo(void * pServiceManager,void * pRegistryKey)52 sal_Bool SAL_CALL component_writeInfo(
53     void * pServiceManager, void * pRegistryKey )
54 {
55     if (pRegistryKey)
56     {
57         try
58         {
59             Reference< XRegistryKey > xKey(
60                 reinterpret_cast< XRegistryKey * >( pRegistryKey ) );
61 
62             OUString str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
63                 OPipeTest_getImplementationName() +
64                 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
65             Reference< XRegistryKey >  xNewKey = xKey->createKey( str );
66             xNewKey->createKey( OPipeTest_getServiceName() );
67 
68             str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
69                 OPumpTest_getImplementationName() +
70                 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
71             xNewKey = xKey->createKey( str );
72             xNewKey->createKey( OPumpTest_getServiceName() );
73 
74             str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
75                 ODataStreamTest_getImplementationName(1) +
76                 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
77             xNewKey = xKey->createKey( str );
78             xNewKey->createKey( ODataStreamTest_getServiceName(1) );
79 
80             str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
81                 ODataStreamTest_getImplementationName(2) +
82                 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
83             xNewKey = xKey->createKey( str );
84             xNewKey->createKey( ODataStreamTest_getServiceName(2) );
85 
86             str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
87                 OObjectStreamTest_getImplementationName(1) +
88                 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
89             xNewKey = xKey->createKey( str );
90             xNewKey->createKey( OObjectStreamTest_getServiceName(1) );
91 
92             str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
93                 OObjectStreamTest_getImplementationName(2) +
94                 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
95             xNewKey = xKey->createKey( str );
96             xNewKey->createKey( OObjectStreamTest_getServiceName(2) );
97 
98             str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
99                 OMarkableOutputStreamTest_getImplementationName() +
100                 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
101             xNewKey = xKey->createKey( str );
102             xNewKey->createKey( OMarkableOutputStreamTest_getServiceName() );
103 
104             str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
105                 OMarkableInputStreamTest_getImplementationName() +
106                 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
107             xNewKey = xKey->createKey( str );
108             xNewKey->createKey( OMarkableInputStreamTest_getServiceName() );
109 
110             str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
111                 OMyPersistObject_getImplementationName() +
112                 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
113             xNewKey = xKey->createKey( str );
114             xNewKey->createKey( OMyPersistObject_getServiceName() );
115 
116             return sal_True;
117         }
118         catch (InvalidRegistryException &)
119         {
120             OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
121         }
122     }
123     return sal_False;
124 }
125 
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey)126 void * SAL_CALL component_getFactory(
127     const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
128 {
129     void * pRet = 0;
130 
131     if (pServiceManager )
132     {
133         Reference< XSingleServiceFactory > xRet;
134         Reference< XMultiServiceFactory > xSMgr =
135             reinterpret_cast< XMultiServiceFactory * > ( pServiceManager );
136 
137         OUString aImplementationName = OUString::createFromAscii( pImplName );
138 
139         if (aImplementationName == OPipeTest_getImplementationName() )
140         {
141             xRet = createSingleFactory( xSMgr, aImplementationName,
142                                         OPipeTest_CreateInstance,
143                                         OPipeTest_getSupportedServiceNames() );
144         }
145         else if (aImplementationName == OPumpTest_getImplementationName() )
146         {
147             xRet = createSingleFactory( xSMgr, aImplementationName,
148                                         OPumpTest_CreateInstance,
149                                         OPumpTest_getSupportedServiceNames() );
150         }
151 
152         else if( aImplementationName == ODataStreamTest_getImplementationName(1) ) {
153             xRet = createSingleFactory( xSMgr , aImplementationName,
154                                         ODataStreamTest_CreateInstance,
155                                         ODataStreamTest_getSupportedServiceNames(1) );
156         }
157         else if( aImplementationName == ODataStreamTest_getImplementationName(2) ) {
158             xRet = createSingleFactory( xSMgr , aImplementationName,
159                                         ODataStreamTest_CreateInstance,
160                                         ODataStreamTest_getSupportedServiceNames(2) );
161         }
162         else if( aImplementationName == OObjectStreamTest_getImplementationName(1) ) {
163             xRet = createSingleFactory( xSMgr , aImplementationName,
164                                         OObjectStreamTest_CreateInstance,
165                                         OObjectStreamTest_getSupportedServiceNames(1) );
166         }
167         else if( aImplementationName == OObjectStreamTest_getImplementationName(2) ) {
168             xRet = createSingleFactory( xSMgr , aImplementationName,
169                                         OObjectStreamTest_CreateInstance,
170                                         OObjectStreamTest_getSupportedServiceNames(2) );
171         }
172         else if( aImplementationName == OMarkableOutputStreamTest_getImplementationName() ) {
173             xRet = createSingleFactory( xSMgr , aImplementationName,
174                                         OMarkableOutputStreamTest_CreateInstance,
175                                         OMarkableOutputStreamTest_getSupportedServiceNames() );
176         }
177         else if( aImplementationName == OMarkableInputStreamTest_getImplementationName() ) {
178             xRet = createSingleFactory( xSMgr , aImplementationName,
179                                         OMarkableInputStreamTest_CreateInstance,
180                                         OMarkableInputStreamTest_getSupportedServiceNames() );
181         }
182         else if( aImplementationName == OMyPersistObject_getImplementationName() ) {
183             xRet = createSingleFactory( xSMgr , aImplementationName,
184                                     OMyPersistObject_CreateInstance,
185                                         OMyPersistObject_getSupportedServiceNames() );
186         }
187         if (xRet.is())
188         {
189             xRet->acquire();
190             pRet = xRet.get();
191         }
192     }
193 
194     return pRet;
195 }
196 
197 }
198 
createSeq(char * p)199 Sequence<sal_Int8 > createSeq( char * p )
200 {
201     Sequence<sal_Int8> seq( strlen( p )+1 );
202     strcpy( (char * ) seq.getArray() , p );
203     return seq;
204 }
205 
createIntSeq(sal_Int32 i)206 Sequence<sal_Int8> createIntSeq( sal_Int32 i )
207 {
208     char pcCount[20];
209     sprintf( pcCount , "%d" , i );
210     return createSeq( pcCount );
211 }
212 
213