1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 * This file is part of LibreOffice published API.
23 #ifndef INCLUDED_UNO_ENVIRONMENT_H
24 #define INCLUDED_UNO_ENVIRONMENT_H
26 #include "cppu/cppudllapi.h"
27 #include "rtl/ustring.h"
36 struct _uno_ExtEnvironment
;
37 struct _typelib_InterfaceTypeDescription
;
43 /** The binary specification of a UNO environment.
45 typedef struct SAL_DLLPUBLIC_RTTI _uno_Environment
47 /** reserved for future use (0 if not used)
51 /** type name of environment
53 rtl_uString
* pTypeName
;
55 /** free context pointer to be used for specific classes of environments (e.g., a jvm pointer)
59 /** pointer to extended environment (interface registration functionality), if supported
61 struct _uno_ExtEnvironment
* pExtEnv
;
63 /** Acquires this environment.
65 @param pEnv this environment
67 void (SAL_CALL
* acquire
)( struct _uno_Environment
* pEnv
);
69 /** Releases this environment; last release of environment will revoke the environment from
72 @param pEnv this environment
74 void (SAL_CALL
* release
)( struct _uno_Environment
* pEnv
);
76 /** Acquires this environment weakly. You can only harden a weakly held environment if it
77 is still acquired hard (acquire()).
79 @param pEnv this environment
81 void (SAL_CALL
* acquireWeak
)( struct _uno_Environment
* pEnv
);
83 /** Releases this environment weakly in correspondence to acquireWeak().
85 @param pEnv this environment
87 void (SAL_CALL
* releaseWeak
)( struct _uno_Environment
* pEnv
);
89 /** Makes hard reference out of weak referenced environment. You can only harden a weakly
90 held environment if it is still acquired hard (acquire()).
92 @param ppHardEnv inout hard referenced environment (has to be released via release())
93 @param pEnv environment (may be weak referenced)
95 void (SAL_CALL
* harden
)(
96 struct _uno_Environment
** ppHardEnv
,
97 struct _uno_Environment
* pEnv
);
99 /** Call this function to EXPLICITLY dispose this environment (e.g., release all
100 interfaces). You may want to call this function before shutting down due to a runtime error.
102 @param pEnv this environment
104 void (SAL_CALL
* dispose
)( struct _uno_Environment
* pEnv
);
106 /* ===== the following part will be late initialized by a matching bridge ===== *
107 * ===== and is NOT for public use. ===== */
109 /** CALLBACK function pointer: Disposing callback function pointer that can be set to get
110 signalled before the environment is destroyed.
112 @param pEnv environment that is being disposed
114 void (SAL_CALL
* environmentDisposing
)( struct _uno_Environment
* pEnv
);
117 /** Generic function pointer declaration to free a proxy object if it is not needed by the
119 Any proxy object must register itself on first acquire() call and revoke itself on last
120 release() call. This can happen several times because the environment caches proxy objects
121 until the environment explicitly frees the proxy object calling this function.
123 @param pEnv environment
124 @param pProxy proxy pointer
126 typedef void (SAL_CALL
* uno_freeProxyFunc
)( struct _uno_ExtEnvironment
* pEnv
, void * pProxy
);
128 /** Generic function pointer declaration to allocate memory. Used with getRegisteredInterfaces().
130 @param nBytes amount of memory in bytes
131 @return pointer to allocated memory
133 typedef void * (SAL_CALL
* uno_memAlloc
)( sal_Size nBytes
);
135 /** The binary specification of a UNO environment supporting interface registration.
137 typedef struct SAL_DLLPUBLIC_RTTI _uno_ExtEnvironment
139 /** inherits all members of a uno_Environment
141 uno_Environment aBase
;
143 /** Registers an interface of this environment.
145 @param pEnv this environment
146 @param ppInterface inout parameter of interface to be registered
147 @param pOId object id of interface
148 @param pTypeDescr type description of interface
150 void (SAL_CALL
* registerInterface
)(
151 struct _uno_ExtEnvironment
* pEnv
,
154 struct _typelib_InterfaceTypeDescription
* pTypeDescr
);
156 /** Registers a proxy interface of this environment that can be reanimated and is freed
157 explicitly by this environment.
159 @param pEnv this environment
160 @param ppInterface inout parameter of interface to be registered
161 @param freeProxy function to free proxy object
162 @param pOId object id of interface
163 @param pTypeDescr type description of interface
165 void (SAL_CALL
* registerProxyInterface
)(
166 struct _uno_ExtEnvironment
* pEnv
,
168 uno_freeProxyFunc freeProxy
,
170 struct _typelib_InterfaceTypeDescription
* pTypeDescr
);
172 /** Revokes an interface from this environment. You have to revoke any interface that has
173 been registered via this method.
175 @param pEnv this environment
176 @param pInterface interface to be revoked
178 void (SAL_CALL
* revokeInterface
)(
179 struct _uno_ExtEnvironment
* pEnv
,
182 /** Provides the object id of a given interface.
184 @param ppOut inout oid
185 @param pInterface interface of object
187 void (SAL_CALL
* getObjectIdentifier
)(
188 struct _uno_ExtEnvironment
* pEnv
,
189 rtl_uString
** ppOId
,
192 /** Retrieves an interface identified by its object id and type from this environment.
193 Interfaces are retrieved in the same order as they are registered.
195 @param pEnv this environment
196 @param ppInterface inout parameter for the registered interface; (0) if none was found
197 @param pOId object id of interface to be retrieved
198 @param pTypeDescr type description of interface to be retrieved
200 void (SAL_CALL
* getRegisteredInterface
)(
201 struct _uno_ExtEnvironment
* pEnv
,
204 struct _typelib_InterfaceTypeDescription
* pTypeDescr
);
206 /** Returns all currently registered interfaces of this environment. The memory block
207 allocated might be slightly larger than (*pnLen * sizeof(void *)).
209 @param pEnv this environment
210 @param pppInterfaces out param; pointer to array of interface pointers
211 @param pnLen out param; length of array
212 @param memAlloc function for allocating memory that is passed back
214 void (SAL_CALL
* getRegisteredInterfaces
)(
215 struct _uno_ExtEnvironment
* pEnv
,
216 void *** pppInterfaces
,
218 uno_memAlloc memAlloc
);
220 /* ===== the following part will be late initialized by a matching bridge ===== */
222 /** Computes an object id of the given interface; is called by the environment implementation.
224 @param pEnv corresponding environment
225 @param ppOId out param: computed id
226 @param pInterface an interface
228 void (SAL_CALL
* computeObjectIdentifier
)(
229 struct _uno_ExtEnvironment
* pEnv
,
230 rtl_uString
** ppOId
, void * pInterface
);
232 /** Function to acquire an interface.
234 @param pEnv corresponding environment
235 @param pInterface an interface
237 void (SAL_CALL
* acquireInterface
)(
238 struct _uno_ExtEnvironment
* pEnv
,
241 /** Function to release an interface.
243 @param pEnv corresponding environment
244 @param pInterface an interface
246 void (SAL_CALL
* releaseInterface
)(
247 struct _uno_ExtEnvironment
* pEnv
,
250 } uno_ExtEnvironment
;
256 /** Function exported by some bridge library providing acquireInterface(), releaseInterface();
257 may set a disposing callback.
259 @param pEnv environment to be initialized
261 typedef void (SAL_CALL
* uno_initEnvironmentFunc
)( uno_Environment
* pEnv
);
262 #define UNO_INIT_ENVIRONMENT "uno_initEnvironment"
264 #ifdef DISABLE_DYNLOADING
265 /* We link statically and have just the C++ environment */
266 void SAL_CALL
CPPU_ENV_uno_initEnvironment( uno_Environment
* Env
)
267 SAL_THROW_EXTERN_C();
269 /* We might also have the Java environment */
270 void SAL_CALL
java_uno_initEnvironment( uno_Environment
* Env
)
271 SAL_THROW_EXTERN_C();
274 /** Gets a specific environment. If the specified environment does not exist, then a default one
275 is created and registered. The environment revokes itself on last release() call.
277 @param ppEnv inout parameter of environment; given environment will be released
278 @param pEnvDcp descriptor of environment
279 @param pContext some context pointer (e.g., to distinguish java vm; set 0 if not needed)
281 CPPU_DLLPUBLIC
void SAL_CALL
uno_getEnvironment(
282 uno_Environment
** ppEnv
, rtl_uString
* pEnvDcp
, void * pContext
)
283 SAL_THROW_EXTERN_C();
285 /** Gets all specified environments. Caller has to release returned environments and free allocated
288 @param pppEnvs out param; pointer to array of environments
289 @param pnLen out param; length of array
290 @param memAlloc function for allocating memory that is passed back
291 @param pEnvDcp descriptor of environments; 0 defaults to all
293 CPPU_DLLPUBLIC
void SAL_CALL
uno_getRegisteredEnvironments(
294 uno_Environment
*** pppEnvs
, sal_Int32
* pnLen
, uno_memAlloc memAlloc
,
295 rtl_uString
* pEnvDcp
)
296 SAL_THROW_EXTERN_C();
298 /** Creates an environment. The new environment is anonymous (NOT publicly registered/ accessible).
300 @param ppEnv out parameter of environment; given environment will be released
301 @param pEnvDcp descriptor of environment
302 @param pContext context pointer (e.g., to distinguish java vm); set 0 if not needed
304 CPPU_DLLPUBLIC
void SAL_CALL
uno_createEnvironment(
305 uno_Environment
** ppEnv
, rtl_uString
* pEnvDcp
, void * pContext
)
306 SAL_THROW_EXTERN_C();
308 /** Dumps out environment information, i.e. registered interfaces.
310 @param stream output stream (FILE *)
311 @param pEnv environment to be dumped
312 @param pFilter if not null, filters output
314 CPPU_DLLPUBLIC
void SAL_CALL
uno_dumpEnvironment(
315 void * stream
, uno_Environment
* pEnv
, const char * pFilter
)
316 SAL_THROW_EXTERN_C();
317 /** Dumps out environment information, i.e. registered interfaces.
319 @param stream output stream (FILE *)
320 @param pEnvDcp descriptor of environment to be dumped
321 @param pFilter if not null, filters output
323 CPPU_DLLPUBLIC
void SAL_CALL
uno_dumpEnvironmentByName(
324 void * stream
, rtl_uString
* pEnvDcp
, const char * pFilter
)
325 SAL_THROW_EXTERN_C();
329 /** Returns the current Environment.
330 In case no Environment has explicitly been entered, a purpose free
331 default environment gets returned (e.g. the "uno" or "gcc3" Environment).
333 @param ppEnv inout parameter; a given environment will be released
334 @param pTypeName the optional type of the environment, falls back to "uno"
337 CPPU_DLLPUBLIC
void SAL_CALL
uno_getCurrentEnvironment(uno_Environment
** ppEnv
, rtl_uString
* pTypeName
)
338 SAL_THROW_EXTERN_C();
340 /** Typedef for variable argument function.
342 typedef void SAL_CALL
uno_EnvCallee(va_list * pParam
);
344 /** Invoke the passed function in the given environment.
346 @param pEnv the target environment
347 @param pCallee the function to call
348 @param pParam the parameter pointer passed to the function
351 CPPU_DLLPUBLIC
void SAL_CALL
uno_Environment_invoke_v(uno_Environment
* pEnv
, uno_EnvCallee
* pCallee
, va_list * pParam
)
352 SAL_THROW_EXTERN_C();
354 /** Invoke the passed function in the given environment.
356 @param pEnv the target environment
357 @param pCallee the function to call
358 @param ... the parameters passed to the function
361 CPPU_DLLPUBLIC
void SAL_CALL
uno_Environment_invoke (uno_Environment
* pEnv
, uno_EnvCallee
* pCallee
, ...)
362 SAL_THROW_EXTERN_C();
364 /** Enter an environment explicitly.
366 @param pEnv the environment to enter; NULL leaves all environments
369 CPPU_DLLPUBLIC
void SAL_CALL
uno_Environment_enter(uno_Environment
* pEnv
)
370 SAL_THROW_EXTERN_C();
372 /** Check if a particular environment is currently valid, so
373 that objects of that environment might be called.
375 @param pEnv the environment
376 @param pReason the reason, if it is not valid
377 @return 1 == valid, 0 == invalid
380 CPPU_DLLPUBLIC
int SAL_CALL
uno_Environment_isValid(uno_Environment
* pEnv
, rtl_uString
** pReason
)
381 SAL_THROW_EXTERN_C();
389 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */