Bump for 3.6-28
[LibreOffice.git] / cli_ure / source / bootstrap / native_glue.cxx
blob10f63fb76570cff6befd660aa4a0dcfd44118098
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #ifndef _RTL_USTRING_HXX_
29 #include "rtl/ustring.hxx"
30 #endif
31 #ifndef _RTL_BOOTSTRAP_HXX_
32 #include "rtl/bootstrap.hxx"
33 #endif
34 #ifndef _CPPUHELPER_BOOTSTRAP_HXX_
35 #include "cppuhelper/bootstrap.hxx"
36 #endif
37 #ifndef _UNO_MAPPING_HXX_
38 #include "uno/mapping.hxx"
39 #endif
40 extern "C" {
41 #include "mono/metadata/object.h"
44 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
46 using namespace com::sun::star::uno;
48 static void * to_cli( Reference< XInterface > const & context )
50 Mapping mapping( OUSTR( CPPU_CURRENT_LANGUAGE_BINDING_NAME ), OUSTR( UNO_LB_CLI ) );
51 OSL_ASSERT( mapping.is() );
52 if (! mapping.is() )
54 // FIXME do something
55 return 0;
58 return (void *)mono_gchandle_new( (MonoObject *)mapping.mapInterface( context.get(), ::getCppuType( &context ) ), sal_False );
61 extern "C" {
63 void SAL_CALL native_bootstrap_set( const sal_Unicode* pName, sal_Int32 nNameLength,
64 const sal_Unicode* pValue, sal_Int32 nValueLength )
65 SAL_THROW_EXTERN_C()
67 ::rtl::OUString const name( pName, nNameLength );
68 ::rtl::OUString const value( pValue, nValueLength );
70 ::rtl::Bootstrap::set( name, value );
73 void * SAL_CALL native_defaultBootstrap_InitialComponentContext()
74 SAL_THROW_EXTERN_C()
76 try {
77 Reference< XComponentContext > xContext = ::cppu::defaultBootstrap_InitialComponentContext();
79 return to_cli( xContext );
80 } catch (const Exception &ex) {
81 fprintf( stderr, "Exception bootstrapping '%s'\n",
82 (const sal_Char *) rtl::OUStringToOString( ex.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
83 return NULL;
87 void * SAL_CALL native_defaultBootstrap_InitialComponentContext_iniFile( const sal_Unicode *pIniFile, sal_Int32 nNameLength )
88 SAL_THROW_EXTERN_C()
90 ::rtl::OUString sFileName( pIniFile, nNameLength );
92 try {
93 Reference< XComponentContext > xContext = ::cppu::defaultBootstrap_InitialComponentContext( sFileName );
94 if (!xContext.is())
95 fprintf( stderr, "Bootstrap context is in fact NULL\n" );
97 return to_cli( xContext );
98 } catch (const Exception &ex) {
99 rtl::OString aIni = rtl::OUStringToOString( sFileName, RTL_TEXTENCODING_UTF8 );
100 fprintf( stderr, "Exception bootstrapping from ini '%s' (%d) '%s'\n", (const sal_Char *) aIni.getStr(), nNameLength,
101 (const sal_Char *) rtl::OUStringToOString( ex.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
102 return NULL;
106 void * SAL_CALL native_bootstrap()
107 SAL_THROW_EXTERN_C()
109 Reference< XComponentContext > xContext = ::cppu::bootstrap();
111 return to_cli( xContext );
114 } // extern "C"