1 /* 2 * Copyright 2017 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Brian Hill 7 */ 8 #ifndef TASK_LOOPER_H 9 #define TASK_LOOPER_H 10 11 12 #include <Job.h> 13 #include <Looper.h> 14 #include <ObjectList.h> 15 #include <String.h> 16 #include <StringList.h> 17 #include <package/Context.h> 18 19 #include "TaskTimer.h" 20 21 22 class DecisionProvider : public BPackageKit::BDecisionProvider { 23 public: 24 DecisionProvider() {} 25 26 virtual bool YesNoDecisionNeeded(const BString& description, 27 const BString& question, 28 const BString& yes, 29 const BString& no, 30 const BString& defaultChoice) 31 { return true; } 32 }; 33 34 35 class JobStateListener : public BSupportKit::BJobStateListener { 36 public: 37 JobStateListener() {} 38 39 virtual void JobStarted(BSupportKit::BJob* job); 40 virtual void JobSucceeded(BSupportKit::BJob* job); 41 virtual void JobFailed(BSupportKit::BJob* job); 42 virtual void JobAborted(BSupportKit::BJob* job); 43 BString GetJobLog(); 44 45 private: 46 BStringList fJobLog; 47 }; 48 49 50 class TaskLooper : public BLooper { 51 public: 52 TaskLooper(const BMessenger& target); 53 virtual bool QuitRequested(); 54 virtual void MessageReceived(BMessage*); 55 56 private: 57 void _RemoveAndDelete(Task* task); 58 static status_t _DoTask(void* data); 59 static void _AppendErrorDetails(BString& details, 60 JobStateListener* listener); 61 62 BObjectList<Task> fTaskQueue; 63 BMessenger fReplyTarget; 64 BMessenger fMessenger; 65 }; 66 67 68 #endif 69