Skip to content

Commit

Permalink
move more initialization into Message c'tor
Browse files Browse the repository at this point in the history
Signed-off-by: Heiko Hund <[email protected]>
  • Loading branch information
d12fk committed May 16, 2022
1 parent 01120f1 commit 2391617
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
32 changes: 19 additions & 13 deletions src/dbus_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ void DBus::Message::Parameters::add(const DBus::Type::Any& value)
//
// Message
//
DBus::Message::Message(const Identifier& id, const Parameters& params)
: m_Parameters(params)
{
m_Header.path = id.path;
m_Header.interface = id.interface;
m_Header.member = id.member;
}

DBus::Message::Message(const Header& header, OctetBuffer& body)
: m_Header(header)
{
Expand Down Expand Up @@ -399,9 +407,10 @@ DBus::Message::MethodCall::MethodCall(const Message::Header& header,

DBus::Message::MethodCall::MethodCall(
const BusName& destination,
const Identifier& name,
const Identifier& id,
const Parameters& params,
uint32_t flags)
: Message(id, params)
{

if (flags & Message::Flag::AllowInteractiveAuthorization) {
Expand All @@ -415,10 +424,6 @@ DBus::Message::MethodCall::MethodCall(
m_Header.flags = flags;
m_Header.type = Message::Type::MethodCall;
m_Header.destination = destination;
m_Header.path = name.path;
m_Header.interface = name.interface;
m_Header.member = name.member;
m_Parameters = params;
}


Expand All @@ -427,13 +432,14 @@ DBus::Message::MethodCall::MethodCall(
// Message::MethodReturn
//
DBus::Message::MethodReturn::MethodReturn(
const BusName& destination,
uint32_t replySerial)
const BusName& destination, uint32_t replySerial,
const Message::Parameters& params)
{
m_Header.flags = Flag::NoReplyExpected;
m_Header.type = Message::Type::MethodReturn;
m_Header.destination = destination;
m_Header.replySerial = replySerial;
m_Parameters = params;
}

DBus::Message::MethodReturn::MethodReturn(const Message::Header& header,
Expand Down Expand Up @@ -487,19 +493,19 @@ std::string DBus::Message::Error::getMessage() const
// Message::Signal
//
DBus::Message::Signal::Signal(
const Message::Identifier& name)
const Message::Identifier& id,
const Message::Parameters& params)
: Message(id, params)
{
m_Header.flags = Flag::NoReplyExpected;
m_Header.type = Message::Type::Signal;
m_Header.path = name.path;
m_Header.interface = name.interface;
m_Header.member = name.member;
}

DBus::Message::Signal::Signal(
const BusName& destination,
const Message::Identifier& name)
: Signal(name)
const Message::Identifier& id,
const Message::Parameters& params)
: Signal(id, params)
{
m_Header.destination = destination;
}
Expand Down
14 changes: 10 additions & 4 deletions src/dbus_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class Message {
};

Message() = default;
Message(const Message::Identifier& id,
const Message::Parameters& params = {});
Message(const Header& header, OctetBuffer& body);

explicit operator bool() const { return m_Header.type != Type::Invalid; }
Expand Down Expand Up @@ -271,7 +273,7 @@ class Message::MethodCall : public Message {
MethodCall() = default;
// This is for outgoing method calls
MethodCall(
const BusName& destination, const Identifier& name,
const BusName& destination, const Identifier& id,
const Parameters& params = Parameters(), uint32_t flags = 0);
// This is for receiving method calls
MethodCall(const Header& header, OctetBuffer& body);
Expand All @@ -285,7 +287,8 @@ class Message::MethodReturn : public Message {
public:
MethodReturn() = default;
// This is for sending outgoing replies
MethodReturn(const BusName& destination, uint32_t replySerial);
MethodReturn(const BusName& destination, uint32_t replySerial,
const Parameters& params = {});
// This is for receiving method returns
MethodReturn(const Header& header, OctetBuffer& body);
};
Expand All @@ -307,9 +310,12 @@ class Message::Signal : public Message {
public:
Signal() = default;
// This is for outgoing broadcast signals
Signal(const Identifier& name);
Signal(const Identifier& id,
const Parameters& params = {});
// This is for outgoing unicast signals
Signal(const BusName& destination, const Identifier& name);
Signal(const BusName& destination,
const Identifier& id,
const Parameters& params = {});
// This is for receiving signals
Signal(const Header& header, OctetBuffer& body);
};
Expand Down

0 comments on commit 2391617

Please sign in to comment.