diff --git a/include/dbus-c++/message.h b/include/dbus-c++/message.h index 5ebccfd..8e4017e 100644 --- a/include/dbus-c++/message.h +++ b/include/dbus-c++/message.h @@ -167,6 +167,8 @@ public: ~Message(); + Message& operator = ( const Message& m ); + Message copy(); int type() const; diff --git a/include/dbus-c++/object.h b/include/dbus-c++/object.h index 79ad167..aa64b08 100644 --- a/include/dbus-c++/object.h +++ b/include/dbus-c++/object.h @@ -85,6 +85,17 @@ const std::string& Object::service() const /* */ +class Tag +{ +public: + + virtual ~Tag() + {} +}; + +/* +*/ + class ObjectAdaptor; typedef std::list ObjectAdaptorPList; @@ -113,28 +124,28 @@ protected: inline MessageIter& writer(); - inline void* tag(); + inline Tag* tag(); private: - Continuation( Connection& conn, const CallMessage& call, const void* tag ); + Continuation( Connection& conn, const CallMessage& call, const Tag* tag ); Connection _conn; CallMessage _call; MessageIter _writer; ReturnMessage _return; - const void* _tag; + const Tag* _tag; friend class ObjectAdaptor; }; - void return_later( const void* tag ); + void return_later( const Tag* tag ); void return_now( Continuation* ret ); void return_error( Continuation* ret, const Error error ); - Continuation* find_continuation( const void* tag ); + Continuation* find_continuation( const Tag* tag ); private: @@ -145,7 +156,7 @@ private: void register_obj(); void unregister_obj(); - typedef std::map ContinuationMap; + typedef std::map ContinuationMap; ContinuationMap _continuations; friend struct Private; @@ -156,9 +167,9 @@ const ObjectAdaptor* ObjectAdaptor::object() const return this; } -void* ObjectAdaptor::Continuation::tag() +Tag* ObjectAdaptor::Continuation::tag() { - return const_cast(_tag); + return const_cast(_tag); } MessageIter& ObjectAdaptor::Continuation::writer() diff --git a/include/dbus-c++/types.h b/include/dbus-c++/types.h index 19b3ab2..5d90f94 100644 --- a/include/dbus-c++/types.h +++ b/include/dbus-c++/types.h @@ -242,7 +242,6 @@ inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Str return iter; } - inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Path& val ) { iter.append_path(val.c_str()); @@ -393,6 +392,18 @@ inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::String& v return ++iter; } +inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Path& val ) +{ + val = iter.get_path(); + return ++iter; +} + +inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Signature& val ) +{ + val = iter.get_signature(); + return ++iter; +} + template inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector& val ) { @@ -408,8 +419,6 @@ inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector& ait >> elem; val.push_back(elem); - - ++ait; } return ++iter; } diff --git a/src/debug.cpp b/src/debug.cpp index fa56233..2d64c40 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -28,20 +28,24 @@ #include #include +static int debug_env = -1; + static void _debug_log_default(const char* format, ...) { #ifdef DEBUG - if(getenv("DBUSXX_VERBOSE")) + if(debug_env < 0) debug_env = getenv("DBUSXX_VERBOSE") ? 1 : 0; + + if(debug_env) { - va_list args; - va_start(args, format); + va_list args; + va_start(args, format); - fprintf(stderr, "dbus-c++: "); - vfprintf(stderr, format, args); - fprintf(stderr, "\n"); + fprintf(stderr, "dbus-c++: "); + vfprintf(stderr, format, args); + fprintf(stderr, "\n"); - va_end(args); + va_end(args); } #endif//DEBUG diff --git a/src/message.cpp b/src/message.cpp index 36ddeb6..1afee6b 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -303,7 +303,7 @@ void MessageIter::close_container( MessageIter& container ) void MessageIter::copy_data( MessageIter& to ) { - for(MessageIter from = *this; from.at_end(); ++from) + for(MessageIter& from = *this; !from.at_end(); ++from) { switch(from.type()) { @@ -320,6 +320,8 @@ void MessageIter::copy_data( MessageIter& to ) case DBUS_TYPE_OBJECT_PATH: case DBUS_TYPE_SIGNATURE: { + debug_log("copying basic type: %c", from.type()); + unsigned char value[8]; from.get_basic(from.type(), &value); to.append_basic(from.type(), &value); @@ -333,12 +335,14 @@ void MessageIter::copy_data( MessageIter& to ) MessageIter from_container = from.recurse(); char* sig = from_container.signature(); - MessageIter to_container(to.msg()); + debug_log("copying compound type: %c[%s]", from.type(), sig); + + MessageIter to_container (to.msg()); dbus_message_iter_open_container ( (DBusMessageIter*)&(to._iter), from.type(), - sig, + from.type() == DBUS_TYPE_VARIANT ? NULL : sig, (DBusMessageIter*)&(to_container._iter) ); @@ -376,6 +380,15 @@ Message::~Message() dbus_message_unref(_pvt->msg); } +Message& Message::operator = ( const Message& m ) +{ + if(&m != this) + { + _pvt = m._pvt; + } + return *this; +} + Message Message::copy() { Private* pvt = new Private(dbus_message_copy(_pvt->msg)); diff --git a/src/object.cpp b/src/object.cpp index 0cf3381..092e5d4 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -175,11 +175,6 @@ void ObjectAdaptor::_emit_signal( SignalMessage& sig ) conn().send(sig); } -struct WontReturnException -{ - const void* tag; -}; - bool ObjectAdaptor::handle_message( const Message& msg ) { switch( msg.type() ) @@ -205,9 +200,9 @@ bool ObjectAdaptor::handle_message( const Message& msg ) ErrorMessage em(cmsg, e.name(), e.message()); conn().send(em); } - catch(WontReturnException& wre) + catch(Tag* tag) { - _continuations[wre.tag] = new Continuation(conn(), cmsg, wre.tag); + _continuations[tag] = new Continuation(conn(), cmsg, tag); } return true; } @@ -223,11 +218,9 @@ bool ObjectAdaptor::handle_message( const Message& msg ) } } -void ObjectAdaptor::return_later( const void* tag ) +void ObjectAdaptor::return_later( const Tag* tag ) { - WontReturnException wre = { tag }; - - throw wre; + throw tag; } void ObjectAdaptor::return_now( Continuation* ret ) @@ -252,14 +245,14 @@ void ObjectAdaptor::return_error( Continuation* ret, const Error error ) _continuations.erase(di); } -ObjectAdaptor::Continuation* ObjectAdaptor::find_continuation( const void* tag ) +ObjectAdaptor::Continuation* ObjectAdaptor::find_continuation( const Tag* tag ) { ContinuationMap::iterator di = _continuations.find(tag); return di != _continuations.end() ? di->second : NULL; } -ObjectAdaptor::Continuation::Continuation( Connection& conn, const CallMessage& call, const void* tag ) +ObjectAdaptor::Continuation::Continuation( Connection& conn, const CallMessage& call, const Tag* tag ) : _conn(conn), _call(call), _return(_call), _tag(tag) { _writer = _return.writer(); //todo: verify diff --git a/src/property.cpp b/src/property.cpp index 5e70a82..95d62c2 100644 --- a/src/property.cpp +++ b/src/property.cpp @@ -21,7 +21,7 @@ * */ - +#include #include #include @@ -46,6 +46,8 @@ Message PropertiesAdaptor::Get( const CallMessage& call ) ri >> iface_name >> property_name; + debug_log("requesting property %s on interface %s\n", property_name.c_str(), iface_name.c_str()); + InterfaceAdaptor* interface = (InterfaceAdaptor*) find_interface(iface_name); if(!interface) @@ -63,7 +65,6 @@ Message PropertiesAdaptor::Get( const CallMessage& call ) MessageIter wi = reply.writer(); wi << *value; - return reply; } diff --git a/src/types.cpp b/src/types.cpp index 3a8a742..4ecc2ed 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -89,7 +89,13 @@ MessageIter& operator >> ( MessageIter& iter, Variant& val ) { //TODO: check if iter really points to a variant - val = Variant(iter); + val.clear(); + + MessageIter vit = iter.recurse(); + MessageIter mit = val.writer(); + + vit.copy_data(mit); + return ++iter; } diff --git a/tools/xml2cpp.cpp b/tools/xml2cpp.cpp index 16e444f..a7da444 100644 --- a/tools/xml2cpp.cpp +++ b/tools/xml2cpp.cpp @@ -599,7 +599,7 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) } file << endl - << "protected:" << endl + << "public:" << endl << endl << tab << "/* signals emitted by this interface" << endl << tab << " */" << endl;