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_H 6 #define ABSTRACT_PROCESS_H 7 8 #include <String.h> 9 #include <Url.h> 10 11 #include "StandardMetaData.h" 12 #include "Stoppable.h" 13 14 15 typedef enum process_state { 16 PROCESS_INITIAL = 1 << 0, 17 PROCESS_RUNNING = 1 << 1, 18 PROCESS_COMPLETE = 1 << 2 19 } process_state; 20 21 22 class ProcessListener; 23 24 25 /*! This is the superclass of all Processes. */ 26 27 class AbstractProcess : public Stoppable { 28 public: 29 AbstractProcess(); 30 virtual ~AbstractProcess(); 31 32 virtual const char* Name() const = 0; 33 virtual const char* Description() const = 0; 34 virtual float Progress(); 35 status_t Run(); 36 status_t Stop(); 37 status_t ErrorStatus(); 38 bool IsRunning(); 39 bool WasStopped(); 40 process_state ProcessState(); 41 42 virtual BString LogReport(); 43 44 void SetListener(ProcessListener* listener); 45 46 protected: 47 virtual status_t RunInternal() = 0; 48 virtual status_t StopInternal(); 49 void _NotifyChanged(); 50 51 static char _ProcessStateIdentifier(process_state value); 52 53 protected: 54 BLocker fLock; 55 56 private: 57 ProcessListener* fListener; 58 bool fWasStopped; 59 process_state fProcessState; 60 status_t fErrorStatus; 61 double fDurationSeconds; 62 }; 63 64 #endif // ABSTRACT_PROCESS_H 65