Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 265cc8df57834c768158f3048c567b9961e82281 (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
/*******************************************************************************
 * Copyright (c) 2012 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)
 * 
 *******************************************************************************/

package org.eclipse.etrice.generator.generic

import com.google.inject.Inject
import java.util.ArrayList
import org.eclipse.etrice.core.room.ProtocolClass
import org.eclipse.etrice.core.room.Port
import org.eclipse.etrice.core.room.InterfaceItem
import org.eclipse.etrice.core.room.SAPRef
import org.eclipse.etrice.core.room.SPPRef
import org.eclipse.etrice.core.room.Message
import org.eclipse.etrice.core.room.MessageFromIf
import org.eclipse.etrice.generator.extensions.RoomExtensions
import org.eclipse.xtext.util.Pair
import static org.eclipse.xtext.util.Tuples.*


class GenericProtocolClassGenerator {

	@Inject extension ILanguageExtension langExt
	@Inject extension RoomExtensions roomExt

	def genMessageIDs(ProtocolClass pc) {
		var offset = 0
		
		var list = new ArrayList<Pair<String, String>>()
		list.add(pair(memberInDeclaration(pc.name, "MSG_MIN"), offset.toString))
		for (msg : pc.allOutgoingMessages) {
			offset = offset+1
			list.add(pair(memberInDeclaration(pc.name, "OUT_"+msg.name), offset.toString))
		}
		for (msg : pc.allIncomingMessages) {
			offset = offset+1
			list.add(pair(memberInDeclaration(pc.name, "IN_"+msg.name), offset.toString))
		}
		offset = offset+1
		list.add(pair(memberInDeclaration(pc.name, "MSG_MAX"), offset.toString))
		
		return langExt.genEnumeration("msg_ids", list)
	}
	
	def getMessageID(MessageFromIf mif) {
		return getMessageID(mif.message, mif.from)
	}
	
	def getMessageID(Message msg, InterfaceItem item) {
		if (item instanceof Port) {
			var p = item as Port;
			var direction = if (p.isConjugated())"OUT_" else "IN_"
			return memberInUse(p.getProtocol().getName(), direction+msg.getName())
		}
		else if (item instanceof SAPRef) {
			var sap = item as SAPRef;
			return memberInUse(sap.getProtocol().getName(), "OUT_"+msg.getName())
		}
		else if (item instanceof SPPRef) {
			var spp = item as SPPRef;
			return memberInUse(spp.getProtocol().getName(), "IN_"+msg.getName())
		}

		return "unknown interface item";
	}
}

Back to the top