fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / cppu / source / helper / purpenv / helper_purpenv_Mapping.cxx
blob250ad9dede94742ee2a2ec3e81b92d9fb66d717d
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 .
21 #include "cppu/helper/purpenv/Mapping.hxx"
23 #include "Proxy.hxx"
25 #include "osl/interlck.h"
26 #include "uno/environment.hxx"
27 #include "uno/dispatcher.h"
28 #include "typelib/typedescription.h"
31 #ifdef debug
32 # define LOG_LIFECYCLE_cppu_helper_purpenv_Mapping
33 #endif
35 #ifdef LOG_LIFECYCLE_cppu_helper_purpenv_Mapping
36 # include <iostream>
37 # define LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(x) x
39 #else
40 # define LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(x)
42 #endif
45 using namespace com::sun::star;
48 class Mapping : public uno_Mapping
50 uno::Environment m_from;
51 uno::Environment m_to;
53 oslInterlockedCount m_nCount;
55 cppu::helper::purpenv::ProbeFun * m_probeFun;
56 void * m_pContext;
58 public:
59 explicit Mapping(uno_Environment * pFrom,
60 uno_Environment * pTo,
61 cppu::helper::purpenv::ProbeFun * probeFun,
62 void * pProbeContext);
63 virtual ~Mapping();
65 void mapInterface(
66 uno_Interface ** ppOut,
67 uno_Interface * pUnoI,
68 typelib_InterfaceTypeDescription * pTypeDescr);
70 void acquire();
71 void release();
74 static void SAL_CALL s_mapInterface(
75 uno_Mapping * puno_Mapping,
76 void ** ppOut,
77 void * pUnoI,
78 typelib_InterfaceTypeDescription * pTypeDescr )
79 SAL_THROW_EXTERN_C()
81 Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
82 pMapping->mapInterface(
83 reinterpret_cast<uno_Interface **>(ppOut),
84 static_cast<uno_Interface *>(pUnoI), pTypeDescr);
87 extern "C" {
88 static void SAL_CALL s_acquire(uno_Mapping * puno_Mapping)
89 SAL_THROW_EXTERN_C()
91 Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
92 pMapping->acquire();
95 static void SAL_CALL s_release(uno_Mapping * puno_Mapping)
96 SAL_THROW_EXTERN_C()
98 Mapping * pMapping = static_cast<Mapping * >(puno_Mapping);
99 pMapping->release();
103 static void s_getIdentifier_v(va_list * pParam)
105 uno_ExtEnvironment * pEnv = va_arg(*pParam, uno_ExtEnvironment *);
106 rtl_uString ** ppOid = va_arg(*pParam, rtl_uString **);
107 uno_Interface * pUnoI = va_arg(*pParam, uno_Interface *);
109 pEnv->getObjectIdentifier(pEnv, ppOid, pUnoI);
112 static void SAL_CALL s_free(uno_Mapping * puno_Mapping)
113 SAL_THROW_EXTERN_C()
115 Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
116 delete pMapping;
120 Mapping::Mapping(uno_Environment * pFrom,
121 uno_Environment * pTo,
122 cppu::helper::purpenv::ProbeFun * probeFun,
123 void * pProbeContext
125 : m_from (pFrom),
126 m_to (pTo),
127 m_nCount (1),
128 m_probeFun(probeFun),
129 m_pContext(pProbeContext)
131 LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(fprintf(stderr, "LIFE: %s -> %p\n", "Mapping::Mapping(uno_Environment * pFrom, uno_Environment * pTo)", this));
133 uno_Mapping::acquire = s_acquire;
134 uno_Mapping::release = s_release;
135 uno_Mapping::mapInterface = (uno_MapInterfaceFunc)s_mapInterface;
138 Mapping::~Mapping()
140 LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(fprintf(stderr, "LIFE: %s -> %p\n", "Mapping::~Mapping()", this));
144 void Mapping::mapInterface(
145 uno_Interface ** ppOut,
146 uno_Interface * pUnoI,
147 typelib_InterfaceTypeDescription * pTypeDescr)
149 OSL_ASSERT(ppOut && pTypeDescr);
150 if (*ppOut)
152 (*ppOut)->release(*ppOut);
153 *ppOut = 0;
156 if (!pUnoI)
157 return;
159 // get object id of uno interface to be wrapped
160 // need to enter environment because of potential "queryInterface" call
161 rtl_uString * pOId = 0;
162 uno_Environment_invoke(m_from.get(), s_getIdentifier_v, m_from.get(), &pOId, pUnoI);
163 OSL_ASSERT(pOId);
165 // try to get any known interface from target environment
166 m_to.get()->pExtEnv->getRegisteredInterface(m_to.get()->pExtEnv, reinterpret_cast<void **>(ppOut), pOId, pTypeDescr);
168 if (!*ppOut) // not yet there, register new proxy interface
170 // try to publish a new proxy (ref count initially 1)
171 uno_Interface * pProxy = new Proxy(this,
172 m_from.get(),
173 m_to.get(),
174 pUnoI,
175 pTypeDescr,
176 pOId,
177 m_probeFun,
178 m_pContext);
180 // proxy may be exchanged during registration
181 m_to.get()->pExtEnv->registerProxyInterface(m_to.get()->pExtEnv,
182 reinterpret_cast<void **>(&pProxy),
183 Proxy_free,
184 pOId,
185 pTypeDescr);
187 *ppOut = pProxy;
190 rtl_uString_release(pOId);
194 void Mapping::acquire()
196 if (osl_atomic_increment(&m_nCount) == 1)
198 uno_Mapping * pMapping = this;
200 ::uno_registerMapping(&pMapping, s_free, m_from.get(), m_to.get(), NULL);
204 void Mapping::release()
206 if (osl_atomic_decrement(&m_nCount) == 0)
207 ::uno_revokeMapping(this);
211 namespace cppu { namespace helper { namespace purpenv {
213 void createMapping(uno_Mapping ** ppMapping,
214 uno_Environment * pFrom,
215 uno_Environment * pTo,
216 ProbeFun * probeFun,
217 void * pContext
220 *ppMapping = new Mapping(pFrom, pTo, probeFun, pContext);
222 ::uno_registerMapping(ppMapping, s_free, pFrom, pTo, NULL);
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */