LibreOffice
LibreOffice 24.8 SDK C/C++ API Reference
 
Loading...
Searching...
No Matches
environment.hxx
Go to the documentation of this file.
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
20/*
21 * This file is part of LibreOffice published API.
22 */
23#ifndef INCLUDED_UNO_ENVIRONMENT_HXX
24#define INCLUDED_UNO_ENVIRONMENT_HXX
25
26#include "sal/config.h"
27
28#include <cstddef>
29
30#include "rtl/alloc.h"
31#include "rtl/ustring.hxx"
32#include "uno/environment.h"
33
34#include "uno/lbnames.h"
35
36namespace com
37{
38namespace sun
39{
40namespace star
41{
42namespace uno
43{
44
50{
53 uno_Environment * _pEnv;
54
55public:
62 inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME));
63
65 // these are here to force memory de/allocation to sal lib.
66 static void * SAL_CALL operator new ( size_t nSize )
67 { return ::rtl_allocateMemory( nSize ); }
68 static void SAL_CALL operator delete ( void * pMem )
69 { ::rtl_freeMemory( pMem ); }
70 static void * SAL_CALL operator new ( size_t, void * pMem )
71 { return pMem; }
72 static void SAL_CALL operator delete ( void *, void * )
73 {}
75
80 inline Environment( uno_Environment * pEnv = NULL );
81
88 inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL );
89
90
95 inline Environment( const Environment & rEnv );
96
97#if defined LIBO_INTERNAL_ONLY
98 Environment(Environment && other) noexcept : _pEnv(other._pEnv)
99 { other._pEnv = nullptr; }
100#endif
101
104 inline ~Environment();
105
111 inline Environment & SAL_CALL operator = ( uno_Environment * pEnv );
117 Environment & SAL_CALL operator = ( const Environment & rEnv )
118 { return operator = ( rEnv._pEnv ); }
119
120#if defined LIBO_INTERNAL_ONLY
122 if (_pEnv != nullptr) {
123 (*_pEnv->release)(_pEnv);
124 }
125 _pEnv = other._pEnv;
126 other._pEnv = nullptr;
127 return *this;
128 }
129#endif
130
135 uno_Environment * SAL_CALL get() const
136 { return _pEnv; }
137
143 { return _pEnv->pTypeName; }
144
149 void * SAL_CALL getContext() const
150 { return _pEnv->pContext; }
151
156 bool SAL_CALL is() const
157 { return (_pEnv != NULL); }
158
161 inline void SAL_CALL clear();
162
169 inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const;
170
177 inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const;
178
183 inline void SAL_CALL enter() const;
184
190 inline int SAL_CALL isValid(rtl::OUString * pReason) const;
191};
192
194 : _pEnv( pEnv )
195{
196 if (_pEnv)
197 (*_pEnv->acquire)( _pEnv );
198}
199
200inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext )
201 : _pEnv(NULL)
202{
203 uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
204}
205
207 : _pEnv( rEnv._pEnv )
208{
209 if (_pEnv)
210 (*_pEnv->acquire)( _pEnv );
211}
212
214{
215 if (_pEnv)
216 (*_pEnv->release)( _pEnv );
217}
218
220{
221 if (_pEnv)
222 {
223 (*_pEnv->release)( _pEnv );
224 _pEnv = NULL;
225 }
226}
227
229{
230 if (pEnv != _pEnv)
231 {
232 if (pEnv)
233 (*pEnv->acquire)( pEnv );
234 if (_pEnv)
235 (*_pEnv->release)( _pEnv );
236 _pEnv = pEnv;
237 }
238 return *this;
239}
240
241inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const
242{
243 if (_pEnv)
244 uno_Environment_invoke_v(_pEnv, pCallee, pParam);
245}
246
247inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const
248{
249 if (_pEnv)
250 {
251 va_list param;
252
253 va_start(param, pCallee);
254 uno_Environment_invoke_v(_pEnv, pCallee, &param);
255 va_end(param);
256 }
257
258}
259
260inline void SAL_CALL Environment::enter() const
261{
263}
264
265inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const
266{
267 return uno_Environment_isValid(_pEnv, &pReason->pData);
268}
269
271{
272 Environment environment;
273
274 uno_Environment * pEnv = NULL;
275 uno_getCurrentEnvironment(&pEnv, typeName.pData);
276 environment = pEnv;
277 if (pEnv)
278 pEnv->release(pEnv);
279
280 return environment;
281}
282
283}
284}
285}
286}
287
288#endif
289
290/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
struct SAL_DLLPUBLIC_RTTI _uno_Environment uno_Environment
The binary specification of a UNO environment.
CPPU_DLLPUBLIC void uno_getEnvironment(uno_Environment **ppEnv, rtl_uString *pEnvDcp, void *pContext) SAL_THROW_EXTERN_C()
Gets a specific environment.
CPPU_DLLPUBLIC int uno_Environment_isValid(uno_Environment *pEnv, rtl_uString **pReason) SAL_THROW_EXTERN_C()
Check if a particular environment is currently valid, so that objects of that environment might be ca...
CPPU_DLLPUBLIC void uno_Environment_enter(uno_Environment *pEnv) SAL_THROW_EXTERN_C()
Enter an environment explicitly.
CPPU_DLLPUBLIC void uno_Environment_invoke_v(uno_Environment *pEnv, uno_EnvCallee *pCallee, va_list *pParam) SAL_THROW_EXTERN_C()
Invoke the passed function in the given environment.
void uno_EnvCallee(va_list *pParam)
Typedef for variable argument function.
Definition environment.h:342
CPPU_DLLPUBLIC void uno_getCurrentEnvironment(uno_Environment **ppEnv, rtl_uString *pTypeName) SAL_THROW_EXTERN_C()
Returns the current Environment.
Definition types.h:377
Definition types.h:377
Definition types.h:377
Definition typedescription.hxx:43
This String class provides base functionality for C++ like Unicode character array handling.
Definition ustring.hxx:172
C++ wrapper for binary C uno_Environment.
Definition environment.hxx:50
void invoke_v(uno_EnvCallee *pCallee, va_list *pParam) const
Invoke the passed function in this environment.
Definition environment.hxx:241
void invoke(uno_EnvCallee *pCallee,...) const
Invoke the passed function in this environment.
Definition environment.hxx:247
void clear()
Releases a set environment.
Definition environment.hxx:219
Environment(uno_Environment *pEnv=NULL)
Constructor: acquires given environment.
Definition environment.hxx:193
~Environment()
Destructor: releases a set environment.
Definition environment.hxx:213
static Environment getCurrent(rtl::OUString const &typeName=rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME))
Returns the current Environment.
Definition environment.hxx:270
Environment & operator=(uno_Environment *pEnv)
Sets a given environment, i.e.
Definition environment.hxx:228
void * getContext() const
Gets free context pointer of set environment.
Definition environment.hxx:149
::rtl::OUString getTypeName() const
Gets type name of set environment.
Definition environment.hxx:142
int isValid(rtl::OUString *pReason) const
Checks, if it is valid to currently call objects belonging to this environment.
Definition environment.hxx:265
bool is() const
Tests if an environment is set.
Definition environment.hxx:156
uno_Environment * get() const
Provides UNacquired pointer to the set C environment.
Definition environment.hxx:135
void enter() const
Enter this environment explicitly.
Definition environment.hxx:260