forked from solidoss/solidframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.hpp
135 lines (98 loc) · 3.03 KB
/
manager.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
// solid/frame/manager.hpp
//
// Copyright (c) 2013 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_MANAGER_HPP
#define SOLID_FRAME_MANAGER_HPP
#include <mutex>
#include "solid/frame/common.hpp"
#include "solid/system/error.hpp"
#include "solid/utility/dynamicpointer.hpp"
#include "solid/system/function.hpp"
#include "solid/frame/schedulerbase.hpp"
//#include "solid/utility/functor.hpp"
namespace solid{
struct Event;
namespace frame{
class Manager;
class Service;
class ObjectBase;
class SchedulerBase;
class ReactorBase;
struct ServiceStub;
class Manager{
public:
Manager(
const size_t _svcmtxcnt = 0,
const size_t _objmtxcnt = 0,
const size_t _objbucketsize = 0
);
virtual ~Manager();
void stop();
bool notify(ObjectIdT const &_ruid, Event &&_uevt, const size_t _sigmsk = 0);
//bool notifyAll(Event const &_revt, const size_t _sigmsk = 0);
template <class F>
bool visit(ObjectIdT const &_ruid, F _f){
ObjectVisitFunctionT fct(_f);
return doVisit(_ruid, fct);
}
ObjectIdT id(const ObjectBase &_robj)const;
Service& service(const ObjectBase &_robj)const;
protected:
size_t serviceCount()const;
private:
friend class Service;
friend class ObjectBase;
friend class ReactorBase;
friend class SchedulerBase;
typedef FUNCTION<bool(ObjectBase&, ReactorBase&)> ObjectVisitFunctionT;
static bool notify_object(
ObjectBase &_robj, ReactorBase &_rreact,
Event const &_revt, const size_t _sigmsk
);
static bool notify_object(
ObjectBase &_robj, ReactorBase &_rreact,
Event &&_uevt, const size_t _sigmsk
);
bool registerService(Service &_rsvc);
void unregisterService(Service &_rsvc);
void unregisterObject(ObjectBase &_robj);
bool disableObjectVisits(ObjectBase &_robj);
ObjectIdT unsafeId(const ObjectBase &_robj)const;
std::mutex& mutex(const Service &_rsvc)const;
std::mutex& mutex(const ObjectBase &_robj)const;
ObjectIdT registerObject(
const Service &_rsvc,
ObjectBase &_robj,
ReactorBase &_rr,
ScheduleFunctionT &_rfct,
ErrorConditionT &_rerr
);
size_t notifyAll(const Service &_rsvc, Event const & _revt, const size_t _sigmsk);
template <typename F>
size_t forEachServiceObject(const Service &_rsvc, F _f){
ObjectVisitFunctionT fct(_f);
return doForEachServiceObject(_rsvc, fct);
}
bool raise(const ObjectBase &_robj, Event const &_re);
void stopService(Service &_rsvc, bool _wait);
bool startService(Service &_rsvc);
size_t doForEachServiceObject(const Service &_rsvc, ObjectVisitFunctionT &_rfct);
size_t doForEachServiceObject(const size_t _chkidx, ObjectVisitFunctionT &_rfct);
bool doVisit(ObjectIdT const &_ruid, ObjectVisitFunctionT &_fctor);
void doUnregisterService(ServiceStub &_rss);
private:
struct Data;
Data &d;
};
#ifndef SOLID_HAS_NO_INLINES
#include "solid/frame/manager.ipp"
#endif
}//namespace frame
}//namespace solid
#endif