Collage  1.7.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
30 {
31 class Barrier;
32 }
33 
41 class Barrier : public Object
42 {
43 public:
68  CO_API Barrier(LocalNodePtr localNode, const uint128_t& masterNodeID,
69  const uint32_t height = 0);
70 
79  CO_API Barrier(LocalNodePtr localNode, const ObjectVersion& barrier);
80 
82  CO_API virtual ~Barrier();
83 
92  bool isGood() const { return isAttached(); }
94  CO_API void setHeight(const uint32_t height);
95 
97  CO_API void increase();
98 
100  CO_API uint32_t getHeight() const;
102 
114  CO_API bool enter(const uint32_t timeout = LB_TIMEOUT_INDEFINITE);
116 
117 protected:
120  void attach(const uint128_t& id, const uint32_t instanceID) override;
121  ChangeType getChangeType() const override { return DELTA; }
122  void getInstanceData(DataOStream& os) override;
123  void applyInstanceData(DataIStream& is) override;
124  void pack(DataOStream& os) override;
125  void unpack(DataIStream& is) override;
127 
128 private:
129  detail::Barrier* const _impl;
130 
131  void _cleanup(const uint64_t time);
132  void _sendNotify(const uint128_t& version, NodePtr node);
133 
134  /* The command handlers. */
135  bool _cmdEnter(ICommand& command);
136  bool _cmdEnterReply(ICommand& command);
137 
138  LB_TS_VAR(_thread);
139 };
140 }
141 
142 #endif // CO_BARRIER_H
A distributed object.
Definition: object.h:47
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
Definition: types.h:89
A helper struct bundling an object identifier and version.
Definition: objectVersion.h:46
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:51
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:56
Object-oriented network library.
Definition: barrier.h:27
A class managing received commands.
Definition: iCommand.h:45
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:45
ChangeType getChangeType() const override
Definition: barrier.h:121
A networked, versioned barrier.
Definition: barrier.h:41
bool isGood() const
Definition: barrier.h:92
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:85