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"
24 #include "cppu/helper/purpenv/Environment.hxx"
25 #include "cppu/helper/purpenv/Mapping.hxx"
29 # define LOG_LIFECYCLE_UnsafeBridge
32 #ifdef LOG_LIFECYCLE_UnsafeBridge
34 # define LOG_LIFECYCLE_UnsafeBridge_emit(x) x
37 # define LOG_LIFECYCLE_UnsafeBridge_emit(x)
42 class SAL_DLLPRIVATE UnsafeBridge
: public cppu::Enterable
46 oslThreadIdentifier m_threadId
;
48 virtual ~UnsafeBridge(void);
51 explicit UnsafeBridge(void);
53 virtual void v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
);
54 virtual void v_callOut_v (uno_EnvCallee
* pCallee
, va_list * pParam
);
56 virtual void v_enter(void);
57 virtual void v_leave(void);
59 virtual int v_isValid(rtl::OUString
* pReason
);
62 UnsafeBridge::UnsafeBridge(void)
66 LOG_LIFECYCLE_UnsafeBridge_emit(fprintf(stderr
, "LIFE: %s -> %p\n", "UnsafeBridge::UnsafeBridge(uno_Environment * pEnv)", this));
69 UnsafeBridge::~UnsafeBridge(void)
71 LOG_LIFECYCLE_UnsafeBridge_emit(fprintf(stderr
, "LIFE: %s -> %p\n", "UnsafeBridge::~UnsafeBridge(void)", this));
73 OSL_ASSERT(m_count
>= 0);
76 void UnsafeBridge::v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
83 void UnsafeBridge::v_callOut_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
85 OSL_ASSERT(m_count
> 0);
92 m_threadId
= osl_getThreadIdentifier(NULL
);
95 void UnsafeBridge::v_enter(void)
99 OSL_ASSERT(m_count
>= 0);
102 m_threadId
= osl_getThreadIdentifier(NULL
);
107 void UnsafeBridge::v_leave(void)
109 OSL_ASSERT(m_count
> 0);
119 int UnsafeBridge::v_isValid(rtl::OUString
* pReason
)
123 result
= m_count
> 0;
125 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("not entered"));
129 result
= m_threadId
== osl_getThreadIdentifier(NULL
);
132 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("wrong thread"));
136 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OK"));
141 extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL
uno_initEnvironment(uno_Environment
* pEnv
)
144 cppu::helper::purpenv::Environment_initWithEnterable(pEnv
, new UnsafeBridge());
147 extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL
uno_ext_getMapping(uno_Mapping
** ppMapping
,
148 uno_Environment
* pFrom
,
149 uno_Environment
* pTo
)
151 cppu::helper::purpenv::createMapping(ppMapping
, pFrom
, pTo
);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */