-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_sequence_base.h
58 lines (51 loc) · 1.41 KB
/
control_sequence_base.h
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
// (C) Copyright 2009-2011 Vit Kasal
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include <boost/function.hpp>
#include <boost/mpl/assert.hpp>
namespace si
{
template <typename channel_tt = void> struct control_sequence_base
{
typedef boost::function<void()> callback_type;
typedef typename channel_tt::pointer channel_type;
// BOOST_MPL_ASSERT_MSG(false, CHANNEL_TT_PARAMETER, (types<channel_tt>));
control_sequence_base(channel_type channel_ = channel_type()
, callback_type success_cb_ = callback_type()
, callback_type failure_cb_ = callback_type())
: channel(channel_)
, success_cb(success_cb_)
, failure_cb(failure_cb_)
{
}
void start(channel_type channel_
, callback_type success_cb_ = callback_type()
, callback_type failure_cb_ = callback_type())
{
channel = channel_;
success_cb = success_cb_;
failure_cb = failure_cb_;
}
void success()
{
if(success_cb)
success_cb();
channel.reset();
}
void failure()
{
if(failure_cb)
failure_cb();
channel.reset();
}
channel_type channel;
callback_type success_cb;
callback_type failure_cb;
};
template<>struct control_sequence_base<void>
{
typedef boost::function<void()> callback_type;
};
}//namespace si