lok: avoid expensive fetching of a property.
[LibreOffice.git] / include / uno / environment.h
blob314fc6f2c7c14334b71a1d189822ddd0bacb29a2
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 INCLUDED_UNO_ENVIRONMENT_H
20 #define INCLUDED_UNO_ENVIRONMENT_H
22 #include "cppu/cppudllapi.h"
23 #include "rtl/ustring.h"
25 #include <stdarg.h>
27 #ifdef __cplusplus
28 extern "C"
30 #endif
32 struct _uno_ExtEnvironment;
33 struct _typelib_InterfaceTypeDescription;
35 #if defined( _WIN32)
36 #pragma pack(push, 8)
37 #endif
39 /** The binary specification of a UNO environment.
41 typedef struct SAL_DLLPUBLIC_RTTI _uno_Environment
43 /** reserved for future use (0 if not used)
45 void * pReserved;
47 /** type name of environment
49 rtl_uString * pTypeName;
51 /** free context pointer to be used for specific classes of environments (e.g., a jvm pointer)
53 void * pContext;
55 /** pointer to extended environment (interface registration functionality), if supported
57 struct _uno_ExtEnvironment * pExtEnv;
59 /** Acquires this environment.
61 @param pEnv this environment
63 void (SAL_CALL * acquire)( struct _uno_Environment * pEnv );
65 /** Releases this environment; last release of environment will revoke the environment from
66 runtime.
68 @param pEnv this environment
70 void (SAL_CALL * release)( struct _uno_Environment * pEnv );
72 /** Acquires this environment weakly. You can only harden a weakly held environment if it
73 is still acquired hard (acquire()).
75 @param pEnv this environment
77 void (SAL_CALL * acquireWeak)( struct _uno_Environment * pEnv );
79 /** Releases this environment weakly in correspondence to acquireWeak().
81 @param pEnv this environment
83 void (SAL_CALL * releaseWeak)( struct _uno_Environment * pEnv );
85 /** Makes hard reference out of weak referenced environment. You can only harden a weakly
86 held environment if it is still acquired hard (acquire()).
88 @param ppHardEnv inout hard referenced environment (has to be released via release())
89 @param pEnv environment (may be weak referenced)
91 void (SAL_CALL * harden)(
92 struct _uno_Environment ** ppHardEnv,
93 struct _uno_Environment * pEnv );
95 /** Call this function to EXPLICITLY dispose this environment (e.g., release all
96 interfaces). You may want to call this function before shutting down due to a runtime error.
98 @param pEnv this environment
100 void (SAL_CALL * dispose)( struct _uno_Environment * pEnv );
102 /* ===== the following part will be late initialized by a matching bridge ===== *
103 * ===== and is NOT for public use. ===== */
105 /** CALLBACK function pointer: Disposing callback function pointer that can be set to get
106 signalled before the environment is destroyed.
108 @param pEnv environment that is being disposed
110 void (SAL_CALL * environmentDisposing)( struct _uno_Environment * pEnv );
111 } uno_Environment;
113 /** Generic function pointer declaration to free a proxy object if it is not needed by the
114 environment anymore.
115 Any proxy object must register itself on first acquire() call and revoke itself on last
116 release() call. This can happen several times because the environment caches proxy objects
117 until the environment explicitly frees the proxy object calling this function.
119 @param pEnv environment
120 @param pProxy proxy pointer
122 typedef void (SAL_CALL * uno_freeProxyFunc)( struct _uno_ExtEnvironment * pEnv, void * pProxy );
124 /** Generic function pointer declaration to allocate memory. Used with getRegisteredInterfaces().
126 @param nBytes amount of memory in bytes
127 @return pointer to allocated memory
129 typedef void * (SAL_CALL * uno_memAlloc)( sal_Size nBytes );
131 /** The binary specification of a UNO environment supporting interface registration.
133 typedef struct SAL_DLLPUBLIC_RTTI _uno_ExtEnvironment
135 /** inherits all members of a uno_Environment
137 uno_Environment aBase;
139 /** Registers an interface of this environment.
141 @param pEnv this environment
142 @param ppInterface inout parameter of interface to be registered
143 @param pOId object id of interface
144 @param pTypeDescr type description of interface
146 void (SAL_CALL * registerInterface)(
147 struct _uno_ExtEnvironment * pEnv,
148 void ** ppInterface,
149 rtl_uString * pOId,
150 struct _typelib_InterfaceTypeDescription * pTypeDescr );
152 /** Registers a proxy interface of this environment that can be reanimated and is freed
153 explicitly by this environment.
155 @param pEnv this environment
156 @param ppInterface inout parameter of interface to be registered
157 @param freeProxy function to free proxy object
158 @param pOId object id of interface
159 @param pTypeDescr type description of interface
161 void (SAL_CALL * registerProxyInterface)(
162 struct _uno_ExtEnvironment * pEnv,
163 void ** ppProxy,
164 uno_freeProxyFunc freeProxy,
165 rtl_uString * pOId,
166 struct _typelib_InterfaceTypeDescription * pTypeDescr );
168 /** Revokes an interface from this environment. You have to revoke any interface that has
169 been registered via this method.
171 @param pEnv this environment
172 @param pInterface interface to be revoked
174 void (SAL_CALL * revokeInterface)(
175 struct _uno_ExtEnvironment * pEnv,
176 void * pInterface );
178 /** Provides the object id of a given interface.
180 @param ppOut inout oid
181 @param pInterface interface of object
183 void (SAL_CALL * getObjectIdentifier)(
184 struct _uno_ExtEnvironment * pEnv,
185 rtl_uString ** ppOId,
186 void * pInterface );
188 /** Retrieves an interface identified by its object id and type from this environment.
189 Interfaces are retrieved in the same order as they are registered.
191 @param pEnv this environment
192 @param ppInterface inout parameter for the registered interface; (0) if none was found
193 @param pOId object id of interface to be retrieved
194 @param pTypeDescr type description of interface to be retrieved
196 void (SAL_CALL * getRegisteredInterface)(
197 struct _uno_ExtEnvironment * pEnv,
198 void ** ppInterface,
199 rtl_uString * pOId,
200 struct _typelib_InterfaceTypeDescription * pTypeDescr );
202 /** Returns all currently registered interfaces of this environment. The memory block
203 allocated might be slightly larger than (*pnLen * sizeof(void *)).
205 @param pEnv this environment
206 @param pppInterfaces out param; pointer to array of interface pointers
207 @param pnLen out param; length of array
208 @param memAlloc function for allocating memory that is passed back
210 void (SAL_CALL * getRegisteredInterfaces)(
211 struct _uno_ExtEnvironment * pEnv,
212 void *** pppInterfaces,
213 sal_Int32 * pnLen,
214 uno_memAlloc memAlloc );
216 /* ===== the following part will be late initialized by a matching bridge ===== */
218 /** Computes an object id of the given interface; is called by the environment implementation.
220 @param pEnv corresponding environment
221 @param ppOId out param: computed id
222 @param pInterface an interface
224 void (SAL_CALL * computeObjectIdentifier)(
225 struct _uno_ExtEnvironment * pEnv,
226 rtl_uString ** ppOId, void * pInterface );
228 /** Function to acquire an interface.
230 @param pEnv corresponding environment
231 @param pInterface an interface
233 void (SAL_CALL * acquireInterface)(
234 struct _uno_ExtEnvironment * pEnv,
235 void * pInterface );
237 /** Function to release an interface.
239 @param pEnv corresponding environment
240 @param pInterface an interface
242 void (SAL_CALL * releaseInterface)(
243 struct _uno_ExtEnvironment * pEnv,
244 void * pInterface );
246 } uno_ExtEnvironment;
248 #if defined( _WIN32)
249 #pragma pack(pop)
250 #endif
252 /** Function exported by some bridge library providing acquireInterface(), releaseInterface();
253 may set a disposing callback.
255 @param pEnv environment to be initialized
257 typedef void (SAL_CALL * uno_initEnvironmentFunc)( uno_Environment * pEnv );
258 #define UNO_INIT_ENVIRONMENT "uno_initEnvironment"
260 #ifdef DISABLE_DYNLOADING
261 /* We link statically and have just the C++ environment */
262 void SAL_CALL CPPU_ENV_uno_initEnvironment( uno_Environment * Env )
263 SAL_THROW_EXTERN_C();
265 /* We might also have the Java environment */
266 void SAL_CALL java_uno_initEnvironment( uno_Environment * Env )
267 SAL_THROW_EXTERN_C();
268 #endif
270 /** Gets a specific environment. If the specified environment does not exist, then a default one
271 is created and registered. The environment revokes itself on last release() call.
273 @param ppEnv inout parameter of environment; given environment will be released
274 @param pEnvDcp descriptor of environment
275 @param pContext some context pointer (e.g., to distinguish java vm; set 0 if not needed)
277 CPPU_DLLPUBLIC void SAL_CALL uno_getEnvironment(
278 uno_Environment ** ppEnv, rtl_uString * pEnvDcp, void * pContext )
279 SAL_THROW_EXTERN_C();
281 /** Gets all specified environments. Caller has to release returned environments and free allocated
282 memory.
284 @param pppEnvs out param; pointer to array of environments
285 @param pnLen out param; length of array
286 @param memAlloc function for allocating memory that is passed back
287 @param pEnvDcp descriptor of environments; 0 defaults to all
289 CPPU_DLLPUBLIC void SAL_CALL uno_getRegisteredEnvironments(
290 uno_Environment *** pppEnvs, sal_Int32 * pnLen, uno_memAlloc memAlloc,
291 rtl_uString * pEnvDcp )
292 SAL_THROW_EXTERN_C();
294 /** Creates an environment. The new environment is anonymous (NOT publicly registered/ accessible).
296 @param ppEnv out parameter of environment; given environment will be released
297 @param pEnvDcp descriptor of environment
298 @param pContext context pointer (e.g., to distinguish java vm); set 0 if not needed
300 CPPU_DLLPUBLIC void SAL_CALL uno_createEnvironment(
301 uno_Environment ** ppEnv, rtl_uString * pEnvDcp, void * pContext )
302 SAL_THROW_EXTERN_C();
304 /** Dumps out environment information, i.e. registered interfaces.
306 @param stream output stream (FILE *)
307 @param pEnv environment to be dumped
308 @param pFilter if not null, filters output
310 CPPU_DLLPUBLIC void SAL_CALL uno_dumpEnvironment(
311 void * stream, uno_Environment * pEnv, const char * pFilter )
312 SAL_THROW_EXTERN_C();
313 /** Dumps out environment information, i.e. registered interfaces.
315 @param stream output stream (FILE *)
316 @param pEnvDcp descriptor of environment to be dumped
317 @param pFilter if not null, filters output
319 CPPU_DLLPUBLIC void SAL_CALL uno_dumpEnvironmentByName(
320 void * stream, rtl_uString * pEnvDcp, const char * pFilter )
321 SAL_THROW_EXTERN_C();
325 /** Returns the current Environment.
326 In case no Environment has explicitly been entered, a purpose free
327 default environment gets returned (e.g. the "uno" or "gcc3" Environment).
329 @param ppEnv inout parameter; a given environment will be released
330 @param pTypeName the optional type of the environment, falls back to "uno"
331 @since UDK 3.2.7
333 CPPU_DLLPUBLIC void SAL_CALL uno_getCurrentEnvironment(uno_Environment ** ppEnv, rtl_uString * pTypeName)
334 SAL_THROW_EXTERN_C();
336 /** Typedef for variable argument function.
338 typedef void SAL_CALL uno_EnvCallee(va_list * pParam);
340 /** Invoke the passed function in the given environment.
342 @param pEnv the target environment
343 @param pCallee the function to call
344 @param pParam the parameter pointer passed to the function
345 @since UDK 3.2.7
347 CPPU_DLLPUBLIC void SAL_CALL uno_Environment_invoke_v(uno_Environment * pEnv, uno_EnvCallee * pCallee, va_list * pParam)
348 SAL_THROW_EXTERN_C();
350 /** Invoke the passed function in the given environment.
352 @param pEnv the target environment
353 @param pCallee the function to call
354 @param ... the parameters passed to the function
355 @since UDK 3.2.7
357 CPPU_DLLPUBLIC void SAL_CALL uno_Environment_invoke (uno_Environment * pEnv, uno_EnvCallee * pCallee, ...)
358 SAL_THROW_EXTERN_C();
360 /** Enter an environment explicitly.
362 @param pEnv the environment to enter; NULL leaves all environments
363 @since UDK 3.2.7
365 CPPU_DLLPUBLIC void SAL_CALL uno_Environment_enter(uno_Environment * pEnv)
366 SAL_THROW_EXTERN_C();
368 /** Check if a particular environment is currently valid, so
369 that objects of that environment might be called.
371 @param pEnv the environment
372 @param pReason the reason, if it is not valid
373 @return 1 == valid, 0 == invalid
374 @since UDK 3.2.7
376 CPPU_DLLPUBLIC int SAL_CALL uno_Environment_isValid(uno_Environment * pEnv, rtl_uString ** pReason)
377 SAL_THROW_EXTERN_C();
379 #ifdef __cplusplus
381 #endif
383 #endif
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */