forked from solidoss/solidframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objectbase.hpp
105 lines (79 loc) · 2.18 KB
/
objectbase.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
// solid/frame/objectbase.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.
//
#ifndef SOLID_FRAME_OBJECTBASE_HPP
#define SOLID_FRAME_OBJECTBASE_HPP
#include <vector>
#include "solid/frame/common.hpp"
#include "solid/utility/dynamictype.hpp"
#include "solid/utility/dynamicpointer.hpp"
#include <atomic>
namespace solid{
namespace frame{
class Manager;
class Service;
class ReactorBase;
class Object;
class CompletionHandler;
class ObjectBase: public Dynamic<ObjectBase>{
public:
//! Get the id of the object
IndexT id() const;
//! Virtual destructor
virtual ~ObjectBase();
UniqueId const& runId()const;
bool isAcceptingEvents()const;
protected:
friend class Service;
friend class Manager;
friend class ReactorBase;
//! Constructor
ObjectBase();
//! Grab the signal mask eventually leaving some bits set- CALL this inside lock!!
size_t grabSignalMask(const size_t _leave = 0);
void unregister(Manager &_rm);
bool isRegistered()const;
virtual void doStop(Manager &_rm);
bool notify(const size_t _smask);
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;
std::atomic<size_t> smask;
};
inline IndexT ObjectBase::id() const {
return fullid;
}
inline bool ObjectBase::isRegistered()const{
return fullid.load() != InvalidIndex();
}
inline void ObjectBase::id(IndexT const &_fullid){
fullid = _fullid;
}
inline UniqueId const& ObjectBase::runId()const{
return runid;
}
inline void ObjectBase::runId(UniqueId const& _runid){
runid = _runid;
}
inline size_t ObjectBase::grabSignalMask(const size_t _leave/* = 0*/){
return smask.fetch_and(_leave/*, std::memory_order_seq_cst*/);
}
inline bool ObjectBase::notify(const size_t _smask){
const size_t osm = smask.fetch_or(_smask/*, std::memory_order_seq_cst*/);
return (_smask | osm) != osm;
}
}//namespace frame
}//namespace solid
#endif