1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _REMOTEASPECT_H_
40 #define _REMOTEASPECT_H_
47 #include <boost/function.hpp>
49 #include "OSGClusterDef.h"
50 #include "OSGStatElemTypes.h"
51 #include "OSGFieldContainerFactory.h"
59 /*! \ingroup GrpClusterBase
60 \ingroup GrpLibOSGCluster
63 class OSG_CLUSTER_DLLMAPPING RemoteAspect
65 /*========================== PUBLIC =================================*/
83 /** functor called for changed containers **/
84 typedef boost::function
<bool (FieldContainer
* const,
85 RemoteAspect
* )> Functor
;
88 /** Map remote to local id **/
89 typedef std::map
<UInt64
,UInt32
> LocalFCMapT
;
91 /** Map local to remote id **/
92 typedef std::map
<UInt32
,UInt64
> RemoteFCMapT
;
94 /** Map remote to local type **/
95 typedef std::map
<UInt32
,UInt32
> LocalTypeMapT
;
98 typedef std::set
<UInt32
> IdSetT
;
100 /*---------------------------------------------------------------------*/
101 /*! \name Constants */
104 static StatElemDesc
<StatTimeElem
> statSyncTime
;
107 /*---------------------------------------------------------------------*/
108 /*! \name Constructors */
111 RemoteAspect(UInt32 aspectId
= 0);
112 virtual ~RemoteAspect(void);
115 /*---------------------------------------------------------------------*/
116 /*! \name Remote aspect functionaliy */
119 void receiveSync ( Connection
&connection
,
120 bool applyToChangelist
= false);
121 void sendSync ( Connection
&connection
,
122 ChangeList
*changeList
= NULL
);
123 void registerCreated (const FieldContainerType
&type
,
124 const Functor
&func
);
125 void registerDestroyed(const FieldContainerType
&type
,
126 const Functor
&func
);
127 void registerChanged (const FieldContainerType
&type
,
128 const Functor
&func
);
131 /*---------------------------------------------------------------------*/
132 /*! \name Static Remote aspect functionaliy */
135 static void addFieldFilter(UInt32 typeId
,BitVector mask
);
136 static void subFieldFilter(UInt32 typeId
,BitVector mask
);
139 /*---------------------------------------------------------------------*/
140 /*! \name Statistics */
143 void setStatistics(StatCollector
*stat
);
146 /*========================= PROTECTED ===============================*/
150 typedef std::map
<UInt32
, BitVector
> FieldFilter
;
151 typedef std::vector
<FieldContainerUnrecPtr
> FieldContainerVector
;
153 /*---------------------------------------------------------------------*/
160 /** remote id to fieldcontainer mapping **/
161 LocalFCMapT _localFC
;
162 /** local to remote fieldcontainer mapping **/
163 RemoteFCMapT _remoteFC
;
164 /** remote typeid mapping **/
165 LocalTypeMapT _localType
;
167 /** indicates fc was sent **/
169 /** indicates fc was received **/
172 /** indicates remote knows this fc **/
174 /** indicates mapped type **/
177 UInt32 _remoteAspectId
;
179 std::vector
<Functor
> _createdFunctors
;
180 std::vector
<Functor
> _destroyedFunctors
;
181 std::vector
<Functor
> _changedFunctors
;
182 StatCollector
*_statistics
;
184 static FieldFilter _fieldFilter
;
187 /*---------------------------------------------------------------------*/
188 /*! \name protected helper functions */
191 bool callCreated (FieldContainer
* const node
);
192 bool callDestroyed(FieldContainer
* const node
);
193 bool callChanged (FieldContainer
* const node
);
197 /*========================== PRIVATE ================================*/
201 /*---------------------------------------------------------------------*/
202 /*! \name Receive Helper functions */
205 void receiveNewType (Connection
&con
,
206 FieldContainerFactoryBase
*fcFactory
);
207 void receiveCreated (Connection
&con
,
208 FieldContainerFactoryBase
*fcFactory
,
209 FieldContainerVector
&newContainers
);
210 void receiveChanged (Connection
&con
,
211 FieldContainerFactoryBase
*fcFactory
);
212 void receiveAddRefed (Connection
&con
,
213 FieldContainerFactoryBase
*fcFactory
,
214 ChangeList
*pChangeList
);
215 void receiveSubRefed (Connection
&con
,
216 FieldContainerFactoryBase
*fcFactory
,
217 ChangeList
*pChangeList
);
218 void receiveIdMapping(Connection
&con
);
221 /*---------------------------------------------------------------------*/
222 /*! \name Send Helper functions */
225 void sendCreated (Connection
&con
,
226 FieldContainer
*fcPtr
);
227 void sendChanged (Connection
&con
,
228 FieldContainer
*fcPtr
,
229 BitVector changedMask
);
230 void sendAddRefed (Connection
&con
,
231 FieldContainer
*fcPtr
,
233 void sendSubRefed (Connection
&con
,
234 FieldContainer
*fcPtr
,
236 void sendIdMapping(Connection
&con
);
239 /*---------------------------------------------------------------------*/
240 /*! \name Helper functions */
243 void clearFCMapping (UInt32 localId
,
245 bool getLocalId (UInt32 remoteId
,
247 UInt64
getFullRemoteId (UInt32 remoteId
);
250 /*---------------------------------------------------------------------*/
251 /*! \name static elements */
254 static bool _defaultCreatedFunction (FieldContainer
* const fcp
,
255 RemoteAspect
* aspect
);
256 static bool _defaultDestroyedFunction(FieldContainer
* const fcp
,
257 RemoteAspect
* aspect
);
258 static bool _defaultChangedFunction (FieldContainer
* const fcp
,
259 RemoteAspect
* aspect
);
262 /*---------------------------------------------------------------------*/
264 friend struct RemoteAspectFieldContainerMapper
;
266 // prohibit default functions (move to 'public' if you need one)
268 RemoteAspect(const RemoteAspect
&source
);
269 RemoteAspect
&operator =(const RemoteAspect
&source
);
273 typedef RemoteAspect
*RemoteAspectP
;
275 /*! \ingroup GrpClusterBase
276 \ingroup GrpLibOSGCluster
279 struct RemoteAspectFieldContainerMapper
: public ContainerIdMapper
281 virtual UInt32
map(UInt32 uiId
) const;
283 RemoteAspect
*_remoteAspect
;
285 RemoteAspectFieldContainerMapper(void) : _remoteAspect(NULL
) {}
289 RemoteAspectFieldContainerMapper(
290 const RemoteAspectFieldContainerMapper
&other
);
292 void operator =(const RemoteAspectFieldContainerMapper
&other
);
297 #endif /* _REMOTEASPECT_H_ */