Collage  1.0.1
Object-Oriented C++ Network Library
barrier.h
1 
2 /* Copyright (c) 2006-2012, 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 
32  class Barrier : public Object
33  {
34  public:
51  CO_API Barrier( NodePtr master = 0, const uint32_t height = 0 );
52 
54  CO_API virtual ~Barrier();
55 
64  CO_API void setHeight( const uint32_t height );
65 
67  CO_API void increase();
68 
70  CO_API uint32_t getHeight() const;
72 
83  CO_API void enter( const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
85 
86  protected:
89  virtual void attach( const UUID& id, const uint32_t instanceID );
90 
91  virtual ChangeType getChangeType() const { return DELTA; }
92 
93  virtual void getInstanceData( DataOStream& os );
94  virtual void applyInstanceData( DataIStream& is );
95  virtual void pack( DataOStream& os );
96  virtual void unpack( DataIStream& is );
98 
99  private:
100  detail::Barrier* const _impl;
101 
102  void _cleanup( const uint64_t time );
103  void _sendNotify( const uint128_t& version, NodePtr node );
104 
105  /* The command handlers. */
106  bool _cmdEnter( ICommand& command );
107  bool _cmdEnterReply( ICommand& command );
108 
109  LB_TS_VAR( _thread );
110  };
111 }
112 
113 #endif // CO_BARRIER_H
CO_API uint32_t getHeight() const
virtual CO_API ~Barrier()
Destruct the barrier.
A networked, versioned barrier.
Definition: barrier.h:32
virtual void pack(DataOStream &os)
Serialize the modifications since the last call to commit().
A class managing received commands.
Definition: iCommand.h:43
virtual void getInstanceData(DataOStream &os)
Serialize all instance information of this distributed object.
CO_API void setHeight(const uint32_t height)
Set the number of participants in the barrier.
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:49
CO_API Barrier(NodePtr master=0, const uint32_t height=0)
Construct a new barrier.
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:80
use pack/unpack delta
Definition: object.h:54
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:40
CO_API void enter(const uint32_t timeout=LB_TIMEOUT_INDEFINITE)
Enter the barrier, blocks until the barrier has been reached.
virtual void unpack(DataIStream &is)
Deserialize a change.
virtual void applyInstanceData(DataIStream &is)
Deserialize the instance data.
A distributed object.
Definition: object.h:45
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:46
CO_API void increase()
Add one participant to the barrier.
virtual ChangeType getChangeType() const
Definition: barrier.h:91