00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "torc/generic/om/DumpRestoreConfig.hpp"
00017
00018 #ifndef HAVE_CONFIG_H
00019 #include "torc/generic/config.h"
00020 #endif
00021
00022
00023 #include <boost/bind.hpp>
00024 #include <boost/mem_fn.hpp>
00025 #ifdef GENOM_SERIALIZATION
00026 #include <boost/archive/binary_iarchive.hpp>
00027 #include <boost/archive/binary_oarchive.hpp>
00028 #include <boost/serialization/base_object.hpp>
00029 #include <boost/serialization/export.hpp>
00030 #endif //GENOM_SERIALIZATION
00031
00032 #include "torc/generic/om/ConnectionHandler.hpp"
00033 #include "torc/generic/om/Net.hpp"
00034 #include "torc/generic/om/Port.hpp"
00035 #include "torc/generic/om/VectorPortReference.hpp"
00036 #include "torc/generic/om/PortBundleReference.hpp"
00037
00038 #ifdef GENOM_SERIALIZATION
00039 BOOST_CLASS_EXPORT( torc::generic::VectorPortReference )
00040 #endif //GENOM_SERIALIZATION
00041
00042 namespace {
00043
00044 class PortBinder
00045 : public torc::generic::VectorPortBitReference::Visitor {
00046 public:
00047 void
00048 visit( torc::generic::VectorPortBitReference &portBit
00049 ) throw(torc::generic::Error) {
00050 torc::generic::PortSharedPtr childPort
00051 = mMasterVector->get( portBit.getIndices() );
00052 try
00053 {
00054 portBit.bindToMasterPort( childPort );
00055 }
00056 catch(torc::generic::Error &e)
00057 {
00058 e.setCurrentLocation(
00059 __FUNCTION__, __FILE__, __LINE__ );
00060 throw;
00061 }
00062 return;
00063 }
00064
00065 PortBinder(
00066 const torc::generic::PortSharedPtr &inMasterVector )
00067 : mMasterVector( inMasterVector ) {
00068 }
00069
00070 ~PortBinder() throw() {
00071 }
00072
00073 private:
00074 torc::generic::PortSharedPtr mMasterVector;
00075 };
00076
00077
00078 }
00079 namespace torc {
00080
00081 namespace generic {
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 VectorPortReferenceSharedPtr
00094 VectorPortReference::Factory::newVectorPortReferencePtr( const InstanceSharedPtr &inInstancePtr,
00095 const PortSharedPtr &inPortPtr,
00096 const size_t &inSize,
00097 const PortBundleReferenceSharedPtr &inParentCollection,
00098 const ChildFactorySharedPtr &inFactory ) throw(Error) {
00099 try
00100 {
00101 std::vector<size_t> limits;
00102 limits.push_back( inSize );
00103 return newVectorPortReferencePtr( inInstancePtr, inPortPtr, limits, inParentCollection, inFactory );
00104 }
00105 catch( Error &e )
00106 {
00107 e.setCurrentLocation(
00108 __FUNCTION__, __FILE__, __LINE__ );
00109 throw;
00110 }
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 VectorPortReferenceSharedPtr
00124 VectorPortReference::Factory::newVectorPortReferencePtr( const InstanceSharedPtr &inInstancePtr,
00125 const PortSharedPtr &inPortPtr,
00126 const std::vector<size_t> &inLimits,
00127 const PortBundleReferenceSharedPtr &inParentCollection,
00128 const ChildFactorySharedPtr &inFactory ) throw(Error) {
00129 try
00130 {
00131 VectorPortReferenceSharedPtr newVectorPortReference;
00132 create( newVectorPortReference );
00133 newVectorPortReference->constructChildren( inFactory, inLimits);
00134 newVectorPortReference->bindToMasterPort( inPortPtr );
00135 if( inParentCollection )
00136 {
00137 inParentCollection->addChild( newVectorPortReference );
00138 }
00139 else
00140 {
00141 inInstancePtr->addPortReference( newVectorPortReference );
00142 }
00143 return newVectorPortReference;
00144 }
00145 catch( Error &e )
00146 {
00147 e.setCurrentLocation(
00148 __FUNCTION__, __FILE__, __LINE__ );
00149 throw;
00150 }
00151 }
00152
00153 void
00154 VectorPortReference::accept(
00155 BaseVisitor & inoutVisitor) throw(Error) {
00156 try
00157 {
00158 runVisitor( *this, inoutVisitor );
00159 }
00160 catch( Error &e )
00161 {
00162 e.setCurrentLocation(
00163 __FUNCTION__, __FILE__, __LINE__ );
00164 throw;
00165 }
00166 }
00167
00168 void
00169 VectorPortReference::setParent(
00170 const InstanceSharedPtr &inParent ) throw() {
00171 ParentedObject<Instance>::setParent( inParent );
00172 BaseType::List children;
00173 getCreatedChildren( children );
00174 std::for_each( children.begin(), children.end(),
00175 boost::bind( boost::mem_fn(
00176 &PortReference::setParent), _1, getParent() ));
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 Connectable::Connection
00192 VectorPortReference::connect(const NetSharedPtr &inNet) throw(Error) {
00193 if( !inNet )
00194 {
00195 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00196 __FUNCTION__, __FILE__, __LINE__ );
00197 e.saveContextData("Pointer to Net", inNet);
00198 throw e;
00199 }
00200 if( inNet->getSize() != getSize() )
00201 {
00202 Error e( eMessageIdErrorItemSizeMismatch,
00203 __FUNCTION__, __FILE__, __LINE__ );
00204 e.saveContextData("Net Size", inNet->getSize());
00205 e.saveContextData("VectorPortReference Size", getSize() );
00206 throw e;
00207 }
00208 Connectable::Connection newConnection;
00209 try
00210 {
00211 ConnectionHandler handler( inNet );
00212 handler.connectPortRefToNet( getSharedThis() );
00213 newConnection = Connectable::connect( inNet );
00214 }
00215 catch( Error &e )
00216 {
00217 e.setCurrentLocation(
00218 __FUNCTION__, __FILE__, __LINE__ );
00219 throw;
00220 }
00221 return newConnection;
00222 }
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 void
00233 VectorPortReference::disconnect(
00234 const Connectable::Connection &inConnection) throw(Error) {
00235 NetSharedPtr connNet = *inConnection;
00236 if( !connNet )
00237 {
00238 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00239 __FUNCTION__, __FILE__, __LINE__ );
00240 e.saveContextData("Pointer to Net", connNet);
00241 throw e;
00242 }
00243 try
00244 {
00245 BaseType::List children;
00246 getCreatedChildren( children );
00247 for_each( children.begin(), children.end(),
00248 boost::bind( boost::mem_fn(
00249 &Connectable::disconnect), _1));
00250 ConnectionHandler handler( connNet );
00251 handler.disconnectPortRefFromNet( getSharedThis() );
00252 Connectable::disconnect( inConnection );
00253 }
00254 catch( Error &e )
00255 {
00256 e.setCurrentLocation(
00257 __FUNCTION__, __FILE__, __LINE__ );
00258 throw;
00259 }
00260 return;
00261 }
00262
00263 void
00264 VectorPortReference::getConnectedNets(
00265 std::vector< NetSharedPtr > &outNets,
00266 bool inSkipChildConnections
00267 ) const throw(Error) {
00268 PortReference::getConnectedNets( outNets );
00269 if( !inSkipChildConnections )
00270 {
00271 BaseType::List children;
00272 getCreatedChildren( children );
00273
00274 BaseType::List::iterator pRef = children.begin();
00275 BaseType::List::iterator nEnd = children.end();
00276 for(; pRef != nEnd; ++pRef )
00277 {
00278 (*pRef)->getConnectedNets ( outNets, true );
00279 }
00280 }
00281 return;
00282 }
00283
00284
00285
00286
00287
00288
00289 void
00290 VectorPortReference::bindToMasterPort(
00291 const PortSharedPtr &inMaster) throw(Error) {
00292 PortReference::bindToMasterPort( inMaster );
00293
00294 }
00295
00296 void
00297 VectorPortReference::onChildCreate(
00298 const VectorPortBitReferenceSharedPtr &inCreatedChild
00299 ) const throw(Error) {
00300 PortSharedPtr masterPort = getMaster();
00301 if( masterPort )
00302 {
00303 PortBinder binder( masterPort );
00304
00305
00306
00307 try
00308 {
00309 inCreatedChild->accept( binder );
00310 }
00311 catch( Error &e )
00312 {
00313 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00314 throw;
00315 }
00316 }
00317 }
00318
00319 VectorPortReference::VectorPortReference()
00320 :PortReference(),
00321 BaseType()
00322 {
00323 }
00324
00325 VectorPortReference::~VectorPortReference() throw()
00326 {
00327 }
00328
00329 #ifdef GENOM_SERIALIZATION
00330 template<class Archive> void
00331 VectorPortReference::serialize( Archive &ar, unsigned int ) {
00332 ar & boost::serialization::base_object< PortReference >( *this );
00333 ar & boost::serialization::base_object< BaseType >(*this);
00334 }
00335
00336
00337 template void
00338 VectorPortReference::serialize<boost::archive::binary_iarchive>(
00339 boost::archive::binary_iarchive & ar, const unsigned int);
00340
00341 template void
00342 VectorPortReference::serialize<boost::archive::binary_oarchive>(
00343 boost::archive::binary_oarchive & ar, const unsigned int);
00344
00345 #endif //GENOM_SERIALIZATION
00346
00347 }
00348
00349 }