blob: 7dfb405646a7e867e8724b4fab81678d334d90a8 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Robert Bosch GmbH.
* 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:
* Robert Bosch GmbH - initial API and implementation
*******************************************************************************/
package app4mc.example.transform.m2m.transformers
import app4mc.example.transform.samplemodel.Model
import org.eclipse.app4mc.amalthea.model.Cache
import org.eclipse.app4mc.amalthea.model.HWModel
import org.eclipse.app4mc.amalthea.model.Memory
import org.eclipse.app4mc.amalthea.model.ProcessingUnit
import org.eclipse.app4mc.amalthea.model.StructureType
import org.eclipse.app4mc.transformation.ServiceConstants
import org.eclipse.app4mc.transformation.transformers.AbstractTransformer
import org.osgi.service.component.annotations.Activate
import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.ConfigurationPolicy
import org.osgi.service.component.annotations.Reference
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@Component(configurationPid = ServiceConstants.SESSION_CONFIGURATION_PID,
configurationPolicy = ConfigurationPolicy.REQUIRE,
service = #[HWTransformer,AbstractTransformer])
class HWTransformer extends AbstractTransformer {
static final Logger LOG = LoggerFactory.getLogger(typeof(HWTransformer))
@Reference MemoryTransformer memoryTransformer
@Reference CacheTransformer cacheTransformer
@Reference ProcessingUnitTransformer processingUnitTransformer
@Activate
def package void activate() {
LOG.debug("HWTransformer activated : "+this.hashCode)
}
def transfromHWModel(HWModel hwModel, Model outputModel) {
// Getting all caches
val structures = hwModel.structures
for (hwStructureTypeSystem : structures) {
if (hwStructureTypeSystem.structureType == StructureType.SYSTEM) {
val hwStructuresOfTypeECU = hwStructureTypeSystem.structures
for (hwStructureECU : hwStructuresOfTypeECU) {
if (hwStructureECU.structureType == StructureType.ECU) {
val hwStructuresOfTypeMC = hwStructureECU.structures
for (hwStructureMC : hwStructuresOfTypeMC) {
if (hwStructureMC.structureType == StructureType.MICROCONTROLLER) {
val hwModules = hwStructureMC.modules
hwModules.forEach [ hwModule |
if (hwModule instanceof Cache) {
// global cache : object creation
val outputCache = cacheTransformer.transfromCache(hwModule)
outputModel.caches.add(outputCache)
}
else if (hwModule instanceof Memory) {
val outputMemory = memoryTransformer.transfromMemory(hwModule as Memory)
outputModel.memories.add(outputMemory as app4mc.example.transform.samplemodel.Memory)
}
else if (hwModule instanceof ProcessingUnit) {
LOG.info("Transforming PU : " + hwModule)
processingUnitTransformer.transfromProcessingUnit(hwModule,outputModel)
}
]
}
}
}
}
}
}
}
}