1818#include " sst/core/factory.h"
1919#include " sst/core/link.h"
2020#include " sst/core/linkMap.h"
21+ #include " sst/core/portModule.h"
2122#include " sst/core/profile/clockHandlerProfileTool.h"
2223#include " sst/core/profile/eventHandlerProfileTool.h"
2324#include " sst/core/serialization/serialize.h"
@@ -88,6 +89,11 @@ BaseComponent::~BaseComponent()
8889 " Warning: BaseComponent destructor failed to remove ComponentInfo from parent.\n " );
8990 }
9091 }
92+
93+ // Delete any portModules
94+ for ( auto port : portModules ) {
95+ delete port;
96+ }
9197}
9298
9399void
@@ -221,7 +227,7 @@ BaseComponent::isPortConnected(const std::string& name) const
221227// child and remove it from my linkmap. The child will insert it into
222228// their link map.
223229Link*
224- BaseComponent::getLinkFromParentSharedPort (const std::string& port)
230+ BaseComponent::getLinkFromParentSharedPort (const std::string& port, std::vector<ConfigPortModule>& port_modules )
225231{
226232 LinkMap* myLinks = my_info->getLinkMap ();
227233
@@ -237,6 +243,16 @@ BaseComponent::getLinkFromParentSharedPort(const std::string& port)
237243 // it from my link map and return it to the child.
238244 if ( !tmp->isConfigured () ) {
239245 myLinks->removeLink (port);
246+ // Need to see if there are any associated PortModules
247+ if ( my_info->portModules != nullptr ) {
248+ auto it = my_info->portModules ->find (port);
249+ if ( it != my_info->portModules ->end () ) {
250+ // Found PortModules, swap them into
251+ // port_modules and remove from my map
252+ port_modules.swap (it->second );
253+ my_info->portModules ->erase (it);
254+ }
255+ }
240256 return tmp;
241257 }
242258 }
@@ -246,7 +262,9 @@ BaseComponent::getLinkFromParentSharedPort(const std::string& port)
246262 // parent shared with me and if so, call
247263 // getLinkFromParentSharedPort on them
248264
249- if ( my_info->sharesPorts () ) { return my_info->parent_info ->component ->getLinkFromParentSharedPort (port); }
265+ if ( my_info->sharesPorts () ) {
266+ return my_info->parent_info ->component ->getLinkFromParentSharedPort (port, port_modules);
267+ }
250268 else {
251269 return nullptr ;
252270 }
@@ -266,7 +284,8 @@ BaseComponent::configureLink(const std::string& name, TimeConverter* time_base,
266284 // with parents if sharing is turned on
267285 if ( nullptr == tmp ) {
268286 if ( my_info->sharesPorts () ) {
269- tmp = my_info->parent_info ->component ->getLinkFromParentSharedPort (name);
287+ std::vector<ConfigPortModule> port_modules;
288+ tmp = my_info->parent_info ->component ->getLinkFromParentSharedPort (name, port_modules);
270289 // If I got a link from my parent, I need to put it in my
271290 // link map
272291 if ( nullptr != tmp ) {
@@ -277,6 +296,15 @@ BaseComponent::configureLink(const std::string& name, TimeConverter* time_base,
277296 myLinks->insertLink (name, tmp);
278297 // Need to set the link's defaultTimeBase to nullptr
279298 tmp->setDefaultTimeBase (nullptr );
299+
300+ // Need to see if I got any port_modules, if so, need
301+ // to add them to my_info->portModules
302+ if ( port_modules.size () > 0 ) {
303+ if ( nullptr == my_info->portModules ) {
304+ my_info->portModules = new std::map<std::string, std::vector<ConfigPortModule>>();
305+ }
306+ (*my_info->portModules )[name].swap (port_modules);
307+ }
280308 }
281309 }
282310 }
@@ -301,6 +329,29 @@ BaseComponent::configureLink(const std::string& name, TimeConverter* time_base,
301329 if ( tool->profileSends () ) tmp->attachTool (tool, mdata);
302330 }
303331 }
332+
333+ // Check for PortModules
334+ if ( my_info->portModules != nullptr ) {
335+ auto it = my_info->portModules ->find (name);
336+ if ( it != my_info->portModules ->end () ) {
337+ EventHandlerMetaData mdata (my_info->getID (), getName (), getType (), name);
338+ for ( auto & portModule : it->second ) {
339+ auto * pm = Factory::getFactory ()->CreateWithParams <PortModule>(
340+ portModule.type , portModule.params , portModule.params );
341+ pm->setComponent (this );
342+ if ( pm->installOnSend () ) tmp->attachTool (pm, mdata);
343+ if ( pm->installOnReceive () ) {
344+ if ( handler )
345+ handler->attachInterceptTool (pm, mdata);
346+ else
347+ fatal (
348+ CALL_INFO_LONG, 1 , " ERROR: Trying to install a receive PortModule on a Polling Link\n " );
349+ }
350+ portModules.push_back (pm);
351+ }
352+ }
353+ }
354+
304355 if ( nullptr != time_base )
305356 tmp->setDefaultTimeBase (time_base);
306357 else
0 commit comments