Apollo 10.0
自动驾驶开放平台
py_timer.cc 文件参考
#include "cyber/python/internal/py_timer.h"
#include <set>
#include <string>
#include <Python.h>
py_timer.cc 的引用(Include)关系图:

浏览源代码.

宏定义

#define PyInt_AsLong   PyLong_AsLong
 

函数

template<typename T >
PyObjectToPtr (PyObject *pyobj, const std::string &type_ptr)
 
PyObject * cyber_new_PyTimer (PyObject *self, PyObject *args)
 
PyObject * cyber_new_PyTimer_noparam (PyObject *self, PyObject *args)
 
PyObject * cyber_delete_PyTimer (PyObject *self, PyObject *args)
 
PyObject * cyber_PyTimer_start (PyObject *self, PyObject *args)
 
PyObject * cyber_PyTimer_stop (PyObject *self, PyObject *args)
 
PyObject * cyber_PyTimer_set_option (PyObject *self, PyObject *args)
 
PyMODINIT_FUNC PyInit__cyber_timer_wrapper (void)
 Init function of this module
 

宏定义说明

◆ PyInt_AsLong

#define PyInt_AsLong   PyLong_AsLong

在文件 py_timer.cc26 行定义.

函数说明

◆ cyber_delete_PyTimer()

PyObject * cyber_delete_PyTimer ( PyObject *  self,
PyObject *  args 
)

在文件 py_timer.cc59 行定义.

59 {
60 PyObject* pyobj_timer = nullptr;
61 if (!PyArg_ParseTuple(args, const_cast<char*>("O:cyber_delete_PyTimer"),
62 &pyobj_timer)) {
63 Py_INCREF(Py_None);
64 return Py_None;
65 }
66
67 auto* pytimer = reinterpret_cast<PyTimer*>(
68 PyCapsule_GetPointer(pyobj_timer, "apollo_cybertron_pytimer"));
69 if (nullptr == pytimer) {
70 AERROR << "cyber_delete_PyTimer:timer ptr is null!";
71 Py_INCREF(Py_None);
72 return Py_None;
73 }
74 delete pytimer;
75 Py_INCREF(Py_None);
76 return Py_None;
77}
#define AERROR
Definition log.h:44

◆ cyber_new_PyTimer()

PyObject * cyber_new_PyTimer ( PyObject *  self,
PyObject *  args 
)

在文件 py_timer.cc37 行定义.

37 {
38 uint32_t period = 0;
39 PyObject* pyobj_regist_fun = nullptr;
40 unsigned int oneshot = 0;
41 if (!PyArg_ParseTuple(args, const_cast<char*>("kOI:cyber_new_PyTimer"),
42 &period, &pyobj_regist_fun, &oneshot)) {
43 AERROR << "cyber_new_PyTimer parsetuple failed!";
44 Py_INCREF(Py_None);
45 return Py_None;
46 }
47
48 void (*callback_fun)() = (void (*)())0;
49 callback_fun = (void (*)())PyInt_AsLong(pyobj_regist_fun);
50 PyTimer* pytimer = new PyTimer(period, callback_fun, oneshot != 0);
51 return PyCapsule_New(pytimer, "apollo_cybertron_pytimer", nullptr);
52}
#define PyInt_AsLong
Definition py_timer.cc:26

◆ cyber_new_PyTimer_noparam()

PyObject * cyber_new_PyTimer_noparam ( PyObject *  self,
PyObject *  args 
)

在文件 py_timer.cc54 行定义.

54 {
55 PyTimer* pytimer = new PyTimer();
56 return PyCapsule_New(pytimer, "apollo_cybertron_pytimer", nullptr);
57}

◆ cyber_PyTimer_set_option()

PyObject * cyber_PyTimer_set_option ( PyObject *  self,
PyObject *  args 
)

在文件 py_timer.cc119 行定义.

119 {
120 PyObject* pyobj_timer = nullptr;
121 uint32_t period = 0;
122 PyObject* pyobj_regist_fun = nullptr;
123 unsigned int oneshot = 0;
124
125 void (*callback_fun)() = (void (*)())0;
126
127 if (!PyArg_ParseTuple(args,
128 const_cast<char*>("OkOI:cyber_PyTimer_set_option"),
129 &pyobj_timer, &period, &pyobj_regist_fun, &oneshot)) {
130 Py_INCREF(Py_None);
131 return Py_None;
132 }
133
134 PyTimer* pytimer =
135 PyObjectToPtr<PyTimer*>(pyobj_timer, "apollo_cybertron_pytimer");
136 callback_fun = (void (*)())PyInt_AsLong(pyobj_regist_fun);
137 if (nullptr == pytimer) {
138 AERROR << "cyber_PyTimer_set_option ptr is null!";
139 Py_INCREF(Py_None);
140 return Py_None;
141 }
142
143 pytimer->set_option(period, callback_fun, oneshot != 0);
144
145 Py_INCREF(Py_None);
146 return Py_None;
147}
void set_option(uint32_t period, void(*func)(), bool oneshot)
Definition py_timer.h:44

◆ cyber_PyTimer_start()

PyObject * cyber_PyTimer_start ( PyObject *  self,
PyObject *  args 
)

在文件 py_timer.cc79 行定义.

79 {
80 PyObject* pyobj_timer = nullptr;
81 if (!PyArg_ParseTuple(args, const_cast<char*>("O:cyber_delete_PyTimer"),
82 &pyobj_timer)) {
83 Py_INCREF(Py_None);
84 return Py_None;
85 }
86
87 auto* pytimer = reinterpret_cast<PyTimer*>(
88 PyCapsule_GetPointer(pyobj_timer, "apollo_cybertron_pytimer"));
89 if (nullptr == pytimer) {
90 AERROR << "cyber_delete_PyTimer:timer ptr is null!";
91 Py_INCREF(Py_None);
92 return Py_None;
93 }
94 pytimer->start();
95 Py_INCREF(Py_None);
96 return Py_None;
97}

◆ cyber_PyTimer_stop()

PyObject * cyber_PyTimer_stop ( PyObject *  self,
PyObject *  args 
)

在文件 py_timer.cc99 行定义.

99 {
100 PyObject* pyobj_timer = nullptr;
101 if (!PyArg_ParseTuple(args, const_cast<char*>("O:cyber_delete_PyTimer"),
102 &pyobj_timer)) {
103 Py_INCREF(Py_None);
104 return Py_None;
105 }
106
107 auto* pytimer = reinterpret_cast<PyTimer*>(
108 PyCapsule_GetPointer(pyobj_timer, "apollo_cybertron_pytimer"));
109 if (nullptr == pytimer) {
110 AERROR << "cyber_delete_PyTimer:timer ptr is null!";
111 Py_INCREF(Py_None);
112 return Py_None;
113 }
114 pytimer->stop();
115 Py_INCREF(Py_None);
116 return Py_None;
117}

◆ PyInit__cyber_timer_wrapper()

PyMODINIT_FUNC PyInit__cyber_timer_wrapper ( void  )

Init function of this module

在文件 py_timer.cc161 行定义.

161 {
162 static struct PyModuleDef module_def = {
163 PyModuleDef_HEAD_INIT,
164 "_cyber_timer_wrapper", // Module name.
165 "CyberTimer module", // Module doc.
166 -1, // Module size.
167 _cyber_timer_methods, // Module methods.
168 nullptr,
169 nullptr,
170 nullptr,
171 nullptr,
172 };
173
174 return PyModule_Create(&module_def);
175}

◆ PyObjectToPtr()

template<typename T >
T PyObjectToPtr ( PyObject *  pyobj,
const std::string &  type_ptr 
)

在文件 py_timer.cc29 行定义.

29 {
30 T obj_ptr = (T)PyCapsule_GetPointer(pyobj, type_ptr.c_str());
31 if (obj_ptr == nullptr) {
32 AERROR << "PyObjectToPtr failed,type->" << type_ptr << "pyobj: " << pyobj;
33 }
34 return obj_ptr;
35}