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