Skip to content

Commit

Permalink
Rebased on main for new Message class
Browse files Browse the repository at this point in the history
  • Loading branch information
kdewald committed Oct 21, 2024
1 parent 51d9660 commit 7ab4858
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions simpledbus/include/simpledbus/base/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Message {
bool is_signal(const std::string& interface, const std::string& signal_name) const;
bool is_method_call(const std::string& interface, const std::string& method) const;

static Message from_retained(DBusMessage* msg);
static Message from_acquired(DBusMessage* msg);
static Message create_method_call(const std::string& bus_name, const std::string& path,
const std::string& interface, const std::string& method);
Expand Down
2 changes: 1 addition & 1 deletion simpledbus/src/base/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ bool Connection::unregister_object_path(const std::string& path) {

DBusHandlerResult Connection::static_message_handler(DBusConnection* connection, DBusMessage* message, void* user_data) {
Connection* conn = static_cast<Connection*>(user_data);
Message msg(message);
Message msg = Message::from_retained(message);
std::string path = msg.get_path();

std::lock_guard<std::recursive_mutex> lock(conn->_mutex);
Expand Down
39 changes: 35 additions & 4 deletions simpledbus/src/base/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,16 @@ Holder Message::_extract_generic(DBusMessageIter* iter) {
return Holder();
}

Message Message::from_retained(DBusMessage* msg) {
Message message;
if (msg) {
dbus_message_ref(msg);
message._msg = msg;
message._unique_id = _creation_counter++;
}
return message;
}

Message Message::from_acquired(DBusMessage* msg) {
Message message;
if (msg) {
Expand All @@ -583,9 +593,30 @@ Message Message::create_error(const Message& msg, const std::string& error_name,
return Message::from_acquired(msg_error);
}

Message Message::create_signal(std::string path, std::string interface, std::string signal) {
Message Message::create_signal(const std::string& path, const std::string& interface, const std::string& signal) {
DBusMessage* msg_signal = dbus_message_new_signal(path.c_str(), interface.c_str(), signal.c_str());
Message message(msg_signal);
dbus_message_unref(msg_signal);
return message;
return Message::from_acquired(msg_signal);
}

void Message::_invalidate() {
_unique_id = INVALID_UNIQUE_ID;
_msg = nullptr;
_iter_initialized = false;
_is_extracted = false;
_extracted = Holder();

#ifdef DBUS_MESSAGE_ITER_INIT_CLOSED
_iter = DBUS_MESSAGE_ITER_INIT_CLOSED;
#else
// For older versions of DBus, DBUS_MESSAGE_ITER_INIT_CLOSED is not defined.
_iter = DBusMessageIter();
#endif
_arguments.clear();
}

void Message::_safe_delete() {
if (is_valid()) {
dbus_message_unref(this->_msg);
_invalidate();
}
}

0 comments on commit 7ab4858

Please sign in to comment.