Apollo 10.0
自动驾驶开放平台
py_parameter.h
浏览该文件的文档.
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
32namespace apollo {
33namespace cyber {
34
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_
Parameter Client is used to set/get/list parameter(s) by sending a request to ParameterServer
bool ListParameters(std::vector< Parameter > *parameters)
Get all the Parameter objects
bool SetParameter(const Parameter &parameter)
Set the Parameter object
bool GetParameter(const std::string &param_name, Parameter *parameter)
Get the Parameter object
Parameter Service is a very important function of auto-driving.
void ListParameters(std::vector< Parameter > *parameters)
get all the parameters
bool GetParameter(const std::string &parameter_name, Parameter *parameter)
Get the Parameter object
void SetParameter(const Parameter &parmeter)
Set the Parameter object
A Parameter holds an apollo::cyber::proto::Param, It's more human-readable, you can use basic-value t...
Definition parameter.h:42
std::string TypeName() const
Get Paramter's type name, i.e.
Definition parameter.h:344
double AsDouble() const
et Paramter as a double value
Definition parameter.h:354
std::string DebugString() const
show debug string
Definition parameter.cc:116
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
std::string Descriptor() const
Get Paramter's descriptor, only work on protobuf types
Definition parameter.h:346
const std::string AsString() const
Get Paramter as a string value
Definition parameter.h:356
const std::string Name() const
Get the Parameter name
Definition parameter.h:348
bool list_parameters(std::vector< Parameter > *parameters)
PyParameterClient(const std::shared_ptr< Node > &node, const std::string &service_node_name)
bool set_parameter(const Parameter &parameter)
bool get_parameter(const std::string &param_name, Parameter *parameter)
bool get_parameter(const std::string &param_name, Parameter *parameter)
void list_parameters(std::vector< Parameter > *parameters)
void set_parameter(const Parameter &parameter)
PyParameterServer(const std::shared_ptr< Node > &node)
PyParameter(const std::string &name, const double double_value)
PyParameter(const std::string &name, const std::string &string_value)
PyParameter(const std::string &name, const std::string &msg_str, const std::string &full_name, const std::string &proto_desc)
PyParameter(const std::string &name, const int64_t int_value)
PyParameter(Parameter *param)
class register implement
Definition arena_queue.h:37