1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "osl/mutex.hxx"
22 #include "osl/thread.h"
23 #include "uno/dispatcher.h"
24 #include "typelib/typedescription.hxx"
25 #include "cppu/helper/purpenv/Environment.hxx"
26 #include "cppu/helper/purpenv/Mapping.hxx"
27 #include "cppu/EnvDcp.hxx"
28 #include "rtl/logfile.hxx"
29 #include "uno/environment.hxx"
30 #include <com/sun/star/uno/Type.hxx>
31 #include <boost/unordered_map.hpp>
36 class LogBridge
: public cppu::Enterable
40 oslThreadIdentifier m_threadId
;
42 virtual ~LogBridge(void);
45 explicit LogBridge(void);
47 virtual void v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
);
48 virtual void v_callOut_v (uno_EnvCallee
* pCallee
, va_list * pParam
);
50 virtual void v_enter(void);
51 virtual void v_leave(void);
53 virtual int v_isValid(rtl::OUString
* pReason
);
56 LogBridge::LogBridge(void)
62 LogBridge::~LogBridge(void)
64 OSL_ASSERT(m_count
>= 0);
67 void LogBridge::v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
74 void LogBridge::v_callOut_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
76 OSL_ASSERT(m_count
> 0);
83 m_threadId
= osl_getThreadIdentifier(NULL
);
86 void LogBridge::v_enter(void)
90 OSL_ASSERT(m_count
>= 0);
93 m_threadId
= osl_getThreadIdentifier(NULL
);
98 void LogBridge::v_leave(void)
100 OSL_ASSERT(m_count
> 0);
110 int LogBridge::v_isValid(rtl::OUString
* pReason
)
114 result
= m_count
> 0;
116 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("not entered"));
120 result
= m_threadId
== osl_getThreadIdentifier(NULL
);
123 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("wrong thread"));
127 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OK"));
132 void traceValue(typelib_TypeDescriptionReference
* _pTypeRef
,void* pArg
)
134 switch(_pTypeRef
->eTypeClass
)
136 case typelib_TypeClass_STRING
:
138 const ::rtl::OString
sValue( ::rtl::OUStringToOString(*static_cast< ::rtl::OUString
*>(pArg
),osl_getThreadTextEncoding()));
139 rtl_logfile_trace( "%s", sValue
.getStr());
142 case typelib_TypeClass_BOOLEAN
:
143 rtl_logfile_trace( "%d", *static_cast<sal_Bool
*>(pArg
));
145 case typelib_TypeClass_BYTE
:
146 rtl_logfile_trace( "%d", *static_cast<sal_Int8
*>(pArg
));
148 case typelib_TypeClass_CHAR
:
149 rtl_logfile_trace( "%c", *static_cast<sal_Char
*>(pArg
));
151 case typelib_TypeClass_SHORT
:
152 case typelib_TypeClass_UNSIGNED_SHORT
:
153 rtl_logfile_trace( "%d", *static_cast<sal_Int16
*>(pArg
));
155 case typelib_TypeClass_LONG
:
156 case typelib_TypeClass_UNSIGNED_LONG
:
157 case typelib_TypeClass_ENUM
:
158 rtl_logfile_trace( "%d", *static_cast<sal_Int32
*>(pArg
));
160 case typelib_TypeClass_HYPER
:
161 case typelib_TypeClass_UNSIGNED_HYPER
:
162 rtl_logfile_trace( "%d", *static_cast<sal_Int64
*>(pArg
));
164 case typelib_TypeClass_FLOAT
:
165 rtl_logfile_trace( "%f", *static_cast<float*>(pArg
));
167 case typelib_TypeClass_DOUBLE
:
168 rtl_logfile_trace( "%f", *static_cast<double*>(pArg
));
170 case typelib_TypeClass_TYPE
:
172 const ::rtl::OString
sValue( ::rtl::OUStringToOString(((com::sun::star::uno::Type
*)pArg
)->getTypeName(),osl_getThreadTextEncoding()));
173 rtl_logfile_trace( "%s", sValue
.getStr());
176 case typelib_TypeClass_ANY
:
177 if ( static_cast<uno_Any
*>(pArg
)->pData
)
178 traceValue(static_cast<uno_Any
*>(pArg
)->pType
,static_cast<uno_Any
*>(pArg
)->pData
);
180 rtl_logfile_trace( "void");
182 case typelib_TypeClass_EXCEPTION
:
183 rtl_logfile_trace( "exception");
185 case typelib_TypeClass_INTERFACE
:
187 const ::rtl::OString
sValue( ::rtl::OUStringToOString(_pTypeRef
->pTypeName
,osl_getThreadTextEncoding()));
188 rtl_logfile_trace( "%s 0x%p", sValue
.getStr(),pArg
);
191 case typelib_TypeClass_VOID
:
192 rtl_logfile_trace( "void");
195 rtl_logfile_trace( "0x%p", pArg
);
197 } // switch(pParams[i].pTypeRef->eTypeClass)
203 SAL_UNUSED_PARAMETER
void * /*pThis*/,
204 SAL_UNUSED_PARAMETER
void * /*pContext*/,
205 typelib_TypeDescriptionReference
* pReturnTypeRef
,
206 typelib_MethodParameter
* pParams
,
208 typelib_TypeDescription
const * pMemberType
,
211 uno_Any
** ppException
)
213 static ::std::auto_ptr
< ::rtl::Logfile
> pLogger
;
214 ::rtl::OString sTemp
;
215 if ( pMemberType
&& pMemberType
->pTypeName
)
216 sTemp
= ::rtl::OUStringToOString(pMemberType
->pTypeName
,RTL_TEXTENCODING_ASCII_US
);
219 rtl_logfile_longTrace( "{ LogBridge () %s", sTemp
.getStr() );
222 rtl_logfile_trace( "\n| : ( LogBridge ");
223 for(sal_Int32 i
= 0;i
< nParams
;++i
)
226 rtl_logfile_trace( ",");
227 traceValue(pParams
[i
].pTypeRef
,pArgs
[i
]);
230 rtl_logfile_trace( ")");
232 rtl_logfile_trace( "\n");
236 rtl_logfile_longTrace( "} LogBridge () %s",sTemp
.getStr());
237 if ( ppException
&& *ppException
)
239 rtl_logfile_trace( " excption occurred : ");
240 typelib_TypeDescription
* pElementTypeDescr
= 0;
241 TYPELIB_DANGER_GET( &pElementTypeDescr
, (*ppException
)->pType
);
242 const ::rtl::OString
sValue( ::rtl::OUStringToOString(pElementTypeDescr
->pTypeName
,osl_getThreadTextEncoding()));
243 rtl_logfile_trace( "%s", sValue
.getStr());
244 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
246 else if ( pReturnTypeRef
)
248 rtl_logfile_trace( " return : ");
249 traceValue(pReturnTypeRef
,pReturn
);
250 } // if ( pReturn && pReturnTypeRef )
252 rtl_logfile_trace( "\n");
256 #ifdef DISABLE_DYNLOADING
258 #define uno_initEnvironment log_uno_uno_initEnvironment
259 #define uno_ext_getMapping log_uno_uno_ext_getMapping
263 extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL
uno_initEnvironment(uno_Environment
* pEnv
)
266 cppu::helper::purpenv::Environment_initWithEnterable(pEnv
, new LogBridge());
269 extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL
uno_ext_getMapping(uno_Mapping
** ppMapping
,
270 uno_Environment
* pFrom
,
271 uno_Environment
* pTo
)
273 cppu::helper::purpenv::createMapping(ppMapping
, pFrom
, pTo
,LogProbe
);
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */