Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 244121ba33075dbec61a7d0e9f2e564824e8d8c6 (plain) (blame)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/**
 * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * CONTRIBUTORS:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 		Thomas Schuetz (changed for C code generator)
 */
package org.eclipse.etrice.generator.c.gen;

import com.google.common.base.Objects;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Collection;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.etrice.core.common.base.Annotation;
import org.eclipse.etrice.core.common.base.util.BaseHelpers;
import org.eclipse.etrice.core.etmap.util.ETMapUtil;
import org.eclipse.etrice.core.etphys.eTPhys.NodeRef;
import org.eclipse.etrice.core.genmodel.etricegen.Root;
import org.eclipse.etrice.core.genmodel.etricegen.StructureInstance;
import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance;
import org.eclipse.etrice.core.room.SubSystemClass;
import org.eclipse.etrice.generator.base.GlobalGeneratorSettings;
import org.eclipse.etrice.generator.c.Main;
import org.eclipse.etrice.generator.c.gen.CExtensions;
import org.eclipse.etrice.generator.generic.RoomExtensions;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
import org.eclipse.xtext.xbase.lib.Extension;

@Singleton
@SuppressWarnings("all")
public class NodeRunnerGen {
  @Inject
  @Extension
  private BaseHelpers _baseHelpers;
  
  @Inject
  @Extension
  private JavaIoFileSystemAccess fileAccess;
  
  @Inject
  @Extension
  private CExtensions _cExtensions;
  
  @Inject
  @Extension
  private RoomExtensions _roomExtensions;
  
  public void doGenerate(final Root root) {
    boolean first = true;
    Collection<NodeRef> _nodeRefs = ETMapUtil.getNodeRefs();
    for (final NodeRef nr : _nodeRefs) {
      List<String> _subSystemInstancePaths = ETMapUtil.getSubSystemInstancePaths(nr);
      for (final String instpath : _subSystemInstancePaths) {
        {
          StructureInstance _instance = root.getInstance(instpath);
          final SubSystemInstance ssi = ((SubSystemInstance) _instance);
          boolean _notEquals = (!Objects.equal(ssi, null));
          if (_notEquals) {
            String _name = nr.getName();
            String _plus = (_name + "_");
            String _name_1 = ssi.getName();
            final String clsname = (_plus + _name_1);
            SubSystemClass _subSystemClass = ssi.getSubSystemClass();
            String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(_subSystemClass);
            SubSystemClass _subSystemClass_1 = ssi.getSubSystemClass();
            String _path = this._roomExtensions.getPath(_subSystemClass_1);
            String _plus_1 = (_generationTargetPath + _path);
            this.fileAccess.setOutputPath(_plus_1);
            CharSequence _generateSourceFile = this.generateSourceFile(root, ssi, first);
            this.fileAccess.generateFile((clsname + "_Runner.c"), _generateSourceFile);
            first = false;
          }
        }
      }
    }
  }
  
