[45157b3] | 1 | /* This file is part of the KDE libraries |
---|
| 2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) |
---|
| 3 | |
---|
| 4 | Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008 |
---|
| 5 | |
---|
| 6 | This library is free software; you can redistribute it and/or |
---|
| 7 | modify it under the terms of the GNU Library General Public |
---|
| 8 | License as published by the Free Software Foundation; either |
---|
| 9 | version 2 of the License, or (at your option) any later version. |
---|
| 10 | |
---|
| 11 | This library is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 14 | Library General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU Library General Public License |
---|
| 17 | along with this library; see the file COPYING.LIB. If not, write to |
---|
| 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
---|
| 19 | Boston, MA 02110-1301, USA. |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #ifndef K3PROCCTRL_H |
---|
| 23 | #define K3PROCCTRL_H |
---|
| 24 | |
---|
| 25 | #include <QtCore/QList> |
---|
| 26 | #include <k3process.h> |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | * @short Used internally by K3Process |
---|
| 31 | * @internal |
---|
| 32 | * @author Christian Czezatke <e9025461@student.tuwien.ac.at> |
---|
| 33 | * |
---|
| 34 | * A class for internal use by K3Process only. -- Exactly one instance |
---|
| 35 | * of this class is created by KApplication. |
---|
| 36 | * |
---|
| 37 | * This class takes care of the actual (UN*X) signal handling. |
---|
| 38 | */ |
---|
| 39 | class K3ProcessController : public QObject |
---|
| 40 | { |
---|
| 41 | Q_OBJECT |
---|
| 42 | |
---|
| 43 | public: |
---|
| 44 | /** |
---|
| 45 | * Create an instance if none exists yet. |
---|
| 46 | * Called by KApplication::KApplication() |
---|
| 47 | */ |
---|
| 48 | static void ref(); |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * Destroy the instance if one exists and it is not referenced any more. |
---|
| 52 | * Called by KApplication::~KApplication() |
---|
| 53 | */ |
---|
| 54 | static void deref(); |
---|
| 55 | |
---|
| 56 | /** |
---|
| 57 | * Only a single instance of this class is allowed at a time. |
---|
| 58 | * This method provides access to that instance. |
---|
| 59 | */ |
---|
| 60 | static K3ProcessController *instance(); |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * Automatically called upon SIGCHLD. Never call it directly. |
---|
| 64 | * If your application (or some library it uses) redirects SIGCHLD, |
---|
| 65 | * the new signal handler (and only it) should call the old handler |
---|
| 66 | * returned by sigaction(). |
---|
| 67 | * @internal |
---|
| 68 | */ |
---|
| 69 | static void theSigCHLDHandler(int signal); // KDE4: private |
---|
| 70 | |
---|
| 71 | /** |
---|
| 72 | * Wait for any process to exit and handle their exit without |
---|
| 73 | * starting an event loop. |
---|
| 74 | * This function may cause K3Process to emit any of its signals. |
---|
| 75 | * |
---|
| 76 | * @param timeout the timeout in seconds. -1 means no timeout. |
---|
| 77 | * @return true if a process exited, false |
---|
| 78 | * if no process exited within @p timeout seconds. |
---|
| 79 | */ |
---|
| 80 | bool waitForProcessExit(int timeout); |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | * Call this function to defer processing of the data that became available |
---|
| 84 | * on notifierFd(). |
---|
| 85 | */ |
---|
| 86 | void unscheduleCheck(); |
---|
| 87 | |
---|
| 88 | /** |
---|
| 89 | * This function @em must be called at some point after calling |
---|
| 90 | * unscheduleCheck(). |
---|
| 91 | */ |
---|
| 92 | void rescheduleCheck(); |
---|
| 93 | |
---|
| 94 | /* |
---|
| 95 | * Obtain the file descriptor K3ProcessController uses to get notified |
---|
| 96 | * about process exits. select() or poll() on it if you create a custom |
---|
| 97 | * event loop that needs to act upon SIGCHLD. |
---|
| 98 | * @return the file descriptor of the reading end of the notification pipe |
---|
| 99 | */ |
---|
| 100 | int notifierFd() const; |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * @internal |
---|
| 104 | */ |
---|
| 105 | void addKProcess( K3Process* ); |
---|
| 106 | /** |
---|
| 107 | * @internal |
---|
| 108 | */ |
---|
| 109 | void removeKProcess( K3Process* ); |
---|
| 110 | /** |
---|
| 111 | * @internal |
---|
| 112 | */ |
---|
| 113 | void addProcess( int pid ); |
---|
| 114 | |
---|
| 115 | private Q_SLOTS: |
---|
| 116 | void slotDoHousekeeping(); |
---|
| 117 | |
---|
| 118 | private: |
---|
| 119 | friend class I_just_love_gcc; |
---|
| 120 | |
---|
| 121 | static void setupHandlers(); |
---|
| 122 | static void resetHandlers(); |
---|
| 123 | |
---|
| 124 | // Disallow instantiation |
---|
| 125 | K3ProcessController(); |
---|
| 126 | ~K3ProcessController(); |
---|
| 127 | |
---|
| 128 | // Disallow assignment and copy-construction |
---|
| 129 | K3ProcessController( const K3ProcessController& ); |
---|
| 130 | K3ProcessController& operator= ( const K3ProcessController& ); |
---|
| 131 | |
---|
| 132 | class Private; |
---|
| 133 | Private * const d; |
---|
| 134 | }; |
---|
| 135 | |
---|
| 136 | #endif |
---|
| 137 | |
---|