-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
StoppableSGObject.cpp
79 lines (67 loc) · 1.72 KB
/
StoppableSGObject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* This software is distributed under BSD 3-clause license (see LICENSE file).
*
* Authors: Shubham Shukla
*/
#include <rxcpp/rx-lite.hpp>
#include <shogun/base/init.h>
#include <shogun/lib/Signal.h>
#include <shogun/lib/StoppableSGObject.h>
using namespace shogun;
#define COMPUTATION_CONTROLLERS \
if (cancel_computation()) \
continue; \
pause_computation();
CStoppableSGObject::CStoppableSGObject() : CSGObject()
{
m_cancel_computation = false;
m_pause_computation_flag = false;
m_callback = nullptr;
};
CStoppableSGObject::~CStoppableSGObject(){};
rxcpp::subscription CStoppableSGObject::connect_to_signal_handler()
{
// Subscribe this algorithm to the signal handler
auto subscriber = rxcpp::make_subscriber<int>(
[this](int i) {
if (i == SG_PAUSE_COMP)
this->on_pause();
else
this->on_next();
},
[this]() { this->on_complete(); });
return get_global_signal()->get_observable()->subscribe(subscriber);
}
void CStoppableSGObject::set_callback(std::function<bool()> callback)
{
m_callback = callback;
}
void CStoppableSGObject::reset_computation_variables()
{
m_cancel_computation = false;
m_pause_computation_flag = false;
}
void CStoppableSGObject::on_next()
{
m_cancel_computation.store(true);
on_next_impl();
}
void CStoppableSGObject::on_pause()
{
m_pause_computation_flag.store(true);
on_pause_impl();
resume_computation();
}
void CStoppableSGObject::on_complete()
{
on_complete_impl();
}
void CStoppableSGObject::on_next_impl()
{
}
void CStoppableSGObject::on_pause_impl()
{
}
void CStoppableSGObject::on_complete_impl()
{
}