Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 099b075f52c8a08c72569b8ded5cf8fd2a907de0 (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
/*******************************************************************************
 * 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.inject.Inject
import com.google.inject.Singleton
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.core.etmap.util.ETMapUtil

@Singleton
class NodeRunnerGen {

	@Inject extension JavaIoFileSystemAccess fileAccess
	@Inject extension CExtensions
	@Inject extension RoomExtensions
	
	def doGenerate(Root root) {
		var first = true
		for (nr : ETMapUtil::getNodeRefs()) {
			for (instpath : ETMapUtil::getSubSystemInstancePaths(nr)) {
				val ssi = root.getInstance(instpath) as SubSystemInstance
				val clsname = nr.name+"_"+ssi.name
				fileAccess.setOutputPath(ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath)
				fileAccess.generateFile( clsname+"_Runner.c", root.generateSourceFile(ssi, first))
				first = false
			}
		}
	}
	
	def generateSourceFile(Root root, SubSystemInstance ssi, boolean first) {
	val nr = ETMapUtil::getNodeRef(ssi)
	val clsname = nr.name+"_"+ssi.name
	'''
		/**
		 * @author generated by eTrice
		 *
		 * this class contains the main function running Node «nr.name» with SubSystem «ssi.name»
		 * it instantiates Node «nr.name» with SubSystem «ssi.name» and starts and ends the lifecycle
		 */
		
		
		#include "«nr.getCHeaderFileName(ssi)»"

		#include "debugging/etLogger.h"
		#include "debugging/etMSCLogger.h"
		#include "platform/etPlatform.h"
		
		
		/**
		 * main function
		 * creates component and starts and stops the lifecycle
		 */
		
		«IF first»
		int main(void) {
		«ELSE»
		static int main_unused(void) {
		«ENDIF»
			etUserEntry(); /* platform specific */
			
			etLogger_logInfo("***   T H E   B E G I N   ***");
			ET_MSC_LOGGER_OPEN("main");
		
			/* startup sequence  of lifecycle */
			«clsname»_init(); 		/* lifecycle init */
			«clsname»_start(); 	/* lifecycle start */
		
			etUserPreRun(); /* platform specific */

			/* run Scheduler */
			«clsname»_run();
		
			etUserPostRun(); /* platform specific */

			/* shutdown sequence of lifecycle */
			«clsname»_stop(); 		/* lifecycle stop */
			«clsname»_destroy(); 	/* lifecycle destroy */
		
			ET_MSC_LOGGER_CLOSE
			etLogger_logInfo("***   T H E   E N D   ***");
		
			etUserExit(); /* platform specific */
		
			return 0;
		}
		
	'''
	}	
}

Back to the top