为了在 dbus 上设置 Connman 信号回调,我非常关注https://www.freedesktop.org/software/gstreamer-sdk/data/docs/latest/gio/GDBusProxy.html上的示例,但是在我的回调函数:
g_signal_connect(
this->manager_proxy,
"property-changed",
G_CALLBACK(on_manager_properties_changed),
this); //Pass in pointer to self so static function can operate on object.
g_signal_connect(
this->manager_proxy,
"technology-added",
G_CALLBACK(on_manager_tech_added),
this); //Pass in pointer to self so static function can operate on object.
g_signal_connect(
this->manager_proxy,
"technology-removed",
G_CALLBACK(on_manager_tech_removed),
this); //Pass in pointer to self so static function can operate on object
void
CM_InterfaceController::on_manager_properties_changed (
GDBusProxy *proxy,
GVariant *changed_properties,
const gchar* const *invalidated_properties,
gpointer user_data)
{
if(!user_data){CM_ERR("NO THIS * on_manager_properties_changed");return;}
CM_InterfaceController * ths = static_cast<CM_InterfaceController *>(user_data);
std::cout<<"on_manager_properties_changed"<<std::endl;
if(changed_properties){
std::cout<<"children: "<<g_variant_n_children(changed_properties)<<std::endl;
}
}
我被告知 GVariant * 对象包含的孩子的数量是完全错误的。例如,我的反馈:
Calling Extraction
Service List Size: 1
Identified Ethernet Link:
Path: /net/connman/service/ethernet_0800277d326e_cable
Type: ethernet
Sate: ready
Favorite: 0
Auto Connect: 0
Name: Wired
Net Mode: manual
Iface: eth0
Mac: 08:00:27:7D:32:6E
IP Address: 10.0.2.15
Net Mask: 255.255.255.0
on_manager_properties_changed
children: 139764141513856
on_manager_properties_changed
children: 145
on_manager_properties_changed 孩子:139764141513856 on_manager_properties_changed 孩子:145
这两个值都超出了范围,一个比另一个更重要。更重要的是,如果我尝试从 GVariant 对象中解析出值,即使只是尝试调用 g_variant_get_type_string,我最终也会出现段错误。为什么我的回调返回一个垃圾数据指针?似乎如果它什么都没有,它至少应该返回一个空指针。
编辑:源代码 https://drive.google.com/file/d/1E0Kg9JKW54gghUHbVyBJ0ysBIdqBlpVA/view?usp=sharing
还有一些 dbus-monitor --system 输出:
signal time=1549641357.679460 sender=:1.3 -> destination=(null destination) serial=488 path=/net/connman/service/ethernet_0800277d326e_cable; interface=net.connman.Service; member=PropertyChanged
string "State"
variant string "ready"
signal time=1549641357.680844 sender=:1.3 -> destination=(null destination) serial=489 path=/net/connman/service/ethernet_0800277d326e_cable; interface=net.connman.Service; member=PropertyChanged
string "Nameservers"
variant array [
string "10.0.2.3"
]
signal time=1549641357.681186 sender=:1.3 -> destination=(null destination) serial=490 path=/net/connman/service/ethernet_0800277d326e_cable; interface=net.connman.Service; member=PropertyChanged
string "Domains"
variant array [
]
signal time=1549641357.681601 sender=:1.3 -> destination=(null destination) serial=491 path=/net/connman/service/ethernet_0800277d326e_cable; interface=net.connman.Service; member=PropertyChanged
string "Proxy"
variant array [
dict entry(
string "Method"
variant string "direct"
)
]
signal time=1549641357.681780 sender=:1.3 -> destination=(null destination) serial=492 path=/net/connman/technology/ethernet; interface=net.connman.Technology; member=PropertyChanged
string "Connected"
variant boolean true
signal time=1549641357.682210 sender=:1.3 -> destination=(null destination) serial=493 path=/; interface=net.connman.Manager; member=PropertyChanged
string "State"
variant string "ready"
signal time=1549641357.696004 sender=:1.3 -> destination=(null destination) serial=494 path=/net/connman/service/ethernet_0800277d326e_cable; interface=net.connman.Service; member=PropertyChanged
string "IPv4"
variant array [
dict entry(
string "Method"
variant string "dhcp"
)
]
signal time=1549641357.696227 sender=:1.3 -> destination=(null destination) serial=495 path=/net/connman/service/ethernet_0800277d326e_cable; interface=net.connman.Service; member=PropertyChanged
string "IPv4"
variant array [
dict entry(
string "Method"
variant string "dhcp"
)
dict entry(
string "Address"
variant string "10.0.2.15"
)
dict entry(
string "Netmask"
variant string "255.255.255.0"
)
]
signal time=1549641357.696454 sender=:1.3 -> destination=(null destination) serial=496 path=/net/connman/service/ethernet_0800277d326e_cable; interface=net.connman.Service; member=PropertyChanged
string "IPv4"
variant array [
dict entry(
string "Method"
variant string "dhcp"
)
dict entry(
string "Address"
variant string "10.0.2.15"
)
dict entry(
string "Netmask"
variant string "255.255.255.0"
)
dict entry(
string "Gateway"
variant string "10.0.2.2"
)
]