方法" GetManagedObjects"签名""在接口" org.freedesktop.DBus.ObjectManager"不存在

时间:2018-05-29 20:47:53

标签: c++ dbus bluez

我正在尝试使用libdbus-cpp从bluez对象管理器获取托管对象。在python中,我可以这样做:

import dbus
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.freedesktop.DBus.ObjectManager")
objects = manager.GetManagedObjects()

一般来说,我对dbus没有太多经验。要创建ManagedObject类,我模仿dbus-cpp源代码中/include/core/dbus/interfaces/object_manager.h下的那个。这是我到目前为止用C ++编写的代码:

#include <core/dbus/bus.h>
#include <core/dbus/object.h>
#include <core/dbus/service.h>
#include <core/dbus/types/variant.h>
#include <core/dbus/types/object_path.h>

namespace dbus = core::dbus;

class ObjectManager {
public:
  ObjectManager(const dbus::Bus::Ptr& bus) 
    : service(dbus::Service::use_service(bus, "org.bluez")) {}

  virtual ~ObjectManager() = default;

  using get_managed_objects_return_type = std::map<dbus::types::ObjectPath,
                                                   std::map<std::string,
                                                            std::map<std::string, dbus::types::Variant>>>;
  get_managed_objects_return_type get_managed_objects() {
    return service->root_object()->invoke_method_synchronously<GetManagedObjects, 
                                                               get_managed_objects_return_type>().value();
  }

private:
  struct GetManagedObjects {
    using Interface = ObjectManager;

    inline static std::string name() {
      return "GetManagedObjects";
    }

    static const bool call_synchronously = true;
    inline static const std::chrono::milliseconds default_timeout() {
      return std::chrono::seconds{1};
    }
  };

  dbus::Service::Ptr service;
};

namespace core {
namespace dbus {
namespace traits {
template<>
struct Service<ObjectManager> {
  inline static const std::string& interface_name() {
    static const std::string s {
      "org.freedesktop.DBus.ObjectManager"
    };
    return s;
  }
};
} // namespace traits
} // namespace dbus
} // namespace core

int main() {
    auto bus = std::make_shared<dbus::Bus>(dbus::WellKnownBus::system);
    auto manager= std::make_shared<ObjectManager>(bus);
    auto objects = manager->get_managed_objects();

    return EXIT_SUCCESS;
}

但是在运行它时我收到了这个错误:

terminate called after throwing an instance of 'std::runtime_error'
  what():  org.freedesktop.DBus.Error.UnknownMethod: Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist

我做错了什么?我错过了什么吗?

0 个答案:

没有答案