summaryrefslogtreecommitdiff
path: root/cli_ure/source
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2007-05-09 12:30:57 +0000
committerKurt Zenker <kz@openoffice.org>2007-05-09 12:30:57 +0000
commit7b9d203177cf4ccc50cf664066cf7bc721f56864 (patch)
treefad16cca1554b16e27dd0ddbc1bed6418f75b9ba /cli_ure/source
parent22f7117d120088d7e572613dbbd9db96ee5a0cb0 (diff)
INTEGRATION: CWS bunoexttm (1.1.2); FILE ADDED
2006/12/19 12:05:22 kr 1.1.2.1: added: moved cli_uno bridge from bridges to here
Diffstat (limited to 'cli_ure/source')
-rw-r--r--cli_ure/source/uno_bridge/cli_base.h188
-rw-r--r--cli_ure/source/uno_bridge/cli_bridge.h128
2 files changed, 316 insertions, 0 deletions
diff --git a/cli_ure/source/uno_bridge/cli_base.h b/cli_ure/source/uno_bridge/cli_base.h
new file mode 100644
index 000000000000..ef19d43e509e
--- /dev/null
+++ b/cli_ure/source/uno_bridge/cli_base.h
@@ -0,0 +1,188 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: cli_base.h,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: kz $ $Date: 2007-05-09 13:30:36 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#if ! defined INCLUDED_CLI_BASE_H
+#define INCLUDED_CLI_BASE_H
+
+#pragma unmanaged
+// Workaround: osl/mutex.h contains only a forward declaration of _oslMutexImpls.
+// When using the inline class in Mutex in osl/mutex.hxx, the loader needs to find
+// a declaration for the struct. If not found a TypeLoadException is being thrown.
+struct _oslMutexImpl
+{
+};
+#pragma managed
+#include <memory>
+#include "rtl/ustring.hxx"
+#include "typelib/typedescription.hxx"
+
+#using <mscorlib.dll>
+#using <system.dll>
+
+#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
+
+namespace cli_uno
+{
+System::Type* loadCliType(System::String * typeName);
+System::Type* mapUnoType(typelib_TypeDescription const * pTD);
+System::Type* mapUnoType(typelib_TypeDescriptionReference const * pTD);
+typelib_TypeDescriptionReference* mapCliType(System::Type* cliType);
+rtl::OUString mapCliString(System::String const * data);
+System::String* mapUnoString(rtl_uString const * data);
+System::String* mapUnoTypeName(rtl_uString const * typeName);
+
+__gc struct Constants
+{
+ static const System::String* sXInterfaceName= new System::String(
+ S"unoidl.com.sun.star.uno.XInterface");
+ static const System::String* sObject= new System::String(S"System.Object");
+ static const System::String* sType= new System::String(S"System.Type");
+ static const System::String* sUnoidl= new System::String(S"unoidl.");
+ static const System::String* sVoid= new System::String(S"System.Void");
+ static const System::String* sAny= new System::String(S"uno.Any");
+ static const System::String* sArArray= new System::String(S"System.Array[]");
+ static const System::String* sBoolean= new System::String(S"System.Boolean");
+ static const System::String* sChar= new System::String(S"System.Char");
+ static const System::String* sByte= new System::String(S"System.Byte");
+ static const System::String* sInt16= new System::String(S"System.Int16");
+ static const System::String* sUInt16= new System::String(S"System.UInt16");
+ static const System::String* sInt32= new System::String(S"System.Int32");
+ static const System::String* sUInt32= new System::String(S"System.UInt32");
+ static const System::String* sInt64= new System::String(S"System.Int64");
+ static const System::String* sUInt64= new System::String(S"System.UInt64");
+ static const System::String* sString= new System::String(S"System.String");
+ static const System::String* sSingle= new System::String(S"System.Single");
+ static const System::String* sDouble= new System::String(S"System.Double");
+ static const System::String* sArBoolean= new System::String(S"System.Boolean[]");
+ static const System::String* sArChar= new System::String(S"System.Char[]");
+ static const System::String* sArByte= new System::String(S"System.Byte[]");
+ static const System::String* sArInt16= new System::String(S"System.Int16[]");
+ static const System::String* sArUInt16= new System::String(S"System.UInt16[]");
+ static const System::String* sArInt32= new System::String(S"System.Int32[]");
+ static const System::String* sArUInt32= new System::String(S"System.UInt32[]");
+ static const System::String* sArInt64= new System::String(S"System.Int64[]");
+ static const System::String* sArUInt64= new System::String(S"System.UInt64[]");
+ static const System::String* sArString= new System::String(S"System.String[]");
+ static const System::String* sArSingle= new System::String(S"System.Single[]");
+ static const System::String* sArDouble= new System::String(S"System.Double[]");
+ static const System::String* sArType= new System::String(S"System.Type[]");
+ static const System::String* sArObject= new System::String(S"System.Object[]");
+ static const System::String* sBrackets= new System::String(S"[]");
+ static const System::String* sAttributeSet= new System::String(S"set_");
+ static const System::String* sAttributeGet= new System::String(S"get_");
+
+ static const System::String* usXInterface = S"com.sun.star.uno.XInterface";
+ static const System::String* usVoid = S"void";
+ static const System::String* usType = S"type";
+ static const System::String* usAny = S"any";
+ static const System::String* usBrackets = S"[]";
+ static const System::String* usBool = S"boolean";
+ static const System::String* usByte = S"byte";
+ static const System::String* usChar = S"char";
+ static const System::String* usShort = S"short";
+ static const System::String* usUShort = S"unsigned short";
+ static const System::String* usLong = S"long";
+ static const System::String* usULong = S"unsigned long";
+ static const System::String* usHyper = S"hyper";
+ static const System::String* usUHyper = S"unsigned hyper";
+ static const System::String* usString = S"string";
+ static const System::String* usFloat = S"float";
+ static const System::String* usDouble = S"double";
+};
+
+struct BridgeRuntimeError
+{
+ ::rtl::OUString m_message;
+
+ inline BridgeRuntimeError( ::rtl::OUString const & message )
+ : m_message( message )
+ {}
+};
+
+//==================================================================================================
+struct rtl_mem
+{
+ inline static void * operator new ( size_t nSize )
+ { return rtl_allocateMemory( nSize ); }
+ inline static void operator delete ( void * mem )
+ { if (mem) rtl_freeMemory( mem ); }
+ inline static void * operator new ( size_t, void * mem )
+ { return mem; }
+ inline static void operator delete ( void *, void * )
+ {}
+
+ static inline ::std::auto_ptr< rtl_mem > allocate( ::std::size_t bytes );
+};
+//--------------------------------------------------------------------------------------------------
+inline ::std::auto_ptr< rtl_mem > rtl_mem::allocate( ::std::size_t bytes )
+{
+ void * p = rtl_allocateMemory( bytes );
+ if (0 == p)
+ throw BridgeRuntimeError(OUSTR("out of memory!") );
+ return ::std::auto_ptr< rtl_mem >( (rtl_mem *)p );
+}
+
+//==================================================================================================
+class TypeDescr
+{
+ typelib_TypeDescription * m_td;
+
+ TypeDescr( TypeDescr & ); // not impl
+ void operator = ( TypeDescr ); // not impl
+
+public:
+ inline explicit TypeDescr( typelib_TypeDescriptionReference * td_ref );
+ inline ~TypeDescr() SAL_THROW( () )
+ { TYPELIB_DANGER_RELEASE( m_td ); }
+
+ inline typelib_TypeDescription * get() const
+ { return m_td; }
+};
+
+inline TypeDescr::TypeDescr( typelib_TypeDescriptionReference * td_ref )
+ : m_td( 0 )
+{
+ TYPELIB_DANGER_GET( &m_td, td_ref );
+ if (0 == m_td)
+ {
+ throw BridgeRuntimeError(
+ OUSTR("cannot get comprehensive type description for ") +
+ *reinterpret_cast< ::rtl::OUString const * >( &td_ref->pTypeName ) );
+ }
+}
+
+
+} //end namespace cli_uno
+ #endif
diff --git a/cli_ure/source/uno_bridge/cli_bridge.h b/cli_ure/source/uno_bridge/cli_bridge.h
new file mode 100644
index 000000000000..46d6f9527702
--- /dev/null
+++ b/cli_ure/source/uno_bridge/cli_bridge.h
@@ -0,0 +1,128 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: cli_bridge.h,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: kz $ $Date: 2007-05-09 13:30:57 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#if ! defined INCLUDED_CLI_BRIDGE_H
+#define INCLUDED_CLI_BRIDGE_H
+#include <vcclr.h>
+#include "osl/interlck.h"
+#include "uno/mapping.h"
+#include "uno/environment.h"
+#include "uno/dispatcher.h"
+#include "cli_base.h"
+#include "cli_environment.h"
+#using <mscorlib.dll>
+#using <cli_types.dll>
+#using <cli_basetypes.dll>
+#using <system.dll>
+
+namespace sr = System::Reflection;
+
+namespace cli_uno
+{
+
+
+//==== holds environments and mappings =============================================================
+struct Bridge;
+struct Mapping : public uno_Mapping
+{
+ Bridge* m_bridge;
+};
+
+// The environment will be created in uno_initEnvironment. See also the remarks there
+//Managed cli environment for cli objects an UNO proxies (which are cli
+//objects. The uno_Environment is not used for cli objects.
+__gc struct CliEnvHolder {
+static Cli_environment * g_cli_env = NULL;
+};
+
+//==================================================================================================
+/** An instance of Bridge represents exactly one mapping therefore either
+ m_cli2uno or m_uno2cli is valid.
+*/
+struct Bridge
+{
+ mutable oslInterlockedCount m_ref;
+ uno_ExtEnvironment * m_uno_env;
+ uno_Environment * m_uno_cli_env;
+
+ Mapping m_cli2uno;
+ Mapping m_uno2cli;
+ bool m_registered_cli2uno;
+
+ ~Bridge() SAL_THROW( () );
+ Bridge( uno_Environment * java_env, uno_ExtEnvironment * uno_env, bool registered_java2uno );
+
+ void acquire() const;
+ void release() const;
+
+ void map_to_uno(
+ void * uno_data, System::Object* cli_data,
+ typelib_TypeDescriptionReference * type,
+ bool assign) const;
+
+ /**
+ @param info
+ the type of the converted data. It may be a byref type.
+ */
+ void map_to_cli(
+ System::Object* *cli_data, void const * uno_data,
+ typelib_TypeDescriptionReference * type, System::Type* info /* maybe 0 */,
+ bool bDontCreateObj) const;
+
+ System::Object* map_uno2cli(uno_Interface * pUnoI, typelib_InterfaceTypeDescription* pTD) const;
+
+ System::Object* Bridge::call_uno(uno_Interface * pUnoI,
+ typelib_TypeDescription* member_td,
+ typelib_TypeDescriptionReference * return_type,
+ sal_Int32 nParams, typelib_MethodParameter const * pParams,
+ System::Object * args[], System::Type* argTypes[],
+ System::Object** pException) const;
+
+
+ void call_cli(
+ System::Object* cliI, sr::MethodInfo* method,
+ typelib_TypeDescriptionReference * return_type,
+ typelib_MethodParameter * params, int nParams,
+ void * uno_ret, void * uno_args [], uno_Any ** uno_exc ) const;
+
+ uno_Interface * map_cli2uno(
+ System::Object* cliI, typelib_TypeDescription* pTD) const;
+
+};
+
+} //namespace cli_uno
+
+
+#endif