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 #include <stdlib.h>
00040 #include <stdio.h>
00041
00042 #include "OSGConfig.h"
00043 #include "OSGClusterException.h"
00044 #include "OSGFieldDescription.h"
00045 #include "OSGRemoteAspect.h"
00046 #include "OSGFieldContainer.h"
00047 #include "OSGLog.h"
00048 #include "OSGGeometry.h"
00049 #include "OSGSurface.h"
00050 #include "OSGTextureChunk.h"
00051 #include "OSGCubeTextureChunk.h"
00052 #include "OSGWindow.h"
00053 #include "OSGMaterial.h"
00054 #include "OSGVertexProgramChunk.h"
00055 #include "OSGFragmentProgramChunk.h"
00056
00057 #include <map>
00058
00059 OSG_USING_NAMESPACE
00060
00073 RemoteAspect::FieldFilterT RemoteAspect::_fieldFilter;
00074 std::map<UInt32, UInt32> RemoteAspect::_clStore;
00075
00076 StatElemDesc<StatTimeElem> RemoteAspect::statSyncTime
00077 ("remoteSyncTime", "time for scenegraph distribution");
00078
00079
00080
00081
00084 RemoteAspect::RemoteAspect(UInt32 aspectId) :
00085 _aspectId(aspectId),
00086
00087 _localFC(),
00088 _remoteFC(),
00089 _localType(),
00090
00091 _sentFC(),
00092 _receivedFC(),
00093 _mappedFC(),
00094 _mappedType(),
00095
00096 _createdFunctors(),
00097 _destroyedFunctors(),
00098 _changedFunctors(),
00099 _statistics(NULL)
00100 {
00101 FieldContainerFactory::TypeMapIterator typeI;
00102
00103
00104 _fieldFilter[Geometry::getClassType().getId()] =
00105 Geometry::GLIdFieldMask;
00106 _fieldFilter[Surface::getClassType().getId()] =
00107 Surface::GLIdFieldMask | Surface::SurfaceGLIdFieldMask;
00108 _fieldFilter[TextureChunk::getClassType().getId()] =
00109 TextureChunk::GLIdFieldMask;
00110 _fieldFilter[CubeTextureChunk::getClassType().getId()] =
00111 CubeTextureChunk::GLIdFieldMask;
00112 _fieldFilter[VertexProgramChunk::getClassType().getId()] =
00113 VertexProgramChunk::GLIdFieldMask;
00114 _fieldFilter[FragmentProgramChunk::getClassType().getId()] =
00115 FragmentProgramChunk::GLIdFieldMask;
00116
00117 for(typeI = FieldContainerFactory::the()->beginTypes();
00118 typeI != FieldContainerFactory::the()->endTypes(); ++typeI)
00119 {
00120 if(typeI->second->isDerivedFrom(Window::getClassType()))
00121 {
00122 _fieldFilter[typeI->second->getId()
00123 ] = Window::GlObjectEventCounterFieldMask |
00124 Window::GlObjectLastRefreshFieldMask |
00125 Window::GlObjectLastReinitializeFieldMask;
00126 }
00127 }
00128 }
00129
00132 RemoteAspect::~RemoteAspect(void)
00133 {
00134 FieldContainerFactory *factory = FieldContainerFactory::the();
00135 IdSetT::iterator i;
00136 FieldContainerPtr fcPtr;
00137 NodePtr node;
00138 WindowPtr window;
00139
00140
00141 for(i = _receivedFC.begin(); i != _receivedFC.end(); i++)
00142 {
00143 fcPtr = factory->getContainer(*i);
00144 if(fcPtr != NullFC)
00145 {
00146 callDestroyed(fcPtr);
00147
00148
00149
00150
00151
00152 node = NodePtr::dcast(fcPtr);
00153 if(node != NullFC)
00154 {
00155 if(node->getParent() == NullFC)
00156 {
00157 do
00158 {
00159 subRefCP(fcPtr);
00160 fcPtr = factory->getContainer(*i);
00161 } while(fcPtr != NullFC);
00162 }
00163 }
00164 window = WindowPtr::dcast(fcPtr);
00165 if(window != NullFC)
00166 {
00167 do
00168 {
00169 subRefCP(fcPtr);
00170 fcPtr = factory->getContainer(*i);
00171 } while(fcPtr != NullFC);
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 }
00183 }
00184 }
00185
00186
00187
00188
00196 void RemoteAspect::receiveSync(Connection &connection, bool applyToChangelist)
00197 {
00198 bool finish = false;
00199 UInt8 cmd;
00200 UInt32 remoteTypeId;
00201 UInt32 localTypeId;
00202 UInt32 remoteId;
00203 UInt32 localId;
00204 UInt32 localAspect;
00205 std::string name;
00206 FieldContainerFactory *factory = FieldContainerFactory::the();
00207 FieldContainerType *fcType;
00208 FieldContainerPtr fcPtr;
00209 BitVector mask;
00210 RemoteAspectFieldContainerMapper mapper;
00211 UInt64 fullRemoteId;
00212 LocalTypeMapT::iterator localTypeI;
00213 LocalFCMapT::iterator localFCI;
00214 UInt32 len;
00215
00216
00217 std::vector<std::pair<FieldContainerPtr,BitVector> > changedFCs;
00218
00219 if(_statistics)
00220 {
00221 _statistics->getElem(statSyncTime)->start();
00222 }
00223
00224 connection.selectChannel();
00225 connection.getValue(_remoteAspectId);
00226
00227
00228 mapper._remoteAspect = this;
00229 factory->setMapper(&mapper);
00230 do
00231 {
00232 connection.getValue(cmd);
00233 switch(cmd)
00234 {
00235 case NEWTYPE:
00236 {
00237 connection.getValue(remoteTypeId);
00238 connection.getValue(name);
00239
00240
00241 fcType = FieldContainerFactory::the()->findType(name.c_str());
00242 if(!fcType)
00243 {
00244 SWARNING << "Unknown Type: " << name << std::endl;
00245 }
00246 else
00247 {
00248 localTypeId = FieldContainerFactory::the()->findType(name.c_str())->getId();
00249
00250
00251 _localType[remoteTypeId] = localTypeId;
00252 }
00253 break;
00254 }
00255
00256 case CREATED:
00257 {
00258 connection.getValue(remoteTypeId);
00259 connection.getValue(remoteId);
00260 localTypeI = _localType.find(remoteTypeId);
00261 if(localTypeI == _localType.end())
00262 {
00263 SWARNING <<
00264 "Unknown TypeID: " <<
00265 remoteTypeId <<
00266 " for remote id " <<
00267 remoteId <<
00268 std::endl;
00269 }
00270 else
00271 {
00272 UInt64 fullRemoteId=getFullRemoteId(remoteId);
00273 if(_localFC.find(fullRemoteId) == _localFC.end())
00274 {
00275 localTypeId = localTypeI->second;
00276 fcType = factory->findType(localTypeId);
00277 fcPtr = fcType->createFieldContainer();
00278
00279
00280 _receivedFC.insert(fcPtr.getFieldContainerId());
00281
00282
00283 _localFC[fullRemoteId] = fcPtr.getFieldContainerId();
00284 _remoteFC[fcPtr.getFieldContainerId()] = fullRemoteId;
00285
00286
00287 addRefCP(fcPtr);
00288 addRefCP(fcPtr);
00289 callCreated(fcPtr);
00290 }
00291 else
00292 {
00293 FDEBUG(("FC already created %d\n",remoteId));
00294 }
00295 }
00296 break;
00297 }
00298
00299 case DESTROYED:
00300 {
00301 connection.getValue(remoteId);
00302 if(getLocalId(remoteId,localId))
00303 {
00304 clearFCMapping(localId,remoteId);
00305 fcPtr = factory->getContainer(localId);
00306 if(fcPtr != NullFC)
00307 {
00308 callDestroyed(fcPtr);
00309
00310
00311
00312
00313
00314
00315
00316
00317 FieldContainerType &fcType = fcPtr->getType();
00318 for(UInt32 i = 1; i <= fcType.getNumFieldDescs(); ++i)
00319 {
00320 FieldDescription *desc = fcPtr->getType().getFieldDescription(i);
00321
00322
00323
00324
00325
00326
00327 if(strcmp(desc->getName().str(),"beacon")==0)
00328 continue;
00329 Field *fieldPtr = fcPtr->getField(i);
00330 const FieldType &fType = fieldPtr->getType();
00331 const char *ptrStr = strstr(fType.getCName(), "Ptr");
00332 if(ptrStr && strlen(ptrStr) == 3)
00333 {
00334 if(fieldPtr->getCardinality() == FieldType::SINGLE_FIELD)
00335 {
00336 ((SFFieldContainerPtr *)fieldPtr)->setValue(NullFC);
00337 }
00338 else
00339 {
00340 ((MFFieldContainerPtr *) fieldPtr)->clear();
00341 }
00342 }
00343 }
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 do
00355 {
00356 subRefCP(fcPtr);
00357 fcPtr = factory->getContainer(localId);
00358 }
00359 while(fcPtr != NullFC);
00360 }
00361 }
00362 else
00363 {
00364 SWARNING <<
00365 "Can't destroy unknown FC:" <<
00366 remoteId << " " <<
00367 std::endl;
00368 }
00369 break;
00370 }
00371
00372 case CHANGED:
00373 {
00374 connection.getValue(remoteId);
00375 connection.getValue(mask);
00376 connection.getValue(len);
00377
00378 if(getLocalId(remoteId,localId))
00379 {
00380 fcPtr = factory->getContainer(localId);
00381
00382 if(applyToChangelist)
00383 {
00384 beginEditCP(fcPtr, mask);
00385 }
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395 fcPtr->copyFromBin(connection, mask);
00396 if(applyToChangelist)
00397 {
00398 endEditCP(fcPtr, mask);
00399 }
00400 else
00401 {
00402
00403 changedCP(fcPtr, mask);
00404 }
00405 changedFCs.push_back(
00406 std::pair<FieldContainerPtr,BitVector>(
00407 fcPtr,mask));
00408 }
00409 else
00410 {
00411 char dummy;
00412
00413 SWARNING <<
00414 "Can't change unknown FC:" <<
00415 remoteId << " skip " << len << " bytes." <<
00416 std::endl;
00417 while(len--)
00418 connection.get(&dummy,1);
00419 }
00420 break;
00421 }
00422
00423 case SYNCENDED:
00424 {
00425 finish = true;
00426 break;
00427 }
00428
00429 case ADDREFED:
00430 {
00431 connection.getValue(remoteId);
00432 if(getLocalId(remoteId,localId))
00433 {
00434 fcPtr = factory->getContainer(localId);
00435 FDEBUG(("AddRef: %s ID:%d\n",
00436 fcPtr->getType().getName().str(),
00437 fcPtr.getFieldContainerId()))
00438 addRefCP(fcPtr);
00439 }
00440 else
00441 {
00442 FDEBUG(("Can't addref unknown FC:%d\n", remoteId));
00443 }
00444 break;
00445 }
00446
00447 case SUBREFED:
00448 {
00449 connection.getValue(remoteId);
00450 if(getLocalId(remoteId,localId))
00451 {
00452 fcPtr = factory->getContainer(localId);
00453 FDEBUG(("SubRef: %s ID:%d\n",
00454 fcPtr->getType().getName().str(),
00455 fcPtr.getFieldContainerId()))
00456 #if 0
00457
00458 subRefCP(fcPtr);
00459 #endif
00460 }
00461 else
00462 {
00463 FDEBUG(("Can't subref unknown FC:%d\n", remoteId));
00464 }
00465 break;
00466 }
00467 case IDMAPPING:
00468 {
00469 connection.getValue(remoteId);
00470 connection.getValue(localAspect);
00471 connection.getValue(localId);
00472 if(localAspect != _aspectId)
00473 {
00474 SFATAL << "ID mapping for wrong aspect" << std::endl;
00475 }
00476
00477
00478 fullRemoteId = getFullRemoteId(remoteId);
00479 _localFC[fullRemoteId] = localId;
00480 break;
00481 }
00482 default:
00483 {
00484 SFATAL << "Unknown tag:" << (int) cmd << std::endl;
00485 throw RemoteSyncError();
00486 }
00487 }
00488 }
00489 while(!finish);
00490
00491
00492
00493 for(std::vector<std::pair<FieldContainerPtr,BitVector> >::iterator cI=changedFCs.begin();
00494 cI != changedFCs.end();
00495 ++cI)
00496 {
00497 changedCP(cI->first,cI->second);
00498 callChanged(cI->first);
00499 }
00500
00501
00502 factory->setMapper(NULL);
00503
00504 if(_statistics)
00505 {
00506 _statistics->getElem(statSyncTime)->stop();
00507 }
00508 }
00509
00514 void RemoteAspect::sendSync(Connection &connection, ChangeList *changeList)
00515 {
00516 ChangeList::changed_const_iterator changedI;
00517 ChangeList::idrefd_const_iterator createdI;
00518 ChangeList::idrefd_const_iterator destroyedI;
00519 ChangeList::refd_const_iterator addRefedI;
00520 ChangeList::refd_const_iterator subRefedI;
00521 FieldFilterT::iterator filterI;
00522 FieldContainerFactory *fcFactory = FieldContainerFactory::the();
00523 FieldContainerPtr fcPtr;
00524 UInt32 typeId;
00525 BitVector mask;
00526 UInt8 cmd;
00527 std::string typeName;
00528 FieldMaskMapT::iterator sentFCI;
00529 FieldMaskMapT changedMap;
00530 FieldMaskMapT::iterator changedMapI;
00531 UInt32 len;
00532
00533 if(_statistics)
00534 {
00535 _statistics->getElem(statSyncTime)->start();
00536 }
00537
00538 if(!changeList)
00539 {
00540 changeList = OSG::Thread::getCurrentChangeList();
00541 }
00542
00543
00544 connection.putValue(_aspectId);
00545
00546 handleFCMapping(connection);
00547
00548
00549 for(createdI = changeList->beginCreated();
00550 createdI != changeList->endCreated(); createdI++)
00551 {
00552 fcPtr = fcFactory->getContainer(*createdI);
00553 if(fcPtr == NullFC)
00554 {
00555 continue;
00556 }
00557
00558 typeId = fcPtr->getTypeId();
00559
00560
00561 if(_mappedType.count(typeId) == 0)
00562 {
00563
00564 _mappedType.insert(typeId);
00565
00566
00567 cmd = NEWTYPE;
00568 typeName = fcPtr->getType().getName().str();
00569 connection.putValue(cmd);
00570 connection.putValue(typeId);
00571 connection.putValue(typeName);
00572 }
00573
00574 cmd = CREATED;
00575 connection.putValue(cmd);
00576 connection.putValue(typeId);
00577 connection.putValue(*createdI);
00578
00579
00580 _sentFC.insert(*createdI);
00581
00582 _mappedFC.insert(*createdI);
00583
00584 }
00585
00586
00587
00588
00589 for(changedI = changeList->beginChanged();
00590 changedI != changeList->endChanged();
00591 changedI++)
00592 {
00593 changedMapI = changedMap.find(changedI->first);
00594 if(changedMapI == changedMap.end())
00595 {
00596 changedMap.insert(std::pair < UInt32,
00597 BitVector > (changedI->first, changedI->second));
00598 }
00599 else
00600 {
00601 changedMapI->second |= changedI->second;
00602 }
00603 }
00604
00605 for(FieldMaskMapT::iterator condensedI = changedMap.begin();
00606 condensedI != changedMap.end();
00607 ++condensedI)
00608 {
00609 if(_mappedFC.count(condensedI->first)==0)
00610 continue;
00611
00612 FieldContainerPtr fcPtr =
00613 FieldContainerFactory::the()->getContainer(condensedI->first);
00614
00615
00616 if(fcPtr == NullFC)
00617 continue;
00618 mask = condensedI->second;
00619
00620
00621 filterI = _fieldFilter.find(fcPtr->getType().getId());
00622 if(filterI != _fieldFilter.end())
00623 {
00624 FDEBUG(("SyncFieldFilter: :%s \n",
00625 fcPtr->getType().getName().str() ))
00626 mask &= TypeTraits<BitVector>::BitsSet ^ filterI->second;
00627 }
00628
00629 if(mask)
00630 {
00631
00632 condensedI->second |= mask;
00633 cmd = CHANGED;
00634 connection.putValue(cmd);
00635 connection.putValue(condensedI->first);
00636 connection.putValue(mask);
00637 len = fcPtr->getBinSize(mask);
00638 connection.putValue(len);
00639 fcPtr->copyToBin(connection, mask);
00640 FDEBUG(("Changed: %s ID:%d Mask:%lld\n",
00641 fcPtr->getType().getName().str(),
00642 fcPtr.getFieldContainerId(),
00643 mask))
00644 }
00645 }
00646
00647
00648
00649 for(destroyedI = changeList->beginDestroyed();
00650 destroyedI != changeList->endDestroyed(); destroyedI++)
00651 {
00652 UInt32 id = (*destroyedI);
00653
00654
00655 if(_mappedFC.count(id))
00656 {
00657 clearFCMapping(id,0);
00658 cmd = DESTROYED;
00659 connection.putValue(cmd);
00660 connection.putValue(id);
00661 }
00662 }
00663
00664
00665 for(addRefedI = changeList->beginAddRefd();
00666 addRefedI != changeList->endAddRefd();
00667 ++addRefedI)
00668 {
00669 UInt32 id = (*addRefedI);
00670
00671 if(_mappedFC.count(id)==0)
00672 continue;
00673 cmd = ADDREFED;
00674 connection.putValue(cmd);
00675 connection.putValue(id);
00676 }
00677
00678
00679 for(subRefedI = changeList->beginSubRefd();
00680 subRefedI != changeList->endSubRefd();
00681 ++subRefedI)
00682 {
00683 UInt32 id = (*subRefedI);
00684
00685
00686 if(_mappedFC.count(id)==0)
00687 continue;
00688 cmd = SUBREFED;
00689 connection.putValue(cmd);
00690 connection.putValue(id);
00691 }
00692
00693 cmd = SYNCENDED;
00694 connection.putValue(cmd);
00695
00696
00697 connection.flush();
00698
00699 if(_statistics)
00700 {
00701 _statistics->getElem(statSyncTime)->stop();
00702 }
00703 }
00704
00710 void RemoteAspect::registerCreated(const FieldContainerType &type,
00711 const Functor &func)
00712 {
00713 while(type.getId() >= _createdFunctors.size())
00714 {
00715 _createdFunctors.push_back(
00716 osgTypedFunctionFunctor2CPtrRef
00717 <bool,FieldContainerPtr,RemoteAspect * >
00718 (&_defaultCreatedFunction));
00719 }
00720
00721 _createdFunctors[type.getId()] = func;
00722 }
00723
00729 void RemoteAspect::registerDestroyed(const FieldContainerType &type,
00730 const Functor &func)
00731 {
00732 while(type.getId() >= _destroyedFunctors.size())
00733 {
00734 _destroyedFunctors.push_back(osgTypedFunctionFunctor2CPtrRef < bool,
00735 FieldContainerPtr, RemoteAspect * > (&_defaultDestroyedFunction));
00736 }
00737
00738 _destroyedFunctors[type.getId()] = func;
00739 }
00740
00746 void RemoteAspect::registerChanged(const FieldContainerType &type,
00747 const Functor &func)
00748 {
00749 while(type.getId() >= _changedFunctors.size())
00750 {
00751 _changedFunctors.push_back(osgTypedFunctionFunctor2CPtrRef < bool,
00752 FieldContainerPtr,
00753 RemoteAspect * > (&_defaultChangedFunction));
00754 }
00755
00756 _changedFunctors[type.getId()] = func;
00757 }
00758
00761 void RemoteAspect::addFieldFilter( UInt32 typeId,BitVector mask)
00762 {
00763 _fieldFilter[typeId] |= mask;
00764 }
00765
00768 void RemoteAspect::subFieldFilter( UInt32 typeId,BitVector mask)
00769 {
00770 _fieldFilter[typeId] &= ~mask;
00771 }
00772
00775 void RemoteAspect::restoreChangeList(ChangeList *tocl)
00776 {
00777 for(clStoreIt i = _clStore.begin();i != _clStore.end(); ++i)
00778 {
00779 UInt32 id = (*i).first;
00780 FieldContainerPtr fc = FieldContainerFactory::the()->getContainer(id);
00781 if(fc != NullFC)
00782 {
00783 tocl->addCreated(id);
00784 for(UInt32 j=0;j<(*i).second;++j)
00785 tocl->addAddRefd(fc);
00786 tocl->addChanged(fc, FieldBits::AllFields);
00787 }
00788 }
00789 }
00790
00793 void RemoteAspect::storeChangeList(ChangeList *cl)
00794 {
00795
00796 for(ChangeList::idrefd_const_iterator i = cl->beginCreated(); i != cl->endCreated(); ++i)
00797 {
00798 clStoreIt ci = _clStore.find(*i);
00799 if(ci == _clStore.end())
00800 _clStore.insert(std::pair<UInt32, UInt32>(*i, 0));
00801 }
00802
00803
00804 for(ChangeList::idrefd_const_iterator i = cl->beginAddRefd(); i != cl->endAddRefd(); ++i)
00805 {
00806 clStoreIt ci = _clStore.find(*i);
00807 if(ci != _clStore.end())
00808 (*ci).second++;
00809
00810
00811 }
00812
00813
00814 for(ChangeList::idrefd_const_iterator i = cl->beginSubRefd(); i != cl->endSubRefd(); ++i)
00815 {
00816 clStoreIt ci = _clStore.find(*i);
00817 if(ci != _clStore.end())
00818 (*ci).second--;
00819
00820
00821 }
00822
00823
00824 for(ChangeList::idrefd_const_iterator i = cl->beginDestroyed(); i != cl->endDestroyed(); ++i)
00825 {
00826 clStoreIt ci = _clStore.find(*i);
00827 if(ci != _clStore.end())
00828 _clStore.erase(ci);
00829 }
00830 }
00831
00832 UInt32 RemoteAspect::getStoreSize(void)
00833 {
00834 return _clStore.size();
00835 }
00836
00837 RemoteAspect::clStoreMap &RemoteAspect::getStore(void)
00838 {
00839 return _clStore;
00840 }
00841
00842 void RemoteAspect::createCurrentStateChangeList(const FieldContainerPtr &start, ChangeList *cl)
00843 {
00844 if(cl == NULL)
00845 return;
00846
00847 cl->clearAll();
00848 const std::vector<FieldContainerPtr> &fcs = *FieldContainerFactory::the()->getFieldContainerStore();
00849
00850 bool found_start = false;
00851 for(unsigned int i=0;i<fcs.size();++i)
00852 {
00853 FieldContainerPtr fc = fcs[i];
00854 if(fc != NullFC)
00855 {
00856 if(fc == start)
00857 found_start = true;
00858
00859 if(found_start)
00860 {
00861 cl->addCreated(fc.getFieldContainerId());
00862 for(UInt32 j=0;j<fc.getRefCount();++j)
00863 cl->addAddRefd(fc);
00864 cl->addChanged(fc, FieldBits::AllFields);
00865 }
00866 }
00867 }
00868 }
00869
00870
00871
00872
00875 void RemoteAspect::setStatistics(StatCollector *statistics)
00876 {
00877 _statistics = statistics;
00878 }
00879
00880
00881
00882
00887 bool RemoteAspect::callCreated(FieldContainerPtr &fcp)
00888 {
00889 bool result;
00890 UInt32 uiFunctorIndex = fcp->getType().getId();
00891
00892 if(uiFunctorIndex < _createdFunctors.size())
00893 {
00894 result = _createdFunctors[uiFunctorIndex].call(fcp, this);
00895 }
00896 else
00897 {
00898 result = _defaultCreatedFunction(fcp, this);
00899 }
00900
00901 return result;
00902 }
00903
00908 bool RemoteAspect::callDestroyed(FieldContainerPtr &fcp)
00909 {
00910 bool result;
00911 UInt32 uiFunctorIndex = fcp->getType().getId();
00912
00913 if(uiFunctorIndex < _destroyedFunctors.size())
00914 {
00915 result = _destroyedFunctors[uiFunctorIndex].call(fcp, this);
00916 }
00917 else
00918 {
00919 result = _defaultDestroyedFunction(fcp, this);
00920 }
00921
00922 return result;
00923 }
00924
00929 bool RemoteAspect::callChanged(FieldContainerPtr &fcp)
00930 {
00931 bool result;
00932 UInt32 uiFunctorIndex = fcp->getType().getId();
00933
00934 if(uiFunctorIndex < _changedFunctors.size())
00935 {
00936 result = _changedFunctors[uiFunctorIndex].call(fcp, this);
00937 }
00938 else
00939 {
00940 result = _defaultChangedFunction(fcp, this);
00941 }
00942
00943 return result;
00944 }
00945
00949 void RemoteAspect::handleFCMapping(Connection &connection)
00950 {
00951 UInt8 cmd;
00952 UInt32 remoteId;
00953 UInt32 remoteAspect;
00954 RemoteFCMapT::iterator remoteFCI;
00955
00956 for(remoteFCI = _remoteFC.begin() ;
00957 remoteFCI != _remoteFC.end() ;
00958 ++remoteFCI)
00959 {
00960 remoteId = (UInt32)(remoteFCI->second);
00961 remoteAspect = (UInt32)(remoteFCI->second>>32);
00962
00963 cmd = IDMAPPING;
00964 connection.putValue(cmd);
00965 connection.putValue(remoteFCI->first);
00966 connection.putValue(remoteAspect);
00967 connection.putValue(remoteId);
00968
00969 _mappedFC.insert(remoteFCI->first);
00970 }
00971 _remoteFC.clear();
00972 }
00973
00976 void RemoteAspect::clearFCMapping(UInt32 localId,UInt32 remoteId)
00977 {
00978 _mappedFC.erase(localId);
00979 _sentFC.erase(localId);
00980 _receivedFC.erase(localId);
00981
00982 if(!remoteId)
00983 {
00984 RemoteFCMapT::iterator remoteFCI=_remoteFC.find(localId);
00985 if(remoteFCI != _remoteFC.end())
00986 remoteId=static_cast<UInt32>(remoteFCI->second);
00987 }
00988
00989 RemoteFCMapT::iterator remoteFCI=_remoteFC.find(localId);
00990 if(remoteFCI != _remoteFC.end())
00991 _remoteFC.erase(remoteFCI);
00992
00993 LocalFCMapT::iterator localFCI=_localFC.find(remoteId);
00994 if(localFCI != _localFC.end())
00995 _localFC.erase(localFCI);
00996
00997 }
00998
01001 bool RemoteAspect::getLocalId(UInt32 remoteId,
01002 UInt32 &localId)
01003 {
01004 UInt64 fullRemoteId = getFullRemoteId(remoteId);
01005 LocalFCMapT::iterator localFCI=_localFC.find(fullRemoteId);
01006
01007 if( localFCI != _localFC.end() )
01008 {
01009 localId=localFCI->second;
01010 return true;
01011 }
01012 else
01013 {
01014 return false;
01015 }
01016 }
01017
01018 UInt64 RemoteAspect::getFullRemoteId(UInt32 fcId)
01019 {
01020 UInt64 remoteId=_remoteAspectId;
01021 remoteId<<=32;
01022 remoteId|=fcId;
01023 return remoteId;
01024 }
01025
01026
01027
01028
01029 #ifdef __sgi
01030
01031
01032 #pragma set woff 3201
01033 #endif
01034
01037 bool RemoteAspect::_defaultCreatedFunction(FieldContainerPtr &fcp, RemoteAspect *)
01038 {
01039 FDEBUG(("Created:%s %d\n",
01040 fcp->getType().getName().str(),
01041 fcp.getFieldContainerId()))
01042 return true;
01043 }
01044
01047 bool RemoteAspect::_defaultDestroyedFunction(FieldContainerPtr &fcp,
01048 RemoteAspect *)
01049 {
01050 FDEBUG(("Destroyed:%s %d\n",
01051 fcp->getType().getName().str(),
01052 fcp.getFieldContainerId()))
01053 return true;
01054 }
01055
01058 bool RemoteAspect::_defaultChangedFunction(FieldContainerPtr &fcp, RemoteAspect *)
01059 {
01060 FDEBUG(("Changed:%s %d\n",
01061 fcp->getType().getName().str(),
01062 fcp.getFieldContainerId()))
01063 return true;
01064 }
01065
01066 #ifdef __sgi
01067 #pragma reset woff 3201
01068 #endif
01069
01073 UInt32 RemoteAspectFieldContainerMapper::map(UInt32 uiId)
01074 {
01075 UInt32 mappedId;
01076 RemoteAspect::LocalFCMapT::iterator i;
01077
01078 i = _remoteAspect->_localFC.find(
01079 _remoteAspect->getFullRemoteId(uiId));
01080 if(i == _remoteAspect->_localFC.end())
01081 {
01082 SWARNING << "Can't find container id:" << uiId << std::endl;
01083 mappedId = 0;
01084 }
01085 else
01086 {
01087 mappedId = i->second;
01088 }
01089
01090 FDEBUG(("Map: %d to %d\n", uiId, mappedId))
01091
01092 return mappedId;
01093 }
01094
01095
01096
01097
01098 #ifdef __sgi
01099 #pragma set woff 1174
01100 #endif
01101 #ifdef OSG_LINUX_ICC
01102 #pragma warning(disable : 177)
01103 #endif
01104
01105 namespace
01106 {
01107 static Char8 cvsid_cpp[] = "@(#)$Id:$";
01108 static Char8 cvsid_hpp[] = OSGREMOTEASPECT_HEADER_CVSID;
01109 }