-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreactorcontext.hpp
121 lines (99 loc) · 2.52 KB
/
reactorcontext.hpp
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// solid/frame/aio/reactorcontext.hpp
//
// Copyright (c) 2015 Valentin Palade (vipalade @ gmail . com)
//
// This file is part of SolidFrame framework.
//
// 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 "solid/system/common.hpp"
#include "solid/system/error.hpp"
#include "solid/system/nanotime.hpp"
#include "solid/system/socketdevice.hpp"
#include "solid/frame/service.hpp"
#include <mutex>
namespace solid {
namespace frame {
class Actor;
namespace impl {
class Reactor;
} // namespace impl
class CompletionHandler;
class ReactorContext : NonCopyable {
friend class CompletionHandler;
friend class impl::Reactor;
friend class Actor;
impl::Reactor& rreactor_;
const NanoTime& rcurrent_time_;
size_t completion_heandler_index_;
size_t actor_index_;
ReactorEventE reactor_event_;
ErrorCodeT system_error_;
ErrorConditionT error_;
ReactorContext(
impl::Reactor& _rreactor,
const NanoTime& _rcrttm)
: rreactor_(_rreactor)
, rcurrent_time_(_rcrttm)
, completion_heandler_index_(InvalidIndex())
, actor_index_(InvalidIndex())
, reactor_event_(ReactorEventE::None)
{
}
impl::Reactor& reactor()
{
return rreactor_;
}
impl::Reactor const& reactor() const
{
return rreactor_;
}
ReactorEventE reactorEvent() const
{
return reactor_event_;
}
CompletionHandler* completionHandler() const;
void error(ErrorConditionT const& _err)
{
error_ = _err;
}
void systemError(ErrorCodeT const& _err)
{
system_error_ = _err;
}
public:
~ReactorContext()
{
}
UniqueId actorUid() const;
const NanoTime& currentTime() const
{
return rcurrent_time_;
}
std::chrono::steady_clock::time_point steadyTime() const
{
return rcurrent_time_.timePointCast<std::chrono::steady_clock::time_point>();
}
ErrorCodeT const& systemError() const
{
return system_error_;
}
ErrorConditionT const& error() const
{
return error_;
}
Actor& actor() const;
Service& service() const;
Manager& manager() const;
ActorIdT actorId() const;
Service::ActorMutexT& actorMutex() const;
void clearError()
{
error_.clear();
system_error_.clear();
}
};
} // namespace frame
} // namespace solid