geopm  3.1.1.dev214+gba4f9f6d
GEOPM - Global Extensible Open Power Manager
BatchStatus.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef BATCHSTATUS_HPP_INCLUDE
7 #define BATCHSTATUS_HPP_INCLUDE
8 
9 #include <string>
10 #include <memory>
11 #include <unordered_map>
12 
13 #include "POSIXSignal.hpp"
14 
15 namespace geopm
16 {
18  {
19  public:
20  static constexpr char M_MESSAGE_READ = 'r';
21  static constexpr char M_MESSAGE_WRITE = 'w';
22  static constexpr char M_MESSAGE_CONTINUE = 'c';
23  static constexpr char M_MESSAGE_QUIT = 'q';
24  static constexpr char M_MESSAGE_TERMINATE = 't';
25 
26  BatchStatus() = default;
27  virtual ~BatchStatus() = default;
28  static std::unique_ptr<BatchStatus> make_unique_server(
29  int client_pid,
30  const std::string &server_key);
31  static std::unique_ptr<BatchStatus> make_unique_client(
32  const std::string &server_key);
33 
37  virtual void send_message(char msg) = 0;
41  virtual char receive_message(void) = 0;
50  virtual void receive_message(char expect) = 0;
51  };
52 
53  class BatchStatusImp : public BatchStatus
54  {
55  public:
56  BatchStatusImp(int read_fd, int write_fd);
57  virtual ~BatchStatusImp() = default;
58  void send_message(char msg) override;
59  char receive_message(void) override;
60  void receive_message(char expect) override;
61 
62  protected:
63  virtual void open_fifo(void) = 0;
64  void check_return(int ret, const std::string &func_name);
65  int m_read_fd;
67 
68  // This is the single place where the server prefix is located,
69  // which is also accessed by BatchStatusTest.
70  static constexpr const char* M_DEFAULT_FIFO_PREFIX =
71  "/run/geopm/batch-status-";
72  };
73 
75  {
76  public:
80  BatchStatusServer(int other_pid, const std::string &server_key);
81  BatchStatusServer(int other_pid, const std::string &server_key,
82  const std::string &fifo_prefix);
83  BatchStatusServer(const BatchStatusServer &other) = delete;
85  virtual ~BatchStatusServer();
86 
87  private:
88  void open_fifo(void) override;
89  std::string m_read_fifo_path;
90  std::string m_write_fifo_path;
91  };
92 
94  {
95  public:
99  BatchStatusClient(const std::string &server_key);
100  BatchStatusClient(const std::string &server_key,
101  const std::string &fifo_prefix);
102  BatchStatusClient(const BatchStatusClient &other) = delete;
104  virtual ~BatchStatusClient();
105 
106  private:
107  void open_fifo(void) override;
108  std::string m_read_fifo_path;
109  std::string m_write_fifo_path;
110  };
111 }
112 
113 #endif
Definition: BatchStatus.hpp:94
BatchStatusClient & operator=(const BatchStatusClient &other)=delete
BatchStatusClient(const BatchStatusClient &other)=delete
virtual ~BatchStatusClient()
Definition: BatchStatus.cpp:174
BatchStatusClient(const std::string &server_key)
Definition: BatchStatus.cpp:160
Definition: BatchStatus.hpp:18
static constexpr char M_MESSAGE_WRITE
Definition: BatchStatus.hpp:21
virtual ~BatchStatus()=default
static constexpr char M_MESSAGE_TERMINATE
Definition: BatchStatus.hpp:24
BatchStatus()=default
static std::unique_ptr< BatchStatus > make_unique_client(const std::string &server_key)
Definition: BatchStatus.cpp:35
virtual void receive_message(char expect)=0
Receive specified integer from the other process.
static constexpr char M_MESSAGE_QUIT
Definition: BatchStatus.hpp:23
virtual char receive_message(void)=0
Receive any integer from the other process.
static std::unique_ptr< BatchStatus > make_unique_server(int client_pid, const std::string &server_key)
Definition: BatchStatus.cpp:27
static constexpr char M_MESSAGE_READ
Definition: BatchStatus.hpp:20
virtual void send_message(char msg)=0
Send an integer to the other process.
static constexpr char M_MESSAGE_CONTINUE
Definition: BatchStatus.hpp:22
Definition: BatchStatus.hpp:54
int m_write_fd
Definition: BatchStatus.hpp:66
char receive_message(void) override
Receive any integer from the other process.
Definition: BatchStatus.cpp:57
virtual void open_fifo(void)=0
int m_read_fd
Definition: BatchStatus.hpp:65
void send_message(char msg) override
Send an integer to the other process.
Definition: BatchStatus.cpp:51
void check_return(int ret, const std::string &func_name)
Definition: BatchStatus.cpp:79
virtual ~BatchStatusImp()=default
static constexpr const char * M_DEFAULT_FIFO_PREFIX
Definition: BatchStatus.hpp:70
BatchStatusImp(int read_fd, int write_fd)
Definition: BatchStatus.cpp:45
Definition: BatchStatus.hpp:75
virtual ~BatchStatusServer()
Definition: BatchStatus.cpp:129
BatchStatusServer(int other_pid, const std::string &server_key)
Definition: BatchStatus.cpp:93
BatchStatusServer(const BatchStatusServer &other)=delete
BatchStatusServer & operator=(const BatchStatusServer &other)=delete
Definition: Agg.cpp:20