All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.joynr.generator.cpp.proxy.InterfaceAsyncProxyCppTemplate.xtend Maven / Gradle / Ivy

There is a newer version: 0.9.3
Show newest version
package io.joynr.generator.cpp.proxy
/*
 * !!!
 *
 * Copyright (C) 2011 - 2015 BMW Car IT GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.google.inject.Inject
import io.joynr.generator.cpp.util.CppStdTypeUtil
import io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions
import io.joynr.generator.cpp.util.TemplateBase
import io.joynr.generator.util.InterfaceTemplate
import org.franca.core.franca.FInterface

class InterfaceAsyncProxyCppTemplate implements InterfaceTemplate{
	@Inject	extension JoynrCppGeneratorExtensions
	@Inject extension TemplateBase
	@Inject extension CppStdTypeUtil

	override generate(FInterface fInterface)
'''
«val interfaceName =  fInterface.joynrName»
«val className = interfaceName + "Proxy"»
«val asyncClassName = interfaceName + "AsyncProxy"»
«warning()»

#include "«getPackagePathWithJoynrPrefix(fInterface, "/")»/«asyncClassName».h"
«FOR parameterType: getRequiredIncludesFor(fInterface).addElements(includeForString)»
	#include «parameterType»
«ENDFOR»

#include "joynr/Future.h"
#include "joynr/exceptions.h"
#include "joynr/Request.h"
#include "joynr/Reply.h"
#include "joynr/RequestStatus.h"
#include "joynr/RequestStatusCode.h"
#include 

«getNamespaceStarter(fInterface)»
«asyncClassName»::«asyncClassName»(
		QSharedPointer messagingAddress,
		joynr::ConnectorFactory* connectorFactory,
		joynr::IClientCache *cache,
		const std::string &domain,
		const joynr::MessagingQos &qosSettings,
		bool cached
) :
	joynr::ProxyBase(connectorFactory, cache, domain, INTERFACE_NAME(), qosSettings, cached),
	«className»Base(messagingAddress, connectorFactory, cache, domain, qosSettings, cached)
{
}

«FOR attribute: getAttributes(fInterface)»
	«var attributeName = attribute.joynrName»
	«var attributeType = attribute.typeName»
	«IF attribute.readable»
		«var getAttribute = "get" + attributeName.toFirstUpper»
		/*
		 * «getAttribute»
		 */

		std::shared_ptr> «asyncClassName»::«getAttribute»Async(
				std::function onSuccess,
				std::function onError
		)
		{
			if (connector==NULL){
				«val errorMsg = "proxy cannot invoke " + getAttribute + ", because the communication end partner is not (yet) known"»
				LOG_WARN(logger, "«errorMsg»");
				joynr::RequestStatus status(RequestStatusCode::ERROR, "«errorMsg»");
				if (onError) {
					onError(status);
				}
				std::shared_ptr> future(new joynr::Future<«attributeType»>());
				future->onError(status);
				return future;
			}
			else{
				return connector->«getAttribute»Async(onSuccess);
			}
		}

	«ENDIF»
	«IF attribute.writable»
		«var setAttribute = "set" + attributeName.toFirstUpper»
		/*
		 * «setAttribute»
		 */

		std::shared_ptr> «asyncClassName»::«setAttribute»Async(
				«attributeType» «attributeName»,
				std::function onSuccess,
				std::function onError
		)
		{
			if (connector==NULL){
				«val errorMsg = "proxy cannot invoke " + setAttribute + ", because the communication end partner is not (yet) known"»
				LOG_WARN(logger, "«errorMsg»");
				joynr::RequestStatus status(RequestStatusCode::ERROR, "«errorMsg»");
				if (onError) {
					onError(status);
				}
				std::shared_ptr> future(new joynr::Future());
				future->onError(status);
				return future;
			}
			else{
				return connector->«setAttribute»Async(«attributeName», onSuccess);
			}
		}

	«ENDIF»
«ENDFOR»
«FOR method: getMethods(fInterface)»
	«var methodName = method.joynrName»
	«var outputParameters = method.commaSeparatedOutputParameterTypes»
	«var outputTypedParamList = method.commaSeperatedTypedConstOutputParameterList»
	«var inputParamList = getCommaSeperatedUntypedInputParameterList(method)»
	/*
	 * «methodName»
	 */
	std::shared_ptr > «asyncClassName»::«methodName»Async(
			«IF !method.inputParameters.empty»«method.commaSeperatedTypedConstInputParameterList»,«ENDIF»
			std::function onSuccess,
			std::function onError
	)
	{
		if (connector==NULL){
			«val errorMsg = "proxy cannot invoke " + methodName + ", because the communication end partner is not (yet) known"»
			LOG_WARN(logger, "«errorMsg»");
			joynr::RequestStatus status(RequestStatusCode::ERROR, "«errorMsg»");
			if (onError) {
				onError(status);
			}
			std::shared_ptr> future(new joynr::Future<«outputParameters»>());
			future->onError(status);
			return future;
		}
		else{
			return connector->«methodName»Async(«inputParamList»«IF !method.inputParameters.empty», «ENDIF»onSuccess);
		}
	}

«ENDFOR»
«getNamespaceEnder(fInterface)»
'''
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy