Process.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 PROCESS_H
00020 #define PROCESS_H
00021 
00022 #include <vector>
00023 class IDataSource;
00024 class ODataSource;
00025 
00026 class Process {
00027 public:
00028 
00029         friend class Kernel;
00030 
00031         // returns true if screen needs to be repainted
00032         virtual bool run(const uint32 framenum) = 0;
00033 
00034         Process(ObjId item_num=0, uint16 type=0);
00035         virtual ~Process() { }
00036 
00037         // p_dynamic_cast stuff
00038         ENABLE_RUNTIME_CLASSTYPE();
00039 
00040         // memory pooling stuff
00041         ENABLE_CUSTOM_MEMORY_ALLOCATION();
00042 
00043         uint32 getProcessFlags() const { return flags; }
00044         bool is_active() const { return (flags & PROC_ACTIVE); }
00045         bool is_terminated() const { return (flags & (PROC_TERMINATED |
00046                                                                                                   PROC_TERM_DEFERRED))!=0; }
00047         bool is_suspended() const { return (flags & PROC_SUSPENDED)!=0; }
00048 
00050         void fail();
00051 
00053         virtual void terminate();
00054 
00056         void terminateDeferred() { flags |= PROC_TERM_DEFERRED; }
00057 
00059         void waitFor(ProcId pid);
00060 
00062         void waitFor(Process* proc);
00063 
00065         void suspend();
00066 
00067         void wakeUp(uint32 result);
00068 
00069         void setItemNum(ObjId it) { item_num = it; }
00070         void setType(uint16 ty) { type = ty; }
00071 
00072         ProcId getPid() const { return pid; }
00073         ObjId getItemNum() const { return item_num; }
00074         uint16 getType() const { return type; }
00075 
00077         virtual void dumpInfo();
00078 
00080         void save(ODataSource* ods);
00081 
00083         bool loadData(IDataSource* ids, uint32 version);
00084 
00085 protected:
00087         virtual void saveData(ODataSource* ods);
00088 
00089         void writeProcessHeader(ODataSource* ods);
00090 
00092         ProcId pid;
00093 
00094         uint32 flags;
00095 
00097         ObjId item_num;
00098         uint16 type;
00099 
00101         uint32 result;
00102 
00105         std::vector<ProcId> waiting;
00106 
00107 public:
00108 
00109         enum processflags {
00110                 PROC_ACTIVE      = 0x0001, 
00111                 PROC_SUSPENDED   = 0x0002, 
00112                 PROC_TERMINATED  = 0x0004,
00113                 PROC_TERM_DEFERRED=0x0008, 
00114                 PROC_FAILED      = 0x0010,
00115                 PROC_RUNPAUSED   = 0x0020, 
00116         };
00117 
00118 };
00119 
00120 
00121 #endif

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