1//
2// Activity.cpp
3//
4// This sample demonstrates the Activity class.
5//
6// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
7// and Contributors.
8//
9// SPDX-License-Identifier: BSL-1.0
10//
11
12
13#include "Poco/Activity.h"
14#include "Poco/Thread.h"
15#include <iostream>
16
17
18using Poco::Activity;
19using Poco::Thread;
20
21
22class ActivityExample
23{
24public:
25 ActivityExample():
26 _activity(this, &ActivityExample::runActivity)
27 {
28 }
29
30 void start()
31 {
32 _activity.start();
33 }
34
35 void stop()
36 {
37 _activity.stop();
38 _activity.wait();
39 }
40
41protected:
42 void runActivity()
43 {
44 while (!_activity.isStopped())
45 {
46 std::cout << "Activity running." << std::endl;
47 Thread::sleep(250);
48 }
49 std::cout << "Activity stopped." << std::endl;
50 }
51
52private:
53 Activity<ActivityExample> _activity;
54};
55
56
57int main(int argc, char** argv)
58{
59 ActivityExample example;
60 example.start();
61 Thread::sleep(2000);
62 example.stop();
63
64 example.start();
65 example.stop();
66
67 return 0;
68}
69