OverSim
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
PubSubSubspace.h
Go to the documentation of this file.
1
//
2
// Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3
//
4
// This program is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU General Public License
6
// as published by the Free Software Foundation; either version 2
7
// of the License, or (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
//
18
25
#ifndef __PUBSUBSUBSPACE_H_
26
#define __PUBSUBSUBSPACE_H_
27
28
#include "
PubSubSubspaceId.h
"
29
#include "
NodeHandle.h
"
30
#include "
PubSubMessage_m.h
"
31
#include <deque>
32
33
class
PubSubSubspace
34
{
35
protected
:
36
PubSubSubspaceId
spaceId
;
37
NodeHandle
responsibleNode
;
38
39
simtime_t
lastTimestamp
;
40
public
:
46
PubSubSubspace
(
PubSubSubspaceId
id
);
47
~PubSubSubspace
( );
48
49
const
PubSubSubspaceId
&
getId
() {
return
spaceId
; }
50
void
setResponsibleNode
(
NodeHandle
node ) {
responsibleNode
= node; }
51
NodeHandle
getResponsibleNode
() {
return
responsibleNode
; }
52
53
void
setTimestamp
() {
lastTimestamp
= simTime(); }
54
void
setTimestamp
( simtime_t stamp ) {
lastTimestamp
= stamp; }
55
simtime_t
getLastTimestamp
() {
return
lastTimestamp
; }
56
simtime_t
getTimeSinceLastTimestamp
() {
return
simTime() -
lastTimestamp
; }
57
friend
std::ostream&
operator<<
(std::ostream& o,
const
PubSubSubspace
& subspace);
58
};
59
60
class
PubSubSubspaceLobby
:
public
PubSubSubspace
61
{
62
public
:
63
std::list<PubSubResponsibleNodeCall*>
waitingNodes
;
64
bool
waitingForRespNode
;
65
PubSubSubspaceLobby
(
PubSubSubspaceId
id
);
66
};
67
68
class
PubSubSubspaceIntermediate
:
public
PubSubSubspace
69
{
70
public
:
71
std::set<NodeHandle>
children
;
72
PubSubSubspaceIntermediate
(
PubSubSubspaceId
id
) :
PubSubSubspace
( id ) {}
73
virtual
~PubSubSubspaceIntermediate
( ) {}
74
virtual
bool
addChild
(
NodeHandle
node ) {
return
children
.insert( node ).second; }
75
virtual
bool
removeChild
(
NodeHandle
node ) {
return
children
.erase( node ); }
76
virtual
int
getNumChildren
() {
return
children
.size(); }
77
78
friend
std::ostream&
operator<<
(std::ostream& o,
const
PubSubSubspaceIntermediate
& subspace);
79
};
80
81
class
PubSubSubspaceResponsible
:
public
PubSubSubspaceIntermediate
82
{
83
public
:
84
class
IntermediateNode
85
{
86
public
:
87
NodeHandle
node
;
88
std::set<NodeHandle>
children
;
89
unsigned
int
waitingChildren
;
90
IntermediateNode
() :
waitingChildren
(0) {}
91
};
92
std::deque<IntermediateNode>
intermediateNodes
;
93
std::map<NodeHandle,bool>
cachedChildren
;
94
95
std::deque<PubSubMoveMessage*>
waitingMoveMessages
;
96
97
static
unsigned
int
maxChildren
;
98
99
PubSubSubspaceResponsible
(
PubSubSubspaceId
id
);
100
void
setBackupNode
(
NodeHandle
b ) {
backupNode
= b; }
101
const
NodeHandle
&
getBackupNode
() {
return
backupNode
; }
102
103
void
setHeartbeatTimer
(
PubSubTimer
* t ) {
heartbeatTimer
= t; }
104
PubSubTimer
*
getHeartbeatTimer
() {
return
heartbeatTimer
; }
105
106
int
getHeartbeatFailCount
() {
return
heartbeatFailCount
; }
107
void
incHeartbeatFailCount
() { ++
heartbeatFailCount
; }
108
void
resetHeartbeatFailCount
() {
heartbeatFailCount
= 0; }
109
110
int
getTotalChildrenCount
() {
return
totalChildrenCount
; }
111
void
fixTotalChildrenCount
();
112
113
int
getNumIntermediates
() {
return
intermediateNodes
.size(); }
114
IntermediateNode*
getNextFreeIntermediate
();
115
116
virtual
bool
addChild
(
NodeHandle
node );
117
virtual
IntermediateNode*
removeAnyChild
(
NodeHandle
node );
118
protected
:
119
int
totalChildrenCount
;
120
NodeHandle
backupNode
;
121
122
PubSubTimer
*
heartbeatTimer
;
123
int
heartbeatFailCount
;
124
125
friend
std::ostream&
operator<<
(std::ostream& o,
const
PubSubSubspaceResponsible
& subspace);
126
};
127
128
#endif
src
overlay
pubsubmmog
PubSubSubspace.h
Generated on Fri Dec 7 2012 13:37:53 for OverSim by
1.8.1.2