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