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 TASKTIMER_H
9#define TASKTIMER_H
10
11
12#include <Alert.h>
13#include <Invoker.h>
14#include <Looper.h>
15#include <Message.h>
16#include <MessageRunner.h>
17#include <Messenger.h>
18#include <String.h>
19
20#include "RepoRow.h"
21
22class TaskTimer;
23class TaskLooper;
24
25
26typedef struct {
27		RepoRow*		rowItem;
28		int32			taskType;
29		BString			name, taskParam;
30		thread_id		threadId;
31		TaskLooper*		owner;
32		BString			resultName, resultErrorDetails;
33		TaskTimer*		fTimer;
34} Task;
35
36
37class TaskTimer : public BLooper {
38public:
39							TaskTimer(const BMessenger& target, Task* owner);
40							~TaskTimer();
41	virtual bool			QuitRequested();
42	virtual void			MessageReceived(BMessage*);
43	void					Start(const char* name);
44	void					Stop(const char* name);
45
46private:
47	int32					_NextAlertStackCount();
48
49	int32					fTimeoutMicroSeconds;
50	bool					fTimerIsRunning;
51	BString					fRepositoryName;
52	BMessenger				fReplyTarget;
53	BMessenger				fMessenger;
54	BMessageRunner*			fMessageRunner;
55	BMessage				fTimeoutMessage;
56	BAlert*					fTimeoutAlert;
57	BInvoker				fTimeoutAlertInvoker;
58	Task*					fOwner;
59};
60
61
62#endif
63