Kernel.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2002-2005 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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); // returns pid of new process
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         // objid = 0 means any object, type = 6 means any type
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 // a bit of a hack to prevent having to write a load function for
00135 // every process
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

Generated on Fri Jul 27 22:27:22 2007 for pentagram by  doxygen 1.4.7