summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CommonAPI/DBus/DBusConnection.cpp22
-rw-r--r--src/CommonAPI/DBus/DBusFactory.cpp7
-rw-r--r--src/CommonAPI/DBus/DBusProxy.cpp14
-rw-r--r--src/test/CMakeLists.txt10
4 files changed, 33 insertions, 20 deletions
diff --git a/src/CommonAPI/DBus/DBusConnection.cpp b/src/CommonAPI/DBus/DBusConnection.cpp
index d9da52e..4206f95 100644
--- a/src/CommonAPI/DBus/DBusConnection.cpp
+++ b/src/CommonAPI/DBus/DBusConnection.cpp
@@ -67,13 +67,20 @@ public:
}
bool forceDetach(false);
- if (0u != activeConnections) {
- std::future<bool> ready = readyToCleanup_.get_future();
- if (ready.valid()) {
- const std::future_status status = ready.wait_for(std::chrono::seconds(1));
- forceDetach = (std::future_status::ready != status);
+ #if defined (_MSC_VER) && (_MSC_VER < 1900)
+ // MSVC compiler RTL is buggy until fixed in Visual Studio 2015
+ // The code crashes when doing a wait_for() in a static destructor
+ // So, skip the check if we have an older version of MSVC
+ forceDetach = true;
+ #else
+ if (0u != activeConnections) {
+ std::future<bool> ready = readyToCleanup_.get_future();
+ if (ready.valid()) {
+ const std::future_status status = ready.wait_for(std::chrono::seconds(1));
+ forceDetach = (std::future_status::ready != status);
+ }
}
- }
+ #endif
{
std::lock_guard<std::mutex> lock(mutex_);
@@ -465,6 +472,7 @@ void DBusConnection::disconnect() {
isDisconnecting_ = true;
if (std::shared_ptr<CommonAPI::MainLoopContext> mainLoopContext = mainLoopContext_.lock()) {
+ DBusServiceRegistry::remove(shared_from_this());
Factory::get()->releaseConnection(connectionId_);
}
@@ -1264,7 +1272,7 @@ bool DBusConnection::removeSignalMemberHandler(const DBusSignalHandlerToken &dbu
bool lastHandlerRemoved = false;
std::lock_guard<std::mutex> dbusSignalHandlersLock(signalHandlersGuard_);
-
+
auto signalHandlerPathIt = dbusSignalHandlers_.find(dbusSignalHandlerToken);
if (signalHandlerPathIt != dbusSignalHandlers_.end()) {
diff --git a/src/CommonAPI/DBus/DBusFactory.cpp b/src/CommonAPI/DBus/DBusFactory.cpp
index 2490e98..2006f5a 100644
--- a/src/CommonAPI/DBus/DBusFactory.cpp
+++ b/src/CommonAPI/DBus/DBusFactory.cpp
@@ -88,7 +88,7 @@ Factory::createProxy(
if (proxyCreateFunctionsIterator != proxyCreateFunctions_.end()) {
CommonAPI::Address address(_domain, _interface, _instance);
DBusAddress dbusAddress;
-
+
if (DBusAddressTranslator::get()->translate(address, dbusAddress)) {
std::shared_ptr<DBusConnection> connection
= getConnection(_connectionId);
@@ -113,7 +113,7 @@ Factory::createProxy(
if (proxyCreateFunctionsIterator != proxyCreateFunctions_.end()) {
CommonAPI::Address address(_domain, _interface, _instance);
DBusAddress dbusAddress;
-
+
if (DBusAddressTranslator::get()->translate(address, dbusAddress)) {
std::shared_ptr<DBusConnection> connection
= getConnection(_context);
@@ -188,7 +188,7 @@ Factory::unregisterStub(const std::string &_domain, const std::string &_interfac
const auto _adapter = adapterResult->second;
const auto &connection = _adapter->getDBusConnection();
const auto objectManager = connection->getDBusObjectManager();
-
+
if (!objectManager->unregisterDBusStubAdapter(_adapter)) {
return false;
}
@@ -462,7 +462,6 @@ void Factory::releaseConnection(const ConnectionId_t& _connectionId) {
auto itsConnection = connections_.find(_connectionId);
if (itsConnection != connections_.end()) {
- DBusServiceRegistry::remove(itsConnection->second);
connections_.erase(_connectionId);
}
}
diff --git a/src/CommonAPI/DBus/DBusProxy.cpp b/src/CommonAPI/DBus/DBusProxy.cpp
index eef22b4..0b5b14c 100644
--- a/src/CommonAPI/DBus/DBusProxy.cpp
+++ b/src/CommonAPI/DBus/DBusProxy.cpp
@@ -50,7 +50,7 @@ void DBusProxyStatusEvent::onListenerRemoved(const Listener& _listener,
void DBusProxy::availabilityTimeoutThreadHandler() const {
std::unique_lock<std::mutex> threadLock(availabilityTimeoutThreadMutex_);
- bool cancel = false;
+ bool finish = false;
bool firstIteration = true;
// the callbacks that have to be done are stored with
@@ -63,7 +63,7 @@ void DBusProxy::availabilityTimeoutThreadHandler() const {
> CallbackData_t;
std::list<CallbackData_t> callbacks;
- while(!cancel) {
+ while(!cancelAvailabilityTimeoutThread_ && !finish) {
//get min timeout
timeoutsMutex_.lock();
@@ -175,7 +175,7 @@ void DBusProxy::availabilityTimeoutThreadHandler() const {
//cancel thread
timeoutsMutex_.lock();
if(timeouts_.size() == 0 && callbacks.size() == 0)
- cancel = true;
+ finish = true;
timeoutsMutex_.unlock();
}
}
@@ -187,7 +187,8 @@ DBusProxy::DBusProxy(const DBusAddress &_dbusAddress,
availabilityStatus_(AvailabilityStatus::UNKNOWN),
interfaceVersionAttribute_(*this, "uu", "getInterfaceVersion"),
dbusServiceRegistry_(DBusServiceRegistry::get(_connection)),
- everAvailable_(false)
+ everAvailable_(false),
+ cancelAvailabilityTimeoutThread_(false)
{
}
@@ -200,6 +201,11 @@ void DBusProxy::init() {
}
DBusProxy::~DBusProxy() {
+ cancelAvailabilityTimeoutThread_ = true;
+ {
+ std::lock_guard<std::mutex> itsTimeoutThreadLock(availabilityTimeoutThreadMutex_);
+ availabilityTimeoutCondition_.notify_all();
+ }
if(availabilityTimeoutThread_) {
if(availabilityTimeoutThread_->joinable())
availabilityTimeoutThread_->join();
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt
index 5ae19c9..3707379 100644
--- a/src/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -70,10 +70,11 @@ set(ExtendedInterfaceDBusSources ${ExtendedInterfaceSources}
src-gen/dbus/${VERSION}/commonapi/tests/ExtendedInterfaceDBusProxy.cpp
src-gen/dbus/${VERSION}/commonapi/tests/ExtendedInterfaceDBusStubAdapter.cpp)
-
-set(TEST_LINK_LIBRARIES -Wl,--no-as-needed CommonAPI-DBus -Wl,--as-needed CommonAPI ${DBus_LDFLAGS} ${DL_LIBRARY} gtest ${PTHREAD_LIBRARY})
-
-set(TEST_LINK_LIBRARIES_WITHOUT_COMMONAPI_DBUS CommonAPI gtest ${PTHREAD_LIBRARY})
+if (MSVC)
+ set(TEST_LINK_LIBRARIES ${DBus_LDFLAGS} CommonAPI-DBus CommonAPI gtest )
+else()
+ set(TEST_LINK_LIBRARIES -Wl,--no-as-needed CommonAPI-DBus -Wl,--as-needed CommonAPI ${DBus_LDFLAGS} ${DL_LIBRARY} gtest ${PTHREAD_LIBRARY})
+endif()
##############################################################################
# DBusConnectionTest
@@ -145,4 +146,3 @@ add_test(NAME DBusVariantOutputStreamTest COMMAND DBusVariantOutputStreamTest)
add_test(NAME DBusDaemonProxyTest COMMAND DBusDaemonProxyTest)
add_test(NAME DBusVariantTest COMMAND DBusVariantTest)
add_test(NAME DBusClientIdTest COMMAND DBusClientIdTest)
-