-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathactorbase.hpp
92 lines (69 loc) · 1.75 KB
/
actorbase.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
// solid/frame/actorbase.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 <vector>
#include "solid/frame/common.hpp"
#include <atomic>
#include <memory>
namespace solid {
namespace frame {
class Manager;
class Service;
class ReactorBase;
class Actor;
class CompletionHandler;
class ActorBase : public std::enable_shared_from_this<ActorBase>, NonCopyable {
public:
//! Get the id of the actor
IndexT id() const;
//! Virtual destructor
virtual ~ActorBase();
UniqueId const& runId() const;
protected:
friend class Service;
friend class Manager;
friend class ReactorBase;
//! Constructor
ActorBase();
void unregister(Manager& _rm);
bool isRegistered() const;
virtual void onStop(Manager& _rm);
bool disableVisits(Manager& _rm);
private:
void id(const IndexT& _fullid);
void runId(UniqueId const& _runid);
void prepareSpecific();
void stop(Manager& _rm);
private:
std::atomic<IndexT> fullid;
UniqueId runid;
};
inline IndexT ActorBase::id() const
{
return fullid.load(/*std::memory_order_relaxed*/);
}
inline bool ActorBase::isRegistered() const
{
return fullid.load(/*std::memory_order_relaxed*/) != InvalidIndex();
}
inline void ActorBase::id(IndexT const& _fullid)
{
fullid.store(_fullid /*, std::memory_order_relaxed*/);
}
inline UniqueId const& ActorBase::runId() const
{
return runid;
}
inline void ActorBase::runId(UniqueId const& _runid)
{
runid = _runid;
}
} // namespace frame
} // namespace solid