xref: /haiku/src/apps/haikudepot/process/AbstractProcessNode.h (revision 3538133f9fefc41c557f365f0919f18bd0f0404b)
1a18f873fSAndrew Lindesay /*
2409af934SAndrew Lindesay  * Copyright 2018-2022, Andrew Lindesay <apl@lindesay.co.nz>.
3a18f873fSAndrew Lindesay  * All rights reserved. Distributed under the terms of the MIT License.
4a18f873fSAndrew Lindesay  */
5a18f873fSAndrew Lindesay #ifndef ABSTRACT_PROCESS_NODE_H
6a18f873fSAndrew Lindesay #define ABSTRACT_PROCESS_NODE_H
7a18f873fSAndrew Lindesay 
8a18f873fSAndrew Lindesay 
9409af934SAndrew Lindesay #include <AutoLocker.h>
10409af934SAndrew Lindesay #include <Locker.h>
11a18f873fSAndrew Lindesay #include <ObjectList.h>
12a18f873fSAndrew Lindesay #include <OS.h>
13*3538133fSAndrew Lindesay #include <String.h>
14a18f873fSAndrew Lindesay 
15a18f873fSAndrew Lindesay 
16a18f873fSAndrew Lindesay class AbstractProcess;
17409af934SAndrew Lindesay class ProcessListener;
18a18f873fSAndrew Lindesay 
19a18f873fSAndrew Lindesay 
20a18f873fSAndrew Lindesay /*! This class is designed to be used by the ProcessCoordinator class.  The
21a18f873fSAndrew Lindesay     purpose of the class is to hold a process and also any dependent processes
22a18f873fSAndrew Lindesay     of this one.  This effectively creates a dependency tree of processes.
23a18f873fSAndrew Lindesay */
24a18f873fSAndrew Lindesay 
25a18f873fSAndrew Lindesay class AbstractProcessNode {
26a18f873fSAndrew Lindesay public:
27a18f873fSAndrew Lindesay 								AbstractProcessNode(AbstractProcess* process);
28a18f873fSAndrew Lindesay 	virtual						~AbstractProcessNode();
29a18f873fSAndrew Lindesay 
30a18f873fSAndrew Lindesay 			AbstractProcess*	Process() const;
3195c7b018SAndrew Lindesay 	virtual	status_t			Start() = 0;
3295c7b018SAndrew Lindesay 	virtual	status_t			RequestStop() = 0;
33409af934SAndrew Lindesay 	virtual	bool				IsRunning();
34a18f873fSAndrew Lindesay 
35a18f873fSAndrew Lindesay 			void				AddPredecessor(AbstractProcessNode* node);
36a18f873fSAndrew Lindesay 			int32				CountPredecessors() const;
37a18f873fSAndrew Lindesay 			AbstractProcessNode*
38a18f873fSAndrew Lindesay 								PredecessorAt(int32 index) const;
39a18f873fSAndrew Lindesay 			bool				AllPredecessorsComplete() const;
40a18f873fSAndrew Lindesay 
41a18f873fSAndrew Lindesay 			int32				CountSuccessors() const;
42a18f873fSAndrew Lindesay 			AbstractProcessNode*
43a18f873fSAndrew Lindesay 								SuccessorAt(int32 index) const;
44a18f873fSAndrew Lindesay 
45409af934SAndrew Lindesay 	virtual	void				SetListener(ProcessListener* listener);
46409af934SAndrew Lindesay 
47*3538133fSAndrew Lindesay 			BString				LogReport();
48*3538133fSAndrew Lindesay 
49a18f873fSAndrew Lindesay protected:
50a18f873fSAndrew Lindesay 			status_t			_SpinUntilProcessState(
51a18f873fSAndrew Lindesay 									uint32 desiredStatesMask,
5295c7b018SAndrew Lindesay 									int32 timeoutSeconds);
53a18f873fSAndrew Lindesay 
54409af934SAndrew Lindesay protected:
55409af934SAndrew Lindesay 			BLocker				fLock;
56409af934SAndrew Lindesay 			ProcessListener*	fListener;
57409af934SAndrew Lindesay 
58a18f873fSAndrew Lindesay private:
59a18f873fSAndrew Lindesay 			void				_AddSuccessor(AbstractProcessNode* node);
60a18f873fSAndrew Lindesay 
61a18f873fSAndrew Lindesay 			AbstractProcess*	fProcess;
62a18f873fSAndrew Lindesay 			BObjectList<AbstractProcessNode>
63a18f873fSAndrew Lindesay 								fPredecessorNodes;
64a18f873fSAndrew Lindesay 			BObjectList<AbstractProcessNode>
65a18f873fSAndrew Lindesay 								fSuccessorNodes;
66a18f873fSAndrew Lindesay };
67a18f873fSAndrew Lindesay 
68a18f873fSAndrew Lindesay 
69a18f873fSAndrew Lindesay #endif // ABSTRACT_PROCESS_NODE_H
70