<commit_before>package io.joynr.generator.cpp.provider
/*
 * !!!
 *
 * Copyright (C) 2011 - 2017 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.templates.InterfaceTemplate
import io.joynr.generator.templates.util.AttributeUtil
import io.joynr.generator.templates.util.InterfaceUtil
import io.joynr.generator.templates.util.MethodUtil
import io.joynr.generator.templates.util.NamingUtil

class InterfaceRequestInterpreterCppTemplate extends InterfaceTemplate {

	@Inject private extension TemplateBase
	@Inject private extension CppStdTypeUtil
	@Inject private extension JoynrCppGeneratorExtensions
	@Inject private extension NamingUtil
	@Inject private extension AttributeUtil
	@Inject private extension MethodUtil
	@Inject private extension InterfaceUtil

	override generate()
'''
«val interfaceName = francaIntf.joynrName»
«warning()»
#include <functional>
#include <tuple>

#include "«getPackagePathWithJoynrPrefix(francaIntf, "/")»/«interfaceName»RequestInterpreter.h"
#include "«getPackagePathWithJoynrPrefix(francaIntf, "/")»/«interfaceName»RequestCaller.h"
#include "joynr/Util.h"
#include "joynr/Request.h"
#include "joynr/OneWayRequest.h"
#include "joynr/BaseReply.h"
#include "joynr/exceptions/JoynrException.h"
#include "joynr/exceptions/MethodInvocationException.h"

«FOR parameterType: getDataTypeIncludesFor(francaIntf)»
	#include «parameterType»
«ENDFOR»

«getNamespaceStarter(francaIntf)»

INIT_LOGGER(«interfaceName»RequestInterpreter);

«val requestCallerName = interfaceName.toFirstLower+"RequestCallerVar"»
«val attributes = getAttributes(francaIntf)»
«val methodsWithoutFireAndForget = getMethods(francaIntf).filter[!fireAndForget]»
void «interfaceName»RequestInterpreter::execute(
		std::shared_ptr<joynr::RequestCaller> requestCaller,
		Request& request,
		std::function<void (BaseReply&& reply)>&& onSuccess,
		std::function<void (const std::shared_ptr<exceptions::JoynrException>& exception)>&& onError
) {
	«IF francaIntf.hasReadAttribute || francaIntf.hasWriteAttribute || !methodsWithoutFireAndForget.empty»
		// cast generic RequestCaller to «interfaceName»Requestcaller
		std::shared_ptr<«interfaceName»RequestCaller> «requestCallerName» =
				std::dynamic_pointer_cast<«interfaceName»RequestCaller>(requestCaller);

		const std::vector<std::string>& paramTypes = request.getParamDatatypes();
		const std::string& methodName = request.getMethodName();

		// execute operation
		«IF !attributes.empty»
			«FOR attribute : attributes»
				«val attributeName = attribute.joynrName»
				«IF attribute.readable»
				if (methodName == "get«attributeName.toFirstUpper»"){
					auto requestCallerOnSuccess =
							[onSuccess = std::move(onSuccess)](«attribute.typeName» «attributeName»){
								BaseReply reply;
								reply.setResponse(std::move(«attributeName»));
								onSuccess(std::move(reply));
							};
					«requestCallerName»->get«attributeName.toFirstUpper»(
						std::move(requestCallerOnSuccess),
						std::move(onError));
					return;
				}
			«ENDIF»
			«IF attribute.writable»
				if (methodName == "set«attributeName.toFirstUpper»" && paramTypes.size() == 1){
					try {
						«attribute.typeName» typedInput«attributeName.toFirstUpper»;
						request.getParams(typedInput«attributeName.toFirstUpper»);<commit_msg>[C++] avoid unused-variable warning in case of only void methods<commit_after>package io.joynr.generator.cpp.provider
/*
 * !!!
 *
 * Copyright (C) 2011 - 2017 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.templates.InterfaceTemplate
import io.joynr.generator.templates.util.AttributeUtil
import io.joynr.generator.templates.util.InterfaceUtil
import io.joynr.generator.templates.util.MethodUtil
import io.joynr.generator.templates.util.NamingUtil

class InterfaceRequestInterpreterCppTemplate extends InterfaceTemplate {

	@Inject private extension TemplateBase
	@Inject private extension CppStdTypeUtil
	@Inject private extension JoynrCppGeneratorExtensions
	@Inject private extension NamingUtil
	@Inject private extension AttributeUtil
	@Inject private extension MethodUtil
	@Inject private extension InterfaceUtil

	override generate()
'''
«val interfaceName = francaIntf.joynrName»
«warning()»
#include <functional>
#include <tuple>

#include "«getPackagePathWithJoynrPrefix(francaIntf, "/")»/«interfaceName»RequestInterpreter.h"
#include "«getPackagePathWithJoynrPrefix(francaIntf, "/")»/«interfaceName»RequestCaller.h"
#include "joynr/Util.h"
#include "joynr/Request.h"
#include "joynr/OneWayRequest.h"
#include "joynr/BaseReply.h"
#include "joynr/exceptions/JoynrException.h"
#include "joynr/exceptions/MethodInvocationException.h"

«FOR parameterType: getDataTypeIncludesFor(francaIntf)»
	#include «parameterType»
«ENDFOR»

«getNamespaceStarter(francaIntf)»

INIT_LOGGER(«interfaceName»RequestInterpreter);

«val requestCallerName = interfaceName.toFirstLower+"RequestCallerVar"»
«val attributes = getAttributes(francaIntf)»
«val methodsWithoutFireAndForget = getMethods(francaIntf).filter[!fireAndForget]»
void «interfaceName»RequestInterpreter::execute(
		std::shared_ptr<joynr::RequestCaller> requestCaller,
		Request& request,
		std::function<void (BaseReply&& reply)>&& onSuccess,
		std::function<void (const std::shared_ptr<exceptions::JoynrException>& exception)>&& onError
) {
	«IF francaIntf.hasReadAttribute || francaIntf.hasWriteAttribute || !methodsWithoutFireAndForget.empty»
		// cast generic RequestCaller to «interfaceName»Requestcaller
		std::shared_ptr<«interfaceName»RequestCaller> «requestCallerName» =
				std::dynamic_pointer_cast<«interfaceName»RequestCaller>(requestCaller);

		«IF francaIntf.hasMethodWithArguments || francaIntf.hasWriteAttribute»
			const std::vector<std::string>& paramTypes = request.getParamDatatypes();
		«ENDIF»
		const std::string& methodName = request.getMethodName();

		// execute operation
		«IF !attributes.empty»
			«FOR attribute : attributes»
				«val attributeName = attribute.joynrName»
				«IF attribute.readable»
				if (methodName == "get«attributeName.toFirstUpper»"){
					auto requestCallerOnSuccess =
							[onSuccess = std::move(onSuccess)](«attribute.typeName» «attributeName»){
								BaseReply reply;
								reply.setResponse(std::move(«attributeName»));
								onSuccess(std::move(reply));
							};
					«requestCallerName»->get«attributeName.toFirstUpper»(
						std::move(requestCallerOnSuccess),
						std::move(onError));
					return;
				}
			«ENDIF»
			«IF attribute.writable»
				if (methodName == "set«attributeName.toFirstUpper»" && paramTypes.size() == 1){
					try {
						«attribute.typeName» typedInput«attributeName.toFirstUpper»;
						request.getParams(typedInput«attributeName.toFirstUpper»);
{'fraction_non_alphanumeric': 0.10969481554112023, 'fraction_numerical': 0.0031866650324794705, 'mean_word_length': 5.81704260651629, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6822561', 'n_tokens_mistral': 2651, 'n_tokens_neox': 2407, 'n_words': 713}