geopm 3.1.1.dev456+g3ba31824
GEOPM - Global Extensible Open Power Manager
Loading...
Searching...
No Matches
BatchServer.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 BATCHSERVER_HPP_INCLUDE
7#define BATCHSERVER_HPP_INCLUDE
8
9#include <memory>
10#include <vector>
11#include <string>
12#include <functional>
13#include <signal.h>
14
15
16struct geopm_request_s;
17
18namespace geopm
19{
20 class PlatformIO;
21 class SharedMemory;
22 class BatchStatus;
23 class POSIXSignal;
24
26 {
27 public:
30 BatchServer() = default;
31 virtual ~BatchServer() = default;
68 static std::unique_ptr<BatchServer> make_unique(int client_pid,
69 const std::vector<geopm_request_s> &signal_config,
70 const std::vector<geopm_request_s> &control_config);
73 static std::string get_signal_shmem_key(
74 const std::string &server_key);
77 static std::string get_control_shmem_key(
78 const std::string &server_key);
81 static int main(int argc, char **argv);
82 static void main(int client_pid, std::istream &input_stream);
83 virtual int server_pid(void) const = 0;
87 virtual std::string server_key(void) const = 0;
89 virtual bool is_active(void) = 0;
90 virtual void run_batch(void) = 0;
91 virtual void create_shmem(void) = 0;
92 virtual void register_handler(void) = 0;
93 protected:
94 static constexpr const char* M_SHMEM_PREFIX =
95 "/run/geopm/batch-buffer-";
96 };
97
99 {
100 public:
101 BatchServerImp(int client_pid,
102 const std::vector<geopm_request_s> &signal_config,
103 const std::vector<geopm_request_s> &control_config);
104 BatchServerImp(int client_pid,
105 const std::vector<geopm_request_s> &signal_config,
106 const std::vector<geopm_request_s> &control_config,
107 const std::string &signal_shmem_key,
108 const std::string &control_shmem_key,
109 PlatformIO &pio,
110 std::shared_ptr<BatchStatus> batch_status,
111 std::shared_ptr<POSIXSignal> posix_signal,
112 std::shared_ptr<SharedMemory> signal_shmem,
113 std::shared_ptr<SharedMemory> control_shmem,
114 int server_pid);
115 BatchServerImp(const BatchServerImp &other) = delete;
116 BatchServerImp &operator=(const BatchServerImp &other) = delete;
117 virtual ~BatchServerImp();
118 int server_pid(void) const override;
119 std::string server_key(void) const override;
120 bool is_active(void) override;
121 void run_batch(void) override;
122 void create_shmem(void) override;
123 void register_handler(void) override;
124 void push_requests(void);
125 void read_and_update(void);
126 void update_and_write(void);
128 void check_return(int ret, const std::string &func_name) const;
129 char read_message(void);
130 void write_message(char message);
131 void event_loop(void);
132 private:
133 const int m_client_pid;
134 const std::string m_server_key;
135 const std::vector<geopm_request_s> m_signal_config;
136 const std::vector<geopm_request_s> m_control_config;
137 const std::string m_signal_shmem_key;
138 const std::string m_control_shmem_key;
139 PlatformIO &m_pio;
140 std::shared_ptr<SharedMemory> m_signal_shmem;
141 std::shared_ptr<SharedMemory> m_control_shmem;
142 std::shared_ptr<BatchStatus> m_batch_status;
143 std::shared_ptr<POSIXSignal> m_posix_signal;
144 int m_server_pid;
145 bool m_is_active;
146 bool m_is_client_attached;
147 bool m_is_client_waiting;
150 std::vector<int> m_signal_handle;
153 std::vector<int> m_control_handle;
154 };
155}
156
157#endif
Definition BatchServer.hpp:26
static std::unique_ptr< BatchServer > make_unique(int client_pid, const std::vector< geopm_request_s > &signal_config, const std::vector< geopm_request_s > &control_config)
Supports the D-Bus interface for starting a batch server.
Definition BatchServer.cpp:44
static std::string get_control_shmem_key(const std::string &server_key)
Definition BatchServer.cpp:58
virtual std::string server_key(void) const =0
virtual void run_batch(void)=0
static std::string get_signal_shmem_key(const std::string &server_key)
Definition BatchServer.cpp:52
static constexpr const char * M_SHMEM_PREFIX
Definition BatchServer.hpp:94
virtual void register_handler(void)=0
static int main(int argc, char **argv)
Definition BatchServer.cpp:315
BatchServer()=default
Interface called by geopmd to create the server for batch commands.
virtual int server_pid(void) const =0
virtual void create_shmem(void)=0
virtual bool is_active(void)=0
Returns true if the batch server is running.
virtual ~BatchServer()=default
Definition BatchServer.hpp:99
void check_invalid_signal(void)
void run_batch(void) override
Definition BatchServer.cpp:178
bool is_active(void) override
Returns true if the batch server is running.
Definition BatchServer.cpp:236
void update_and_write(void)
Definition BatchServer.cpp:268
char read_message(void)
Definition BatchServer.cpp:135
void check_return(int ret, const std::string &func_name) const
Definition BatchServer.cpp:413
void event_loop(void)
Definition BatchServer.cpp:201
void push_requests(void)
Definition BatchServer.cpp:241
virtual ~BatchServerImp()
Definition BatchServer.cpp:114
BatchServerImp & operator=(const BatchServerImp &other)=delete
void register_handler(void) override
Definition BatchServer.cpp:304
void create_shmem(void) override
Definition BatchServer.cpp:283
BatchServerImp(const BatchServerImp &other)=delete
int server_pid(void) const override
Definition BatchServer.cpp:125
void write_message(char message)
Definition BatchServer.cpp:162
std::string server_key(void) const override
Definition BatchServer.cpp:130
void read_and_update(void)
Definition BatchServer.cpp:253
Class which is a collection of all valid control and signal objects for a platform.
Definition PlatformIO.hpp:26
Definition Agg.cpp:20
Definition geopm_pio.h:387