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 af8ed03 commit 57f7c6d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion simpledbus/include/simpledbus/base/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Message {
static Message create_error(const Message& msg, const std::string& error_name, const std::string& error_message);
static Message create_signal(const std::string& path, const std::string& interface, const std::string& signal);

private:
private:
static std::atomic_int32_t _creation_counter;

int _indent = 0;
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
29 changes: 25 additions & 4 deletions simpledbus/src/base/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,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 57f7c6d

Please sign in to comment.