summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/oprocctrl.h
blob: 4922ba2d3209474283dddd7bb22b56269a415781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* This file is part of the KDE libraries
    Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at)
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
 
    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
//
//  KPROCESSCONTROLLER -- A helper class for KProcess
//
//  version 0.3.1, Jan 8th 1997
//
//  (C) Christian Czezatke
//  e9025461@student.tuwien.ac.at
//  Ported by Holger Freyther
//

#ifndef __KPROCCTRL_H__
#define __KPROCCTRL_H__

#include <qvaluelist.h>
#include <qtimer.h>

#include "oprocess.h"

class QSocketNotifier;


namespace Opie {
namespace Core {
namespace Private {
class OProcessControllerPrivate;

/**
 * @short Used internally by @ref OProcess
 * @internal
 * @author Christian Czezakte <e9025461@student.tuwien.ac.at>
 *
 *  A class for internal use by OProcess only. -- Exactly one instance
 *  of this class is generated by the first instance of OProcess that is
 *  created (a pointer to it gets stored in @ref theOProcessController ).
 *
 * This class takes care of the actual (UN*X) signal handling.
*/
class OProcessController : public QObject
{
    Q_OBJECT

public:
    OProcessController();
    ~OProcessController();
    //CC: WARNING! Destructor Not virtual (but you don't derive classes from this anyhow...)

public:

    /**
     * Only a single instance of this class is allowed at a time,
     * and this static variable is used to track the one instance.
     */
    static OProcessController *theOProcessController;

    /**
     * Automatically called upon SIGCHLD.
     *
     * Normally you do not need to do anything with this function but
     * if your application needs to disable SIGCHLD for some time for
     * reasons beyond your control, you should call this function afterwards
     * to make sure that no SIGCHLDs where missed.
     */
    static void theSigCHLDHandler(int signal);
    // handler for sigchld

    /**
     * @internal
    */
    static void setupHandlers();
    /**
     * @internal
    */
    static void resetHandlers();
    /**
     * @internal
    */
    void addOProcess( OProcess* );
    /**
     * @internal
    */
    void removeOProcess( OProcess* );
public slots:
    /**
     * @internal
     */
    void slotDoHousekeeping(int socket);

private slots:
    void delayedChildrenCleanup();
private:
    int fd[2];
    QSocketNotifier *notifier;
    static struct sigaction oldChildHandlerData;
    static bool handlerSet;
    QValueList<OProcess*> processList;
    QTimer delayedChildrenCleanupTimer;

    // Disallow assignment and copy-construction
    OProcessController( const OProcessController& );
    OProcessController& operator= ( const OProcessController& );

    OProcessControllerPrivate *d;
};

}
}
}


#endif