1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_BRIDGES_CPP_UNO_SHARED_CPPINTERFACEPROXY_HXX
25 #define INCLUDED_BRIDGES_CPP_UNO_SHARED_CPPINTERFACEPROXY_HXX
26 
27 #include "osl/interlck.h"
28 #include "rtl/ustring.hxx"
29 #include "sal/types.h"
30 #include "typelib/typedescription.h"
31 #include "uno/dispatcher.h"
32 #include "uno/environment.h"
33 #include "bridges/cpp_uno/shared/vtablefactory.hxx"
34 
35 namespace com { namespace sun { namespace star { namespace uno {
36     class XInterface;
37 } } } }
38 
39 namespace bridges { namespace cpp_uno { namespace shared {
40 
41 class Bridge;
42 
43 extern "C" typedef void SAL_CALL FreeCppInterfaceProxy(
44     uno_ExtEnvironment * pEnv, void * pInterface);
45 FreeCppInterfaceProxy freeCppInterfaceProxy;
46 
47 /**
48  * A cpp proxy wrapping a uno interface.
49  */
50 class CppInterfaceProxy {
51 public:
52     // Interface for Bridge:
53 
54     static com::sun::star::uno::XInterface * create(
55         Bridge * pBridge, uno_Interface * pUnoI,
56         typelib_InterfaceTypeDescription * pTypeDescr,
57         rtl::OUString const & rOId) SAL_THROW(());
58 
59     // Interface for individual CPP--UNO bridges:
60 
getBridge()61     Bridge * getBridge() { return pBridge; }
getUnoI()62     uno_Interface * getUnoI() { return pUnoI; }
getTypeDescr()63     typelib_InterfaceTypeDescription * getTypeDescr() { return pTypeDescr; }
getOid()64     rtl::OUString getOid() { return oid; }
65 
66     // non virtual methods called on incoming vtable calls #1, #2
67     void acquireProxy() SAL_THROW(());
68     void releaseProxy() SAL_THROW(());
69 
70     static CppInterfaceProxy * castInterfaceToProxy(void * pInterface);
71 
72 private:
73     CppInterfaceProxy(CppInterfaceProxy &); // not implemented
74     void operator =(CppInterfaceProxy); // not implemented
75 
76     CppInterfaceProxy(
77         Bridge * pBridge_, uno_Interface * pUnoI_,
78         typelib_InterfaceTypeDescription * pTypeDescr_,
79         rtl::OUString const & rOId_) SAL_THROW(());
80 
81     ~CppInterfaceProxy();
82 
83     static com::sun::star::uno::XInterface * castProxyToInterface(
84         CppInterfaceProxy * pProxy);
85 
86     oslInterlockedCount nRef;
87     Bridge * pBridge;
88 
89     // mapping information
90     uno_Interface * pUnoI; // wrapped interface
91     typelib_InterfaceTypeDescription * pTypeDescr;
92     rtl::OUString oid;
93 
94     VtableFactory::Slot * vtables[1];
95 
96     friend void SAL_CALL freeCppInterfaceProxy(
97         uno_ExtEnvironment * pEnv, void * pInterface);
98 };
99 
100 } } }
101 
102 #endif
103