Skip to content

Commit

Permalink
Refs #19435. Added RTPSDomain::set_filewatch_thread_config
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Oct 11, 2023
1 parent 41c3702 commit 3245527
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
13 changes: 13 additions & 0 deletions include/fastdds/rtps/RTPSDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <set>

#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastdds/rtps/attributes/ThreadSettings.hpp>
#include <fastdds/rtps/common/Types.h>
#include <fastdds/rtps/history/IPayloadPool.h>
#include <fastdds/rtps/history/IChangePool.h>
Expand Down Expand Up @@ -54,6 +55,18 @@ class RTPSDomain
{
public:

/**
* Method to set the configuration of the threads created by the file watcher for the environment file.
* In order for these settings to take effect, this method must be called before the first call
* to @ref createParticipant.
*
* @param watch_thread Settings for the thread watching the environment file.
* @param callback_thread Settings for the thread executing the callback when the environment file changed.
*/
RTPS_DllAPI static void set_filewatch_thread_config(
const fastdds::rtps::ThreadSettings& watch_thread,
const fastdds::rtps::ThreadSettings& callback_thread);

/**
* Method to shut down all RTPSParticipants, readers, writers, etc.
* It must be called at the end of the process to avoid memory leaks.
Expand Down
21 changes: 20 additions & 1 deletion src/cpp/rtps/RTPSDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ std::shared_ptr<RTPSDomainImpl> RTPSDomainImpl::get_instance()
return instance;
}

void RTPSDomain::set_filewatch_thread_config(
const fastdds::rtps::ThreadSettings& watch_thread,
const fastdds::rtps::ThreadSettings& callback_thread)
{
RTPSDomainImpl::set_filewatch_thread_config(watch_thread, callback_thread);
}

void RTPSDomain::stopAll()
{
RTPSDomainImpl::stopAll();
Expand Down Expand Up @@ -143,8 +150,10 @@ RTPSParticipant* RTPSDomainImpl::createParticipant(
std::string filename = SystemInfo::get_environment_file();
if (!filename.empty() && SystemInfo::file_exists(filename))
{
std::lock_guard<std::mutex> guard(instance->m_mutex);
// Create filewatch
instance->file_watch_handle_ = SystemInfo::watch_file(filename, RTPSDomainImpl::file_watch_callback, {}, {});
instance->file_watch_handle_ = SystemInfo::watch_file(filename, RTPSDomainImpl::file_watch_callback,
instance->watch_thread_config_, instance->callback_thread_config_);
}
else if (!filename.empty())
{
Expand Down Expand Up @@ -778,6 +787,16 @@ void RTPSDomainImpl::file_watch_callback()
}
}

void RTPSDomainImpl::set_filewatch_thread_config(
const fastdds::rtps::ThreadSettings& watch_thread,
const fastdds::rtps::ThreadSettings& callback_thread)
{
auto instance = get_instance();
std::lock_guard<std::mutex> guard(instance->m_mutex);
instance->watch_thread_config_ = watch_thread;
instance->callback_thread_config_ = callback_thread;
}

} // namespace rtps
} // namespace fastrtps
} // namespace eprosima
15 changes: 15 additions & 0 deletions src/cpp/rtps/RTPSDomainImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <FileWatch.hpp>
#endif // defined(_WIN32) || defined(__unix__)

#include <fastdds/rtps/attributes/ThreadSettings.hpp>
#include <fastrtps/rtps/reader/RTPSReader.h>
#include <fastrtps/rtps/RTPSDomain.h>
#include <fastrtps/rtps/writer/RTPSWriter.h>
Expand Down Expand Up @@ -203,6 +204,18 @@ class RTPSDomainImpl
*/
static void file_watch_callback();

/**
* Method to set the configuration of the threads created by the file watcher for the environment file.
* In order for these settings to take effect, this method must be called before the first call
* to @ref createParticipant.
*
* @param watch_thread Settings for the thread watching the environment file.
* @param callback_thread Settings for the thread executing the callback when the environment file changed.
*/
static void set_filewatch_thread_config(
const fastdds::rtps::ThreadSettings& watch_thread,
const fastdds::rtps::ThreadSettings& callback_thread);

private:

/**
Expand Down Expand Up @@ -252,6 +265,8 @@ class RTPSDomainImpl
std::unordered_map<uint32_t, ParticipantIDState> m_RTPSParticipantIDs;

FileWatchHandle file_watch_handle_;
fastdds::rtps::ThreadSettings watch_thread_config_;
fastdds::rtps::ThreadSettings callback_thread_config_;
};

} // namespace rtps
Expand Down
7 changes: 7 additions & 0 deletions test/mock/rtps/RTPSDomain/fastdds/rtps/RTPSDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define _FASTDDS_RTPS_DOMAIN_H_

#include <fastdds/rtps/common/Types.h>
#include <fastdds/rtps/attributes/ThreadSettings.hpp>
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>

#include <fastdds/rtps/participant/RTPSParticipant.h>
Expand Down Expand Up @@ -44,6 +45,12 @@ class RTPSDomain
{
public:

static void set_filewatch_thread_config(
const fastdds::rtps::ThreadSettings&,
const fastdds::rtps::ThreadSettings&)
{
}

static void stopAll()
{
}
Expand Down

0 comments on commit 3245527

Please sign in to comment.