GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/catkin/dg_control/dynamic_graph_manager/src/ros_interpreter.cpp Lines: 30 30 100.0 %
Date: 2020-04-15 11:50:02 Branches: 12 24 50.0 %

Line Branch Exec Source
1
/**
2
 * @file ros_interpreter.cpp
3
 * @author Maximilien Naveau (maximilien.naveau@gmail.com)
4
 * @license License BSD-3-Clause
5
 * @copyright Copyright (c) 2019, New York University and Max Planck Gesellschaft.
6
 * @date 2019-05-22
7
 */
8
9
#include <dynamic_graph_manager/ros_interpreter.hh>
10
11
namespace dynamic_graph
12
{
13
  static const int queueSize = 5;
14
15
24
  RosPythonInterpreter::RosPythonInterpreter (ros::NodeHandle& node_handle)
16
    : interpreter_ (),
17
      ros_node_handle_ (node_handle),
18
      run_python_command_srv_ (),
19
24
      run_python_file_srv_ ()
20
  {
21
24
  }
22
23
48
  RosPythonInterpreter::~RosPythonInterpreter()
24
  {
25
24
    run_python_command_srv_.shutdown();
26
24
    run_python_file_srv_.shutdown();
27
24
  }
28
29
20
  void RosPythonInterpreter::
30
  start_ros_service ()
31
  {
32
    run_python_command_callback_t runCommandCb =
33

40
      boost::bind (&RosPythonInterpreter::runCommandCallback, this, _1, _2);
34
20
    run_python_command_srv_ =
35

40
      ros_node_handle_.advertiseService ("run_python_command", runCommandCb);
36
37
    run_python_file_callback_t runPythonFileCb =
38

40
      boost::bind (&RosPythonInterpreter::runPythonFileCallback, this, _1, _2);
39
20
    run_python_file_srv_ =
40

40
      ros_node_handle_.advertiseService ("run_python_script", runPythonFileCb);
41
20
  }
42
43
  bool
44
3
  RosPythonInterpreter::runCommandCallback(
45
      dynamic_graph_manager::RunCommand::Request& req,
46
      dynamic_graph_manager::RunCommand::Response& res)
47
  {
48
3
    run_python_command(req.input,
49
                       res.result,
50
                       res.standard_output,
51
3
                       res.standard_error);
52
3
    return true;
53
  }
54
55
  bool
56
2
  RosPythonInterpreter::runPythonFileCallback (
57
      dynamic_graph_manager::RunPythonFile::Request& req,
58
      dynamic_graph_manager::RunPythonFile::Response& res)
59
  {
60
2
    run_python_file(req.input, res.standard_error);
61
    // FIX: It is just an echo, is there a way to have a feedback?
62
2
    res.result = "File parsed";
63
2
    return true;
64
  }
65
66
133
  void RosPythonInterpreter::run_python_command
67
  (const std::string & command,
68
   std::string &result,
69
   std::string &out,
70
   std::string &err)
71
  {
72
133
    interpreter_.python(command, result, out, err);
73
133
  }
74
75
2
  void RosPythonInterpreter::run_python_file(const std::string ifilename,
76
                                             std::string& standard_error){
77
2
      interpreter_.runPythonFile(ifilename, standard_error);
78
2
  }
79
80

9
} // end of namespace dynamicgraph.
81