LibreOffice Module cppu (master) 1
UnsafeBridge.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#include <osl/mutex.hxx>
21#include <osl/thread.h>
22#include <osl/thread.hxx>
23#include <sal/log.hxx>
24
25#include <cppu/Enterable.hxx>
28
29namespace {
30
31class UnsafeBridge : public cppu::Enterable
32{
33 osl::Mutex m_mutex;
34 sal_Int32 m_count;
35 oslThreadIdentifier m_threadId;
36
37 virtual ~UnsafeBridge() override;
38
39public:
40 explicit UnsafeBridge();
41
42 virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam) override;
43 virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam) override;
44
45 virtual void v_enter() override;
46 virtual void v_leave() override;
47
48 virtual bool v_isValid(OUString * pReason) override;
49};
50
51}
52
53UnsafeBridge::UnsafeBridge()
54 : m_count (0),
55 m_threadId(0)
56{
57 SAL_INFO("cppu.unsafebridge", "LIFE: UnsafeBridge::UnsafeBridge(uno_Environment * pEnv) -> " << this);
58}
59
60UnsafeBridge::~UnsafeBridge()
61{
62 SAL_INFO("cppu.unsafebridge", "LIFE: UnsafeBridge::~UnsafeBridge() -> " << this);
63
64 SAL_WARN_IF(m_count < 0, "cppu.unsafebridge", "m_count is less than 0");
65}
66
67void UnsafeBridge::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam)
68{
69 enter();
70 pCallee(pParam);
71 leave();
72}
73
74void UnsafeBridge::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam)
75{
76 SAL_WARN_IF(m_count <= 0, "cppu.unsafebridge", "m_count is less than or equal to 0");
77
78 -- m_count;
79 pCallee(pParam);
80 ++ m_count;
81
82 if (!m_threadId)
83 m_threadId = osl::Thread::getCurrentIdentifier();
84}
85
86void UnsafeBridge::v_enter()
87{
88 m_mutex.acquire();
89
90 SAL_WARN_IF(m_count < 0, "cppu.unsafebridge", "m_count is less than 0");
91
92 if (m_count == 0)
93 m_threadId = osl::Thread::getCurrentIdentifier();
94
95 ++ m_count;
96}
97
98void UnsafeBridge::v_leave()
99{
100 SAL_WARN_IF(m_count <= 0, "cppu.unsafebridge", "m_count is less than or equal to 0");
101
102 -- m_count;
103 if (!m_count)
104 m_threadId = 0;
105
106
107 m_mutex.release();
108}
109
110bool UnsafeBridge::v_isValid(OUString * pReason)
111{
112 bool result = m_count > 0;
113 if (!result)
114 {
115 *pReason = "not entered";
116 }
117 else
118 {
119 result = m_threadId == osl::Thread::getCurrentIdentifier();
120
121 if (!result)
122 *pReason = "wrong thread";
123 }
124
125 if (result)
126 *pReason = "OK";
127
128 return result;
129}
130
131extern "C" void SAL_DLLPUBLIC_EXPORT uno_initEnvironment(uno_Environment * pEnv)
133{
135}
136
137extern "C" void SAL_DLLPUBLIC_EXPORT uno_ext_getMapping(uno_Mapping ** ppMapping,
138 uno_Environment * pFrom,
139 uno_Environment * pTo )
140{
141 cppu::helper::purpenv::createMapping(ppMapping, pFrom, pTo);
142}
143
144/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SAL_DLLPUBLIC_EXPORT uno_ext_getMapping(uno_Mapping **ppMapping, uno_Environment *pFrom, uno_Environment *pTo)
void SAL_DLLPUBLIC_EXPORT uno_initEnvironment(uno_Environment *pEnv) SAL_THROW_EXTERN_C()
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_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
struct _uno_Mapping uno_Mapping
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)
#define SAL_THROW_EXTERN_C()
Any result