LibreOffice Module cppu (master) 1
LogBridge.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
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>
28#include <com/sun/star/uno/Type.hxx>
29#include <sal/log.hxx>
30
31namespace
32{
33class LogBridge : public cppu::Enterable
34{
35 osl::Mutex m_mutex;
36 sal_Int32 m_count;
37 oslThreadIdentifier m_threadId;
38
39 virtual ~LogBridge() override;
40
41public:
42 explicit LogBridge();
43
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;
46
47 virtual void v_enter() override;
48 virtual void v_leave() override;
49
50 virtual bool v_isValid(OUString * pReason) override;
51};
52
53LogBridge::LogBridge()
54 : m_count (0)
55 ,m_threadId(0)
56{
57}
58
59LogBridge::~LogBridge()
60{
61 OSL_ASSERT(m_count >= 0);
62}
63
64void LogBridge::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam)
65{
66 enter();
67 pCallee(pParam);
68 leave();
69}
70
71void LogBridge::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam)
72{
73 OSL_ASSERT(m_count > 0);
74
75 -- m_count;
76 pCallee(pParam);
77 ++ m_count;
78
79 if (!m_threadId)
80 m_threadId = osl::Thread::getCurrentIdentifier();
81}
82
83void LogBridge::v_enter()
84{
85 m_mutex.acquire();
86
87 OSL_ASSERT(m_count >= 0);
88
89 if (m_count == 0)
90 m_threadId = osl::Thread::getCurrentIdentifier();
91
92 ++ m_count;
93}
94
95void LogBridge::v_leave()
96{
97 OSL_ASSERT(m_count > 0);
98
99 -- m_count;
100 if (!m_count)
101 m_threadId = 0;
102
103
104 m_mutex.release();
105}
106
107bool LogBridge::v_isValid(OUString * pReason)
108{
109 bool result = m_count > 0;
110 if (!result)
111 {
112 *pReason = "not entered";
113 }
114 else
115 {
116 result = m_threadId == osl::Thread::getCurrentIdentifier();
117
118 if (!result)
119 *pReason = "wrong thread";
120 }
121
122 if (result)
123 *pReason = "OK";
124
125 return result;
126}
127
128 void traceValue(typelib_TypeDescriptionReference* _pTypeRef,void* pArg)
129 {
130 switch(_pTypeRef->eTypeClass)
131 {
132 case typelib_TypeClass_STRING:
133 SAL_INFO("cppu.log", "" << *static_cast< OUString*>(pArg));
134 break;
135 case typelib_TypeClass_BOOLEAN:
136 SAL_INFO("cppu.log", "" << *static_cast<sal_Bool*>(pArg));
137 break;
138 case typelib_TypeClass_BYTE:
139 SAL_INFO("cppu.log", "" << *static_cast<sal_Int8*>(pArg));
140 break;
141 case typelib_TypeClass_CHAR:
142 SAL_INFO("cppu.log", "" << *static_cast<char*>(pArg));
143 break;
144 case typelib_TypeClass_SHORT:
145 case typelib_TypeClass_UNSIGNED_SHORT:
146 SAL_INFO("cppu.log", "" << *static_cast<sal_Int16*>(pArg));
147 break;
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));
152 break;
153 case typelib_TypeClass_HYPER:
154 case typelib_TypeClass_UNSIGNED_HYPER:
155 SAL_INFO("cppu.log", "" << *static_cast<sal_Int64*>(pArg));
156 break;
157 case typelib_TypeClass_FLOAT:
158 SAL_INFO("cppu.log", "" << *static_cast<float*>(pArg));
159 break;
160 case typelib_TypeClass_DOUBLE:
161 SAL_INFO("cppu.log", "" << *static_cast<double*>(pArg));
162 break;
163 case typelib_TypeClass_TYPE:
164 SAL_INFO("cppu.log", "" << static_cast<css::uno::Type*>(pArg)->getTypeName());
165 break;
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);
169 else
170 SAL_INFO("cppu.log", "void");
171 break;
172 case typelib_TypeClass_EXCEPTION:
173 SAL_INFO("cppu.log", "exception");
174 break;
175 case typelib_TypeClass_INTERFACE:
176 SAL_INFO("cppu.log", "" << _pTypeRef->pTypeName << "0x" << std::hex << pArg);
177 break;
178 case typelib_TypeClass_VOID:
179 SAL_INFO("cppu.log", "void");
180 break;
181 default:
182 SAL_INFO("cppu.log", "0x" << std::hex << pArg);
183 break;
184 } // switch(pParams[i].pTypeRef->eTypeClass)
185 }
186}
187
188static void LogProbe(
189 bool pre,
190 SAL_UNUSED_PARAMETER void * /*pThis*/,
191 SAL_UNUSED_PARAMETER void * /*pContext*/,
192 typelib_TypeDescriptionReference * pReturnTypeRef,
193 typelib_MethodParameter * pParams,
194 sal_Int32 nParams,
195 typelib_TypeDescription const * pMemberType,
196 void * pReturn,
197 void * pArgs[],
198 uno_Any ** ppException )
199{
200 OString sTemp;
201 if ( pMemberType && pMemberType->pTypeName )
202 sTemp = OUStringToOString(
203 OUString::unacquired(&pMemberType->pTypeName),RTL_TEXTENCODING_ASCII_US);
204 if ( pre )
205 {
206 SAL_INFO("cppu.log", "{ LogBridge () " << sTemp );
207 if ( nParams )
208 {
209 SAL_INFO("cppu.log", "\n| : ( LogBridge ");
210 for(sal_Int32 i = 0;i < nParams;++i)
211 {
212 if ( i > 0 )
213 SAL_INFO("cppu.log", ",");
214 traceValue(pParams[i].pTypeRef,pArgs[i]);
215
216 }
217 SAL_INFO("cppu.log", ")");
218 } // if ( nParams )
219 SAL_INFO("cppu.log", "\n");
220 }
221 else if ( !pre )
222 {
223 SAL_INFO("cppu.log", "} LogBridge () " << sTemp);
224 if ( ppException && *ppException )
225 {
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 );
231 }
232 else if ( pReturnTypeRef )
233 {
234 SAL_INFO("cppu.log", " return : ");
235 traceValue(pReturnTypeRef,pReturn);
236 } // if ( pReturn && pReturnTypeRef )
237
238 SAL_INFO("cppu.log", "\n");
239 }
240}
241
242#ifdef DISABLE_DYNLOADING
243
244#define uno_initEnvironment log_uno_uno_initEnvironment
245#define uno_ext_getMapping log_uno_uno_ext_getMapping
246
247#endif
248
249extern "C" void SAL_DLLPUBLIC_EXPORT uno_initEnvironment(uno_Environment * pEnv)
251{
253}
254
255extern "C" void SAL_DLLPUBLIC_EXPORT uno_ext_getMapping(uno_Mapping ** ppMapping,
256 uno_Environment * pFrom,
257 uno_Environment * pTo )
258{
259 cppu::helper::purpenv::createMapping(ppMapping, pFrom, pTo,LogProbe);
260}
261
262/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void LogProbe(bool pre, SAL_UNUSED_PARAMETER void *, SAL_UNUSED_PARAMETER void *, typelib_TypeDescriptionReference *pReturnTypeRef, typelib_MethodParameter *pParams, sal_Int32 nParams, typelib_TypeDescription const *pMemberType, void *pReturn, void *pArgs[], uno_Any **ppException)
Definition: LogBridge.cxx:188
void SAL_DLLPUBLIC_EXPORT uno_ext_getMapping(uno_Mapping **ppMapping, uno_Environment *pFrom, uno_Environment *pTo)
Definition: LogBridge.cxx:255
void SAL_DLLPUBLIC_EXPORT uno_initEnvironment(uno_Environment *pEnv) SAL_THROW_EXTERN_C()
Definition: LogBridge.cxx:249
C++ wrapper for binary C Enterable (http://wiki.openoffice.org/wiki/Uno/Cpp/Spec/Environment_Stack)
Definition: Enterable.hxx:39
virtual void v_enter()=0
virtual bool v_isValid(rtl::OUString *pReason)=0
virtual void v_callOut_v(uno_EnvCallee *pCallee, va_list *pParam)=0
virtual void v_leave()=0
virtual void v_callInto_v(uno_EnvCallee *pCallee, va_list *pParam)=0
sal_uInt32 m_count
struct _uno_Environment uno_Environment
Mutex m_mutex
#define SAL_INFO(area, stream)
struct _uno_Mapping uno_Mapping
struct _typelib_TypeDescription typelib_TypeDescription
struct _uno_Any uno_Any
rtl::OUString getTypeName(rtl::OUString const &rEnvDcp)
Get the OBI type part of an environment descriptor.
Definition: EnvDcp.hxx:41
void Environment_initWithEnterable(uno_Environment *pEnvironment, cppu::Enterable *pEnterable)
C++ helper for implementing Purpose Environments.
void createMapping(uno_Mapping **ppMapping, uno_Environment *pFrom, uno_Environment *pTo, ProbeFun *probeFun, void *pContext)
int i
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
unsigned char sal_Bool
#define SAL_THROW_EXTERN_C()
signed char sal_Int8
Any result