diff options
Diffstat (limited to 'tools/InterfaceGenerator')
4 files changed, 97 insertions, 4 deletions
diff --git a/tools/InterfaceGenerator/Generator.py b/tools/InterfaceGenerator/Generator.py index 5b5894bc00..932620c153 100755 --- a/tools/InterfaceGenerator/Generator.py +++ b/tools/InterfaceGenerator/Generator.py @@ -26,6 +26,7 @@ import generator.parsers.SDLRPCV2 import generator.parsers.JSONRPC import generator.generators.SmartFactorySDLRPC import generator.generators.SmartFactoryJSONRPC +import MsgVersionGenerate from generator.parsers.RPCBase import ParseError from generator.generators.SmartFactoryBase import GenerateError @@ -71,7 +72,6 @@ def _handle_fatal_error(error): print sys.exit(errno.EINVAL) - def main(): """Main function of the generator that does actual work.""" @@ -101,6 +101,13 @@ Generating interface source code with following parameters: except ParseError as error: _handle_fatal_error(error) + # Parse sdl version from MOBILE_API.xml and create source file with this version + if src_xml_name == "MOBILE_API": + try: + MsgVersionGenerate.generate_msg_version(src_xml, output_dir) + except ParseError as error: + _handle_fatal_error(error) + # Generate SmartFactory source code from internal model try: code_generator.generate(interface, diff --git a/tools/InterfaceGenerator/MsgVersionGenerate.py b/tools/InterfaceGenerator/MsgVersionGenerate.py new file mode 100644 index 0000000000..7ff6c384d3 --- /dev/null +++ b/tools/InterfaceGenerator/MsgVersionGenerate.py @@ -0,0 +1,85 @@ +""" +Generate file with major and minor msg_version. +""" +import xml.etree.ElementTree +from string import Template +import re +from generator.parsers import RPCBase + +def generate_msg_version(file_name, path_to_storage): + """Parses MOBILE_API.xml in order to + receive major_version and minor_version + """ + tree = xml.etree.ElementTree.parse(file_name) + root = tree.getroot() + if (root.tag == "interface" and "version" in root.attrib): + check_version_format(root.attrib["version"]) + array = (root.attrib["version"]).split(".") + major_version = array[0] + minor_version = array[1] + if (major_version.isdigit() and minor_version.isdigit()): + data_for_storage = prepare_data_for_storage(major_version, minor_version) + store_data_to_file(path_to_storage, data_for_storage) + else: + raise RPCBase.ParseError("Attribute version has incorect value in MOBILE_API.xml") + else: + raise RPCBase.ParseError("Check MOBILE_API.xml file, parser can not find first element " + " with tag interface or atribute version") + +def store_data_to_file(path_to_storage, data_for_storage): + """Stores data with major and minor version + to file generated_msg_version.h + """ + path_to_storage = path_to_storage + "/generated_msg_version.h" + fh = open(path_to_storage, 'w') + fh.write(data_for_storage) + fh.close() + +def check_version_format(version): + """Checks correctness of format of version + """ + p = re.compile('\d+\\.\d+') + result = p.match(version) + if result == None or (result.end() != len(version)): + raise RPCBase.ParseError("Incorrect format of version please check MOBILE_API.xml. " + "Need format of version major_version.minor_version") + +def prepare_data_for_storage(major_version, minor_version): + """Prepares data to store to file. + """ + temp = Template( + u'''/*Copyright (c) 2016, Ford Motor Company\n''' + u'''All rights reserved.\n''' + u'''Redistribution and use in source and binary forms, with or without\n''' + u'''modification, are permitted provided that the following conditions are met:\n''' + u'''Redistributions of source code must retain the above copyright notice, this\n''' + u'''list of conditions and the following disclaimer.\n''' + u'''Redistributions in binary form must reproduce the above copyright notice,\n''' + u'''this list of conditions and the following\n''' + u'''disclaimer in the documentation and/or other materials provided with the\n''' + u'''distribution.\n''' + u'''Neither the name of the Ford Motor Company nor the names of its contributors\n''' + u'''may be used to endorse or promote products derived from this software\n''' + u'''without specific prior written permission.\n''' + u'''THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n''' + u'''AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n''' + u'''IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n''' + u'''ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\n''' + u'''LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n''' + u'''CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n''' + u'''SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n''' + u'''INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n''' + u'''CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n''' + u'''ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n''' + u'''POSSIBILITY OF SUCH DAMAGE.\n''' + u'''*/\n''' + u'''#ifndef GENERATED_MSG_VERSION_H\n''' + u'''#define GENERATED_MSG_VERSION_H\n\n''' + u'''namespace application_manager {\n\n''' + u'''const uint16_t major_version = $m_version;\n''' + u'''const uint16_t minor_version = $min_version;\n''' + u'''} // namespace application_manager\n''' + u'''#endif // GENERATED_MSG_VERSION_H''') + data_to_file = temp.substitute(m_version = major_version, min_version = minor_version) + return data_to_file + diff --git a/tools/InterfaceGenerator/generator/generators/SmartFactoryBase.py b/tools/InterfaceGenerator/generator/generators/SmartFactoryBase.py index 2b372021c2..d13ac29c9b 100755 --- a/tools/InterfaceGenerator/generator/generators/SmartFactoryBase.py +++ b/tools/InterfaceGenerator/generator/generators/SmartFactoryBase.py @@ -1223,7 +1223,7 @@ class CodeGenerator(object): _hpp_schema_file_tempalte = string.Template( u'''/**\n''' - u''' * @file ${class_name}.hpp\n''' + u''' * @file ${class_name}.h\n''' u''' * @brief Generated class ${class_name} header file.\n''' u''' *\n''' u''' * This class is a part of SmartObjects solution. It provides\n''' @@ -1280,7 +1280,7 @@ class CodeGenerator(object): u'''#ifndef $guard\n''' u'''#define $guard\n''' u'''\n''' - u'''#include "formatters/CSmartFactory.hpp"\n''' + u'''#include "formatters/CSmartFactory.h"\n''' u'''#include "smart_objects/smart_schema.h"\n''' u'''#include "smart_objects/schema_item.h"\n''' u'''#include "utils/shared_ptr.h"\n''' diff --git a/tools/InterfaceGenerator/generator/parsers/RPCBase.py b/tools/InterfaceGenerator/generator/parsers/RPCBase.py index 2b3db62d56..22f3fd2c2d 100755 --- a/tools/InterfaceGenerator/generator/parsers/RPCBase.py +++ b/tools/InterfaceGenerator/generator/parsers/RPCBase.py @@ -568,7 +568,8 @@ class Parser(object): default_value = self._get_bool_from_string(default_value); param_type = Model.Boolean(default_value=default_value) elif type_name == "Integer" or \ - type_name == "Float": + type_name == "Float" or \ + type_name == "Double" : min_value = self._extract_optional_number_attrib( attrib, "minvalue", int if type_name == "Integer" else float) max_value = self._extract_optional_number_attrib( |