Skip to content

Commit

Permalink
Android Improvements (eProsima#2977)
Browse files Browse the repository at this point in the history
* Refs #15493: Improvements to Android SHM handling. Minor fixes.

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #15493: Reverted Datasharing autodisabling on Android when using wrong folder

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #15493: Removed overly cautious path correction

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #15493: Applied suggestions

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #15493: Removed unneeded flags reported by Clang

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #15493: Fixed typo

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
  • Loading branch information
jsan-rt authored Sep 26, 2022
1 parent 7bc586f commit f8c6641
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 15 deletions.
4 changes: 2 additions & 2 deletions examples/cpp/dds/DeadlineQoSExample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ target_compile_definitions(DDSDeadlineQoSExample PRIVATE
)
target_include_directories(DDSDeadlineQoSExample PRIVATE ${Asio_INCLUDE_DIR})
target_link_libraries(DDSDeadlineQoSExample fastrtps fastcdr foonathan_memory)
if(UNIX AND NOT(QNXNTO))
target_link_libraries(DDSDeadlineQoSExample pthread)
if(UNIX AND NOT(QNXNTO) AND NOT(ANDROID))
target_link_libraries(DDSDeadlineQoSExample pthread)
endif()

install(TARGETS DDSDeadlineQoSExample
Expand Down
5 changes: 5 additions & 0 deletions src/cpp/rtps/persistence/PersistenceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ IPersistenceService* PersistenceFactory::create_persistence_service(
{
const std::string* filename_property = PropertyPolicyHelper::find_property(property_policy,
"dds.persistence.sqlite3.filename");
#ifdef ANDROID
const char* filename = (filename_property == nullptr) ?
"/data/local/tmp/persistence.db" : filename_property->c_str();
#else
const char* filename = (filename_property == nullptr) ?
"persistence.db" : filename_property->c_str();
#endif // if ANDROID
bool update_schema = false;
const std::string* update_schema_value = PropertyPolicyHelper::find_property(property_policy,
"dds.persistence.update_schema");
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/rtps/reader/WriterProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "rtps/RTPSDomainImpl.hpp"
#include "utils/collections/node_size_helpers.hpp"

#if !defined(NDEBUG) && defined(FASTRTPS_SOURCE) && defined(__unix__)
#if !defined(NDEBUG) && !defined(ANDROID) && defined(FASTRTPS_SOURCE) && defined(__unix__)
#define SHOULD_DEBUG_LINUX
#endif // SHOULD_DEBUG_LINUX

Expand Down
14 changes: 14 additions & 0 deletions src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include <cstring>
#include <algorithm>

#ifdef ANDROID
#include <boostconfig.hpp>
#include <unistd.h>
#endif // ifdef ANDROID

#include <fastdds/dds/log/Log.hpp>
#include <fastdds/rtps/common/Locator.h>
#include <fastdds/rtps/network/ReceiverResource.h>
Expand Down Expand Up @@ -251,6 +256,15 @@ bool SharedMemTransport::init(
return false;
}

#ifdef ANDROID
if (access(BOOST_INTERPROCESS_SHARED_DIR_PATH, W_OK) != F_OK)
{
logWarning(RTPS_MSG_OUT,
"Unable to write on " << BOOST_INTERPROCESS_SHARED_DIR_PATH << ". SHM Transport not enabled");
return false;
}
#endif // ifdef ANDROID

try
{
shared_mem_manager_ = SharedMemManager::create(SHM_MANAGER_DOMAIN);
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/utils/shared_memory/RobustExclusiveLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class RobustExclusiveLock
const std::string& file_path,
bool* was_lock_created)
{
auto fd = open(file_path.c_str(), O_RDONLY, 0666);
auto fd = open(file_path.c_str(), O_RDONLY, 0);

if (fd != -1)
{
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/utils/shared_memory/RobustSharedLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class RobustSharedLock
bool* was_lock_created,
bool* was_lock_released)
{
auto fd = open(file_path.c_str(), O_RDONLY, 0666);
auto fd = open(file_path.c_str(), O_RDONLY, 0);

if (fd != -1)
{
Expand Down Expand Up @@ -289,7 +289,7 @@ class RobustSharedLock
{
LockStatus lock_status;

auto fd = open(file_path.c_str(), O_RDONLY, 0666);
auto fd = open(file_path.c_str(), O_RDONLY, 0);

if (fd != -1)
{
Expand Down
36 changes: 27 additions & 9 deletions thirdparty/boost/include/boost/interprocess/detail/workaround.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,34 @@
//////////////////////////////////////////////////////
// _POSIX_SEMAPHORES (POSIX.1b/POSIX.4)
//////////////////////////////////////////////////////
#if ( defined(_POSIX_SEMAPHORES) && ((_POSIX_SEMAPHORES + 0) > 0) ) ||\
( defined(__FreeBSD__) && (__FreeBSD__ >= 4)) || \
defined(__APPLE__)
#define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
//MacOsX declares _POSIX_SEMAPHORES but sem_init returns ENOSYS
#if !defined(__APPLE__)
#define BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES
#if !defined(BOOST_FASTDDS_PATCHES)
#if ( defined(_POSIX_SEMAPHORES) && ((_POSIX_SEMAPHORES + 0) > 0) ) ||\
( defined(__FreeBSD__) && (__FreeBSD__ >= 4)) || \
defined(__APPLE__)
#define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
//MacOsX declares _POSIX_SEMAPHORES but sem_init returns ENOSYS
#if !defined(__APPLE__)
#define BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES
#endif
#if defined(__osf__) || defined(__vms)
#define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
#endif
#endif
#if defined(__osf__) || defined(__vms)
#define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
#else
#if ( defined(_POSIX_SEMAPHORES) && ((_POSIX_SEMAPHORES + 0) > 0) ) ||\
( defined(__FreeBSD__) && (__FreeBSD__ >= 4)) || \
defined(__APPLE__)
// Android does not implement sem_open/sem_close
#if !defined(__ANDROID__)
#define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
#endif
//MacOsX declares _POSIX_SEMAPHORES but sem_init returns ENOSYS
#if !defined(__APPLE__)
#define BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES
#endif
#if defined(__osf__) || defined(__vms)
#define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
#endif
#endif
#endif

Expand Down
4 changes: 4 additions & 0 deletions thirdparty/boost/include/boostconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
// it is more performant
#define BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION

#ifdef ANDROID
#define BOOST_INTERPROCESS_SHARED_DIR_PATH "/data/local/tmp"
#endif

#ifdef _MSC_VER

#include <stdlib.h>
Expand Down

0 comments on commit f8c6641

Please sign in to comment.