1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_BRIDGES_CPP_UNO_SHARED_BRIDGE_HXX
29 #define INCLUDED_BRIDGES_CPP_UNO_SHARED_BRIDGE_HXX
30 
31 #include "osl/interlck.h"
32 #include "sal/types.h"
33 #include "typelib/typedescription.h"
34 #include "uno/environment.h"
35 #include "uno/mapping.h"
36 
37 namespace bridges { namespace cpp_uno { namespace shared {
38 
39 // private:
40 extern "C" typedef void SAL_CALL FreeMapping(uno_Mapping *);
41 FreeMapping freeMapping;
42 
43 // private:
44 extern "C"
45 typedef void SAL_CALL AcquireMapping(uno_Mapping *);
46 AcquireMapping acquireMapping;
47 
48 // private:
49 extern "C"
50 typedef void SAL_CALL ReleaseMapping(uno_Mapping *);
51 ReleaseMapping releaseMapping;
52 
53 // private:
54 extern "C" typedef void SAL_CALL Cpp2unoMapping(
55     uno_Mapping *, void **, void *, typelib_InterfaceTypeDescription *);
56 Cpp2unoMapping cpp2unoMapping;
57 
58 // private:
59 extern "C" typedef void SAL_CALL Uno2cppMapping(
60     uno_Mapping *, void **, void *, typelib_InterfaceTypeDescription *);
61 Uno2cppMapping uno2cppMapping;
62 
63 /**
64  * Holding environments and mappings.
65  */
66 class Bridge {
67 public:
68     // Interface for generic/component.cxx:
69 
70     static uno_Mapping * createMapping(
71         uno_ExtEnvironment * pCppEnv, uno_ExtEnvironment * pUnoEnv,
72         bool bExportCpp2Uno) SAL_THROW(());
73 
74     // Interface for Cpp/UnoInterfaceProxy:
75 
76     void acquire() SAL_THROW(());
77     void release() SAL_THROW(());
78 
79     // Interface for individual CPP--UNO bridges:
80 
81     uno_ExtEnvironment * getCppEnv() { return pCppEnv; }
82     uno_ExtEnvironment * getUnoEnv() { return pUnoEnv; }
83 
84     uno_Mapping * getCpp2Uno() { return &aCpp2Uno; }
85     uno_Mapping * getUno2Cpp() { return &aUno2Cpp; }
86 
87 private:
88     Bridge(Bridge &); // not implemented
89     void operator =(Bridge); // not implemented
90 
91     Bridge(
92         uno_ExtEnvironment * pCppEnv_, uno_ExtEnvironment * pUnoEnv_,
93         bool bExportCpp2Uno_) SAL_THROW(());
94 
95     ~Bridge() SAL_THROW(());
96 
97     struct Mapping: public uno_Mapping {
98         Bridge * pBridge;
99     };
100 
101     oslInterlockedCount nRef;
102 
103     uno_ExtEnvironment * pCppEnv;
104     uno_ExtEnvironment * pUnoEnv;
105 
106     Mapping aCpp2Uno;
107     Mapping aUno2Cpp;
108 
109     bool bExportCpp2Uno;
110 
111     friend void SAL_CALL freeMapping(uno_Mapping * pMapping);
112 
113     friend void SAL_CALL acquireMapping(uno_Mapping * pMapping);
114 
115     friend void SAL_CALL releaseMapping(uno_Mapping * pMapping);
116 
117     friend void SAL_CALL cpp2unoMapping(
118         uno_Mapping * pMapping, void ** ppUnoI, void * pCppI,
119         typelib_InterfaceTypeDescription * pTypeDescr);
120 
121     friend void SAL_CALL uno2cppMapping(
122         uno_Mapping * pMapping, void ** ppCppI, void * pUnoI,
123         typelib_InterfaceTypeDescription * pTypeDescr);
124 };
125 
126 } } }
127 
128 #endif
129