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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cppu.hxx"
31 #include "osl/mutex.hxx"
32 #include "osl/thread.h"
33 #include "uno/dispatcher.h"
34 #include "typelib/typedescription.hxx"
35 #include "cppu/helper/purpenv/Environment.hxx"
36 #include "cppu/helper/purpenv/Mapping.hxx"
37 #include "cppu/EnvDcp.hxx"
38 #include "rtl/logfile.hxx"
39 #include "uno/environment.hxx"
40 #include <com/sun/star/uno/Type.hxx>
46 class LogBridge
: public cppu::Enterable
50 oslThreadIdentifier m_threadId
;
52 virtual ~LogBridge(void);
55 explicit LogBridge(void);
57 virtual void v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
);
58 virtual void v_callOut_v (uno_EnvCallee
* pCallee
, va_list * pParam
);
60 virtual void v_enter(void);
61 virtual void v_leave(void);
63 virtual int v_isValid(rtl::OUString
* pReason
);
66 LogBridge::LogBridge(void)
72 LogBridge::~LogBridge(void)
74 OSL_ASSERT(m_count
>= 0);
77 void LogBridge::v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
84 void LogBridge::v_callOut_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
86 OSL_ASSERT(m_count
> 0);
93 m_threadId
= osl_getThreadIdentifier(NULL
);
96 void LogBridge::v_enter(void)
100 OSL_ASSERT(m_count
>= 0);
103 m_threadId
= osl_getThreadIdentifier(NULL
);
108 void LogBridge::v_leave(void)
110 OSL_ASSERT(m_count
> 0);
120 int LogBridge::v_isValid(rtl::OUString
* pReason
)
124 result
= m_count
> 0;
126 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("not entered"));
130 result
= m_threadId
== osl_getThreadIdentifier(NULL
);
133 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("wrong thread"));
137 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OK"));
142 void traceValue(typelib_TypeDescriptionReference
* _pTypeRef
,void* pArg
)
144 switch(_pTypeRef
->eTypeClass
)
146 case typelib_TypeClass_STRING
:
148 const ::rtl::OString
sValue( ::rtl::OUStringToOString(*static_cast< ::rtl::OUString
*>(pArg
),osl_getThreadTextEncoding()));
149 rtl_logfile_trace( "%s", sValue
.getStr());
152 case typelib_TypeClass_BOOLEAN
:
153 rtl_logfile_trace( "%d", *static_cast<sal_Bool
*>(pArg
));
155 case typelib_TypeClass_BYTE
:
156 rtl_logfile_trace( "%d", *static_cast<sal_Int8
*>(pArg
));
158 case typelib_TypeClass_CHAR
:
159 rtl_logfile_trace( "%c", *static_cast<sal_Char
*>(pArg
));
161 case typelib_TypeClass_SHORT
:
162 case typelib_TypeClass_UNSIGNED_SHORT
:
163 rtl_logfile_trace( "%d", *static_cast<sal_Int16
*>(pArg
));
165 case typelib_TypeClass_LONG
:
166 case typelib_TypeClass_UNSIGNED_LONG
:
167 case typelib_TypeClass_ENUM
:
168 rtl_logfile_trace( "%d", *static_cast<sal_Int32
*>(pArg
));
170 case typelib_TypeClass_HYPER
:
171 case typelib_TypeClass_UNSIGNED_HYPER
:
172 rtl_logfile_trace( "%d", *static_cast<sal_Int64
*>(pArg
));
174 case typelib_TypeClass_FLOAT
:
175 rtl_logfile_trace( "%f", *static_cast<float*>(pArg
));
177 case typelib_TypeClass_DOUBLE
:
178 rtl_logfile_trace( "%f", *static_cast<double*>(pArg
));
180 case typelib_TypeClass_TYPE
:
182 const ::rtl::OString
sValue( ::rtl::OUStringToOString(((com::sun::star::uno::Type
*)pArg
)->getTypeName(),osl_getThreadTextEncoding()));
183 rtl_logfile_trace( "%s", sValue
.getStr());
186 case typelib_TypeClass_ANY
:
187 if ( static_cast<uno_Any
*>(pArg
)->pData
)
188 traceValue(static_cast<uno_Any
*>(pArg
)->pType
,static_cast<uno_Any
*>(pArg
)->pData
);
190 rtl_logfile_trace( "void");
192 case typelib_TypeClass_EXCEPTION
:
193 rtl_logfile_trace( "exception");
195 case typelib_TypeClass_INTERFACE
:
197 const ::rtl::OString
sValue( ::rtl::OUStringToOString(_pTypeRef
->pTypeName
,osl_getThreadTextEncoding()));
198 rtl_logfile_trace( "%s 0x%p", sValue
.getStr(),pArg
);
201 case typelib_TypeClass_VOID
:
202 rtl_logfile_trace( "void");
205 rtl_logfile_trace( "0x%p", pArg
);
207 } // switch(pParams[i].pTypeRef->eTypeClass)
215 typelib_TypeDescriptionReference
* pReturnTypeRef
,
216 typelib_MethodParameter
* pParams
,
218 typelib_TypeDescription
const * pMemberType
,
221 uno_Any
** ppException
)
223 static ::std::auto_ptr
< ::rtl::Logfile
> pLogger
;
224 ::rtl::OString sTemp
;
225 if ( pMemberType
&& pMemberType
->pTypeName
)
226 sTemp
= ::rtl::OUStringToOString(pMemberType
->pTypeName
,RTL_TEXTENCODING_ASCII_US
);
229 rtl_logfile_longTrace( "{ LogBridge () %s", sTemp
.getStr() );
232 rtl_logfile_trace( "\n| : ( LogBridge ");
233 for(sal_Int32 i
= 0;i
< nParams
;++i
)
236 rtl_logfile_trace( ",");
237 traceValue(pParams
[i
].pTypeRef
,pArgs
[i
]);
240 rtl_logfile_trace( ")");
242 rtl_logfile_trace( "\n");
246 rtl_logfile_longTrace( "} LogBridge () %s",sTemp
.getStr());
247 if ( ppException
&& *ppException
)
249 rtl_logfile_trace( " excption occured : ");
250 typelib_TypeDescription
* pElementTypeDescr
= 0;
251 TYPELIB_DANGER_GET( &pElementTypeDescr
, (*ppException
)->pType
);
252 const ::rtl::OString
sValue( ::rtl::OUStringToOString(pElementTypeDescr
->pTypeName
,osl_getThreadTextEncoding()));
253 rtl_logfile_trace( "%s", sValue
.getStr());
254 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
256 else if ( pReturnTypeRef
)
258 rtl_logfile_trace( " return : ");
259 traceValue(pReturnTypeRef
,pReturn
);
260 } // if ( pReturn && pReturnTypeRef )
262 rtl_logfile_trace( "\n");
266 extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL
uno_initEnvironment(uno_Environment
* pEnv
)
269 cppu::helper::purpenv::Environment_initWithEnterable(pEnv
, new LogBridge());
272 extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL
uno_ext_getMapping(uno_Mapping
** ppMapping
,
273 uno_Environment
* pFrom
,
274 uno_Environment
* pTo
)
276 cppu::helper::purpenv::createMapping(ppMapping
, pFrom
, pTo
,LogProbe
);