xref: /haiku/src/apps/haikudepot/process/AbstractProcessNode.h (revision a18f873f8b884375ea8278f3c9df0e433b822262)
1*a18f873fSAndrew Lindesay /*
2*a18f873fSAndrew Lindesay  * Copyright 2018-2021, Andrew Lindesay <apl@lindesay.co.nz>.
3*a18f873fSAndrew Lindesay  * All rights reserved. Distributed under the terms of the MIT License.
4*a18f873fSAndrew Lindesay  */
5*a18f873fSAndrew Lindesay #ifndef ABSTRACT_PROCESS_NODE_H
6*a18f873fSAndrew Lindesay #define ABSTRACT_PROCESS_NODE_H
7*a18f873fSAndrew Lindesay 
8*a18f873fSAndrew Lindesay 
9*a18f873fSAndrew Lindesay #include <ObjectList.h>
10*a18f873fSAndrew Lindesay #include <OS.h>
11*a18f873fSAndrew Lindesay 
12*a18f873fSAndrew Lindesay 
13*a18f873fSAndrew Lindesay class AbstractProcess;
14*a18f873fSAndrew Lindesay 
15*a18f873fSAndrew Lindesay 
16*a18f873fSAndrew Lindesay /*! This class is designed to be used by the ProcessCoordinator class.  The
17*a18f873fSAndrew Lindesay     purpose of the class is to hold a process and also any dependent processes
18*a18f873fSAndrew Lindesay     of this one.  This effectively creates a dependency tree of processes.
19*a18f873fSAndrew Lindesay */
20*a18f873fSAndrew Lindesay 
21*a18f873fSAndrew Lindesay class AbstractProcessNode {
22*a18f873fSAndrew Lindesay public:
23*a18f873fSAndrew Lindesay 								AbstractProcessNode(AbstractProcess* process);
24*a18f873fSAndrew Lindesay 	virtual						~AbstractProcessNode();
25*a18f873fSAndrew Lindesay 
26*a18f873fSAndrew Lindesay 			AbstractProcess*	Process() const;
27*a18f873fSAndrew Lindesay 	virtual	status_t			StartProcess() = 0;
28*a18f873fSAndrew Lindesay 	virtual	status_t			StopProcess() = 0;
29*a18f873fSAndrew Lindesay 
30*a18f873fSAndrew Lindesay 			void				AddPredecessor(AbstractProcessNode* node);
31*a18f873fSAndrew Lindesay 			int32				CountPredecessors() const;
32*a18f873fSAndrew Lindesay 			AbstractProcessNode*
33*a18f873fSAndrew Lindesay 								PredecessorAt(int32 index) const;
34*a18f873fSAndrew Lindesay 			bool				AllPredecessorsComplete() const;
35*a18f873fSAndrew Lindesay 
36*a18f873fSAndrew Lindesay 			int32				CountSuccessors() const;
37*a18f873fSAndrew Lindesay 			AbstractProcessNode*
38*a18f873fSAndrew Lindesay 								SuccessorAt(int32 index) const;
39*a18f873fSAndrew Lindesay 
40*a18f873fSAndrew Lindesay protected:
41*a18f873fSAndrew Lindesay 			status_t			_SpinUntilProcessState(
42*a18f873fSAndrew Lindesay 									uint32 desiredStatesMask,
43*a18f873fSAndrew Lindesay 									uint32 timeoutSeconds);
44*a18f873fSAndrew Lindesay 
45*a18f873fSAndrew Lindesay private:
46*a18f873fSAndrew Lindesay 			void				_AddSuccessor(AbstractProcessNode* node);
47*a18f873fSAndrew Lindesay 
48*a18f873fSAndrew Lindesay 			AbstractProcess*	fProcess;
49*a18f873fSAndrew Lindesay 			BObjectList<AbstractProcessNode>
50*a18f873fSAndrew Lindesay 								fPredecessorNodes;
51*a18f873fSAndrew Lindesay 			BObjectList<AbstractProcessNode>
52*a18f873fSAndrew Lindesay 								fSuccessorNodes;
53*a18f873fSAndrew Lindesay };
54*a18f873fSAndrew Lindesay 
55*a18f873fSAndrew Lindesay 
56*a18f873fSAndrew Lindesay #endif // ABSTRACT_PROCESS_NODE_H
57