LibreOffice
LibreOffice 7.2 SDK C/C++ API Reference
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 //for docpp
37namespace com
38{ //for docpp
40namespace sun
41{ //for docpp
43namespace star
44{ //for docpp
46namespace uno
47{
48
54{
57 uno_Environment * _pEnv;
58
59public:
66 inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME));
67
69 // these are here to force memory de/allocation to sal lib.
70 static void * SAL_CALL operator new ( size_t nSize )
71 { return ::rtl_allocateMemory( nSize ); }
72 static void SAL_CALL operator delete ( void * pMem )
73 { ::rtl_freeMemory( pMem ); }
74 static void * SAL_CALL operator new ( size_t, void * pMem )
75 { return pMem; }
76 static void SAL_CALL operator delete ( void *, void * )
77 {}
79
84 inline Environment( uno_Environment * pEnv = NULL );
85
92 inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL );
93
94
99 inline Environment( const Environment & rEnv );
100
101#if defined LIBO_INTERNAL_ONLY
102 Environment(Environment && other) noexcept : _pEnv(other._pEnv)
103 { other._pEnv = nullptr; }
104#endif
105
108 inline ~Environment();
109
115 inline Environment & SAL_CALL operator = ( uno_Environment * pEnv );
121 Environment & SAL_CALL operator = ( const Environment & rEnv )
122 { return operator = ( rEnv._pEnv ); }
123
124#if defined LIBO_INTERNAL_ONLY
126 if (_pEnv != nullptr) {
127 (*_pEnv->release)(_pEnv);
128 }
129 _pEnv = other._pEnv;
130 other._pEnv = nullptr;
131 return *this;
132 }
133#endif
134
139 uno_Environment * SAL_CALL get() const
140 { return _pEnv; }
141
147 { return _pEnv->pTypeName; }
148
153 void * SAL_CALL getContext() const
154 { return _pEnv->pContext; }
155
160 bool SAL_CALL is() const
161 { return (_pEnv != NULL); }
162
165 inline void SAL_CALL clear();
166
173 inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const;
174
181 inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const;
182
187 inline void SAL_CALL enter() const;
188
194 inline int SAL_CALL isValid(rtl::OUString * pReason) const;
195};
196
198 : _pEnv( pEnv )
199{
200 if (_pEnv)
201 (*_pEnv->acquire)( _pEnv );
202}
203
204inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext )
205 : _pEnv(NULL)
206{
207 uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
208}
209
211 : _pEnv( rEnv._pEnv )
212{
213 if (_pEnv)
214 (*_pEnv->acquire)( _pEnv );
215}
216
218{
219 if (_pEnv)
220 (*_pEnv->release)( _pEnv );
221}
222
224{
225 if (_pEnv)
226 {
227 (*_pEnv->release)( _pEnv );
228 _pEnv = NULL;
229 }
230}
231
233{
234 if (pEnv != _pEnv)
235 {
236 if (pEnv)
237 (*pEnv->acquire)( pEnv );
238 if (_pEnv)
239 (*_pEnv->release)( _pEnv );
240 _pEnv = pEnv;
241 }
242 return *this;
243}
244
245inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const
246{
247 if (_pEnv)
248 uno_Environment_invoke_v(_pEnv, pCallee, pParam);
249}
250
251inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const
252{
253 if (_pEnv)
254 {
255 va_list param;
256
257 va_start(param, pCallee);
258 uno_Environment_invoke_v(_pEnv, pCallee, &param);
259 va_end(param);
260 }
261
262}
263
264inline void SAL_CALL Environment::enter() const
265{
267}
268
269inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const
270{
271 return uno_Environment_isValid(_pEnv, &pReason->pData);
272}
273
275{
276 Environment environment;
277
278 uno_Environment * pEnv = NULL;
279 uno_getCurrentEnvironment(&pEnv, typeName.pData);
280 environment = pEnv;
281 if (pEnv)
282 pEnv->release(pEnv);
283
284 return environment;
285}
286
287}
288}
289}
290}
291
292#endif
293
294/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
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: unotype.hxx:39
This String class provides base functionality for C++ like Unicode character array handling.
Definition: ustring.hxx:169
The binary specification of a UNO environment.
Definition: environment.h:46
void * pContext
free context pointer to be used for specific classes of environments (e.g., a jvm pointer)
Definition: environment.h:57
void(* acquire)(struct _uno_Environment *pEnv)
Acquires this environment.
Definition: environment.h:67
rtl_uString * pTypeName
type name of environment
Definition: environment.h:53
void(* release)(struct _uno_Environment *pEnv)
Releases this environment; last release of environment will revoke the environment from runtime.
Definition: environment.h:74
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:54
void invoke_v(uno_EnvCallee *pCallee, va_list *pParam) const
Invoke the passed function in this environment.
Definition: environment.hxx:245
void invoke(uno_EnvCallee *pCallee,...) const
Invoke the passed function in this environment.
Definition: environment.hxx:251
void clear()
Releases a set environment.
Definition: environment.hxx:223
Environment(uno_Environment *pEnv=NULL)
Constructor: acquires given environment.
Definition: environment.hxx:197
~Environment()
Destructor: releases a set environment.
Definition: environment.hxx:217
static Environment getCurrent(rtl::OUString const &typeName=rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME))
Returns the current Environment.
Definition: environment.hxx:274
Environment & operator=(uno_Environment *pEnv)
Sets a given environment, i.e.
Definition: environment.hxx:232
void * getContext() const
Gets free context pointer of set environment.
Definition: environment.hxx:153
::rtl::OUString getTypeName() const
Gets type name of set environment.
Definition: environment.hxx:146
int isValid(rtl::OUString *pReason) const
Checks, if it is valid to currently call objects belonging to this environment.
Definition: environment.hxx:269
bool is() const
Tests if an environment is set.
Definition: environment.hxx:160
uno_Environment * get() const
Provides UNacquired pointer to the set C environment.
Definition: environment.hxx:139
void enter() const
Enter this environment explicitly.
Definition: environment.hxx:264