forked from solidoss/solidframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.hpp
86 lines (69 loc) · 1.9 KB
/
object.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
// solid/frame/object.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_OBJECT_HPP
#define SOLID_FRAME_OBJECT_HPP
#include "solid/utility/event.hpp"
#include "solid/frame/objectbase.hpp"
#include "solid/frame/common.hpp"
#include "solid/frame/forwardcompletion.hpp"
#include "solid/frame/reactor.hpp"
#include "solid/frame/reactorcontext.hpp"
namespace solid{
namespace frame{
class Reactor;
struct ReactorContext;
class CompletionHandler;
class Object;
struct ObjectProxy{
Object& object()const{
return robj;
}
private:
friend class Object;
ObjectProxy(Object &_robj): robj(_robj){}
ObjectProxy(ObjectProxy const &_rd):robj(_rd.robj){}
ObjectProxy& operator=(ObjectProxy const&_rd);
private:
Object &robj;
};
class Object: public Dynamic<Object, ObjectBase>, ForwardCompletionHandler{
protected:
friend class CompletionHandler;
friend class Reactor;
//! Constructor
Object();
ObjectProxy proxy(){
return ObjectProxy(*this);
}
bool registerCompletionHandler(CompletionHandler &_rch);
void registerCompletionHandlers();
bool isRunning()const;
void postStop(ReactorContext &_rctx){
if(doPrepareStop(_rctx)){
_rctx.reactor().postObjectStop(_rctx);
}
}
template <class F>
void postStop(ReactorContext &_rctx, F _f, Event &&_revent = Event()){
if(doPrepareStop(_rctx)){
_rctx.reactor().postObjectStop(_rctx, _f, _revent);
}
}
template <class F>
void post(ReactorContext &_rctx, F _f, Event &&_revent = Event()){
_rctx.reactor().post(_rctx, _f, std::move(_revent));
}
private:
virtual void onEvent(ReactorContext &_rctx, Event &&_uevent);
bool doPrepareStop(ReactorContext &_rctx);
};
}//namespace frame
}//namespace solid
#endif