Collage  1.6.0
High-performance C++ library for developing object-oriented distributed applications.
barrier.h
1 
2 /* Copyright (c) 2006-2014, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2011, Cedric Stalder <cedric.stalder@gmail.com>
4  *
5  * This file is part of Collage <https://github.com/Eyescale/Collage>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 2.1 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef CO_BARRIER_H
22 #define CO_BARRIER_H
23 
24 #include <co/object.h> // base class
25 #include <co/types.h>
26 
27 namespace co
28 {
29 namespace detail { class Barrier; }
30 
38 class Barrier : public Object
39 {
40 public:
65  CO_API Barrier( LocalNodePtr localNode, const uint128_t& masterNodeID,
66  const uint32_t height = 0 );
67 
76  CO_API Barrier( LocalNodePtr localNode, const ObjectVersion& barrier );
77 
79  CO_API virtual ~Barrier();
80 
89  bool isGood() const { return isAttached(); }
90 
92  CO_API void setHeight( const uint32_t height );
93 
95  CO_API void increase();
96 
98  CO_API uint32_t getHeight() const;
100 
112  CO_API bool enter( const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
114 
115 protected:
118  void attach( const uint128_t& id, const uint32_t instanceID ) override;
119  ChangeType getChangeType() const override { return DELTA; }
120 
121  void getInstanceData( DataOStream& os ) override;
122  void applyInstanceData( DataIStream& is ) override;
123  void pack( DataOStream& os ) override;
124  void unpack( DataIStream& is ) override;
126 
127 private:
128  detail::Barrier* const _impl;
129 
130  void _cleanup( const uint64_t time );
131  void _sendNotify( const uint128_t& version, NodePtr node );
132 
133  /* The command handlers. */
134  bool _cmdEnter( ICommand& command );
135  bool _cmdEnterReply( ICommand& command );
136 
137  LB_TS_VAR( _thread );
138 };
139 }
140 
141 #endif // CO_BARRIER_H
A distributed object.
Definition: object.h:45
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
Definition: types.h:90
A helper struct bundling an object identifier and version.
Definition: objectVersion.h:47
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:49
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:86
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:48
Object-oriented network library.
Definition: barrier.h:27
A class managing received commands.
Definition: iCommand.h:43
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:41
ChangeType getChangeType() const override
Definition: barrier.h:119
A networked, versioned barrier.
Definition: barrier.h:38
bool isGood() const
Definition: barrier.h:89