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/shared/std/containers.h"
26 #include "ultima/ultima8/misc/classtype.h"
27 #include "ultima/ultima8/misc/debugger.h"
28 
29 namespace Ultima {
30 namespace Ultima8 {
31 
32 class Debugger;
33 
34 class Process {
35  friend class Kernel;
36  friend class Debugger;
37 public:
38  virtual void run() = 0;
39 
40  Process(ObjId _itemNum = 0, uint16 type = 0);
41  virtual ~Process() { }
42 
43  ENABLE_RUNTIME_CLASSTYPE_BASE()
44 
45  uint32 getProcessFlags() const {
46  return _flags;
47  }
48  bool is_active() const {
49  return (_flags & PROC_ACTIVE);
50  }
51  bool is_terminated() const {
52  return (_flags & (PROC_TERMINATED |
53  PROC_TERM_DEFERRED)) != 0;
54  }
55  bool is_suspended() const {
56  return (_flags & PROC_SUSPENDED) != 0;
57  }
58 
60  void fail();
61 
63  virtual void terminate();
64 
67  _flags |= PROC_TERM_DEFERRED;
68  }
69 
71  void setRunPaused() {
72  _flags |= PROC_RUNPAUSED;
73  };
74 
76  void waitFor(ProcId pid);
77 
79  void waitFor(Process *proc);
80 
82  void suspend();
83 
85  void wakeUp(uint32 result);
86 
88  virtual void onWakeUp() {};
89 
90  void setItemNum(ObjId it) {
91  _itemNum = it;
92  }
93  void setType(uint16 ty) {
94  _type = ty;
95  }
96  void setTicksPerRun(uint32 val) {
97  _ticksPerRun = val;
98  }
99 
100  ProcId getPid() const {
101  return _pid;
102  }
103  ObjId getItemNum() const {
104  return _itemNum;
105  }
106  uint16 getType() const {
107  return _type;
108  }
109  uint32 getTicksPerRun() const {
110  return _ticksPerRun;
111  }
112 
114  virtual Common::String dumpInfo() const;
115 
117  bool loadData(Common::ReadStream *rs, uint32 version);
118 
120  virtual void saveData(Common::WriteStream *ws);
121 
125  bool validateWaiters() const;
126 
127 protected:
129  ProcId _pid;
130 
131  uint32 _flags;
132 
135  uint32 _ticksPerRun;
136 
138  ObjId _itemNum;
139  uint16 _type;
140 
142  uint32 _result;
143 
147 
148 public:
149 
151  PROC_ACTIVE = 0x0001,
152  PROC_SUSPENDED = 0x0002,
153  PROC_TERMINATED = 0x0004,
155  PROC_FAILED = 0x0010,
156  PROC_RUNPAUSED = 0x0020,
157  PROC_TERM_DISPOSE = 0x0040,
159  };
160 
161 };
162 
163 } // End of namespace Ultima8
164 } // End of namespace Ultima
165 
166 #endif
uint32 _ticksPerRun
Definition: process.h:135
run even if game is paused
Definition: process.h:156
Definition: str.h:59
Definition: stream.h:77
processflags
Definition: process.h:150
Definition: process.h:34
ProcId _pid
process id
Definition: process.h:129
virtual void terminate()
terminate the process. This wakes up all processes waiting for it.
uint32 _result
process result
Definition: process.h:142
suspended? (because it&#39;s waiting)
Definition: process.h:152
Std::vector< ProcId > _waiting
Definition: process.h:146
automatically call terminate next frame
Definition: process.h:154
Definition: detection.h:27
bool validateWaiters() const
Dispose after termination.
Definition: process.h:157
void suspend()
suspend process
void setRunPaused()
run even when paused
Definition: process.h:71
void wakeUp(uint32 result)
Wake up when the process we were waiting for has finished.
bool loadData(Common::ReadStream *rs, uint32 version)
load Process data
void waitFor(ProcId pid)
suspend until process &#39;pid&#39; returns. If pid is 0, suspend indefinitely
void fail()
terminate the process and recursively fail all processes waiting for it
Definition: kernel.h:41
void terminateDeferred()
terminate next frame
Definition: process.h:66
Definition: stream.h:385
Definition: debugger.h:37
ObjId _itemNum
item we are assigned to
Definition: process.h:138
When set, prevent game from saving.
Definition: process.h:158
virtual Common::String dumpInfo() const
dump some info about this process to a string
is the process in the run-list?
Definition: process.h:151
virtual void saveData(Common::WriteStream *ws)
save Process data
virtual void onWakeUp()
A hook to add aditional behavior on wakeup, before anything else happens.
Definition: process.h:88