Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5c205ff64ceb055af3e7ad9de48c18d0b281863c (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
/*******************************************************************************
 * Copyright (c) 2011 Draeger Medical GmbH (http://www.draeger.com).
 * 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:
 * 		Peter Karlitschek (initial contribution)
 *
 *******************************************************************************/
package org.eclipse.etrice.generator.cpp.gen

import com.google.inject.Inject
import com.google.inject.Singleton
import org.eclipse.etrice.core.etmap.util.ETMapUtil
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
import org.eclipse.etrice.core.genmodel.etricegen.SystemInstance
import org.eclipse.etrice.generator.cpp.Main
import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers
import org.eclipse.etrice.generator.fsm.base.IGeneratorFileIo
import org.eclipse.etrice.generator.generic.RoomExtensions

@Singleton
class NodeRunnerGen {

	@Inject extension RoomExtensions roomExt
	@Inject extension CppExtensions
	@Inject extension FileSystemHelpers

	@Inject IGeneratorFileIo fileIO

	def doGenerate(Root root) {
		for (nr : ETMapUtil::getNodeRefs()) {
			for (instpath : ETMapUtil::getSubSystemInstancePaths(nr)) {
				val ssi = root.getInstance(instpath) as SubSystemInstance
				if (ssi!=null && ssi.subSystemClass.validGenerationLocation) {
					val filepath = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath
					val infopath = ssi.subSystemClass.generationInfoPath+ssi.subSystemClass.getPath
					fileIO.generateFile("generating SubSystemRunner declaration", filepath, infopath, nr.getCppClassName(ssi)+"Runner.h", root.generateHeaderFile(ssi))
					fileIO.generateFile("generating SubSystemRunner implementation", filepath, infopath, nr.getCppClassName(ssi)+"Runner.cpp", root.generateSourceFile(ssi))
				}
			}
		}
	}

	def generateHeaderFile(Root root, SubSystemInstance ssc) {
		val cc = ssc.subSystemClass
		val nr = ETMapUtil::getNodeRef(ssc)
		val clsname = nr.getCppClassName(ssc)
		'''
			/**
			 * @author generated by eTrice
			 *
			 * this class contains the main function running component «ssc.name»
			 * it instantiates «ssc.name» and starts and ends the lifecycle
			 */

			«generateIncludeGuardBegin(cc, 'Runner')»

			«cc.generateNamespaceBegin»

			#include "common/modelbase/SubSystemRunnerBase.h"

			class «clsname+"Runner"» : public etRuntime::SubSystemRunnerBase {

			};

			«cc.generateNamespaceEnd»

			«generateIncludeGuardEnd(cc, 'Runner')»
		'''
	}

	def generateSourceFile(Root root, SubSystemInstance ssc) {
		val cc = ssc.subSystemClass
		val nr = ETMapUtil::getNodeRef(ssc)
		val clsname = nr.getCppClassName(ssc)
		'''
			/**
			 * @author generated by eTrice
			 *
			 * this class contains the main function running component «ssc.name»
			 * it instantiates «ssc.name» and starts and ends the lifecycle
			 */


			#include "«clsname»Runner.h"

			#include "«clsname».h"
			#include "common/modelbase/RTSystem.h"

			using namespace etRuntime;

			«cc.generateNamespaceBegin»

			/**
			 * «Main.getSettings.mainMethodName» function
			 * creates components and starts and stops the lifecycle
			 */
			int «Main.getSettings.mainMethodName»(int argc, char* argv[]) {
				// instantiate the main component
				RTSystem* sys = «IF ssc.eContainer instanceof SystemInstance»new RTSystem("«(ssc.eContainer as SystemInstance).name»")«ELSE»0«ENDIF»;
				«clsname»* main_component = new «clsname»(sys, "«ssc.name»");

				«clsname»Runner::run(*main_component, argc, argv);

«««				// TODO JH crash
				//delete sys;

				return 0;
			}

			«cc.generateNamespaceEnd»

		'''
	}
}

Back to the top