geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
SDBus.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 SDBUS_HPP_INCLUDE
7 #define SDBUS_HPP_INCLUDE
8 
9 #include <memory>
10 #include <string>
11 #include <vector>
12 
13 struct sd_bus;
14 
15 namespace geopm
16 {
17  class SDBusMessage;
18 
29  class SDBus
30  {
31  public:
32  SDBus() = default;
33  virtual ~SDBus() = default;
38  static std::unique_ptr<SDBus> make_unique(void);
56  virtual std::shared_ptr<SDBusMessage> call_method(
57  std::shared_ptr<SDBusMessage> message) = 0;
66  virtual std::shared_ptr<SDBusMessage> call_method(
67  const std::string &member) = 0;
82  virtual std::shared_ptr<SDBusMessage> call_method(
83  const std::string &member,
84  const std::string &arg0,
85  int arg1,
86  int arg2) = 0;
103  virtual std::shared_ptr<SDBusMessage> call_method(
104  const std::string &member,
105  const std::string &arg0,
106  int arg1,
107  int arg2,
108  double arg3) = 0;
119  virtual std::shared_ptr<SDBusMessage> call_method(
120  const std::string &member,
121  int arg0) = 0;
136  virtual std::shared_ptr<SDBusMessage> make_call_message(
137  const std::string &member) = 0;
138 
139  virtual std::shared_ptr<SDBusMessage> call_method(
140  const std::string &member,
141  const std::string &arg0) = 0;
142 
143  };
144 
145  class SDBusImp : public SDBus
146  {
147  public:
148  SDBusImp();
149  SDBusImp(const SDBusImp &other) = delete;
150  SDBusImp &operator=(const SDBusImp &other) = delete;
151  virtual ~SDBusImp();
152  std::shared_ptr<SDBusMessage> call_method(
153  std::shared_ptr<SDBusMessage> message) override;
154  std::shared_ptr<SDBusMessage> call_method(
155  const std::string &member) override;
156  std::shared_ptr<SDBusMessage> call_method(
157  const std::string &member,
158  const std::string &arg0,
159  int arg1,
160  int arg2) override;
161  std::shared_ptr<SDBusMessage> call_method(
162  const std::string &member,
163  const std::string &arg0,
164  int arg1,
165  int arg2,
166  double arg3) override;
167  std::shared_ptr<SDBusMessage> call_method(
168  const std::string &member,
169  int arg0) override;
170  std::shared_ptr<SDBusMessage> make_call_message(
171  const std::string &member) override;
172  std::shared_ptr<SDBusMessage> call_method(
173  const std::string &member,
174  const std::string &arg0) override;
175  private:
176  sd_bus *m_bus;
177  const char *m_dbus_destination;
178  const char *m_dbus_path;
179  const char *m_dbus_interface;
180  const uint64_t m_dbus_timeout_usec;
181  };
182 }
183 
184 #endif
Abstraction around sd_bus interface for calling methods.
Definition: SDBus.hpp:30
virtual std::shared_ptr< SDBusMessage > call_method(const std::string &member, const std::string &arg0)=0
SDBus()=default
virtual std::shared_ptr< SDBusMessage > call_method(const std::string &member, const std::string &arg0, int arg1, int arg2)=0
Wrapper for the sd_bus_call_method(3) function.
static std::unique_ptr< SDBus > make_unique(void)
Factory method for SDBus interface.
Definition: SDBus.cpp:41
virtual ~SDBus()=default
virtual std::shared_ptr< SDBusMessage > call_method(const std::string &member)=0
Wrapper for the sd_bus_call_method(3) function.
virtual std::shared_ptr< SDBusMessage > call_method(const std::string &member, int arg0)=0
Wrapper for the sd_bus_call_method(3) function.
virtual std::shared_ptr< SDBusMessage > make_call_message(const std::string &member)=0
Wrapper for the sd_bus_message_new_method_call(3) function.
virtual std::shared_ptr< SDBusMessage > call_method(std::shared_ptr< SDBusMessage > message)=0
Wrapper for the sd_bus_call(3) function.
virtual std::shared_ptr< SDBusMessage > call_method(const std::string &member, const std::string &arg0, int arg1, int arg2, double arg3)=0
Wrapper for the sd_bus_call_method(3) function.
Definition: SDBus.hpp:146
SDBusImp(const SDBusImp &other)=delete
std::shared_ptr< SDBusMessage > call_method(std::shared_ptr< SDBusMessage > message) override
Wrapper for the sd_bus_call(3) function.
Definition: SDBus.cpp:66
std::shared_ptr< SDBusMessage > make_call_message(const std::string &member) override
Wrapper for the sd_bus_message_new_method_call(3) function.
Definition: SDBus.cpp:184
SDBusImp & operator=(const SDBusImp &other)=delete
virtual ~SDBusImp()
Definition: SDBus.cpp:59
SDBusImp()
Definition: SDBus.cpp:46
Definition: Agg.cpp:20