Skip to content

Add "share_private" argument to copy constructor #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion include/dbus-c++/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class DXXAPI Message

Message(Private *, bool incref = true);

Message(const Message &m);
Message(const Message &m, bool share_private = true);

~Message();

Expand Down Expand Up @@ -227,6 +227,8 @@ class DXXAPI ErrorMessage : public Message

ErrorMessage(const Message &, const char *name, const char *message);

ErrorMessage(const ErrorMessage &m, bool share_private = true);

const char *name() const;

bool name(const char *n);
Expand All @@ -245,6 +247,8 @@ class DXXAPI SignalMessage : public Message

SignalMessage(const char *path, const char *interface, const char *name);

SignalMessage(const SignalMessage &m, bool share_private = true);

const char *interface() const;

bool interface(const char *i);
Expand Down Expand Up @@ -273,6 +277,8 @@ class DXXAPI CallMessage : public Message

CallMessage(const char *dest, const char *path, const char *iface, const char *method);

CallMessage(const CallMessage &m, bool share_private = true);

const char *interface() const;

bool interface(const char *i);
Expand Down Expand Up @@ -301,6 +307,8 @@ class DXXAPI ReturnMessage : public Message

ReturnMessage(const CallMessage &callee);

ReturnMessage(const ReturnMessage &m, bool share_private = true);

const char *signature() const;
};

Expand Down
45 changes: 43 additions & 2 deletions src/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,26 +376,39 @@ Message::Message()
Message::Message(Message::Private *p, bool incref)
: _pvt(p)
{
if (_pvt->msg && incref) dbus_message_ref(_pvt->msg);
if (_pvt->msg && incref) {
debug_log("%s About to ref msg this %p msg %p\n", __FUNCTION__, this, _pvt->msg);
dbus_message_ref(_pvt->msg);
}
}

Message::Message(const Message &m)
Message::Message(const Message &m, bool share_private)
: _pvt(m._pvt)
{
if (!share_private) {
// Create a new Private wrapper to avoid sharing refcount
// instances across threads
_pvt = new Private;
_pvt->msg = m._pvt->msg;
}
debug_log("%s About to ref msg this %p msg %p\n", __FUNCTION__, this, _pvt->msg);
dbus_message_ref(_pvt->msg);
}

Message::~Message()
{
debug_log("%s About to unref msg this %p msg %p\n", __FUNCTION__, this, _pvt->msg);
dbus_message_unref(_pvt->msg);
}

Message &Message::operator = (const Message &m)
{
if (&m != this)
{
debug_log("%s About to unref msg this %p msg %p\n", __FUNCTION__, this, _pvt->msg);
dbus_message_unref(_pvt->msg);
_pvt = m._pvt;
debug_log("%s About to ref msg this %p msg %p\n", __FUNCTION__, this, _pvt->msg);
dbus_message_ref(_pvt->msg);
}
return *this;
Expand All @@ -404,6 +417,7 @@ Message &Message::operator = (const Message &m)
Message Message::copy()
{
Private *pvt = new Private(dbus_message_copy(_pvt->msg));
debug_log("%s Copied %p\n", __FUNCTION__, pvt->msg);
return Message(pvt);
}

Expand Down Expand Up @@ -493,11 +507,18 @@ MessageIter Message::reader() const
ErrorMessage::ErrorMessage()
{
_pvt->msg = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR);
debug_log("%s Created msg %p\n", __FUNCTION__, _pvt->msg);
}

ErrorMessage::ErrorMessage(const ErrorMessage &m, bool share_private)
:Message(m, share_private)
{
}

ErrorMessage::ErrorMessage(const Message &to_reply, const char *name, const char *message)
{
_pvt->msg = dbus_message_new_error(to_reply._pvt->msg, name, message);
debug_log("%s Created error msg %p\n", __FUNCTION__, _pvt->msg);
}

bool ErrorMessage::operator == (const ErrorMessage &m) const
Expand All @@ -522,11 +543,18 @@ SignalMessage::SignalMessage(const char *name)
{
_pvt->msg = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
member(name);
debug_log("%s Created signal msg %p\n", __FUNCTION__, _pvt->msg);
}

SignalMessage::SignalMessage(const SignalMessage &m, bool share_private)
:Message(m, share_private)
{
}

SignalMessage::SignalMessage(const char *path, const char *interface, const char *name)
{
_pvt->msg = dbus_message_new_signal(path, interface, name);
debug_log("%s Created signal msg %p\n", __FUNCTION__, _pvt->msg);
}

bool SignalMessage::operator == (const SignalMessage &m) const
Expand Down Expand Up @@ -577,11 +605,18 @@ bool SignalMessage::path(const char *p)
CallMessage::CallMessage()
{
_pvt->msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
debug_log("%s Created call msg %p\n", __FUNCTION__, _pvt->msg);
}

CallMessage::CallMessage(const CallMessage &m, bool share_private)
:Message(m, share_private)
{
}

CallMessage::CallMessage(const char *dest, const char *path, const char *iface, const char *method)
{
_pvt->msg = dbus_message_new_method_call(dest, path, iface, method);
debug_log("%s Created call msg %p\n", __FUNCTION__, _pvt->msg);
}

bool CallMessage::operator == (const CallMessage &m) const
Expand Down Expand Up @@ -637,6 +672,12 @@ const char *CallMessage::signature() const
ReturnMessage::ReturnMessage(const CallMessage &callee)
{
_pvt = new Private(dbus_message_new_method_return(callee._pvt->msg));
debug_log("%s Created return msg %p\n", __FUNCTION__, _pvt->msg);
}

ReturnMessage::ReturnMessage(const ReturnMessage &m, bool share_private)
:Message(m, share_private)
{
}

const char *ReturnMessage::signature() const
Expand Down