blob: 72281823500c6b45be92b795778cd3b006efdf5d [file] [log] [blame]
Syed Aoun Raza93c20df2017-08-18 15:59:16 +02001/**
Harald Mackamulddb243a2018-07-09 11:10:10 +02002 ********************************************************************************
Syed Aoun Raza4a34ae92020-02-21 18:38:33 +01003 * Copyright (c) 2017-2020 Robert Bosch GmbH and others.
Harald Mackamulddb243a2018-07-09 11:10:10 +02004 *
5 * This program and the accompanying materials are made
6 * available under the terms of the Eclipse Public License 2.0
7 * which is available at https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
Syed Aoun Raza93c20df2017-08-18 15:59:16 +020011 * Contributors:
12 * Robert Bosch GmbH - initial API and implementation
Harald Mackamulddb243a2018-07-09 11:10:10 +020013 ********************************************************************************
Syed Aoun Raza93c20df2017-08-18 15:59:16 +020014 */
15package org.eclipse.app4mc.sca2amalthea.exporter;
16
17import java.util.List;
18
19import org.eclipse.app4mc.amalthea.model.Amalthea;
20import org.eclipse.app4mc.amalthea.model.AmaltheaFactory;
21import org.eclipse.app4mc.amalthea.model.IAnnotatable;
22import org.eclipse.app4mc.amalthea.model.OSModel;
23import org.eclipse.app4mc.amalthea.model.Semaphore;
24import org.eclipse.app4mc.sca.amalthea.model.utils.helper.CustomPropertiesUtil;
25import org.eclipse.app4mc.sca2amalthea.exporter.locks.LockDefinition;
26import org.eclipse.app4mc.sca2amalthea.exporter.locks.LockFunction;
27import org.eclipse.app4mc.sca2amalthea.exporter.util.CustomPropertiesAdder;
28
29/**
30 * This class transforms an AMALHTEA OsModel. Right now only the Semaphore definition is part of this OsModel
31 */
32public class OsModelTransformer {
33
34 private final TransformerDataStore dataStore;
35
36 /**
37 * Constructor
38 *
39 * @param dataStore
40 */
41 public OsModelTransformer(final TransformerDataStore dataStore) {
42 super();
43 this.dataStore = dataStore;
44 }
45
46 /**
47 * This function creates OSModel and also initializes the global {@link #data.getSemaMap()}
48 *
49 * @param amaltheaModel
50 * @param lockDefintion
51 */
52 public void transform(final Amalthea amaltheaModel, final LockDefinition lockDefintion) {
53 if(lockDefintion!=null && lockDefintion.getLockFunctions().size()!=0){
54 OSModel osModel = AmaltheaFactory.eINSTANCE.createOSModel();
55 amaltheaModel.setOsModel(osModel);
56 createSemaphoresFillMap(lockDefintion, osModel);
57 }
58 }
59
60 /**
61 * @param lockDefintion
62 * @param osModel
63 */
64 private void createSemaphoresFillMap(final LockDefinition lockDefintion, final OSModel osModel) {
65 List<LockFunction> lockFunctions = lockDefintion.getLockFunctions();
66 for (LockFunction lockFunction : lockFunctions) {
67 Semaphore semaphore = AmaltheaFactory.eINSTANCE.createSemaphore();
68 semaphore.setName(lockFunction.getName());
69 semaphore.setInitialValue(0);
70 semaphore.setMaxValue(1);
71 String getLockFunctionName = lockFunction.getGetLockFunction();
72 String releaseLockFunctionName = lockFunction.getReleaseLockFunction();
73 addSemaphoreFunctions(semaphore, getLockFunctionName, releaseLockFunctionName);
74 CustomPropertiesUtil.addToCustomProperties(semaphore, CustomPropertiesAdder.LOCK_TYPE,
75 lockFunction.getLockType().name());
76 osModel.getSemaphores().add(semaphore);
77 this.dataStore.getSemaMap().put(getLockFunctionName, semaphore);
78 this.dataStore.getSemaMap().put(releaseLockFunctionName, semaphore);
79 }
80 }
81
82 /**
83 * @param amBaseObject
84 * @param getLockFunctionName
85 * @param releaseLockFunctionName
86 */
87 private void addSemaphoreFunctions(final IAnnotatable amBaseObject, final String getLockFunctionName,
88 final String releaseLockFunctionName) {
89 CustomPropertiesUtil.addToCustomProperties(amBaseObject, CustomPropertiesAdder.GET_LOCK_FUNC_NAME,
90 getLockFunctionName);
91 CustomPropertiesUtil.addToCustomProperties(amBaseObject, CustomPropertiesAdder.RELEASE_LOCK_FUNC_NAME,
92 releaseLockFunctionName);
93 }
94
95
96}