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 14 15 class AbstractProcess; 16 class ProcessListener; 17 18 19 /*! This class is designed to be used by the ProcessCoordinator class. The 20 purpose of the class is to hold a process and also any dependent processes 21 of this one. This effectively creates a dependency tree of processes. 22 */ 23 24 class AbstractProcessNode { 25 public: 26 AbstractProcessNode(AbstractProcess* process); 27 virtual ~AbstractProcessNode(); 28 29 AbstractProcess* Process() const; 30 virtual status_t Start() = 0; 31 virtual status_t RequestStop() = 0; 32 virtual bool IsRunning(); 33 34 void AddPredecessor(AbstractProcessNode* node); 35 int32 CountPredecessors() const; 36 AbstractProcessNode* 37 PredecessorAt(int32 index) const; 38 bool AllPredecessorsComplete() const; 39 40 int32 CountSuccessors() const; 41 AbstractProcessNode* 42 SuccessorAt(int32 index) const; 43 44 virtual void SetListener(ProcessListener* listener); 45 46 protected: 47 status_t _SpinUntilProcessState( 48 uint32 desiredStatesMask, 49 int32 timeoutSeconds); 50 51 protected: 52 BLocker fLock; 53 ProcessListener* fListener; 54 55 private: 56 void _AddSuccessor(AbstractProcessNode* node); 57 58 AbstractProcess* fProcess; 59 BObjectList<AbstractProcessNode> 60 fPredecessorNodes; 61 BObjectList<AbstractProcessNode> 62 fSuccessorNodes; 63 }; 64 65 66 #endif // ABSTRACT_PROCESS_NODE_H 67