00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef KERNEL_H
00020 #define KERNEL_H
00021
00022 #include <list>
00023 #include <map>
00024
00025 #include "intrinsics.h"
00026
00027 class Process;
00028 class idMan;
00029 class IDataSource;
00030 class ODataSource;
00031
00032 typedef Process* (*ProcessLoadFunc)(IDataSource*, uint32 version);
00033 typedef std::list<Process*>::const_iterator ProcessIter;
00034
00035 class Kernel {
00036 public:
00037 Kernel();
00038 ~Kernel();
00039
00040 static Kernel* get_instance() { return kernel; }
00041
00042 void reset();
00043
00044 ProcId addProcess(Process *proc);
00045
00048 ProcId addProcessExec(Process *proc);
00049
00050 void removeProcess(Process *proc);
00051 bool runProcesses();
00052 Process* getProcess(ProcId pid);
00053
00054 ProcId assignPID(Process* proc);
00055
00056 void setNextProcess(Process *proc);
00057 Process* getRunningProcess() const { return runningprocess; }
00058
00059
00060 uint32 getNumProcesses(ObjId objid, uint16 processtype);
00061
00063 Process* findProcess(ObjId objid, uint16 processtype);
00064
00069 void killProcesses(ObjId objid, uint16 processtype, bool fail);
00070
00075 void killProcessesNotOfType(ObjId objid, uint16 processtype, bool fail);
00076
00078 ProcessIter getProcessBeginIterator() { return processes.begin(); }
00079 ProcessIter getProcessEndIterator() { return processes.end(); }
00080
00081 void kernelStats();
00082 void processTypes();
00083
00084 void save(ODataSource* ods);
00085 bool load(IDataSource* ids, uint32 version);
00086
00087 void pause() { paused++; }
00088 void unpause() { if (paused > 0) paused--; }
00089 bool isPaused() const { return paused > 0; }
00090
00091 void setFrameByFrame(bool fbf) { framebyframe = fbf; }
00092 bool isFrameByFrame() const { return framebyframe; }
00093
00094 void addProcessLoader(std::string classname, ProcessLoadFunc func)
00095 { processloaders[classname] = func; }
00096
00097 uint32 getFrameNum() const { return framenum; };
00098
00100 static void ConCmd_processTypes(const Console::ArgvType &argv);
00102 static void ConCmd_listProcesses(const Console::ArgvType &argv);
00104 static void ConCmd_processInfo(const Console::ArgvType &argv);
00105
00107 static void ConCmd_toggleFrameByFrame(const Console::ArgvType &argv);
00109 static void ConCmd_advanceFrame(const Console::ArgvType &argv);
00110
00111 INTRINSIC(I_getNumProcesses);
00112 INTRINSIC(I_resetRef);
00113 private:
00114 Process* loadProcess(IDataSource* ids, uint32 version);
00115
00116 std::list<Process*> processes;
00117 idMan *pIDs;
00118
00119 std::list<Process*>::iterator current_process;
00120
00121 std::map<std::string, ProcessLoadFunc> processloaders;
00122
00123 bool loading;
00124
00125 uint32 framenum;
00126 unsigned int paused;
00127 bool framebyframe;
00128
00129 Process* runningprocess;
00130
00131 static Kernel* kernel;
00132 };
00133
00134
00135
00136 template<class T>
00137 struct ProcessLoader {
00138 static Process* load(IDataSource* ids, uint32 version) {
00139 T* p = new T();
00140 bool ok = p->loadData(ids, version);
00141 if (!ok) {
00142 delete p;
00143 p = 0;
00144 }
00145 return p;
00146 }
00147 };
00148
00149
00150 #endif