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 <osl/thread.hxx>
24 #include <osl/diagnose.h>
25 #include <cppu/Enterable.hxx>
26 #include <cppu/helper/purpenv/Environment.hxx>
27 #include <cppu/helper/purpenv/Mapping.hxx>
28 #include <com/sun/star/uno/Type.hxx>
29 #include <sal/log.hxx>
33 class LogBridge
: public cppu::Enterable
37 oslThreadIdentifier m_threadId
;
39 virtual ~LogBridge() override
;
44 virtual void v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
) override
;
45 virtual void v_callOut_v (uno_EnvCallee
* pCallee
, va_list * pParam
) override
;
47 virtual void v_enter() override
;
48 virtual void v_leave() override
;
50 virtual bool v_isValid(OUString
* pReason
) override
;
53 LogBridge::LogBridge()
59 LogBridge::~LogBridge()
61 OSL_ASSERT(m_count
>= 0);
64 void LogBridge::v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
71 void LogBridge::v_callOut_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
73 OSL_ASSERT(m_count
> 0);
80 m_threadId
= osl::Thread::getCurrentIdentifier();
83 void LogBridge::v_enter()
87 OSL_ASSERT(m_count
>= 0);
90 m_threadId
= osl::Thread::getCurrentIdentifier();
95 void LogBridge::v_leave()
97 OSL_ASSERT(m_count
> 0);
107 bool LogBridge::v_isValid(OUString
* pReason
)
109 bool result
= m_count
> 0;
112 *pReason
= "not entered";
116 result
= m_threadId
== osl::Thread::getCurrentIdentifier();
119 *pReason
= "wrong thread";
128 void traceValue(typelib_TypeDescriptionReference
* _pTypeRef
,void* pArg
)
130 switch(_pTypeRef
->eTypeClass
)
132 case typelib_TypeClass_STRING
:
133 SAL_INFO("cppu.log", "" << *static_cast< OUString
*>(pArg
));
135 case typelib_TypeClass_BOOLEAN
:
136 SAL_INFO("cppu.log", "" << *static_cast<sal_Bool
*>(pArg
));
138 case typelib_TypeClass_BYTE
:
139 SAL_INFO("cppu.log", "" << *static_cast<sal_Int8
*>(pArg
));
141 case typelib_TypeClass_CHAR
:
142 SAL_INFO("cppu.log", "" << *static_cast<char*>(pArg
));
144 case typelib_TypeClass_SHORT
:
145 case typelib_TypeClass_UNSIGNED_SHORT
:
146 SAL_INFO("cppu.log", "" << *static_cast<sal_Int16
*>(pArg
));
148 case typelib_TypeClass_LONG
:
149 case typelib_TypeClass_UNSIGNED_LONG
:
150 case typelib_TypeClass_ENUM
:
151 SAL_INFO("cppu.log", "" << *static_cast<sal_Int32
*>(pArg
));
153 case typelib_TypeClass_HYPER
:
154 case typelib_TypeClass_UNSIGNED_HYPER
:
155 SAL_INFO("cppu.log", "" << *static_cast<sal_Int64
*>(pArg
));
157 case typelib_TypeClass_FLOAT
:
158 SAL_INFO("cppu.log", "" << *static_cast<float*>(pArg
));
160 case typelib_TypeClass_DOUBLE
:
161 SAL_INFO("cppu.log", "" << *static_cast<double*>(pArg
));
163 case typelib_TypeClass_TYPE
:
164 SAL_INFO("cppu.log", "" << static_cast<css::uno::Type
*>(pArg
)->getTypeName());
166 case typelib_TypeClass_ANY
:
167 if ( static_cast<uno_Any
*>(pArg
)->pData
)
168 traceValue(static_cast<uno_Any
*>(pArg
)->pType
,static_cast<uno_Any
*>(pArg
)->pData
);
170 SAL_INFO("cppu.log", "void");
172 case typelib_TypeClass_EXCEPTION
:
173 SAL_INFO("cppu.log", "exception");
175 case typelib_TypeClass_INTERFACE
:
176 SAL_INFO("cppu.log", "" << _pTypeRef
->pTypeName
<< "0x" << std::hex
<< pArg
);
178 case typelib_TypeClass_VOID
:
179 SAL_INFO("cppu.log", "void");
182 SAL_INFO("cppu.log", "0x" << std::hex
<< pArg
);
184 } // switch(pParams[i].pTypeRef->eTypeClass)
188 static void LogProbe(
190 SAL_UNUSED_PARAMETER
void * /*pThis*/,
191 SAL_UNUSED_PARAMETER
void * /*pContext*/,
192 typelib_TypeDescriptionReference
* pReturnTypeRef
,
193 typelib_MethodParameter
* pParams
,
195 typelib_TypeDescription
const * pMemberType
,
198 uno_Any
** ppException
)
201 if ( pMemberType
&& pMemberType
->pTypeName
)
202 sTemp
= OUStringToOString(
203 OUString::unacquired(&pMemberType
->pTypeName
),RTL_TEXTENCODING_ASCII_US
);
206 SAL_INFO("cppu.log", "{ LogBridge () " << sTemp
);
209 SAL_INFO("cppu.log", "\n| : ( LogBridge ");
210 for(sal_Int32 i
= 0;i
< nParams
;++i
)
213 SAL_INFO("cppu.log", ",");
214 traceValue(pParams
[i
].pTypeRef
,pArgs
[i
]);
217 SAL_INFO("cppu.log", ")");
219 SAL_INFO("cppu.log", "\n");
223 SAL_INFO("cppu.log", "} LogBridge () " << sTemp
);
224 if ( ppException
&& *ppException
)
226 SAL_INFO("cppu.log", " exception occurred : ");
227 typelib_TypeDescription
* pElementTypeDescr
= nullptr;
228 TYPELIB_DANGER_GET( &pElementTypeDescr
, (*ppException
)->pType
);
229 SAL_INFO("cppu.log", "" << pElementTypeDescr
->pTypeName
);
230 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
232 else if ( pReturnTypeRef
)
234 SAL_INFO("cppu.log", " return : ");
235 traceValue(pReturnTypeRef
,pReturn
);
236 } // if ( pReturn && pReturnTypeRef )
238 SAL_INFO("cppu.log", "\n");
242 #ifdef DISABLE_DYNLOADING
244 #define uno_initEnvironment log_uno_uno_initEnvironment
245 #define uno_ext_getMapping log_uno_uno_ext_getMapping
249 extern "C" void SAL_DLLPUBLIC_EXPORT
uno_initEnvironment(uno_Environment
* pEnv
) noexcept
251 cppu::helper::purpenv::Environment_initWithEnterable(pEnv
, new LogBridge());
254 extern "C" void SAL_DLLPUBLIC_EXPORT
uno_ext_getMapping(uno_Mapping
** ppMapping
,
255 uno_Environment
* pFrom
,
256 uno_Environment
* pTo
)
258 cppu::helper::purpenv::createMapping(ppMapping
, pFrom
, pTo
,LogProbe
);
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */