fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Cluster / Base / OSGRemoteAspect.h
blobd4fea340f1d509333b844cb8a07f6e462f258901
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _REMOTEASPECT_H_
40 #define _REMOTEASPECT_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include <map>
46 #include <set>
47 #include <boost/function.hpp>
49 #include "OSGClusterDef.h"
50 #include "OSGStatElemTypes.h"
51 #include "OSGFieldContainerFactory.h"
53 OSG_BEGIN_NAMESPACE
55 class Connection;
56 class ChangeList;
57 class StatCollector;
59 /*! \ingroup GrpClusterBase
60 \ingroup GrpLibOSGCluster
63 class OSG_CLUSTER_DLLMAPPING RemoteAspect
65 /*========================== PUBLIC =================================*/
67 public:
69 /** Message types */
71 enum DataTypes
73 SYNCENDED = 1,
74 CREATED = 2,
75 DESTROYED = 3,
76 NEWTYPE = 4,
77 CHANGED = 5,
78 ADDREFED = 6,
79 SUBREFED = 7,
80 IDMAPPING = 8
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;
97 /** id set **/
98 typedef std::set<UInt32> IdSetT;
100 /*---------------------------------------------------------------------*/
101 /*! \name Constants */
102 /*! \{ */
104 static StatElemDesc<StatTimeElem> statSyncTime;
106 /*! \} */
107 /*---------------------------------------------------------------------*/
108 /*! \name Constructors */
109 /*! \{ */
111 RemoteAspect(UInt32 aspectId = 0);
112 virtual ~RemoteAspect(void);
114 /*! \} */
115 /*---------------------------------------------------------------------*/
116 /*! \name Remote aspect functionaliy */
117 /*! \{ */
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 );
130 /*! \} */
131 /*---------------------------------------------------------------------*/
132 /*! \name Static Remote aspect functionaliy */
133 /*! \{ */
135 static void addFieldFilter(UInt32 typeId,BitVector mask);
136 static void subFieldFilter(UInt32 typeId,BitVector mask);
138 /*! \} */
139 /*---------------------------------------------------------------------*/
140 /*! \name Statistics */
141 /*! \{ */
143 void setStatistics(StatCollector *stat);
145 /*! \} */
146 /*========================= PROTECTED ===============================*/
148 protected:
150 typedef std::map<UInt32, BitVector> FieldFilter;
151 typedef std::vector<FieldContainerUnrecPtr> FieldContainerVector;
153 /*---------------------------------------------------------------------*/
154 /*! \name member */
155 /*! \{ */
157 /** Aspect id **/
158 UInt32 _aspectId;
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 **/
168 IdSetT _sentFC;
169 /** indicates fc was received **/
170 IdSetT _receivedFC;
172 /** indicates remote knows this fc **/
173 IdSetT _mappedFC;
174 /** indicates mapped type **/
175 IdSetT _mappedType;
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;
186 /*! \} */
187 /*---------------------------------------------------------------------*/
188 /*! \name protected helper functions */
189 /*! \{ */
191 bool callCreated (FieldContainer * const node);
192 bool callDestroyed(FieldContainer * const node);
193 bool callChanged (FieldContainer * const node);
195 /*! \} */
197 /*========================== PRIVATE ================================*/
199 private:
201 /*---------------------------------------------------------------------*/
202 /*! \name Receive Helper functions */
203 /*! \{ */
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 );
220 /*! \} */
221 /*---------------------------------------------------------------------*/
222 /*! \name Send Helper functions */
223 /*! \{ */
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,
232 UInt32 localId );
233 void sendSubRefed (Connection &con,
234 FieldContainer *fcPtr,
235 UInt32 localId );
236 void sendIdMapping(Connection &con );
238 /*! \} */
239 /*---------------------------------------------------------------------*/
240 /*! \name Helper functions */
241 /*! \{ */
243 void clearFCMapping (UInt32 localId,
244 UInt32 remoteId );
245 bool getLocalId (UInt32 remoteId,
246 UInt32 &localId );
247 UInt64 getFullRemoteId (UInt32 remoteId );
249 /*! \} */
250 /*---------------------------------------------------------------------*/
251 /*! \name static elements */
252 /*! \{ */
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);
261 /*! \} */
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);
272 // class pointer
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) {}
287 private:
289 RemoteAspectFieldContainerMapper(
290 const RemoteAspectFieldContainerMapper &other);
292 void operator =(const RemoteAspectFieldContainerMapper &other);
295 OSG_END_NAMESPACE
297 #endif /* _REMOTEASPECT_H_ */