-
Notifications
You must be signed in to change notification settings - Fork 8
/
RealTimeLoader.cpp
150 lines (130 loc) · 5.65 KB
/
RealTimeLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* @file RealTimeLoader.cpp
* @brief Source file for class RealTimeLoader
* @date 04/04/2018
* @author Andre' Neto
*
* @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
* the Development of Fusion Energy ('Fusion for Energy').
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence")
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
*
* @warning Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an "AS IS"
* basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the Licence permissions and limitations under the Licence.
* @details This source file contains the definition of all the methods for
* the class RealTimeLoader (public, protected, and private). Be aware that some
* methods, such as those inline could be defined on the header file, instead.
*/
/*---------------------------------------------------------------------------*/
/* Standard header includes */
/*---------------------------------------------------------------------------*/
#define DLL_API
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "AdvancedErrorManagement.h"
#include "ConfigurationDatabase.h"
#include "RealTimeLoader.h"
#include "MessageI.h"
#include "ObjectRegistryDatabase.h"
/*---------------------------------------------------------------------------*/
/* Static definitions */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Method definitions */
/*---------------------------------------------------------------------------*/
namespace MARTe {
RealTimeLoader::RealTimeLoader() :
Loader() {
}
RealTimeLoader::~RealTimeLoader() {
}
ErrorManagement::ErrorType RealTimeLoader::Configure(StructuredDataI& data, StreamI &configuration) {
ErrorManagement::ErrorType ret = Loader::Configure(data, configuration);
ObjectRegistryDatabase *objDb = ObjectRegistryDatabase::Instance();
uint32 nOfObjs = objDb->Size();
uint32 found = 0u;
//start all the rtapp
for (uint32 n = 0u; (ret) && (n < nOfObjs); n++) {
ReferenceT<RealTimeApplication> rtApp = objDb->Get(n);
if (rtApp.IsValid()) {
ret.initialisationError = !rtApps.Insert(rtApp);
if (ret.ErrorsCleared()) {
ret.initialisationError = !rtApp->ConfigureApplication();
if (!ret) {
REPORT_ERROR_STATIC(ErrorManagement::ParametersError, "Failed to Configure RealTimeApplication");
}
}
found++;
}
}
if (found > 0u) {
if (data.Read("FirstState", firstState)) {
}
}
else {
REPORT_ERROR_STATIC(ErrorManagement::ParametersError, "Could not find a RealTimeApplication");
ret = ErrorManagement::ParametersError;
}
return ret;
}
ErrorManagement::ErrorType RealTimeLoader::Start() {
ErrorManagement::ErrorType err;
uint32 nApps = rtApps.Size();
(void) firstState.Seek(0ull);
if (firstState.Size() > 0u) {
for (uint32 i = 0u; (err.ErrorsCleared()) && (i < nApps); i++) {
ReferenceT<RealTimeApplication> rtApp = rtApps.Get(i);
StreamString destination;
char8 term;
err.fatalError = !firstState.GetToken(destination, ":", term);
if (err.ErrorsCleared()) {
REPORT_ERROR_STATIC(ErrorManagement::Information, "Preparing state %s ", destination.Buffer());
err.initialisationError = !rtApp->PrepareNextState(destination.Buffer());
if (err.ErrorsCleared()) {
err = rtApp->StartNextStateExecution();
if (err.ErrorsCleared()) {
REPORT_ERROR_STATIC(ErrorManagement::Information, "Started application in state %s ", destination.Buffer());
}
else {
REPORT_ERROR_STATIC(err, "Failed to StartNextStateExecution for state %s ", destination.Buffer());
}
}
else {
REPORT_ERROR_STATIC(err, "Failed to PrepareNextState for state %s ", destination.Buffer());
}
}
else {
const uint32 ii = i;
REPORT_ERROR_STATIC(err, "Failed to get the first state for the application %d ", ii);
}
}
}
else {
err = Loader::Start();
}
return err;
}
ErrorManagement::ErrorType RealTimeLoader::Stop() {
ErrorManagement::ErrorType ret = true;
uint32 nApps = rtApps.Size();
if (ret.ErrorsCleared()) {
for (uint32 i = 0u; (ret.ErrorsCleared()) && (i < nApps); i++) {
ReferenceT<RealTimeApplication> rtApp = rtApps.Get(i);
ret = rtApp->StopCurrentStateExecution();
if (!ret.ErrorsCleared()) {
REPORT_ERROR_STATIC(ErrorManagement::FatalError, "Failed to StopCurrentStateExecution");
}
}
}
if (ret.ErrorsCleared()) {
ret = Loader::Stop();
}
return ret;
}
CLASS_REGISTER(RealTimeLoader, "")
}