service_splitter.py
Go to the documentation of this file.
00001 # *****************************************************************************
00002 #
00003 # Copyright (c) 2018, Southwest Research Institute (SwRI)
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are met:
00008 #     * Redistributions of source code must retain the above copyright
00009 #       notice, this list of conditions and the following disclaimer.
00010 #     * Redistributions in binary form must reproduce the above copyright
00011 #       notice, this list of conditions and the following disclaimer in the
00012 #       documentation and/or other materials provided with the distribution.
00013 #     * Neither the name of Southwest Research Institute (SwRI) nor the
00014 #       names of its contributors may be used to endorse or promote products
00015 #       derived from this software without specific prior written permission.
00016 #
00017 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 # ARE DISCLAIMED. IN NO EVENT SHALL SOUTHWEST RESEARCH INSTITUTE BE LIABLE FOR ANY
00021 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 #
00028 # *****************************************************************************
00029 
00030 # This file takes in a service file and splits it into two topics and a header file with useful
00031 # includes and type definitions to match standard services.
00032 
00033 # Arguments are:
00034 # 1. Input service file path
00035 # 2. Output Request message file path
00036 # 3. Output Response message file path
00037 # 4. Package name
00038 # 5. Service name
00039 # 6. Output header file path
00040 
00041 import sys
00042 
00043 data = sys.argv
00044 
00045 
00046 rf = open(data[1], "rb")
00047 contents = rf.read();
00048 lines = contents.split('---')# split by statement
00049 #split by brackets
00050 rf.close()
00051 
00052 
00053 oi = open(data[2], "wb")
00054 oi.write("marti_common_msgs/ServiceHeader srv_header\n")
00055 oi.write(lines[0])
00056 oi.close()
00057 
00058 oi = open(data[3], "wb")
00059 oi.write("marti_common_msgs/ServiceHeader srv_header\n")
00060 oi.write(lines[1])
00061 oi.close()
00062 
00063 # Write out a wrapper header so we can use and include it like it is a service
00064 # Data 4 has the message name and 5 has the message name
00065 data[5] = data[5].replace(".srv", "")
00066 
00067 oi = open(data[6], "wb")
00068 name = data[4] + "_" + data[5]
00069 oi.write("// This file is autogenerated, do not modify\n")
00070 oi.write("#ifndef _" + name + "_TOPIC_SERVICE_H_\n")
00071 oi.write("#define _" + name + "_TOPIC_SERVICE_H_\n")
00072 
00073 oi.write("#include <" + data[4] + "/" + data[5] + "Response.h>\n")
00074 oi.write("#include <" + data[4] + "/" + data[5] + "Request.h>\n\n")
00075 
00076 oi.write("namespace " + data[4] + "{\n")
00077 oi.write("class " + data[5] + "{ public: \n")
00078 oi.write("typedef " + data[5] + "Response Response;\n")
00079 oi.write("typedef " + data[5] + "Request Request;\n")
00080 oi.write("  Request request; Response response;\n")
00081 oi.write("};\n}\n")
00082 
00083 oi.write("#endif")


swri_roscpp
Author(s):
autogenerated on Thu Jun 6 2019 20:34:47