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 136 : ObjectInstanceDataOStream::ObjectInstanceDataOStream( const ObjectCM* cm )
35 : : ObjectDataOStream( cm )
36 : , _instanceID( CO_INSTANCE_ALL )
37 136 : , _command( 0 )
38 136 : {}
39 :
40 136 : ObjectInstanceDataOStream::~ObjectInstanceDataOStream()
41 136 : {}
42 :
43 122 : void ObjectInstanceDataOStream::reset()
44 : {
45 122 : ObjectDataOStream::reset();
46 122 : _nodeID = 0;
47 122 : _instanceID = CO_INSTANCE_NONE;
48 122 : _command = 0;
49 122 : }
50 :
51 122 : void ObjectInstanceDataOStream::enableCommit( const uint128_t& version,
52 : const Nodes& receivers )
53 : {
54 122 : _command = CMD_NODE_OBJECT_INSTANCE_COMMIT;
55 122 : _nodeID = 0;
56 122 : _instanceID = CO_INSTANCE_NONE;
57 122 : ObjectDataOStream::enableCommit( version, receivers );
58 122 : }
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 4 : 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 2 : void ObjectInstanceDataOStream::push( const Nodes& receivers,
81 : const uint128_t& objectID,
82 : const uint128_t& groupID,
83 : const uint128_t& typeID )
84 : {
85 2 : _command = CMD_NODE_OBJECT_INSTANCE_PUSH;
86 2 : _nodeID = 0;
87 2 : _instanceID = CO_INSTANCE_NONE;
88 2 : _setupConnections( receivers );
89 :
90 2 : _resend();
91 2 : OCommand( getConnections(), CMD_NODE_OBJECT_PUSH )
92 2 : << objectID << groupID << typeID;
93 :
94 2 : _clearConnections();
95 2 : }
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 29 : void ObjectInstanceDataOStream::sendMapData( NodePtr node,
120 : const uint32_t instanceID )
121 : {
122 29 : _command = CMD_NODE_OBJECT_INSTANCE_MAP;
123 29 : _nodeID = node->getNodeID();
124 29 : _instanceID = instanceID;
125 29 : _setupConnection( node, true /* useMulticast */ );
126 29 : _resend();
127 29 : _clearConnections();
128 29 : }
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 54 : void ObjectInstanceDataOStream::sendData( const void* data,
143 : const uint64_t size, const bool last )
144 : {
145 54 : LBASSERT( _command );
146 : send( _command, COMMANDTYPE_NODE, _instanceID, data, size, last )
147 54 : << _nodeID << _cm->getObject()->getInstanceID();
148 54 : }
149 :
150 60 : }
|