SST  13.1.0
Structural Simulation Toolkit
enclosingComponent.h
1 // Copyright 2009-2023 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2023, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_CORETEST_MESSAGEMESH_ENCLOSINGCOMPONENT_H
13 #define SST_CORE_CORETEST_MESSAGEMESH_ENCLOSINGCOMPONENT_H
14 
15 #include "sst/core/testElements/message_mesh/messageEvent.h"
16 
17 #include "sst/core/component.h"
18 #include "sst/core/event.h"
19 #include "sst/core/link.h"
20 #include "sst/core/rng/rng.h"
21 #include "sst/core/ssthandler.h"
22 #include "sst/core/subcomponent.h"
23 
24 namespace SST {
25 namespace CoreTest {
26 namespace MessageMesh {
27 
29 {
30 public:
31  SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTest::MessageMesh::PortInterface)
32 
33  PortInterface(ComponentId_t id) : SubComponent(id) {}
34  virtual ~PortInterface() {}
35 
36  /**
37  Base handler for event delivery.
38  */
40 
41  /**
42  Used to create handlers to notify the component when a message
43  has arrived. endpoint when the The callback function is
44  expected to be in the form of:
45 
46  void func(Event* ev)
47 
48  In which case, the class is created with:
49 
50  new PortInterface::Handler<classname>(this, &classname::function_name)
51 
52  Or, to add static data, the callback function is:
53 
54  void func(Event* ev, dataT data)
55 
56  and the class is created with:
57 
58  new PortInterface::Handler<classname, dataT>(this, &classname::function_name, data)
59  */
60  template <typename classT, typename dataT = void>
62 
63  virtual void setNotifyOnReceive(HandlerBase* functor) { rFunctor = functor; }
64 
65  virtual void send(MessageEvent* ev) = 0;
66 
67 protected:
68  HandlerBase* rFunctor;
69 };
70 
72 {
73 public:
74  SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTest::MessageMesh::RouteInterface, const std::vector<PortInterface*>&, int)
75 
76  RouteInterface(ComponentId_t id) : SubComponent(id) {}
77  virtual ~RouteInterface() {}
78 
79  virtual void send(MessageEvent* ev, int incoming_port) = 0;
80 };
81 
83 {
84 public:
85  // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
86  SST_ELI_REGISTER_COMPONENT(
88  "coreTestElement",
89  "message_mesh.enclosing_component",
90  SST_ELI_ELEMENT_VERSION(1,0,0),
91  "Base element that encloses the SubComponents that actually provide the functionality",
92  COMPONENT_CATEGORY_NETWORK
93  )
94 
95  SST_ELI_DOCUMENT_PARAMS(
96  {"id", "Id for this componentd", ""},
97  )
98 
99  SST_ELI_DOCUMENT_STATISTICS(
100  )
101 
102  SST_ELI_DOCUMENT_PORTS(
103  )
104 
105  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
106  {"ports", "Slot that the ports objects go in", "SST::CoreTest::MessageMesh::PortInterface" },
107  {"route", "Slot that the ports objects go in", "SST::CoreTest::MessageMesh::RouteInterface" }
108  )
109 
110  EnclosingComponent(ComponentId_t id, Params& params);
111 
112  void setup();
113  void finish();
114 
115 private:
116  void handleEvent(SST::Event* ev, int port);
117 
118  std::vector<PortInterface*> ports;
119  RouteInterface* route;
120 
121  int my_id;
122  int message_count;
123 };
124 
125 // SubComponents
126 
127 class PortSlot : public PortInterface
128 {
129 public:
130  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
131  SST_ELI_REGISTER_SUBCOMPONENT(
132  PortSlot,
133  "coreTestElement",
134  "message_mesh.port_slot",
135  SST_ELI_ELEMENT_VERSION(1,0,0),
136  "SubComponent implementing PortInterface that simply defers to another loaded PortInterface",
138  )
139 
140  SST_ELI_DOCUMENT_PARAMS(
141  )
142 
143  SST_ELI_DOCUMENT_STATISTICS(
144  )
145 
146  SST_ELI_DOCUMENT_PORTS(
147  )
148 
149  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
150  {"port", "Slot to load the real PortInterface object", "SST::CoreTest::MessageMesh::PortInterface" }
151  )
152 
153  PortSlot(ComponentId_t id, Params& params);
154  ~PortSlot() {}
155 
156  void send(MessageEvent* ev) override { port->send(ev); }
157  void setNotifyOnReceive(HandlerBase* functor) override { port->setNotifyOnReceive(functor); }
158 
159 private:
160  PortInterface* port;
161 };
162 
163 
165 {
166 public:
167  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
168  SST_ELI_REGISTER_SUBCOMPONENT(
169  MessagePort,
170  "coreTestElement",
171  "message_mesh.message_port",
172  SST_ELI_ELEMENT_VERSION(1,0,0),
173  "SubComponent implementing PortInterface for sending and receiving messages",
175  )
176 
177  SST_ELI_DOCUMENT_PARAMS(
178  )
179 
180  SST_ELI_DOCUMENT_STATISTICS(
181  )
182 
183  SST_ELI_DOCUMENT_PORTS(
184  {"port", "Port to send or receive on", { "" } },
185  )
186 
187  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
188  )
189 
190  MessagePort(ComponentId_t id, Params& params);
191  ~MessagePort() {}
192 
193  void send(MessageEvent* ev);
194  void handleEvent(Event* ev);
195 
196 private:
197  Link* link;
198 };
199 
201 {
202 public:
203  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
204  SST_ELI_REGISTER_SUBCOMPONENT(
205  RouteMessage,
206  "coreTestElement",
207  "message_mesh.route_message",
208  SST_ELI_ELEMENT_VERSION(1,0,0),
209  "SubComponent implementing message routing",
211  )
212 
213  SST_ELI_DOCUMENT_PARAMS(
214  )
215 
216  SST_ELI_DOCUMENT_STATISTICS(
217  )
218 
219  SST_ELI_DOCUMENT_PORTS(
220  )
221 
222  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
223  )
224 
225  RouteMessage(ComponentId_t id, Params& params, const std::vector<PortInterface*>& ports, int my_id);
226  ~RouteMessage() {}
227 
228  void send(MessageEvent* ev, int incoming_port) override;
229 
230 private:
231  const std::vector<PortInterface*> ports;
232  int my_id;
233  SST::RNG::Random* rng;
234 };
235 
236 } // namespace MessageMesh
237 } // namespace CoreTest
238 } // namespace SST
239 
240 #endif // SST_CORE_CORETEST_MESSAGEMESH_ENCLOSINGCOMPONENT_H
Main component object for the simulation.
Definition: component.h:31
Definition: enclosingComponent.h:83
void finish()
Called after complete phase, but before objects are destroyed.
Definition: enclosingComponent.cc:72
void setup()
Called after all components have been constructed and initialization has completed,...
Definition: enclosingComponent.cc:60
Definition: messageEvent.h:22
Definition: enclosingComponent.h:165
Definition: enclosingComponent.h:29
SSTHandlerBase< void, Event * > HandlerBase
Base handler for event delivery.
Definition: enclosingComponent.h:39
Definition: enclosingComponent.h:128
Definition: enclosingComponent.h:72
Definition: enclosingComponent.h:201
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:35
Parameter store.
Definition: params.h:56
Implements the base class for random number generators for the SST core.
Definition: rng.h:28
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:171
Handler class with user-data argument.
Definition: ssthandler.h:220
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29