blob: 90bb9cbcd8bea828726fc4b095b00c8f0638a679 [file]
#ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_SHARED_MEM_STATIC_SHARED_MEMORY_SERVER_IMPL_H
#define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_SHARED_MEM_STATIC_SHARED_MEMORY_SERVER_IMPL_H
#include <cstdint>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include "absl/container/flat_hash_map.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/time/time.h"
#include "absl/types/span.h"
#include "tlbmc/hal/shared_mem/metrics.h"
#include "tlbmc/hal/shared_mem/sensors.h"
#include "tlbmc/hal/shared_mem/server_interface.h"
#include "tlbmc/hal/shared_mem/static_shm_common.h"
namespace milotic_tlbmc {
class StaticSharedMemoryServer : public IpcServer {
public:
StaticSharedMemoryServer(const StaticSharedMemoryServer& other) = delete;
StaticSharedMemoryServer(StaticSharedMemoryServer&& other) noexcept = delete;
StaticSharedMemoryServer& operator=(const StaticSharedMemoryServer& other) =
delete;
StaticSharedMemoryServer& operator=(
StaticSharedMemoryServer&& other) noexcept = delete;
static absl::Status InitializeSharedMemoryForUnitTest(
absl::Span<const std::string> shm_sensors);
static void SetupInstanceForUnitTest();
static absl::Status InitializeSharedMemory(
absl::Span<const std::string> shm_sensors);
static absl::Status InitializeSharedMemory(
const std::string& initialized_file_path, const std::string& shm_name,
absl::Span<const std::string> shm_sensors);
static IpcServer& GetInstance();
static IpcServer& GetInstance(const std::string& initialized_file_path,
const std::string& shm_name,
bool force_reset_for_testing = false);
absl::StatusOr<std::pair<float, uint64_t>> ReadSensorValue(
const std::string& sensor_name) override;
// copybara:strip_begin(g3-shared-libs)
void UpdateMetricsRequestCount(bool is_tlbmc_request) override;
void UpdateMetricsResponse(absl::Duration response_time, int status_code,
std::string_view resource_url) override;
void UpdateMetricsRps(absl::Duration time_delta) override;
// copybara:strip_end
StaticSharedMemoryServer(
std::unique_ptr<TlbmcSharedMemoryType> memory,
absl::flat_hash_map<std::string, IpcSensor*> name_to_sensor,
TlbmcMetrics* metrics);
~StaticSharedMemoryServer() override = default;
protected:
StaticSharedMemoryServer() = default;
static std::unique_ptr<IpcServer> PerformServerInit(
const std::string& initialized_file_path, const std::string& shm_name);
private:
std::unique_ptr<TlbmcSharedMemoryType> memory_;
absl::flat_hash_map<std::string, IpcSensor*> name_to_sensor_;
TlbmcMetrics* metrics_;
};
} // namespace milotic_tlbmc
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_SHARED_MEM_STATIC_SHARED_MEMORY_SERVER_IMPL_H