Main Page
Namespaces
Classes
Files
File List
File Members
scripts
service_splitter.py
Go to the documentation of this file.
1
# *****************************************************************************
2
#
3
# Copyright (c) 2018, Southwest Research Institute (SwRI)
4
# All rights reserved.
5
#
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions are met:
8
# * Redistributions of source code must retain the above copyright
9
# notice, this list of conditions and the following disclaimer.
10
# * Redistributions in binary form must reproduce the above copyright
11
# notice, this list of conditions and the following disclaimer in the
12
# documentation and/or other materials provided with the distribution.
13
# * Neither the name of Southwest Research Institute (SwRI) nor the
14
# names of its contributors may be used to endorse or promote products
15
# derived from this software without specific prior written permission.
16
#
17
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
# ARE DISCLAIMED. IN NO EVENT SHALL SOUTHWEST RESEARCH INSTITUTE BE LIABLE FOR ANY
21
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#
28
# *****************************************************************************
29
30
# This file takes in a service file and splits it into two topics and a header file with useful
31
# includes and type definitions to match standard services.
32
33
# Arguments are:
34
# 1. Input service file path
35
# 2. Output Request message file path
36
# 3. Output Response message file path
37
# 4. Package name
38
# 5. Service name
39
# 6. Output header file path
40
41
import
sys
42
43
data = sys.argv
44
45
46
rf = open(data[1],
"rb"
)
47
contents = rf.read();
48
lines = contents.split(
'---'
)
# split by statement
49
#split by brackets
50
rf.close()
51
52
53
oi = open(data[2],
"wb"
)
54
oi.write(
"marti_common_msgs/ServiceHeader srv_header\n"
)
55
oi.write(lines[0])
56
oi.close()
57
58
oi = open(data[3],
"wb"
)
59
oi.write(
"marti_common_msgs/ServiceHeader srv_header\n"
)
60
oi.write(lines[1])
61
oi.close()
62
63
# Write out a wrapper header so we can use and include it like it is a service
64
# Data 4 has the message name and 5 has the message name
65
data[5] = data[5].replace(
".srv"
,
""
)
66
67
oi = open(data[6],
"wb"
)
68
name = data[4] +
"_"
+ data[5]
69
oi.write(
"// This file is autogenerated, do not modify\n"
)
70
oi.write(
"#ifndef _"
+ name +
"_TOPIC_SERVICE_H_\n"
)
71
oi.write(
"#define _"
+ name +
"_TOPIC_SERVICE_H_\n"
)
72
73
oi.write(
"#include <"
+ data[4] +
"/"
+ data[5] +
"Response.h>\n"
)
74
oi.write(
"#include <"
+ data[4] +
"/"
+ data[5] +
"Request.h>\n\n"
)
75
76
oi.write(
"namespace "
+ data[4] +
"{\n"
)
77
oi.write(
"class "
+ data[5] +
"{ public: \n"
)
78
oi.write(
"typedef "
+ data[5] +
"Response Response;\n"
)
79
oi.write(
"typedef "
+ data[5] +
"Request Request;\n"
)
80
oi.write(
" Request request; Response response;\n"
)
81
oi.write(
"};\n}\n"
)
82
83
oi.write(
"#endif"
)
swri_roscpp
Author(s):
autogenerated on Tue Apr 6 2021 02:50:35