moved the D-Bus component into its own thread.

various API changes and fixes.


git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@7852 30a43799-04e7-0310-8b2b-ea0d24f86d0e
This commit is contained in:
pdurante 2006-10-01 13:37:47 +00:00
parent 42ea920aeb
commit 24637001ce
9 changed files with 77 additions and 38 deletions

View file

@ -167,6 +167,8 @@ public:
~Message();
Message& operator = ( const Message& m );
Message copy();
int type() const;

View file

@ -85,6 +85,17 @@ const std::string& Object::service() const
/*
*/
class Tag
{
public:
virtual ~Tag()
{}
};
/*
*/
class ObjectAdaptor;
typedef std::list<ObjectAdaptor*> 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<const void*, Continuation*> ContinuationMap;
typedef std::map<const Tag*, Continuation*> 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<void*>(_tag);
return const_cast<Tag*>(_tag);
}
MessageIter& ObjectAdaptor::Continuation::writer()

View file

@ -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<typename E>
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector<E>& val )
{
@ -408,8 +419,6 @@ inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector<E>&
ait >> elem;
val.push_back(elem);
++ait;
}
return ++iter;
}

View file

@ -28,20 +28,24 @@
#include <cstdio>
#include <stdlib.h>
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

View file

@ -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));

View file

@ -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

View file

@ -21,7 +21,7 @@
*
*/
#include <dbus-c++/debug.h>
#include <dbus-c++/property.h>
#include <dbus-c++/introspection.h>
@ -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;
}

View file

@ -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;
}

View file

@ -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;