checking in the recent efforts at optimizing clam
[feisty_meow.git] / nucleus / library / processes / process_control.h
1 #ifndef PROCESS_CONTROL_CLASS
2 #define PROCESS_CONTROL_CLASS
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : process_control                                                   *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
11 * redistribute it and/or modify it under the terms of the GNU General Public  *
12 * License as published by the Free Software Foundation; either version 2 of   *
13 * the License or (at your option) any later version.  This is online at:      *
14 *     http://www.fsf.org/copyleft/gpl.html                                    *
15 * Please send any updates to: fred@gruntose.com                               *
16 \*****************************************************************************/
17
18 #include "process_entry.h"
19
20 #include <basis/contracts.h>
21 #include <mathematics/chaos.h>
22 #include <structures/set.h>
23
24 namespace processes {
25
26 // forward.
27 class process_entry_array;
28 class process_implementation_hider;
29
30 //! Provides a bridge to the operating system for information on processes.
31 /*!
32   This object can query the operating system for the current set of processes
33   or zap a particular process of interest.
34 */
35
36 class process_control : public virtual basis::nameable
37 {
38 public:
39   process_control();
40   virtual ~process_control();
41
42   DEFINE_CLASS_NAME("process_control");
43
44   bool healthy() const { return _healthy; }
45     //!< returns true if this object should be functional.
46     /*!< if it failed to construct properly, this returns false.  usually a
47     failure indicates that a required dynamic library is missing, such as
48     "psapi.dll" on win32. */
49
50   process_entry query_process(basis::un_int to_query);
51     //!< returns the information for just one process.
52
53   bool query_processes(process_entry_array &to_fill);
54     //!< finds the processes that are running and drops them into "to_fill".
55
56   bool zap_process(basis::un_int to_zap);
57     //!< preemptively zaps the process "to_zap".
58     /*!< this does not invoke any friendly graceful shut down process, but
59     merely terminates it if possible. */
60
61   static bool find_process_in_list(const process_entry_array &processes,
62           const basis::astring &app_name, structures::int_set &pids);
63     //!< uses a pre-existing list of "processes" to search for the "app_name".
64     /*!< if the process is found, true is returned and the "pids" are set to
65     all entries matching the process name.  note that this is an approximate
66     match for some OSes that have a brain damaged process lister (such as
67     ms-windows); they have programs listed under incomplete names in some
68     cases. */
69
70   void sort_by_name(process_entry_array &to_sort);
71     // sorts the list by process name.
72   void sort_by_pid(process_entry_array &to_sort);
73     // sorts the list by process id.
74
75 private:
76   process_implementation_hider *_ptrs;  //!< our OS baggage.
77 //#ifndef _MSC_VER
78   mathematics::chaos *_rando;  //!< used for process list.
79 //#else
80   //bool _use_psapi;  //!< true if we should be using the PSAPI on NT and family.
81 //#endif
82   bool _healthy;  //!< true if construction succeeded.
83
84 //#ifndef _MSC_VER
85   bool get_processes_with_ps(process_entry_array &to_fill);
86     //!< asks the ps program what processes exist.
87 /*
88 #else
89   // fill in our function pointers to access the kernel functions appropriate
90   // for either NT (psapi) or 9x (toolhelp).
91   bool initialize_psapi_support();
92   bool initialize_toolhelp_support();
93
94   bool get_processes_with_psapi(process_entry_array &to_fill);
95     //!< uses the PSAPI support for windows NT 4 (or earlier?).
96   bool get_processes_with_toolhelp(process_entry_array &to_fill);
97     //!< uses the toolhelp support for windows 9x, ME, 2000.
98 #endif
99 */
100 };
101
102 } //namespace.
103
104 #endif // outer guard.
105