Skip to content

Commit

Permalink
capicxx-dbus-runtime 3.1.12.7
Browse files Browse the repository at this point in the history
  • Loading branch information
juergengehring committed May 22, 2018
1 parent 1b5f83a commit 77fd3ae
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 97 deletions.
10 changes: 10 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Changes
=======
v3.1.12.7
- Adapted 'capi-dbus-add-support-for-custom-marshalling.patch' to be compatible with dbus version 1.12.x

v3.1.12.6
- Removed concurrent timeout handling

v3.1.12.5
- Ensure availability listeners are unregistered properly (to free memory) when
proxies are being destroyed in callback invoking the availability listener(s)

v3.1.12.4
- support 'lock functors' in AttributeDispatcher(s)

Expand Down
5 changes: 0 additions & 5 deletions include/CommonAPI/DBus/DBusConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ class DBusConnection
DBusQueueDispatchSource* queueDispatchSource_;
DispatchSource* dispatchSource_;
WatchContext* watchContext_;
TimeoutContext* timeoutContext_;

COMMONAPI_EXPORT void addLibdbusSignalMatchRule(const std::string& objectPath,
const std::string& interfaceName,
Expand Down Expand Up @@ -296,10 +295,6 @@ class DBusConnection
COMMONAPI_EXPORT static void onRemoveWatch(::DBusWatch* libdbusWatch, void* data);
COMMONAPI_EXPORT static void onToggleWatch(::DBusWatch* libdbusWatch, void* data);

COMMONAPI_EXPORT static dbus_bool_t onAddTimeout(::DBusTimeout* dbus_timeout, void* data);
COMMONAPI_EXPORT static void onRemoveTimeout(::DBusTimeout* dbus_timeout, void* data);
COMMONAPI_EXPORT static void onToggleTimeout(::DBusTimeout* dbus_timeout, void* data);

COMMONAPI_EXPORT static void onWakeupMainContext(void* data);

COMMONAPI_EXPORT void enforceAsynchronousTimeouts();
Expand Down
70 changes: 0 additions & 70 deletions src/CommonAPI/DBus/DBusConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ DBusConnection::DBusConnection(DBusType_t busType,
dispatchThread_(NULL),
dispatchSource_(),
watchContext_(NULL),
timeoutContext_(NULL),
connection_(NULL),
busType_(busType),
dbusConnectionStatusEvent_(this),
Expand All @@ -184,7 +183,6 @@ DBusConnection::DBusConnection(::DBusConnection *_connection,
dispatchThread_(NULL),
dispatchSource_(),
watchContext_(NULL),
timeoutContext_(NULL),
connection_(_connection),
busType_(DBusType_t::WRAPPED),
dbusConnectionStatusEvent_(this),
Expand Down Expand Up @@ -214,14 +212,12 @@ DBusConnection::~DBusConnection() {
if (auto lockedContext = mainLoopContext_.lock()) {
if (isConnected()) {
dbus_connection_set_watch_functions(connection_, NULL, NULL, NULL, NULL, NULL);
dbus_connection_set_timeout_functions(connection_, NULL, NULL, NULL, NULL, NULL);
}

lockedContext->deregisterDispatchSource(queueDispatchSource_);
lockedContext->deregisterDispatchSource(dispatchSource_);
lockedContext->deregisterWatch(queueWatch_);
delete watchContext_;
delete timeoutContext_;
}
}

Expand All @@ -237,7 +233,6 @@ bool DBusConnection::attachMainLoopContext(std::weak_ptr<MainLoopContext> mainLo

dispatchSource_ = new DBusDispatchSource(this);
watchContext_ = new WatchContext(mainLoopContext_, dispatchSource_, shared_from_this());
timeoutContext_ = new TimeoutContext(mainLoopContext_, shared_from_this());
lockedContext->registerDispatchSource(dispatchSource_);

if (!isConnected()) {
Expand All @@ -263,19 +258,6 @@ bool DBusConnection::attachMainLoopContext(std::weak_ptr<MainLoopContext> mainLo
return false;
}

success = 0 != dbus_connection_set_timeout_functions(
connection_,
&DBusConnection::onAddTimeout,
&DBusConnection::onRemoveTimeout,
&DBusConnection::onToggleTimeout,
timeoutContext_,
NULL);

if (!success) {
dbus_connection_set_watch_functions(connection_, NULL, NULL, NULL, NULL, NULL);
return false;
}

return true;
}
return false;
Expand Down Expand Up @@ -355,53 +337,6 @@ void DBusConnection::onToggleWatch(::DBusWatch* libdbusWatch, void* data) {
}
}


dbus_bool_t DBusConnection::onAddTimeout(::DBusTimeout* libdbusTimeout, void* data) {
TimeoutContext* timeoutContext = static_cast<TimeoutContext*>(data);
if (NULL == timeoutContext) {
COMMONAPI_ERROR(std::string(__FUNCTION__), "timeoutContext == NULL");
return FALSE;
}

DBusTimeout* dbusTimeout = new DBusTimeout(libdbusTimeout, timeoutContext->mainLoopContext_, timeoutContext->dbusConnection_);
dbus_timeout_set_data(libdbusTimeout, dbusTimeout, NULL);

if (dbusTimeout->isReadyToBeMonitored()) {
dbusTimeout->startMonitoring();
} else {
delete dbusTimeout;
dbus_timeout_set_data(libdbusTimeout, NULL, NULL);
}

return TRUE;
}

void DBusConnection::onRemoveTimeout(::DBusTimeout* libdbusTimeout, void* data) {
if (NULL == static_cast<std::weak_ptr<MainLoopContext>*>(data)) {
COMMONAPI_ERROR(std::string(__FUNCTION__), "MainLoopContext == NULL");
}

DBusTimeout* dbusTimeout = static_cast<DBusTimeout*>(dbus_timeout_get_data(libdbusTimeout));
if (dbusTimeout) {
dbusTimeout->stopMonitoring();
}
dbus_timeout_set_data(libdbusTimeout, NULL, NULL);
// DBusTimeout will be deleted in Mainloop
}

void DBusConnection::onToggleTimeout(::DBusTimeout* dbustimeout, void* data) {
if (NULL == static_cast<std::weak_ptr<MainLoopContext>*>(data)) {
COMMONAPI_ERROR(std::string(__FUNCTION__), "MainLoopContext == NULL");
}

DBusTimeout* timeout = static_cast<DBusTimeout*>(dbus_timeout_get_data(dbustimeout));
if (timeout->isReadyToBeMonitored()) {
timeout->startMonitoring();
} else {
timeout->stopMonitoring();
}
}

bool DBusConnection::connect(bool startDispatchThread) {
DBusError dbusError;
return connect(dbusError, startDispatchThread);
Expand Down Expand Up @@ -539,7 +474,6 @@ void DBusConnection::disconnect() {

// remote mainloop watchers
dbus_connection_set_watch_functions(connection_, NULL, NULL, NULL, NULL, NULL);
dbus_connection_set_timeout_functions(connection_, NULL, NULL, NULL, NULL, NULL);

dbus_connection_unref(connection_);
connection_ = nullptr;
Expand Down Expand Up @@ -937,7 +871,6 @@ bool DBusConnection::sendDBusMessageWithReplyAsync(
replyAsyncHandler = dbusMessageReplyAsyncHandler.release();

PendingCallNotificationData* userData = new PendingCallNotificationData(this, replyAsyncHandler);
DBusTimeout::currentTimeout_ = NULL;

libdbusSuccess = dbus_connection_send_with_reply_set_notify(connection_,
dbusMessage.message_,
Expand Down Expand Up @@ -985,9 +918,6 @@ bool DBusConnection::sendDBusMessageWithReplyAsync(
dbusMessage
};

if(DBusTimeout::currentTimeout_)
DBusTimeout::currentTimeout_->setPendingCall(libdbusPendingCall);

DBusMessageReplyAsyncHandler* asyncHandler = nullptr;
{
std::lock_guard<std::mutex> enforcerLock(enforceTimeoutMutex_);
Expand Down
48 changes: 48 additions & 0 deletions src/CommonAPI/DBus/DBusServiceRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,54 @@ DBusServiceRegistry::unsubscribeAvailabilityListener(
// mark listener to remove
dbusInterfaceNameListenersRecord.listenersToRemove.push_back(listenerSubscription);

// remove listener from lists in mainloop context to make sure that in case
// of no availability change or in case of unsubscribing in availability callback
// the lists will be cleared / the lists grow infinitely.
auto dbusProxyConnection = dbusDaemonProxy_->getDBusConnection();
auto removeListener = [&](std::weak_ptr<DBusServiceRegistry> _registry,
DBusAddress dbusAddress, DBusServiceSubscription _subscription) {

if(auto itsServiceRegistry = _registry.lock()) {
std::lock_guard<std::recursive_mutex> itsLock(dbusServicesMutex_);

auto dbusServiceListenersIterator = dbusServiceListenersMap.find(dbusAddress.getService());
if(dbusServiceListenersIterator != dbusServiceListenersMap.end()) {
auto& dbusServiceListenersRecord = dbusServiceListenersIterator->second;
auto dbusObjectPathListenersIterator =
dbusServiceListenersRecord.dbusObjectPathListenersMap.find(dbusAddress.getObjectPath());

if(dbusObjectPathListenersIterator != dbusServiceListenersRecord.dbusObjectPathListenersMap.end()) {
auto& dbusInterfaceNameListenersMap = dbusObjectPathListenersIterator->second;
auto dbusInterfaceNameListenersIterator = dbusInterfaceNameListenersMap.find(dbusAddress.getInterface());

if(dbusInterfaceNameListenersIterator != dbusInterfaceNameListenersMap.end()) {
auto& dbusInterfaceNameListenersRecord = dbusInterfaceNameListenersIterator->second;

auto itsRemoveListenerIt = std::find(dbusInterfaceNameListenersRecord.listenersToRemove.begin(),
dbusInterfaceNameListenersRecord.listenersToRemove.end(),
_subscription);

if(itsRemoveListenerIt != dbusInterfaceNameListenersRecord.listenersToRemove.end()) {
dbusInterfaceNameListenersRecord.listenersToRemove.remove(_subscription);
dbusInterfaceNameListenersRecord.listenerList.erase(_subscription);

if (dbusInterfaceNameListenersRecord.listenerList.empty()) {
dbusInterfaceNameListenersMap.erase(dbusInterfaceNameListenersIterator);
if (dbusInterfaceNameListenersMap.empty()) {
dbusServiceListenersRecord.dbusObjectPathListenersMap.erase(dbusObjectPathListenersIterator);
}
}
}
}
}
}
}
};

std::weak_ptr<DBusServiceRegistry> itsRegistry = shared_from_this();
dbusProxyConnection->proxyPushFunctionToMainLoop<DBusConnection>(removeListener, itsRegistry,
dbusAddress, listenerSubscription);

dbusServicesMutex_.unlock();
}

Expand Down
48 changes: 26 additions & 22 deletions src/dbus-patches/capi-dbus-add-support-for-custom-marshalling.patch
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
From 7b0925938400b970bf699a9188fe03b7271eeead Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrgen=20Gehring?= <[email protected]>
Date: Thu, 23 Apr 2015 01:18:11 -0700
Subject: [PATCH] Add functions to support querying and manipulating the
From 689ff4ef20347a2999afd2e39502aee71b653f1a Mon Sep 17 00:00:00 2001
From: Juergen Gehring <[email protected]>
Date: Fri, 19 Jan 2018 08:30:28 -0800
Subject: [PATCH] patch Add functions to support querying and manipulating the
message body and signature. This is useful for code generators, which can
generate custom marshaling functions based on a given IDL. Those functions
tend to be optimized and faster than the generic iterator based marshaling.

---
dbus/dbus-message.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++
dbus/dbus-message.h | 14 ++++++++
dbus/dbus-string.c | 16 +++++++++
dbus/dbus-string.h | 5 +++
4 files changed, 134 insertions(+)
dbus/dbus-message.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++
dbus/dbus-message.h | 14 +++++++
dbus/dbus-string.c | 16 ++++++++
dbus/dbus-string.h | 5 +++
4 files changed, 138 insertions(+)

diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 43cb1be..d34663a 100644
index 43b3a9f..f5a04fa 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -3445,6 +3445,47 @@ dbus_message_get_sender (DBusMessage *message)
@@ -3746,6 +3746,51 @@ dbus_message_get_sender (DBusMessage *message)
}

/**
Expand Down Expand Up @@ -47,10 +47,14 @@ index 43cb1be..d34663a 100644
+dbus_message_set_signature (DBusMessage *message,
+ const char *signature)
+{
+ DBusString str;
+ _dbus_string_init_const (&str, signature);
+
+ _dbus_return_val_if_fail (message != NULL, FALSE);
+ _dbus_return_val_if_fail (!message->locked, FALSE);
+ _dbus_return_val_if_fail (signature == NULL ||
+ _dbus_check_is_valid_signature (signature), FALSE);
+
+ _dbus_return_val_if_fail (signature != NULL &&
+ _dbus_validate_signature_with_reason (&str, 0, _dbus_string_get_length (&str)) == DBUS_VALID, FALSE);
+ /* can't delete the signature if you have a message body */
+ _dbus_return_val_if_fail (_dbus_string_get_length (&message->body) == 0 ||
+ signature != NULL, FALSE);
Expand All @@ -65,7 +69,7 @@ index 43cb1be..d34663a 100644
* Gets the type signature of the message, i.e. the arguments in the
* message payload. The signature includes only "in" arguments for
* #DBUS_MESSAGE_TYPE_METHOD_CALL and only "out" arguments for
@@ -4632,6 +4673,64 @@ dbus_message_type_to_string (int type)
@@ -5009,6 +5054,64 @@ dbus_message_type_to_string (int type)
}

/**
Expand Down Expand Up @@ -131,10 +135,10 @@ index 43cb1be..d34663a 100644
* specification.
*
diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
index 4fd44da..76377b8 100644
index 8a9d57a..2f7873a 100644
--- a/dbus/dbus-message.h
+++ b/dbus/dbus-message.h
@@ -138,6 +138,9 @@ dbus_bool_t dbus_message_set_sender (DBusMessage *message,
@@ -170,6 +170,9 @@ dbus_bool_t dbus_message_set_sender (DBusMessage *message,
DBUS_EXPORT
const char* dbus_message_get_sender (DBusMessage *message);
DBUS_EXPORT
Expand All @@ -144,7 +148,7 @@ index 4fd44da..76377b8 100644
const char* dbus_message_get_signature (DBusMessage *message);
DBUS_EXPORT
void dbus_message_set_no_reply (DBusMessage *message,
@@ -262,6 +265,17 @@ dbus_bool_t dbus_message_iter_close_container (DBusMessageIter *iter,
@@ -299,6 +302,17 @@ dbus_bool_t dbus_message_iter_close_container (DBusMessageIter *iter,
DBUS_EXPORT
void dbus_message_iter_abandon_container (DBusMessageIter *iter,
DBusMessageIter *sub);
Expand All @@ -161,12 +165,12 @@ index 4fd44da..76377b8 100644
+int dbus_message_get_body_allocated (DBusMessage *message);

DBUS_EXPORT
void dbus_message_lock (DBusMessage *message);
void dbus_message_iter_abandon_container_if_open (DBusMessageIter *iter,
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index 0f63612..a084eca 100644
index 98d9f2b..565fa26 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -730,6 +730,22 @@ _dbus_string_get_length (const DBusString *str)
@@ -744,6 +744,22 @@ _dbus_string_get_length (const DBusString *str)
}
#endif /* !_dbus_string_get_length */

Expand All @@ -190,7 +194,7 @@ index 0f63612..a084eca 100644
* Makes a string longer by the given number of bytes. Checks whether
* adding additional_length to the current length would overflow an
diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h
index 86fb8c3..bfa2a39 100644
index 1c01770..fdc5412 100644
--- a/dbus/dbus-string.h
+++ b/dbus/dbus-string.h
@@ -61,6 +61,7 @@ struct DBusString
Expand All @@ -213,5 +217,5 @@ index 86fb8c3..bfa2a39 100644
* Get the string's length as an unsigned integer, for comparison with
* size_t and similar unsigned types that does not trigger compiler
--
1.9.1
2.7.4

0 comments on commit 77fd3ae

Please sign in to comment.