Line data Source code
1 :
2 : /* Copyright (c) 2007-2014, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2010, Cedric Stalder <cedric.stalder@gmail.com>
4 : * 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
5 : *
6 : * This file is part of Collage <https://github.com/Eyescale/Collage>
7 : *
8 : * This library is free software; you can redistribute it and/or modify it under
9 : * the terms of the GNU Lesser General Public License version 2.1 as published
10 : * by the Free Software Foundation.
11 : *
12 : * This library is distributed in the hope that it will be useful, but WITHOUT
13 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 : * details.
16 : *
17 : * You should have received a copy of the GNU Lesser General Public License
18 : * along with this library; if not, write to the Free Software Foundation, Inc.,
19 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 : */
21 :
22 : #include "objectInstanceDataOStream.h"
23 :
24 : #include "log.h"
25 : #include "nodeCommand.h"
26 : #include "object.h"
27 : #include "objectDataIStream.h"
28 : #include "objectDataOCommand.h"
29 : #include "versionedMasterCM.h"
30 :
31 :
32 : namespace co
33 : {
34 135 : ObjectInstanceDataOStream::ObjectInstanceDataOStream( const ObjectCM* cm )
35 : : ObjectDataOStream( cm )
36 : , _instanceID( CO_INSTANCE_ALL )
37 135 : , _command( 0 )
38 135 : {}
39 :
40 135 : ObjectInstanceDataOStream::~ObjectInstanceDataOStream()
41 135 : {}
42 :
43 121 : void ObjectInstanceDataOStream::reset()
44 : {
45 121 : ObjectDataOStream::reset();
46 121 : _nodeID = 0;
47 121 : _instanceID = CO_INSTANCE_NONE;
48 121 : _command = 0;
49 121 : }
50 :
51 121 : void ObjectInstanceDataOStream::enableCommit( const uint128_t& version,
52 : const Nodes& receivers )
53 : {
54 121 : _command = CMD_NODE_OBJECT_INSTANCE_COMMIT;
55 121 : _nodeID = 0;
56 121 : _instanceID = CO_INSTANCE_NONE;
57 121 : ObjectDataOStream::enableCommit( version, receivers );
58 121 : }
59 :
60 2 : void ObjectInstanceDataOStream::enablePush( const uint128_t& version,
61 : const Nodes& receivers )
62 : {
63 2 : _command = CMD_NODE_OBJECT_INSTANCE_PUSH;
64 2 : _nodeID = 0;
65 2 : _instanceID = CO_INSTANCE_NONE;
66 2 : ObjectDataOStream::enableCommit( version, receivers );
67 2 : }
68 :
69 4 : void ObjectInstanceDataOStream::enableSync( const uint128_t& version,
70 : const MasterCMCommand& command )
71 : {
72 8 : NodePtr node = command.getNode();
73 :
74 4 : _command = CMD_NODE_OBJECT_INSTANCE_SYNC;
75 4 : _nodeID = node->getNodeID();
76 4 : _instanceID = command.getRequestID(); // ugh
77 4 : ObjectDataOStream::enableCommit( version, Nodes( 1, node ));
78 4 : }
79 :
80 3 : void ObjectInstanceDataOStream::push( const Nodes& receivers,
81 : const uint128_t& objectID,
82 : const uint128_t& groupID,
83 : const uint128_t& typeID )
84 : {
85 3 : _command = CMD_NODE_OBJECT_INSTANCE_PUSH;
86 3 : _nodeID = 0;
87 3 : _instanceID = CO_INSTANCE_NONE;
88 3 : _setupConnections( receivers );
89 :
90 3 : _resend();
91 6 : OCommand( getConnections(), CMD_NODE_OBJECT_PUSH )
92 3 : << objectID << groupID << typeID;
93 :
94 3 : _clearConnections();
95 3 : }
96 :
97 0 : void ObjectInstanceDataOStream::sync( const MasterCMCommand& command )
98 : {
99 0 : NodePtr node = command.getNode();
100 :
101 0 : _command = CMD_NODE_OBJECT_INSTANCE_SYNC;
102 0 : _nodeID = node->getNodeID();
103 0 : _instanceID = command.getRequestID(); // ugh
104 0 : _setupConnections( Nodes( 1, node ));
105 0 : _resend();
106 0 : _clearConnections();
107 0 : }
108 :
109 0 : void ObjectInstanceDataOStream::sendInstanceData( const Nodes& receivers )
110 : {
111 0 : _command = CMD_NODE_OBJECT_INSTANCE;
112 0 : _nodeID = 0;
113 0 : _instanceID = CO_INSTANCE_NONE;
114 0 : _setupConnections( receivers );
115 0 : _resend();
116 0 : _clearConnections();
117 0 : }
118 :
119 30 : void ObjectInstanceDataOStream::sendMapData( NodePtr node,
120 : const uint32_t instanceID )
121 : {
122 30 : _command = CMD_NODE_OBJECT_INSTANCE_MAP;
123 30 : _nodeID = node->getNodeID();
124 30 : _instanceID = instanceID;
125 30 : _setupConnection( node, true /* useMulticast */ );
126 30 : _resend();
127 30 : _clearConnections();
128 30 : }
129 :
130 8 : void ObjectInstanceDataOStream::enableMap( const uint128_t& version,
131 : NodePtr node,
132 : const uint32_t instanceID )
133 : {
134 8 : _command = CMD_NODE_OBJECT_INSTANCE_MAP;
135 8 : _nodeID = node->getNodeID();
136 8 : _instanceID = instanceID;
137 8 : _version = version;
138 8 : _setupConnection( node, true /* useMulticast */ );
139 8 : _enable();
140 8 : }
141 :
142 57 : void ObjectInstanceDataOStream::sendData( const void* data,
143 : const uint64_t size, const bool last )
144 : {
145 57 : LBASSERT( _command );
146 114 : send( _command, COMMANDTYPE_NODE, _instanceID, data, size, last )
147 171 : << _nodeID << _cm->getObject()->getInstanceID();
148 57 : }
149 :
150 66 : }
|