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 void SetListener(ProcessListener* listener); 43 44 protected: 45 virtual status_t RunInternal() = 0; 46 virtual status_t StopInternal(); 47 void _NotifyChanged(); 48 49 protected: 50 BLocker fLock; 51 52 private: 53 ProcessListener* fListener; 54 bool fWasStopped; 55 process_state fProcessState; 56 status_t fErrorStatus; 57 }; 58 59 #endif // ABSTRACT_PROCESS_H 60