Apollo  6.0
Open source self driving car software
py_parameter.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #ifndef CYBER_PYTHON_INTERNAL_PY_PARAMETER_H_
18 #define CYBER_PYTHON_INTERNAL_PY_PARAMETER_H_
19 
20 #include <unistd.h>
21 #include <functional>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "cyber/cyber.h"
27 #include "cyber/init.h"
31 
32 namespace apollo {
33 namespace cyber {
34 
35 class PyParameter {
36  public:
38  explicit PyParameter(Parameter* param) : parameter_(*param) {}
39 
40  PyParameter(const std::string& name, const int64_t int_value)
41  : parameter_(name, int_value) {}
42  PyParameter(const std::string& name, const double double_value)
43  : parameter_(name, double_value) {}
44  PyParameter(const std::string& name, const std::string& string_value)
45  : parameter_(name, string_value) {}
46  PyParameter(const std::string& name, const std::string& msg_str,
47  const std::string& full_name, const std::string& proto_desc)
48  : parameter_(name, msg_str, full_name, proto_desc) {}
49 
50  uint type() { return parameter_.Type(); }
51 
52  std::string type_name() { return parameter_.TypeName(); }
53 
54  std::string descriptor() { return parameter_.Descriptor(); }
55 
56  std::string name() { return parameter_.Name(); }
57 
58  int64_t as_int64() { return parameter_.AsInt64(); }
59  double as_double() { return parameter_.AsDouble(); }
60  std::string as_string() { return parameter_.AsString(); }
61  std::string debug_string() { return parameter_.DebugString(); }
62 
63  Parameter& get_param() { return parameter_; }
64 
65  private:
66  Parameter parameter_;
67 };
68 
70  public:
71  PyParameterClient(const std::shared_ptr<Node>& node,
72  const std::string& service_node_name)
73  : parameter_clt_(node, service_node_name) {}
74 
75  bool set_parameter(const Parameter& parameter) {
76  return parameter_clt_.SetParameter(parameter);
77  }
78  bool get_parameter(const std::string& param_name, Parameter* parameter) {
79  return parameter_clt_.GetParameter(param_name, parameter);
80  }
81  bool list_parameters(std::vector<Parameter>* parameters) {
82  return parameter_clt_.ListParameters(parameters);
83  }
84 
85  private:
86  ParameterClient parameter_clt_;
87 };
88 
90  public:
91  explicit PyParameterServer(const std::shared_ptr<Node>& node)
92  : parameter_srv_(node) {}
93 
94  void set_parameter(const Parameter& parameter) {
95  parameter_srv_.SetParameter(parameter);
96  }
97  bool get_parameter(const std::string& param_name, Parameter* parameter) {
98  return parameter_srv_.GetParameter(param_name, parameter);
99  }
100  void list_parameters(std::vector<Parameter>* parameters) {
101  parameter_srv_.ListParameters(parameters);
102  }
103 
104  private:
105  ParameterServer parameter_srv_;
106 };
107 
108 } // namespace cyber
109 } // namespace apollo
110 
111 #endif // CYBER_PYTHON_INTERNAL_PY_PARAMETER_H_
uint type()
Definition: py_parameter.h:50
Parameter Service is a very important function of auto-driving. If you want to set a key-value...
Definition: parameter_server.h:44
double as_double()
Definition: py_parameter.h:59
std::string debug_string()
Definition: py_parameter.h:61
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
PyParameter(const std::string &name, const int64_t int_value)
Definition: py_parameter.h:40
A Parameter holds an apollo::cyber::proto::Param, It&#39;s more human-readable, you can use basic-value t...
Definition: parameter.h:42
std::string as_string()
Definition: py_parameter.h:60
const std::string AsString() const
Get Paramter as a string value.
Definition: parameter.h:356
void list_parameters(std::vector< Parameter > *parameters)
Definition: py_parameter.h:100
PyParameterServer(const std::shared_ptr< Node > &node)
Definition: py_parameter.h:91
PyParameter(const std::string &name, const double double_value)
Definition: py_parameter.h:42
bool set_parameter(const Parameter &parameter)
Definition: py_parameter.h:75
int64_t as_int64()
Definition: py_parameter.h:58
std::string TypeName() const
Get Paramter&#39;s type name, i.e. INT,DOUBLE,STRING or protobuf message&#39;s fullname.
Definition: parameter.h:344
PyParameter(const std::string &name, const std::string &string_value)
Definition: py_parameter.h:44
bool list_parameters(std::vector< Parameter > *parameters)
Definition: py_parameter.h:81
Definition: py_parameter.h:35
bool get_parameter(const std::string &param_name, Parameter *parameter)
Definition: py_parameter.h:78
std::string type_name()
Definition: py_parameter.h:52
Parameter Client is used to set/get/list parameter(s) by sending a request to ParameterServer.
Definition: parameter_client.h:39
PyParameter(Parameter *param)
Definition: py_parameter.h:38
PyParameterClient(const std::shared_ptr< Node > &node, const std::string &service_node_name)
Definition: py_parameter.h:71
std::string DebugString() const
show debug string
bool get_parameter(const std::string &param_name, Parameter *parameter)
Definition: py_parameter.h:97
double AsDouble() const
et Paramter as a double value
Definition: parameter.h:354
PyParameter(const std::string &name, const std::string &msg_str, const std::string &full_name, const std::string &proto_desc)
Definition: py_parameter.h:46
Parameter & get_param()
Definition: py_parameter.h:63
Definition: py_parameter.h:69
std::string descriptor()
Definition: py_parameter.h:54
std::string Descriptor() const
Get Paramter&#39;s descriptor, only work on protobuf types.
Definition: parameter.h:346
Definition: py_parameter.h:89
void set_parameter(const Parameter &parameter)
Definition: py_parameter.h:94
PyParameter()
Definition: py_parameter.h:37
std::string name()
Definition: py_parameter.h:56
int64_t AsInt64() const
Get Paramter as an int64_t value.
Definition: parameter.h:352
ParamType Type() const
Get the cyber:parameter::ParamType of this object.
Definition: parameter.h:342
const std::string Name() const
Get the Parameter name.
Definition: parameter.h:348