| #include "tlbmc/hal/shared_mem/static_client_segment.h" |
| |
| #include <memory> |
| #include <string> |
| #include <utility> |
| |
| #include "absl/log/log.h" |
| #include "boost/interprocess/managed_shared_memory.hpp" //NOLINT |
| // copybara:strip_begin(g3-shared-libs) |
| #include "tlbmc/hal/shared_mem/metrics.h" |
| // copybara:strip_end |
| #include "tlbmc/hal/shared_mem/sensors.h" |
| #include "tlbmc/hal/shared_mem/static_shm_common.h" |
| |
| namespace milotic_tlbmc { |
| |
| std::unique_ptr<StaticClientSegment> StaticClientSegment::Create( |
| const std::string& shared_memory_name) { |
| try { |
| auto shm = std::make_unique<TlbmcSharedMemoryType>( |
| boost::interprocess::open_only, shared_memory_name.c_str()); |
| return std::make_unique<StaticClientSegment>(std::move(shm)); |
| } catch (const boost::interprocess::interprocess_exception& e) { |
| LOG(ERROR) << "Failed to open shared memory: " << e.what(); |
| } |
| return nullptr; |
| } |
| |
| StaticClientSegment::StaticClientSegment( |
| std::unique_ptr<TlbmcSharedMemoryType> memory) |
| : memory_(std::move(memory)) {} |
| |
| IpcSensor* StaticClientSegment::FindSensor( |
| const std::string& sensor_name) const { |
| auto [sensor, _] = memory_->find<IpcSensor>(sensor_name.c_str()); |
| return sensor; |
| } |
| |
| // copybara:strip_begin(g3-shared-libs) |
| TlbmcMetrics* StaticClientSegment::GetMetrics() { |
| return StaticSharedMemoryMetrics::GetInProcessMetrics(); |
| } |
| // copybara:strip_end |
| |
| } // namespace milotic_tlbmc |