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
|
/*******************************************************************************
* 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.room.ActorClass
import org.eclipse.etrice.generator.base.ILogger
import org.eclipse.etrice.generator.etricegen.ExpandedActorClass
import org.eclipse.etrice.generator.etricegen.Root
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
import org.eclipse.etrice.generator.extensions.RoomExtensions
import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.generator.generic.TypeHelpers
import org.eclipse.etrice.generator.generic.GenericActorClassGenerator
@Singleton
class ActorClassGen extends GenericActorClassGenerator {
@Inject extension JavaIoFileSystemAccess fileAccess
@Inject extension CExtensions stdExt
@Inject extension RoomExtensions roomExt
@Inject extension ProcedureHelpers helpers
@Inject extension TypeHelpers
@Inject extension StateMachineGen stateMachineGen
@Inject ILogger logger
def doGenerate(Root root) {
for (xpac: root.xpActorClasses) {
var path = xpac.actorClass.generationTargetPath+xpac.actorClass.getPath
// header file
logger.logInfo("generating ActorClass header '"+xpac.actorClass.getCHeaderFileName+"' in '"+path+"'")
fileAccess.setOutputPath(path)
fileAccess.generateFile(xpac.actorClass.getCHeaderFileName, root.generateHeaderFile(xpac, xpac.actorClass))
// source file
if (hasBehaviorAnnotation(xpac, "BehaviorManual")) {
logger.logInfo("omitting ActorClass source for '"+xpac.actorClass.name+"' since @BehaviorManual is specified")
}
else {
logger.logInfo("generating ActorClass source '"+xpac.actorClass.getCSourceFileName +"' in '"+path+"'")
fileAccess.setOutputPath(path)
fileAccess.generateFile(xpac.actorClass.getCSourceFileName , root.generateSourceFile(xpac, xpac.actorClass))
}
}
}
def hasBehaviorAnnotation(ExpandedActorClass xpac, String annotation) {
if (xpac.actorClass.annotations != null){
if(xpac.actorClass.annotations.findFirst(e|e.name == annotation) != null){
return true;
}
}
return false;
}
def generateHeaderFile(Root root, ExpandedActorClass xpac, ActorClass ac) {'''
/**
* @author generated by eTrice
*
* Header File of ActorClass «xpac.name»
*
*/
«generateIncludeGuardBegin(xpac.name)»
#include "etDatatypes.h"
#include "etMessage.h"
«FOR dataClass : root.getReferencedDataClasses(ac)»
#include "«dataClass.name».h"
«ENDFOR»
«FOR pc : root.getReferencedProtocolClasses(ac)»
#include "«pc.name».h"
«ENDFOR»
«helpers.userCode(ac.userCode1)»
typedef struct «xpac.name» «xpac.name»;
/* const part of ActorClass (ROM) */
«IF ac.allEndPorts.empty»
/* this actor class has no ports and thus no constant data */
«ELSE»
typedef struct «xpac.name»_const {
/* simple ports */
«FOR ep : ac.allEndPorts»
«IF ep.multiplicity==1»
const «ep.getPortClassName()» «ep.name»;
«ENDIF»
«ENDFOR»
/* replicated ports */
«FOR ep : ac.allEndPorts»
«IF ep.multiplicity!=1»
const etReplPort «ep.name»;
«ENDIF»
«ENDFOR»
} «xpac.name»_const;
«ENDIF»
/* variable part of ActorClass (RAM) */
struct «xpac.name» {
«IF !ac.allEndPorts.empty»
const «xpac.name»_const* constData;
«ENDIF»
«helpers.attributes(ac.allAttributes)»
«IF xpac.hasNonEmptyStateMachine»
«stateMachineGen.genDataMembers(xpac, ac)»
«ENDIF»
};
void «xpac.name»_init(«xpac.name»* self);
void «xpac.name»_ReceiveMessage(void* self, void* ifitem, const etMessage* msg);
«helpers.userCode(ac.userCode2)»
«generateIncludeGuardEnd(xpac.name)»
'''
}
def generateSourceFile(Root root, ExpandedActorClass xpac, ActorClass ac) {'''
/**
* @author generated by eTrice
*
* Source File of ActorClass «xpac.name»
*
*/
#include "«xpac.getCHeaderFileName»"
#include "etActor.h"
#include "etLogger.h"
#include "etMSCLogger.h"
«FOR pc : root.getReferencedProtocolClasses(ac)»
#include "«pc.getCHeaderFileName»"
«ENDFOR»
«helpers.userCode(ac.userCode3)»
/* interface item IDs */
«genInterfaceItemConstants(xpac, ac)»
«IF xpac.hasNonEmptyStateMachine»
«stateMachineGen.genStateMachine(xpac, ac)»
«ENDIF»
void «xpac.name»_init(«xpac.name»* self){
ET_MSC_LOGGER_SYNC_ENTRY("«xpac.name»", "init")
«IF xpac.hasNonEmptyStateMachine»
«stateMachineGen.genInitialization(xpac, ac)»
«ENDIF»
ET_MSC_LOGGER_SYNC_EXIT
}
void «xpac.name»_ReceiveMessage(void* self, void* ifitem, const etMessage* msg){
ET_MSC_LOGGER_SYNC_ENTRY("«xpac.name»", "ReceiveMessage")
«IF xpac.hasNonEmptyStateMachine»
receiveEvent(self, (etPort*)ifitem, msg->evtID, (void*)(&msg[1]));
«ENDIF»
ET_MSC_LOGGER_SYNC_EXIT
}
'''
}
}
|