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 #ifndef INCLUDED_OSL_PROCESS_H
22 #define INCLUDED_OSL_PROCESS_H
24 #include <sal/config.h>
28 #include <osl/security.h>
29 #include <osl/socket.h>
31 #include <rtl/locale.h>
32 #include <rtl/textenc.h>
33 #include <rtl/ustring.h>
34 #include <sal/saldllapi.h>
41 typedef sal_Int32 oslProcessOption
;
42 #define osl_Process_WAIT 0x0001 /* wait for completion */
43 #define osl_Process_SEARCHPATH 0x0002 /* search path for executable */
44 #define osl_Process_DETACHED 0x0004 /* run detached */
45 #define osl_Process_NORMAL 0x0000 /* run in normal window */
46 #define osl_Process_HIDDEN 0x0010 /* run hidden */
47 #define osl_Process_MINIMIZED 0x0020 /* run in minimized window */
48 #define osl_Process_MAXIMIZED 0x0040 /* run in maximized window */
49 #define osl_Process_FULLSCREEN 0x0080 /* run in fullscreen window */
51 typedef sal_Int32 oslProcessData
;
53 /* defines for osl_getProcessInfo , can be OR'ed */
54 #define osl_Process_IDENTIFIER 0x0001 /* retrieves the process identifier */
55 #define osl_Process_EXITCODE 0x0002 /* retrieves exit code of the process */
56 #define osl_Process_CPUTIMES 0x0004 /* retrieves used cpu time */
57 #define osl_Process_HEAPUSAGE 0x0008 /* retrieves the used size of heap */
59 typedef sal_uInt32 oslProcessIdentifier
;
60 typedef sal_uInt32 oslProcessExitCode
;
63 osl_Process_E_None
, /* no error */
64 osl_Process_E_NotFound
, /* image not found */
65 osl_Process_E_TimedOut
, /* timout occurred */
66 osl_Process_E_NoPermission
, /* permission denied */
67 osl_Process_E_Unknown
, /* unknown error */
68 osl_Process_E_InvalidError
, /* unmapped error */
69 osl_Process_E_FORCE_EQUAL_SIZE
= SAL_MAX_ENUM
73 # pragma pack(push, 8)
78 oslProcessData Fields
;
79 oslProcessIdentifier Ident
;
80 oslProcessExitCode Code
;
92 @see osl_executeProcess
93 @see osl_terminateProcess
94 @see osl_freeProcessHandle
95 @see osl_getProcessInfo
98 typedef void* oslProcess
;
100 /** Execute a process.
102 Executes the program image provided in strImageName in a new process.
105 [in] The file URL of the executable to be started.
106 Can be NULL in this case the file URL of the executable must be the first element
110 [in] An array of argument strings. Can be NULL if strImageName is not NULL.
111 If strImageName is NULL it is expected that the first element contains
112 the file URL of the executable to start.
115 [in] The number of arguments provided. If this number is 0 strArguments will be ignored.
118 [in] A combination of int-constants to describe the mode of execution.
121 [in] The user and his rights for which the process is started. May be NULL in which case
122 the process will be started in the context of the current user.
125 [in] The file URL of the working directory of the new process. If the specified directory
126 does not exist or is inaccessible the working directory of the newly created process
127 is undefined. If this parameter is NULL or the caller provides an empty string the
128 new process will have the same current working directory as the calling process.
130 @param ustrEnvironments
131 [in] An array of strings describing environment variables that should be merged into the
132 environment of the new process. Each string has to be in the form "variable=value".
133 This parameter can be NULL in which case the new process gets the same environment
134 as the parent process.
136 @param nEnvironmentVars
137 [in] The number of environment variables to set.
140 [out] Pointer to a oslProcess variable, which receives the handle of the newly created process.
141 This parameter must not be NULL.
143 @retval osl_Process_E_None on success
144 @retval osl_Process_E_NotFound if the specified executable could not be found</dd>
145 @retval osl_Process_E_InvalidError if invalid parameters will be detected</dd>
146 @retval osl_Process_E_Unknown if arbitrary other errors occur</dd>
148 @see oslProcessOption
149 @see osl_executeProcess_WithRedirectedIO
150 @see osl_freeProcessHandle
153 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_executeProcess(
154 rtl_uString
* ustrImageName
,
155 rtl_uString
* ustrArguments
[],
156 sal_uInt32 nArguments
,
157 oslProcessOption Options
,
158 oslSecurity Security
,
159 rtl_uString
* ustrDirectory
,
160 rtl_uString
* ustrEnvironments
[],
161 sal_uInt32 nEnvironmentVars
,
162 oslProcess
* pProcess
);
165 /** Execute a process and redirect child process standard IO.
168 [in] The file URL of the executable to be started.
169 Can be NULL in this case the file URL of the executable must be the first element
173 [in] An array of argument strings. Can be NULL if strImageName is not NULL.
174 If strImageName is NULL it is expected that the first element contains
175 the file URL of the executable to start.
178 [in] The number of arguments provided. If this number is 0 strArguments will be ignored.
181 [in] A combination of int-constants to describe the mode of execution.
184 [in] The user and his rights for which the process is started. May be NULL in which case
185 the process will be started in the context of the current user.
188 [in] The file URL of the working directory of the new process. If the specified directory
189 does not exist or is inaccessible the working directory of the newly created process
190 is undefined. If this parameter is NULL or the caller provides an empty string the
191 new process will have the same current working directory as the calling process.
193 @param ustrEnvironments
194 [in] An array of strings describing environment variables that should be merged into the
195 environment of the new process. Each string has to be in the form "variable=value".
196 This parameter can be NULL in which case the new process gets the same environment
197 as the parent process.
199 @param nEnvironmentVars
200 [in] The number of environment variables to set.
203 [out] Pointer to a oslProcess variable, which receives the handle of the newly created process.
204 This parameter must not be NULL.
206 @param pChildInputWrite
207 [in] Pointer to a oslFileHandle variable that receives the handle which can be used to write
208 to the child process standard input device. The returned handle is not random accessible.
209 The handle has to be closed with osl_closeFile if no longer used. This parameter can be NULL.
211 @param pChildOutputRead
212 [in] Pointer to a oslFileHandle variable that receives the handle which can be used to read from
213 the child process standard output device. The returned handle is not random accessible.
214 The Handle has to be closed with osl_closeFile if no longer used. This parameter can be NULL.
216 @param pChildErrorRead
217 [in] Pointer to a oslFileHandle variable that receives the handle which can be used to read from
218 the child process standard error device. The returned handle is not random accessible.
219 The Handle has to be closed with osl_closeFile if no longer used. This parameter can be NULL.
221 @retval osl_Process_E_None on success
222 @retval osl_Process_E_NotFound if the specified executable could not be found
223 @retval osl_Process_E_InvalidError if invalid parameters will be detected
224 @retval osl_Process_E_Unknown if arbitrary other errors occur
226 @see oslProcessOption
227 @see osl_executeProcess
228 @see osl_freeProcessHandle
232 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_executeProcess_WithRedirectedIO(
233 rtl_uString
* strImageName
,
234 rtl_uString
* ustrArguments
[],
235 sal_uInt32 nArguments
,
236 oslProcessOption Options
,
237 oslSecurity Security
,
238 rtl_uString
* ustrDirectory
,
239 rtl_uString
* ustrEnvironments
[],
240 sal_uInt32 nEnvironmentVars
,
241 oslProcess
* pProcess
,
242 oslFileHandle
* pChildInputWrite
,
243 oslFileHandle
* pChildOutputRead
,
244 oslFileHandle
* pChildErrorRead
);
246 /** Terminate a process
247 @param Process [in] the handle of the process to be terminated
249 @see osl_executeProcess
253 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_terminateProcess(
258 Retrieve the process handle of a process identifier
259 @param Ident [in] a process identifier
261 @return the process handle on success, NULL in all other cases
263 SAL_DLLPUBLIC oslProcess SAL_CALL
osl_getProcess(
264 oslProcessIdentifier Ident
) SAL_COLD
;
267 /** Free the specified process-handle.
270 SAL_DLLPUBLIC
void SAL_CALL
osl_freeProcessHandle(
274 /** Wait for completion of the specified childprocess.
276 @retval ols_Process_E_None
277 @see osl_executeProcess
279 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_joinProcess(
282 /** Wait with a timeout for the completion of the specified child
286 A process identifier.
289 A timeout value or NULL for infinite waiting.
290 The unit of resolution is second.
292 @retval osl_Process_E_None on success
293 @retval osl_Process_E_TimedOut waiting for the child process timed out
294 @retval osl_Process_E_Unknown an error occurred or the parameter are invalid
296 @see osl_executeProcess
298 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_joinProcessWithTimeout(
299 oslProcess Process
, const TimeValue
* pTimeout
);
301 /** Retrieves information about a Process
302 @param[in] Process the process handle of the process
303 @param[in] Fields the information which is to be retrieved
304 this can be one or more of
305 osl_Process_IDENTIFIER
308 osl_Process_HEAPUSAGE
309 @param[out] pInfo a pointer to a valid oslProcessInfo structure.
310 the Size field has to be initialized with the size
311 of the oslProcessInfo structure.
312 on success the Field member holds the (or'ed)
313 retrieved valid information fields.
314 @retval osl_Process_E_None on success
315 @retval osl_Process_E_Unknown on failure
317 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_getProcessInfo(
318 oslProcess Process
, oslProcessData Fields
, oslProcessInfo
* pInfo
);
320 /** Get the filename of the executable.
321 @param strFile [out] the string that receives the executable file path.
322 @return osl_Process_E_None or does not return.
323 @see osl_executeProcess
325 Ideally this will return the true executable file path as a file:
326 URL, but actually in case something else happens to have been
327 passed as argv[0] to osl_setCommandArgs(), it will return that
328 either as a file URL, or as such in case it doesn't look like an
331 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_getExecutableFile(
332 rtl_uString
**strFile
);
334 /** @return the number of commandline arguments passed to the main-function of
336 @see osl_getCommandArg
338 SAL_DLLPUBLIC sal_uInt32 SAL_CALL
osl_getCommandArgCount(void);
340 /** Get the nArg-th command-line argument passed to the main-function of this process.
341 @param nArg [in] The number of the argument to return.
342 @param strCommandArg [out] The string receives the nArg-th command-line argument.
343 @return osl_Process_E_None or does not return.
344 @see osl_executeProcess
346 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_getCommandArg(
347 sal_uInt32 nArg
, rtl_uString
**strCommandArg
);
349 /** Set the command-line arguments as passed to the main-function of this process.
351 Deprecated: This function is only for internal use. Passing the args from main will
352 only work for Unix, on Windows there's no effect, the full command line will automatically
353 be taken. This is due to Windows 9x/ME limitation that don't allow UTF-16 wmain to provide
354 a osl_setCommandArgsU( int argc, sal_Unicode **argv );
356 @param argc [in] The number of elements in the argv array.
357 @param argv [in] The array of command-line arguments.
358 @see osl_getExecutableFile
359 @see osl_getCommandArgCount
360 @see osl_getCommandArg
362 SAL_DLLPUBLIC
void SAL_CALL
osl_setCommandArgs (int argc
, char **argv
);
364 /** Get the value of one environment variable.
365 @param strVar [in] denotes the name of the variable to get.
366 @param strValue [out] string that receives the value of environment variable.
368 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_getEnvironment(
369 rtl_uString
*strVar
, rtl_uString
**strValue
);
371 /** Set the value of one environment variable.
372 @param strVar [in] denotes the name of the variable to set.
373 @param strValue [in] string of the new value of environment variable.
377 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_setEnvironment(
378 rtl_uString
*strVar
, rtl_uString
*strValue
);
380 /** Unsets the value of one environment variable.
381 @param strVar [in] denotes the name of the variable to unset.
385 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_clearEnvironment(
386 rtl_uString
*strVar
);
388 /** Get the working directory of the current process as a file URL.
390 The file URL is encoded as common for the OSL file API.
391 @param pustrWorkingDir [out] string that receives the working directory file URL.
394 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_getProcessWorkingDir(
395 rtl_uString
**pustrWorkingDir
);
397 /** Get the locale the process is currently running in.
399 @param ppLocale [out] a pointer that receives the currently selected locale structure
402 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_getProcessLocale(
403 rtl_Locale
** ppLocale
);
405 /** Change the locale of the process.
407 @param pLocale [in] a pointer to the locale to be set
409 @deprecated LibreOffice itself does not use this, and client code should
410 not have good use for it either. It may eventually be removed.
413 SAL_DLLPUBLIC oslProcessError SAL_CALL
osl_setProcessLocale(
414 rtl_Locale
* pLocale
);
420 #endif // INCLUDED_OSL_PROCESS_H
422 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */