Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15493] Android Improvements #2977

Merged
merged 6 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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