00001 #ifndef PROCESS_CONTROL_CLASS 00002 #define PROCESS_CONTROL_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : process_control * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 2000-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include "process_entry.h" 00019 00020 #include <basis/contracts.h> 00021 #include <mathematics/chaos.h> 00022 #include <structures/set.h> 00023 00024 namespace processes { 00025 00026 // forward. 00027 class process_entry_array; 00028 class process_implementation_hider; 00029 00031 00036 class process_control : public virtual basis::nameable 00037 { 00038 public: 00039 process_control(); 00040 virtual ~process_control(); 00041 00042 DEFINE_CLASS_NAME("process_control"); 00043 00044 bool healthy() const { return _healthy; } 00046 00050 process_entry query_process(basis::un_int to_query); 00052 00053 bool query_processes(process_entry_array &to_fill); 00055 00056 bool zap_process(basis::un_int to_zap); 00058 00061 static bool find_process_in_list(const process_entry_array &processes, 00062 const basis::astring &app_name, structures::int_set &pids); 00064 00070 void sort_by_name(process_entry_array &to_sort); 00071 // sorts the list by process name. 00072 void sort_by_pid(process_entry_array &to_sort); 00073 // sorts the list by process id. 00074 00075 private: 00076 process_implementation_hider *_ptrs; 00077 #ifdef __UNIX__ 00078 mathematics::chaos *_rando; 00079 #endif 00080 #ifdef __WIN32__ 00081 bool _use_psapi; 00082 #endif 00083 bool _healthy; 00084 00085 #ifdef __UNIX__ 00086 bool get_processes_with_ps(process_entry_array &to_fill); 00088 #endif 00089 #ifdef __WIN32__ 00090 // fill in our function pointers to access the kernel functions appropriate 00091 // for either NT (psapi) or 9x (toolhelp). 00092 bool initialize_psapi_support(); 00093 bool initialize_toolhelp_support(); 00094 00095 bool get_processes_with_psapi(process_entry_array &to_fill); 00097 bool get_processes_with_toolhelp(process_entry_array &to_fill); 00099 #endif 00100 }; 00101 00102 } //namespace. 00103 00104 #endif // outer guard. 00105
1.6.3