howto use callback with cppyy in connect.

121 views
Skip to first unread message

AHMED BOUDARBALA

unread,
Nov 7, 2022, 6:21:22 AM11/7/22
to ns-3-users
ns.cppyy.cppdef("""
    using namespace ns3;
    static void CourseChange(std::string context, Ptr<const MobilityModel> mobility)
    {
        Vector pos = mobility->GetPosition();
        Vector vel = mobility->GetVelocity();
        std::cout << Simulator::Now() << ", model=" << mobility << ", POS: x=" << pos.x
                << ", y=" << pos.y << ", z=" << pos.z << "; VEL:" << vel.x << ", y=" << vel.y
                << ", z=" << vel.z << std::endl;
    }
""")

....
....
....
ns.core.Connect("/NodeList/*/$ns3::MobilityModel/CourseChange",ns.MakeCallback(ns.cppyy.gbl.CourseChange))

Gabriel Ferreira

unread,
Nov 8, 2022, 8:58:30 AM11/8/22
to ns-3-users
The following seems to works just fine
Untitled3.png

AHMED BOUDARBALA

unread,
Nov 8, 2022, 3:31:43 PM11/8/22
to ns-3-users
thank you
third.py

Shyam Parekh

unread,
Aug 28, 2025, 9:17:43 AMAug 28
to ns-3-users
I'm trying to use this approach for an LTE example with RRC state transition as the trace source. I'm continuing to get errors after trying many variants. If possible, please point me to a template/example that I could adapt for my purpose? Thanks!

Shyam Parekh

Shyam Parekh

unread,
Aug 28, 2025, 4:59:02 PMAug 28
to ns-3-users
I'm attaching a simple version of the code I'm trying using the approach suggested in this thread. This code is failing to connect the callback. Please take a look and see if you can see the error(s).

Thanks,

Shyam
rrcStateTransition_cppyy_example2.py

Shyam Parekh

unread,
Aug 29, 2025, 5:18:05 PMAug 29
to ns-3-users
Hi Gabriel. Could you please take a look? Your insights would be very valuable. Thanks!

Shyam

Shyam Parekh

unread,
Aug 30, 2025, 5:45:32 AM (14 days ago) Aug 30
to ns-3-users
It's working for me now. If you're interested in this, here is the working example.
rrcStateTransition_cppyy_example4.py
Reply all
Reply to author
Forward
0 new messages