1//
2// ActiveMethod.cpp
3//
4// This sample demonstrates the ActiveMethod and ActiveResult classes.
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/ActiveMethod.h"
14#include "Poco/ActiveResult.h"
15#include <iostream>
16
17
18using Poco::ActiveMethod;
19using Poco::ActiveResult;
20
21
22class ActiveMethodExample
23{
24public:
25 struct AddArgs
26 {
27 int a;
28 int b;
29 };
30
31 ActiveMethodExample():
32 activeAdd(this, &ActiveMethodExample::activeAddImp)
33 {
34 }
35
36 ActiveMethod<int, AddArgs, ActiveMethodExample> activeAdd;
37
38private:
39 int activeAddImp(const AddArgs& args)
40 {
41 return args.a + args.b;
42 }
43};
44
45
46int main(int argc, char** argv)
47{
48 ActiveMethodExample example;
49
50 ActiveMethodExample::AddArgs args = {1, 2};
51 ActiveResult<int> result = example.activeAdd(args);
52 result.wait();
53 std::cout << result.data() << std::endl;
54
55 return 0;
56}
57