fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / uno / environment.hxx
blob272a069d331f129298a84db267dc1c05e6e4e006
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 .
19 #ifndef _UNO_ENVIRONMENT_HXX_
20 #define _UNO_ENVIRONMENT_HXX_
22 #include <rtl/alloc.h>
23 #include <rtl/ustring.hxx>
24 #include <uno/environment.h>
26 #include "uno/lbnames.h"
28 /** */ //for docpp
29 namespace com
31 /** */ //for docpp
32 namespace sun
34 /** */ //for docpp
35 namespace star
37 /** */ //for docpp
38 namespace uno
41 /** C++ wrapper for binary C uno_Environment.
43 @see uno_Environment
45 class Environment
47 /** binary C uno_Environment
49 uno_Environment * _pEnv;
51 public:
52 /** Returns the current Environment.
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
58 inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(CPPU_STRINGIFY(CPPU_ENV))) SAL_THROW(());
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(())
70 /// @endcond
72 /** Constructor: acquires given environment
74 @param pEnv environment
76 inline Environment( uno_Environment * pEnv = 0 ) SAL_THROW(());
78 /** Gets a specific environment. If the specified environment does not exist, then a default one
79 is created and registered.
81 @param envDcp descriptor of the environment
82 @param pContext context pointer
84 inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL ) SAL_THROW(());
87 /** Copy constructor: acquires given environment
89 @param rEnv another environment
91 inline Environment( const Environment & rEnv ) SAL_THROW(());
93 /** Destructor: releases a set environment.
95 inline ~Environment() SAL_THROW(());
97 /** Sets a given environment, i.e. acquires given one and releases a set one.
99 @param pEnv another environment
100 @return this environment
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.
105 @param rEnv another environment
106 @return this environment
108 inline Environment & SAL_CALL operator = ( const Environment & rEnv ) SAL_THROW(())
109 { return operator = ( rEnv._pEnv ); }
111 /** Provides UNacquired pointer to the set C environment.
113 @return UNacquired pointer to the C environment struct
115 inline uno_Environment * SAL_CALL get() const SAL_THROW(())
116 { return _pEnv; }
118 /** Gets type name of set environment.
120 @return type name of set environment
122 inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW(())
123 { return _pEnv->pTypeName; }
125 /** Gets free context pointer of set environment.
127 @return free context pointer of set environment
129 inline void * SAL_CALL getContext() const SAL_THROW(())
130 { return _pEnv->pContext; }
132 /** Tests if a environment is set.
134 @return true, if a environment is set, false otherwise
136 inline sal_Bool SAL_CALL is() const SAL_THROW(())
137 { return (_pEnv != 0); }
139 /** Releases a set environment.
141 inline void SAL_CALL clear() SAL_THROW(());
143 /** Invoke the passed function in this environment.
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
149 inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(());
151 /** Invoke the passed function in this environment.
153 @param pCallee the function to call
154 @param ... the parameters to be passed to the function
155 @since UDK 3.2.7
157 inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(());
159 /** Enter this environment explicitly.
161 @since UDK 3.2.7
163 inline void SAL_CALL enter() const SAL_THROW(());
165 /** Checks, if it is valid to currently call objects
166 belonging to this environment.
168 @since UDK 3.2.7
170 inline int SAL_CALL isValid(rtl::OUString * pReason) const SAL_THROW(());
172 //__________________________________________________________________________________________________
173 inline Environment::Environment( uno_Environment * pEnv ) SAL_THROW(())
174 : _pEnv( pEnv )
176 if (_pEnv)
177 (*_pEnv->acquire)( _pEnv );
179 //__________________________________________________________________________________________________
180 inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext ) SAL_THROW(())
181 : _pEnv(NULL)
183 uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
185 //__________________________________________________________________________________________________
186 inline Environment::Environment( const Environment & rEnv ) SAL_THROW(())
187 : _pEnv( rEnv._pEnv )
189 if (_pEnv)
190 (*_pEnv->acquire)( _pEnv );
192 //__________________________________________________________________________________________________
193 inline Environment::~Environment() SAL_THROW(())
195 if (_pEnv)
196 (*_pEnv->release)( _pEnv );
198 //__________________________________________________________________________________________________
199 inline void Environment::clear() SAL_THROW(())
201 if (_pEnv)
203 (*_pEnv->release)( _pEnv );
204 _pEnv = 0;
207 //__________________________________________________________________________________________________
208 inline Environment & Environment::operator = ( uno_Environment * pEnv ) SAL_THROW(())
210 if (pEnv != _pEnv)
212 if (pEnv)
213 (*pEnv->acquire)( pEnv );
214 if (_pEnv)
215 (*_pEnv->release)( _pEnv );
216 _pEnv = pEnv;
218 return *this;
220 //__________________________________________________________________________________________________
221 inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(())
223 if (_pEnv)
224 uno_Environment_invoke_v(_pEnv, pCallee, pParam);
226 //__________________________________________________________________________________________________
227 inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(())
229 if (_pEnv)
231 va_list param;
233 va_start(param, pCallee);
234 uno_Environment_invoke_v(_pEnv, pCallee, &param);
235 va_end(param);
239 //__________________________________________________________________________________________________
240 inline void SAL_CALL Environment::enter() const SAL_THROW(())
242 uno_Environment_enter(_pEnv);
244 //__________________________________________________________________________________________________
245 inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const SAL_THROW(())
247 return uno_Environment_isValid(_pEnv, (rtl_uString **)pReason);
249 //__________________________________________________________________________________________________
250 inline Environment Environment::getCurrent(rtl::OUString const & typeName) SAL_THROW(())
252 Environment environment;
254 uno_Environment * pEnv = NULL;
255 uno_getCurrentEnvironment(&pEnv, typeName.pData);
256 environment = pEnv;
257 if (pEnv)
258 pEnv->release(pEnv);
260 return environment;
268 #endif
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */