GeezerVison is showing github.com — [feat] add python GDaemon · feiyunwill/CGraph@f53ad2d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: python/PyCGraph.cpp +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -98,6 +98,17 @@ PYBIND11_MODULE(PyCGraph, m) { | 98 | 98 | .def("removeGParam", &GAspect::__removeGParam_4py, | 99 | 99 | py::call_guard<py::gil_scoped_release>()); | 100 | 100 |
| | 101 | + py::class_<GDaemon, PywGDaemon, std::unique_ptr<GDaemon, py::nodelete> >(m, "GDaemon") | | 102 | + .def(py::init<>()) | | 103 | + .def("getInterval", &GDaemon::__getInterval_4py) | | 104 | + .def("createGParam", &GDaemon::__createGParam_4py, | | 105 | + py::call_guard<py::gil_scoped_release>(), | | 106 | + py::keep_alive<1, 2>()) | | 107 | + .def("getGParam", &GDaemon::__getGParam_4py) | | 108 | + .def("getGParamWithNoEmpty", &GDaemon::__getGParamWithNoEmpty_4py) | | 109 | + .def("removeGParam", &GDaemon::__removeGParam_4py, | | 110 | + py::call_guard<py::gil_scoped_release>()); | | 111 | + | 101 | 112 | py::class_<GEvent, PywGEvent, std::unique_ptr<GEvent, py::nodelete> >(m, "GEvent") | 102 | 113 | .def(py::init<>()) | 103 | 114 | .def("createGParam", &GEvent::__createGParam_4py, | @@ -120,6 +131,7 @@ PYBIND11_MODULE(PyCGraph, m) { | 120 | 131 | py::class_<GPassedParam, PywGPassedParam, std::unique_ptr<GPassedParam, py::nodelete> >(m, "GPassedParam") | 121 | 132 | .def(py::init<>()); | 122 | 133 | m.attr("GElementParam") = m.attr("GPassedParam"); | | 134 | + m.attr("GDaemonParam") = m.attr("GPassedParam"); | 123 | 135 |
| 124 | 136 | py::class_<PyGPipeline>(m, "GPipeline") | 125 | 137 | .def(py::init<>()) | @@ -143,6 +155,10 @@ PYBIND11_MODULE(PyCGraph, m) { | 143 | 155 | .def("destroy", &PyGPipeline::destroy) | 144 | 156 | .def("addGEvent", &PyGPipeline::__addGEvent_4py, | 145 | 157 | py::keep_alive<1, 2>()) | | 158 | + .def("addGDaemon", &PyGPipeline::__addGDaemon_4py, | | 159 | + py::arg("daemon"), | | 160 | + py::arg("ms"), | | 161 | + py::keep_alive<1, 2>()) | 146 | 162 | .def("asyncRun", &PyGPipeline::asyncRun, | 147 | 163 | py::arg("policy") = std::launch::async, | 148 | 164 | py::call_guard<py::gil_scoped_release>()) | |
Collapse file Copy file name to clipboard +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +""" | | 2 | +@Author: Chunel | | 3 | + | | 4 | +@File: MyMonitorDaemon | | 5 | +@Time: 2025/3/30 00:49 | | 6 | +@Desc: | | 7 | +""" | | 8 | + | | 9 | +from PyCGraph import GDaemon | | 10 | + | | 11 | +from MyParams.MyParam import MyParam | | 12 | + | | 13 | +class MyMonitorGDaemon(GDaemon): | | 14 | + def daemonTask(self, _): | | 15 | + param: MyParam = self.getGParamWithNoEmpty('param1') | | 16 | + print("----> [MyMonitorDaemon] monitor span is [{0}] ms, count is [{1}]".format( | | 17 | + self.getInterval(), param.count)) |
Collapse file Copy file name to clipboard +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +""" | | 2 | +@Author: Chunel | | 3 | + | | 4 | +@File: __init__.py | | 5 | +@Time: 2025/3/30 00:48 | | 6 | +@Desc: | | 7 | +""" |
Collapse file Copy file name to clipboardExpand all lines: python/tutorial/T00-HelloCGraph.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | @Desc: | 7 | 7 | """ | 8 | 8 |
| 9 | | -from PyCGraph import GNode, GPipeline | | 9 | +from PyCGraph import GPipeline | 10 | 10 |
| 11 | 11 | from MyGNode.HelloCGraphNode import HelloCGraphNode | 12 | 12 |
| |
Collapse file Copy file name to clipboard +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +""" | | 2 | +@Author: Chunel | | 3 | + | | 4 | +@File: T13-Deamon | | 5 | +@Time: 2025/3/30 00:46 | | 6 | +@Desc: | | 7 | +""" | | 8 | + | | 9 | +from PyCGraph import GPipeline | | 10 | + | | 11 | +from MyGNode.MyNode1 import MyNode1 | | 12 | +from MyGNode.MyWriteParamNode import MyWriteParamNode | | 13 | +from MyGDaemon.MyMonitorDaemon import MyMonitorGDaemon | | 14 | + | | 15 | + | | 16 | +def tutorial_simple(): | | 17 | + pipeline = GPipeline() | | 18 | + a, b = MyNode1(), MyWriteParamNode() | | 19 | + | | 20 | + pipeline.registerGElement(a, set(), "nodeA") | | 21 | + pipeline.registerGElement(b, {a}, "writeParamNodeB") | | 22 | + | | 23 | + pipeline.addGDaemon(MyMonitorGDaemon(), ms=3333) | | 24 | + | | 25 | + pipeline.process(20) | | 26 | + | | 27 | + | | 28 | +if __name__ == '__main__': | | 29 | + tutorial_simple() | | 30 | + |
Collapse file Copy file name to clipboardExpand all lines: python/wrapper/PyWrapperInclude.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 | #include "PywGParam.h" | 20 | 20 | #include "PywGAspect.h" | 21 | 21 | #include "PywGEvent.h" | | 22 | +#include "PywGDaemon.h" | 22 | 23 | #include "PywGPassedParam.h" | 23 | 24 |
| 24 | 25 | #endif //CGRAPH_PYWRAPPERINCLUDE_H |
Collapse file Copy file name to clipboardExpand all lines: python/wrapper/PywGAspect.h -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 |
| 14 | 14 | #include "CGraph.h" | 15 | 15 |
| 16 | | -namespace py = pybind11; | 17 | | - | 18 | 16 | class PywGAspect : public CGraph::GAspect { | 19 | 17 | public: | 20 | 18 | explicit PywGAspect() = default; | |
Collapse file Copy file name to clipboardExpand all lines: python/wrapper/PywGCondition.h -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 |
| 14 | 14 | #include "CGraph.h" | 15 | 15 |
| 16 | | -namespace py = pybind11; | 17 | | - | 18 | 16 | class PywGCondition : public CGraph::GCondition { | 19 | 17 | public: | 20 | 18 | explicit PywGCondition(const CGraph::GElementPtrArr& elements = CGraph::GElementPtrArr{}) { | |
Collapse file Copy file name to clipboard +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/*************************** | | 2 | +@Author: Chunel | | 3 | + | | 4 | +@File: PywGDaemon.h | | 5 | +@Time: 2025/3/30 00:13 | | 6 | +@Desc: | | 7 | +***************************/ | | 8 | + | | 9 | +#ifndef CGRAPH_PYWGDAEMON_H | | 10 | +#define CGRAPH_PYWGDAEMON_H | | 11 | + | | 12 | +#include "CGraph.h" | | 13 | + | | 14 | +class PywGDaemon : public CGraph::GDaemon { | | 15 | +public: | | 16 | + explicit PywGDaemon() = default; | | 17 | + ~PywGDaemon() override = default; | | 18 | + | | 19 | +protected: | | 20 | + CVoid daemonTask(CGraph::GDaemonParamPtr param) override { | | 21 | + PYBIND11_OVERLOAD_PURE(CVoid, GDaemon, daemonTask, param); | | 22 | + } | | 23 | + | | 24 | + CMSec modify(CGraph::GDaemonParamPtr param) override { | | 25 | + PYBIND11_OVERLOAD(CMSec, GDaemon, modify, param); | | 26 | + } | | 27 | +}; | | 28 | + | | 29 | +#endif //CGRAPH_PYWGDAEMON_H |
Collapse file Copy file name to clipboardExpand all lines: python/wrapper/PywGElement.h -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 |
| 14 | 14 | #include "CGraph.h" | 15 | 15 |
| 16 | | -namespace py = pybind11; | 17 | | - | 18 | 16 | class PywGElement : public CGraph::GElement { | 19 | 17 | protected: | 20 | 18 | CStatus run() override { | |
|