Syed Aoun Raza | 93c20df | 2017-08-18 15:59:16 +0200 | [diff] [blame] | 1 | /**
|
Harald Mackamul | ddb243a | 2018-07-09 11:10:10 +0200 | [diff] [blame] | 2 | ********************************************************************************
|
Syed Aoun Raza | 4a34ae9 | 2020-02-21 18:38:33 +0100 | [diff] [blame^] | 3 | * Copyright (c) 2017-2020 Robert Bosch GmbH and others.
|
Harald Mackamul | ddb243a | 2018-07-09 11:10:10 +0200 | [diff] [blame] | 4 | *
|
| 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 Raza | 93c20df | 2017-08-18 15:59:16 +0200 | [diff] [blame] | 11 | * Contributors:
|
| 12 | * Robert Bosch GmbH - initial API and implementation
|
Harald Mackamul | ddb243a | 2018-07-09 11:10:10 +0200 | [diff] [blame] | 13 | ********************************************************************************
|
Syed Aoun Raza | 93c20df | 2017-08-18 15:59:16 +0200 | [diff] [blame] | 14 | */
|
| 15 | package org.eclipse.app4mc.sca2amalthea.exporter;
|
| 16 |
|
| 17 | import java.util.List;
|
| 18 |
|
| 19 | import org.eclipse.app4mc.amalthea.model.Amalthea;
|
| 20 | import org.eclipse.app4mc.amalthea.model.AmaltheaFactory;
|
| 21 | import org.eclipse.app4mc.amalthea.model.IAnnotatable;
|
| 22 | import org.eclipse.app4mc.amalthea.model.OSModel;
|
| 23 | import org.eclipse.app4mc.amalthea.model.Semaphore;
|
| 24 | import org.eclipse.app4mc.sca.amalthea.model.utils.helper.CustomPropertiesUtil;
|
| 25 | import org.eclipse.app4mc.sca2amalthea.exporter.locks.LockDefinition;
|
| 26 | import org.eclipse.app4mc.sca2amalthea.exporter.locks.LockFunction;
|
| 27 | import 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 | */
|
| 32 | public 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 | }
|