Skip to content

Commit 8dce5d2

Browse files
committed
WIP pybind: fix trans msg no attr info
1 parent e739545 commit 8dce5d2

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

python/example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def init(self):
1515

1616
# 接收 pymyframe.Msg
1717
def proc(self, msg):
18-
print(f"actor get msg: {msg.getData()}")
18+
print(f"{msg.getDst()} get msg from {msg.getSrc()}: {msg.getData()}")
1919

2020
# 初始化
2121
app = myframe.App()
@@ -52,7 +52,7 @@ def proc(self, msg):
5252
while True:
5353
time.sleep(1)
5454

55-
msg_text = "hello, world"
55+
msg_text = "hello,world"
5656
print(f"mainthread send msg: {msg_text}")
5757

5858
msg = myframe.Msg()

python/pyactor.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,31 @@ class PyActor : public myframe::Actor {
5252
}
5353

5454
void Proc(const std::shared_ptr<const myframe::Msg>& msg) {
55-
PyGILState_STATE gstate = PyGILState_Ensure();
5655
// 封装python Msg
57-
pymyframe::Msg* m = new pymyframe::Msg(GetActorName(), msg->GetData());
56+
pymyframe::Msg* m = new pymyframe::Msg();
57+
myframe::Msg::TransMode msg_tm = msg->GetTransMode();
58+
pymyframe::Msg::TransMode pymsg_tm;
59+
if (msg_tm == myframe::Msg::TransMode::kHybrid) {
60+
pymsg_tm = pymyframe::Msg::TransMode::HYBRID;
61+
} else if (msg_tm == myframe::Msg::TransMode::kDDS) {
62+
pymsg_tm = pymyframe::Msg::TransMode::DDS;
63+
} else {
64+
pymsg_tm = pymyframe::Msg::TransMode::INTRA;
65+
}
66+
m->setTransMode(pymsg_tm);
67+
m->setSrc(msg->GetSrc());
68+
m->setDst(msg->GetDst());
69+
m->setType(msg->GetType());
70+
m->setDesc(msg->GetDesc());
71+
m->setData(msg->GetData());
72+
73+
PyGILState_STATE gstate = PyGILState_Ensure();
74+
// 创建python msg对象
5875
PyObject* py_msg = SWIG_NewPointerObj(
5976
reinterpret_cast<void*>(m),
6077
SWIGTYPE_p_pymyframe__Msg,
6178
SWIG_POINTER_OWN); // 获得所有权
79+
6280
// 调用python proc
6381
PyObject* py_res = PyObject_CallMethod(
6482
pyactor_,

python/pymsg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Msg {
6969
void setDst(const std::string& dst) { msg_->SetDst(dst); }
7070
void setType(const std::string& type) { msg_->SetType(type); }
7171
void setDesc(const std::string& desc) { msg_->SetDesc(desc); }
72-
void setData(const std::string& data) {msg_->SetData(data); }
72+
void setData(const std::string& data) { msg_->SetData(data); }
7373

7474
private:
7575
std::shared_ptr<myframe::Msg> msg_;
File renamed without changes.

0 commit comments

Comments
 (0)