1 | // |
2 | // ThreadTarget.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Threading |
6 | // Module: ThreadTarget |
7 | // |
8 | // Definition of the ThreadTarget class. |
9 | // |
10 | // Copyright (c) 2008, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_ThreadTarget_INCLUDED |
18 | #define Foundation_ThreadTarget_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include "Poco/Runnable.h" |
23 | |
24 | |
25 | namespace Poco { |
26 | |
27 | |
28 | class Foundation_API ThreadTarget: public Runnable |
29 | /// This adapter simplifies using static member functions as well as |
30 | /// standalone functions as targets for threads. |
31 | /// Note that it is possible to pass those entities directly to Thread::start(). |
32 | /// This adapter is provided as a convenience for higher abstraction level |
33 | /// scenarios where Runnable abstract class is used. |
34 | /// |
35 | /// For using a non-static member function as a thread target, please |
36 | /// see the RunnableAdapter class. |
37 | /// |
38 | /// Usage: |
39 | /// class MyObject |
40 | /// { |
41 | /// static void doSomething() {} |
42 | /// }; |
43 | /// ThreadTarget ra(&MyObject::doSomething); |
44 | /// Thread thr; |
45 | /// thr.start(ra); |
46 | /// |
47 | /// or: |
48 | /// |
49 | /// void doSomething() {} |
50 | /// |
51 | /// ThreadTarget ra(doSomething); |
52 | /// Thread thr; |
53 | /// thr.start(ra); |
54 | { |
55 | public: |
56 | typedef void (*Callback)(); |
57 | |
58 | ThreadTarget(Callback method); |
59 | |
60 | ThreadTarget(const ThreadTarget& te); |
61 | |
62 | ~ThreadTarget(); |
63 | |
64 | ThreadTarget& operator = (const ThreadTarget& te); |
65 | |
66 | void run(); |
67 | |
68 | private: |
69 | ThreadTarget(); |
70 | |
71 | Callback _method; |
72 | }; |
73 | |
74 | |
75 | // |
76 | // inlines |
77 | // |
78 | inline void ThreadTarget::run() |
79 | { |
80 | _method(); |
81 | } |
82 | |
83 | |
84 | } // namespace Poco |
85 | |
86 | |
87 | #endif // Foundation_ThreadTarget_INCLUDED |
88 | |