1 | /** @file
|
---|
2 | * VirtualBox ThreadTask class definition
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2015-2022 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef MAIN_INCLUDED_ThreadTask_h
|
---|
18 | #define MAIN_INCLUDED_ThreadTask_h
|
---|
19 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
20 | # pragma once
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | #include "VBox/com/string.h"
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * The class ThreadVoidData is used as a base class for any data which we want to pass into a thread
|
---|
27 | */
|
---|
28 | struct ThreadVoidData
|
---|
29 | {
|
---|
30 | public:
|
---|
31 | ThreadVoidData() { }
|
---|
32 | virtual ~ThreadVoidData() { }
|
---|
33 | };
|
---|
34 |
|
---|
35 |
|
---|
36 | class ThreadTask
|
---|
37 | {
|
---|
38 | public:
|
---|
39 | ThreadTask(const Utf8Str &t)
|
---|
40 | : m_strTaskName(t)
|
---|
41 | , mAsync(false)
|
---|
42 | { }
|
---|
43 |
|
---|
44 | virtual ~ThreadTask()
|
---|
45 | { }
|
---|
46 |
|
---|
47 | HRESULT createThread(void);
|
---|
48 | HRESULT createThreadWithType(RTTHREADTYPE enmType);
|
---|
49 |
|
---|
50 | inline Utf8Str getTaskName() const { return m_strTaskName; }
|
---|
51 | bool isAsync() { return mAsync; }
|
---|
52 |
|
---|
53 | protected:
|
---|
54 | HRESULT createThreadInternal(RTTHREADTYPE enmType);
|
---|
55 | static DECLCALLBACK(int) taskHandlerThreadProc(RTTHREAD thread, void *pvUser);
|
---|
56 |
|
---|
57 | ThreadTask() : m_strTaskName("GenericTask")
|
---|
58 | { }
|
---|
59 |
|
---|
60 | Utf8Str m_strTaskName;
|
---|
61 | bool mAsync;
|
---|
62 |
|
---|
63 | private:
|
---|
64 | virtual void handler() = 0;
|
---|
65 | };
|
---|
66 |
|
---|
67 | #endif /* !MAIN_INCLUDED_ThreadTask_h */
|
---|
68 |
|
---|