C++ 코드 스 니펫을 사용하여 dbus 인터페이스에서 속성을 가져 오는 방법/코드 스 니펫을 알고 싶습니다.C++ gdbus - gdbus 라이브러리를 사용하여 인터페이스의 등록 정보를 가져 오는 방법은 무엇입니까?
다음과 같은 방법으로 오류가 발생했습니다.
접근 # 1 g_dbus_proxy_get_cached_property 를 사용하고 있지만 항상 반환 널
ifproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
flags,
NULL,
"org.freedesktop.NetworkManager",
"org/freedesktop/NetworkManager/Device/0",
"org.freedesktop.NetworkManager.Device",
NULL,
&error);
ret = g_dbus_proxy_get_cached_property(ifproxy, "State")
접근 # 2 g_dbus_proxy_call_sync한다 - 이 하나가 말한다 "org.freedesktop.networkmanager"내보낼 수 없습니다 (또는 존재하지 않을 수도 있음), "인터페이스"속성에 액세스 할 수 없습니다.
ifproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.NetworkManager",
"org/freedesktop/NetworkManager/Device/0",
"org.freedesktop.DBus.Properties",
NULL, NULL);
g_assert (ifproxy);
/* Get the object path of the Connection details */
ret = g_dbus_proxy_call_sync (ifproxy,
"Get",
g_variant_new ("(ss)",
"org/freedesktop/NetworkManager/Device/0",
"Interface"),
G_DBUS_CALL_FLAGS_NONE, -1,
NULL, &error);
if (!ret) {
g_dbus_error_strip_remote_error (error);
g_warning ("Failed to get property: %s\n",
error->message);
g_error_free (error);
return;
}
name = g_variant_get_string(ret, NULL);
//g_assert(ret != NULL);
g_variant_get (ret, "s", &name);
g_variant_unref (ret);
입력 해 주셔서 감사합니다. :). "Devices/0"의 prpoerty "Interface"에 대한 일부 출력을 얻고 있습니다. 출력은 인터페이스 이름입니다. - 1 \ xedI \ x89 \ xd1^H \ x89 \ xe2H \ x83 \ xe4 \ xf0PTI \ xc7 \ xc0. 나는이 문자열이 무엇을 나타내는 지 모르겠다. (그것은 나를위한 헥사 - 십진수로 보이지 않는다.) 이것을 ASCII 문자열로 변환하는 것을 도와주세요. –