1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LogBridge.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppu.hxx"
34 #include "osl/mutex.hxx"
35 #include "osl/thread.h"
36 #include "uno/dispatcher.h"
37 #include "typelib/typedescription.hxx"
38 #include "cppu/helper/purpenv/Environment.hxx"
39 #include "cppu/helper/purpenv/Mapping.hxx"
40 #include "cppu/EnvDcp.hxx"
41 #include "rtl/logfile.hxx"
42 #include "uno/environment.hxx"
43 #include <com/sun/star/uno/Type.hxx>
49 class LogBridge
: public cppu::Enterable
53 oslThreadIdentifier m_threadId
;
55 virtual ~LogBridge(void);
58 explicit LogBridge(void);
60 virtual void v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
);
61 virtual void v_callOut_v (uno_EnvCallee
* pCallee
, va_list * pParam
);
63 virtual void v_enter(void);
64 virtual void v_leave(void);
66 virtual int v_isValid(rtl::OUString
* pReason
);
69 LogBridge::LogBridge(void)
75 LogBridge::~LogBridge(void)
77 OSL_ASSERT(m_count
>= 0);
80 void LogBridge::v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
87 void LogBridge::v_callOut_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
89 OSL_ASSERT(m_count
> 0);
96 m_threadId
= osl_getThreadIdentifier(NULL
);
99 void LogBridge::v_enter(void)
103 OSL_ASSERT(m_count
>= 0);
106 m_threadId
= osl_getThreadIdentifier(NULL
);
111 void LogBridge::v_leave(void)
113 OSL_ASSERT(m_count
> 0);
123 int LogBridge::v_isValid(rtl::OUString
* pReason
)
127 result
= m_count
> 0;
129 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("not entered"));
133 result
= m_threadId
== osl_getThreadIdentifier(NULL
);
136 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("wrong thread"));
140 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OK"));
145 void traceValue(typelib_TypeDescriptionReference
* _pTypeRef
,void* pArg
)
147 switch(_pTypeRef
->eTypeClass
)
149 case typelib_TypeClass_STRING
:
151 const ::rtl::OString
sValue( ::rtl::OUStringToOString(*static_cast< ::rtl::OUString
*>(pArg
),osl_getThreadTextEncoding()));
152 rtl_logfile_trace( "%s", sValue
.getStr());
155 case typelib_TypeClass_BOOLEAN
:
156 rtl_logfile_trace( "%d", *static_cast<sal_Bool
*>(pArg
));
158 case typelib_TypeClass_BYTE
:
159 rtl_logfile_trace( "%d", *static_cast<sal_Int8
*>(pArg
));
161 case typelib_TypeClass_CHAR
:
162 rtl_logfile_trace( "%c", *static_cast<sal_Char
*>(pArg
));
164 case typelib_TypeClass_SHORT
:
165 case typelib_TypeClass_UNSIGNED_SHORT
:
166 rtl_logfile_trace( "%d", *static_cast<sal_Int16
*>(pArg
));
168 case typelib_TypeClass_LONG
:
169 case typelib_TypeClass_UNSIGNED_LONG
:
170 case typelib_TypeClass_ENUM
:
171 rtl_logfile_trace( "%d", *static_cast<sal_Int32
*>(pArg
));
173 case typelib_TypeClass_HYPER
:
174 case typelib_TypeClass_UNSIGNED_HYPER
:
175 rtl_logfile_trace( "%d", *static_cast<sal_Int64
*>(pArg
));
177 case typelib_TypeClass_FLOAT
:
178 rtl_logfile_trace( "%f", *static_cast<float*>(pArg
));
180 case typelib_TypeClass_DOUBLE
:
181 rtl_logfile_trace( "%f", *static_cast<double*>(pArg
));
183 case typelib_TypeClass_TYPE
:
185 const ::rtl::OString
sValue( ::rtl::OUStringToOString(((com::sun::star::uno::Type
*)pArg
)->getTypeName(),osl_getThreadTextEncoding()));
186 rtl_logfile_trace( "%s", sValue
.getStr());
189 case typelib_TypeClass_ANY
:
190 if ( static_cast<uno_Any
*>(pArg
)->pData
)
191 traceValue(static_cast<uno_Any
*>(pArg
)->pType
,static_cast<uno_Any
*>(pArg
)->pData
);
193 rtl_logfile_trace( "void");
195 case typelib_TypeClass_EXCEPTION
:
196 rtl_logfile_trace( "exception");
198 case typelib_TypeClass_INTERFACE
:
200 const ::rtl::OString
sValue( ::rtl::OUStringToOString(_pTypeRef
->pTypeName
,osl_getThreadTextEncoding()));
201 rtl_logfile_trace( "%s 0x%p", sValue
.getStr(),pArg
);
204 case typelib_TypeClass_VOID
:
205 rtl_logfile_trace( "void");
208 rtl_logfile_trace( "0x%p", pArg
);
210 } // switch(pParams[i].pTypeRef->eTypeClass)
218 typelib_TypeDescriptionReference
* pReturnTypeRef
,
219 typelib_MethodParameter
* pParams
,
221 typelib_TypeDescription
const * pMemberType
,
224 uno_Any
** ppException
)
226 static ::std::auto_ptr
< ::rtl::Logfile
> pLogger
;
227 ::rtl::OString sTemp
;
228 if ( pMemberType
&& pMemberType
->pTypeName
)
229 sTemp
= ::rtl::OUStringToOString(pMemberType
->pTypeName
,RTL_TEXTENCODING_ASCII_US
);
232 rtl_logfile_longTrace( "{ LogBridge () %s", sTemp
.getStr() );
235 rtl_logfile_trace( "\n| : ( LogBridge ");
236 for(sal_Int32 i
= 0;i
< nParams
;++i
)
239 rtl_logfile_trace( ",");
240 traceValue(pParams
[i
].pTypeRef
,pArgs
[i
]);
243 rtl_logfile_trace( ")");
245 rtl_logfile_trace( "\n");
249 rtl_logfile_longTrace( "} LogBridge () %s",sTemp
.getStr());
250 if ( ppException
&& *ppException
)
252 rtl_logfile_trace( " excption occured : ");
253 typelib_TypeDescription
* pElementTypeDescr
= 0;
254 TYPELIB_DANGER_GET( &pElementTypeDescr
, (*ppException
)->pType
);
255 const ::rtl::OString
sValue( ::rtl::OUStringToOString(pElementTypeDescr
->pTypeName
,osl_getThreadTextEncoding()));
256 rtl_logfile_trace( "%s", sValue
.getStr());
257 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
259 else if ( pReturnTypeRef
)
261 rtl_logfile_trace( " return : ");
262 traceValue(pReturnTypeRef
,pReturn
);
263 } // if ( pReturn && pReturnTypeRef )
265 rtl_logfile_trace( "\n");
269 extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL
uno_initEnvironment(uno_Environment
* pEnv
)
272 cppu::helper::purpenv::Environment_initWithEnterable(pEnv
, new LogBridge());
275 extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL
uno_ext_getMapping(uno_Mapping
** ppMapping
,
276 uno_Environment
* pFrom
,
277 uno_Environment
* pTo
)
279 cppu::helper::purpenv::createMapping(ppMapping
, pFrom
, pTo
,LogProbe
);