ScummVM API documentation
process.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ULTIMA8_KERNEL_USECODE_PROCESS_H
23 #define ULTIMA8_KERNEL_USECODE_PROCESS_H
24 
25 #include "ultima/ultima8/misc/classtype.h"
26 #include "ultima/ultima8/misc/common_types.h"
27 #include "ultima/ultima8/misc/debugger.h"
28 
29 namespace Common {
30 class ReadStream;
31 }
32 
33 namespace Ultima {
34 namespace Ultima8 {
35 
36 class Debugger;
37 
38 class Process {
39  friend class Kernel;
40  friend class Debugger;
41 public:
42  virtual void run() = 0;
43 
44  Process(ObjId _itemNum = 0, uint16 type = 0);
45  virtual ~Process() { }
46 
47  ENABLE_RUNTIME_CLASSTYPE_BASE()
48 
49  uint32 getProcessFlags() const {
50  return _flags;
51  }
52  bool is_active() const {
53  return (_flags & PROC_ACTIVE);
54  }
55  bool is_terminated() const {
56  return (_flags & (PROC_TERMINATED |
57  PROC_TERM_DEFERRED)) != 0;
58  }
59  bool is_suspended() const {
60  return (_flags & PROC_SUSPENDED) != 0;
61  }
62 
64  void fail();
65 
67  virtual void terminate();
68 
71  _flags |= PROC_TERM_DEFERRED;
72  }
73 
75  void setRunPaused() {
76  _flags |= PROC_RUNPAUSED;
77  };
78 
80  void waitFor(ProcId pid);
81 
83  void waitFor(Process *proc);
84 
86  void suspend();
87 
89  void wakeUp(uint32 result);
90 
92  virtual void onWakeUp() {};
93 
94  void setItemNum(ObjId it) {
95  _itemNum = it;
96  }
97  void setType(uint16 ty) {
98  _type = ty;
99  }
100  void setTicksPerRun(uint32 val) {
101  _ticksPerRun = val;
102  }
103 
104  ProcId getPid() const {
105  return _pid;
106  }
107  ObjId getItemNum() const {
108  return _itemNum;
109  }
110  uint16 getType() const {
111  return _type;
112  }
113  uint32 getTicksPerRun() const {
114  return _ticksPerRun;
115  }
116 
118  virtual Common::String dumpInfo() const;
119 
121  bool loadData(Common::ReadStream *rs, uint32 version);
122 
124  virtual void saveData(Common::WriteStream *ws);
125 
129  bool validateWaiters() const;
130 
131 protected:
133  ProcId _pid;
134 
135  uint32 _flags;
136 
139  uint32 _ticksPerRun;
140 
142  ObjId _itemNum;
143  uint16 _type;
144 
146  uint32 _result;
147 
151 
152 public:
153 
155  PROC_ACTIVE = 0x0001,
156  PROC_SUSPENDED = 0x0002,
157  PROC_TERMINATED = 0x0004,
158  PROC_TERM_DEFERRED = 0x0008,
159  PROC_FAILED = 0x0010,
160  PROC_RUNPAUSED = 0x0020,
161  PROC_TERM_DISPOSE = 0x0040,
162  PROC_PREVENT_SAVE = 0x0080
163  };
164 
165 };
166 
167 } // End of namespace Ultima8
168 } // End of namespace Ultima
169 
170 #endif
uint32 _ticksPerRun
Definition: process.h:139
Definition: str.h:59
Definition: stream.h:77
processflags
Definition: process.h:154
Definition: process.h:38
ProcId _pid
process id
Definition: process.h:133
uint32 _result
process result
Definition: process.h:146
Definition: detection.h:27
void setRunPaused()
run even when paused
Definition: process.h:75
Common::Array< ProcId > _waiting
Definition: process.h:150
Definition: algorithm.h:29
Definition: kernel.h:45
void terminateDeferred()
terminate next frame
Definition: process.h:70
Definition: stream.h:385
Definition: debugger.h:33
ObjId _itemNum
item we are assigned to
Definition: process.h:142
virtual void onWakeUp()
A hook to add aditional behavior on wakeup, before anything else happens.
Definition: process.h:92