#include #include #include #include #include #include #include #include "pipe_transfer.h" #include #include bool block_iteration = false; class MyProxy : public Gio::DBus::Proxy { public: std::vector< guint32 > RemoteFunction(const std::vector< guint32 >& coeff_a, const std::vector< guint32 >& coeff_b) { Glib::RefPtr connection = get_connection(); connection->reference(); Glib::RefPtr cancellable; Glib::RefPtr fd_list = Gio::UnixFDList::create(); int fd[2]; /*int r =*/ pipe(fd); fd_list->append(fd[0]); fd_list->append(fd[1]); Glib::RefPtr out_fd_list = Gio::UnixFDList::create(); int timeout_msec = -1; Gio::DBus::CallFlags flags = Gio::DBus::CALL_FLAGS_NONE; Glib::VariantType reply_type; std::vector query_vector; const Glib::VariantContainerBase& query = Glib::VariantContainerBase::create_tuple(query_vector); Glib::VariantContainerBase response; GMainContext *context = g_main_context_new(); GMainLoop *loop = g_main_loop_new(context, FALSE); g_main_context_push_thread_default(context); connection->call( get_object_path(), "org.glibmm.DBusExample.Machine", "RemoteFunction", query, sigc::bind(sigc::bind(sigc::bind(sigc::mem_fun(this, &MyProxy::AsyncCallReady), loop), &response), out_fd_list), cancellable, fd_list, "org.glibmm.DBusExample", timeout_msec, flags, reply_type); write_vector_to_pipe(fd[1], coeff_a); write_vector_to_pipe(fd[1], coeff_b); g_main_loop_run(loop); g_main_context_pop_thread_default(context); g_main_context_unref(context); g_main_loop_unref(loop); std::vector< guint32 > ov_low_fill; read_vector_from_pipe(fd[0], ov_low_fill); close(fd[0]); close(fd[1]); return ov_low_fill; } MyProxy( Gio::DBus::BusType bus_type, const Glib::ustring& name, const Glib::ustring& object_path, const Glib::ustring& interface_name, Gio::DBus::ProxyFlags flags) : Gio::DBus::Proxy(bus_type, name, object_path, interface_name, Glib::RefPtr(), flags) {} private: void AsyncCallReady(Glib::RefPtr& async_result, Glib::RefPtr& async_fd_list, Glib::VariantContainerBase *result, GMainLoop *loop)//Glib::RefPtr mainloop) { auto connection = get_connection(); connection->reference(); *result = connection->call_finish(async_result, async_fd_list); g_main_loop_quit(loop); }; }; int main(int, char**) { Gio::init(); // Get the bus connection. Glib::RefPtr connection = Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SESSION); // Create a proxy object MyProxy proxy(Gio::DBus::BUS_TYPE_SESSION, "org.glibmm.DBusExample", "/org/glibmm/DBus/TestObject", "org.glibmm.DBusExample.Machine", Gio::DBus::ProxyFlags()); for (int i = 0;; ++i) { std::vector vector_a(1000,0); std::vector vector_b(1000,1); std::vector result = proxy.RemoteFunction(vector_a, vector_b); std::cerr << result.size() << " " // size() should be the sum of vector_a.size() and vector_b.size() << result[0] << " " // should be 0 << result[999] << " " // should be 0 << result[1000] << " " // should be 1 << result[1999] << " " // should be 1 << std::endl; } return 0; }