tsan: make oslPipe thread-safe
[LibreOffice.git] / bridges / inc / bridge.hxx
blob0a6da78859cac8737642148c68f671e8b5f64eb4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <atomic>
25 #include <cstddef>
27 #include <sal/types.h>
28 #include <typelib/typedescription.h>
29 #include <uno/environment.h>
30 #include <uno/mapping.h>
32 namespace bridges::cpp_uno::shared {
34 // private:
35 extern "C" void freeMapping(uno_Mapping *);
37 // private:
38 extern "C" void acquireMapping(uno_Mapping *);
40 // private:
41 extern "C" void releaseMapping(uno_Mapping *);
43 // private:
44 extern "C" void cpp2unoMapping(
45 uno_Mapping *, void **, void *, typelib_InterfaceTypeDescription *);
47 // private:
48 extern "C" void uno2cppMapping(
49 uno_Mapping *, void **, void *, typelib_InterfaceTypeDescription *);
51 /**
52 * Holding environments and mappings.
54 class Bridge {
55 public:
56 // Interface for generic/component.cxx:
58 static uno_Mapping * createMapping(
59 uno_ExtEnvironment * pCppEnv, uno_ExtEnvironment * pUnoEnv,
60 bool bExportCpp2Uno);
62 // Interface for Cpp/UnoInterfaceProxy:
64 void acquire();
65 void release();
67 // Interface for individual CPP--UNO bridges:
69 uno_ExtEnvironment * getCppEnv() { return pCppEnv; }
70 uno_ExtEnvironment * getUnoEnv() { return pUnoEnv; }
72 uno_Mapping * getCpp2Uno() { return &aCpp2Uno; }
73 uno_Mapping * getUno2Cpp() { return &aUno2Cpp; }
75 private:
76 Bridge(Bridge const &) = delete;
77 Bridge& operator =(const Bridge&) = delete;
79 Bridge(
80 uno_ExtEnvironment * pCppEnv_, uno_ExtEnvironment * pUnoEnv_,
81 bool bExportCpp2Uno_);
83 ~Bridge();
85 struct Mapping: public uno_Mapping {
86 Bridge * pBridge;
89 std::atomic<std::size_t> nRef;
91 uno_ExtEnvironment * pCppEnv;
92 uno_ExtEnvironment * pUnoEnv;
94 Mapping aCpp2Uno;
95 Mapping aUno2Cpp;
97 bool bExportCpp2Uno;
99 friend void freeMapping(uno_Mapping * pMapping);
101 friend void acquireMapping(uno_Mapping * pMapping);
103 friend void releaseMapping(uno_Mapping * pMapping);
105 friend void cpp2unoMapping(
106 uno_Mapping * pMapping, void ** ppUnoI, void * pCppI,
107 typelib_InterfaceTypeDescription * pTypeDescr);
109 friend void uno2cppMapping(
110 uno_Mapping * pMapping, void ** ppCppI, void * pUnoI,
111 typelib_InterfaceTypeDescription * pTypeDescr);
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */