Replace mmap-based IPC with score_baselibs SharedMemoryFactory in ts_client#54
Replace mmap-based IPC with score_baselibs SharedMemoryFactory in ts_client#54gordon9901 wants to merge 2 commits into
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run //:license-checkStatus: Click to expand output |
|
The created documentation from the pull request is available at: docu-html |
aad9e21 to
7c692e8
Compare
There was a problem hiding this comment.
I think, we should not add these code duplications here. But instead replace the stub_ptp_machine by the shm_ptp_machine (see PR #25 how to achieve this)
There was a problem hiding this comment.
The stub variant was kept to avoid breaking existing code during development. Now that the shm path is confirmed working, I've removed svt_handler_shm.cpp/.h and factory_shm.cpp/.h, and updated SvtHandler directly to use CreateGPTPShmMachine instead of CreateGPTPStubMachine.
| ********************************************************************************/ | ||
| #ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_H | ||
| #define SCORE_TS_CLIENT_SRC_GPTP_IPC_H | ||
| #ifndef SCORE_TS_CLIENT_GPTP_IPC_H |
There was a problem hiding this comment.
Here and everywhere: Why doing this include guard renaming?
There was a problem hiding this comment.
The SRC segment encodes the physical directory path (ts_client/src/), which is an internal layout detail. Include guards should reflect the logical module name, not the filesystem structure — hence SCORE_TS_CLIENT_* rather than SCORE_TS_CLIENT_SRC_*. All 6 headers under ts_client/src/ were updated consistently.
There was a problem hiding this comment.
Yes, I also see this. But I'm struggeling with the point, that the "physical" structure is also visible in the includes, e.g.
#include "score/ts_client/src/gptp_ipc_channel.h"
which then should also be
#include "score/ts_client/gptp_ipc_channel.h"
instead. But that's how it is in Bazel.
If we change it here, we would be inconsistent in the overall module and should change it everywhere. (Maybe not now)
Maybe there is some S-CORE convention. Lets check ...
| * @brief IPC data snapshot written by TimeSlave and read by TimeDaemon. | ||
| * | ||
| * This type is internal to ts_client/src and intentionally decoupled from | ||
| * This type is internal to libTSClient and intentionally decoupled from |
There was a problem hiding this comment.
| * This type is internal to libTSClient and intentionally decoupled from | |
| * This type is internal to ts_client and intentionally decoupled from |
There was a problem hiding this comment.
Good catch. This was an oversight — the comment should say ts_client, not libTSClient. Fixed.
| { | ||
|
|
||
| /// Default POSIX shared memory name for the gPTP IPC channel. | ||
| constexpr char kGptpIpcName[] = "/gptp_ptp_info"; |
There was a problem hiding this comment.
| constexpr char kGptpIpcName[] = "/gptp_ptp_info"; | |
| /// Default shared memory name for the gPTP IPC channel. | |
| constexpr char kGptpIpcName[] = "/gptp_ptp_info"; |
There was a problem hiding this comment.
Agreed. The comment was removed because "POSIX" is no longer accurate after switching to SharedMemoryFactory. Restored as /// Default shared memory name for the gPTP IPC channel.
|
|
||
| /// Open and map the shared memory segment (read-only). | ||
| /// @return true on success. | ||
| bool Init(const std::string& ipc_name = kGptpIpcName); |
There was a problem hiding this comment.
| bool Init(const std::string& ipc_name = kGptpIpcName); | |
| bool Open(const std::string& ipc_name = kGptpIpcName); |
There was a problem hiding this comment.
Agreed. Open/Close is more semantically precise and forms a natural pair. Renamed in both GptpIpcPublisher and GptpIpcReceiver, including all call sites and test cases.
|
|
||
| /// Create and map the shared memory segment. | ||
| /// @return true on success. | ||
| bool Init(const std::string& ipc_name = kGptpIpcName); |
There was a problem hiding this comment.
| bool Init(const std::string& ipc_name = kGptpIpcName); | |
| bool Open(const std::string& ipc_name = kGptpIpcName); |
There was a problem hiding this comment.
Agreed. Open/Close is more semantically precise and forms a natural pair. Renamed in both GptpIpcPublisher and GptpIpcReceiver, including all call sites and test cases.
| void Publish(const score::ts::GptpIpcData& data); | ||
|
|
||
| /// Unmap and unlink the shared memory segment. | ||
| void Destroy(); |
There was a problem hiding this comment.
| void Destroy(); | |
| void Close(); |
There was a problem hiding this comment.
Agreed. Open/Close is more semantically precise and forms a natural pair. Renamed in both GptpIpcPublisher and GptpIpcReceiver, including all call sites and test cases.
Summary
Replaces the hand-rolled POSIX
shm_open/mmapimplementation ints_clientwith
score::memory::shared::SharedMemoryFactoryfromscore_baselibs, andwires up a new
SvtHandlerShmtimebase handler inTimeDaemon.ts_client (
score/ts_client/)GptpIpcPublisher/GptpIpcReceiver: remove directshm_open,mmap,ftruncate,closecalls; useSharedMemoryFactory::Create/SharedMemoryFactory::Openinstead. Memory region is now constructed viaISharedMemoryResource::construct<GptpIpcRegion>().SharedMemoryFactory::Remove+RemoveStaleArtefactsreplace the rawshm_unlinkin publisher init._SRC_segment.TimeDaemon (
score/time_daemon/src/application/svt/)SvtHandlerShm(factory_shm.h/.cpp,svt_handler_shm.h/.cpp):a
TimebaseHandlerimplementation that reads live gPTP data from sharedmemory via
GPTPShmMachineand drives the same verification + IPC-publishpipeline as the existing
SvtHandler.fixes (#41)