00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef _REMOTEASPECT_H_
00041 #define _REMOTEASPECT_H_
00042 #ifdef __sgi
00043 #pragma once
00044 #endif
00045
00046 #include <map>
00047 #include <set>
00048 #include <OSGSystemDef.h>
00049 #include <OSGBaseTypes.h>
00050 #include <OSGFieldContainerPtr.h>
00051 #include <OSGFieldContainerFactory.h>
00052 #include <OSGChangeList.h>
00053 #include <OSGConnection.h>
00054 #include <OSGTypedFunctors.h>
00055 #include <OSGStatCollector.h>
00056 #include <OSGStatElemTypes.h>
00057
00058 OSG_BEGIN_NAMESPACE
00059
00060 class OSG_SYSTEMLIB_DLLMAPPING RemoteAspect
00061 {
00062
00063 public:
00065 enum DataTypes
00066 {
00067 SYNCENDED =1,
00068 CREATED =2,
00069 DESTROYED =3,
00070 NEWTYPE =4,
00071 CHANGED =5,
00072 ADDREFED =6,
00073 SUBREFED =7,
00074 IDMAPPING =8
00075 };
00076
00078 typedef ArgsCollector<RemoteAspect *> FunctorArgs;
00079 typedef TypedFunctor2Base<bool,
00080 CPtrRefCallArg<FieldContainerPtr>,
00081 FunctorArgs > Functor;
00082
00084 typedef std::map<UInt64,UInt32> LocalFCMapT;
00086 typedef std::map<UInt32,UInt64> RemoteFCMapT;
00088 typedef std::map<UInt32,UInt32> LocalTypeMapT;
00089
00091 typedef std::set<UInt32> IdSetT;
00092
00094 typedef std::map<UInt32,BitVector> FieldFilterT;
00095 typedef std::map<UInt32,BitVector> FieldMaskMapT;
00096
00097
00101 RemoteAspect(UInt32 aspectId=0);
00102 virtual ~RemoteAspect(void);
00103
00105
00109 void receiveSync ( Connection &connection,
00110 bool applyToChangelist=false );
00111 void sendSync ( Connection &connection,
00112 ChangeList *changeList=NULL );
00113 void registerCreated ( const FieldContainerType &type,
00114 const Functor &func );
00115 void registerDestroyed( const FieldContainerType &type,
00116 const Functor &func );
00117 void registerChanged ( const FieldContainerType &type,
00118 const Functor &func );
00119 static void addFieldFilter ( UInt32 typeId,BitVector mask );
00120 static void subFieldFilter ( UInt32 typeId,BitVector mask );
00121
00122 static void restoreChangeList (ChangeList *tocl);
00123 static void storeChangeList (ChangeList *cl );
00124 static UInt32 getStoreSize (void );
00125
00126 typedef std::map<UInt32, UInt32> clStoreMap;
00127 typedef clStoreMap::iterator clStoreIt;
00128 static clStoreMap &getStore (void );
00129
00130 static void createCurrentStateChangeList(const FieldContainerPtr &start,
00131 ChangeList *cl);
00132
00134
00138 void setStatistics( StatCollector * stat );
00139
00142
00143 protected:
00144
00149 UInt32 _aspectId;
00150
00152 LocalFCMapT _localFC;
00154 RemoteFCMapT _remoteFC;
00156 LocalTypeMapT _localType;
00157
00159 IdSetT _sentFC;
00161 IdSetT _receivedFC;
00162
00164 IdSetT _mappedFC;
00166 IdSetT _mappedType;
00167
00168 UInt32 _remoteAspectId;
00169
00170 #if 0
00171
00172 std::map<UInt32,BitVector> _sentFC;
00173 #endif
00174
00176 static FieldFilterT _fieldFilter;
00177 std::vector<Functor> _createdFunctors;
00178 std::vector<Functor> _destroyedFunctors;
00179 std::vector<Functor> _changedFunctors;
00180 StatCollector *_statistics;
00181
00182 static std::map<UInt32, UInt32> _clStore;
00183
00185
00189 bool callCreated ( FieldContainerPtr &node );
00190 bool callDestroyed ( FieldContainerPtr &node );
00191 bool callChanged ( FieldContainerPtr &node );
00192
00195
00196 private:
00197
00201 void handleFCMapping (Connection &connection );
00202 void clearFCMapping (UInt32 localId,UInt32 remoteId );
00203 bool getLocalId (UInt32 remoteId,
00204 UInt32 &localId );
00205 UInt64 getFullRemoteId (UInt32 remoteId );
00206
00208
00211 static bool _defaultCreatedFunction (FieldContainerPtr& fcp,
00212 RemoteAspect * aspect);
00213 static bool _defaultDestroyedFunction(FieldContainerPtr& fcp,
00214 RemoteAspect * aspect);
00215 static bool _defaultChangedFunction (FieldContainerPtr& fcp,
00216 RemoteAspect * aspect);
00217
00218 static StatElemDesc<StatTimeElem> statSyncTime;
00221 friend class RemoteAspectFieldContainerMapper;
00222
00223 RemoteAspect(const RemoteAspect &source);
00224 RemoteAspect &operator =(const RemoteAspect &source);
00225 };
00226
00227
00228 typedef RemoteAspect *RemoteAspectP;
00229
00230 struct RemoteAspectFieldContainerMapper:public FieldContainerMapper
00231 {
00232 virtual UInt32 map(UInt32 uiId);
00233 RemoteAspect *_remoteAspect;
00234 };
00235
00236 OSG_END_NAMESPACE
00237
00238 #define OSGREMOTEASPECT_HEADER_CVSID "@(#)$Id:$"
00239
00240 #endif