Equalizer  1.4.1
sharedData.cpp
00001 
00002 /*
00003  * Copyright (c) 2009, Philippe Robert <philippe.robert@gmail.com> 
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * - Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  * - Redistributions in binary form must reproduce the above copyright notice,
00011  *   this list of conditions and the following disclaimer in the documentation
00012  *   and/or other materials provided with the distribution.
00013  * - Neither the name of Eyescale Software GmbH nor the names of its
00014  *   contributors may be used to endorse or promote products derived from this
00015  *   software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "sharedData.h"
00031 #include "sharedDataProxy.h"
00032 #include "pipe.h"
00033 #include "config.h"
00034 #include "controller.h"
00035 
00036 namespace eqNbody
00037 {
00038 SharedData::SharedData( Config *cfg ) : _cfg( cfg )
00039 {
00040     LBASSERT( _cfg );
00041 }
00042     
00043 SharedData::~SharedData()
00044 {
00045     if( _cfg )
00046         _cfg = 0;
00047 
00048     for( uint32_t i=0; i< _frameData.getNumDataProxies(); i++ )
00049     {
00050         delete _proxies[i];
00051     }
00052     _proxies.clear();
00053 }
00054             
00055 void SharedData::registerMemory( const eq::Range& range )
00056 {       
00057     // Initialise the local proxy
00058     unsigned int offset = range.start * _frameData.getNumBodies() * 4;
00059     unsigned int numBytes = ( range.end - range.start ) *
00060                             _frameData.getNumBytes(); 
00061     SharedDataProxy *shMem = new SharedDataProxy();
00062     _proxies.push_back( shMem );
00063 
00064     shMem->init( offset, numBytes, _frameData.getPos(), _frameData.getVel(),
00065                  _frameData.getCol() );    
00066     
00067     // Register the proxy object
00068     _cfg->registerObject( shMem );
00069 
00070     const eq::uint128_t version = shMem->commit(); 
00071         
00072     // Let the app know which range is covered by this proxy
00073     _sendEvent( ConfigEvent::DATA_CHANGED, version, shMem->getID(), range );
00074 }
00075     
00076 void SharedData::mapMemory()
00077 {
00078     const SharedDataProxy *shMem = _proxies[0];
00079         
00080     // Initialise the remote shared memory proxies
00081     for( uint32_t i=0; i< _frameData.getNumDataProxies(); i++) 
00082     {
00083         const eq::uint128_t& pid = _frameData.getProxyID(i);
00084             
00085         if( pid != shMem->getID() ) 
00086         {
00087             SharedDataProxy *readMem = new SharedDataProxy();
00088                 
00089             readMem->init( _frameData.getPos(), _frameData.getVel(), 
00090                            _frameData.getCol() );
00091             _proxies.push_back( readMem );
00092                 
00093             LBCHECK( _cfg->mapObject( readMem, pid ));
00094         }
00095     }           
00096 }
00097 
00098 void SharedData::releaseMemory()
00099 {
00100     for( uint32_t i=0; i< _frameData.getNumDataProxies(); i++ )
00101     {
00102         _cfg->releaseObject( _proxies[i] );
00103     }
00104 }
00105     
00106 void SharedData::syncMemory()
00107 {
00108     for(unsigned int i=1; i< _frameData.getNumDataProxies(); i++)
00109     {
00110         const eq::uint128_t& pid = _proxies[i]->getID();
00111         const eq::uint128_t version = _frameData.getVersionForProxyID(pid);
00112             
00113         // ...and sync!
00114         _proxies[i]->sync( version );
00115     }
00116 }
00117     
00118 void SharedData::updateMemory(const eq::Range& range, Controller *controller)
00119 {
00120     SharedDataProxy *local = _proxies[0];
00121 
00122     controller->getArray(BODYSYSTEM_POSITION, *local);
00123     controller->getArray(BODYSYSTEM_VELOCITY, *local);          
00124         
00125     // Commit the local changes
00126     const eq::uint128_t version = local->commit();
00127         
00128     // Tell the others what version to sync.
00129     _sendEvent( ConfigEvent::PROXY_CHANGED, version, local->getID(), range) ;
00130 }
00131     
00132 void SharedData::_sendEvent( ConfigEvent::Type type,
00133                              const eq::uint128_t& version,
00134                              const eq::uint128_t& pid,
00135                              const eq::Range& range)
00136 {
00137     ConfigEvent event;
00138 
00139     event.data.type = type;
00140     event._version = version;
00141     event._range[0] = range.start;
00142     event._range[1] = range.end;
00143     event._proxyID = pid;
00144         
00145     _cfg->sendEvent( event );
00146 }   
00147 }
Generated on Mon Nov 26 2012 14:41:49 for Equalizer 1.4.1 by  doxygen 1.7.6.1