Line data Source code
1 :
2 : /* Copyright (c) 2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #ifndef EQFABRIC_LAYOUT_H
19 : #define EQFABRIC_LAYOUT_H
20 :
21 : #include <eq/fabric/object.h> // base class
22 : #include <eq/fabric/types.h>
23 : #include <string>
24 :
25 : namespace eq
26 : {
27 : namespace fabric
28 : {
29 : /** Base data transport class for layouts. @sa eq::Layout */
30 : template< class C, class L, class V > class Layout : public Object
31 : {
32 : public:
33 : /** @name Data Access */
34 : //@{
35 : /** A vector of pointers to views. @version 1.0 */
36 : typedef std::vector< V* > Views;
37 : /** The layout visitor type. @version 1.0 */
38 : typedef ElementVisitor< L, LeafVisitor< V > > Visitor;
39 :
40 : /** @return the current config. @version 1.0 */
41 2513 : C* getConfig() { return _config; }
42 :
43 : /** @return the current config. @version 1.0 */
44 300 : const C* getConfig() const { return _config; }
45 :
46 : /** Get the list of views. @version 1.0 */
47 14891 : const Views& getViews() const { return _views; }
48 :
49 : /**
50 : * @return true if the layout is activated in at least one canvas.
51 : * @version 1.1.5
52 : */
53 : EQFABRIC_INL bool isActive() const;
54 :
55 : /** @internal @return the view of the given path. */
56 : V* getView( const ViewPath& path );
57 :
58 : /** @internal @return the first view of the given name. */
59 : V* findView( const std::string& name );
60 :
61 : /** @internal @return the index path to this layout. */
62 : LayoutPath getPath() const;
63 : //@}
64 :
65 : /** @name Operations */
66 : //@{
67 : /**
68 : * Traverse this layout and all children using a layout visitor.
69 : *
70 : * @param visitor the visitor.
71 : * @return the result of the visitor traversal.
72 : * @version 1.0
73 : */
74 : EQFABRIC_INL VisitorResult accept( Visitor& visitor );
75 :
76 : /** Const-version of accept(). @version 1.0 */
77 : EQFABRIC_INL VisitorResult accept( Visitor& visitor )
78 : const;
79 :
80 : void create( V** view ); //!< @internal
81 : void release( V* view ); //!< @internal
82 : //@}
83 :
84 : protected:
85 : /** @internal Construct a new layout. */
86 : EQFABRIC_INL Layout( C* config );
87 :
88 : /** @internal Destruct this layout. */
89 : EQFABRIC_INL virtual ~Layout();
90 :
91 : /** @internal */
92 : EQFABRIC_INL virtual void attach( const uint128_t& id,
93 : const uint32_t instanceID );
94 :
95 : /** @internal */
96 : EQFABRIC_INL virtual void serialize( co::DataOStream& os,
97 : const uint64_t dirtyBits );
98 : /** @internal */
99 : EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
100 : const uint64_t dirtyBits );
101 :
102 : EQFABRIC_INL virtual void notifyDetach(); //!< @internal
103 :
104 : /** @internal */
105 : EQFABRIC_INL virtual void setDirty( const uint64_t bits );
106 :
107 : /** @internal */
108 : enum DirtyBits
109 : {
110 : DIRTY_VIEWS = Object::DIRTY_CUSTOM << 0,
111 : DIRTY_LAYOUT_BITS = DIRTY_VIEWS | DIRTY_OBJECT_BITS
112 : };
113 :
114 : /** @internal @return the bits to be re-committed by the master. */
115 56 : virtual uint64_t getRedistributableBits() const
116 56 : { return DIRTY_LAYOUT_BITS; }
117 :
118 : private:
119 : /** The parent Config. */
120 : C* const _config;
121 :
122 : /** Child views on this layout. */
123 : Views _views;
124 :
125 : struct Private;
126 : Private* _private; // placeholder for binary-compatible changes
127 :
128 : template< class, class, class > friend class View;
129 : friend class Object;
130 : void _addChild( V* view );
131 : bool _removeChild( V* view );
132 :
133 : /** @internal */
134 : EQFABRIC_INL virtual uint128_t commit( const uint32_t incarnation );
135 :
136 : template< class O > void _removeObserver( const O* observer );
137 : template< class, class, class, class, class, class,
138 : class > friend class Config;
139 :
140 : typedef co::CommandFunc< Layout< C, L, V > > CmdFunc;
141 : bool _cmdNewView( co::ICommand& command );
142 : bool _cmdNewViewReply( co::ICommand& command );
143 : };
144 :
145 : template< class C, class L, class V >
146 : std::ostream& operator << ( std::ostream&, const Layout< C, L, V >& );
147 : }
148 : }
149 : #endif // EQFABRIC_LAYOUT_H
|