Skip to content

Commit

Permalink
capicxx-dbus-runtime 3.1.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
juergengehring committed Jan 25, 2018
1 parent 3fac877 commit f072e9b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changes
=======
v3.1.12.2
- Fixed hang-up in proxy destruction when async method call was done and proxy is not available
- DBus connections are now released even if they were not created with the Factory interface

v3.1.12.1
- Fixed race condition for managed services. When a managed services was removed, an appropriate
availability status changed event was received (service became unavailable) and afterwards a 'getAvailablStatusAsync' call for the removed service instance was done, the response could be that
Expand Down
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCOMMONAPI_LOGLEVEL=COMMONAPI_LOGLEVEL_${MAX_LOG_LEVEL}")

message(STATUS "Compiler options: ${CMAKE_CXX_FLAGS}")
message(STATUS "Compiler options: ${CMAKE_CXX_FLAGS}")

include_directories(
include
Expand Down Expand Up @@ -325,7 +325,7 @@ else()
COMMAND asciidoc
-a version=${PACKAGE_VERSION}
-b html
-o doc/html/README.html
-o doc/html/README.html
${PROJECT_BINARY_DIR}/../README)
endif()
endif()
Expand Down Expand Up @@ -360,6 +360,10 @@ if ("${BUILD_SHARED_LIBS}" STREQUAL "ON")
set(BUILD_SHARED_LIBS OFF)
set(BUILD_SHARED_LIBS_AUTOMATIC_OFF 1)
endif()
# ...but visual studio needs a shared CRT for gtest, otherwise the linker won't work correctly with the testcases.
if (MSVC)
set( gtest_force_shared_crt ON CACHE BOOL "Always use msvcrt.dll" )
endif()
add_subdirectory(${GTEST_ROOT} ${CMAKE_CURRENT_BINARY_DIR}/gtest EXCLUDE_FROM_ALL)
if ("${BUILD_SHARED_LIBS_AUTOMATIC_OFF}" STREQUAL "1")
set(BUILD_SHARED_LIBS ON)
Expand All @@ -382,4 +386,3 @@ add_dependencies(check build_tests)
# add test directory

add_subdirectory( src/test EXCLUDE_FROM_ALL )

1 change: 1 addition & 0 deletions include/CommonAPI/DBus/DBusProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class COMMONAPI_EXPORT_CLASS_EXPLICIT DBusProxy
mutable std::list<AvailabilityTimeout_t> timeouts_;

std::atomic<bool> everAvailable_;
mutable std::atomic<bool> cancelAvailabilityTimeoutThread_;
};


Expand Down
22 changes: 15 additions & 7 deletions src/CommonAPI/DBus/DBusConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,20 @@ class CompletionHelper {
}

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_);
Expand Down Expand Up @@ -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_);
}

Expand Down Expand Up @@ -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()) {

Expand Down
7 changes: 3 additions & 4 deletions src/CommonAPI/DBus/DBusFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/CommonAPI/DBus/DBusProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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)
{
}

Expand All @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit f072e9b

Please sign in to comment.