Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef _UNO_ENVIRONMENT_HXX_
20 : #define _UNO_ENVIRONMENT_HXX_
21 :
22 : #include <rtl/alloc.h>
23 : #include <rtl/ustring.hxx>
24 : #include <uno/environment.h>
25 :
26 : #include "uno/lbnames.h"
27 :
28 : /** */ //for docpp
29 : namespace com
30 : {
31 : /** */ //for docpp
32 : namespace sun
33 : {
34 : /** */ //for docpp
35 : namespace star
36 : {
37 : /** */ //for docpp
38 : namespace uno
39 : {
40 :
41 : /** C++ wrapper for binary C uno_Environment.
42 :
43 : @see uno_Environment
44 : */
45 : class Environment
46 : {
47 : /** binary C uno_Environment
48 : */
49 : uno_Environment * _pEnv;
50 :
51 : public:
52 : /** Returns the current Environment.
53 :
54 : @param typeName the optional type of the Environment, falls back to "uno" in case being empty,
55 : respectively to current C++ Environment.
56 : @since UDK 3.2.7
57 : */
58 : inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV)))) SAL_THROW(());
59 :
60 : /// @cond INTERNAL
61 : // these are here to force memory de/allocation to sal lib.
62 : inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
63 : { return ::rtl_allocateMemory( nSize ); }
64 : inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
65 : { ::rtl_freeMemory( pMem ); }
66 : inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
67 : { return pMem; }
68 : inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
69 : {}
70 : /// @endcond
71 :
72 : /** Constructor: acquires given environment
73 :
74 : @param pEnv environment
75 : */
76 : inline Environment( uno_Environment * pEnv = 0 ) SAL_THROW(());
77 :
78 : /** Gets a specific environment. If the specified environment does not exist, then a default one
79 : is created and registered.
80 :
81 : @param envDcp descriptor of the environment
82 : @param pContext context pointer
83 : */
84 : inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL ) SAL_THROW(());
85 :
86 :
87 : /** Copy constructor: acquires given environment
88 :
89 : @param rEnv another environment
90 : */
91 : inline Environment( const Environment & rEnv ) SAL_THROW(());
92 :
93 : /** Destructor: releases a set environment.
94 : */
95 : inline ~Environment() SAL_THROW(());
96 :
97 : /** Sets a given environment, i.e. acquires given one and releases a set one.
98 :
99 : @param pEnv another environment
100 : @return this environment
101 : */
102 : inline Environment & SAL_CALL operator = ( uno_Environment * pEnv ) SAL_THROW(());
103 : /** Sets a given environment, i.e. acquires given one and releases a set one.
104 :
105 : @param rEnv another environment
106 : @return this environment
107 : */
108 4707 : inline Environment & SAL_CALL operator = ( const Environment & rEnv ) SAL_THROW(())
109 4707 : { return operator = ( rEnv._pEnv ); }
110 :
111 : /** Provides UNacquired pointer to the set C environment.
112 :
113 : @return UNacquired pointer to the C environment struct
114 : */
115 117590 : inline uno_Environment * SAL_CALL get() const SAL_THROW(())
116 117590 : { return _pEnv; }
117 :
118 : /** Gets type name of set environment.
119 :
120 : @return type name of set environment
121 : */
122 44728 : inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW(())
123 44728 : { return _pEnv->pTypeName; }
124 :
125 : /** Gets free context pointer of set environment.
126 :
127 : @return free context pointer of set environment
128 : */
129 : inline void * SAL_CALL getContext() const SAL_THROW(())
130 : { return _pEnv->pContext; }
131 :
132 : /** Tests if a environment is set.
133 :
134 : @return true, if a environment is set, false otherwise
135 : */
136 22496 : inline sal_Bool SAL_CALL is() const SAL_THROW(())
137 22496 : { return (_pEnv != 0); }
138 :
139 : /** Releases a set environment.
140 : */
141 : inline void SAL_CALL clear() SAL_THROW(());
142 :
143 : /** Invoke the passed function in this environment.
144 :
145 : @param pCallee the function to call
146 : @param pParam the parameter pointer to be passed to the function
147 : @since UDK 3.2.7
148 : */
149 : inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(());
150 :
151 : /** Invoke the passed function in this environment.
152 :
153 : @param pCallee the function to call
154 : @param ... the parameters to be passed to the function
155 : @since UDK 3.2.7
156 : */
157 : inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(());
158 :
159 : /** Enter this environment explicitly.
160 :
161 : @since UDK 3.2.7
162 : */
163 : inline void SAL_CALL enter() const SAL_THROW(());
164 :
165 : /** Checks, if it is valid to currently call objects
166 : belonging to this environment.
167 :
168 : @since UDK 3.2.7
169 : */
170 : inline int SAL_CALL isValid(rtl::OUString * pReason) const SAL_THROW(());
171 : };
172 : //__________________________________________________________________________________________________
173 56747 : inline Environment::Environment( uno_Environment * pEnv ) SAL_THROW(())
174 56747 : : _pEnv( pEnv )
175 : {
176 56747 : if (_pEnv)
177 44697 : (*_pEnv->acquire)( _pEnv );
178 56747 : }
179 : //__________________________________________________________________________________________________
180 7299 : inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext ) SAL_THROW(())
181 7299 : : _pEnv(NULL)
182 : {
183 7299 : uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
184 7299 : }
185 : //__________________________________________________________________________________________________
186 5483 : inline Environment::Environment( const Environment & rEnv ) SAL_THROW(())
187 5483 : : _pEnv( rEnv._pEnv )
188 : {
189 5483 : if (_pEnv)
190 5483 : (*_pEnv->acquire)( _pEnv );
191 5483 : }
192 : //__________________________________________________________________________________________________
193 69529 : inline Environment::~Environment() SAL_THROW(())
194 : {
195 69529 : if (_pEnv)
196 69494 : (*_pEnv->release)( _pEnv );
197 69529 : }
198 : //__________________________________________________________________________________________________
199 : inline void Environment::clear() SAL_THROW(())
200 : {
201 : if (_pEnv)
202 : {
203 : (*_pEnv->release)( _pEnv );
204 : _pEnv = 0;
205 : }
206 : }
207 : //__________________________________________________________________________________________________
208 12002 : inline Environment & Environment::operator = ( uno_Environment * pEnv ) SAL_THROW(())
209 : {
210 12002 : if (pEnv != _pEnv)
211 : {
212 12002 : if (pEnv)
213 12002 : (*pEnv->acquire)( pEnv );
214 12002 : if (_pEnv)
215 0 : (*_pEnv->release)( _pEnv );
216 12002 : _pEnv = pEnv;
217 : }
218 12002 : return *this;
219 : }
220 : //__________________________________________________________________________________________________
221 : inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(())
222 : {
223 : if (_pEnv)
224 : uno_Environment_invoke_v(_pEnv, pCallee, pParam);
225 : }
226 : //__________________________________________________________________________________________________
227 4963 : inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(())
228 : {
229 4963 : if (_pEnv)
230 : {
231 : va_list param;
232 :
233 4963 : va_start(param, pCallee);
234 4963 : uno_Environment_invoke_v(_pEnv, pCallee, ¶m);
235 4963 : va_end(param);
236 : }
237 :
238 4963 : }
239 : //__________________________________________________________________________________________________
240 : inline void SAL_CALL Environment::enter() const SAL_THROW(())
241 : {
242 : uno_Environment_enter(_pEnv);
243 : }
244 : //__________________________________________________________________________________________________
245 0 : inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const SAL_THROW(())
246 : {
247 0 : return uno_Environment_isValid(_pEnv, (rtl_uString **)pReason);
248 : }
249 : //__________________________________________________________________________________________________
250 7295 : inline Environment Environment::getCurrent(rtl::OUString const & typeName) SAL_THROW(())
251 : {
252 7295 : Environment environment;
253 :
254 7295 : uno_Environment * pEnv = NULL;
255 7295 : uno_getCurrentEnvironment(&pEnv, typeName.pData);
256 7295 : environment = pEnv;
257 7295 : if (pEnv)
258 7295 : pEnv->release(pEnv);
259 :
260 7295 : return environment;
261 : }
262 :
263 : }
264 : }
265 : }
266 : }
267 :
268 : #endif
269 :
270 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|