-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaioreactorcontext.hpp
142 lines (114 loc) · 2.99 KB
/
aioreactorcontext.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// solid/frame/aio/aioreactorcontext.hpp
//
// Copyright (c) 2014 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/aio/aiocommon.hpp"
#include "solid/frame/service.hpp"
#include <mutex>
namespace solid {
namespace frame {
class Service;
class Manager;
namespace aio {
class Actor;
namespace impl {
class Reactor;
} // namespace impl
class CompletionHandler;
class ReactorContext : NonCopyable {
friend class CompletionHandler;
friend class impl::Reactor;
friend class Actor;
friend class SocketBase;
impl::Reactor& rreactor_;
const NanoTime& rcurrent_time_;
size_t completion_heandler_index_;
size_t actor_index_;
ReactorEventE reactor_event_;
ErrorCodeT system_error_;
ErrorConditionT error_;
public:
~ReactorContext()
{
}
const NanoTime& nanoTime() 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();
}
private:
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;
}
UniqueId actorUid() const;
ReactorContext(const ReactorContext& _rother)
: rreactor_(_rother.rreactor_)
, rcurrent_time_(_rother.rcurrent_time_)
, completion_heandler_index_(_rother.completion_heandler_index_)
, actor_index_(_rother.actor_index_)
, reactor_event_(_rother.reactor_event_)
{
}
ReactorContext(
impl::Reactor& _rreactor,
const NanoTime& _rcurrent_time)
: rreactor_(_rreactor)
, rcurrent_time_(_rcurrent_time)
, completion_heandler_index_(InvalidIndex())
, actor_index_(InvalidIndex())
, reactor_event_(ReactorEventE::None)
{
}
};
} // namespace aio
} // namespace frame
} // namespace solid