geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
SDBusMessage.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 SDBUSMESSAGE_HPP_INCLUDE
7 #define SDBUSMESSAGE_HPP_INCLUDE
8 
9 #include <memory>
10 #include <string>
11 #include <vector>
12 
13 struct sd_bus_message;
14 struct geopm_request_s;
15 
16 namespace geopm
17 {
28  {
29  public:
32  static const char M_MESSAGE_TYPE_STRUCT;
35  static const char M_MESSAGE_TYPE_ARRAY;
36  SDBusMessage() = default;
37  virtual ~SDBusMessage() = default;
42  static std::unique_ptr<SDBusMessage> make_unique(sd_bus_message *bus_message);
49  virtual sd_bus_message *get_sd_ptr(void) = 0;
60  virtual void enter_container(
61  char type,
62  const std::string &contents) = 0;
67  virtual void exit_container(void) = 0;
77  virtual void open_container(
78  char type,
79  const std::string &contents) = 0;
84  virtual void close_container(void) = 0;
90  virtual std::string read_string(void) = 0;
96  virtual double read_double(void) = 0;
102  virtual int read_integer(void) = 0;
110  virtual void append_strings(
111  const std::vector<std::string> &write_values) = 0;
119  virtual void append_request(const geopm_request_s &request) = 0;
133  virtual bool was_success(void) = 0;
134  };
135 
137  {
138  public:
139  SDBusMessageImp();
140  SDBusMessageImp(sd_bus_message *bus_message);
141  virtual ~SDBusMessageImp();
142  sd_bus_message *get_sd_ptr(void) override;
143  void enter_container(
144  char type,
145  const std::string &contents) override;
146  void exit_container(void) override;
147  virtual void open_container(
148  char type,
149  const std::string &contents) override;
150  virtual void close_container(void) override;
151  std::string read_string(void) override;
152  double read_double(void) override;
153  int read_integer(void) override;
154  void append_strings(
155  const std::vector<std::string> &write_values) override;
156  void append_request(const geopm_request_s &request) override;
157  bool was_success(void) override;
158  private:
159  sd_bus_message *m_bus_message;
160  bool m_was_success;
161  };
162 }
163 
164 #endif
Abstraction around sd_bus interfaces that read from or append to sd_bus_message types.
Definition: SDBusMessage.hpp:28
SDBusMessage()=default
virtual bool was_success(void)=0
Determine if end of array has been reached.
virtual void close_container(void)=0
Close a container in the message for writing.
virtual sd_bus_message * get_sd_ptr(void)=0
Get raw pointer to sd_bus struct.
static const char M_MESSAGE_TYPE_STRUCT
Used with enter_container() method to specify a structure container.
Definition: SDBusMessage.hpp:32
static std::unique_ptr< SDBusMessage > make_unique(sd_bus_message *bus_message)
Factory method for SDBusMessage interface.
Definition: SDBusMessage.cpp:47
virtual int read_integer(void)=0
Read an integer out of the message.
virtual ~SDBusMessage()=default
virtual void exit_container(void)=0
Exit a container in the message for reading.
static const char M_MESSAGE_TYPE_ARRAY
Used with enter_container() method to specify an array container.
Definition: SDBusMessage.hpp:35
virtual void append_strings(const std::vector< std::string > &write_values)=0
Write an array of strings into the message.
virtual void open_container(char type, const std::string &contents)=0
Open a container in the message for writing.
virtual std::string read_string(void)=0
Read a string out of the message.
virtual void append_request(const geopm_request_s &request)=0
Write an array of geopm_request_s into the message.
virtual void enter_container(char type, const std::string &contents)=0
Enter a container in the message for reading.
virtual double read_double(void)=0
Read a double out of the message.
Definition: SDBusMessage.hpp:137
sd_bus_message * get_sd_ptr(void) override
Get raw pointer to sd_bus struct.
Definition: SDBusMessage.cpp:70
std::string read_string(void) override
Read a string out of the message.
Definition: SDBusMessage.cpp:107
double read_double(void) override
Read a double out of the message.
Definition: SDBusMessage.cpp:123
void enter_container(char type, const std::string &contents) override
Enter a container in the message for reading.
Definition: SDBusMessage.cpp:75
void append_request(const geopm_request_s &request) override
Write an array of geopm_request_s into the message.
Definition: SDBusMessage.cpp:156
virtual void open_container(char type, const std::string &contents) override
Open a container in the message for writing.
Definition: SDBusMessage.cpp:92
bool was_success(void) override
Determine if end of array has been reached.
Definition: SDBusMessage.cpp:164
SDBusMessageImp()
Definition: SDBusMessage.cpp:52
void exit_container(void) override
Exit a container in the message for reading.
Definition: SDBusMessage.cpp:84
int read_integer(void) override
Read an integer out of the message.
Definition: SDBusMessage.cpp:133
virtual ~SDBusMessageImp()
Definition: SDBusMessage.cpp:65
virtual void close_container(void) override
Close a container in the message for writing.
Definition: SDBusMessage.cpp:100
void append_strings(const std::vector< std::string > &write_values) override
Write an array of strings into the message.
Definition: SDBusMessage.cpp:143
Definition: Agg.cpp:20
Definition: geopm_pio.h:387