Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 98490915d9878a8fb846b5c9103f8eb946d14009 (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
/*******************************************************************************
 * 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
import org.eclipse.etrice.core.common.base.util.BaseHelpers
import org.eclipse.etrice.generator.c.Main
import org.eclipse.etrice.generator.c.setup.GeneratorOptionsHelper

@Singleton
class NodeRunnerGen {

	@Inject extension BaseHelpers
	@Inject extension JavaIoFileSystemAccess fileAccess
	@Inject extension CExtensions
	@Inject extension RoomExtensions
	@Inject protected extension GeneratorOptionsHelper
	
	def doGenerate(Root root) {
		var first = true
		for (nr : ETMapUtil::getNodeRefs()) {
			for (instpath : ETMapUtil::getSubSystemInstancePaths(nr)) {
				val ssi = root.getInstance(instpath) as SubSystemInstance
				if (ssi!==null) {
					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
	val logData = Main.getSettings.isGenerateDataInstrumentation && ssi.subSystemClass.annotations.isAnnotationPresent("DataLogging")
	'''
		/**
		 * @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 <string.h>
		
		#include "nr.getCHeaderFileName(ssi)"

		#include "debugging/etLogger.h"
		#include "debugging/etMSCLogger.h"
		#include "debugging/etDataLogger.h"
		
		#include "osal/etPlatformLifecycle.h"
		
		/**
		 * Main.getSettings.mainMethodName function
		 * creates components and starts and stops the lifecycle
		 */
		
		int Main.getSettings.mainMethodName(int argc, char** argv) {
			etBool runAsTest = ET_FALSE;
		
		#ifdef ET_DO_NOT_USE_ARGC_ARGV
		#else
			if (argc>1 && strcmp(argv[1], "-headless")==0)
				runAsTest = ET_TRUE;
			if (argc>1 && strcmp(argv[1], "-run_as_test")==0)
				runAsTest = ET_TRUE;
		#endif		
		
			etUserEntry(); /* platform specific */
			
			etLogger_logInfo("***   T H E   B E G I N   ***");
			ET_MSC_LOGGER_OPEN("main");
			IF logData
				ET_DATA_LOGGER_OPEN("main");
			ENDIF
		
			/* startup sequence  of lifecycle */
			clsname_init(); 		/* lifecycle init */
			clsname_start(); 	/* lifecycle start */
		
			etUserPreRun(); /* platform specific */

			/* run Scheduler */
			clsname_run(runAsTest);
		
			etUserPostRun(); /* platform specific */

			/* shutdown sequence of lifecycle */
			clsname_stop(); 		/* lifecycle stop */
			clsname_destroy(); 	/* lifecycle destroy */
		
			IF logData
				ET_DATA_LOGGER_CLOSE
			ENDIF
			ET_MSC_LOGGER_CLOSE
			etLogger_logInfo("***   T H E   E N D   ***");
		
			etUserExit(); /* platform specific */
		
			return 0;
		}
		
	'''
	}	
}

Back to the top