[Dbus-cxx-devel] About string arrays
Status: Beta
Brought to you by:
rvinyard
From: Michał 'K. R. <mi...@rz...> - 2010-04-09 10:22:40
|
Hi folks, String arrays work on the server side, the only needed addition is namespace DBus { template<> std::string signature<std::vector<std::string> >() { std::string t; return DBUS_TYPE_ARRAY_AS_STRING + signature(t); } } After that I am able to register a method returning std::vector<std::string> > and d-feet dbus debugger is able to call it and get the correct result. What I can't get to work is the client side. Without additional specializations, calling a method proxy ::DBus::MethodProxy<std::vector<std::string> >::pointer f; // ... return (*f)(); causes the compiler to complain: /usr/include/dbus-cxx-0.7/dbus-cxx/types.h:61: error: cannot convert ‘std::string’ to ‘DBus::Type’ in return but after adding the following (weird) specialization: namespace DBus { template<> inline Type type<std::string>() { return TYPE_STRING; } } It compiles, but cannot call the method because of an exception: MessageIterator: Extracting non fixed array into std::vector I am new to DBus, but from this message I can guess that array of strings is quite different than array of primitives, which in glib bindings is reflected by G_TYPE_STRV as opposed to G_FOO_ARRAY. If I guess right, this requires the implementation to use dbus_message_iter_open_container() instead of dbus_message_iter_get_fixed_array() to read data. This seems to be implemented in MessageAppendIterator template <typename T> void append( const std::vector<T>& v ) { this->open_container( CONTAINER_ARRAY, DBus::signature<T>().c_str() ); for ( size_t i=0; i < v.size(); i++ ) *m_subiter << v[i]; this->close_container(); } but not in MessageIterator, as the default template <typename T> std::vector<T> get_array() uses forementioned dbus_message_iter_get_fixed_array(). Is specializing MessageIterator::get_array method a correct way to implement reading string arrays from the message? cheers -- Michał 'Khorne' Rzechonek http://rzechonek.net |