blocxx
Main Page
Namespaces
Classes
Files
File List
File Members
src
blocxx
Process.hpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* Copyright (C) 2005, Quest Software, Inc. All rights reserved.
3
* Copyright (C) 2006, Novell, Inc. All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* * Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* * Neither the name of
14
* Quest Software, Inc.,
15
* nor Novell, Inc.,
16
* nor the names of its contributors or employees may be used to
17
* endorse or promote products derived from this software without
18
* specific prior written permission.
19
*
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
31
*******************************************************************************/
32
33
34
#ifndef BLOCXX_PROCESS_HPP_INCLUDE_GUARD_
35
#define BLOCXX_PROCESS_HPP_INCLUDE_GUARD_
36
41
#include "blocxx/BLOCXX_config.h"
42
#include "
blocxx/Exception.hpp
"
43
#include "
blocxx/Types.hpp
"
44
#include "
blocxx/IntrusiveCountableBase.hpp
"
45
#include "
blocxx/CommonFwd.hpp
"
46
#include "
blocxx/Cstr.hpp
"
47
#include "
blocxx/Timeout.hpp
"
48
// For Exec::spawn
49
#include <vector>
50
51
namespace
BLOCXX_NAMESPACE
52
{
53
54
BLOCXX_DECLARE_EXCEPTION
(ProcessError);
55
56
class
ProcessImpl
;
57
typedef
IntrusiveReference<ProcessImpl>
ProcessImplRef
;
58
60
//
61
class
BLOCXX_COMMON_API
Process
:
public
IntrusiveCountableBase
62
{
63
public
:
66
//
67
Process
(
68
UnnamedPipeRef
const
& in,
UnnamedPipeRef
const
& out,
69
UnnamedPipeRef
const
& err,
ProcId
pid
70
);
71
72
protected
:
79
//
80
Process
(
81
const
ProcessImplRef
& impl,
UnnamedPipeRef
const
& in,
UnnamedPipeRef
const
& out,
82
UnnamedPipeRef
const
& err,
ProcId
pid
83
);
84
85
public
:
88
Process
(
ProcId
pid);
89
97
void
release();
98
103
virtual
~
Process
();
104
107
UnnamedPipeRef
in()
const
;
108
111
UnnamedPipeRef
out()
const
;
112
115
UnnamedPipeRef
err()
const
;
116
118
ProcId
pid()
const
;
119
121
//
122
class
BLOCXX_COMMON_API
Status
123
{
124
public
:
125
struct
Repr
{ };
126
129
132
//
133
Status
(
ProcId
wpid,
int
status);
134
137
//
138
Status
(
int
rep1,
int
rep2,
Repr
);
139
141
//
142
Status
();
143
145
//
146
bool
running()
const
;
147
149
//
150
bool
exitTerminated()
const
;
151
157
int
exitStatus()
const
;
158
160
//
161
bool
terminatedSuccessfully()
const
;
162
164
//
165
bool
signalTerminated()
const
;
166
168
//
169
bool
terminated()
const
;
170
173
//
174
int
termSignal()
const
;
175
177
//
178
bool
stopped()
const
;
179
182
//
183
int
stopSignal()
const
;
184
188
String
toString()
const
;
189
193
int
getPOSIXwaitpidStatus()
const
;
194
195
void
repr(
int
& rep1,
int
& rep2)
const
;
196
197
private
:
198
bool
m_status_available
;
199
int
m_status
;
200
};
201
207
Status
processStatus();
208
209
enum
ETerminationSelectionFlag
210
{
212
E_TERMINATE_PROCESS_GROUP
,
214
E_TERMINATE_PROCESS_ONLY
215
};
238
void
waitCloseTerm(
239
const
Timeout
& wait_initial =
Timeout::relative
(5.0),
240
const
Timeout
& wait_close =
Timeout::relative
(10.0),
241
const
Timeout
& wait_term =
Timeout::relative
(15.0),
242
ETerminationSelectionFlag terminationSelectionFlag = E_TERMINATE_PROCESS_GROUP);
243
266
void
waitCloseTerm(
float
wait_initial,
float
wait_close,
float
wait_term);
267
268
private
:
269
bool
terminatesWithin(
const
Timeout
& wait_time);
270
ProcId
getCurProcessId();
271
272
#ifdef BLOCXX_WIN32
273
bool
terminateByMessage(
const
Timeout
& waitTime);
274
bool
killProcess(
const
Timeout
& waitTime, ETerminationSelectionFlag terminationSelectionFlag);
275
#else
276
bool
killWait(
const
Timeout
& wait_time,
int
sig
,
char
const
* signame, ETerminationSelectionFlag terminationSelectionFlag);
277
#endif
278
280
Process
(
Process
const
&);
281
283
void
operator=(
Process
const
&);
284
285
ProcessImplRef
m_impl
;
286
UnnamedPipeRef
m_in
;
287
UnnamedPipeRef
m_out
;
288
UnnamedPipeRef
m_err
;
289
ProcId
m_pid
;
290
Status
m_status
;
291
};
292
296
class
BLOCXX_COMMON_API
ProcessImpl
:
public
IntrusiveCountableBase
297
{
298
public
:
299
virtual
~
ProcessImpl
();
300
307
virtual
int
kill(
ProcId
pid,
int
sig
) = 0;
308
315
virtual
Process::Status
pollStatus(
ProcId
pid) = 0;
316
};
317
318
319
320
}
// namespace BLOCXX_NAMESPACE
321
322
#endif
Generated by
1.8.2