diff options
Diffstat (limited to 'org.genivi.commonapi.core/src/org')
17 files changed, 2383 insertions, 1128 deletions
diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/DeploymentInterfacePropertyAccessorWrapper.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/DeploymentInterfacePropertyAccessorWrapper.java deleted file mode 100644 index b4f6811..0000000 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/DeploymentInterfacePropertyAccessorWrapper.java +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2013 BMW Group - * Author: Manfred Bathelt (manfred.bathelt@bmw.de) - * Author: Juergen Gehring (juergen.gehring@bmw.de) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.genivi.commonapi.core.deployment; - -import org.franca.core.franca.FEnumerationType; -import org.franca.core.franca.FInterface; -import org.franca.deploymodel.core.FDeployedInterface; -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor; - -public class DeploymentInterfacePropertyAccessorWrapper extends DeploymentInterfacePropertyAccessor { - - boolean encapsulate; - - public DeploymentInterfacePropertyAccessorWrapper(FDeployedInterface target) { - super(target); - encapsulate = (target == null); - } - - public DefaultEnumBackingType getDefaultEnumBackingType(FInterface obj) { - if(encapsulate) { - return DefaultEnumBackingType.Int32; - } - return super.getDefaultEnumBackingType(obj); - } - - public EnumBackingType getEnumBackingType (FEnumerationType obj) { - if(encapsulate) { - return EnumBackingType.Int32; - } - return super.getEnumBackingType(obj); - } -} diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/PropertyAccessor.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/PropertyAccessor.java new file mode 100644 index 0000000..b733fdf --- /dev/null +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/PropertyAccessor.java @@ -0,0 +1,255 @@ +/* Copyright (C) 2015 BMW Group + * Author: Lutz Bichler (lutz.bichler@bmw.de) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +package org.genivi.commonapi.core.deployment; + +import java.util.List; + +import org.franca.core.franca.FEnumerationType; +import org.franca.core.franca.FInterface; +import org.franca.core.franca.FMethod; +import org.franca.deploymodel.core.FDeployedInterface; +import org.franca.deploymodel.core.FDeployedProvider; +import org.franca.deploymodel.core.FDeployedTypeCollection; +import org.franca.deploymodel.dsl.fDeploy.FDInterfaceInstance; +import org.franca.deploymodel.dsl.fDeploy.FDProvider; +import org.genivi.commonapi.core.DeploymentInterfacePropertyAccessor; +import org.genivi.commonapi.core.DeploymentProviderPropertyAccessor; +import org.genivi.commonapi.core.DeploymentTypeCollectionPropertyAccessor; + +public class PropertyAccessor { + + protected static Integer defaultTimeout_ = new Integer(0); + + protected enum DeploymentType { NONE, INTERFACE, TYPE_COLLECTION, PROVIDER }; + protected DeploymentType type_; + + DeploymentInterfacePropertyAccessor interface_; + DeploymentTypeCollectionPropertyAccessor typeCollection_; + DeploymentProviderPropertyAccessor provider_; + + // The following definitions are contained in the specific accessors + // for interfaces and type collections. We will simply cast them... + public enum DefaultEnumBackingType { + UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64 + } + + public enum EnumBackingType { + UseDefault, UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64 + } + + public PropertyAccessor() { + type_ = DeploymentType.NONE; + interface_ = null; + typeCollection_ = null; + provider_ = null; + } + + public PropertyAccessor(FDeployedInterface _target) { + type_ = (_target == null ? DeploymentType.NONE : DeploymentType.INTERFACE); + interface_ = new DeploymentInterfacePropertyAccessor(_target); + typeCollection_ = null; + provider_ = null; + } + + public PropertyAccessor(FDeployedTypeCollection _target) { + type_ = (_target == null ? DeploymentType.NONE : DeploymentType.TYPE_COLLECTION); + interface_ = null; + typeCollection_ = new DeploymentTypeCollectionPropertyAccessor(_target); + provider_ = null; + } + + public PropertyAccessor(FDeployedProvider _target) { + type_ = (_target == null ? DeploymentType.NONE : DeploymentType.PROVIDER); + interface_ = null; + typeCollection_ = null; + provider_ = new DeploymentProviderPropertyAccessor(_target); + } + + public DefaultEnumBackingType getDefaultEnumBackingType(FInterface obj) { + try { + switch (type_) { + case INTERFACE: + return from(interface_.getDefaultEnumBackingType(obj)); + case TYPE_COLLECTION: + return from(typeCollection_.getDefaultEnumBackingType(obj)); + case PROVIDER: + case NONE: + default: + } + } + catch (java.lang.NullPointerException e) {} + return DefaultEnumBackingType.Int32; + } + + public EnumBackingType getEnumBackingType (FEnumerationType obj) { + try { + switch (type_) { + case INTERFACE: + return from(interface_.getEnumBackingType(obj)); + case TYPE_COLLECTION: + return from(typeCollection_.getEnumBackingType(obj)); + case PROVIDER: + case NONE: + default: + return EnumBackingType.Int32; + } + } + catch (java.lang.NullPointerException e) {} + return EnumBackingType.Int32; + } + + public Integer getTimeout(FMethod obj) { + try { + if (type_ == DeploymentType.INTERFACE) + return interface_.getTimeout(obj); + } + catch (java.lang.NullPointerException e) {} + return defaultTimeout_; + } + + public List<FInterface> getClientInstanceReferences (FDProvider obj) { + try { + if (type_ == DeploymentType.PROVIDER) + return provider_.getClientInstanceReferences(obj); + } + catch (java.lang.NullPointerException e) {} + return null; + } + + public String getDomain (FDInterfaceInstance obj) { + try { + if (type_ == DeploymentType.PROVIDER) + return provider_.getDomain(obj); + } + catch (java.lang.NullPointerException e) {} + return null; + } + + public String getInstanceId (FDInterfaceInstance obj) { + try { + if (type_ == DeploymentType.PROVIDER) + return provider_.getInstanceId(obj); + } + catch (java.lang.NullPointerException e) {} + return null; + } + + public Integer getDefaultMethodTimeout (FDInterfaceInstance obj) { + try { + if (type_ == DeploymentType.PROVIDER) + return provider_.getDefaultMethodTimeout(obj); + } + catch (java.lang.NullPointerException e) {} + return null; + } + + public List<String> getPreregisteredProperties (FDInterfaceInstance obj) { + try { + if (type_ == DeploymentType.PROVIDER) + return provider_.getPreregisteredProperties(obj); + } + catch (java.lang.NullPointerException e) {} + return null; + } + + private DefaultEnumBackingType from(DeploymentInterfacePropertyAccessor.DefaultEnumBackingType _source) { + switch (_source) { + case UInt8: + return DefaultEnumBackingType.UInt8; + case UInt16: + return DefaultEnumBackingType.UInt16; + case UInt32: + return DefaultEnumBackingType.UInt8; + case UInt64: + return DefaultEnumBackingType.UInt8; + case Int8: + return DefaultEnumBackingType.Int8; + case Int16: + return DefaultEnumBackingType.Int16; + case Int32: + return DefaultEnumBackingType.Int32; + case Int64: + return DefaultEnumBackingType.Int64; + default: + return DefaultEnumBackingType.Int32; + } + } + + private EnumBackingType from(DeploymentInterfacePropertyAccessor.EnumBackingType _source) { + switch (_source) { + case UInt8: + return EnumBackingType.UInt8; + case UInt16: + return EnumBackingType.UInt16; + case UInt32: + return EnumBackingType.UInt8; + case UInt64: + return EnumBackingType.UInt8; + case Int8: + return EnumBackingType.Int8; + case Int16: + return EnumBackingType.Int16; + case Int32: + return EnumBackingType.Int32; + case Int64: + return EnumBackingType.Int64; + default: + return EnumBackingType.UseDefault; + } + } + + private DefaultEnumBackingType from(DeploymentTypeCollectionPropertyAccessor.DefaultEnumBackingType _source) { + if (_source != null) { + switch (_source) { + case UInt8: + return DefaultEnumBackingType.UInt8; + case UInt16: + return DefaultEnumBackingType.UInt16; + case UInt32: + return DefaultEnumBackingType.UInt8; + case UInt64: + return DefaultEnumBackingType.UInt8; + case Int8: + return DefaultEnumBackingType.Int8; + case Int16: + return DefaultEnumBackingType.Int16; + case Int32: + return DefaultEnumBackingType.Int32; + case Int64: + return DefaultEnumBackingType.Int64; + default: + return DefaultEnumBackingType.Int32; + } + } + return DefaultEnumBackingType.Int32; + } + + private EnumBackingType from(DeploymentTypeCollectionPropertyAccessor.EnumBackingType _source) { + if (_source != null) { + switch (_source) { + case UInt8: + return EnumBackingType.UInt8; + case UInt16: + return EnumBackingType.UInt16; + case UInt32: + return EnumBackingType.UInt8; + case UInt64: + return EnumBackingType.UInt8; + case Int8: + return EnumBackingType.Int8; + case Int16: + return EnumBackingType.Int16; + case Int32: + return EnumBackingType.Int32; + case Int64: + return EnumBackingType.Int64; + default: + return EnumBackingType.UseDefault; + } + } + return EnumBackingType.UseDefault; + } +} diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FDeployManager.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FDeployManager.java new file mode 100644 index 0000000..a6c62a9 --- /dev/null +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FDeployManager.java @@ -0,0 +1,99 @@ +package org.genivi.commonapi.core.generator; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.franca.core.dsl.FrancaImportsProvider; +import org.franca.core.utils.ImportsProvider; +import org.franca.deploymodel.dsl.FDeployImportsProvider; + +/** + * The FDeployManager loads models from fdepl files and from fidl files that are imported in a fdepl file. + * It continues to import files even it could not find all of them (e.g an unknown deployment specification). + * + * @author gutknecht + * + */ +public class FDeployManager { + + private final static String fileExtension = "fdepl"; + + private ResourceSet resourceSet; + + /** + * Map used to handle generically different model files. + */ + private static Map<String, ImportsProvider> fileHandlerRegistry = new HashMap<String, ImportsProvider>(); + + public FDeployManager() { + + resourceSet = new ResourceSetImpl(); + + // we expect fdepl files + fileHandlerRegistry.put(fileExtension, new FDeployImportsProvider()); + // allow for fidl file imports + fileHandlerRegistry.put("fidl", new FrancaImportsProvider()); + } + + /** + * + * Load the model found in the fileName. Its dependencies (imports) can be loaded subsequently. + * @param uri the URI to be loaded + * @param root the root of the model (needed for loading multiple file models) + * This has to be an absolute, hierarchical URI. + * @return the root model or null in case of an error. + */ + public EObject loadModel(URI uri, URI root) { + // resolve the input uri, in case it is a relative path + URI absURI = uri.resolve(root); + if (! uri.equals(absURI)) { + // add this pair to URI converter so that others can get the URI by its relative path + resourceSet.getURIConverter().getURIMap().put(uri, absURI); + } + + // load root model + Resource resource = null; + try { + resource = resourceSet.getResource(absURI, true); + resource.load(Collections.EMPTY_MAP); + } catch (Exception e) { + // Don't show an error message here, because code may be generated from an included fidl file. + //System.err.println("Failed to load model from : " + absURI); + return null; + } + EObject model = resource.getContents().get(0); + + // load all its imports recursively + for (Iterator<String> it = fileHandlerRegistry.get(absURI.fileExtension()).importsIterator(model); it.hasNext();) { + String importURIStr = it.next(); + URI importURI = URI.createURI(importURIStr); + URI resolvedURI = importURI.resolve(absURI); + + // add this pair to URI converter so that others can get the URI by its relative path + resourceSet.getURIConverter().getURIMap().put(importURI, resolvedURI); + //System.out.println("trying to load model " + resolvedURI); + model = loadModel(resolvedURI, root); + if(model == null) { + // something went wrong with this import, go on with the next one + continue; + } + } + return model; + } + + /** + * @return the file extension this class will deal with (.fdepl) + */ + public static String fileExtension() { + return fileExtension; + } + + +} diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend index db5f8e9..4402ac6 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend @@ -6,32 +6,33 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.genivi.commonapi.core.generator +import java.util.Collection +import java.util.HashSet import javax.inject.Inject +import org.eclipse.core.resources.IResource import org.eclipse.xtext.generator.IFileSystemAccess import org.franca.core.franca.FInterface -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor -import java.util.Collection -import java.util.HashSet import org.franca.core.franca.FMethod -import org.eclipse.core.resources.IResource +import org.franca.core.franca.FVersion +import org.genivi.commonapi.core.deployment.PropertyAccessor class FInterfaceGenerator { @Inject private extension FTypeGenerator @Inject private extension FTypeCommonAreaGenerator @Inject private extension FrancaGeneratorExtensions - def generate(FInterface fInterface, IFileSystemAccess fileSystemAccess, DeploymentInterfacePropertyAccessor deploymentAccessor, IResource modelid) { - fileSystemAccess.generateFile(fInterface.headerPath, fInterface.generateHeader(deploymentAccessor, modelid)) + def generate(FInterface fInterface, IFileSystemAccess fileSystemAccess, PropertyAccessor deploymentAccessor, IResource modelid) { + fileSystemAccess.generateFile(fInterface.headerPath, IFileSystemAccess.DEFAULT_OUTPUT, fInterface.generateHeader(modelid, deploymentAccessor)) if (fInterface.hasSourceFile) - fileSystemAccess.generateFile(fInterface.sourcePath, fInterface.generateSource(modelid)) + fileSystemAccess.generateFile(fInterface.sourcePath, IFileSystemAccess.DEFAULT_OUTPUT, fInterface.generateSource(modelid, deploymentAccessor)) } - def private generateHeader(FInterface fInterface, DeploymentInterfacePropertyAccessor deploymentAccessor, IResource modelid) ''' + def private generateHeader(FInterface fInterface, IResource modelid, PropertyAccessor deploymentAccessor) ''' «generateCommonApiLicenseHeader(fInterface, modelid)» «FTypeGenerator::generateComments(fInterface, false)» - #ifndef «fInterface.defineName»_H_ - #define «fInterface.defineName»_H_ + #ifndef «fInterface.defineName.toUpperCase»_HPP_ + #define «fInterface.defineName.toUpperCase»_HPP_ «val libraryHeaders = new HashSet<String>» «val generatedHeaders = new HashSet<String>» @@ -55,78 +56,74 @@ class FInterfaceGenerator { #undef COMMONAPI_INTERNAL_COMPILATION + «fInterface.generateVersionNamespaceBegin» «fInterface.model.generateNamespaceBeginDeclaration» - class «fInterface.elementName»«IF fInterface.base != null»: public «fInterface.base.getRelativeNameReference(fInterface)»«ENDIF» { - public: + class «fInterface.elementName»«IF fInterface.base != null» + : virtual public «fInterface.base.getTypeCollectionName(fInterface)»«ENDIF» { + public: virtual ~«fInterface.elementName»() { } - static inline const char* getInterfaceId(); + static inline const char* getInterface(); static inline CommonAPI::Version getInterfaceVersion(); «fInterface.generateFTypeDeclarations(deploymentAccessor)» }; - const char* «fInterface.elementName»::getInterfaceId() { - static const char* interfaceId = "«fInterface.fullyQualifiedName»"; - return interfaceId; + const char* «fInterface.elementName»::getInterface() { + return ("«fInterface.fullyQualifiedName»"); } CommonAPI::Version «fInterface.elementName»::getInterfaceVersion() { - return CommonAPI::Version(«fInterface.version.major», «fInterface.version.minor»); + «val FVersion itsVersion = fInterface.version» + «IF itsVersion != null» + return CommonAPI::Version(«itsVersion.major», «itsVersion.minor»); + «ELSE» + return CommonAPI::Version(0, 0); + «ENDIF» } «FOR type : fInterface.types» «FTypeGenerator::generateComments(type, false)» «type.generateFTypeInlineImplementation(fInterface, deploymentAccessor)» «ENDFOR» - «FOR method : fInterface.methods.filter[errors != null]» - «FTypeGenerator::generateComments(method, false)» - «method.errors.generateInlineImplementation(method.errors.errorName, fInterface, fInterface.elementName, deploymentAccessor)» - «ENDFOR» «fInterface.model.generateNamespaceEndDeclaration» + «fInterface.generateVersionNamespaceEnd» namespace CommonAPI { - «fInterface.generateTypeWriters(deploymentAccessor)» - «fInterface.generateVariantComparators» } - - namespace std { - //hashes for types - «fInterface.generateHashers(deploymentAccessor)» - - //hashes for error types - «FOR method : fInterface.methods.filter[errors != null]» - «method.errors.generateHash(method.errors.errorName, fInterface, deploymentAccessor)» - «ENDFOR» - } - - #endif // «fInterface.defineName»_H_ + #endif // «fInterface.defineName.toUpperCase»_HPP_ ''' - def private generateSource(FInterface fInterface, IResource modelid) ''' + def private generateSource(FInterface fInterface, IResource modelid, PropertyAccessor _accessor) ''' «generateCommonApiLicenseHeader(fInterface, modelid)» «FTypeGenerator::generateComments(fInterface, false)» #include "«fInterface.headerFile»" + «fInterface.generateVersionNamespaceBegin» «fInterface.model.generateNamespaceBeginDeclaration» + + «FOR method : fInterface.methodsWithError» + «method.errors.generateFTypeImplementation(method.containingInterface, _accessor)» + «ENDFOR» «FOR type : fInterface.types» «FTypeGenerator::generateComments(type,false)» - «type.generateFTypeImplementation(fInterface)» + «type.generateFTypeImplementation(fInterface, _accessor)» «ENDFOR» «fInterface.model.generateNamespaceEndDeclaration» + «fInterface.generateVersionNamespaceEnd» ''' def void getRequiredHeaderFiles(FInterface fInterface, Collection<String> generatedHeaders, Collection<String> libraryHeaders) { - libraryHeaders.add('CommonAPI/types.h') + libraryHeaders.add('CommonAPI/Types.hpp') if (!fInterface.methods.filter[errors != null].empty) { - libraryHeaders.addAll('CommonAPI/InputStream.h', 'CommonAPI/OutputStream.h') + libraryHeaders.addAll('CommonAPI/InputStream.hpp', 'CommonAPI/OutputStream.hpp') } if (!fInterface.managedInterfaces.empty) { generatedHeaders.add('set'); @@ -134,7 +131,7 @@ class FInterfaceGenerator { fInterface.types.forEach[addRequiredHeaders(generatedHeaders, libraryHeaders)] var Iterable<FMethod> errorMethods = fInterface.methods.filter[errors!=null] if(errorMethods.size!=0){ - libraryHeaders.addAll('CommonAPI/InputStream.h', 'CommonAPI/OutputStream.h') + libraryHeaders.addAll('CommonAPI/InputStream.hpp', 'CommonAPI/OutputStream.hpp') errorMethods.forEach[ if (errors.base != null) { errors.base.addRequiredHeaders(generatedHeaders, libraryHeaders) @@ -147,6 +144,7 @@ class FInterfaceGenerator { def private hasSourceFile(FInterface fInterface) { val hasTypeWithImplementation = fInterface.types.exists[hasImplementation] - return hasTypeWithImplementation + val hasMethodWithError = fInterface.methods.exists[hasError] + return (hasTypeWithImplementation || hasMethodWithError) } } diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend index 30480a3..664b386 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend @@ -7,34 +7,34 @@ package org.genivi.commonapi.core.generator import java.util.ArrayList +import java.util.HashSet import javax.inject.Inject +import org.eclipse.core.resources.IResource import org.eclipse.xtext.generator.IFileSystemAccess import org.franca.core.franca.FAttribute import org.franca.core.franca.FInterface import org.franca.core.franca.FMethod -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor - -import java.util.HashSet -import org.eclipse.core.resources.IResource +import org.genivi.commonapi.core.deployment.PropertyAccessor +import org.genivi.commonapi.core.preferences.PreferenceConstants class FInterfaceProxyGenerator { @Inject private extension FTypeGenerator @Inject private extension FrancaGeneratorExtensions - def generateProxy(FInterface fInterface, IFileSystemAccess fileSystemAccess, DeploymentInterfacePropertyAccessor deploymentAccessor, IResource modelid) { - fileSystemAccess.generateFile(fInterface.proxyBaseHeaderPath, fInterface.generateProxyBaseHeader(deploymentAccessor, modelid)) - fileSystemAccess.generateFile(fInterface.proxyHeaderPath, fInterface.generateProxyHeader(modelid)) + def generateProxy(FInterface fInterface, IFileSystemAccess fileSystemAccess, PropertyAccessor deploymentAccessor, IResource modelid) { + fileSystemAccess.generateFile(fInterface.proxyBaseHeaderPath, PreferenceConstants.P_OUTPUT_PROXIES, fInterface.generateProxyBaseHeader(deploymentAccessor, modelid)) + fileSystemAccess.generateFile(fInterface.proxyHeaderPath, PreferenceConstants.P_OUTPUT_PROXIES, fInterface.generateProxyHeader(modelid)) } - def private generateProxyBaseHeader(FInterface fInterface, DeploymentInterfacePropertyAccessor deploymentAccessor, IResource modelid) ''' + def private generateProxyBaseHeader(FInterface fInterface, PropertyAccessor deploymentAccessor, IResource modelid) ''' «generateCommonApiLicenseHeader(fInterface, modelid)» «FTypeGenerator::generateComments(fInterface, false)» - #ifndef «fInterface.defineName»_PROXY_BASE_H_ - #define «fInterface.defineName»_PROXY_BASE_H_ + #ifndef «fInterface.defineName»_PROXY_BASE_HPP_ + #define «fInterface.defineName»_PROXY_BASE_HPP_ - #include "«fInterface.headerFile»" + #include <«fInterface.headerPath»> «IF fInterface.base != null» - #include "«fInterface.base.proxyBaseHeaderFile»" + #include <«fInterface.base.proxyBaseHeaderPath»> «ENDIF» «val generatedHeaders = new HashSet<String>» @@ -54,18 +54,18 @@ class FInterfaceProxyGenerator { «ENDFOR» «IF !fInterface.managedInterfaces.empty» - #include <CommonAPI/ProxyManager.h> + #include <CommonAPI/ProxyManager.hpp> «ENDIF» «IF fInterface.hasAttributes» - #include <CommonAPI/Attribute.h> + #include <CommonAPI/Attribute.hpp> «ENDIF» «IF fInterface.hasBroadcasts» - #include <CommonAPI/Event.h> + #include <CommonAPI/Event.hpp> «IF fInterface.hasSelectiveBroadcasts» - #include <CommonAPI/SelectiveEvent.h> + #include <CommonAPI/SelectiveEvent.hpp> «ENDIF» «ENDIF» - #include <CommonAPI/Proxy.h> + #include <CommonAPI/Proxy.hpp> «IF !fInterface.methods.empty» #include <functional> #include <future> @@ -73,18 +73,22 @@ class FInterfaceProxyGenerator { #undef COMMONAPI_INTERNAL_COMPILATION + «fInterface.generateVersionNamespaceBegin» «fInterface.model.generateNamespaceBeginDeclaration» - class «fInterface.proxyBaseClassName»: virtual public «IF fInterface.base != null»«fInterface.base.proxyBaseClassName»«ELSE»CommonAPI::Proxy«ENDIF» { - public: + class «fInterface.proxyBaseClassName» + : virtual public «IF fInterface.base != null»«fInterface.base.getTypeCollectionName(fInterface)»ProxyBase«ELSE»CommonAPI::Proxy«ENDIF» { + public: «FOR attribute : fInterface.attributes» - typedef CommonAPI::«attribute.commonApiBaseClassname»<«attribute.getTypeName(fInterface.model)»> «attribute.className»; + typedef CommonAPI::«attribute.commonApiBaseClassname»<«attribute.getTypeName(fInterface, true)»> «attribute.className»; «ENDFOR» «FOR broadcast : fInterface.broadcasts» «IF broadcast.isSelective» - typedef CommonAPI::SelectiveEvent<«broadcast.outArgs.map[getTypeName(fInterface.model)].join(', ')»> «broadcast.className»; + typedef CommonAPI::SelectiveEvent<«broadcast.outArgs.map[getTypeName(fInterface, true)].join(', ')»> «broadcast.className»; «ELSE» - typedef CommonAPI::Event<«broadcast.outArgs.map[getTypeName(fInterface.model)].join(', ')»> «broadcast.className»; + typedef CommonAPI::Event< + «broadcast.outArgs.map[getTypeName(fInterface, true)].join(', ')» + > «broadcast.className»; «ENDIF» «ENDFOR» @@ -107,9 +111,9 @@ class FInterfaceProxyGenerator { * @invariant Fire And Forget */ «ENDIF» - virtual «method.generateDefinition» = 0; + virtual «method.generateDefinition(true)» = 0; «IF !method.isFireAndForget» - virtual «method.generateAsyncDefinition» = 0; + virtual «method.generateAsyncDefinition(true)» = 0; «ENDIF» «ENDFOR» «FOR managed : fInterface.managedInterfaces» @@ -118,20 +122,21 @@ class FInterfaceProxyGenerator { }; «fInterface.model.generateNamespaceEndDeclaration» - - #endif // «fInterface.defineName»_PROXY_BASE_H_ + «fInterface.generateVersionNamespaceEnd» + + #endif // «fInterface.defineName»_PROXY_BASE_HPP_ ''' def private generateProxyHeader(FInterface fInterface, IResource modelid) ''' «generateCommonApiLicenseHeader(fInterface, modelid)» «FTypeGenerator::generateComments(fInterface, false)» - #ifndef «fInterface.defineName»_PROXY_H_ - #define «fInterface.defineName»_PROXY_H_ + #ifndef «fInterface.defineName»_PROXY_HPP_ + #define «fInterface.defineName»_PROXY_HPP_ - #include "«fInterface.proxyBaseHeaderFile»" + #include <«fInterface.proxyBaseHeaderPath»> «IF fInterface.base != null» - #include "«fInterface.base.proxyHeaderFile»" + #include "«fInterface.base.proxyHeaderPath»" «ENDIF» #if !defined (COMMONAPI_INTERNAL_COMPILATION) @@ -139,20 +144,21 @@ class FInterfaceProxyGenerator { #endif «IF fInterface.hasAttributes» - #include <CommonAPI/AttributeExtension.h> - #include <CommonAPI/Factory.h> + #include <CommonAPI/AttributeExtension.hpp> + #include <CommonAPI/Factory.hpp> «ENDIF» #undef COMMONAPI_INTERNAL_COMPILATION + «fInterface.generateVersionNamespaceBegin» «fInterface.model.generateNamespaceBeginDeclaration» template <typename ... _AttributeExtensions> - class «fInterface.proxyClassName»: virtual public «fInterface.elementName», virtual public «fInterface.proxyBaseClassName» - «IF fInterface.base != null» - , virtual public «fInterface.base.proxyClassName»<_AttributeExtensions...> - «ENDIF» - , public _AttributeExtensions... { + class «fInterface.proxyClassName» + : virtual public «fInterface.elementName», + virtual public «fInterface.proxyBaseClassName»,«IF fInterface.base != null» + virtual public «fInterface.base.getTypeCollectionName(fInterface)»Proxy<_AttributeExtensions...>,«ENDIF» + public _AttributeExtensions... { public: «fInterface.proxyClassName»(std::shared_ptr<CommonAPI::Proxy> delegate); ~«fInterface.proxyClassName»(); @@ -196,7 +202,7 @@ class FInterfaceProxyGenerator { * "SUCCESS" or which type of error has occurred. In case of an error, ONLY the CallStatus * will be set. */ - virtual «method.generateDefinition»; + virtual «method.generateDefinition(true)»; «IF !method.isFireAndForget» /** * Calls «method.elementName» with asynchronous semantics. @@ -208,7 +214,7 @@ class FInterfaceProxyGenerator { * The std::future returned by this method will be fulfilled at arrival of the reply. * It will provide the same value for CallStatus as will be handed to the callback. */ - virtual «method.generateAsyncDefinition»; + virtual «method.generateAsyncDefinition(true)»; «ENDIF» «ENDFOR» @@ -219,22 +225,7 @@ class FInterfaceProxyGenerator { /** * Returns the CommonAPI address of the remote partner this proxy communicates with. */ - virtual std::string getAddress() const; - - /** - * Returns the domain of the remote partner this proxy communicates with. - */ - virtual const std::string& getDomain() const; - - /** - * Returns the service ID of the remote partner this proxy communicates with. - */ - virtual const std::string& getServiceId() const; - - /** - * Returns the instance ID of the remote partner this proxy communicates with. - */ - virtual const std::string& getInstanceId() const; + virtual const CommonAPI::Address &getAddress() const; /** * Returns true if the remote partner for this proxy is currently known to be available. @@ -262,11 +253,7 @@ class FInterfaceProxyGenerator { std::shared_ptr<«fInterface.proxyBaseClassName»> delegate_; }; - #ifdef WIN32 - typedef «fInterface.proxyClassName»<CommonAPI::WINDummyAttributeExtension<CommonAPI::WINDummyAttribute>> «fInterface.proxyDefaultClassName»; - #else - typedef «fInterface.proxyClassName»<> «fInterface.proxyDefaultClassName»; - #endif + typedef «fInterface.proxyClassName»<> «fInterface.proxyDefaultClassName»; «IF fInterface.hasAttributes» namespace «fInterface.extensionsSubnamespace» { @@ -296,39 +283,24 @@ class FInterfaceProxyGenerator { «FOR method : fInterface.methods» «FTypeGenerator::generateComments(method, false)» template <typename ... _AttributeExtensions> - «method.generateDefinitionWithin(fInterface.proxyClassName + '<_AttributeExtensions...>')» { + «method.generateDefinitionWithin(fInterface.proxyClassName + '<_AttributeExtensions...>', false)» { delegate_->«method.elementName»(«method.generateSyncVariableList»); } «IF !method.isFireAndForget» template <typename ... _AttributeExtensions> - «method.generateAsyncDefinitionWithin(fInterface.proxyClassName + '<_AttributeExtensions...>')» { + «method.generateAsyncDefinitionWithin(fInterface.proxyClassName + '<_AttributeExtensions...>', false)» { return delegate_->«method.elementName»Async(«method.generateASyncVariableList»); } «ENDIF» «ENDFOR» template <typename ... _AttributeExtensions> - std::string «fInterface.proxyClassName»<_AttributeExtensions...>::getAddress() const { + const CommonAPI::Address &«fInterface.proxyClassName»<_AttributeExtensions...>::getAddress() const { return delegate_->getAddress(); } template <typename ... _AttributeExtensions> - const std::string& «fInterface.proxyClassName»<_AttributeExtensions...>::getDomain() const { - return delegate_->getDomain(); - } - - template <typename ... _AttributeExtensions> - const std::string& «fInterface.proxyClassName»<_AttributeExtensions...>::getServiceId() const { - return delegate_->getServiceId(); - } - - template <typename ... _AttributeExtensions> - const std::string& «fInterface.proxyClassName»<_AttributeExtensions...>::getInstanceId() const { - return delegate_->getInstanceId(); - } - - template <typename ... _AttributeExtensions> bool «fInterface.proxyClassName»<_AttributeExtensions...>::isAvailable() const { return delegate_->isAvailable(); } @@ -356,20 +328,21 @@ class FInterfaceProxyGenerator { «ENDFOR» «fInterface.model.generateNamespaceEndDeclaration» + «fInterface.generateVersionNamespaceEnd» «IF fInterface.hasAttributes» namespace CommonAPI { template<template<typename > class _AttributeExtension> - struct DefaultAttributeProxyFactoryHelper<«fInterface.model.generateCppNamespace»«fInterface.proxyClassName», + struct DefaultAttributeProxyHelper<«fInterface.versionPrefix»«fInterface.model.generateCppNamespace»«fInterface.proxyClassName», _AttributeExtension> { - typedef typename «fInterface.model.generateCppNamespace»«fInterface.proxyClassName»< - «fInterface.attributes.map[fInterface.model.generateCppNamespace + fInterface.extensionsSubnamespace + '::' + extensionClassName + "<_AttributeExtension>"].join(", \n")» + typedef typename «fInterface.versionPrefix»«fInterface.model.generateCppNamespace»«fInterface.proxyClassName»< + «fInterface.attributes.map[fInterface.versionPrefix + fInterface.model.generateCppNamespace + fInterface.extensionsSubnamespace + '::' + extensionClassName + "<_AttributeExtension>"].join(", \n")» > class_t; }; } «ENDIF» - #endif // «fInterface.defineName»_PROXY_H_ + #endif // «fInterface.defineName»_PROXY_HPP_ ''' def private generateExtension(FAttribute fAttribute, FInterface fInterface) ''' @@ -448,21 +421,21 @@ class FInterfaceProxyGenerator { } def private generateSyncVariableList(FMethod fMethod) { - val syncVariableList = new ArrayList(fMethod.inArgs.map[elementName]) + val syncVariableList = new ArrayList(fMethod.inArgs.map['_' + elementName]) - syncVariableList.add('callStatus') + syncVariableList.add('_status') if (fMethod.hasError) - syncVariableList.add('methodError') - - syncVariableList.addAll(fMethod.outArgs.map[elementName]) + syncVariableList.add('_error') - return syncVariableList.join(', ') + syncVariableList.addAll(fMethod.outArgs.map['_' + elementName]) + + return syncVariableList.join(', ') + ", _info" } def private generateASyncVariableList(FMethod fMethod) { - var asyncVariableList = new ArrayList(fMethod.inArgs.map[elementName]) - asyncVariableList.add('callback') - return asyncVariableList.join(', ') + var asyncVariableList = new ArrayList(fMethod.inArgs.map['_' + elementName]) + asyncVariableList.add('_callback') + return asyncVariableList.join(', ') + ", _info" } } diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceStubGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceStubGenerator.xtend index a8f098b..c03b058 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceStubGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceStubGenerator.xtend @@ -1,33 +1,42 @@ -/* Copyright (C) 2013 BMW Group +/* Copyright (C) 2013, 2014 BMW Group * Author: Manfred Bathelt (manfred.bathelt@bmw.de) * Author: Juergen Gehring (juergen.gehring@bmw.de) + * Author: Lutz Bichler (lutz.bichler@bmw.de) * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.genivi.commonapi.core.generator +import java.util.HashSet import javax.inject.Inject +import org.eclipse.core.resources.IResource import org.eclipse.xtext.generator.IFileSystemAccess import org.franca.core.franca.FAttribute import org.franca.core.franca.FInterface -import java.util.HashSet -import org.eclipse.core.resources.IResource +import org.genivi.commonapi.core.preferences.PreferenceConstants +import org.genivi.commonapi.core.preferences.FPreferences class FInterfaceStubGenerator { @Inject private extension FTypeGenerator @Inject private extension FrancaGeneratorExtensions def generateStub(FInterface fInterface, IFileSystemAccess fileSystemAccess, IResource modelid) { - fileSystemAccess.generateFile(fInterface.stubHeaderPath, fInterface.generateStubHeader(modelid)) - fileSystemAccess.generateFile(fInterface.stubDefaultHeaderPath, fInterface.generateStubDefaultHeader(modelid)) - fileSystemAccess.generateFile(fInterface.stubDefaultSourcePath, fInterface.generateStubDefaultSource(modelid)) + fileSystemAccess.generateFile(fInterface.stubHeaderPath, PreferenceConstants.P_OUTPUT_STUBS, fInterface.generateStubHeader(modelid)) + // should skeleton code be generated ? + if(FPreferences::instance.getPreference(PreferenceConstants::P_GENERATESKELETON, "false").equals("true")) + { + fileSystemAccess.generateFile(fInterface.stubDefaultHeaderPath, PreferenceConstants.P_OUTPUT_SKELETON, fInterface.generateStubDefaultHeader(modelid)) + fileSystemAccess.generateFile(fInterface.stubDefaultSourcePath, PreferenceConstants.P_OUTPUT_SKELETON, fInterface.generateStubDefaultSource(modelid)) + } } def private generateStubHeader(FInterface fInterface, IResource modelid) ''' «generateCommonApiLicenseHeader(fInterface, modelid)» «FTypeGenerator::generateComments(fInterface, false)» - #ifndef «fInterface.defineName»_STUB_H_ - #define «fInterface.defineName»_STUB_H_ + #ifndef «fInterface.defineName»_STUB_HPP_ + #define «fInterface.defineName»_STUB_HPP_ + + #include <functional> «val generatedHeaders = new HashSet<String>» «val libraryHeaders = new HashSet<String>» @@ -40,7 +49,7 @@ class FInterfaceStubGenerator { #include <«requiredHeaderFile»> «ENDFOR» - #include "«fInterface.elementName».h" + #include <«fInterface.headerPath»> #if !defined (COMMONAPI_INTERNAL_COMPILATION) #define COMMONAPI_INTERNAL_COMPILATION @@ -50,10 +59,11 @@ class FInterfaceStubGenerator { #include <«requiredHeaderFile»> «ENDFOR» - #include <CommonAPI/Stub.h> + #include <CommonAPI/Stub.hpp> #undef COMMONAPI_INTERNAL_COMPILATION + «fInterface.generateVersionNamespaceBegin» «fInterface.model.generateNamespaceBeginDeclaration» /** @@ -62,17 +72,20 @@ class FInterfaceStubGenerator { * and attribute-changed-notifications of observable attributes as defined by this service. * An application developer should not need to bother with this class. */ - class «fInterface.stubAdapterClassName»: virtual public CommonAPI::StubAdapter, public «fInterface.elementName»«IF fInterface.base != null», public virtual «fInterface.base.stubAdapterClassName»«ENDIF» { + class «fInterface.stubAdapterClassName» + : virtual public CommonAPI::StubAdapter, + public «fInterface.elementName»«IF fInterface.base != null», + public virtual «fInterface.base.getTypeCollectionName(fInterface)»StubAdapter«ENDIF» { public: «FOR attribute : fInterface.attributes» «IF attribute.isObservable» ///Notifies all remote listeners about a change of value of the attribute «attribute.elementName». - virtual void «attribute.stubAdapterClassFireChangedMethodName»(const «attribute.getTypeName(fInterface.model)»& «attribute.elementName») = 0; + virtual void «attribute.stubAdapterClassFireChangedMethodName»(const «attribute.getTypeName(fInterface, true)»& «attribute.elementName») = 0; «ENDIF» «ENDFOR» «FOR broadcast : fInterface.broadcasts» - «IF !broadcast.selective.nullOrEmpty» + «IF broadcast.selective» /** * Sends a selective broadcast event for «broadcast.elementName». Should not be called directly. * Instead, the "fire<broadcastName>Event" methods of the stub should be used. @@ -87,7 +100,7 @@ class FInterfaceStubGenerator { * Sends a broadcast event for «broadcast.elementName». Should not be called directly. * Instead, the "fire<broadcastName>Event" methods of the stub should be used. */ - virtual void «broadcast.stubAdapterClassFireEventMethodName»(«broadcast.outArgs.map['const ' + getTypeName(fInterface.model) + '& ' + elementName].join(', ')») = 0; + virtual void «broadcast.stubAdapterClassFireEventMethodName»(«broadcast.outArgs.map['const ' + getTypeName(fInterface, true) + ' &_' + elementName].join(', ')») = 0; «ENDIF» «ENDFOR» @@ -104,13 +117,12 @@ class FInterfaceStubGenerator { * subscribed to the selective broadcasts */ «FOR broadcast : fInterface.broadcasts» - «IF broadcast.selective != null» + «IF broadcast.selective» std::shared_ptr<CommonAPI::ClientIdList> «broadcast.stubAdapterClassSubscriberListPropertyName»; «ENDIF» «ENDFOR» }; - /** * Defines the necessary callbacks to handle remote set events related to the attributes * defined in the IDL description for «fInterface.elementName». @@ -123,37 +135,48 @@ class FInterfaceStubGenerator { * This class and the one below are the ones an application developer needs to have * a look at if he wants to implement a service. */ - class «fInterface.stubRemoteEventClassName»«IF fInterface.base != null»: public virtual «fInterface.base.stubRemoteEventClassName»«ENDIF» { - public: + class «fInterface.stubRemoteEventClassName» + «IF fInterface.base != null» + : public virtual «fInterface.base.getTypeCollectionName(fInterface)»StubRemoteEvent + «ENDIF» + { + public: virtual ~«fInterface.stubRemoteEventClassName»() { } «FOR attribute : fInterface.attributes» «IF !attribute.readonly» /// Verification callback for remote set requests on the attribute «attribute.elementName» - virtual bool «attribute.stubRemoteEventClassSetMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId, «attribute.getTypeName(fInterface.model)» «attribute.elementName») = 0; + virtual bool «attribute.stubRemoteEventClassSetMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client, «attribute.getTypeName(fInterface, true)» «attribute.elementName») = 0; /// Action callback for remote set requests on the attribute «attribute.elementName» virtual void «attribute.stubRemoteEventClassChangedMethodName»() = 0; «ENDIF» - «ENDFOR» }; - /** * Defines the interface that must be implemented by any class that should provide * the service «fInterface.elementName» to remote clients. * This class and the one above are the ones an application developer needs to have * a look at if he wants to implement a service. */ - class «fInterface.stubClassName»: public virtual «fInterface.stubCommonAPIClassName»«IF fInterface.base != null», public virtual «fInterface.base.stubClassName»«ENDIF» { + class «fInterface.stubClassName» + : public virtual «fInterface.stubCommonAPIClassName»«IF fInterface.base != null», + public virtual «fInterface.base.getTypeCollectionName(fInterface)»Stub«ENDIF» + { public: - virtual ~«fInterface.stubClassName»() { } + «FOR method: fInterface.methods» + «IF !method.isFireAndForget» + typedef std::function<void («method.generateStubReplySignature()»)> «method.elementName»Reply_t; + «ENDIF» + «ENDFOR» + + virtual ~«fInterface.stubClassName»() {} virtual const CommonAPI::Version& getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> clientId) = 0; «FOR attribute : fInterface.attributes» «FTypeGenerator::generateComments(attribute, false)» /// Provides getter access to the attribute «attribute.elementName» - virtual const «attribute.getTypeName(fInterface.model)»& «attribute.stubClassGetMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId) = 0; + virtual const «attribute.getTypeName(fInterface, true)» &«attribute.stubClassGetMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client) = 0; «ENDFOR» «FOR method: fInterface.methods» @@ -163,7 +186,7 @@ class FInterfaceStubGenerator { «ENDFOR» «FOR broadcast : fInterface.broadcasts» «FTypeGenerator::generateComments(broadcast, false)» - «IF !broadcast.selective.nullOrEmpty» + «IF broadcast.selective» /** * Sends a selective broadcast event for «broadcast.elementName» to the given ClientIds. * The ClientIds must all be out of the set of subscribed clients. @@ -173,12 +196,12 @@ class FInterfaceStubGenerator { /// retreives the list of all subscribed clients for «broadcast.elementName» virtual std::shared_ptr<CommonAPI::ClientIdList> const «broadcast.stubAdapterClassSubscribersMethodName»() = 0; /// Hook method for reacting on new subscriptions or removed subscriptions respectively for selective broadcasts. - virtual void «broadcast.subscriptionChangedMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId, const CommonAPI::SelectiveBroadcastSubscriptionEvent event) = 0; + virtual void «broadcast.subscriptionChangedMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client, const CommonAPI::SelectiveBroadcastSubscriptionEvent _event) = 0; /// Hook method for reacting accepting or denying new subscriptions - virtual bool «broadcast.subscriptionRequestedMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId) = 0; + virtual bool «broadcast.subscriptionRequestedMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client) = 0; «ELSE» /// Sends a broadcast event for «broadcast.elementName». - virtual void «broadcast.stubAdapterClassFireEventMethodName»(«broadcast.outArgs.map['const ' + getTypeName(fInterface.model) + '& ' + elementName].join(', ')») = 0; + virtual void «broadcast.stubAdapterClassFireEventMethodName»(«broadcast.outArgs.map['const ' + getTypeName(fInterface, true) + ' &_' + elementName].join(', ')») = 0; «ENDIF» «ENDFOR» @@ -195,15 +218,16 @@ class FInterfaceStubGenerator { }; «fInterface.model.generateNamespaceEndDeclaration» + «fInterface.generateVersionNamespaceEnd» - #endif // «fInterface.defineName»_STUB_H_ + #endif // «fInterface.defineName»_STUB_HPP_ ''' def private generateStubDefaultHeader(FInterface fInterface, IResource modelid) ''' «generateCommonApiLicenseHeader(fInterface, modelid)» «FTypeGenerator::generateComments(fInterface, false)» - #ifndef «fInterface.defineName»_STUB_DEFAULT_H_ - #define «fInterface.defineName»_STUB_DEFAULT_H_ + #ifndef «getHeaderDefineName(fInterface)»_HPP_ + #define «getHeaderDefineName(fInterface)»_HPP_ «IF fInterface.base != null» #include <«fInterface.base.stubDefaultHeaderPath»> @@ -212,6 +236,7 @@ class FInterfaceStubGenerator { #include <«fInterface.stubHeaderPath»> #include <sstream> + «fInterface.generateVersionNamespaceBegin» «fInterface.model.generateNamespaceBeginDeclaration» /** @@ -224,41 +249,42 @@ class FInterfaceStubGenerator { * that would be defined for this service, and/or if you do not need any non-default * behaviour. */ - class «fInterface.stubDefaultClassName» : public virtual «fInterface.stubClassName»«IF fInterface.base != null», public virtual «fInterface.base.stubDefaultClassName»«ENDIF» { + class «fInterface.stubDefaultClassName» + : public virtual «fInterface.stubClassName»«IF fInterface.base != null», + public virtual «fInterface.base.getTypeCollectionName(fInterface)»StubDefault«ENDIF» { public: «fInterface.stubDefaultClassName»(); - «fInterface.stubRemoteEventClassName»* initStubAdapter(const std::shared_ptr<«fInterface.stubAdapterClassName»>& stubAdapter); + «fInterface.stubRemoteEventClassName»* initStubAdapter(const std::shared_ptr<«fInterface.stubAdapterClassName»> &_adapter); - const CommonAPI::Version& getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> clientId); + const CommonAPI::Version& getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> _client); «FOR attribute : fInterface.attributes» - virtual const «attribute.getTypeName(fInterface.model)»& «attribute.stubClassGetMethodName»(); - virtual const «attribute.getTypeName(fInterface.model)»& «attribute.stubClassGetMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId); - virtual void «attribute.stubDefaultClassSetMethodName»(«attribute.getTypeName(fInterface.model)» value); + «val typeName = attribute.getTypeName(fInterface, true)» + virtual const «typeName»& «attribute.stubClassGetMethodName»(); + virtual const «typeName»& «attribute.stubClassGetMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client); + virtual void «attribute.stubDefaultClassSetMethodName»(«typeName» _value); «IF !attribute.readonly» - virtual void «attribute.stubDefaultClassSetMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId, «attribute.getTypeName(fInterface.model)» value); + virtual void «attribute.stubDefaultClassSetMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client, «typeName» _value); «ENDIF» «ENDFOR» «FOR method: fInterface.methods» «FTypeGenerator::generateComments(method, false)» virtual void «method.elementName»(«method.generateStubSignature»); - virtual void «method.elementName»(«method.generateStubSignatureOldStyle»); - «ENDFOR» - «FOR broadcast : fInterface.broadcasts» + «FOR broadcast : fInterface.broadcasts» «FTypeGenerator::generateComments(broadcast, false)» - «IF !broadcast.selective.nullOrEmpty» + «IF broadcast.selective» virtual void «broadcast.stubAdapterClassFireSelectiveMethodName»(«generateSendSelectiveSignatur(broadcast, fInterface, true)»); virtual std::shared_ptr<CommonAPI::ClientIdList> const «broadcast.stubAdapterClassSubscribersMethodName»(); /// Hook method for reacting on new subscriptions or removed subscriptions respectively for selective broadcasts. - virtual void «broadcast.subscriptionChangedMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId, const CommonAPI::SelectiveBroadcastSubscriptionEvent event); + virtual void «broadcast.subscriptionChangedMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client, const CommonAPI::SelectiveBroadcastSubscriptionEvent _event); /// Hook method for reacting accepting or denying new subscriptions - virtual bool «broadcast.subscriptionRequestedMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId); + virtual bool «broadcast.subscriptionRequestedMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client); «ELSE» - virtual void «broadcast.stubAdapterClassFireEventMethodName»(«broadcast.outArgs.map['const ' + getTypeName(fInterface.model) + '& ' + elementName].join(', ')»); + virtual void «broadcast.stubAdapterClassFireEventMethodName»(«broadcast.outArgs.map['const ' + getTypeName(fInterface, true) + ' &_' + elementName].join(', ')»); «ENDIF» «ENDFOR» @@ -271,29 +297,31 @@ class FInterfaceStubGenerator { protected: «FOR attribute : fInterface.attributes» + «val typeName = attribute.getTypeName(fInterface, true)» «FTypeGenerator::generateComments(attribute, false)» - virtual bool «attribute.stubDefaultClassTrySetMethodName»(«attribute.getTypeName(fInterface.model)» value); - virtual bool «attribute.stubDefaultClassValidateMethodName»(const «attribute.getTypeName(fInterface.model)»& value); + virtual bool «attribute.stubDefaultClassTrySetMethodName»(«typeName» _value); + virtual bool «attribute.stubDefaultClassValidateMethodName»(const «typeName» &_value); «IF !attribute.readonly» virtual void «attribute.stubRemoteEventClassChangedMethodName»(); «ENDIF» «ENDFOR» class RemoteEventHandler: public virtual «fInterface.stubRemoteEventClassName»«IF fInterface.base != null», public virtual «fInterface.base.stubDefaultClassName»::RemoteEventHandler«ENDIF» { - public: - RemoteEventHandler(«fInterface.stubDefaultClassName»* defaultStub); + public: + RemoteEventHandler(«fInterface.stubDefaultClassName» *_defaultStub); «FOR attribute : fInterface.attributes» + «val typeName = attribute.getTypeName(fInterface, true)» «FTypeGenerator::generateComments(attribute, false)» «IF !attribute.readonly» - virtual bool «attribute.stubRemoteEventClassSetMethodName»(«attribute.getTypeName(fInterface.model)» value); - virtual bool «attribute.stubRemoteEventClassSetMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId, «attribute.getTypeName(fInterface.model)» value); + virtual bool «attribute.stubRemoteEventClassSetMethodName»(«typeName» _value); + virtual bool «attribute.stubRemoteEventClassSetMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client, «typeName» _value); virtual void «attribute.stubRemoteEventClassChangedMethodName»(); «ENDIF» «ENDFOR» - private: - «fInterface.stubDefaultClassName»* defaultStub_; + private: + «fInterface.stubDefaultClassName» *defaultStub_; }; private: «fInterface.stubDefaultClassName»::RemoteEventHandler remoteEventHandler_; @@ -303,23 +331,26 @@ class FInterfaceStubGenerator { «FOR attribute : fInterface.attributes» «FTypeGenerator::generateComments(attribute, false)» - «attribute.getTypeName(fInterface.model)» «attribute.stubDefaultClassVariableName»; + «attribute.getTypeName(fInterface, true)» «attribute.stubDefaultClassVariableName»; «ENDFOR» CommonAPI::Version interfaceVersion_; }; «fInterface.model.generateNamespaceEndDeclaration» + «fInterface.generateVersionNamespaceEnd» - #endif // «fInterface.defineName»_STUB_DEFAULT_H_ + #endif // «getHeaderDefineName(fInterface)» ''' def private generateStubDefaultSource(FInterface fInterface, IResource modelid) ''' «generateCommonApiLicenseHeader(fInterface, modelid)» #include <«fInterface.stubDefaultHeaderPath»> + #include <assert.h> + «fInterface.generateVersionNamespaceBegin» «fInterface.model.generateNamespaceBeginDeclaration» - + «fInterface.stubDefaultClassName»::«fInterface.stubDefaultClassName»(): remoteEventHandler_(this), «IF !fInterface.managedInterfaces.empty» @@ -328,27 +359,28 @@ class FInterfaceStubGenerator { interfaceVersion_(«fInterface.elementName»::getInterfaceVersion()) { } - const CommonAPI::Version& «fInterface.stubDefaultClassName»::getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> clientId) { + const CommonAPI::Version& «fInterface.stubDefaultClassName»::getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> _client) { return interfaceVersion_; } - «fInterface.stubRemoteEventClassName»* «fInterface.stubDefaultClassName»::initStubAdapter(const std::shared_ptr<«fInterface.stubAdapterClassName»>& stubAdapter) { - «IF fInterface.base != null»«fInterface.base.stubDefaultClassName»::initStubAdapter(stubAdapter);«ENDIF» - «fInterface.stubCommonAPIClassName»::stubAdapter_ = stubAdapter; + «fInterface.stubRemoteEventClassName»* «fInterface.stubDefaultClassName»::initStubAdapter(const std::shared_ptr<«fInterface.stubAdapterClassName»> &_adapter) { + «IF fInterface.base != null»«fInterface.base.stubDefaultClassName»::initStubAdapter(_adapter);«ENDIF» + «fInterface.stubCommonAPIClassName»::stubAdapter_ = _adapter; return &remoteEventHandler_; } «FOR attribute : fInterface.attributes» - const «attribute.getTypeName(fInterface.model)»& «fInterface.stubDefaultClassName»::«attribute.stubClassGetMethodName»() { + «val typeName = attribute.getTypeName(fInterface, true)» + const «typeName»& «fInterface.stubDefaultClassName»::«attribute.stubClassGetMethodName»() { return «attribute.stubDefaultClassVariableName»; } - const «attribute.getTypeName(fInterface.model)»& «fInterface.stubDefaultClassName»::«attribute.stubClassGetMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId) { + const «typeName»& «fInterface.stubDefaultClassName»::«attribute.stubClassGetMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client) { return «attribute.stubClassGetMethodName»(); } - void «fInterface.stubDefaultClassName»::«attribute.stubDefaultClassSetMethodName»(«attribute.getTypeName(fInterface.model)» value) { - «IF attribute.isObservable»const bool valueChanged = «ENDIF»«attribute.stubDefaultClassTrySetMethodName»(std::move(value)); + void «fInterface.stubDefaultClassName»::«attribute.stubDefaultClassSetMethodName»(«typeName» _value) { + «IF attribute.isObservable»const bool valueChanged = «ENDIF»«attribute.stubDefaultClassTrySetMethodName»(std::move(_value)); «IF attribute.isObservable» if (valueChanged && stubAdapter_ != NULL) { «IF fInterface.base != null»CommonAPI::Stub<«fInterface.stubAdapterClassName», «fInterface.stubRemoteEventClassName»>::«ENDIF»stubAdapter_->«attribute.stubAdapterClassFireChangedMethodName»(«attribute.stubDefaultClassVariableName»); @@ -356,22 +388,22 @@ class FInterfaceStubGenerator { «ENDIF» } - bool «fInterface.stubDefaultClassName»::«attribute.stubDefaultClassTrySetMethodName»(«attribute.getTypeName(fInterface.model)» value) { - if (!«attribute.stubDefaultClassValidateMethodName»(value)) + bool «fInterface.stubDefaultClassName»::«attribute.stubDefaultClassTrySetMethodName»(«typeName» _value) { + if (!«attribute.stubDefaultClassValidateMethodName»(_value)) return false; - const bool valueChanged = («attribute.stubDefaultClassVariableName» != value); - «attribute.stubDefaultClassVariableName» = std::move(value); + const bool valueChanged = («attribute.stubDefaultClassVariableName» != _value); + «attribute.stubDefaultClassVariableName» = std::move(_value); return valueChanged; } - bool «fInterface.stubDefaultClassName»::«attribute.stubDefaultClassValidateMethodName»(const «attribute.getTypeName(fInterface.model)»& value) { + bool «fInterface.stubDefaultClassName»::«attribute.stubDefaultClassValidateMethodName»(const «typeName» &_value) { return true; } «IF !attribute.readonly» - void «fInterface.stubDefaultClassName»::«attribute.stubDefaultClassSetMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId, «attribute.getTypeName(fInterface.model)» value) { - «attribute.stubDefaultClassSetMethodName»(value); + void «fInterface.stubDefaultClassName»::«attribute.stubDefaultClassSetMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client, «typeName» _value) { + «attribute.stubDefaultClassSetMethodName»(_value); } void «fInterface.stubDefaultClassName»::«attribute.stubRemoteEventClassChangedMethodName»() { @@ -379,15 +411,17 @@ class FInterfaceStubGenerator { } void «fInterface.stubDefaultClassName»::RemoteEventHandler::«attribute.stubRemoteEventClassChangedMethodName»() { + assert(defaultStub_ !=NULL); defaultStub_->«attribute.stubRemoteEventClassChangedMethodName»(); } - bool «fInterface.stubDefaultClassName»::RemoteEventHandler::«attribute.stubRemoteEventClassSetMethodName»(«attribute.getTypeName(fInterface.model)» value) { - return defaultStub_->«attribute.stubDefaultClassTrySetMethodName»(std::move(value)); + bool «fInterface.stubDefaultClassName»::RemoteEventHandler::«attribute.stubRemoteEventClassSetMethodName»(«typeName» _value) { + assert(defaultStub_ !=NULL); + return defaultStub_->«attribute.stubDefaultClassTrySetMethodName»(std::move(_value)); } - bool «fInterface.stubDefaultClassName»::RemoteEventHandler::«attribute.stubRemoteEventClassSetMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId, «attribute.getTypeName(fInterface.model)» value) { - return «attribute.stubRemoteEventClassSetMethodName»(value); + bool «fInterface.stubDefaultClassName»::RemoteEventHandler::«attribute.stubRemoteEventClassSetMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client, «typeName» _value) { + return «attribute.stubRemoteEventClassSetMethodName»(_value); } «ENDIF» @@ -396,64 +430,71 @@ class FInterfaceStubGenerator { «FOR method : fInterface.methods» «FTypeGenerator::generateComments(method, false)» void «fInterface.stubDefaultClassName»::«method.elementName»(«method.generateStubSignature») { - // Call old style methods in default - «method.elementName»(«method.generateArgumentsToStubCompatibility»); - } - void «fInterface.stubDefaultClassName»::«method.elementName»(«method.generateStubSignatureOldStyle») { - // No operation in default + «IF !method.isFireAndForget» + «method.generateDummyArgumentDefinitions» + _reply(«method.generateDummyArgumentList»); + «ENDIF» } - + «ENDFOR» «FOR broadcast : fInterface.broadcasts» «FTypeGenerator::generateComments(broadcast, false)» - «IF !broadcast.selective.nullOrEmpty» + «IF broadcast.selective» void «fInterface.stubDefaultClassName»::«broadcast.stubAdapterClassFireSelectiveMethodName»(«generateSendSelectiveSignatur(broadcast, fInterface, false)») { - stubAdapter_->«broadcast.stubAdapterClassSendSelectiveMethodName»(«broadcast.outArgs.map[elementName].join(', ')»«IF(!broadcast.outArgs.empty)», «ENDIF»receivers); + assert(stubAdapter_ !=NULL); + stubAdapter_->«broadcast.stubAdapterClassSendSelectiveMethodName»(«broadcast.outArgs.map["_" + elementName].join(', ')»«IF(!broadcast.outArgs.empty)», «ENDIF»_receivers); } - void «fInterface.stubDefaultClassName»::«broadcast.subscriptionChangedMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId, const CommonAPI::SelectiveBroadcastSubscriptionEvent event) { + void «fInterface.stubDefaultClassName»::«broadcast.subscriptionChangedMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client, const CommonAPI::SelectiveBroadcastSubscriptionEvent _event) { // No operation in default } - bool «fInterface.stubDefaultClassName»::«broadcast.subscriptionRequestedMethodName»(const std::shared_ptr<CommonAPI::ClientId> clientId) { + bool «fInterface.stubDefaultClassName»::«broadcast.subscriptionRequestedMethodName»(const std::shared_ptr<CommonAPI::ClientId> _client) { // Accept in default return true; } std::shared_ptr<CommonAPI::ClientIdList> const «fInterface.stubDefaultClassName»::«broadcast.stubAdapterClassSubscribersMethodName»() { + assert(stubAdapter_ !=NULL); return(stubAdapter_->«broadcast.stubAdapterClassSubscribersMethodName»()); } «ELSE» - void «fInterface.stubDefaultClassName»::«broadcast.stubAdapterClassFireEventMethodName»(«broadcast.outArgs.map['const ' + getTypeName(fInterface.model) + '& ' + elementName].join(', ')») { - stubAdapter_->«broadcast.stubAdapterClassFireEventMethodName»(«broadcast.outArgs.map[elementName].join(', ')»); + void «fInterface.stubDefaultClassName»::«broadcast.stubAdapterClassFireEventMethodName»(«broadcast.outArgs.map['const ' + getTypeName(fInterface, true) + ' &_' + elementName].join(', ')») { + assert(stubAdapter_ !=NULL); + stubAdapter_->«broadcast.stubAdapterClassFireEventMethodName»(«broadcast.outArgs.map["_" + elementName].join(', ')»); } «ENDIF» «ENDFOR» «FOR managed : fInterface.managedInterfaces» - bool «fInterface.stubDefaultClassName»::«managed.stubRegisterManagedAutoName»(std::shared_ptr<«managed.stubClassName»> stub) { + bool «fInterface.stubDefaultClassName»::«managed.stubRegisterManagedAutoName»(std::shared_ptr<«managed.stubClassName»> _stub) { autoInstanceCounter_++; std::stringstream ss; - ss << stubAdapter_->getInstanceId() << ".i" << autoInstanceCounter_; + ss << stubAdapter_->getAddress().getInstance() << ".i" << autoInstanceCounter_; std::string instance = ss.str(); - return stubAdapter_->«managed.stubRegisterManagedName»(stub, instance); + assert(stubAdapter_ !=NULL); + return stubAdapter_->«managed.stubRegisterManagedName»(_stub, instance); } bool «fInterface.stubDefaultClassName»::«managed.stubRegisterManagedMethodImpl» { - return stubAdapter_->«managed.stubRegisterManagedName»(stub, instance); + assert(stubAdapter_ !=NULL); + return stubAdapter_->«managed.stubRegisterManagedName»(_stub, _instance); } - bool «fInterface.stubDefaultClassName»::«managed.stubDeregisterManagedName»(const std::string& instance) { - return stubAdapter_->«managed.stubDeregisterManagedName»(instance); + bool «fInterface.stubDefaultClassName»::«managed.stubDeregisterManagedName»(const std::string &_instance) { + assert(stubAdapter_ !=NULL); + return stubAdapter_->«managed.stubDeregisterManagedName»(_instance); } std::set<std::string>& «fInterface.stubDefaultClassName»::«managed.stubManagedSetGetterName»() { + assert(stubAdapter_ !=NULL); return stubAdapter_->«managed.stubManagedSetGetterName»(); } «ENDFOR» - «fInterface.stubDefaultClassName»::RemoteEventHandler::RemoteEventHandler(«fInterface.stubDefaultClassName»* defaultStub): - «IF fInterface.base != null»«fInterface.base.stubDefaultClassName»::RemoteEventHandler(defaultStub),«ENDIF» - defaultStub_(defaultStub) { + «fInterface.stubDefaultClassName»::RemoteEventHandler::RemoteEventHandler(«fInterface.stubDefaultClassName» *_defaultStub) + : «fInterface.generateBaseRemoteHandlerConstructorsCalls» + defaultStub_(_defaultStub) { } «fInterface.model.generateNamespaceEndDeclaration» + «fInterface.generateVersionNamespaceEnd» ''' def private getStubDefaultClassSetMethodName(FAttribute fAttribute) { diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend index af7f286..a0ac91d 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend @@ -6,14 +6,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.genivi.commonapi.core.generator +import java.util.Collection +import java.util.HashSet import javax.inject.Inject +import org.eclipse.core.resources.IResource import org.eclipse.xtext.generator.IFileSystemAccess import org.franca.core.franca.FStructType import org.franca.core.franca.FTypeCollection -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor -import java.util.HashSet -import java.util.Collection -import org.eclipse.core.resources.IResource +import org.genivi.commonapi.core.deployment.PropertyAccessor class FTypeCollectionGenerator { @Inject private extension FTypeGenerator @@ -22,21 +22,21 @@ class FTypeCollectionGenerator { def generate(FTypeCollection fTypeCollection, IFileSystemAccess fileSystemAccess, - DeploymentInterfacePropertyAccessor deploymentAccessor, + PropertyAccessor deploymentAccessor, IResource modelid) { - fileSystemAccess.generateFile(fTypeCollection.headerPath, fTypeCollection.generateHeader(deploymentAccessor, modelid)) + fileSystemAccess.generateFile(fTypeCollection.headerPath, IFileSystemAccess.DEFAULT_OUTPUT, fTypeCollection.generateHeader(modelid, deploymentAccessor)) if (fTypeCollection.hasSourceFile) { - fileSystemAccess.generateFile(fTypeCollection.sourcePath, fTypeCollection.generateSource(modelid)) + fileSystemAccess.generateFile(fTypeCollection.sourcePath, IFileSystemAccess.DEFAULT_OUTPUT, fTypeCollection.generateSource(modelid, deploymentAccessor)) } } - def private generateHeader(FTypeCollection fTypeCollection, DeploymentInterfacePropertyAccessor deploymentAccessor, IResource modelid) ''' + def private generateHeader(FTypeCollection fTypeCollection, IResource modelid, PropertyAccessor deploymentAccessor) ''' «generateCommonApiLicenseHeader(fTypeCollection, modelid)» «FTypeGenerator::generateComments(fTypeCollection, false)» - #ifndef «fTypeCollection.defineName»_H_ - #define «fTypeCollection.defineName»_H_ + #ifndef «fTypeCollection.defineName»_HPP_ + #define «fTypeCollection.defineName»_HPP_ «val libraryHeaders = new HashSet<String>» «val generatedHeaders = new HashSet<String>» @@ -56,9 +56,10 @@ class FTypeCollectionGenerator { #undef COMMONAPI_INTERNAL_COMPILATION + «fTypeCollection.generateVersionNamespaceBegin» «fTypeCollection.model.generateNamespaceBeginDeclaration» - namespace «fTypeCollection.elementName» { + struct «fTypeCollection.elementName» { «fTypeCollection.generateFTypeDeclarations(deploymentAccessor)» «FOR type : fTypeCollection.types» @@ -77,14 +78,12 @@ class FTypeCollectionGenerator { } «ENDIF» - } // namespace «fTypeCollection.elementName» + }; // struct «fTypeCollection.elementName» «fTypeCollection.model.generateNamespaceEndDeclaration» + «fTypeCollection.generateVersionNamespaceEnd» namespace CommonAPI { - - «fTypeCollection.generateTypeWriters(deploymentAccessor)» - «fTypeCollection.generateVariantComparators» } @@ -93,10 +92,10 @@ class FTypeCollectionGenerator { «fTypeCollection.generateHashers(deploymentAccessor)» } - #endif // «fTypeCollection.defineName»_H_ + #endif // «fTypeCollection.defineName»_HPP_ ''' - def private generateSource(FTypeCollection fTypeCollection, IResource modelid) ''' + def private generateSource(FTypeCollection fTypeCollection, IResource modelid, PropertyAccessor _accessor) ''' «generateCommonApiLicenseHeader(fTypeCollection, modelid)» «FTypeGenerator::generateComments(fTypeCollection, false)» #include "«fTypeCollection.headerFile»" @@ -105,21 +104,20 @@ class FTypeCollectionGenerator { #include <«fStructTypeHeaderPath»> «ENDFOR» + «fTypeCollection.generateVersionNamespaceBegin» «fTypeCollection.model.generateNamespaceBeginDeclaration» - namespace «fTypeCollection.elementName» { «FOR type : fTypeCollection.types» - «/*FTypeGenerator::generateComments(type.comment, false)*/» - «type.generateFTypeImplementation(type)» + «type.generateFTypeImplementation(fTypeCollection, _accessor)» «ENDFOR» - } // namespace «fTypeCollection.elementName» «fTypeCollection.model.generateNamespaceEndDeclaration» + «fTypeCollection.generateVersionNamespaceEnd» ''' def void getRequiredHeaderFiles(FTypeCollection fInterface, Collection<String> generatedHeaders, Collection<String> libraryHeaders) { - libraryHeaders.add('CommonAPI/types.h') + libraryHeaders.add('CommonAPI/Types.hpp') fInterface.types.forEach[addRequiredHeaders(generatedHeaders, libraryHeaders)] generatedHeaders.remove(fInterface.headerPath) } diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCommonAreaGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCommonAreaGenerator.xtend index 7315a05..f9fccfe 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCommonAreaGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCommonAreaGenerator.xtend @@ -15,9 +15,9 @@ import org.franca.core.franca.FModel import org.franca.core.franca.FModelElement import org.franca.core.franca.FType import org.franca.core.franca.FTypeCollection -import org.franca.core.franca.FUnionType -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor import org.franca.core.franca.FTypedElement +import org.franca.core.franca.FUnionType +import org.genivi.commonapi.core.deployment.PropertyAccessor class FTypeCommonAreaGenerator { @Inject private extension FrancaGeneratorExtensions @@ -45,14 +45,6 @@ class FTypeCommonAreaGenerator { return fType as FUnionType } - def generateTypeWriters(FTypeCollection fTypes, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' - «FOR type: fTypes.types» - «IF type.isFEnumerationType» - «generateStreamImplementation(type.getFEnumerationType, type.elementName, fTypes, fTypes.elementName, deploymentAccessor)» - «ENDIF» - «ENDFOR» - ''' - def private List<String> getNamespaceAsList(FModel fModel) { newArrayList(fModel.name.split("\\.")) } @@ -63,50 +55,18 @@ class FTypeCommonAreaGenerator { return (fModelElement.eContainer as FModelElement).model } - def private getWithNamespace(FEnumerationType fEnumerationType, String enumerationName, FModelElement parent, String parentName) { - parent.model.namespaceAsList.join("::") + "::" + fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName) - } - - def private generateStreamImplementation(FEnumerationType fEnumerationType, String enumerationName, FModelElement parent, String parentName, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' - template<> - struct BasicTypeWriter<«fEnumerationType.getWithNamespace(enumerationName, parent, parentName)»> { - inline static void writeType (CommonAPI::TypeOutputStream& typeStream) { - typeStream.write«fEnumerationType.generateTypeOutput(deploymentAccessor)»Type(); - } - }; - - template<> - struct InputStreamVectorHelper<«fEnumerationType.getWithNamespace(enumerationName, parent, parentName)»> { - static void beginReadVector(InputStream& inputStream, const std::vector<«fEnumerationType.getWithNamespace(enumerationName, parent, parentName)»>& vectorValue) { - inputStream.beginRead«fEnumerationType.generateTypeOutput(deploymentAccessor)»Vector(); - } - }; - - template <> - struct OutputStreamVectorHelper<«fEnumerationType.getWithNamespace(enumerationName, parent, parentName)»> { - static void beginWriteVector(OutputStream& outputStream, const std::vector<«fEnumerationType.getWithNamespace(enumerationName, parent, parentName)»>& vectorValue) { - outputStream.beginWrite«fEnumerationType.generateTypeOutput(deploymentAccessor)»Vector(vectorValue.size()); - } - }; - ''' - - def private generateTypeOutput(FEnumerationType fEnumerationType, DeploymentInterfacePropertyAccessor deploymentAccessor) { - FTypeGenerator::generateComments(fEnumerationType, false) - return fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName.split("_").get(0).toUpperCase.replace("NT", "nt") + "Enum" - } - def generateVariantComparators(FTypeCollection fTypes) ''' «FOR type: fTypes.types» «IF type.isFUnionType» «FOR base : type.getFUnionType.baseList» - «generateComparatorImplementation(type.getFUnionType, type.elementName, base, fTypes, fTypes.elementName)» + «generateComparatorImplementation(type.getFUnionType, base)» «ENDFOR» «ENDIF» «ENDFOR» ''' def private getClassNamespaceWithName(FTypedElement type, String name, FModelElement parent, String parentName) { - var reference = type.getTypeName(parent) + var reference = type.getTypeName(parent, false) if (parent != null && parent != type) { reference = parentName + '::' + reference } @@ -115,23 +75,25 @@ class FTypeCommonAreaGenerator { - def private List<String> getElementTypeNames(FUnionType fUnion, String unionName, FModelElement parent, String parentName) { + def private List<String> getElementTypeNames(FUnionType fUnion) { var names = new ArrayList<String> var rev = fUnion.elements var iter = rev.iterator + val parent = (fUnion.eContainer as FTypeCollection) + while (iter.hasNext) { var item = iter.next var lName = ""; if (item.type.derived != null) { - lName = parent.model.namespaceAsList.join("::") + "::" + item.getClassNamespaceWithName(item.elementName, parent, parentName) + lName = parent.model.namespaceAsList.join("::") + "::" + item.getClassNamespaceWithName(item.elementName, parent, parent.name) } else { - lName = item.getTypeName(fUnion) + lName = item.getTypeName(fUnion, false) } names.add(lName) } if (fUnion.base != null) { - for (base : fUnion.base.getElementTypeNames(fUnion.base.elementName, parent, parentName)) { + for (base : fUnion.base.elementTypeNames) { names.add(base); } } @@ -146,9 +108,9 @@ class FTypeCommonAreaGenerator { if (counter > 1) { ret = ret + " else "; } - ret = ret + "if (rhs.getValueType() == " + counter + ") { \n" + - " " + item + " a = lhs.get<" + item + ">(); \n" + - " " + item + " b = rhs.get<" + item + ">(); \n" + + ret = ret + "if (_rhs.getValueType() == " + counter + ") { \n" + + " " + item + " a = _lhs.get<" + item + ">(); \n" + + " " + item + " b = _rhs.get<" + item + ">(); \n" + " " + "return (a == b); \n" + "}" counter = counter + 1; @@ -156,33 +118,38 @@ class FTypeCommonAreaGenerator { return ret } - def private generateComparatorImplementation(FUnionType fUnionType, String unionName, FUnionType base, FModelElement parent, String parentName) ''' + def private generateComparatorImplementation(FUnionType _derived, FUnionType _base) ''' + «val unionTypeName = _derived.getElementName(null, true)» + «val unionBaseTypeName = _base.getElementName(null, true)» + «val unionTypeContainerName = (_derived.eContainer as FTypeCollection).getTypeCollectionName(null)» + «val unionBaseTypeContainerName = (_base.eContainer as FTypeCollection).getTypeCollectionName(null)» + inline bool operator==( - const «parent.model.namespaceAsList.join("::") + "::" + fUnionType.getClassNamespaceWithName(unionName, parent, parentName)»& lhs, - const «parent.model.namespaceAsList.join("::") + "::" + base.getClassNamespaceWithName(base.elementName, parent, parentName)»& rhs) { - if (lhs.getValueType() == rhs.getValueType()) { - «var list = base.getElementTypeNames(unionName, parent, parentName)» + const «unionTypeContainerName»::«unionTypeName» &_lhs, + const «unionBaseTypeContainerName»::«unionBaseTypeName» &_rhs) { + if (_lhs.getValueType() == _rhs.getValueType()) { + «var list = _base.elementTypeNames» «list.generateVariantComnparatorIf» } return false; } inline bool operator==( - const «parent.model.namespaceAsList.join("::") + "::" + base.getClassNamespaceWithName(base.elementName, parent, parentName)»& lhs, - const «parent.model.namespaceAsList.join("::") + "::" + fUnionType.getClassNamespaceWithName(unionName, parent, parentName)»& rhs) { - return rhs == lhs; + const «unionBaseTypeContainerName»::«unionBaseTypeName» &_lhs, + const «unionTypeContainerName»::«unionTypeName» &_rhs) { + return _rhs == _lhs; } inline bool operator!=( - const «parent.model.namespaceAsList.join("::") + "::" + fUnionType.getClassNamespaceWithName(unionName, parent, parentName)»& lhs, - const «parent.model.namespaceAsList.join("::") + "::" + base.getClassNamespaceWithName(base.elementName, parent, parentName)»& rhs) { - return lhs != rhs; + const «unionTypeContainerName»::«unionTypeName» &_lhs, + const «unionBaseTypeContainerName»::«unionBaseTypeName» &_rhs) { + return !(_lhs == _rhs); } inline bool operator!=( - const «parent.model.namespaceAsList.join("::") + "::" + base.getClassNamespaceWithName(base.elementName, parent, parentName)»& lhs, - const «parent.model.namespaceAsList.join("::") + "::" + fUnionType.getClassNamespaceWithName(unionName, parent, parentName)»& rhs) { - return lhs != rhs; + const «unionBaseTypeContainerName»::«unionBaseTypeName» &_lhs, + const «unionTypeContainerName»::«unionTypeName» &_rhs) { + return !(_rhs == _lhs); } ''' @@ -198,11 +165,11 @@ class FTypeCommonAreaGenerator { return baseList } - def getFQN(FType type, FTypeCollection fTypes) '''«fTypes.model.namespaceAsList.join("::")»::«type.getClassNamespaceWithName(type.elementName, fTypes, fTypes.elementName)»''' + def getFQN(FType type, FTypeCollection fTypes) '''«fTypes.versionPrefix»«fTypes.model.namespaceAsList.join("::")»::«type.getClassNamespaceWithName(type.elementName, fTypes, fTypes.elementName)»''' - def getFQN(FType type, String name, FTypeCollection fTypes) '''«fTypes.model.namespaceAsList.join("::")»::«type.getClassNamespaceWithName(name, fTypes, fTypes.elementName)»''' + def getFQN(FType type, String name, FTypeCollection fTypes) '''«fTypes.versionPrefix»«fTypes.model.namespaceAsList.join("::")»::«type.getClassNamespaceWithName(name, fTypes, fTypes.elementName)»''' - def generateHash (FType type, String name, FTypeCollection fTypes, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' + def generateHash (FType type, String name, FTypeCollection fTypes, PropertyAccessor deploymentAccessor) ''' //Hash for «name» template<> struct hash<«type.getFQN(name, fTypes)»> { @@ -212,7 +179,7 @@ class FTypeCommonAreaGenerator { }; ''' - def generateHash (FType type, FTypeCollection fTypes, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' + def generateHash (FType type, FTypeCollection fTypes, PropertyAccessor deploymentAccessor) ''' //Hash for «type.elementName» template<> struct hash<«type.getFQN(fTypes)»> { @@ -222,7 +189,7 @@ class FTypeCommonAreaGenerator { }; ''' - def generateHashers(FTypeCollection fTypes, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' + def generateHashers(FTypeCollection fTypes, PropertyAccessor deploymentAccessor) ''' «FOR type: fTypes.types» «IF type.isFEnumerationType» «type.generateHash(fTypes, deploymentAccessor)» diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeGenerator.xtend index a7b1146..8a70e41 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeGenerator.xtend @@ -6,11 +6,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.genivi.commonapi.core.generator +import java.util.ArrayList import java.util.Collection import java.util.LinkedList import java.util.List import javax.inject.Inject import org.eclipse.emf.common.util.EList +import org.franca.core.franca.FAnnotation +import org.franca.core.franca.FAnnotationBlock +import org.franca.core.franca.FAnnotationType import org.franca.core.franca.FArrayType import org.franca.core.franca.FBasicTypeId import org.franca.core.franca.FEnumerationType @@ -18,6 +22,7 @@ import org.franca.core.franca.FEnumerator import org.franca.core.franca.FField import org.franca.core.franca.FInterface import org.franca.core.franca.FMapType +import org.franca.core.franca.FMethod import org.franca.core.franca.FModelElement import org.franca.core.franca.FStructType import org.franca.core.franca.FType @@ -25,18 +30,15 @@ import org.franca.core.franca.FTypeCollection import org.franca.core.franca.FTypeDef import org.franca.core.franca.FTypeRef import org.franca.core.franca.FUnionType -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor +import org.genivi.commonapi.core.deployment.PropertyAccessor import static com.google.common.base.Preconditions.* -import org.franca.core.franca.FAnnotationType -import org.franca.core.franca.FAnnotationBlock -import org.franca.core.franca.FMethod -import java.util.ArrayList -import org.franca.core.franca.FAnnotation + +import static extension org.genivi.commonapi.core.generator.FrancaGeneratorExtensions.* class FTypeGenerator { @Inject private extension FrancaGeneratorExtensions francaGeneratorExtensions - static int begrenzung = 80 + static final int CommentLineLength = 80 def static isdeprecated(FAnnotationBlock annotations) { if(annotations == null) @@ -48,6 +50,7 @@ class FTypeGenerator { return false } + // TODO: is this code needed ? def static sortAnnotations(FAnnotationBlock annots) { var ArrayList<ArrayList<FAnnotation>> ret = new ArrayList<ArrayList<FAnnotation>>(4) ret.add(new ArrayList<FAnnotation>()) @@ -71,26 +74,42 @@ class FTypeGenerator { } def private static findNextBreak(String text) { - var breakIndex = text.substring(0, begrenzung).lastIndexOf(" "); - if (breakIndex > 0) { + var breakIndex = text.substring(0, CommentLineLength).lastIndexOf(" "); + if (breakIndex > -1) { return breakIndex; } else { - breakIndex = text.substring(0, begrenzung).lastIndexOf("\n"); - if (breakIndex > -1) { - return breakIndex; - } else { - return java.lang.Math.min(begrenzung, text.length); - } + return Math.min(CommentLineLength, text.length); } } - def static breaktext(String text, int annotation) { + def static breaktext(String text, FAnnotationType annotation) { + var commentBody = "" + var line = "" + var startIndex = 0 + var endIndex = CommentLineLength + var commentText = text.replace("\r\n", " ") + + commentBody += " * " + annotation.getName() + ": " + while(endIndex < commentText.length) { + line = commentText.substring(startIndex, endIndex) + endIndex = findNextBreak(line) + commentBody += commentText.substring(startIndex, startIndex + endIndex) + "\n * "; + startIndex += endIndex + endIndex = startIndex + CommentLineLength + } + commentBody += commentText.substring(startIndex, commentText.length) + "\n"; + return commentBody; + } + + // TODO: Does this code offer additional functionality compared to breaktext ? + def static breaktext_(String text, int annotation) { var ret = "" - var temptext = "" - if(annotation == FAnnotationType::DESCRIPTION_VALUE && text.length > begrenzung) { + var temptext = "" + + if(annotation == FAnnotationType::DESCRIPTION_VALUE && text.length > CommentLineLength) { ret = " * " + text.substring(0, findNextBreak(text)) + "\n"; temptext = text.substring(findNextBreak(text)); - }else if(annotation != FAnnotationType::DESCRIPTION_VALUE && text.length > begrenzung) { + }else if(annotation != FAnnotationType::DESCRIPTION_VALUE && text.length > CommentLineLength) { if(annotation == FAnnotationType::AUTHOR_VALUE) { ret = " * @author " }if(annotation == FAnnotationType::DEPRECATED_VALUE){ @@ -111,8 +130,8 @@ class FTypeGenerator { ret = " * " ret = ret + text + "\n"; } - while(temptext.length > begrenzung) { - try { + while(temptext.length > CommentLineLength) { + try { ret = ret + " * " + temptext.substring(0, findNextBreak(temptext)) + "\n"; temptext = temptext.substring(findNextBreak(temptext)); } @@ -127,6 +146,26 @@ class FTypeGenerator { } def static generateComments(FModelElement model, boolean inline) { + var intro = "" + var tail = "" + var annoCommentText = "" + if( model != null && model.comment != null){ + if(!inline) { + intro = "/**\n" + tail = " */" + } + for(annoComment : model.comment.elements) { + if(annoComment != null){ + annoCommentText += breaktext(annoComment.comment, annoComment.type) + } + } + return intro + annoCommentText + tail + } + return "" + } + + // TODO: Does this code offer additional functionality compared to generateComments ? + def static generateComments_(FModelElement model, boolean inline) { var typ = getTyp(model) var ret = "" var commexists = false @@ -140,7 +179,7 @@ class FTypeGenerator { if(!inline && !commexists) ret = "/**\n" commexists = true - ret = ret + breaktext(comment.comment, comment.type.value) + ret = ret + breaktext(comment.comment, comment.type) } } } @@ -162,15 +201,15 @@ class FTypeGenerator { return ModelTyp::UNKNOWN } - def generateFTypeDeclarations(FTypeCollection fTypeCollection, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' + def generateFTypeDeclarations(FTypeCollection fTypeCollection, PropertyAccessor deploymentAccessor) ''' «FOR type: fTypeCollection.types.sortTypes(fTypeCollection)» «generateComments(type, false)» «type.generateFTypeDeclaration(deploymentAccessor)» «ENDFOR» «IF fTypeCollection instanceof FInterface» - «FOR method : (fTypeCollection as FInterface).methods.filter[errors != null]» + «FOR method : (fTypeCollection as FInterface).methodsWithError» «generateComments(method, false)» - «method.errors.generateDeclaration(method.errors.errorName, deploymentAccessor)» + «method.errors.generateDeclaration(method.errors, deploymentAccessor)» «ENDFOR» «ENDIF» ''' @@ -203,84 +242,230 @@ class FTypeGenerator { return references } - def dispatch generateFTypeDeclaration(FTypeDef fTypeDef, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' + def dispatch generateFTypeDeclaration(FTypeDef fTypeDef, PropertyAccessor deploymentAccessor) ''' «generateComments(fTypeDef, false)» - typedef «fTypeDef.actualType.getNameReference(fTypeDef.eContainer)» «fTypeDef.elementName»; + typedef «fTypeDef.actualType.getElementType(null, true)» «fTypeDef.elementName»; ''' - def dispatch generateFTypeDeclaration(FArrayType fArrayType, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' + def dispatch generateFTypeDeclaration(FArrayType fArrayType, PropertyAccessor deploymentAccessor) ''' «generateComments(fArrayType, false)» «IF fArrayType.elementType.derived != null && fArrayType.elementType.derived instanceof FStructType && (fArrayType.elementType.derived as FStructType).polymorphic» - typedef std::vector<std::shared_ptr<«fArrayType.elementType.getNameReference(fArrayType.eContainer)»>> «fArrayType.elementName»; + typedef std::vector<std::shared_ptr<«fArrayType.elementType.getElementType(null, true)»>> «fArrayType.elementName»; «ELSE» - typedef std::vector<«fArrayType.elementType.getNameReference(fArrayType.eContainer)»> «fArrayType.elementName»; + typedef std::vector<«fArrayType.elementType.getElementType(null, true)»> «fArrayType.elementName»; «ENDIF» ''' - def dispatch generateFTypeDeclaration(FMapType fMap, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' + def dispatch generateFTypeDeclaration(FMapType fMap, PropertyAccessor deploymentAccessor) ''' «generateComments(fMap, false)» typedef std::unordered_map<«fMap.generateKeyType», «fMap.generateValueType»«fMap.generateHasher»> «fMap.elementName»; ''' - def dispatch generateFTypeDeclaration(FStructType fStructType, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' - «generateComments(fStructType, false)» - struct «fStructType.elementName»: «fStructType.baseStructName» { - «FOR element : fStructType.elements» - «generateComments(element, false)» - «element.getTypeName(fStructType)» «element.elementName»; - «ENDFOR» - - «fStructType.elementName»() = default; - «IF fStructType.allElements.size > 0» - «fStructType.elementName»(«fStructType.allElements.map[getConstReferenceVariable(fStructType)].join(", ")»); - «ENDIF» - - «IF fStructType.hasPolymorphicBase» - enum: uint32_t { SERIAL_ID = 0x«Integer::toHexString(fStructType.serialId)» }; - - static «fStructType.elementName»* createInstance(const uint32_t& serialId); - - virtual uint32_t getSerialId() const; - virtual void createTypeSignature(CommonAPI::TypeOutputStream& typeOutputStream) const; - «ENDIF» - - virtual void readFromInputStream(CommonAPI::InputStream& inputStream); - virtual void writeToOutputStream(CommonAPI::OutputStream& outputStream) const; - - static inline void writeToTypeOutputStream(CommonAPI::TypeOutputStream& typeOutputStream) { - «IF fStructType.base != null» - «fStructType.baseStructName»::writeToTypeOutputStream(typeOutputStream); - «ENDIF» - «FOR element : fStructType.elements» - «element.type.typeStreamSignature(deploymentAccessor, element)» - «ENDFOR» - } - }; + def dispatch generateFTypeDeclaration(FStructType fStructType, PropertyAccessor deploymentAccessor) ''' + «generateComments(fStructType, false)» + «IF fStructType.polymorphic» + «fStructType.createSerials()» + + «ENDIF» + «IF fStructType.hasPolymorphicBase()» + «IF fStructType.base == null» + struct «fStructType.elementName» : CommonAPI::PolymorphicStruct { + «ELSE» + struct «fStructType.elementName» : «fStructType.base.getElementName(fStructType, false)» { + «ENDIF» + «ELSE» + struct «fStructType.elementName» : CommonAPI::Struct<«fStructType.allElements.map[getTypeName(fStructType, false)].join(", ")»> { + «ENDIF» + «IF fStructType.hasPolymorphicBase()» + «IF fStructType.hasDerivedTypes() » + static std::shared_ptr<«fStructType.elementName»> create(CommonAPI::Serial _serial); + «ENDIF» + const CommonAPI::Serial getSerial() const { return «fStructType.elementName.toUpperCase»_SERIAL; } + «ENDIF» + + «fStructType.elementName»() { + «IF fStructType.allElements.size > 0» + «var n = 0» + «FOR element : fStructType.allElements» + «IF element.type.predefined.equals(FBasicTypeId.BOOLEAN) && !element.array» + std::get<«n»>(values_) = false; + «ENDIF» + «{ n = n + 1; "" }» + «ENDFOR» + «ENDIF» + } + «IF fStructType.allElements.size > 0» + «fStructType.elementName»(«fStructType.allElements.map[getConstReferenceVariable(fStructType)].join(", ")») + «IF fStructType.hasPolymorphicBase() && fStructType.base != null» + : «fStructType.base.elementName»(«fStructType.base.allElements.map["_" + elementName].join(", ")») + «ENDIF» + { + «IF fStructType.hasPolymorphicBase» + «var i = -1» + «FOR element : fStructType.elements» + std::get<«i = i+1»>(values_) = _«element.elementName»; + «ENDFOR» + «ELSE» + «var i = -1» + «FOR element : fStructType.allElements» + std::get<«i = i+1»>(values_) = _«element.elementName»; + «ENDFOR» + «ENDIF» + } + «ENDIF» + «IF fStructType.hasPolymorphicBase()» + template<class _Input> + void readValue(CommonAPI::InputStream<_Input> &_input, const CommonAPI::EmptyDeployment *_depl) { + «var i = -1» + «FOR element : fStructType.elements» + _input.template readValue<CommonAPI::EmptyDeployment>(std::get<«i = i+1»>(values_)); + «ENDFOR» + «IF fStructType.hasDerivedTypes()» + switch (getSerial()) { + «FOR derived : fStructType.derivedFStructTypes» + «derived.generateCases(null, false)» + static_cast<«derived.elementName» *>(this)->template readValue<_Input>(_input, _depl); + break; + «ENDFOR» + default: + break; + } + «ENDIF» + } + + template<class _Input, class _Deployment> + void readValue(CommonAPI::InputStream<_Input> &_input, const _Deployment *_depl) { + «var j = -1» + «var k = fStructType.allElements.size - fStructType.elements.size - 1» + «FOR element : fStructType.elements» + _input.template readValue<>(std::get<«j = j+1»>(values_), std::get<«k = k+1»>(_depl->values_)); + «ENDFOR» + «IF fStructType.hasDerivedTypes()» + switch (getSerial()) { + «FOR derived : fStructType.derivedFStructTypes» + «derived.generateCases(null, false)» + static_cast<«derived.elementName» *>(this)->template readValue<>(_input, _depl); + break; + «ENDFOR» + default: + break; + } + «ENDIF» + } + + template<class _Output> + void writeType(CommonAPI::TypeOutputStream<_Output> &_output) { + «var l = -1» + «FOR element : fStructType.elements» + _output.writeType(std::get<«l = l+1»>(values_)); + «ENDFOR» + «IF fStructType.hasDerivedTypes()» + switch (getSerial()) { + «FOR derived : fStructType.derivedFStructTypes» + «derived.generateCases(null, false)» + static_cast<«derived.elementName» *>(this)->template writeType<_Output>(_output); + break; + «ENDFOR» + default: + break; + } + «ENDIF» + } + + template<class _Output> + void writeValue(CommonAPI::OutputStream<_Output> &_output, const CommonAPI::EmptyDeployment *_depl) { + «var m = -1» + «FOR element : fStructType.elements» + _output.template writeValue<CommonAPI::EmptyDeployment>(std::get<«m = m+1»>(values_)); + «ENDFOR» + «IF fStructType.hasDerivedTypes()» + switch (getSerial()) { + «FOR derived : fStructType.derivedFStructTypes» + «derived.generateCases(null, false)» + static_cast<«derived.elementName» *>(this)->template writeValue<_Output>(_output, _depl); + break; + «ENDFOR» + default: + break; + } + «ENDIF» + } + + template<class _Output, class _Deployment> + void writeValue(CommonAPI::OutputStream<_Output> &_output, const _Deployment *_depl) { + «var n = -1» + «var o = fStructType.allElements.size - fStructType.elements.size - 1» + «FOR element : fStructType.elements» + _output.template writeValue<>(std::get<«n = n+1»>(values_), _depl, std::get<«o = o + 1»>(_depl->values_)); + «ENDFOR» + «IF fStructType.hasDerivedTypes()» + switch (getSerial()) { + «FOR derived : fStructType.derivedFStructTypes» + «derived.generateCases(null, false)» + static_cast<«derived.elementName» *>(this)->template writeValue<>(_output, _depl); + break; + «ENDFOR» + default: + break; + } + «ENDIF» + } + «var p = -1» + «FOR element : fStructType.elements» + «generateComments(element, false)» + «val String typeName = element.getTypeName(fStructType, false)» + inline const «typeName» &get«element.elementName.toFirstUpper»() const { return std::get<«p = p+1»>(values_); } + inline void set«element.elementName.toFirstUpper»(const «typeName» «IF typeName.isComplex»&«ENDIF»_value) { std::get<«p»>(values_) = _value; } + «ENDFOR» + + «IF fStructType.hasPolymorphicBase() && fStructType.elements.size > 0» + std::tuple<«fStructType.elements.map[getTypeName(fStructType, false)].join(", ")»> values_; + «ENDIF» + «ELSE» + «var k = -1» + «FOR element : fStructType.allElements» + «generateComments(element, false)» + «val String typeName = element.getTypeName(fStructType, false)» + inline const «typeName» &get«element.elementName.toFirstUpper»() const { return std::get<«k = k+1»>(values_); } + inline void set«element.elementName.toFirstUpper»(const «typeName» «IF typeName.isComplex»&«ENDIF»_value) { std::get<«k»>(values_) = _value; } + «ENDFOR» + «ENDIF» + bool operator==(const «fStructType.name» &_other) const; + inline bool operator!=(const «fStructType.name» &_other) const { + return !((*this) == _other); + } + + }; ''' - def dispatch generateFTypeDeclaration(FEnumerationType fEnumerationType, DeploymentInterfacePropertyAccessor deploymentAccessor) { - generateDeclaration(fEnumerationType, fEnumerationType.elementName, deploymentAccessor) + def dispatch generateFTypeDeclaration(FEnumerationType fEnumerationType, PropertyAccessor deploymentAccessor) { + generateDeclaration(fEnumerationType, fEnumerationType, deploymentAccessor) } - def generateDeclaration(FEnumerationType fEnumerationType, String name, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' - enum class «name»: «fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName» { - «FOR parent : fEnumerationType.baseList SEPARATOR ',\n'» - «FOR enumerator : parent.enumerators SEPARATOR ','» - «enumerator.elementName» = «parent.getRelativeNameReference(fEnumerationType)»::«enumerator.elementName» - «ENDFOR» - «ENDFOR» - «IF fEnumerationType.base != null && !fEnumerationType.enumerators.empty»,«ENDIF» - «FOR enumerator : fEnumerationType.enumerators SEPARATOR ','» - «generateComments(enumerator, false)» - «enumerator.elementName»«enumerator.generateValue» + def generateDeclaration(FEnumerationType _enumeration, FModelElement _parent, PropertyAccessor _accessor) ''' + «_enumeration.setEnumerationValues» + «IF _enumeration.name == null» + «IF _parent.name != null» + «_enumeration.name = _parent.name + "Enum"» + «ELSE» + «_enumeration.name = (_parent.eContainer as FModelElement).name + "Error"» + «ENDIF» + «ENDIF» + «val backingType = _enumeration.getBackingType(_accessor).primitiveTypeName» + «val baseTypeName = _enumeration.getBaseType(backingType)» + + struct «_enumeration.name» : «baseTypeName» { + «_enumeration.name»() = default; + «_enumeration.name»(const «backingType» &_value) + : «baseTypeName»(_value) {} + «FOR enumerator : _enumeration.enumerators» + «generateComments(enumerator, false)» + static const «backingType» «enumPrefix»«enumerator.elementName» = «enumerator.value.enumeratorValue»; «ENDFOR» }; - - // Definition of a comparator still is necessary for GCC 4.4.1, topic is fixed since 4.5.1 - struct «name»Comparator; ''' - def dispatch generateFTypeDeclaration(FUnionType fUnionType, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' + def dispatch generateFTypeDeclaration(FUnionType fUnionType, PropertyAccessor deploymentAccessor) ''' «generateComments(fUnionType, false)» typedef CommonAPI::Variant<«fUnionType.getElementNames»> «fUnionType.elementName»; ''' @@ -293,158 +478,93 @@ class FTypeGenerator { if (names != "") { names = ", " + names } - names = fUnion.elements.map[getTypeName(fUnion)].join(", ") + names + names = fUnion.elements.map[getTypeName(fUnion, false)].join(", ") + names return names } - def dispatch generateFTypeInlineImplementation(FTypeDef fTypeDef, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) '''''' - def dispatch generateFTypeInlineImplementation(FArrayType fArrayType, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) '''''' - def dispatch generateFTypeInlineImplementation(FMapType fMap, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) '''''' + def dispatch generateFTypeInlineImplementation(FTypeDef fTypeDef, FModelElement parent, PropertyAccessor deploymentAccessor) '''''' + def dispatch generateFTypeInlineImplementation(FArrayType fArrayType, FModelElement parent, PropertyAccessor deploymentAccessor) '''''' + def dispatch generateFTypeInlineImplementation(FMapType fMap, FModelElement parent, PropertyAccessor deploymentAccessor) '''''' - def dispatch generateFTypeInlineImplementation(FStructType fStructType, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' - bool operator==(const «fStructType.getClassNamespace(parent)»& lhs, const «fStructType.getClassNamespace(parent)»& rhs); - inline bool operator!=(const «fStructType.getClassNamespace(parent)»& lhs, const «fStructType.getClassNamespace(parent)»& rhs) { - return !(lhs == rhs); - } + def dispatch generateFTypeInlineImplementation(FStructType fStructType, FModelElement parent, PropertyAccessor deploymentAccessor) ''' ''' - def dispatch generateFTypeInlineImplementation(FEnumerationType fEnumerationType, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) { - fEnumerationType.generateInlineImplementation(fEnumerationType.elementName, parent, parent.elementName, deploymentAccessor) - } - - def generateInlineImplementation(FEnumerationType fEnumerationType, String enumerationName, FModelElement parent, String parentName, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' - inline CommonAPI::InputStream& operator>>(CommonAPI::InputStream& inputStream, «fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName)»& enumValue) { - return inputStream.readEnumValue<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(enumValue); - } - - inline CommonAPI::OutputStream& operator<<(CommonAPI::OutputStream& outputStream, const «fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName)»& enumValue) { - return outputStream.writeEnumValue(static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(enumValue)); - } - - struct «fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName)»Comparator { - inline bool operator()(const «enumerationName»& lhs, const «enumerationName»& rhs) const { - return static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(lhs) < static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(rhs); - } - }; - - «FOR base : fEnumerationType.baseList BEFORE "\n" SEPARATOR "\n"» - «fEnumerationType.generateInlineOperatorWithName(enumerationName, base, parent, parentName, "==", deploymentAccessor)» - «fEnumerationType.generateInlineOperatorWithName(enumerationName, base, parent, parentName, "!=", deploymentAccessor)» - «ENDFOR» + def dispatch generateFTypeInlineImplementation(FEnumerationType fEnumerationType, FModelElement parent, PropertyAccessor deploymentAccessor) ''' ''' + + def dispatch generateFTypeInlineImplementation(FUnionType fUnionType, FModelElement parent, PropertyAccessor deploymentAccessor) '''''' + + def dispatch generateFTypeImplementation(FTypeDef fTypeDef, FModelElement parent, PropertyAccessor _accessor) '''''' + def dispatch generateFTypeImplementation(FArrayType fArrayType, FModelElement parent, PropertyAccessor _accessor) '''''' + def dispatch generateFTypeImplementation(FMapType fMap, FModelElement parent, PropertyAccessor _accessor) '''''' + def dispatch generateFTypeImplementation(FEnumerationType _enumeration, FModelElement _parent, PropertyAccessor _accessor) ''' + #ifndef WIN32 + «FOR enumerator : _enumeration.enumerators» + «IF _parent != null && _parent != _enumeration» + const «_enumeration.getBackingType(_accessor).primitiveTypeName» «_parent.elementName»::«_enumeration.name»::«enumPrefix + enumerator.elementName»; + «ELSE» + const «_enumeration.getBackingType(_accessor).primitiveTypeName» «_enumeration.name»::«enumPrefix + enumerator.elementName»; + «ENDIF» + «ENDFOR» + #endif + ''' + + def dispatch generateFTypeImplementation(FStructType fStructType, FModelElement parent, PropertyAccessor _accessor) ''' + «IF fStructType.polymorphic || (fStructType.hasPolymorphicBase() && fStructType.hasDerivedTypes())» + std::shared_ptr<«fStructType.getClassNamespace(parent)»> «fStructType.getClassNamespace(parent)»::create(CommonAPI::Serial _serial) { + switch (_serial) { + case «parent.elementName»::«fStructType.elementName.toUpperCase()»_SERIAL: + return std::make_shared<«fStructType.getClassNamespace(parent)»>(); + «FOR derived : fStructType.derivedFStructTypes» + «derived.generateCases(parent, true)» + «IF derived.derivedFStructTypes.empty» + return std::make_shared<«derived.getClassNamespace(parent)»>(); + «ELSE» + return «derived.getClassNamespace(parent)»::create(_serial); + «ENDIF» + «ENDFOR» + default: + break; + } + return std::shared_ptr<«fStructType.getClassNamespace(parent)»>(); + } + «ENDIF» + + bool «fStructType.getClassNamespace(parent)»::operator==(const «parent.elementName»::«fStructType.name»& _other) const { + «IF fStructType.allElements.size > 0» + «FOR element : fStructType.allElements BEFORE 'return (' SEPARATOR ' && ' AFTER ');'»get«element.elementName.toFirstUpper»() == _other.get«element.elementName.toFirstUpper»()«ENDFOR» + «ELSE» + return true; + «ENDIF» + } - def dispatch generateFTypeInlineImplementation(FUnionType fUnionType, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) '''''' - - def dispatch generateFTypeImplementation(FTypeDef fTypeDef, FModelElement parent) '''''' - def dispatch generateFTypeImplementation(FArrayType fArrayType, FModelElement parent) '''''' - def dispatch generateFTypeImplementation(FMapType fMap, FModelElement parent) '''''' - def dispatch generateFTypeImplementation(FEnumerationType fEnumerationType, FModelElement parent) '''''' - - def dispatch generateFTypeImplementation(FStructType fStructType, FModelElement parent) ''' - «IF fStructType.allElements.size > 0» - «fStructType.getClassNamespace(parent)»::«fStructType.elementName»(«fStructType.allElements.map[getConstReferenceVariable(fStructType) + "Value"].join(", ")»): - «fStructType.base?.generateBaseConstructorCall(fStructType)» - «FOR element : fStructType.elements SEPARATOR ','» - «element.elementName»(«element.elementName»Value) - «ENDFOR» - { - } - «ENDIF» - - «IF fStructType.hasPolymorphicBase» - «fStructType.getClassNamespace(parent)»* «fStructType.getClassNamespace(parent)»::createInstance(const uint32_t& serialId) { - if (serialId == SERIAL_ID) - return new «fStructType.elementName»; - - «IF fStructType.hasDerivedFStructTypes» - const std::function<«fStructType.elementName»*()> createDerivedInstanceFuncs[] = { - «FOR derivedFStructType : fStructType.getDerivedFStructTypes SEPARATOR ','» - [&]() { return «derivedFStructType.getRelativeNameReference(fStructType)»::createInstance(serialId); } - «ENDFOR» - }; - - for (auto& createDerivedInstanceFunc : createDerivedInstanceFuncs) { - «fStructType.elementName»* derivedInstance = createDerivedInstanceFunc(); - if (derivedInstance != NULL) - return derivedInstance; - } - - «ENDIF» - return NULL; - } - - uint32_t «fStructType.getClassNamespace(parent)»::getSerialId() const { - return SERIAL_ID; - } - - void «fStructType.getClassNamespace(parent)»::createTypeSignature(CommonAPI::TypeOutputStream& typeOutputStream) const { - «fStructType.elementName»::writeToTypeOutputStream(typeOutputStream); - } - «ENDIF» - - bool operator==(const «fStructType.getClassNamespace(parent)»& lhs, const «fStructType.getClassNamespace(parent)»& rhs) { - if (&lhs == &rhs) - return true; - - return - «IF fStructType.allElements.size > 0» - «IF fStructType.base != null» - static_cast<«fStructType.base.getClassNamespace(parent)»>(lhs) == static_cast<«fStructType.base.getClassNamespace(parent)»>(rhs) && - «ENDIF» - «FOR element : fStructType.elements SEPARATOR ' &&'» - lhs.«element.elementName» == rhs.«element.elementName» - «ENDFOR» - «ELSE» - true - «ENDIF» - ; - } - - void «fStructType.getClassNamespace(parent)»::readFromInputStream(CommonAPI::InputStream& inputStream) { - «IF fStructType.base != null» - «fStructType.base.getRelativeNameReference(fStructType)»::readFromInputStream(inputStream); - «ENDIF» - «FOR element : fStructType.elements» - inputStream >> «element.elementName»; - «ENDFOR» - } - - void «fStructType.getClassNamespace(parent)»::writeToOutputStream(CommonAPI::OutputStream& outputStream) const { - «IF fStructType.base != null» - «fStructType.base.getRelativeNameReference(fStructType)»::writeToOutputStream(outputStream); - «ENDIF» - «FOR element : fStructType.elements» - outputStream << «element.elementName»; - «ENDFOR» - } ''' - def dispatch generateFTypeImplementation(FUnionType fUnionType, FModelElement parent) ''' ''' + def dispatch generateFTypeImplementation(FUnionType fUnionType, FModelElement parent, PropertyAccessor _accessor) ''' + ''' def hasImplementation(FType fType) { - return (fType instanceof FStructType); + return ((fType instanceof FStructType) || (fType instanceof FEnumerationType)) } def void generateInheritanceIncludes(FInterface fInterface, Collection<String> generatedHeaders, Collection<String> libraryHeaders) { if(fInterface.base != null) { generatedHeaders.add(fInterface.base.stubHeaderPath) } - } def void generateRequiredTypeIncludes(FInterface fInterface, Collection<String> generatedHeaders, Collection<String> libraryHeaders) { - - if (!fInterface.attributes.filter[(array != null && array.equals("[]"))].nullOrEmpty) { + if (!fInterface.attributes.filter[array].nullOrEmpty) { libraryHeaders.add('vector') } - if (!fInterface.methods.map[inArgs.filter[(array != null && array.equals("[]"))]].nullOrEmpty) { + if (!fInterface.methods.map[inArgs.filter[array]].nullOrEmpty) { libraryHeaders.add('vector') } - if (!fInterface.methods.map[outArgs.filter[(array != null && array.equals("[]"))]].nullOrEmpty) { + if (!fInterface.methods.map[outArgs.filter[array]].nullOrEmpty) { libraryHeaders.add('vector') } - if (!fInterface.broadcasts.map[outArgs.filter[(array != null && array.equals("[]"))]].nullOrEmpty) { + if (!fInterface.broadcasts.map[outArgs.filter[array]].nullOrEmpty) { libraryHeaders.add('vector') } @@ -486,19 +606,19 @@ class FTypeGenerator { if (fStructType.base != null) generatedHeaders.add(fStructType.base.FTypeCollection.headerPath) else - libraryHeaders.addAll('CommonAPI/InputStream.h', 'CommonAPI/OutputStream.h', 'CommonAPI/SerializableStruct.h') + libraryHeaders.addAll('CommonAPI/Deployment.hpp', 'CommonAPI/InputStream.hpp', 'CommonAPI/OutputStream.hpp', 'CommonAPI/Struct.hpp') fStructType.elements.forEach[type.getRequiredHeaderPath(generatedHeaders, libraryHeaders)] } def private dispatch void addFTypeRequiredHeaders(FEnumerationType fEnumerationType, Collection<String> generatedHeaders, Collection<String> libraryHeaders) { if (fEnumerationType.base != null) generatedHeaders.add(fEnumerationType.base.FTypeCollection.headerPath) - libraryHeaders.addAll('cstdint', 'CommonAPI/InputStream.h', 'CommonAPI/OutputStream.h') + libraryHeaders.addAll('cstdint', 'CommonAPI/InputStream.hpp', 'CommonAPI/OutputStream.hpp') } def private dispatch void addFTypeRequiredHeaders(FUnionType fUnionType, Collection<String> generatedHeaders, Collection<String> libraryHeaders) { if (fUnionType.base != null) generatedHeaders.add(fUnionType.base.FTypeCollection.headerPath) else - libraryHeaders.add('CommonAPI/SerializableVariant.h') + libraryHeaders.add('CommonAPI/Variant.hpp') fUnionType.elements.forEach[type.getRequiredHeaderPath(generatedHeaders, libraryHeaders)] libraryHeaders.addAll('cstdint', 'memory') } @@ -513,7 +633,7 @@ class FTypeGenerator { def private void getRequiredHeaderPath(FBasicTypeId fBasicTypeId, Collection<String> generatedHeaders, Collection<String> libraryHeaders) { switch fBasicTypeId { case FBasicTypeId::STRING : libraryHeaders.add('string') - case FBasicTypeId::BYTE_BUFFER : libraryHeaders.add('CommonAPI/ByteBuffer.h') + case FBasicTypeId::BYTE_BUFFER : libraryHeaders.add('CommonAPI/ByteBuffer.hpp') default : libraryHeaders.add('cstdint') } } @@ -529,7 +649,8 @@ class FTypeGenerator { return reference } - def private generateBaseConstructorCall(FStructType parent, FStructType source) { + // TODO: check whether this is used anywhere.... + def String generateBaseConstructorCall(FStructType parent, FStructType source) { var call = parent.getRelativeNameReference(source) call = call + "(" + parent.allElements.map[elementName + "Value"].join(", ") + ")" if (!source.elements.empty) @@ -539,7 +660,7 @@ class FTypeGenerator { def private generateHasher(FMapType fMap) { if (fMap.keyType.derived instanceof FEnumerationType) { - return ''', CommonAPI::EnumHasher<«fMap.keyType.getNameReference(fMap.eContainer)»>''' + return ''', CommonAPI::EnumHasher<«fMap.keyType.getElementType(null, true)»>''' } return "" @@ -547,34 +668,32 @@ class FTypeGenerator { def private generateKeyType(FMapType fMap) { if (fMap.keyType.polymorphic) { - return "std::shared_ptr<" + fMap.keyType.getNameReference(fMap.eContainer) + ">" + return "std::shared_ptr<" + fMap.keyType.getElementType(null, true) + ">" } else { - return fMap.keyType.getNameReference(fMap.eContainer) + return fMap.keyType.getElementType(null, true) } } def private generateValueType(FMapType fMap) { if (fMap.valueType.polymorphic) { - return "std::shared_ptr<" + fMap.valueType.getNameReference(fMap.eContainer) + ">" + return "std::shared_ptr<" + fMap.valueType.getElementType(null, true) + ">" } else { - return fMap.valueType.getNameReference(fMap.eContainer) + return fMap.valueType.getElementType(null, true) } } - def private getBaseStructName(FStructType fStructType) { - if (fStructType.base != null) - return fStructType.base.getRelativeNameReference(fStructType) - + // TODO: Check whether this is used somewhere + def getBaseStructName(FStructType fStructType) { if (fStructType.hasPolymorphicBase) - return "CommonAPI::SerializablePolymorphicStruct" + return "CommonAPI::PolymorphicStruct" - return "CommonAPI::SerializableStruct" + return "CommonAPI::Struct" } def private getConstReferenceVariable(FField destination, FModelElement source) { - "const " + destination.getTypeName(source) + "& " + destination.elementName + "const " + destination.getTypeName(source, false) + " &_" + destination.elementName } def private List<FField> getAllElements(FStructType fStructType) { @@ -586,7 +705,8 @@ class FTypeGenerator { return elements } - def private generateInlineOperatorWithName(FEnumerationType fEnumerationType, String enumerationName, FEnumerationType base, FModelElement parent, String parentName, String operator, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' + //TODO: used? + def generateInlineOperatorWithName(FEnumerationType fEnumerationType, String enumerationName, FEnumerationType base, FModelElement parent, String parentName, String operator, PropertyAccessor deploymentAccessor) ''' inline bool operator«operator»(const «fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName)»& lhs, const «base.getClassNamespaceWithName(base.elementName, base.eContainer as FModelElement, (base.eContainer as FModelElement).elementName)»& rhs) { return static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(lhs) «operator» static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(rhs); } @@ -595,7 +715,8 @@ class FTypeGenerator { } ''' - def private getBaseList(FEnumerationType fEnumerationType) { + //TODO: used? + def getBaseList(FEnumerationType fEnumerationType) { val baseList = new LinkedList<FEnumerationType> var currentBase = fEnumerationType.base @@ -607,8 +728,9 @@ class FTypeGenerator { return baseList } - def private generateValue(FEnumerator fEnumerator) { - val parsedValue = tryParseInteger(fEnumerator.value) + //TODO: used? + def generateValue(FEnumerator fEnumerator) { + val parsedValue = tryParseInteger(fEnumerator.value.enumeratorValue) if (parsedValue != null) return ' = ' + parsedValue return '' diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGenerator.xtend index 35d8bf8..55e12e1 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGenerator.xtend @@ -14,15 +14,10 @@ import javax.inject.Inject import org.eclipse.core.resources.IResource import org.eclipse.core.resources.ResourcesPlugin import org.eclipse.core.runtime.Path -import org.eclipse.core.runtime.QualifiedName -import org.eclipse.core.runtime.preferences.DefaultScope -import org.eclipse.core.runtime.preferences.IEclipsePreferences -import org.eclipse.core.runtime.preferences.InstanceScope import org.eclipse.emf.ecore.resource.Resource -import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2 import org.eclipse.xtext.generator.IFileSystemAccess import org.eclipse.xtext.generator.IGenerator -import org.eclipse.xtext.generator.JavaIoFileSystemAccess +import org.franca.core.dsl.FrancaPersistenceManager import org.franca.core.franca.FArrayType import org.franca.core.franca.FEnumerationType import org.franca.core.franca.FInterface @@ -36,15 +31,16 @@ import org.franca.core.franca.FTypeRef import org.franca.core.franca.FUnionType import org.franca.deploymodel.core.FDModelExtender import org.franca.deploymodel.core.FDeployedInterface -import org.franca.deploymodel.dsl.FDeployPersistenceManager +import org.franca.deploymodel.core.FDeployedTypeCollection import org.franca.deploymodel.dsl.fDeploy.FDInterface -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessorWrapper +import org.franca.deploymodel.dsl.fDeploy.FDProvider +import org.franca.deploymodel.dsl.fDeploy.FDTypes +import org.genivi.commonapi.core.deployment.PropertyAccessor import org.genivi.commonapi.core.preferences.FPreferences import org.genivi.commonapi.core.preferences.PreferenceConstants -import org.osgi.framework.FrameworkUtil import static com.google.common.base.Preconditions.* +import org.franca.deploymodel.dsl.fDeploy.FDModel class FrancaGenerator implements IGenerator { @@ -53,31 +49,40 @@ class FrancaGenerator implements IGenerator @Inject private extension FInterfaceProxyGenerator @Inject private extension FInterfaceStubGenerator @Inject private extension FrancaGeneratorExtensions - - @Inject private MyFrancaPersistenceManager francaPersistenceManager - @Inject private FDeployPersistenceManager fDeployPersistenceManager + + @Inject private FrancaPersistenceManager francaPersistenceManager + @Inject private FDeployManager fDeployManager override doGenerate(Resource input, IFileSystemAccess fileSystemAccess) { var FModel fModel var List<FDInterface> deployedInterfaces + var List<FDTypes> deployedTypeCollections + var List<FDProvider> deployedProviders var IResource res = null + // load the model from a fidl file if(input.URI.fileExtension.equals(francaPersistenceManager.fileExtension)) { - fModel = francaPersistenceManager.loadModel(input.filePath) + fModel = francaPersistenceManager.loadModel(input.URI, input.URI) deployedInterfaces = new LinkedList<FDInterface>() } - else if(input.URI.fileExtension.equals("fdepl"/* fDeployPersistenceManager.fileExtension */)) + // load the model from deployment file + else if(input.URI.fileExtension.equals(FDeployManager.fileExtension)) { - var fDeployedModel = fDeployPersistenceManager.loadModel(input.URI, input.URI); - val fModelExtender = new FDModelExtender(fDeployedModel); - - checkArgument(fModelExtender.getFDInterfaces().size > 0, "No Interfaces were deployed, nothing to generate.") - fModel = fModelExtender.getFDInterfaces().get(0).target.model - deployedInterfaces = fModelExtender.getFDInterfaces() - + var model = fDeployManager.loadModel(input.URI, input.URI); + if(model instanceof FDModel) { + val fModelExtender = new FDModelExtender(model); + checkArgument(fModelExtender.getFDInterfaces().size > 0, "No Interfaces were deployed, nothing to generate.") + fModel = fModelExtender.getFDInterfaces().get(0).target.model + deployedInterfaces = fModelExtender.getFDInterfaces() + deployedTypeCollections = fModelExtender.getFDTypesList() + deployedProviders = fModelExtender.getFDProviders() + } else if(model instanceof FModel) { + fModel = model + deployedInterfaces = new LinkedList<FDInterface>() + } } else { @@ -98,38 +103,22 @@ class FrancaGenerator implements IGenerator } res = ResourcesPlugin.workspace.root.findMember(pathfile) - FPreferences::instance.addPreferences(res) - if(FPreferences::instance.useModelSpecific(res)) - { - var output = res.getPersistentProperty( - new QualifiedName(PreferenceConstants::PROJECT_PAGEID, PreferenceConstants::P_OUTPUT_PROXIES)) - if(output != null && output.length != 0) - { - if(fileSystemAccess instanceof EclipseResourceFileSystemAccess2) - { - (fileSystemAccess as EclipseResourceFileSystemAccess2).setOutputPath(output) - } - else if(fileSystemAccess instanceof JavaIoFileSystemAccess) - { - (fileSystemAccess as JavaIoFileSystemAccess).setOutputPath(output) - } - } - } - doGenerateComponents(fModel, deployedInterfaces, fileSystemAccess, res) + + doGenerateComponents(fModel, deployedInterfaces, deployedTypeCollections, deployedProviders, fileSystemAccess, res) } catch(IllegalStateException e) { //happens only when the cli calls the francagenerator } - doGenerateComponents(fModel, deployedInterfaces, fileSystemAccess, res) - - if(res != null) - { - fileSystemAccess.setFileAccessOutputPathForPreference(PreferenceConstants::P_OUTPUT_PROXIES, res) - } + doGenerateComponents(fModel, deployedInterfaces, deployedTypeCollections, deployedProviders, fileSystemAccess, res) } - def private doGenerateComponents(FModel fModel, List<FDInterface> deployedInterfaces, IFileSystemAccess fileSystemAccess, IResource res) + def private doGenerateComponents(FModel fModel, + List<FDInterface> deployedInterfaces, + List<FDTypes> deployedTypeCollections, + List<FDProvider> deployedProviders, + IFileSystemAccess fileSystemAccess, + IResource res) { val allReferencedFTypes = fModel.allReferencedFTypes @@ -143,33 +132,42 @@ class FrancaGenerator implements IGenerator val generateInterfaces = fModel.allReferencedFInterfaces.toSet generateInterfaces.addAll(allFTypeFInterfaces) - val defaultDeploymentAccessor = new DeploymentInterfacePropertyAccessorWrapper(null) as DeploymentInterfacePropertyAccessor - - generateTypeCollections.forEach [ - generate(it, fileSystemAccess, defaultDeploymentAccessor, res) - ] - - generateInterfaces.forEach [ + val defaultDeploymentAccessor = new PropertyAccessor() + generateInterfaces.forEach [ val currentInterface = it - var DeploymentInterfacePropertyAccessor deploymentAccessor - if(deployedInterfaces.exists[it.target == currentInterface]) + var PropertyAccessor deploymentAccessor + if (deployedInterfaces != null && deployedInterfaces.exists[it.target == currentInterface]) { - deploymentAccessor = new DeploymentInterfacePropertyAccessor( - new FDeployedInterface(deployedInterfaces.filter[it.target == currentInterface].last)) + deploymentAccessor = new PropertyAccessor( + new FDeployedInterface(deployedInterfaces.filter[it.target == currentInterface].last)) } else { deploymentAccessor = defaultDeploymentAccessor } - generate(it, fileSystemAccess, defaultDeploymentAccessor, res) + generate(it, fileSystemAccess, deploymentAccessor, res) ] + + generateTypeCollections.forEach [ + val currentTypeCollection = it + if (!(currentTypeCollection instanceof FInterface)) { + var PropertyAccessor deploymentAccessor + if (deployedTypeCollections != null && deployedTypeCollections.exists[it.target == currentTypeCollection]) { + deploymentAccessor = new PropertyAccessor( + new FDeployedTypeCollection(deployedTypeCollections.filter[it.target == currentTypeCollection].last)) + } else { + deploymentAccessor = defaultDeploymentAccessor + } + generate(it, fileSystemAccess, deploymentAccessor, res) + } + ] fModel.interfaces.forEach [ val currentInterface = it - var DeploymentInterfacePropertyAccessor deploymentAccessor + var PropertyAccessor deploymentAccessor if(deployedInterfaces.exists[it.target == currentInterface]) { - deploymentAccessor = new DeploymentInterfacePropertyAccessor( + deploymentAccessor = new PropertyAccessor( new FDeployedInterface(deployedInterfaces.filter[it.target == currentInterface].last)) } else @@ -177,34 +175,16 @@ class FrancaGenerator implements IGenerator deploymentAccessor = defaultDeploymentAccessor } val booleanTrue = Boolean.toString(true) - var IEclipsePreferences node var String finalValue = booleanTrue - if(FrameworkUtil::getBundle(this.getClass()) != null) - { - node = DefaultScope::INSTANCE.getNode(PreferenceConstants::SCOPE) - finalValue = node.get(PreferenceConstants::P_GENERATEPROXY, booleanTrue) - - node = InstanceScope::INSTANCE.getNode(PreferenceConstants::SCOPE) - finalValue = node.get(PreferenceConstants::P_GENERATEPROXY, finalValue) - } - finalValue = FPreferences::instance.getPreference(res, PreferenceConstants::P_GENERATEPROXY, finalValue) + finalValue = FPreferences::instance.getPreference(PreferenceConstants::P_GENERATEPROXY, finalValue) if(finalValue.equals(booleanTrue)) { - fileSystemAccess.setFileAccessOutputPathForPreference(PreferenceConstants.P_OUTPUT_PROXIES, res) it.generateProxy(fileSystemAccess, deploymentAccessor, res) } finalValue = booleanTrue - if(FrameworkUtil::getBundle(this.getClass()) != null) - { - node = DefaultScope::INSTANCE.getNode(PreferenceConstants::SCOPE) - finalValue = node.get(PreferenceConstants::P_GENERATESTUB, booleanTrue) - node = InstanceScope::INSTANCE.getNode(PreferenceConstants::SCOPE) - finalValue = node.get(PreferenceConstants::P_GENERATESTUB, finalValue) - } - finalValue = FPreferences::instance.getPreference(res, PreferenceConstants::P_GENERATESTUB, finalValue) + finalValue = FPreferences::instance.getPreference(PreferenceConstants::P_GENERATESTUB, finalValue) if(finalValue.equals(booleanTrue)) { - fileSystemAccess.setFileAccessOutputPathForPreference(PreferenceConstants.P_OUTPUT_STUBS, res) it.generateStub(fileSystemAccess, res) } ] @@ -333,19 +313,4 @@ class FrancaGenerator implements IGenerator } } - def void setFileAccessOutputPathForPreference(IFileSystemAccess access, String preference, IResource res) - { - var defaultValue = DefaultScope::INSTANCE.getNode(PreferenceConstants::SCOPE).get(preference, - PreferenceConstants::DEFAULT_OUTPUT); - defaultValue = InstanceScope::INSTANCE.getNode(PreferenceConstants::SCOPE).get(preference, defaultValue) - defaultValue = FPreferences::instance.getPreference(res, preference, defaultValue) - - switch (access) - { - EclipseResourceFileSystemAccess2: - access.setOutputPath(defaultValue) - JavaIoFileSystemAccess: - access.setOutputPath(defaultValue) - } - } } diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend index 9dbf72d..0944894 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend @@ -10,15 +10,19 @@ import com.google.common.base.Charsets import com.google.common.hash.Hasher import com.google.common.hash.Hashing import com.google.common.primitives.Ints +import java.math.BigInteger +import java.util.ArrayList import java.util.Collection +import java.util.HashMap +import java.util.HashSet import java.util.List +import java.util.Map +import java.util.Set import org.eclipse.core.resources.IResource import org.eclipse.core.resources.ResourcesPlugin import org.eclipse.core.runtime.Path import org.eclipse.core.runtime.preferences.DefaultScope import org.eclipse.core.runtime.preferences.InstanceScope -import org.eclipse.emf.common.util.BasicEList -import org.eclipse.emf.common.util.EList import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.resource.Resource import org.eclipse.emf.ecore.util.EcoreUtil @@ -27,12 +31,16 @@ import org.franca.core.franca.FAttribute import org.franca.core.franca.FBasicTypeId import org.franca.core.franca.FBroadcast import org.franca.core.franca.FEnumerationType +import org.franca.core.franca.FEnumerator +import org.franca.core.franca.FExpression import org.franca.core.franca.FField +import org.franca.core.franca.FIntegerConstant import org.franca.core.franca.FInterface import org.franca.core.franca.FMapType import org.franca.core.franca.FMethod import org.franca.core.franca.FModel import org.franca.core.franca.FModelElement +import org.franca.core.franca.FStringConstant import org.franca.core.franca.FStructType import org.franca.core.franca.FType import org.franca.core.franca.FTypeCollection @@ -40,23 +48,78 @@ import org.franca.core.franca.FTypeDef import org.franca.core.franca.FTypeRef import org.franca.core.franca.FTypedElement import org.franca.core.franca.FUnionType -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor.DefaultEnumBackingType -import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor.EnumBackingType +import org.franca.core.franca.FVersion +import org.franca.core.franca.FrancaFactory +import org.genivi.commonapi.core.deployment.PropertyAccessor +import org.genivi.commonapi.core.deployment.PropertyAccessor.DefaultEnumBackingType +import org.genivi.commonapi.core.deployment.PropertyAccessor.EnumBackingType import org.genivi.commonapi.core.preferences.FPreferences import org.genivi.commonapi.core.preferences.PreferenceConstants import org.osgi.framework.FrameworkUtil import static com.google.common.base.Preconditions.* +import static extension java.lang.Integer.* +import org.franca.core.franca.FConstantDef +import org.franca.core.franca.FQualifiedElementRef +import org.franca.core.franca.FInitializerExpression + class FrancaGeneratorExtensions { + + def boolean isComplex(String _typeName) { + if (_typeName == "bool" || + _typeName == "int8" || + _typeName == "int16" || + _typeName == "int32" || + _typeName == "int64" || + _typeName == "uint8" || + _typeName == "uint16" || + _typeName == "uint32" || + _typeName == "uint64") { + return false + } + return true + } + + def String generateIndent(int _indent) { + var String empty = "" + var int i = 0 + while (i < _indent) { + empty = empty + " " + i = i + 1 + } + return empty + } + + def String getRelativeName(FModelElement _element) { + if (_element instanceof FTypeCollection) + return "" + val String next = (_element.eContainer as FModelElement).relativeName + if (next != "") + return next + "_" + _element.name + return _element.name + } def String getFullyQualifiedName(FModelElement fModelElement) { if (fModelElement.eContainer instanceof FModel) return (fModelElement.eContainer as FModel).name + '.' + fModelElement.elementName return (fModelElement.eContainer as FModelElement).fullyQualifiedName + '.' + fModelElement.elementName } - + + def String getFullyQualifiedCppName(FModelElement fModelElement) { + if (fModelElement.eContainer instanceof FModel) { + var name = (fModelElement.eContainer as FModel).name + if (fModelElement instanceof FTypeCollection) { + val FVersion itsVersion = fModelElement.version + if (itsVersion != null) { + name = fModelElement.versionPrefix + name + } + } + return "::" + (name + "::" + fModelElement.elementName).replace(".", "::") + } + return "::" + ((fModelElement.eContainer as FModelElement).fullyQualifiedName + "::" + fModelElement.elementName).replace(".", "::") + } + def splitCamelCase(String string) { string.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])") } @@ -79,7 +142,7 @@ class FrancaGeneratorExtensions { } def FTypeCollection getContainingTypeCollection(FModelElement fModelElement) { - if (fModelElement.eContainer == null || fModelElement.eContainer instanceof FModel) { + if (fModelElement.eContainer != null && fModelElement.eContainer instanceof FModel) { return null } if (fModelElement.eContainer instanceof FTypeCollection) { @@ -107,15 +170,14 @@ class FrancaGeneratorExtensions { } def getElementName(FModelElement fModelElement) { - if(fModelElement.name.nullOrEmpty && fModelElement instanceof FTypeCollection) { - return "AnonymousTypeCollection" + if ((fModelElement.name == null || fModelElement.name == "") && fModelElement instanceof FTypeCollection) { + return "__Anonymous__" } else { return fModelElement.name } } - def private dispatch List<String> getNamespaceAsList(FModel fModel) { newArrayList(fModel.name.split("\\.")) } @@ -146,7 +208,7 @@ class FrancaGeneratorExtensions { def getRelativeNameReference(FModelElement destination, EObject source) { var nameReference = destination.elementName - if (!destination.eContainer.equals(source)) { + if (destination.eContainer != null && !destination.eContainer.equals(source)) { val subnamespaceList = destination.getSubnamespaceList(source) if (!subnamespaceList.empty) nameReference = subnamespaceList.join('::') + '::' + nameReference @@ -156,11 +218,11 @@ class FrancaGeneratorExtensions { } def getHeaderFile(FTypeCollection fTypeCollection) { - fTypeCollection.elementName + ".h" + fTypeCollection.elementName + ".hpp" } def getHeaderPath(FTypeCollection fTypeCollection) { - fTypeCollection.model.directoryPath + '/' + fTypeCollection.headerFile + fTypeCollection.versionPathPrefix + fTypeCollection.model.directoryPath + '/' + fTypeCollection.headerFile } def getSourceFile(FTypeCollection fTypeCollection) { @@ -168,15 +230,15 @@ class FrancaGeneratorExtensions { } def getSourcePath(FTypeCollection fTypeCollection) { - fTypeCollection.model.directoryPath + '/' + fTypeCollection.sourceFile + fTypeCollection.versionPathPrefix + fTypeCollection.model.directoryPath + '/' + fTypeCollection.sourceFile } def getProxyBaseHeaderFile(FInterface fInterface) { - fInterface.elementName + "ProxyBase.h" + fInterface.elementName + "ProxyBase.hpp" } def getProxyBaseHeaderPath(FInterface fInterface) { - fInterface.model.directoryPath + '/' + fInterface.proxyBaseHeaderFile + fInterface.versionPathPrefix + fInterface.model.directoryPath + '/' + fInterface.proxyBaseHeaderFile } def getProxyBaseClassName(FInterface fInterface) { @@ -184,31 +246,39 @@ class FrancaGeneratorExtensions { } def getProxyHeaderFile(FInterface fInterface) { - fInterface.elementName + "Proxy.h" + fInterface.elementName + "Proxy.hpp" } def getProxyHeaderPath(FInterface fInterface) { - fInterface.model.directoryPath + '/' + fInterface.proxyHeaderFile + fInterface.versionPathPrefix + fInterface.model.directoryPath + '/' + fInterface.proxyHeaderFile } def getStubDefaultHeaderFile(FInterface fInterface) { - fInterface.elementName + "StubDefault.h" + fInterface.elementName + "Stub" + skeletonNamePostfix + ".hpp" } + def getSkeletonNamePostfix() { + FPreferences::instance.getPreference(PreferenceConstants::P_SKELETONPOSTFIX, "Default") + } + + def getHeaderDefineName(FInterface fInterface) { + fInterface.defineName + "_STUB_" + skeletonNamePostfix.toUpperCase() + } + def getStubDefaultHeaderPath(FInterface fInterface) { - fInterface.model.directoryPath + '/' + fInterface.stubDefaultHeaderFile + fInterface.versionPathPrefix + fInterface.model.directoryPath + '/' + fInterface.stubDefaultHeaderFile } - def getStubDefaultClassName(FInterface fInterface) { - fInterface.elementName + 'StubDefault' + def getStubDefaultClassName(FInterface fInterface) { + fInterface.elementName + "Stub" + skeletonNamePostfix } def getStubDefaultSourceFile(FInterface fInterface) { - fInterface.elementName + "StubDefault.cpp" + fInterface.elementName + "Stub" + skeletonNamePostfix + ".cpp" } def getStubDefaultSourcePath(FInterface fInterface) { - fInterface.model.directoryPath + '/' + fInterface.getStubDefaultSourceFile + fInterface.versionPathPrefix + fInterface.model.directoryPath + '/' + fInterface.getStubDefaultSourceFile } def getStubRemoteEventClassName(FInterface fInterface) { @@ -224,16 +294,16 @@ class FrancaGeneratorExtensions { } def getStubHeaderFile(FInterface fInterface) { - fInterface.elementName + "Stub.h" + fInterface.elementName + "Stub.hpp" } def getStubHeaderPath(FInterface fInterface) { - fInterface.model.directoryPath + '/' + fInterface.stubHeaderFile + fInterface.versionPathPrefix + fInterface.model.directoryPath + '/' + fInterface.stubHeaderFile } def generateSelectiveBroadcastStubIncludes(FInterface fInterface, Collection<String> generatedHeaders, Collection<String> libraryHeaders) { - if (!fInterface.broadcasts.filter[selective.nullOrEmpty].empty) { + if (!fInterface.broadcasts.filter[!selective].empty) { libraryHeaders.add("unordered_set") } @@ -242,8 +312,8 @@ class FrancaGeneratorExtensions { def generateSelectiveBroadcastProxyIncludes(FInterface fInterface, Collection<String> generatedHeaders, Collection<String> libraryHeaders) { - if (!fInterface.broadcasts.filter[selective.nullOrEmpty].empty) { - libraryHeaders.add("CommonAPI/types.h") + if (!fInterface.broadcasts.filter[!selective].empty) { + libraryHeaders.add("CommonAPI/Types.hpp") } return null @@ -262,102 +332,178 @@ class FrancaGeneratorExtensions { } def hasSelectiveBroadcasts(FInterface fInterface) { - !fInterface.broadcasts.filter[!selective.nullOrEmpty].empty - } - - def generateDefinition(FMethod fMethod) { - fMethod.generateDefinitionWithin(null) - } - - def generateDefinitionWithin(FMethod fMethod, String parentClassName) { + !fInterface.broadcasts.filter[selective].empty + } + + def Collection<FMethod> getMethodsWithError(FInterface _interface) { + val Map<String, FMethod> itsMethods = new HashMap<String, FMethod>() + for (method : _interface.methods.filter[errors != null]) { + var existing = itsMethods.get(method.name) + if (existing == null) { + itsMethods.put(method.name, method) + } else { + val List<FEnumerator> itsAdditionals = new ArrayList<FEnumerator>() + for (e : method.errors.enumerators) { + var found = false + for (f : existing.errors.enumerators) { + if (f.name == e.name) { + found = true + } + } + if (!found) + itsAdditionals.add(e) + } + existing.errors.enumerators.addAll(itsAdditionals) + } + } + return itsMethods.values + } + + def generateDefinition(FMethod fMethod, boolean _isDefault) { + fMethod.generateDefinitionWithin(null, _isDefault) + } + + def generateDefinitionWithin(FMethod fMethod, String parentClassName, boolean _isDefault) { var definition = 'void ' if (FTypeGenerator::isdeprecated(fMethod.comment)) definition = "COMMONAPI_DEPRECATED " + definition if (!parentClassName.nullOrEmpty) definition = definition + parentClassName + '::' - definition = definition + fMethod.elementName + '(' + fMethod.generateDefinitionSignature + ')' + definition = definition + fMethod.elementName + '(' + fMethod.generateDefinitionSignature(_isDefault) + ')' return definition } - def generateDefinitionSignature(FMethod fMethod) { - var signature = fMethod.inArgs.map['const ' + getTypeName(fMethod.model) + '& ' + elementName].join(', ') + def generateDefinitionSignature(FMethod fMethod, boolean _isDefault) { + var signature = fMethod.inArgs.map['const ' + getTypeName(fMethod, true) + ' &_' + elementName].join(', ') if (!fMethod.inArgs.empty) signature = signature + ', ' - signature = signature + 'CommonAPI::CallStatus& callStatus' + signature = signature + 'CommonAPI::CallStatus &_status' if (fMethod.hasError) - signature = signature + ', ' + fMethod.getErrorNameReference(fMethod.eContainer) + '& methodError' + signature = signature + ', ' + fMethod.getErrorNameReference(fMethod.eContainer) + ' &_error' if (!fMethod.outArgs.empty) - signature = signature + ', ' + fMethod.outArgs.map[getTypeName(fMethod.model) + '& ' + elementName].join(', ') - - return signature - } - - def generateStubSignatureCompatibility(FMethod fMethod) { - var signature = fMethod.inArgs.map[getTypeName(fMethod.model) + ' ' + elementName].join(', ') - if (!fMethod.inArgs.empty && (fMethod.hasError || !fMethod.outArgs.empty)) - signature = signature + ', ' + signature = signature + ', ' + fMethod.outArgs.map[getTypeName(fMethod, true) + ' &_' + elementName].join(', ') - signature = signature + generateStubSignatureErrorsAndOutArgs(fMethod) + if (!fMethod.fireAndForget) { + signature += ", const CommonAPI::CallInfo *_info" + if (_isDefault) + signature += " = nullptr" + } return signature } def generateStubSignature(FMethod fMethod) { - var signature = 'const std::shared_ptr<CommonAPI::ClientId> clientId' + var signature = 'const std::shared_ptr<CommonAPI::ClientId> _client' if (!fMethod.inArgs.empty) signature = signature + ', ' - signature = signature + fMethod.inArgs.map[getTypeName(fMethod.model) + ' ' + elementName].join(', ') - - if (fMethod.hasError || !fMethod.outArgs.empty) - signature = signature + ', ' - - signature = signature + generateStubSignatureErrorsAndOutArgs(fMethod) - + signature = signature + fMethod.inArgs.map[getTypeName(fMethod, true) + ' _' + elementName].join(', ') + + if (!fMethod.isFireAndForget) { + if (signature != "") + signature = signature + ", "; + signature = signature + fMethod.elementName + "Reply_t _reply"; + } + return signature } - - def generateStubSignatureOldStyle(FMethod fMethod) { + + def generateStubReplySignature(FMethod fMethod) { var signature = '' - signature = signature + fMethod.inArgs.map[getTypeName(fMethod.model) + ' ' + elementName].join(', ') - - if ((fMethod.hasError || !fMethod.outArgs.empty) && !fMethod.inArgs.empty) + if (fMethod.hasError) + signature = signature + fMethod.getErrorNameReference(fMethod.eContainer) + ' _error' + if (fMethod.hasError && !fMethod.outArgs.empty) signature = signature + ', ' - signature = signature + generateStubSignatureErrorsAndOutArgs(fMethod) + if (!fMethod.outArgs.empty) + signature = signature + fMethod.outArgs.map[getTypeName(fMethod, true) + ' _' + elementName].join(', ') return signature } + + def String generateDummyArgumentInitializations(FMethod fMethod) { + var String retval = "" + for(list_element : fMethod.outArgs) { + retval += getTypeName(list_element, fMethod, true) + ' ' + list_element.elementName + if (((list_element.type.derived instanceof FStructType + && (list_element.type.derived as FStructType).hasPolymorphicBase)) + || list_element.array){ + retval += " = {}" + } else if(list_element.type.predefined != null) { + // primitive types + switch list_element.type.predefined { + case FBasicTypeId::BOOLEAN: retval+= " = false" + case FBasicTypeId::INT8: retval += " = 0" + case FBasicTypeId::UINT8: retval += " = 0" + case FBasicTypeId::INT16: retval += " = 0" + case FBasicTypeId::UINT16: retval += " = 0" + case FBasicTypeId::INT32: retval += " = 0" + case FBasicTypeId::UINT32: retval += " = 0" + case FBasicTypeId::INT64: retval += " = 0" + case FBasicTypeId::UINT64: retval += " = 0" + case FBasicTypeId::FLOAT: retval += " = 0.0f" + case FBasicTypeId::DOUBLE: retval += " = 0.0" + case FBasicTypeId::STRING: retval += " = \"\"" + case FBasicTypeId::BYTE_BUFFER: retval += " = {}" + default: {}//System.out.println("No initialization generated for" + + //" non-basic type: " + list_element.getName) + } + } + retval += ";\n" + } + return retval + } + + def generateDummyArgumentDefinitions(FMethod fMethod) { + var definition = '' + if (fMethod.hasError) + definition = fMethod.getErrorNameReference(fMethod.eContainer) + ' error;\n' + if (!fMethod.outArgs.empty) + definition = definition + generateDummyArgumentInitializations(fMethod) + return definition + } + + def generateDummyArgumentList(FMethod fMethod) { + var arguments = '' + if (fMethod.hasError) + arguments = "error" + if (!fMethod.outArgs.empty) { + if (arguments != '') + arguments = arguments + ', ' + arguments = arguments + fMethod.outArgs.map[elementName].join(', ') + } + return arguments + } def generateFireSelectiveSignatur(FBroadcast fBroadcast, FInterface fInterface) { - var signature = 'const std::shared_ptr<CommonAPI::ClientId> clientId' + var signature = 'const std::shared_ptr<CommonAPI::ClientId> _client' if (!fBroadcast.outArgs.empty) signature = signature + ', ' signature = signature + - fBroadcast.outArgs.map['const ' + getTypeName(fInterface.model) + '& ' + elementName].join(', ') + fBroadcast.outArgs.map['const ' + getTypeName(fInterface, true) + ' &_' + elementName].join(', ') return signature } def generateSendSelectiveSignatur(FBroadcast fBroadcast, FInterface fInterface, Boolean withDefault) { - var signature = fBroadcast.outArgs.map['const ' + getTypeName(fInterface.model) + '& ' + elementName].join(', ') + var signature = fBroadcast.outArgs.map['const ' + getTypeName(fInterface, true) + ' &_' + elementName].join(', ') if (!fBroadcast.outArgs.empty) signature = signature + ', ' - signature = signature + 'const std::shared_ptr<CommonAPI::ClientIdList> receivers' + signature = signature + 'const std::shared_ptr<CommonAPI::ClientIdList> _receivers' if (withDefault) - signature = signature + ' = NULL' + signature = signature + ' = nullptr' return signature } @@ -366,24 +512,45 @@ class FrancaGeneratorExtensions { var signature = '' if (fMethod.hasError) - signature = signature + fMethod.getErrorNameReference(fMethod.eContainer) + '& methodError' + signature = signature + fMethod.getErrorNameReference(fMethod.eContainer) + ' &_error' if (fMethod.hasError && !fMethod.outArgs.empty) signature = signature + ', ' if (!fMethod.outArgs.empty) - signature = signature + fMethod.outArgs.map[getTypeName(fMethod.model) + '& ' + elementName].join(', ') + signature = signature + fMethod.outArgs.map[getTypeName(fMethod, true) + ' &_' + elementName].join(', ') return signature } - def generateArgumentsToStubCompatibility(FMethod fMethod) { + def generateArgumentsToStub(FMethod fMethod) { + var arguments = ' _client' + + if (!fMethod.inArgs.empty) + arguments = arguments + ', ' + fMethod.inArgs.map[elementName].join(', ') + + if ((fMethod.hasError || !fMethod.outArgs.empty)) + arguments = arguments + ', ' + + if (fMethod.hasError) + arguments = arguments + '_error' + + if (fMethod.hasError && !fMethod.outArgs.empty) + arguments = arguments + ', ' + + if (!fMethod.outArgs.empty) + arguments = arguments + fMethod.outArgs.map[elementName].join(', ') + + return arguments + } + + def generateArgumentsToStubOldStyle(FMethod fMethod) { var arguments = fMethod.inArgs.map[elementName].join(', ') if ((fMethod.hasError || !fMethod.outArgs.empty) && !fMethod.inArgs.empty) arguments = arguments + ', ' if (fMethod.hasError) - arguments = arguments + 'methodError' + arguments = arguments + '_error' if (fMethod.hasError && !fMethod.outArgs.empty) arguments = arguments + ', ' @@ -393,30 +560,64 @@ class FrancaGeneratorExtensions { return arguments } - def generateAsyncDefinition(FMethod fMethod) { - fMethod.generateAsyncDefinitionWithin(null) + def generateAsyncDefinition(FMethod fMethod, boolean _isDefault) { + fMethod.generateAsyncDefinitionWithin(null, _isDefault) } - def generateAsyncDefinitionWithin(FMethod fMethod, String parentClassName) { + def generateAsyncDefinitionWithin(FMethod fMethod, String parentClassName, boolean _isDefault) { var definition = 'std::future<CommonAPI::CallStatus> ' if (!parentClassName.nullOrEmpty) { definition = definition + parentClassName + '::' } - definition = definition + fMethod.elementName + 'Async(' + fMethod.generateAsyncDefinitionSignature + ')' + definition = definition + fMethod.elementName + 'Async(' + fMethod.generateAsyncDefinitionSignature(_isDefault) + ')' return definition } - def generateAsyncDefinitionSignature(FMethod fMethod) { - var signature = fMethod.inArgs.map['const ' + getTypeName(fMethod.model) + '& ' + elementName].join(', ') + def generateAsyncDefinitionSignature(FMethod fMethod, boolean _isDefault) { + var signature = fMethod.inArgs.map['const ' + getTypeName(fMethod, true) + ' &_' + elementName].join(', ') if (!fMethod.inArgs.empty) { signature = signature + ', ' } - return signature + fMethod.asyncCallbackClassName + ' callback' + + signature += fMethod.asyncCallbackClassName + ' _callback' + signature += ", const CommonAPI::CallInfo *_info" + if (_isDefault) + signature += " = nullptr" + + return signature + } + + def getErrorType(FMethod _method) { + var errorType = "" + if (_method.hasError) { + errorType = _method.getErrorNameReference(_method.eContainer) + } + return errorType } + def getInTypeList(FMethod _method) { + return _method.inArgs.map[getTypeName(_method, true)].join(', ') + } + + def getOutTypeList(FMethod _method) { + return _method.outArgs.map[getTypeName(_method, true)].join(', ') + } + + def getErrorAndOutTypeList(FMethod _method) { + val errorType = _method.errorType + val outTypes = _method.outTypeList + + var errorAndOutTypes = errorType + if (errorType != "" && outTypes != "") + errorAndOutTypes = errorAndOutTypes + ", " + errorAndOutTypes = errorAndOutTypes + outTypes + + return errorAndOutTypes + } + def private String getBasicMangledName(FBasicTypeId basicType) { switch (basicType) { case FBasicTypeId::BOOLEAN: @@ -445,6 +646,9 @@ class FrancaGeneratorExtensions { return "s" case FBasicTypeId::BYTE_BUFFER: return "au8" + default: { + return null + } } } @@ -522,7 +726,7 @@ class FrancaGeneratorExtensions { signature = signature + ', const ' + fMethod.getErrorNameReference(fMethod.eContainer) + '&' if (!fMethod.outArgs.empty) - signature = signature + ', ' + fMethod.outArgs.map['const ' + getTypeName(fMethod.model) + '&'].join(', ') + signature = signature + ', ' + fMethod.outArgs.map['const ' + getTypeName(fMethod, true) + '&'].join(', ') return signature } @@ -540,7 +744,7 @@ class FrancaGeneratorExtensions { def getErrorNameReference(FMethod fMethod, EObject source) { checkArgument(fMethod.hasError, 'FMethod has no error: ' + fMethod) if (fMethod.errorEnum != null) { - return fMethod.errorEnum.getRelativeNameReference((source as FModelElement).model) + return fMethod.errorEnum.getElementName(fMethod, true) } var errorNameReference = fMethod.errors.errorName @@ -595,7 +799,7 @@ class FrancaGeneratorExtensions { def getClassName(FBroadcast fBroadcast) { var className = fBroadcast.elementName.toFirstUpper - if (!fBroadcast.selective.nullOrEmpty) + if (fBroadcast.selective) className = className + 'Selective' className = className + 'Event' @@ -606,6 +810,10 @@ class FrancaGeneratorExtensions { def generateGetMethodDefinition(FBroadcast fBroadcast) { fBroadcast.generateGetMethodDefinitionWithin(null) } + + def String getTypes(FBroadcast _broadcast) { + return _broadcast.outArgs.map[getTypeName(_broadcast, true)].join(', ') + } def generateGetMethodDefinitionWithin(FBroadcast fBroadcast, String parentClassName) { var definition = fBroadcast.className + '& ' @@ -658,26 +866,28 @@ class FrancaGeneratorExtensions { 'const std::shared_ptr<CommonAPI::ClientId> clientId, bool& success' } - def boolean isSelective(FBroadcast fBroadcast) { - return !fBroadcast.selective.nullOrEmpty - } - - def getTypeName(FTypedElement element, EObject source) { - var typeName = element.type.getNameReference(source) - - if (element.type.derived instanceof FStructType && (element.type.derived as FStructType).hasPolymorphicBase) + def String getTypeName(FTypedElement _element, FModelElement _source, boolean _isOther) { + var String typeName = _element.type.getElementType(_source, _isOther) + + if (_element.type.derived instanceof FStructType && (_element.type.derived as FStructType).hasPolymorphicBase) typeName = 'std::shared_ptr<' + typeName + '>' - if ("[]".equals(element.array)) { - if (element.type.derived instanceof FStructType && (element.type.derived as FStructType).hasPolymorphicBase) { - typeName = 'std::vector<std::shared_ptr<' + element.type.getNameReference(source) + '>>' - } else { - typeName = 'std::vector<' + element.type.getNameReference(source) + '>' - } + if (_element.array) { + typeName = 'std::vector<' + typeName + '>' } return typeName } + + def String getElementType(FTypeRef _typeRef, FModelElement _container, boolean _isOther) { + var String typeName + if (_typeRef.derived != null) { + typeName = _typeRef.derived.getElementName(_container, _isOther) + } else if (_typeRef.predefined != null) { + typeName = _typeRef.predefined.primitiveTypeName + } + return typeName + } def boolean isPolymorphic(FTypeRef typeRef) { return (typeRef.derived != null && typeRef.derived instanceof FStructType && (typeRef.derived as FStructType).polymorphic) @@ -694,7 +904,7 @@ class FrancaGeneratorExtensions { (fMethodErrors.eContainer as FMethod).elementName + 'Error' } - def getBackingType(FEnumerationType fEnumerationType, DeploymentInterfacePropertyAccessor deploymentAccessor) { + def getBackingType(FEnumerationType fEnumerationType, PropertyAccessor deploymentAccessor) { if (deploymentAccessor.getEnumBackingType(fEnumerationType) == EnumBackingType::UseDefault) { if (fEnumerationType.containingInterface != null) { switch (deploymentAccessor.getDefaultEnumBackingType(fEnumerationType.containingInterface)) { @@ -734,11 +944,76 @@ class FrancaGeneratorExtensions { return FBasicTypeId::INT32 case EnumBackingType::Int64: return FBasicTypeId::INT64 + default: { + return FBasicTypeId::INT32 + } } - return FBasicTypeId::INT32 } - def getPrimitiveTypeName(FBasicTypeId fBasicTypeId) { + def String getBaseType(FEnumerationType _enumeration, String _backingType) { + var String baseType + if (_enumeration.base != null) { + baseType = _enumeration.base.getElementName(_enumeration, false) + } else { + baseType = "CommonAPI::Enumeration<" + _backingType + ">" + } + return baseType + } + + def private getMaximumEnumerationValue(FEnumerationType _enumeration) { + var int maximum = 0; + for (literal : _enumeration.enumerators) { + if (literal.value != null && literal.value != "") { + val int literalValue = Integer.parseInt(literal.value.enumeratorValue) + if (maximum < literalValue) + maximum = literalValue + } + } + return maximum + } + + def void setEnumerationValues(FEnumerationType _enumeration) { + var int currentValue = 0 + val predefineEnumValues = new ArrayList<String>() + + // collect all predefined enum values + for (literal : _enumeration.enumerators) { + if (literal.value != null) { + System.out.println(literal.value) + predefineEnumValues.add(literal.value.enumeratorValue) + } + } + if (_enumeration.base != null) { + setEnumerationValues(_enumeration.base) + currentValue = getMaximumEnumerationValue(_enumeration.base) + 1 + } + + for (literal : _enumeration.enumerators) { + if (literal.value == null || literal.value == "") { + // not predefined + while (predefineEnumValues.contains(String.valueOf(currentValue))) { + // increment it, if this was found in the list of predefined values + currentValue += 1 + } + literal.setValue(toExpression(Integer.toString(currentValue))) + } else { + var enumValue = literal.value.enumeratorValue + if (enumValue != null) { + try { + val int literalValue = Integer.parseInt(enumValue) + literal.setValue(toExpression(Integer.toString(literalValue))) + } catch (NumberFormatException e) { + literal.setValue(toExpression(Integer.toString(currentValue))) + } + } else { + literal.setValue(toExpression(Integer.toString(currentValue))) + } + } + currentValue += 1 + } + } + + def getPrimitiveTypeName(FBasicTypeId fBasicTypeId) { switch fBasicTypeId { case FBasicTypeId::BOOLEAN: "bool" case FBasicTypeId::INT8: "int8_t" @@ -757,8 +1032,8 @@ class FrancaGeneratorExtensions { } } - def String typeStreamSignature(FTypeRef fTypeRef, DeploymentInterfacePropertyAccessor deploymentAccessor, FField forThisElement) { - if (forThisElement.array != null && forThisElement.array.equals("[]")) { + def String typeStreamSignature(FTypeRef fTypeRef, PropertyAccessor deploymentAccessor, FField forThisElement) { + if (forThisElement.array) { var String ret = "" ret = ret + "typeOutputStream.beginWriteVectorType();\n" ret = ret + fTypeRef.actualTypeStreamSignature(deploymentAccessor) @@ -768,7 +1043,7 @@ class FrancaGeneratorExtensions { return fTypeRef.actualTypeStreamSignature(deploymentAccessor) } - def String actualTypeStreamSignature(FTypeRef fTypeRef, DeploymentInterfacePropertyAccessor deploymentAccessor) { + def String actualTypeStreamSignature(FTypeRef fTypeRef, PropertyAccessor deploymentAccessor) { if (fTypeRef.derived != null) { return fTypeRef.derived.typeStreamFTypeSignature(deploymentAccessor) } @@ -776,6 +1051,36 @@ class FrancaGeneratorExtensions { return fTypeRef.predefined.basicTypeStreamSignature } + def String createSerials(FStructType fStructType) { + var String serials; + serials = "static const CommonAPI::Serial " + + fStructType.elementName.toUpperCase() + "_SERIAL = 0x" + + getSerialId(fStructType).toHexString.toUpperCase() + ";\n"; + for (derived : fStructType.derivedFStructTypes) + serials = serials + createSerials(derived) + return serials + } + + def String generateCases(FStructType fStructType, FModelElement parent, boolean qualified) { + var String itsCases = "case "; + + if (parent != null) + itsCases = itsCases + parent.elementName + "::" + + if (qualified) { + itsCases = itsCases + if (fStructType.containingInterface != null) + itsCases = itsCases + fStructType.containingInterface.elementName + "::"; + } + + itsCases = itsCases + fStructType.elementName.toUpperCase() + "_SERIAL:\n"; + + for (derived : fStructType.derivedFStructTypes) + itsCases = itsCases + derived.generateCases(parent, qualified); + + return itsCases; + } + def private String getBasicTypeStreamSignature(FBasicTypeId fBasicTypeId) { switch fBasicTypeId { case FBasicTypeId::BOOLEAN: return "typeOutputStream.writeBoolType();" @@ -791,46 +1096,51 @@ class FrancaGeneratorExtensions { case FBasicTypeId::DOUBLE: return "typeOutputStream.writeDoubleType();" case FBasicTypeId::STRING: return "typeOutputStream.writeStringType();" case FBasicTypeId::BYTE_BUFFER: return "typeOutputStream.writeByteBufferType();" + default: return "UNDEFINED" } } def private dispatch String typeStreamFTypeSignature(FTypeDef fTypeDef, - DeploymentInterfacePropertyAccessor deploymentAccessor) { + PropertyAccessor deploymentAccessor) { return fTypeDef.actualType.actualTypeStreamSignature(deploymentAccessor) } def private dispatch String typeStreamFTypeSignature(FArrayType fArrayType, - DeploymentInterfacePropertyAccessor deploymentAccessor) { + PropertyAccessor deploymentAccessor) { return 'typeOutputStream.beginWriteVectorType();\n' + fArrayType.elementType.actualTypeStreamSignature(deploymentAccessor) + '\n' + 'typeOutputStream.endWriteVectorType();' } def private dispatch String typeStreamFTypeSignature(FMapType fMap, - DeploymentInterfacePropertyAccessor deploymentAccessor) { + PropertyAccessor deploymentAccessor) { return 'typeOutputStream.beginWriteMapType();\n' + fMap.keyType.actualTypeStreamSignature(deploymentAccessor) + '\n' + fMap.valueType.actualTypeStreamSignature(deploymentAccessor) + '\n' + 'typeOutputStream.endWriteMapType();' } def private dispatch String typeStreamFTypeSignature(FStructType fStructType, - DeploymentInterfacePropertyAccessor deploymentAccessor) { + PropertyAccessor deploymentAccessor) { return 'typeOutputStream.beginWriteStructType();\n' + fStructType.getElementsTypeStreamSignature(deploymentAccessor) + '\n' + 'typeOutputStream.endWriteStructType();' } def private dispatch String typeStreamFTypeSignature(FEnumerationType fEnumerationType, - DeploymentInterfacePropertyAccessor deploymentAccessor) { - return fEnumerationType.getBackingType(deploymentAccessor).basicTypeStreamSignature + PropertyAccessor deploymentAccessor) { + val backingType = fEnumerationType.getBackingType(deploymentAccessor) + if (backingType != FBasicTypeId.UNDEFINED) + return backingType.basicTypeStreamSignature + + return FBasicTypeId.INT32.basicTypeStreamSignature } def private dispatch String typeStreamFTypeSignature(FUnionType fUnionType, - DeploymentInterfacePropertyAccessor deploymentAccessor) { + PropertyAccessor deploymentAccessor) { return 'typeOutputStream.writeVariantType();' } def private String getElementsTypeStreamSignature(FStructType fStructType, - DeploymentInterfacePropertyAccessor deploymentAccessor) { + PropertyAccessor deploymentAccessor) { var signature = fStructType.elements.map[type.typeStreamSignature(deploymentAccessor, it)].join if (fStructType.base != null) @@ -890,6 +1200,10 @@ class FrancaGeneratorExtensions { return fStructType.base != null && fStructType.base.hasPolymorphicBase } + + def boolean hasDerivedTypes(FStructType fStructType) { + return !fStructType.derivedFStructTypes.empty + } def getSerialId(FStructType fStructType) { val hasher = Hashing::murmur3_32.newHasher @@ -957,7 +1271,7 @@ class FrancaGeneratorExtensions { return EcoreUtil.UsageCrossReferencer::find(fStructType, fStructType.model.eResource.resourceSet).map[EObject]. filter[it instanceof FStructType].map[it as FStructType].filter[base == fStructType] } - + def generateCppNamespace(FModel fModel) ''' «fModel.namespaceAsList.map[toString].join("::")»::''' @@ -973,8 +1287,49 @@ class FrancaGeneratorExtensions { «ENDFOR» ''' + def generateVersionNamespaceBegin(FTypeCollection _tc) ''' + «var FVersion itsVersion = _tc.version» + «IF itsVersion != null && (itsVersion.major != 0 || itsVersion.minor != 0)» + namespace v«itsVersion.major.toString»_«itsVersion.minor.toString» { + «ENDIF» + ''' + + def generateVersionNamespaceEnd(FTypeCollection _tc) ''' + «var FVersion itsVersion = _tc.version» + «IF itsVersion != null && (itsVersion.major != 0 || itsVersion.minor != 0)» + } // namespace v«itsVersion.major.toString»_«itsVersion.minor.toString» + «ENDIF» + ''' + + def generateDeploymentNamespaceBegin(FTypeCollection _tc) ''' + namespace «_tc.elementName»_ { + ''' + + def generateDeploymentNamespaceEnd(FTypeCollection _tc) ''' + } // namespace «_tc.elementName»_ + ''' + + def getVersionPrefix(FTypeCollection _tc) { + var String prefix = "::" + var FVersion itsVersion = _tc.version + if (itsVersion != null && (itsVersion.major != 0 || itsVersion.minor != 0)) { + prefix += "v" + itsVersion.major.toString + "_" + itsVersion.minor.toString + "::" + } + return prefix + } + + def getVersionPathPrefix(FTypeCollection _tc) { + var String prefix = "" + var FVersion itsVersion = _tc.version + if (itsVersion != null && (itsVersion.major != 0 || itsVersion.minor != 0)) { + prefix = "v" + itsVersion.major.toString + "_" + itsVersion.minor.toString + "/" + } + return prefix + } + + // TODO: Remove the following method def isFireAndForget(FMethod fMethod) { - return !fMethod.fireAndForget.nullOrEmpty + return fMethod.fireAndForget } def getFilePath(Resource resource) { @@ -991,7 +1346,7 @@ class FrancaGeneratorExtensions { if (FrameworkUtil::getBundle(this.getClass()) != null) { var returnValue = DefaultScope::INSTANCE.getNode(PreferenceConstants::SCOPE).get(PreferenceConstants::P_LICENSE, "") returnValue = InstanceScope::INSTANCE.getNode(PreferenceConstants::SCOPE).get(PreferenceConstants::P_LICENSE, returnValue) - returnValue = FPreferences::instance.getPreference(res, PreferenceConstants::P_LICENSE, returnValue) + returnValue = FPreferences::instance.getPreference(PreferenceConstants::P_LICENSE, returnValue) return returnValue } return "" @@ -1057,7 +1412,7 @@ class FrancaGeneratorExtensions { } def stubRegisterManagedMethodImpl(FInterface fInterface) { - fInterface.stubRegisterManagedName + '(std::shared_ptr<' + fInterface.stubClassName + '> stub, const std::string& instance)' + fInterface.stubRegisterManagedName + '(std::shared_ptr<' + fInterface.stubClassName + '> _stub, const std::string &_instance)' } def stubDeregisterManagedName(FInterface fInterface) { @@ -1071,37 +1426,276 @@ class FrancaGeneratorExtensions { def proxyManagerMemberName(FInterface fInterface) { 'proxyManager' + fInterface.elementName + '_' } - - def EList<FMethod> getInheritedMethods(FInterface fInterface) { + + def Set<FInterface> getBaseInterfaces(FInterface _interface) { + val Set<FInterface> baseInterfaces = new HashSet<FInterface>() + if (_interface.base != null) { + baseInterfaces.add(_interface.base) + baseInterfaces.addAll(getBaseInterfaces(_interface.base)) + } + return baseInterfaces + } + + def generateBaseInstantiations(FInterface _interface) { + val Set<FInterface> baseInterfaces = getBaseInterfaces(_interface) + return baseInterfaces.map[getTypeCollectionName(_interface) + "(_address, _connection)"].join(',\n') + } + + def generateDBusBaseInstantiations(FInterface _interface) { + val Set<FInterface> baseInterfaces = getBaseInterfaces(_interface) + return baseInterfaces.map[ + getTypeCollectionName(_interface) + + "DBusProxy(_address, _connection)" + ].join(',\n') + } + + def String generateBaseRemoteHandlerConstructorsCalls(FInterface _interface) { + val Set<FInterface> baseInterfaces = getBaseInterfaces(_interface) + var String itsCalls = "" + itsCalls = baseInterfaces.map[getTypeCollectionName(_interface) + "StubDefault::RemoteEventHandler(_defaultStub)"].join(', ') + if (itsCalls != "") + itsCalls = itsCalls + ',' + return itsCalls + } + + def List<FMethod> getInheritedMethods(FInterface fInterface) { + val List<FMethod> result = new ArrayList<FMethod>() + if(fInterface.base == null) { - return new BasicEList() + return result } - val methods = fInterface.base.methods - methods.addAll(fInterface.base.inheritedMethods) + result.addAll(fInterface.base.methods) + result.addAll(fInterface.base.inheritedMethods) - return methods + return result } - def EList<FAttribute> getInheritedAttributes(FInterface fInterface) { + def List<FAttribute> getInheritedAttributes(FInterface fInterface) { + val List<FAttribute> result = new ArrayList<FAttribute>() if(fInterface.base == null) { - return new BasicEList() + return result } - val attributes = fInterface.base.attributes - attributes.addAll(fInterface.base.inheritedAttributes) + result.addAll(fInterface.base.attributes) + result.addAll(fInterface.base.inheritedAttributes) - return attributes + return result } - def EList<FBroadcast> getInheritedBroadcasts(FInterface fInterface) { + def List<FBroadcast> getInheritedBroadcasts(FInterface fInterface) { + val List<FBroadcast> result = new ArrayList<FBroadcast>() + if(fInterface.base == null) { - return new BasicEList() + return result } - val broadcasts = fInterface.base.broadcasts - broadcasts.addAll(fInterface.base.inheritedBroadcasts) + result.addAll(fInterface.base.broadcasts) + result.addAll(fInterface.base.inheritedBroadcasts) + + return result + } + + def static FExpression toExpression(String value) + { + return switch trimmedValue : if(value != null) value.trim else "" + { + case trimmedValue.length > 0: + { + try + { + FrancaFactory.eINSTANCE.createFIntegerConstant => [ + ^val = new BigInteger(trimmedValue) + ] + } + catch(NumberFormatException e) + { + FrancaFactory.eINSTANCE.createFStringConstant => [ + ^val = trimmedValue + ] + } + } + default: + { + null + } + } + } + + def static String getEnumeratorValue(FExpression expression) + { + return switch (expression) + { + FIntegerConstant: expression.^val.toString + FStringConstant: expression.^val + FQualifiedElementRef: expression.element.constantValue + default: null + } + } + + def static String getConstantValue(FModelElement expression) + { + return switch (expression) + { + FConstantDef: expression.rhs.constantType + default: null + } + } + + def static String getConstantType(FInitializerExpression expression) + { + return switch (expression) + { + FIntegerConstant: expression.^val.toString + default: null + } + } - return broadcasts + def Integer getTimeout(FMethod _method, PropertyAccessor _accessor) { + var timeout = 0; + try { + timeout = _accessor.getTimeout(_method) + } + catch (NullPointerException e) { + // intentionally empty + } + return timeout + } + + def boolean isTheSameVersion(FVersion _mine, FVersion _other) { + return ((_mine == null && _other == null) || + (_mine != null && _other != null && + _mine.major == _other.major && + _mine.minor == _other.minor)); + + } + + def EObject getCommonContainer(EObject _me, EObject _other) { + if (_other == null) + return null + + if (_me == _other) + return _me + + if (_me instanceof FTypeCollection && _other instanceof FTypeCollection) { + val FTypeCollection me = _me as FTypeCollection + val FTypeCollection other = _other as FTypeCollection + + if (me.eContainer == other.eContainer && + ((me.version == null && other.version == null) || + (me.version != null && other.version != null && + me.version.major == other.version.major && + me.version.minor == other.version.minor))) { + return _me; + } + } + + return getCommonContainer(_me, _other.eContainer) + } + + def String getContainerName(EObject _container) { + var String name = "" + if (_container instanceof FTypeCollection) { + name = _container.name + if (name == null) name = "__Anonymous__" + } else if (_container instanceof FModelElement) { + name = _container.name + } else if (_container instanceof FModel) { + name = _container.name + } + return name + } + + def String getPartialName(FModelElement _me, EObject _until) { + var String name = _me.containerName + var EObject container = _me.eContainer + while (container != null && container != _until) { + if (container instanceof FModel) { + name = container.name + "::" + name + } + if (container instanceof FModelElement) { + name = container.name + "::" + name + } + container = container.eContainer + } + return name.replace(".", "::") + } + + def String getFullName(EObject _me) { + var String name = "" + if (_me instanceof FModelElement) { + var String prefix = "" + var EObject container = _me + while (container != null) { + if (container instanceof FTypeCollection) { + prefix = (container as FTypeCollection).versionPrefix + } + val containerName = getContainerName(container) + if (containerName != null && containerName != "") { + if (name != "") { + name = containerName + "::" + name + } else { + name = containerName + } + } + + container = container.eContainer + } + name = prefix + name + } + return name.replace(".", "::") + } + + def String getElementName(FModelElement _me, FModelElement _other, boolean _isOther) { + if (_other == null) + return _me.containerName + + var FVersion myVersion = null + if (_me instanceof FTypeCollection) + myVersion = _me.version + + var FVersion otherVersion = null + if (_other instanceof FTypeCollection) + otherVersion = _other.version + + if (isTheSameVersion(myVersion, otherVersion)) { + val EObject myContainer = _me.eContainer + val EObject otherContainer = _other.eContainer + + if (myContainer == otherContainer) { + var String name = _me.containerName + if (_isOther) { + name = getContainerName(myContainer) + "::" + _me.containerName + } + return name + } + + if (myContainer.getCommonContainer(otherContainer) != null) { + return _me.getPartialName(myContainer.eContainer) + } + + if (otherContainer.getCommonContainer(myContainer) != null) { + var String name = _me.containerName + if (_isOther) { + name = getContainerName(myContainer) + "::" + name + } + return name + } + } + + return _me.getFullName() + } + + def String getTypeCollectionName(FTypeCollection _me, FTypeCollection _other) { + if (_other == null || + _me.eContainer() != _other.eContainer() || + !isTheSameVersion(_me.version, _other.version)) { + return _me.getFullName() + } + return _me.getContainerName() + } + + def String getEnumPrefix(){ + FPreferences::instance.getPreference(PreferenceConstants::P_ENUMPREFIX, "") } -}
\ No newline at end of file +} diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/MyFrancaPersistenceManager.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/MyFrancaPersistenceManager.java deleted file mode 100644 index d13d3a6..0000000 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/MyFrancaPersistenceManager.java +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright (C) 2013 BMW Group - * Author: Manfred Bathelt (manfred.bathelt@bmw.de) - * Author: Juergen Gehring (juergen.gehring@bmw.de) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.genivi.commonapi.core.generator; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.franca.core.dsl.FrancaImportsProvider; -import org.franca.core.dsl.FrancaPersistenceManager; -import org.franca.core.franca.FModel; -import org.franca.core.utils.FileHelper; - -import com.google.inject.Inject; -import com.google.inject.Provider; - -public class MyFrancaPersistenceManager extends FrancaPersistenceManager { - - private final String fileExtension = "fidl"; - - @Inject - private Provider<ResourceSet> resourceSetProvider; - - @Override - public FModel loadModel(String filename) { - try { - URI uri = FileHelper.createURI(filename); - URI fileURI = MyModelPersistenceHandler.normalizeURI(uri); - - if (fileURI.segmentCount() > 1) { - return loadModel(fileURI.lastSegment(), fileURI.trimSegments(1) - .toString() + "/"); - } else { - return loadModel(filename, ""); - } - } catch (Exception ex) { - System.err.println("Error: " + ex.getMessage()); - return null; - } - } - - private FModel loadModel(String filename, String cwd) { - String fn = filename; - - if (fn == null) - return null; - if (!fn.endsWith("." + fileExtension)) { - fn += "." + fileExtension; - } - - MyModelPersistenceHandler persistenceHandler = createMyModelPersistenceHandler(resourceSetProvider - .get()); - return (FModel) persistenceHandler.loadModel(fn, cwd); - } - - private MyModelPersistenceHandler createMyModelPersistenceHandler( - ResourceSet resourceSet) { - MyModelPersistenceHandler.registerFileExtensionHandler(fileExtension, - new FrancaImportsProvider()); - - MyModelPersistenceHandler persistenceHandler = new MyModelPersistenceHandler( - resourceSet); - return persistenceHandler; - } -} diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/MyModelPersistenceHandler.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/MyModelPersistenceHandler.java deleted file mode 100644 index 3ead770..0000000 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/MyModelPersistenceHandler.java +++ /dev/null @@ -1,82 +0,0 @@ -/* Copyright (C) 2013 BMW Group - * Author: Manfred Bathelt (manfred.bathelt@bmw.de) - * Author: Juergen Gehring (juergen.gehring@bmw.de) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.genivi.commonapi.core.generator; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.franca.core.utils.ImportsProvider; -import org.franca.core.utils.ModelPersistenceHandler; - -public class MyModelPersistenceHandler extends ModelPersistenceHandler { - - private ResourceSet resourceSet; - - private static Map<String, ImportsProvider> fileHandlerRegistry = new HashMap<String, ImportsProvider>(); - - public MyModelPersistenceHandler(ResourceSet newResourceSet) { - super(newResourceSet); - } - - public static void registerFileExtensionHandler(String extension, - ImportsProvider importsProvider) { - fileHandlerRegistry.put(extension, importsProvider); - } - - @Override - public EObject loadModel(String filename, String cwd) { - resourceSet = super.getResourceSet(); - Path p = new Path(filename); - URI fileURI; - URI cwdURI; - if (!p.isAbsolute()) { - fileURI = normalizeURI(URI.createURI(filename)); - cwdURI = normalizeURI(URI.createURI(cwd)); - } else { - URI absolutURI = normalizeURI(URI.createURI(filename)); - fileURI = normalizeURI(URI.createURI(absolutURI.lastSegment())); - cwdURI = normalizeURI(URI.createURI(absolutURI.toString() - .substring(0, absolutURI.toString().lastIndexOf("/") + 1))); - } - Resource resource = null; - - if (cwd != null && cwd.length() > 0) { - resourceSet - .getURIConverter() - .getURIMap() - .put(fileURI, - URI.createURI((cwdURI.toString() + "/" + fileURI - .toString()).replaceAll("/+", "/"))); - } - - try { - resource = resourceSet.getResource(fileURI, true); - resource.load(Collections.EMPTY_MAP); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - EObject model = resource.getContents().get(0); - - for (Iterator<String> it = fileHandlerRegistry.get( - fileURI.fileExtension()).importsIterator(model); it.hasNext();) { - String importURI = it.next(); - this.loadModel(importURI, getCWDForImport(fileURI, cwdURI) - .toString()); - } - return model; - } -} diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/FPreferences.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/FPreferences.java index 598e38a..5a78630 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/FPreferences.java +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/FPreferences.java @@ -8,29 +8,27 @@ package org.genivi.commonapi.core.preferences; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; + import java.util.HashMap; import java.util.Map; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.xtext.generator.IFileSystemAccess; +import org.eclipse.xtext.generator.OutputConfiguration; import org.franca.core.franca.FModel; + public class FPreferences { private static FPreferences instance = null; - private Map<IResource, Map<String, String>> preferences = null; + private Map<String, String> preferences = null; - private FPreferences() { - preferences = new HashMap<IResource, Map<String, String>>(); + public Map<String, String> getPreferences() { + return preferences; + } + + private FPreferences() { + preferences = new HashMap<String, String>(); + clidefPreferences(); } public void resetPreferences(){ @@ -39,172 +37,115 @@ public class FPreferences { public static FPreferences getInstance() { if (instance == null) { - return instance = new FPreferences(); + instance = new FPreferences(); } return instance; } - public void clidefPreferences(){ - Map<String, String> map = new HashMap<String, String>(); - if (preferences.get(null) == null) { - preferences.put(null, map); - } + /** + * Apply defaults + */ + private void clidefPreferences(){ - if (!preferences.get(null).containsKey(PreferenceConstants.USEPROJECTSETTINGS)) { - map.put(PreferenceConstants.USEPROJECTSETTINGS, Boolean.FALSE.toString()); - } - if (!preferences.get(null).containsKey(PreferenceConstants.P_OUTPUT_PROXIES)) { - map.put(PreferenceConstants.P_OUTPUT_PROXIES, PreferenceConstants.DEFAULT_OUTPUT); + if (!preferences.containsKey(PreferenceConstants.P_OUTPUT_COMMON)) { + preferences.put(PreferenceConstants.P_OUTPUT_COMMON, PreferenceConstants.DEFAULT_OUTPUT); + } + if (!preferences.containsKey(PreferenceConstants.P_OUTPUT_PROXIES)) { + preferences.put(PreferenceConstants.P_OUTPUT_PROXIES, PreferenceConstants.DEFAULT_OUTPUT); } - if (!preferences.get(null).containsKey(PreferenceConstants.P_OUTPUT_STUBS)) { - map.put(PreferenceConstants.P_OUTPUT_STUBS, PreferenceConstants.DEFAULT_OUTPUT); + if (!preferences.containsKey(PreferenceConstants.P_OUTPUT_STUBS)) { + preferences.put(PreferenceConstants.P_OUTPUT_STUBS, PreferenceConstants.DEFAULT_OUTPUT); } - if (!preferences.get(null).containsKey(PreferenceConstants.P_LICENSE)) { - map.put(PreferenceConstants.P_LICENSE, PreferenceConstants.DEFAULT_LICENSE); + if (!preferences.containsKey(PreferenceConstants.P_OUTPUT_DEFAULT)) { + preferences.put(PreferenceConstants.P_OUTPUT_DEFAULT, PreferenceConstants.DEFAULT_OUTPUT); + } + if (!preferences.containsKey(PreferenceConstants.P_OUTPUT_SKELETON)) { + preferences.put(PreferenceConstants.P_OUTPUT_SKELETON, PreferenceConstants.DEFAULT_OUTPUT); + } + + if (!preferences.containsKey(PreferenceConstants.P_LICENSE)) { + preferences.put(PreferenceConstants.P_LICENSE, PreferenceConstants.DEFAULT_LICENSE); } - if (!preferences.get(null).containsKey(PreferenceConstants.P_GENERATESTUB)) { - map.put(PreferenceConstants.P_GENERATESTUB, Boolean.TRUE.toString()); + if (!preferences.containsKey(PreferenceConstants.P_GENERATESTUB)) { + preferences.put(PreferenceConstants.P_GENERATESTUB, "true"); } - if (!preferences.get(null).containsKey(PreferenceConstants.P_GENERATEPROXY)) { - map.put(PreferenceConstants.P_GENERATEPROXY, Boolean.TRUE.toString()); + if (!preferences.containsKey(PreferenceConstants.P_GENERATEPROXY)) { + preferences.put(PreferenceConstants.P_GENERATEPROXY, "true"); } - map.putAll(preferences.get(null)); - preferences.put(null, map); - } - - public void addPreferences(IResource res) { - Map<String, String> map = new HashMap<String, String>(); - - if (res != null) { - try { - QualifiedName useProjectSettingsIdentifier = new QualifiedName(PreferenceConstants.PROJECT_PAGEID, PreferenceConstants.USEPROJECTSETTINGS); - map.put(PreferenceConstants.USEPROJECTSETTINGS, res.getPersistentProperty(useProjectSettingsIdentifier)); - - QualifiedName outputPathIdentifier = new QualifiedName(PreferenceConstants.PROJECT_PAGEID, PreferenceConstants.P_OUTPUT_PROXIES); - map.put(PreferenceConstants.P_OUTPUT_PROXIES, res.getPersistentProperty(outputPathIdentifier)); - - QualifiedName outputPathStubsIdentifier = new QualifiedName(PreferenceConstants.PROJECT_PAGEID, PreferenceConstants.P_OUTPUT_STUBS); - map.put(PreferenceConstants.P_OUTPUT_STUBS, res.getPersistentProperty(outputPathStubsIdentifier)); - - QualifiedName licenseIdentifier = new QualifiedName(PreferenceConstants.PROJECT_PAGEID, PreferenceConstants.P_LICENSE); - map.put(PreferenceConstants.P_LICENSE, res.getPersistentProperty(licenseIdentifier)); - - QualifiedName generateStubsIdentifier = new QualifiedName(PreferenceConstants.PROJECT_PAGEID, PreferenceConstants.P_GENERATESTUB); - map.put(PreferenceConstants.P_GENERATESTUB, res.getPersistentProperty(generateStubsIdentifier)); - - QualifiedName generateProxiesIdentifier = new QualifiedName(PreferenceConstants.PROJECT_PAGEID, PreferenceConstants.P_GENERATEPROXY); - map.put(PreferenceConstants.P_GENERATEPROXY, res.getPersistentProperty(generateProxiesIdentifier)); - - } catch (CoreException e) { - e.printStackTrace(); - } - - } else { - clidefPreferences(); + if (!preferences.containsKey(PreferenceConstants.P_SKELETONPOSTFIX)) { + preferences.put(PreferenceConstants.P_SKELETONPOSTFIX, "Default"); } - preferences.put(res, map); - } - - public String getPreference(IResource res, String preferencename, String defaultValue) { - Map<String, String> map = getPreferencesForResource(res); - if (map != null - && map.get(preferencename) != null - && map.get(PreferenceConstants.USEPROJECTSETTINGS).equals(Boolean.TRUE.toString())) { - return map.get(preferencename); + if (!preferences.containsKey(PreferenceConstants.P_GENERATESKELETON)) { + preferences.put(PreferenceConstants.P_GENERATESKELETON, "false"); } - if (res instanceof IFile) { - return getPreference(res.getProject(), preferencename, defaultValue); + if (!preferences.containsKey(PreferenceConstants.P_LOGOUTPUT)) { + preferences.put(PreferenceConstants.P_LOGOUTPUT, "true"); } - return defaultValue; - } - - public boolean useModelSpecific(IResource res) { - Map<String, String> map = getPreferencesForResource(res); - return map.get(PreferenceConstants.USEPROJECTSETTINGS) != null - && map.get(PreferenceConstants.USEPROJECTSETTINGS).equals(Boolean.TRUE.toString()); - } - - private Map<String, String> getPreferencesForResource(IResource res) { - return preferences.get(res); - } - - public void setPreferences(String name, File file) throws IOException { - Reader r = null; - try { - r = new FileReader(file); - setPreference(name, r, ""); - } finally { - try { - r.close(); - } catch (IOException e) { - } + if (!preferences.containsKey(PreferenceConstants.P_ENUMPREFIX)) { + preferences.put(PreferenceConstants.P_ENUMPREFIX, ""); } + } - public void setPreference(String name, String preference) { - if(preferences.get(null) == null) { - preferences.put(null, new HashMap<String, String>()); - } - preferences.get(null).put(name, preference); + public String getPreference(String preferencename, String defaultValue) { + + if (preferences.containsKey(preferencename)) { + return preferences.get(preferencename); + } + System.err.println("Unknown preference " + preferencename); + return ""; } - public void setPreference(String name, Reader inreader, String path) throws IOException { - BufferedReader reader = new BufferedReader(inreader); - StringBuilder builder = new StringBuilder(); - String line = ""; - while ((line = reader.readLine()) != null) { - builder.append(line + "\n"); + public void setPreference(String name, String value) { + if(preferences != null) { + preferences.put(name, value); } - if (preferences.get(null) == null) - preferences.put(null, new HashMap<String, String>()); - preferences.get(null).put(name, builder.toString()); } public String getModelPath(FModel model) { String ret = model.eResource().getURI().toString(); return ret; } - - public static void init(IPreferenceStore store, IPreferenceStore defaultstore, IProject project) { - if (instance == null) { - instance = new FPreferences(); - } - String useProjectSettingsString = store.getString(PreferenceConstants.USEPROJECTSETTINGS); - boolean useProjectSettings = useProjectSettingsString.equals(Boolean.toString(true)); - if (useProjectSettings) { - if (instance.preferences.get(project) == null) { - instance.preferences.put(project, new HashMap<String, String>()); - } - instance.preferences.get(project).put(PreferenceConstants.USEPROJECTSETTINGS, Boolean.toString(true)); - - String outputFolderProxies = store.getString(PreferenceConstants.P_OUTPUT_PROXIES); - instance.preferences.get(project).put(PreferenceConstants.P_OUTPUT_PROXIES, outputFolderProxies); - - String outputFolderStubs = store.getString(PreferenceConstants.P_OUTPUT_STUBS); - instance.preferences.get(project).put(PreferenceConstants.P_OUTPUT_STUBS, outputFolderStubs); - - String licenseHeader = store.getString(PreferenceConstants.P_LICENSE); - instance.preferences.get(project).put(PreferenceConstants.P_LICENSE, licenseHeader); - - String generateProxy = store.getString(PreferenceConstants.P_GENERATEPROXY); - instance.preferences.get(project).put(PreferenceConstants.P_GENERATEPROXY, generateProxy); - - String generatStub = store.getString(PreferenceConstants.P_GENERATESTUB); - instance.preferences.get(project).put(PreferenceConstants.P_GENERATESTUB, generatStub); - } else { - if (instance.preferences.get(project) == null) { - instance.preferences.put(project, new HashMap<String, String>()); - } - instance.preferences.get(project).put(PreferenceConstants.P_OUTPUT_PROXIES, - defaultstore.getString(PreferenceConstants.P_OUTPUT_PROXIES)); - instance.preferences.get(project).put(PreferenceConstants.P_OUTPUT_STUBS, - defaultstore.getString(PreferenceConstants.P_OUTPUT_STUBS)); - instance.preferences.get(project).put(PreferenceConstants.P_LICENSE, - defaultstore.getString(PreferenceConstants.P_LICENSE)); - instance.preferences.get(project).put(PreferenceConstants.P_GENERATEPROXY, - defaultstore.getString(PreferenceConstants.P_GENERATEPROXY)); - instance.preferences.get(project).put(PreferenceConstants.P_GENERATESTUB, - defaultstore.getString(PreferenceConstants.P_GENERATESTUB)); - } + + /** + * Set the output path configurations (based on stored preference values) for file system access used in the generator. + * @return the map of output configurations + */ + public HashMap<String, OutputConfiguration> getOutputpathConfiguration() { + + String defaultDir = getPreference(PreferenceConstants.P_OUTPUT_DEFAULT, PreferenceConstants.DEFAULT_OUTPUT); + String outputCommonDir = getPreference(PreferenceConstants.P_OUTPUT_COMMON, defaultDir); + String outputProxyDir = getPreference(PreferenceConstants.P_OUTPUT_PROXIES, defaultDir); + String outputStubDir = getPreference(PreferenceConstants.P_OUTPUT_STUBS, defaultDir); + String outputSkelDir = getPreference(PreferenceConstants.P_OUTPUT_SKELETON, defaultDir); + + // the map of output directory configurations + HashMap<String, OutputConfiguration> outputs = new HashMap<String, OutputConfiguration> (); + + OutputConfiguration commonOutput = new OutputConfiguration(PreferenceConstants.P_OUTPUT_COMMON); + commonOutput.setDescription("Common Output Folder"); + commonOutput.setOutputDirectory(outputCommonDir); + commonOutput.setCreateOutputDirectory(true); + outputs.put(IFileSystemAccess.DEFAULT_OUTPUT, commonOutput); + + OutputConfiguration proxyOutput = new OutputConfiguration(PreferenceConstants.P_OUTPUT_PROXIES); + proxyOutput.setDescription("Proxy Output Folder"); + proxyOutput.setOutputDirectory(outputProxyDir); + proxyOutput.setCreateOutputDirectory(true); + outputs.put(PreferenceConstants.P_OUTPUT_PROXIES, proxyOutput); + + OutputConfiguration stubOutput = new OutputConfiguration(PreferenceConstants.P_OUTPUT_STUBS); + stubOutput.setDescription("Stub Output Folder"); + stubOutput.setOutputDirectory(outputStubDir); + stubOutput.setCreateOutputDirectory(true); + outputs.put(PreferenceConstants.P_OUTPUT_STUBS, stubOutput); + + OutputConfiguration skelOutput = new OutputConfiguration(PreferenceConstants.P_OUTPUT_SKELETON); + skelOutput.setDescription("Skeleton Output Folder"); + skelOutput.setOutputDirectory(outputSkelDir); + skelOutput.setCreateOutputDirectory(true); + outputs.put(PreferenceConstants.P_OUTPUT_SKELETON, skelOutput); + + return outputs; } } diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/PreferenceConstants.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/PreferenceConstants.java index ef8af66..74dc942 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/PreferenceConstants.java +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/PreferenceConstants.java @@ -11,20 +11,32 @@ package org.genivi.commonapi.core.preferences; /** * Constant definitions for plug-in preferences */ -public class PreferenceConstants +public interface PreferenceConstants { public static final String SCOPE = "org.genivi.commonapi.core.ui"; + public static final String PROJECT_PAGEID = "org.genivi.commonapi.core.ui.preferences.CommonAPIPreferencePage"; + + // preference keys public static final String P_LICENSE = "licenseHeader"; public static final String P_OUTPUT_PROXIES = "outputDirProxies"; public static final String P_OUTPUT_STUBS = "outputDirStubs"; - public static final String USEPROJECTSETTINGS = "useProjectSettings"; - public static final String DEFAULT_OUTPUT = "./src-gen/"; - public static final String DEFAULT_LICENSE = "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.\n" - + "If a copy of the MPL was not distributed with this file, You can obtain one at\n" - + "http://mozilla.org/MPL/2.0/."; + public static final String P_OUTPUT_COMMON = "outputDirCommon"; + public static final String P_OUTPUT_SKELETON = "outputDirSkeleton"; + public static final String P_OUTPUT_DEFAULT = "outputDirDefault"; public static final String P_GENERATEPROXY = "generateproxy"; public static final String P_GENERATESTUB = "generatestub"; - public static final String PROJECT_PAGEID = "org.genivi.commonapi.core.ui.preferences.CommonAPIPreferencePage"; - public static final String FRANCA_VERSION = "francaversion"; - public static final String CORE_VERSION = "coreversion"; + public static final String P_GENERATESKELETON = "generateskeleton"; + public static final String P_LOGOUTPUT = "logoutput"; + public static final String P_ENUMPREFIX = "enumprefix"; + public static final String P_SKELETONPOSTFIX = "skeletonpostfix"; + public static final String P_USEPROJECTSETTINGS = "useProjectSettings"; + + // preference values + public static final String DEFAULT_OUTPUT = "./src-gen/"; + public static final String LOGLEVEL_QUIET = "quiet"; + public static final String LOGLEVEL_VERBOSE = "verbose"; + public static final String DEFAULT_LICENSE = "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.\n" + + "If a copy of the MPL was not distributed with this file, You can obtain one at\n" + + "http://mozilla.org/MPL/2.0/."; + public static final String DEFAULT_SKELETONPOSTFIX = "Default"; } diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/verification/CppKeywords.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/verification/CppKeywords.java new file mode 100644 index 0000000..de5c0a2 --- /dev/null +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/verification/CppKeywords.java @@ -0,0 +1,107 @@ +/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.genivi.commonapi.core.verification; + +import java.util.ArrayList; +import java.util.List; + +public class CppKeywords { + + public List<String> keyWords = new ArrayList<String>(); + + public CppKeywords() { + + keyWords.add("alignas"); + keyWords.add("alignof"); + keyWords.add("and"); + keyWords.add("and_eq"); + keyWords.add("asm"); + keyWords.add("auto"); + keyWords.add("bitand"); + keyWords.add("bitor"); + keyWords.add("bool"); + keyWords.add("break"); + keyWords.add("case"); + keyWords.add("catch"); + keyWords.add("char"); + keyWords.add("char16_t"); + keyWords.add("char32_t"); + keyWords.add("class"); + keyWords.add("compl"); + keyWords.add("const"); + keyWords.add("constexpr"); + keyWords.add("const_cast"); + keyWords.add("continue"); + keyWords.add("decltype"); + keyWords.add("default"); + keyWords.add("delete"); + keyWords.add("do"); + keyWords.add("double"); + keyWords.add("dynamic_cast"); + keyWords.add("else"); + keyWords.add("enum"); + keyWords.add("explicit"); + keyWords.add("export"); + keyWords.add("extern"); + keyWords.add("false"); + keyWords.add("float"); + keyWords.add("for"); + keyWords.add("friend"); + keyWords.add("goto"); + keyWords.add("if"); + keyWords.add("inline"); + keyWords.add("int"); + keyWords.add("long"); + keyWords.add("mutable"); + keyWords.add("namespace"); + keyWords.add("new"); + keyWords.add("noexcept"); + keyWords.add("not"); + keyWords.add("not_eq"); + keyWords.add("nullptr"); + keyWords.add("operator"); + keyWords.add("or"); + keyWords.add("or_eq"); + keyWords.add("private"); + keyWords.add("protected"); + keyWords.add("public"); + keyWords.add("register"); + keyWords.add("reinterpret_cast"); + keyWords.add("return"); + keyWords.add("short"); + keyWords.add("signed"); + keyWords.add("sizeof"); + keyWords.add("static"); + keyWords.add("static_assert"); + keyWords.add("static_cast"); + keyWords.add("struct"); + keyWords.add("switch"); + keyWords.add("template"); + keyWords.add("this"); + keyWords.add("thread_local"); + keyWords.add("throw"); + keyWords.add("true"); + keyWords.add("try"); + keyWords.add("typedef"); + keyWords.add("typeid"); + keyWords.add("typename"); + keyWords.add("union"); + keyWords.add("unsigned"); + keyWords.add("using"); + keyWords.add("virtual"); + keyWords.add("void"); + keyWords.add("volatile"); + keyWords.add("wchar_t"); + keyWords.add("while"); + keyWords.add("xor"); + keyWords.add("xor_eq"); + + keyWords.add("AnonymousTypeCollection"); + } + +} diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/verification/ValidatorCore.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/verification/ValidatorCore.java new file mode 100644 index 0000000..0f4eb4c --- /dev/null +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/verification/ValidatorCore.java @@ -0,0 +1,369 @@ +package org.genivi.commonapi.core.verification; +/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.xtext.validation.ValidationMessageAcceptor; +import org.franca.core.dsl.validation.IFrancaExternalValidator; +import org.franca.core.franca.FArgument; +import org.franca.core.franca.FAttribute; +import org.franca.core.franca.FBroadcast; +import org.franca.core.franca.FEnumerationType; +import org.franca.core.franca.FEnumerator; +import org.franca.core.franca.FField; +import org.franca.core.franca.FInterface; +import org.franca.core.franca.FMethod; +import org.franca.core.franca.FModel; +import org.franca.core.franca.FModelElement; +import org.franca.core.franca.FStructType; +import org.franca.core.franca.FType; +import org.franca.core.franca.FTypeCollection; +import org.franca.core.franca.FrancaPackage; +import org.osgi.framework.BundleReference; +import org.osgi.framework.Version; + +/** + * This validator is used with the command line environment (it is not automatically triggered from the XText editor). + * It is meant to be called before the actual code generation. The code generation may not be executed if this + * validator detects errors. + * + */ +public class ValidatorCore implements IFrancaExternalValidator { + + private CppKeywords cppKeywords = new CppKeywords(); + private HashMap<String, HashSet<String>> importList = new HashMap<String, HashSet<String>>(); + protected ResourceSet resourceSet = new ResourceSetImpl(); + + @Override + public void validateModel(FModel model, + ValidationMessageAcceptor messageAcceptor) { + + acceptInfo("model " + model.getName(), messageAcceptor); + + List<String> interfaceTypecollectionNames = new ArrayList<String>(); + for (FTypeCollection fTypeCollection : model.getTypeCollections()) { + interfaceTypecollectionNames.add(fTypeCollection.getName()); + } + HashMap<FInterface, EList<FInterface>> managedInterfaces = new HashMap<FInterface, EList<FInterface>>(); + for (FInterface fInterface : model.getInterfaces()) { + interfaceTypecollectionNames.add(fInterface.getName()); + managedInterfaces + .put(fInterface, fInterface.getManagedInterfaces()); + } + + for (FTypeCollection fTypeCollection : model.getTypeCollections()) { + validateTypeCollectionName(messageAcceptor, + interfaceTypecollectionNames, fTypeCollection); + validateTypeCollectionElements(messageAcceptor, fTypeCollection); + } + + for (FInterface fInterface : model.getInterfaces()) { + validateTypeCollectionName(messageAcceptor, + interfaceTypecollectionNames, fInterface); + validateManagedInterfaces(messageAcceptor, fInterface); + validateFInterfaceElements(messageAcceptor, fInterface); + } + + interfaceTypecollectionNames.clear(); + importList.clear(); + } + + protected void validateManagedInterfaces(ValidationMessageAcceptor messageAcceptor, FInterface fInterface) { + ArrayList<FInterface> startI = new ArrayList<FInterface>(); + int index = 0; + startI.add(fInterface); + ArrayList<FInterface> managedList = new ArrayList<FInterface>(); + for (FInterface managedInterface : fInterface.getManagedInterfaces()) { + if(managedInterface.getName() == null) { + acceptError("unknown managed interface: " + managedInterface.getName(), fInterface, + FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, index, messageAcceptor); + } else { + acceptInfo("managed interface: " + managedInterface.getName(), messageAcceptor); + } + findCyclicManagedInterfaces(managedInterface, startI, fInterface, + messageAcceptor, index, false); + if (managedList.contains(managedInterface)) + acceptError("Interface " + managedInterface.getName() + + " is already managed! Delete this equivalent!", + fInterface, + FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, + index, messageAcceptor); + managedList.add(managedInterface); + index++; + } + } + + private void findCyclicManagedInterfaces(FInterface rekInterface, + ArrayList<FInterface> interfaceList, FInterface fInterface, + ValidationMessageAcceptor messageAcceptor, int index, + boolean managed) { + if (interfaceList.contains(rekInterface)) { + String errorString = ""; + for (FInterface a : interfaceList) { + errorString = errorString + a.getName() + " -> "; + } + errorString = errorString + rekInterface.getName(); + if (rekInterface.equals(fInterface)) { + acceptError("Interface " + fInterface.getName() + + " manages itself: " + errorString, fInterface, + FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, + index, messageAcceptor); + } else { + // if(!managed){ + acceptError("Cycle detected: " + errorString, fInterface, + FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, + index, messageAcceptor); + // } + } + // acceptError("Cycle detected: " +errorString, fInterface, + // FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, index, + // messageAcceptor); + } else { + interfaceList.add(rekInterface); + for (FInterface nextInterface : rekInterface.getManagedInterfaces()) { + findCyclicManagedInterfaces(nextInterface, interfaceList, + fInterface, messageAcceptor, index, managed); + } + if (rekInterface.getBase() != null) + findCyclicManagedInterfaces(rekInterface.getBase(), + interfaceList, fInterface, messageAcceptor, index, true); + interfaceList.remove(rekInterface); + } + } + + // TODO: use it without workspace context +// private void validateImport(FModel model, +// ValidationMessageAcceptor messageAcceptor, final IFile file, +// IPath filePath, String cwd) { +// HashSet<String> importedFiles = new HashSet<String>(); +// ArrayList<String> importUriAndNamesspace = new ArrayList<String>(); +// for (Import fImport : model.getImports()) { +// acceptInfo("validateImport: " + fImport.getImportedNamespace()); +// if (importUriAndNamesspace.contains(fImport.getImportURI() + "," +// + fImport.getImportedNamespace())) +// acceptWarning("Multiple times imported!", fImport, +// FrancaPackage.Literals.IMPORT__IMPORT_URI, -1, +// messageAcceptor); +// if (fImport.getImportURI().equals(file.getName())) { +// acceptError("Class may not import itself!", fImport, +// FrancaPackage.Literals.IMPORT__IMPORT_URI, -1, +// messageAcceptor); +// } else { +// Path absoluteImportPath = new Path(fImport.getImportURI()); +// if (!absoluteImportPath.isAbsolute()) { +// absoluteImportPath = new Path(cwd + "/" +// + fImport.getImportURI()); +// importedFiles.add(absoluteImportPath.toString()); +// } else { +// importedFiles.add(absoluteImportPath.toString() +// .replaceFirst(absoluteImportPath.getDevice() + "/", +// "")); +// } +// +// } +// importUriAndNamesspace.add(fImport.getImportURI() + "," +// + fImport.getImportedNamespace()); +// } +// importUriAndNamesspace.clear(); +// importList.put(filePath.toString(), importedFiles); +// +// ArrayList<String> start = new ArrayList<String>(); +// try { +// importList = buildImportList(importList); +// } catch (NullPointerException e) { +// } +// start.add(filePath.toString()); +// for (Import fImport : model.getImports()) { +// Path importPath = new Path(fImport.getImportURI()); +// if (importPath.isAbsolute()) { +// findCyclicImports( +// importPath.toString().replaceFirst( +// importPath.getDevice() + "/", ""), +// filePath.toString(), start, fImport, messageAcceptor); +// } else { +// importPath = new Path(cwd + "/" + fImport.getImportURI()); +// findCyclicImports(importPath.toString(), filePath.toString(), +// start, fImport, messageAcceptor); +// } +// } +// start.clear(); +// } + + + + protected EObject buildResource(String filename, String cwd) { + URI fileURI = normalizeURI(URI.createURI(filename)); + URI cwdURI = normalizeURI(URI.createURI(cwd)); + Resource resource = null; + + if (cwd != null && cwd.length() > 0) { + resourceSet + .getURIConverter() + .getURIMap() + .put(fileURI, + URI.createURI((cwdURI.toString() + "/" + fileURI + .toString()).replaceAll("/+", "/"))); + } + + try { + resource = resourceSet.getResource(fileURI, true); + resource.load(Collections.EMPTY_MAP); + } catch (RuntimeException e) { + return null; + } catch (IOException io) { + return null; + } + + return resource.getContents().get(0); + } + + protected static URI normalizeURI(URI path) { + if (path.isFile()) { + return URI.createURI(path.toString().replaceAll("\\\\", "/")); + } + return path; + } + + protected void validateTypeCollectionName( + ValidationMessageAcceptor messageAcceptor, + List<String> interfaceTypecollectionNames, + FTypeCollection fTypeCollection) { + + acceptInfo("type collection: " + fTypeCollection.getName(), messageAcceptor); + + validateName(messageAcceptor, + fTypeCollection); + if (!isFrancaVersionGreaterThan(0, 8, 9)) { + if (interfaceTypecollectionNames.indexOf(fTypeCollection.getName()) != interfaceTypecollectionNames + .lastIndexOf(fTypeCollection.getName())) { + acceptError("Name " + fTypeCollection.getName() + + " isn't unique in this file!", fTypeCollection, + FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, + messageAcceptor); + } + } + } + + protected void validateTypeCollectionElements( + ValidationMessageAcceptor messageAcceptor, + FTypeCollection fTypeCollection) { + for (FType fType : fTypeCollection.getTypes()) { + validateName(messageAcceptor, fType); + if (fType instanceof FStructType) { + for (FField fField : ((FStructType) fType).getElements()) { + validateName(messageAcceptor, fField); + } + } + + if (fType instanceof FEnumerationType) { + for (FEnumerator fEnumerator : ((FEnumerationType) fType) + .getEnumerators()) { + validateName(messageAcceptor, + fEnumerator); + } + } + } + } + + protected void validateFInterfaceElements( + ValidationMessageAcceptor messageAcceptor, FInterface fInterface) { + acceptInfo("interface elements: " + fInterface.getName(), messageAcceptor); + if (fInterface.getVersion() == null) + acceptError("Missing version! Add: version(major int minor int)", + fInterface, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, + -1, messageAcceptor); + + for (FAttribute att : fInterface.getAttributes()) { + validateName(messageAcceptor, att); + } + for (FBroadcast fBroadcast : fInterface.getBroadcasts()) { + validateName(messageAcceptor, fBroadcast); + for (FArgument out : fBroadcast.getOutArgs()) { + validateName(messageAcceptor, out); + } + } + for (FMethod fMethod : fInterface.getMethods()) { + validateName(messageAcceptor, fMethod); + for (FArgument out : fMethod.getOutArgs()) { + validateName(messageAcceptor, out); + } + for (FArgument in : fMethod.getInArgs()) { + validateName(messageAcceptor, in); + } + } + } + + private void validateName(ValidationMessageAcceptor messageAcceptor, + EObject eObject) { + String name = ((FModelElement) eObject).getName(); + if (cppKeywords.keyWords.contains(name)) { + acceptError("Name " + name + + " is a keyword in c++", eObject, + FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, + messageAcceptor); + return; + } + } + + private boolean isFrancaVersionGreaterThan(int major, int minor, int micro) { + Version francaVersion = ((BundleReference) FArgument.class + .getClassLoader()).getBundle().getVersion(); + if (francaVersion.getMajor() > major) { + return true; + } + if (francaVersion.getMajor() < major){ + return false; + } + if (francaVersion.getMinor() > minor) { + return true; + } + if (francaVersion.getMinor() < minor){ + return false; + } + if (francaVersion.getMicro() > micro) { + return true; + } + if (francaVersion.getMicro() < micro) { + return false; + } + return false; + } + + protected void acceptError(String message, EObject object, + EStructuralFeature feature, int index, + ValidationMessageAcceptor messageAcceptor) { + messageAcceptor.acceptError(message, object, + feature, index, null); + } + + protected void acceptWarning(String message, EObject object, + EStructuralFeature feature, int index, + ValidationMessageAcceptor messageAcceptor) { + messageAcceptor.acceptWarning(message, object, + feature, index, null); + } + + protected void acceptInfo(String message, ValidationMessageAcceptor messageAcceptor) { + messageAcceptor.acceptInfo(message, null, null, 0, null); + } + +} |