  public CharSequence generateSourceFile(final Root root, final SubSystemInstance ssi, final boolean first) {
    CharSequence _xblockexpression = null;
    {
      final NodeRef nr = ETMapUtil.getNodeRef(ssi);
      String _name = nr.getName();
      String _plus = (_name + "_");
      String _name_1 = ssi.getName();
      final String clsname = (_plus + _name_1);
      boolean _and = false;
      GlobalGeneratorSettings _settings = Main.getSettings();
      boolean _isGenerateDataInstrumentation = _settings.isGenerateDataInstrumentation();
      if (!_isGenerateDataInstrumentation) {
        _and = false;
      } else {
        SubSystemClass _subSystemClass = ssi.getSubSystemClass();
        EList<Annotation> _annotations = _subSystemClass.getAnnotations();
        boolean _isAnnotationPresent = this._baseHelpers.isAnnotationPresent(_annotations, "DataLogging");
        _and = _isAnnotationPresent;
      }
      final boolean logData = _and;
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* @author generated by eTrice");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("*");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* this class contains the main function running Node ");
      String _name_2 = nr.getName();
      _builder.append(_name_2, " ");
      _builder.append(" with SubSystem ");
      String _name_3 = ssi.getName();
      _builder.append(_name_3, " ");
      _builder.newLineIfNotEmpty();
      _builder.append(" ");
      _builder.append("* it instantiates Node ");
      String _name_4 = nr.getName();
      _builder.append(_name_4, " ");
      _builder.append(" with SubSystem ");
      String _name_5 = ssi.getName();
      _builder.append(_name_5, " ");
      _builder.append(" and starts and ends the lifecycle");
      _builder.newLineIfNotEmpty();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.newLine();
      _builder.append("#include <string.h>");
      _builder.newLine();
      _builder.newLine();
      _builder.append("#include \"");
      String _cHeaderFileName = this._cExtensions.getCHeaderFileName(nr, ssi);
      _builder.append(_cHeaderFileName, "");
      _builder.append("\"");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("#include \"debugging/etLogger.h\"");
      _builder.newLine();
      _builder.append("#include \"debugging/etMSCLogger.h\"");
      _builder.newLine();
      _builder.append("#include \"debugging/etDataLogger.h\"");
      _builder.newLine();
      _builder.newLine();
      _builder.append("#include \"osal/etPlatformLifecycle.h\"");
      _builder.newLine();
      _builder.newLine();
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* ");
      GlobalGeneratorSettings _settings_1 = Main.getSettings();
      String _mainMethodName = _settings_1.getMainMethodName();
      _builder.append(_mainMethodName, " ");
      _builder.append(" function");
      _builder.newLineIfNotEmpty();
      _builder.append(" ");
      _builder.append("* creates components and starts and stops the lifecycle");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.newLine();
      _builder.append("int ");
      GlobalGeneratorSettings _settings_2 = Main.getSettings();
      String _mainMethodName_1 = _settings_2.getMainMethodName();
      _builder.append(_mainMethodName_1, "");
      _builder.append("(int argc, char** argv) {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("etBool runAsTest = ET_FALSE;");
      _builder.newLine();
      _builder.newLine();
      _builder.append("#ifdef ET_DO_NOT_USE_ARGC_ARGV");
      _builder.newLine();
      _builder.append("#else");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("if (argc>1 && strcmp(argv[1], \"-headless\")==0)");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("runAsTest = ET_TRUE;");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("if (argc>1 && strcmp(argv[1], \"-run_as_test\")==0)");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("runAsTest = ET_TRUE;");
      _builder.newLine();
      _builder.append("#endif\t\t");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("etUserEntry(); /* platform specific */");
      _builder.newLine();
      _builder.append("\t");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("etLogger_logInfo(\"***   T H E   B E G I N   ***\");");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("ET_MSC_LOGGER_OPEN(\"main\");");
      _builder.newLine();
      {
        if (logData) {
          _builder.append("\t");
          _builder.append("ET_DATA_LOGGER_OPEN(\"main\");");
          _builder.newLine();
        }
      }
      _builder.newLine();
      _builder.append("\t");
      _builder.append("/* startup sequence  of lifecycle */");
      _builder.newLine();
      _builder.append("\t");
      _builder.append(clsname, "\t");
      _builder.append("_init(); \t\t/* lifecycle init */");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append(clsname, "\t");
      _builder.append("_start(); \t/* lifecycle start */");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("etUserPreRun(); /* platform specific */");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("/* run Scheduler */");
      _builder.newLine();
      _builder.append("\t");
      _builder.append(clsname, "\t");
      _builder.append("_run(runAsTest);");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("etUserPostRun(); /* platform specific */");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("/* shutdown sequence of lifecycle */");
      _builder.newLine();
      _builder.append("\t");
      _builder.append(clsname, "\t");
      _builder.append("_stop(); \t\t/* lifecycle stop */");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append(clsname, "\t");
      _builder.append("_destroy(); \t/* lifecycle destroy */");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      {
        if (logData) {
          _builder.append("\t");
          _builder.append("ET_DATA_LOGGER_CLOSE");
          _builder.newLine();
        }
      }
      _builder.append("\t");
      _builder.append("ET_MSC_LOGGER_CLOSE");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("etLogger_logInfo(\"***   T H E   E N D   ***\");");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("etUserExit(); /* platform specific */");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("return 0;");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _xblockexpression = _builder;
    }
    return _xblockexpression;
  }
}

Back to the top