ObjFW
OFProcess.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #ifndef __STDC_LIMIT_MACROS
17 # define __STDC_LIMIT_MACROS
18 #endif
19 #ifndef __STDC_CONSTANT_MACROS
20 # define __STDC_CONSTANT_MACROS
21 #endif
22 
23 #include "objfw-defs.h"
24 
25 #ifdef OF_HAVE_SYS_TYPES_H
26 # include <sys/types.h>
27 #endif
28 
29 #import "OFStream.h"
30 #import "OFKernelEventObserver.h"
31 #import "OFString.h"
32 
33 #ifdef OF_WINDOWS
34 # include <windows.h>
35 #endif
36 
37 OF_ASSUME_NONNULL_BEGIN
38 
39 @class OFArray OF_GENERIC(ObjectType);
40 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
41 
47 OF_SUBCLASSING_RESTRICTED
48 @interface OFProcess: OFStream
49 #ifndef OF_WINDOWS
51 #endif
52 {
53 #ifndef OF_WINDOWS
54  pid_t _pid;
55  int _readPipe[2], _writePipe[2];
56 #else
57  HANDLE _process, _readPipe[2], _writePipe[2];
58 #endif
59  int _status;
60  bool _atEndOfStream;
61 }
62 
71 + (instancetype)processWithProgram: (OFString *)program;
72 
82 + (instancetype)
83  processWithProgram: (OFString *)program
84  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
85 
97 + (instancetype)
98  processWithProgram: (OFString *)program
99  programName: (OFString *)programName
100  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
101 
118 + (instancetype)
119  processWithProgram: (OFString *)program
120  programName: (OFString *)programName
121  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments
122  environment: (nullable OFDictionary
123  OF_GENERIC(OFString *, OFString *) *)environment;
124 
125 - (instancetype)init OF_UNAVAILABLE;
126 
135 - (instancetype)initWithProgram: (OFString *)program;
136 
146 - (instancetype)
147  initWithProgram: (OFString *)program
148  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
149 
161 - (instancetype)
162  initWithProgram: (OFString *)program
163  programName: (OFString *)programName
164  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
165 
182 - (instancetype)
183  initWithProgram: (OFString *)program
184  programName: (OFString *)programName
185  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments
186  environment: (nullable OFDictionary
187  OF_GENERIC(OFString *, OFString *) *)environment
188  OF_DESIGNATED_INITIALIZER;
189 
197 - (void)closeForWriting;
198 
204 - (int)waitForTermination;
205 @end
206 
207 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:92
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:58
A class for stream-like communication with a newly created process.
Definition: OFProcess.h:49
A base class for different types of streams.
Definition: OFStream.h:191
A class for handling strings.
Definition: OFString.h:132
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition: OFKernelEventObserver.h:85
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition: OFKernelEventObserver.h:100