File tree Expand file tree Collapse file tree
room_control_unit/src/app/logic/fsm/gatewayexporter Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2023 Smart Operating Block
3+ *
4+ * Use of this source code is governed by an MIT-style
5+ * license that can be found in the LICENSE file or at
6+ * https://opensource.org/licenses/MIT.
7+ */
8+
9+ #include " GatewayExporter.h"
10+ #include " ../../../../utils/ArrayStream.h"
11+ #include " ../../presenter/serializer/JsonSerializer.h"
12+
13+ GatewayExporter::GatewayExporter (const int period, GatewayExporterContext* const context): AbstractFsm(period) {
14+ this ->changeState (new E (context));
15+ }
16+
17+ /*
18+ ##############################################################################
19+ ------------------State of GatewayExporter FSM ---------------
20+ ##############################################################################
21+ */
22+
23+ GatewayExporter::E::E (GatewayExporterContext* const context): context(context) {
24+ this ->serializer = new JsonSerializer ();
25+ }
26+
27+ void GatewayExporter::E::run (Fsm* const parentFsm) {
28+ const int eventListSize = this ->context ->eventList ->size ();
29+ if (eventListSize != 0 ) {
30+ ArrayStream<Event*>(this ->context ->eventList ->toArray (), eventListSize)
31+ .foreach ([this ](Event* ev) {this ->context ->externalGatewayInterface ->send (this ->serializer ->serialize (ev));});
32+ this ->context ->eventList ->clear (true );
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2023 Smart Operating Block
3+ *
4+ * Use of this source code is governed by an MIT-style
5+ * license that can be found in the LICENSE file or at
6+ * https://opensource.org/licenses/MIT.
7+ */
8+
9+ #ifndef __GATEWAY_EXPORTER__
10+ #define __GATEWAY_EXPORTER__
11+
12+ #include " ../AbstractFsm.h"
13+ #include " ../../../model/event/Event.h"
14+ #include " ../../baseio/communication/ExternalGateway.h"
15+ #include " ../../../../utils/List.h"
16+
17+ struct GatewayExporterContext {
18+ List<Event*>* const eventList;
19+ ExternalGateway* const externalGatewayInterface;
20+ };
21+
22+ /*
23+ Gateway Exporter task.
24+ Its main objective is to send data (associated to the internal event) to the system gateway.
25+ */
26+ class GatewayExporter : public AbstractFsm {
27+ public:
28+ /*
29+ Constructor.
30+
31+ @param period the period of the fsm.
32+ @param context the local context of the fsm.
33+ */
34+ GatewayExporter (int period, GatewayExporterContext* context);
35+
36+ private:
37+ class E : public State {
38+ public:
39+ E (GatewayExporterContext* context);
40+ void run (Fsm* parentFsm);
41+ private:
42+ GatewayExporterContext* const context;
43+ Serializer* serializer;
44+ };
45+
46+ };
47+
48+
49+ #endif
You can’t perform that action at this time.
0 commit comments